pkgbld 1.23.1 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/index.js +87 -26
- package/dist/src/get-cli-options.d.ts +4 -0
- package/dist/src/prune.d.ts +5 -0
- package/dist/src/types.d.ts +4 -1
- package/package.json +1 -10
package/README.md
CHANGED
|
@@ -178,6 +178,14 @@ pkgbld --format-package-json
|
|
|
178
178
|
|
|
179
179
|
Formats package.json file.
|
|
180
180
|
|
|
181
|
+
### prune (command)
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
pkgbld prune
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
prune devDependencies and redundunt scripts from package.json
|
|
188
|
+
|
|
181
189
|
## Plugin API
|
|
182
190
|
|
|
183
191
|
`pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
|
package/dist/index.js
CHANGED
|
@@ -213,32 +213,54 @@ function getCliOptions(plugins, pkg) {
|
|
|
213
213
|
const cliOptions = cleye.cli({
|
|
214
214
|
name: 'pkgbld',
|
|
215
215
|
version: pkg.version ?? '<unknown>',
|
|
216
|
-
flags: cliFlags
|
|
216
|
+
flags: cliFlags,
|
|
217
|
+
commands: [
|
|
218
|
+
cleye.command({
|
|
219
|
+
name: 'prune',
|
|
220
|
+
description: 'prune devDependencies and redundunt scripts from package.json',
|
|
221
|
+
flags: {
|
|
222
|
+
profile: {
|
|
223
|
+
type: String,
|
|
224
|
+
description: 'profile to use',
|
|
225
|
+
default: 'library'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
]
|
|
217
230
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
231
|
+
if (cliOptions.command === 'prune') {
|
|
232
|
+
return {
|
|
233
|
+
kind: 'prune',
|
|
234
|
+
profile: cliOptions.flags.profile
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const flags = cliOptions.flags;
|
|
239
|
+
const options = {
|
|
240
|
+
kind: 'build',
|
|
241
|
+
umdInputs: flags.umd,
|
|
242
|
+
compressFormats: flags.compress,
|
|
243
|
+
sourcemapFormats: flags.sourcemaps,
|
|
244
|
+
formats: flags.formats,
|
|
245
|
+
formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
|
|
246
|
+
preprocess: flags.preprocess,
|
|
247
|
+
dir: flags.dest,
|
|
248
|
+
sourceDir: flags.src,
|
|
249
|
+
bin: flags.bin,
|
|
250
|
+
includeExternals: flags.includeExternals,
|
|
251
|
+
eject: flags.eject,
|
|
252
|
+
noTsConfig: flags.noTsConfig,
|
|
253
|
+
noUpdatePackageJson: flags.noUpdatePackageJson,
|
|
254
|
+
commonjsPattern: flags.commonjsPattern,
|
|
255
|
+
esPattern: flags.esmPattern,
|
|
256
|
+
umdPattern: flags.umdPattern,
|
|
257
|
+
formatPackageJson: flags.formatPackageJson
|
|
258
|
+
};
|
|
259
|
+
for (const plugin of plugins) {
|
|
260
|
+
plugin.options?.(flags, options);
|
|
261
|
+
}
|
|
262
|
+
return options;
|
|
240
263
|
}
|
|
241
|
-
return options;
|
|
242
264
|
}
|
|
243
265
|
|
|
244
266
|
async function getJson(fileName) {
|
|
@@ -661,6 +683,12 @@ function processPackage(pkg, config, plugins) {
|
|
|
661
683
|
if (typeof pkg.exports !== 'object' && pkg.exports !== null) {
|
|
662
684
|
pkg.exports = {};
|
|
663
685
|
}
|
|
686
|
+
if (typeof pkg.scripts !== 'object' && pkg.scripts !== null) {
|
|
687
|
+
pkg.scripts = {};
|
|
688
|
+
}
|
|
689
|
+
if (!('prepack' in pkg.scripts)) {
|
|
690
|
+
pkg.scripts.prepack = 'pkgbld prune';
|
|
691
|
+
}
|
|
664
692
|
if (pkg.exports['.'] == null) {
|
|
665
693
|
pkg.exports['.'] = {};
|
|
666
694
|
}
|
|
@@ -775,7 +803,7 @@ async function writeJson(path, json) {
|
|
|
775
803
|
await fs.writeFile(path, toFormattedJson(json));
|
|
776
804
|
}
|
|
777
805
|
|
|
778
|
-
var version = "1.
|
|
806
|
+
var version = "1.24.1";
|
|
779
807
|
var name = "pkgbld";
|
|
780
808
|
var license = "MIT";
|
|
781
809
|
var author = "Konstantin Shutkin";
|
|
@@ -804,7 +832,8 @@ var keywords = [
|
|
|
804
832
|
];
|
|
805
833
|
var scripts = {
|
|
806
834
|
build: "rollup -c",
|
|
807
|
-
lint: "eslint ./src"
|
|
835
|
+
lint: "eslint ./src",
|
|
836
|
+
prepack: "node ./dist/index.js prune"
|
|
808
837
|
};
|
|
809
838
|
var dependencies = {
|
|
810
839
|
"@niceties/logger": "^1.1.12",
|
|
@@ -1000,6 +1029,33 @@ function loadPlugins(pkg) {
|
|
|
1000
1029
|
.map(packageName => import(packageName)));
|
|
1001
1030
|
}
|
|
1002
1031
|
|
|
1032
|
+
const scriptsToKeep = new Set([
|
|
1033
|
+
'preinstall',
|
|
1034
|
+
'install',
|
|
1035
|
+
'postinstall',
|
|
1036
|
+
'prepublish',
|
|
1037
|
+
'preprepare',
|
|
1038
|
+
'prepare',
|
|
1039
|
+
'postprepare'
|
|
1040
|
+
]);
|
|
1041
|
+
function prunePkg(pkg, options) {
|
|
1042
|
+
if (options.kind !== 'prune') {
|
|
1043
|
+
throw new Error('prunePkg should only be called in prune mode');
|
|
1044
|
+
}
|
|
1045
|
+
if (options.profile !== 'library') {
|
|
1046
|
+
throw new Error('only library profile is supported');
|
|
1047
|
+
}
|
|
1048
|
+
delete pkg.devDependencies;
|
|
1049
|
+
for (const key of Object.keys(pkg.scripts)) {
|
|
1050
|
+
if (!scriptsToKeep.has(key)) {
|
|
1051
|
+
delete pkg.scripts[key];
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (Object.keys(pkg.scripts).length === 0) {
|
|
1055
|
+
delete pkg.scripts;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1003
1059
|
execute();
|
|
1004
1060
|
async function execute() {
|
|
1005
1061
|
const time = Date.now();
|
|
@@ -1014,6 +1070,11 @@ async function execute() {
|
|
|
1014
1070
|
mainLogger.update('');
|
|
1015
1071
|
process.stdout.moveCursor?.(0, -1);
|
|
1016
1072
|
const options = getCliOptions(plugins, pkg);
|
|
1073
|
+
if (options.kind === 'prune') {
|
|
1074
|
+
prunePkg(pkg, options);
|
|
1075
|
+
await writeJson(pkgPath, pkg);
|
|
1076
|
+
process.exit(0);
|
|
1077
|
+
}
|
|
1017
1078
|
process.stdout.moveCursor?.(0, 1);
|
|
1018
1079
|
mainLogger.update('preparing...');
|
|
1019
1080
|
checkTsConfig(options, mainLogger, plugins);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PackageJson, PkgbldPlugin } from './types';
|
|
2
2
|
export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: PackageJson): {
|
|
3
|
+
kind: 'build';
|
|
3
4
|
umdInputs: string[];
|
|
4
5
|
compressFormats: string[];
|
|
5
6
|
sourcemapFormats: string[];
|
|
@@ -17,4 +18,7 @@ export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: Pac
|
|
|
17
18
|
esPattern: string;
|
|
18
19
|
umdPattern: string;
|
|
19
20
|
formatPackageJson: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "prune";
|
|
23
|
+
readonly profile: string;
|
|
20
24
|
};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type PackageJson = {
|
|
|
10
10
|
dependencies?: Record<string, string>;
|
|
11
11
|
devDependencies?: Record<string, string>;
|
|
12
12
|
peerDependencies: Record<string, string>;
|
|
13
|
+
scripts?: Record<string, string>;
|
|
13
14
|
};
|
|
14
15
|
export declare const enum Priority {
|
|
15
16
|
preprocess = 1000,
|
|
@@ -39,7 +40,9 @@ export type PkgbldRollupPlugin = {
|
|
|
39
40
|
inputs?: string[];
|
|
40
41
|
outputPlugin?: true;
|
|
41
42
|
};
|
|
42
|
-
export type CliOptions = NonNullable<ReturnType<typeof getCliOptions
|
|
43
|
+
export type CliOptions = NonNullable<Extract<ReturnType<typeof getCliOptions>, {
|
|
44
|
+
kind: 'build';
|
|
45
|
+
}>>;
|
|
43
46
|
export type ParsedOptions = Record<string, string | number | string[] | number[] | boolean | undefined>;
|
|
44
47
|
export interface PkgbldPlugin {
|
|
45
48
|
options(parsedArgs: ParsedOptions, options: CliOptions): void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.24.1",
|
|
3
3
|
"name": "pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -47,16 +47,7 @@
|
|
|
47
47
|
"kleur": "^4.1.5",
|
|
48
48
|
"cleye": "^1.3.2"
|
|
49
49
|
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@types/lodash": "^4.14.199",
|
|
52
|
-
"@total-typescript/ts-reset": "^0.5.1",
|
|
53
|
-
"options": "0.2.0"
|
|
54
|
-
},
|
|
55
50
|
"peerDependencies": {
|
|
56
51
|
"typescript": "^5.2.2"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "rollup -c",
|
|
60
|
-
"lint": "eslint ./src"
|
|
61
52
|
}
|
|
62
53
|
}
|