Skip to content

Commit

Permalink
feat: ignore local path as version
Browse files Browse the repository at this point in the history
  • Loading branch information
smarlhens committed Oct 17, 2023
1 parent cbe75f0 commit ef27aba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/workspace/foo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"dependencies": {
"fake-package-1": "^1.0.0",
"fake-package-2": "^2.0.0",
"fake-package-3": "^3.0.0"
"fake-package-3": "^3.0.0",
"fake-package-4": "file:../vendor/foo-1.2.3.tgz"
}
}
8 changes: 8 additions & 0 deletions examples/workspace/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/npd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ export const pinDependencies = (ctx: PinDependenciesInput): PinDependenciesOutpu

for (const dependencyName of Object.keys(packageJson[dependencyType])) {
const userDefinedVersion = packageJson[dependencyType][dependencyName];

if (userDefinedVersion.startsWith('file:')) {
debug(`Dependency ${chalk.white(dependencyName)} is using a local path as version.`);
continue;
}

let dependencyKey: string = resolver.resolveDependencyKey({
name: dependencyName,
version: userDefinedVersion,
Expand Down
27 changes: 27 additions & 0 deletions tests/pin-from-obj.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,31 @@ describe('pin from obj', () => {
versionsToPin: [],
});
});

it('should continue if dependency is using a local path as version', async () => {
const params: PinDependenciesInput = {
packageJson: {
dependencies: {
'fake-package-1': 'file:../vendor/foo.tgz',
},
},
packageLockFile: {
content: {
lockfileVersion: 3,
packages: {
'node_modules/fake-package-1': { version: '1.2.3', resolved: 'file:../vendor/foo.tgz' },
},
},
},
};
const payload = pinDependencies(params);
expect(payload).toEqual({
packageJson: {
dependencies: {
'fake-package-1': 'file:../vendor/foo.tgz',
},
},
versionsToPin: [],
});
});
});

0 comments on commit ef27aba

Please sign in to comment.