pkgbld 1.23.1 → 1.24.2

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 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
- const flags = cliOptions.flags;
219
- const options = {
220
- umdInputs: flags.umd,
221
- compressFormats: flags.compress,
222
- sourcemapFormats: flags.sourcemaps,
223
- formats: flags.formats,
224
- formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
225
- preprocess: flags.preprocess,
226
- dir: flags.dest,
227
- sourceDir: flags.src,
228
- bin: flags.bin,
229
- includeExternals: flags.includeExternals,
230
- eject: flags.eject,
231
- noTsConfig: flags.noTsConfig,
232
- noUpdatePackageJson: flags.noUpdatePackageJson,
233
- commonjsPattern: flags.commonjsPattern,
234
- esPattern: flags.esmPattern,
235
- umdPattern: flags.umdPattern,
236
- formatPackageJson: flags.formatPackageJson
237
- };
238
- for (const plugin of plugins) {
239
- plugin.options?.(flags, options);
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,13 @@ 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
+ const binary = typeof pkg.scripts.build === 'string' && pkg.scripts.build?.startsWith('pkgbld-internal') ? 'pkgbld-internal' : 'pkgbld';
691
+ pkg.scripts.prepack = `${binary} prune`;
692
+ }
664
693
  if (pkg.exports['.'] == null) {
665
694
  pkg.exports['.'] = {};
666
695
  }
@@ -775,7 +804,7 @@ async function writeJson(path, json) {
775
804
  await fs.writeFile(path, toFormattedJson(json));
776
805
  }
777
806
 
778
- var version = "1.23.1";
807
+ var version = "1.24.2";
779
808
  var name = "pkgbld";
780
809
  var license = "MIT";
781
810
  var author = "Konstantin Shutkin";
@@ -804,7 +833,8 @@ var keywords = [
804
833
  ];
805
834
  var scripts = {
806
835
  build: "rollup -c",
807
- lint: "eslint ./src"
836
+ lint: "eslint ./src",
837
+ prepack: "node ./dist/index.js prune"
808
838
  };
809
839
  var dependencies = {
810
840
  "@niceties/logger": "^1.1.12",
@@ -1000,6 +1030,33 @@ function loadPlugins(pkg) {
1000
1030
  .map(packageName => import(packageName)));
1001
1031
  }
1002
1032
 
1033
+ const scriptsToKeep = new Set([
1034
+ 'preinstall',
1035
+ 'install',
1036
+ 'postinstall',
1037
+ 'prepublish',
1038
+ 'preprepare',
1039
+ 'prepare',
1040
+ 'postprepare'
1041
+ ]);
1042
+ function prunePkg(pkg, options) {
1043
+ if (options.kind !== 'prune') {
1044
+ throw new Error('prunePkg should only be called in prune mode');
1045
+ }
1046
+ if (options.profile !== 'library') {
1047
+ throw new Error('only library profile is supported');
1048
+ }
1049
+ delete pkg.devDependencies;
1050
+ for (const key of Object.keys(pkg.scripts)) {
1051
+ if (!scriptsToKeep.has(key)) {
1052
+ delete pkg.scripts[key];
1053
+ }
1054
+ }
1055
+ if (Object.keys(pkg.scripts).length === 0) {
1056
+ delete pkg.scripts;
1057
+ }
1058
+ }
1059
+
1003
1060
  execute();
1004
1061
  async function execute() {
1005
1062
  const time = Date.now();
@@ -1014,6 +1071,11 @@ async function execute() {
1014
1071
  mainLogger.update('');
1015
1072
  process.stdout.moveCursor?.(0, -1);
1016
1073
  const options = getCliOptions(plugins, pkg);
1074
+ if (options.kind === 'prune') {
1075
+ prunePkg(pkg, options);
1076
+ await writeJson(pkgPath, pkg);
1077
+ process.exit(0);
1078
+ }
1017
1079
  process.stdout.moveCursor?.(0, 1);
1018
1080
  mainLogger.update('preparing...');
1019
1081
  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
  };
@@ -0,0 +1,5 @@
1
+ import { PackageJson } from './types';
2
+ export declare function prunePkg(pkg: PackageJson, options: {
3
+ kind: 'prune';
4
+ profile: string;
5
+ }): void;
@@ -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.23.1",
2
+ "version": "1.24.2",
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
  }