Skip to content

Commit

Permalink
solution to cli issue - TypeError: Cannot read properties of undefine…
Browse files Browse the repository at this point in the history
…d (reading 'fsPath') #895 (#924)

* solution to cli issue TypeError: Cannot read properties of undefined (reading 'fsPath') #895

* readDevContainerConfigFile - implemented logic like in other commands - used the fn

* Update lockfile.ts

* changes as suggested in review comments
  • Loading branch information
gauravsaini04 authored Nov 21, 2024
1 parent f475b2b commit bf230f4
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/spec-node/featuresCLI/resolveDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import * as path from 'path';
import * as jsonc from 'jsonc-parser';
import { Argv } from 'yargs';
import { LogLevel, mapLogLevel } from '../../spec-utils/log';
import { getPackageConfig } from '../../spec-utils/product';
import { createLog } from '../devContainers';
import { UnpackArgv } from '../devContainersSpecCLI';
import { isLocalFile, readLocalFile } from '../../spec-utils/pfs';
import { DevContainerConfig, DevContainerFeature } from '../../spec-configuration/configuration';
import { isLocalFile } from '../../spec-utils/pfs';
import { DevContainerFeature } from '../../spec-configuration/configuration';
import { buildDependencyGraph, computeDependsOnInstallationOrder, generateMermaidDiagram } from '../../spec-configuration/containerFeaturesOrder';
import { OCISourceInformation, processFeatureIdentifier, userFeaturesToArray } from '../../spec-configuration/containerFeaturesConfiguration';
import { readLockfile } from '../../spec-configuration/lockfile';
import { runAsyncHandler } from '../utils';
import { loadNativeModule } from '../../spec-common/commonUtils';
import { getCLIHost } from '../../spec-common/cliHost';
import { ContainerError } from '../../spec-common/errors';
import { uriToFsPath } from '../../spec-configuration/configurationCommonUtils';
import { workspaceFromPath } from '../../spec-utils/workspaces';
import { readDevContainerConfigFile } from '../configContainer';
import { URI } from 'vscode-uri';


interface JsonOutput {
installOrder?: {
Expand Down Expand Up @@ -61,28 +68,28 @@ async function featuresResolveDependencies({
configPath = path.join(workspaceFolder, '.devcontainer', 'devcontainer.json');
}

// Load dev container config
const buffer = await readLocalFile(configPath);
if (!buffer) {
output.write(`Could not load devcontainer.json file from path ${configPath}`, LogLevel.Error);
process.exit(1);
}
const params = {
output,
env: process.env,
};

// Parse dev container config
const config: DevContainerConfig = jsonc.parse(buffer.toString());
if (!config || !config.features) {
output.write(`No Features object in configuration '${configPath}'`, LogLevel.Error);
process.exit(1);
const cwd = workspaceFolder || process.cwd();
const cliHost = await getCLIHost(cwd, loadNativeModule, true);
const workspace = workspaceFromPath(cliHost.path, workspaceFolder);
const configFile: URI = URI.file(path.resolve(process.cwd(), configPath));
const configs = await readDevContainerConfigFile(cliHost, workspace, configFile, false, output, undefined, undefined);

if (configFile && !configs) {
throw new ContainerError({ description: `Dev container config (${uriToFsPath(configFile, cliHost.platform)}) not found.` });
}
const configWithRaw = configs!.config;
const { config } = configWithRaw;

const userFeaturesConfig = userFeaturesToArray(config);
if (!userFeaturesConfig) {
output.write(`Could not parse features object in configuration '${configPath}'`, LogLevel.Error);
process.exit(1);
}
const params = {
output,
env: process.env,
};

const { lockfile } = await readLockfile(config);
const processFeature = async (_userFeature: DevContainerFeature) => {
Expand Down

0 comments on commit bf230f4

Please sign in to comment.