Skip to content

Commit

Permalink
Keep existing lockfile updated (devcontainers/spec#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed May 15, 2023
1 parent 914d873 commit 8965d41
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/spec-configuration/containerFeaturesConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export async function generateFeaturesConfig(params: ContainerFeatureInternalPar

// Read features and get the type.
output.write('--- Processing User Features ----', LogLevel.Trace);
const lockfile = await readLockfile(params, config);
const lockfile = await readLockfile(config);
featuresConfig = await processUserFeatures(params, config, workspaceRoot, userFeatures, featuresConfig, lockfile);
output.write(JSON.stringify(featuresConfig, null, 4), LogLevel.Trace);

Expand Down
23 changes: 10 additions & 13 deletions src/spec-configuration/lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export interface Lockfile {
}

export async function writeLockfile(params: ContainerFeatureInternalParams, config: DevContainerConfig, featuresConfig: FeaturesConfig) {
if (!params.experimentalLockfile && !params.experimentalFrozenLockfile) {
const lockfilePath = getLockfilePath(config);
const oldLockfileContent = await readLocalFile(lockfilePath)
.catch(err => {
if (err?.code !== 'ENOENT') {
throw err;
}
});

if (!oldLockfileContent && !params.experimentalLockfile && !params.experimentalFrozenLockfile) {
return;
}

Expand All @@ -37,14 +45,7 @@ export async function writeLockfile(params: ContainerFeatureInternalParams, conf
features: {} as Record<string, { version: string; resolved: string; integrity: string }>,
});

const lockfilePath = getLockfilePath(config);
const newLockfileContent = Buffer.from(JSON.stringify(lockfile, null, 2));
const oldLockfileContent = await readLocalFile(lockfilePath)
.catch(err => {
if (err?.code !== 'ENOENT') {
throw err;
}
});
if (params.experimentalFrozenLockfile && !oldLockfileContent) {
throw new Error('Lockfile does not exist.');
}
Expand All @@ -56,11 +57,7 @@ export async function writeLockfile(params: ContainerFeatureInternalParams, conf
}
}

export async function readLockfile(params: ContainerFeatureInternalParams, config: DevContainerConfig): Promise<Lockfile | undefined> {
if (!params.experimentalLockfile && !params.experimentalFrozenLockfile) {
return undefined;
}

export async function readLockfile(config: DevContainerConfig): Promise<Lockfile | undefined> {
try {
const content = await readLocalFile(getLockfilePath(config));
return JSON.parse(content.toString()) as Lockfile;
Expand Down

0 comments on commit 8965d41

Please sign in to comment.