Skip to content

Commit 6ea75a7

Browse files
authored
feat: add -r, --remove flag support (#9)
1 parent 3dd9dab commit 6ea75a7

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Add `clean-pkg-json` to the [`prepack` hook](https://docs.npmjs.com/cli/v8/using
3838
| Flag | Description |
3939
| - | - |
4040
| `-k, --keep <property name>` | Property names to keep. Accepts multiple flags or a comma-delimited list. |
41+
| `-r, --remove <property name>` | Property names to remove. Accepts multiple flags or a comma-delimited list. |
4142
| `-v, --verbose` | Verbose logs. |
4243
| `-d, --dry` | Dry run mode. Instead of writing to disk, it will log it. |
4344
| `-h, --help` | Show help |
@@ -80,7 +81,7 @@ By default, these properties are preserved in `package.json`:
8081
- `funding`
8182

8283
#### CDNs
83-
- [`jsdelivr`](https://www.jsdelivr.com/features#publishing-packages)
84+
- [`jsdelivr`](https://www.jsdelivr.com/documentation#id-configuring-a-default-file-in-packagejson)
8485
- [`unpkg`](https://unpkg.com/)
8586

8687
#### [Node.js](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions)
@@ -106,7 +107,8 @@ By default, these properties are preserved in `package.json`:
106107
- `extensionKind`
107108
- `icon`
108109

109-
#### [Angular Package Format](https://angular.io/guide/angular-package-format#legacy-resolution-keys)
110+
#### [Angular Package Format](https://angular.dev/tools/libraries/angular-package-format)
111+
- `fesm2022`
110112
- `fesm2020`
111113
- `fesm2015`
112114
- `esm2020`

src/default-keep-properties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export const defaultKeepProperties = [
7474
'extensionKind',
7575
'icon',
7676

77-
// Angular - https://angular.io/guide/angular-package-format#legacy-resolution-keys
77+
// Angular - https://angular.dev/tools/libraries/angular-package-format
78+
'fesm2022',
7879
'fesm2020',
7980
'fesm2015',
8081
'esm2020',

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const argv = cli({
1919
alias: 'k',
2020
description: 'package.json properties to keep',
2121
},
22+
remove: {
23+
type: [String],
24+
alias: 'r',
25+
description: 'package.json properties to remove',
26+
},
2227
dry: {
2328
type: Boolean,
2429
alias: 'd',
@@ -54,6 +59,10 @@ const log = (...args: any[]) => {
5459
...argv.flags.keep.flatMap(keepProperty => keepProperty.split(',')),
5560
]);
5661

62+
for (const item of argv.flags.remove) {
63+
keepProperties.delete(item);
64+
}
65+
5766
log('Keeing properties', Array.from(keepProperties));
5867

5968
for (const property in packageJson) {

tests/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,21 @@ describe('clean-pkg-roll', ({ test }) => {
5050
},
5151
});
5252
});
53+
54+
test('remove flag', async () => {
55+
const { stdout } = await spawn(
56+
cleanPkgJsonPath,
57+
['--dry', '-r', 'scripts.postinstall'],
58+
{
59+
cwd: './tests/fixture-package',
60+
},
61+
);
62+
63+
expect(JSON.parse(stdout)).toStrictEqual({
64+
name: 'test-package',
65+
dependencies: {
66+
lodash: '*',
67+
},
68+
});
69+
});
5370
});

0 commit comments

Comments
 (0)