Skip to content

Commit d909b97

Browse files
committed
readDevContainerConfigFile - implemented logic like in other commands - used the fn
1 parent 44279cd commit d909b97

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/spec-node/featuresCLI/resolveDependencies.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import * as path from 'path';
2-
import * as jsonc from 'jsonc-parser';
32
import { Argv } from 'yargs';
43
import { LogLevel, mapLogLevel } from '../../spec-utils/log';
54
import { getPackageConfig } from '../../spec-utils/product';
65
import { createLog } from '../devContainers';
76
import { UnpackArgv } from '../devContainersSpecCLI';
8-
import { isLocalFile, readLocalFile } from '../../spec-utils/pfs';
9-
import { DevContainerConfig, DevContainerFeature } from '../../spec-configuration/configuration';
7+
import { isLocalFile } from '../../spec-utils/pfs';
8+
import { DevContainerFeature } from '../../spec-configuration/configuration';
109
import { buildDependencyGraph, computeDependsOnInstallationOrder, generateMermaidDiagram } from '../../spec-configuration/containerFeaturesOrder';
1110
import { OCISourceInformation, processFeatureIdentifier, userFeaturesToArray } from '../../spec-configuration/containerFeaturesConfiguration';
1211
import { readLockfile } from '../../spec-configuration/lockfile';
1312
import { runAsyncHandler } from '../utils';
13+
import { loadNativeModule } from '../../spec-common/commonUtils';
14+
import { getCLIHost } from '../../spec-common/cliHost';
15+
import { ContainerError } from '../../spec-common/errors';
16+
import { uriToFsPath } from '../../spec-configuration/configurationCommonUtils';
17+
import { workspaceFromPath } from '../../spec-utils/workspaces';
18+
import { readDevContainerConfigFile } from '../configContainer';
19+
import { URI } from 'vscode-uri';
20+
1421

1522
interface JsonOutput {
1623
installOrder?: {
@@ -61,32 +68,31 @@ async function featuresResolveDependencies({
6168
configPath = path.join(workspaceFolder, '.devcontainer', 'devcontainer.json');
6269
}
6370

64-
// Load dev container config
65-
const buffer = await readLocalFile(configPath);
66-
if (!buffer) {
67-
output.write(`Could not load devcontainer.json file from path ${configPath}`, LogLevel.Error);
68-
process.exit(1);
69-
}
71+
const params = {
72+
output,
73+
env: process.env,
74+
};
7075

71-
// Parse dev container config
72-
const config: DevContainerConfig = jsonc.parse(buffer.toString());
73-
if (!config || !config.features) {
74-
output.write(`No Features object in configuration '${configPath}'`, LogLevel.Error);
75-
process.exit(1);
76+
const cwd = workspaceFolder || process.cwd();
77+
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
78+
const workspace = workspaceFromPath(cliHost.path, workspaceFolder);
79+
const configFile: URI | undefined = configPath ? URI.file(path.resolve(process.cwd(), configPath)) : undefined;
80+
const configs = configFile && await readDevContainerConfigFile(cliHost, workspace, configFile, false, output, undefined, undefined);
81+
82+
if (configFile && !configs) {
83+
throw new ContainerError({ description: `Dev container config (${uriToFsPath(configFile, cliHost.platform)}) not found.` });
7684
}
85+
86+
const configWithRaw = configs!.config;
87+
const { config } = configWithRaw;
88+
7789
const userFeaturesConfig = userFeaturesToArray(config);
7890
if (!userFeaturesConfig) {
7991
output.write(`Could not parse features object in configuration '${configPath}'`, LogLevel.Error);
8092
process.exit(1);
8193
}
82-
const params = {
83-
output,
84-
env: process.env,
85-
};
86-
87-
let configObj: DevContainerConfig | string = config.hasOwnProperty('configFilePath') && config.configFilePath ? config : configPath;
8894

89-
const { lockfile } = await readLockfile(configObj);
95+
const { lockfile } = await readLockfile(config);
9096
const processFeature = async (_userFeature: DevContainerFeature) => {
9197
return await processFeatureIdentifier(params, configPath, workspaceFolder, _userFeature, lockfile);
9298
};

0 commit comments

Comments
 (0)