From ef27abaad1aecca345725538f34675e51a490da7 Mon Sep 17 00:00:00 2001 From: Samuel MARLHENS Date: Tue, 17 Oct 2023 18:05:03 +0200 Subject: [PATCH] feat: ignore local path as version --- examples/workspace/foo/package.json | 3 ++- examples/workspace/package-lock.json | 8 ++++++++ lib/npd.ts | 6 ++++++ tests/pin-from-obj.spec.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/examples/workspace/foo/package.json b/examples/workspace/foo/package.json index 1d104a82..22c81a8a 100644 --- a/examples/workspace/foo/package.json +++ b/examples/workspace/foo/package.json @@ -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" } } diff --git a/examples/workspace/package-lock.json b/examples/workspace/package-lock.json index d581c7fb..f006ada3 100644 --- a/examples/workspace/package-lock.json +++ b/examples/workspace/package-lock.json @@ -11,6 +11,10 @@ }, "node_modules/fake-package-3": { "version": "3.1.9" + }, + "node_modules/fake-package-4": { + "version": "1.2.3", + "resolved": "file:vendor/foo-1.2.3.tgz" } }, "dependencies": { @@ -22,6 +26,10 @@ }, "fake-package-3": { "version": "3.1.9" + }, + "fake-package-4": { + "version": "1.2.3", + "resolved": "file:vendor/foo-1.2.3.tgz" } } } diff --git a/lib/npd.ts b/lib/npd.ts index 85283bd7..245e7130 100644 --- a/lib/npd.ts +++ b/lib/npd.ts @@ -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, diff --git a/tests/pin-from-obj.spec.ts b/tests/pin-from-obj.spec.ts index 1da5b139..db55202a 100644 --- a/tests/pin-from-obj.spec.ts +++ b/tests/pin-from-obj.spec.ts @@ -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: [], + }); + }); });