pkgbld 1.16.7 → 1.17.0

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
@@ -42,6 +42,10 @@ Run `npm run build`.
42
42
 
43
43
  ### umd
44
44
 
45
+ Defines what subpath exports (entry points) should be compiled as umd bundles.
46
+
47
+ Example:
48
+
45
49
  ```
46
50
  pkgbld --umd=index,core
47
51
  ```
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var logger = require('@niceties/logger');
6
6
  var rollup = require('rollup');
7
7
  var fs = require('fs/promises');
8
8
  var path = require('path');
9
- var minimist = require('minimist');
9
+ var cleye = require('cleye');
10
10
  var refiner = require('@slimlib/refine-partition');
11
11
  var camelCase = require('lodash/camelCase');
12
12
  var kleur = require('kleur');
@@ -43,37 +43,93 @@ const defaults = {
43
43
  noTsConfig: false,
44
44
  noUpdatePackageJson: false
45
45
  };
46
- function getCliOptions(plugins) {
47
- const parsedArgs = minimist(process.argv.slice(2));
48
- const umdInputs = parsedArgs.umd?.split(',').map((arg) => arg.trim()) ?? defaults.umdInputs;
49
- const compressFormats = parsedArgs.compress?.split(',').map((arg) => arg.trim()) ?? defaults.compressFormats;
50
- const sourcemapFormats = parsedArgs.sourcemaps?.split(',').map((arg) => arg.trim()) ?? defaults.sourcemapFormats;
51
- const formats = parsedArgs.formats?.split(',').map((arg) => arg.trim()) ?? defaults.formats;
52
- const preprocess = parsedArgs.preprocess?.split(',').map((arg) => arg.trim()) ?? defaults.preprocess;
53
- const dir = parsedArgs.dir ?? defaults.dir;
54
- const sourceDir = parsedArgs.sourceDir ?? defaults.sourceDir;
55
- const bin = parsedArgs.bin?.split(',').map((arg) => arg.trim());
56
- const includeExternals = parsedArgs['include-externals'] ?? defaults.includeExternals;
57
- const eject = !!parsedArgs.eject ?? defaults.eject;
58
- const noTsConfig = !!parsedArgs.noTsConfig ?? defaults.noTsConfig;
59
- const noUpdatePackageJson = !!parsedArgs.noUpdatePackageJson ?? defaults.noUpdatePackageJson;
46
+ function CommaSeparatedString(value) {
47
+ return value.split(',').map((arg) => arg.trim());
48
+ }
49
+ function getCliOptions(plugins, pkg) {
50
+ const cliOptions = cleye.cli({
51
+ name: 'pkgbld',
52
+ version: pkg.version ?? '<unknown>',
53
+ flags: {
54
+ umd: {
55
+ type: CommaSeparatedString,
56
+ description: 'Package subpath exports in UMD format',
57
+ default: defaults.umdInputs
58
+ },
59
+ compress: {
60
+ type: CommaSeparatedString,
61
+ description: 'Compress formats using terser',
62
+ default: defaults.compressFormats
63
+ },
64
+ sourcemaps: {
65
+ type: CommaSeparatedString,
66
+ description: 'Emit sourcemaps for the specified formats',
67
+ default: defaults.sourcemapFormats
68
+ },
69
+ formats: {
70
+ type: CommaSeparatedString,
71
+ description: 'Formats to emit',
72
+ default: defaults.formats
73
+ },
74
+ preprocess: {
75
+ type: CommaSeparatedString,
76
+ description: 'Preprocess entry points / subpath exports',
77
+ default: defaults.preprocess
78
+ },
79
+ dir: {
80
+ type: String,
81
+ description: 'Output directory',
82
+ default: defaults.dir
83
+ },
84
+ sourceDir: {
85
+ type: String,
86
+ description: 'Source directory',
87
+ default: defaults.sourceDir
88
+ },
89
+ bin: {
90
+ type: CommaSeparatedString,
91
+ description: 'Executable files'
92
+ },
93
+ includeExternals: {
94
+ type: Boolean,
95
+ description: 'Include all externals into result bundle(s)',
96
+ default: defaults.includeExternals
97
+ },
98
+ eject: {
99
+ type: Boolean,
100
+ description: 'Eject config',
101
+ default: defaults.includeExternals
102
+ },
103
+ noTsConfig: {
104
+ type: Boolean,
105
+ description: 'Do not create / update tsconfig.json',
106
+ default: defaults.noTsConfig
107
+ },
108
+ noUpdatePackageJson: {
109
+ type: Boolean,
110
+ description: 'Do not create / update package.json',
111
+ default: defaults.noUpdatePackageJson
112
+ }
113
+ }
114
+ });
115
+ const flags = cliOptions.flags;
60
116
  const options = {
61
- umdInputs,
62
- compressFormats,
63
- sourcemapFormats,
64
- formats,
65
- formatsOverriden: 'formats' in parsedArgs,
66
- preprocess,
67
- dir,
68
- sourceDir,
69
- bin,
70
- includeExternals,
71
- eject,
72
- noTsConfig,
73
- noUpdatePackageJson
117
+ umdInputs: flags.umd,
118
+ compressFormats: flags.compress,
119
+ sourcemapFormats: flags.sourcemaps,
120
+ formats: flags.formats,
121
+ formatsOverridden: flags.formats !== defaults.formats,
122
+ preprocess: flags.preprocess,
123
+ dir: flags.dir,
124
+ sourceDir: flags.sourceDir,
125
+ bin: flags.bin,
126
+ includeExternals: flags.includeExternals,
127
+ eject: flags.eject,
128
+ noTsConfig: flags.noTsConfig,
129
+ noUpdatePackageJson: flags.noUpdatePackageJson
74
130
  };
75
131
  for (const plugin of plugins) {
76
- plugin.options && plugin.options(parsedArgs, options);
132
+ plugin.options?.(flags, options);
77
133
  }
78
134
  return options;
79
135
  }
@@ -303,19 +359,17 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers,
303
359
  if (!plugin.inputs || plugin.inputs.length === 0) {
304
360
  refineNext(doExpandInputs(formats));
305
361
  }
362
+ else if (inputs.length === 1) {
363
+ refineNext(formats);
364
+ }
306
365
  else {
307
- if (inputs.length === 1) {
308
- refineNext(formats);
309
- }
310
- else {
311
- const expanded = [];
312
- for (const format of formats) {
313
- for (const input of plugin.inputs) {
314
- expanded.push(`${format}.${input}`);
315
- }
366
+ const expanded = [];
367
+ for (const format of formats) {
368
+ for (const input of plugin.inputs) {
369
+ expanded.push(`${format}.${input}`);
316
370
  }
317
- refineNext(expanded);
318
371
  }
372
+ refineNext(expanded);
319
373
  }
320
374
  }
321
375
  }
@@ -451,9 +505,9 @@ const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCoun
451
505
  function processPackage(pkg, config, plugins) {
452
506
  const inputs = [];
453
507
  const logger$1 = logger.createLogger();
454
- const allowEsm = (config.formatsOverriden && config.formats.includes('es') || !config.formatsOverriden);
455
- const allowCjs = (config.formatsOverriden && config.formats.includes('cjs') || !config.formatsOverriden);
456
- const allowUmd = (config.formatsOverriden && config.formats.includes('umd') || !config.formatsOverriden || config.umdInputs);
508
+ const allowEsm = (config.formatsOverridden && config.formats.includes('es') || !config.formatsOverridden);
509
+ const allowCjs = (config.formatsOverridden && config.formats.includes('cjs') || !config.formatsOverridden);
510
+ const allowUmd = (config.formatsOverridden && config.formats.includes('umd') || !config.formatsOverridden || config.umdInputs);
457
511
  if (typeof pkg !== 'object' || Array.isArray(pkg)) {
458
512
  logger$1.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
459
513
  process.exit(-1);
@@ -502,13 +556,11 @@ function processPackage(pkg, config, plugins) {
502
556
  }
503
557
  }
504
558
  }
559
+ else if (typeof pkg.bin === 'string') {
560
+ config.bin = [pkg.bin];
561
+ }
505
562
  else {
506
- if (typeof pkg.bin === 'string') {
507
- config.bin = [pkg.bin];
508
- }
509
- else {
510
- delete pkg.bin;
511
- }
563
+ delete pkg.bin;
512
564
  }
513
565
  if (allowCjs && typeof pkg.main !== 'string') {
514
566
  pkg.main = `./${config.dir}/index.cjs`;
@@ -561,7 +613,7 @@ async function writeJson(path, json) {
561
613
  await fs.writeFile(path, JSON.stringify(json, null, 2) + '\n');
562
614
  }
563
615
 
564
- var version = "1.16.7";
616
+ var version = "1.17.0";
565
617
  var license = "MIT";
566
618
  var name = "pkgbld";
567
619
  var author = "Konstantin Shutkin";
@@ -594,7 +646,7 @@ var scripts = {
594
646
  };
595
647
  var devDependencies = {
596
648
  "@types/lodash": "^4.14.192",
597
- "@types/minimist": "^1.2.2"
649
+ "@total-typescript/ts-reset": "^0.5.1"
598
650
  };
599
651
  var dependencies = {
600
652
  "@niceties/logger": "^1.1.10",
@@ -614,11 +666,11 @@ var dependencies = {
614
666
  "@slimlib/smart-mock": "^0.1.2",
615
667
  "is-builtin-module": "^3.2.1",
616
668
  terser: "^5.16.8",
617
- minimist: "^1.2.8",
618
- kleur: "^4.1.5"
669
+ kleur: "^4.1.5",
670
+ cleye: "^1.3.2"
619
671
  };
620
672
  var peerDependencies = {
621
- typescript: "^5.0.2"
673
+ typescript: "^5.2.2"
622
674
  };
623
675
  var pkgbldPkg = {
624
676
  version: version,
@@ -763,7 +815,7 @@ async function checkTsConfig(options, mainLogger, plugins) {
763
815
  }
764
816
  const originalConfig = cloneDeep(config);
765
817
  for (const plugin of plugins) {
766
- plugin.processTsConfig && plugin.processTsConfig(config);
818
+ plugin.processTsConfig?.(config);
767
819
  }
768
820
  if (!isEqual(originalConfig, config)) {
769
821
  needWrite = true;
@@ -784,13 +836,16 @@ function loadPlugins(pkg) {
784
836
  execute();
785
837
  async function execute() {
786
838
  const time = Date.now();
787
- logger.createLogger().update(' '); // blank line
788
839
  const mainLogger = logger.createLogger();
789
- mainLogger.update('preparing...');
840
+ mainLogger.update('preparing..');
790
841
  try {
791
842
  const [pkgPath, pkg] = await getJson('package.json');
792
843
  const plugins = await loadPlugins(pkg);
793
- const options = getCliOptions(plugins);
844
+ mainLogger.update('');
845
+ process.stdout.moveCursor?.(0, -1);
846
+ const options = getCliOptions(plugins, pkg);
847
+ process.stdout.moveCursor?.(0, 1);
848
+ mainLogger.update('preparing...');
794
849
  checkTsConfig(options, mainLogger, plugins);
795
850
  const inputs = processPackage(pkg, options, plugins);
796
851
  const helpers = getHelpers(pkg.name);
@@ -1,3 +1,2 @@
1
- import { getCliOptions } from '../get-cli-options';
2
- import { Provider } from '../types';
3
- export default function (provider: Provider, config: ReturnType<typeof getCliOptions>): Promise<void>;
1
+ import { CliOptions, Provider } from '../types';
2
+ export default function (provider: Provider, config: CliOptions): Promise<void>;
@@ -1,3 +1,2 @@
1
- import { getCliOptions } from '../get-cli-options';
2
- import { Provider } from '../types';
3
- export default function (provider: Provider, config: ReturnType<typeof getCliOptions>, inputs: string[]): Promise<void>;
1
+ import { CliOptions, Provider } from '../types';
2
+ export default function (provider: Provider, config: CliOptions, inputs: string[]): Promise<void>;
@@ -1,3 +1,2 @@
1
- import { getCliOptions } from '../get-cli-options';
2
- import { Provider } from '../types';
3
- export default function (provider: Provider, config: ReturnType<typeof getCliOptions>): Promise<void>;
1
+ import { CliOptions, Provider } from '../types';
2
+ export default function (provider: Provider, config: CliOptions): Promise<void>;
@@ -1,3 +1,2 @@
1
- import { getCliOptions } from '../get-cli-options';
2
- import { Provider } from '../types';
3
- export default function (provider: Provider, config: ReturnType<typeof getCliOptions>): Promise<void>;
1
+ import { CliOptions, Provider } from '../types';
2
+ export default function (provider: Provider, config: CliOptions): Promise<void>;
@@ -1,2 +1,2 @@
1
- import { getCliOptions } from './get-cli-options';
2
- export declare function createSubpackages(inputs: string[], config: ReturnType<typeof getCliOptions>): Promise<void>;
1
+ import { CliOptions } from './types';
2
+ export declare function createSubpackages(inputs: string[], config: CliOptions): Promise<void>;
@@ -1,6 +1,5 @@
1
- import type { PackageJson, PkgbldRollupPlugin, Provider } from './types';
1
+ import type { CliOptions, PackageJson, PkgbldRollupPlugin, Provider } from './types';
2
2
  import type { RollupOptions } from 'rollup';
3
- import { getCliOptions } from './get-cli-options';
4
3
  import { getHelpers } from './helpers';
5
4
  export declare function createEjectProvider(preimportMap: Map<string, Promise<never>>): Promise<[Provider, PkgbldRollupPlugin[]]>;
6
- export declare function ejectConfig(config: RollupOptions[], pkgPath: string, options: ReturnType<typeof getCliOptions>, inputs: string[], helpers: ReturnType<typeof getHelpers>, pkg: PackageJson): Promise<void>;
5
+ export declare function ejectConfig(config: RollupOptions[], pkgPath: string, options: CliOptions, inputs: string[], helpers: ReturnType<typeof getHelpers>, pkg: PackageJson): Promise<void>;
@@ -1,10 +1,10 @@
1
- import { PkgbldPlugin } from './types';
2
- export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[]): {
1
+ import { PackageJson, PkgbldPlugin } from './types';
2
+ export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: PackageJson): {
3
3
  umdInputs: string[];
4
4
  compressFormats: string[];
5
5
  sourcemapFormats: string[];
6
6
  formats: string[];
7
- formatsOverriden: boolean;
7
+ formatsOverridden: boolean;
8
8
  preprocess: string[];
9
9
  dir: string;
10
10
  sourceDir: string;
@@ -1,7 +1,6 @@
1
- import type { getCliOptions } from './get-cli-options';
2
1
  import type { getHelpers } from './helpers';
3
- import type { PkgbldPlugin, PkgbldRollupPlugin, Provider } from './types';
4
- export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldRollupPlugin[]], inputs: string[], config: ReturnType<typeof getCliOptions>, helpers: ReturnType<typeof getHelpers>, externalPlugins: Partial<PkgbldPlugin>[]): Promise<{
2
+ import type { CliOptions, PkgbldPlugin, PkgbldRollupPlugin, Provider } from './types';
3
+ export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldRollupPlugin[]], inputs: string[], config: CliOptions, helpers: ReturnType<typeof getHelpers>, externalPlugins: Partial<PkgbldPlugin>[]): Promise<{
5
4
  input: string[];
6
5
  output: {
7
6
  amd?: import("rollup").AmdOptions | undefined;
@@ -1,3 +1,2 @@
1
- import { getCliOptions } from './get-cli-options';
2
- import { Json, PkgbldPlugin } from './types';
3
- export declare function processPackage(pkg: Json, config: ReturnType<typeof getCliOptions>, plugins: Partial<PkgbldPlugin>[]): string[];
1
+ import { CliOptions, Json, PkgbldPlugin } from './types';
2
+ export declare function processPackage(pkg: Json, config: CliOptions, plugins: Partial<PkgbldPlugin>[]): string[];
@@ -1,4 +1,3 @@
1
1
  import { Logger } from '@niceties/logger';
2
- import { getCliOptions } from './get-cli-options';
3
- import { PkgbldPlugin } from './types';
4
- export declare function checkTsConfig(options: ReturnType<typeof getCliOptions>, mainLogger: Logger, plugins: Partial<PkgbldPlugin>[]): Promise<void>;
2
+ import { CliOptions, PkgbldPlugin } from './types';
3
+ export declare function checkTsConfig(options: CliOptions, mainLogger: Logger, plugins: Partial<PkgbldPlugin>[]): Promise<void>;
@@ -6,6 +6,7 @@ export type Json = null | string | number | boolean | Json[] | {
6
6
  };
7
7
  export type PackageJson = {
8
8
  name: string;
9
+ version: string;
9
10
  dependencies?: Record<string, string>;
10
11
  devDependencies?: Record<string, string>;
11
12
  peerDependencies: Record<string, string>;
@@ -38,13 +39,13 @@ export type PkgbldRollupPlugin = {
38
39
  inputs?: string[];
39
40
  outputPlugin?: true;
40
41
  };
42
+ export type CliOptions = NonNullable<ReturnType<typeof getCliOptions>>;
43
+ export type ParsedOptions = Record<string, string | number | string[] | number[] | boolean | undefined>;
41
44
  export interface PkgbldPlugin {
42
- options(parsedArgs: {
43
- [key: string]: string | number;
44
- }, options: ReturnType<typeof getCliOptions>): void;
45
+ options(parsedArgs: ParsedOptions, options: CliOptions): void;
45
46
  processPackageJson(packageJson: PackageJson, inputs: string[], logger: Logger): void;
46
47
  processTsConfig(config: Json): void;
47
- providePlugins(provider: Provider, config: Record<string, string | string[] | boolean>, inputs: string[]): Promise<void>;
48
+ providePlugins(provider: Provider, config: ParsedOptions, inputs: string[]): Promise<void>;
48
49
  getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
49
50
  buildEnd(): Promise<void>;
50
51
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.16.7",
2
+ "version": "1.17.0",
3
3
  "license": "MIT",
4
4
  "name": "pkgbld",
5
5
  "author": "Konstantin Shutkin",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "devDependencies": {
30
30
  "@types/lodash": "^4.14.192",
31
- "@types/minimist": "^1.2.2"
31
+ "@total-typescript/ts-reset": "^0.5.1"
32
32
  },
33
33
  "dependencies": {
34
34
  "@niceties/logger": "^1.1.10",
@@ -48,11 +48,11 @@
48
48
  "@slimlib/smart-mock": "^0.1.2",
49
49
  "is-builtin-module": "^3.2.1",
50
50
  "terser": "^5.16.8",
51
- "minimist": "^1.2.8",
52
- "kleur": "^4.1.5"
51
+ "kleur": "^4.1.5",
52
+ "cleye": "^1.3.2"
53
53
  },
54
54
  "peerDependencies": {
55
- "typescript": "^5.0.2"
55
+ "typescript": "^5.2.2"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "rollup -c",