|
1 | 1 | import * as path from 'path'; |
2 | | -import * as jsonc from 'jsonc-parser'; |
3 | 2 | import { Argv } from 'yargs'; |
4 | 3 | import { LogLevel, mapLogLevel } from '../../spec-utils/log'; |
5 | 4 | import { getPackageConfig } from '../../spec-utils/product'; |
6 | 5 | import { createLog } from '../devContainers'; |
7 | 6 | 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'; |
10 | 9 | import { buildDependencyGraph, computeDependsOnInstallationOrder, generateMermaidDiagram } from '../../spec-configuration/containerFeaturesOrder'; |
11 | 10 | import { OCISourceInformation, processFeatureIdentifier, userFeaturesToArray } from '../../spec-configuration/containerFeaturesConfiguration'; |
12 | 11 | import { readLockfile } from '../../spec-configuration/lockfile'; |
13 | 12 | 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 | + |
14 | 21 |
|
15 | 22 | interface JsonOutput { |
16 | 23 | installOrder?: { |
@@ -61,28 +68,28 @@ async function featuresResolveDependencies({ |
61 | 68 | configPath = path.join(workspaceFolder, '.devcontainer', 'devcontainer.json'); |
62 | 69 | } |
63 | 70 |
|
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 | + }; |
70 | 75 |
|
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 = URI.file(path.resolve(process.cwd(), configPath)); |
| 80 | + const configs = 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.` }); |
76 | 84 | } |
| 85 | + const configWithRaw = configs!.config; |
| 86 | + const { config } = configWithRaw; |
| 87 | + |
77 | 88 | const userFeaturesConfig = userFeaturesToArray(config); |
78 | 89 | if (!userFeaturesConfig) { |
79 | 90 | output.write(`Could not parse features object in configuration '${configPath}'`, LogLevel.Error); |
80 | 91 | process.exit(1); |
81 | 92 | } |
82 | | - const params = { |
83 | | - output, |
84 | | - env: process.env, |
85 | | - }; |
86 | 93 |
|
87 | 94 | const { lockfile } = await readLockfile(config); |
88 | 95 | const processFeature = async (_userFeature: DevContainerFeature) => { |
|
0 commit comments