Skip to content

Commit

Permalink
Fix #86 Files leak across instances of Project
Browse files Browse the repository at this point in the history
  • Loading branch information
lolmaus committed Dec 7, 2023
1 parent d253630 commit e225549
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export interface ProjectArgs {

tmp.setGracefulCleanup();

// This only shallow-merges with any user-provided files, which is OK right now
// because this is only one level deep. If we ever make it deeper, we'll need to
// switch to a proper deep merge.
const defaultFiles = {
'index.js': `
'use strict';
Expand Down Expand Up @@ -107,7 +104,7 @@ export class Project {

if (files && typeof files?.['package.json'] === 'string') {
pkg = JSON.parse(files['package.json']);
files = Object.assign({}, files);
files = deepmerge({}, files);
delete files['package.json'];
}

Expand All @@ -117,9 +114,9 @@ export class Project {
keywords: pkg.keywords || [],
});
if (files) {
this.files = { ...defaultFiles, ...files };
this.files = deepmerge({}, { ...defaultFiles, ...files });
} else {
this.files = defaultFiles;
this.files = deepmerge({}, defaultFiles);
}
this.requestedRange = requestedRange || this.pkg.version!;

Expand Down

0 comments on commit e225549

Please sign in to comment.