Skip to content

Commit

Permalink
fix: handle package with only dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
smarlhens committed Jan 7, 2023
1 parent dbdffb3 commit 05dfc4a
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
14 changes: 14 additions & 0 deletions examples/with-only-dependencies/package-lock.json

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

7 changes: 7 additions & 0 deletions examples/with-only-dependencies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fake",
"private": true,
"dependencies": {
"fake-package-1": "1.0.0"
}
}
14 changes: 14 additions & 0 deletions examples/with-only-dev-dependencies/package-lock.json

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

7 changes: 7 additions & 0 deletions examples/with-only-dev-dependencies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fake",
"private": true,
"devDependencies": {
"fake-dev-package-1": "2.0.0"
}
}
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const packageJsonSchema: JSONSchemaType<PackageJson> = {
required: [],
},
},
required: ['dependencies'],
required: [],
};

// @ts-ignore
Expand Down
62 changes: 62 additions & 0 deletions tests/npd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,66 @@ describe('npd', () => {
'[SUCCESS] All dependency versions are already pinned :)',
);
}, 10000);

it('should output no dependency versions to pin from dependencies only', async () => {
const execaOptions: Options = {
cwd: resolve(process.cwd(), 'examples', 'with-only-dependencies'),
stdio: 'pipe',
cleanup: true,
};
const { stdout } = await execaCommand(
`node --experimental-specifier-resolution=node --loader ts-node/esm ${resolve(process.cwd(), 'bin', 'npd.ts')}`,
execaOptions,
);
expect(stdout).toEqual(
'[STARTED] Pinning dependency versions in package.json file...\n' +
'[STARTED] Reading package-lock.json...\n' +
'[SUCCESS] Reading package-lock.json...\n' +
'[STARTED] Reading package.json...\n' +
'[SUCCESS] Reading package.json...\n' +
'[STARTED] Validating package-lock.json...\n' +
'[SUCCESS] Validating package-lock.json...\n' +
'[STARTED] Validating package.json...\n' +
'[SUCCESS] Validating package.json...\n' +
'[STARTED] Computing which dependency versions are to pin...\n' +
'[SUCCESS] Computing which dependency versions are to pin...\n' +
'[STARTED] Output dependency versions that can be pinned...\n' +
'[TITLE] All dependency versions are already pinned :)\n' +
'[SUCCESS] Output dependency versions that can be pinned...\n' +
'[STARTED] Updating package.json...\n' +
'[SKIPPED] Update is disabled by default.\n' +
'[SUCCESS] All dependency versions are already pinned :)',
);
}, 10000);

it('should output no dependency versions to pin from devDependencies only', async () => {
const execaOptions: Options = {
cwd: resolve(process.cwd(), 'examples', 'with-only-dev-dependencies'),
stdio: 'pipe',
cleanup: true,
};
const { stdout } = await execaCommand(
`node --experimental-specifier-resolution=node --loader ts-node/esm ${resolve(process.cwd(), 'bin', 'npd.ts')}`,
execaOptions,
);
expect(stdout).toEqual(
'[STARTED] Pinning dependency versions in package.json file...\n' +
'[STARTED] Reading package-lock.json...\n' +
'[SUCCESS] Reading package-lock.json...\n' +
'[STARTED] Reading package.json...\n' +
'[SUCCESS] Reading package.json...\n' +
'[STARTED] Validating package-lock.json...\n' +
'[SUCCESS] Validating package-lock.json...\n' +
'[STARTED] Validating package.json...\n' +
'[SUCCESS] Validating package.json...\n' +
'[STARTED] Computing which dependency versions are to pin...\n' +
'[SUCCESS] Computing which dependency versions are to pin...\n' +
'[STARTED] Output dependency versions that can be pinned...\n' +
'[TITLE] All dependency versions are already pinned :)\n' +
'[SUCCESS] Output dependency versions that can be pinned...\n' +
'[STARTED] Updating package.json...\n' +
'[SKIPPED] Update is disabled by default.\n' +
'[SUCCESS] All dependency versions are already pinned :)',
);
}, 10000);
});

0 comments on commit 05dfc4a

Please sign in to comment.