pkgbld 1.16.7 → 1.17.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 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,9 +613,9 @@ 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";
565
- var license = "MIT";
616
+ var version = "1.17.1";
566
617
  var name = "pkgbld";
618
+ var license = "MIT";
567
619
  var author = "Konstantin Shutkin";
568
620
  var bin = "./dist/index.js";
569
621
  var main = "./dist/index.js";
@@ -576,12 +628,12 @@ var engines = {
576
628
  };
577
629
  var repository = {
578
630
  type: "git",
579
- url: "git+https://github.com/kshutkin/package-build.git"
580
- };
581
- var bugs = {
582
- url: "https://github.com/kshutkin/rollup-extras/issues"
631
+ url: "git+https://github.com/kshutkin/package-build.git",
632
+ directory: "pkgbld"
583
633
  };
634
+ var bugs = "https://github.com/kshutkin/package-build/issues";
584
635
  var homepage = "https://github.com/kshutkin/package-build/blob/main/pkgbld/README.md";
636
+ var readme = "README.md";
585
637
  var keywords = [
586
638
  "pkgbld",
587
639
  "build",
@@ -592,10 +644,6 @@ var scripts = {
592
644
  build: "rollup -c",
593
645
  lint: "eslint ./src"
594
646
  };
595
- var devDependencies = {
596
- "@types/lodash": "^4.14.192",
597
- "@types/minimist": "^1.2.2"
598
- };
599
647
  var dependencies = {
600
648
  "@niceties/logger": "^1.1.10",
601
649
  "@niceties/draftlog-appender": "^1.3.0",
@@ -614,16 +662,20 @@ var dependencies = {
614
662
  "@slimlib/smart-mock": "^0.1.2",
615
663
  "is-builtin-module": "^3.2.1",
616
664
  terser: "^5.16.8",
617
- minimist: "^1.2.8",
618
- kleur: "^4.1.5"
665
+ kleur: "^4.1.5",
666
+ cleye: "^1.3.2"
667
+ };
668
+ var devDependencies = {
669
+ "@types/lodash": "^4.14.192",
670
+ "@total-typescript/ts-reset": "^0.5.1"
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,
625
- license: license,
626
677
  name: name,
678
+ license: license,
627
679
  author: author,
628
680
  bin: bin,
629
681
  main: main,
@@ -633,10 +685,11 @@ var pkgbldPkg = {
633
685
  repository: repository,
634
686
  bugs: bugs,
635
687
  homepage: homepage,
688
+ readme: readme,
636
689
  keywords: keywords,
637
690
  scripts: scripts,
638
- devDependencies: devDependencies,
639
691
  dependencies: dependencies,
692
+ devDependencies: devDependencies,
640
693
  peerDependencies: peerDependencies
641
694
  };
642
695
 
@@ -763,7 +816,7 @@ async function checkTsConfig(options, mainLogger, plugins) {
763
816
  }
764
817
  const originalConfig = cloneDeep(config);
765
818
  for (const plugin of plugins) {
766
- plugin.processTsConfig && plugin.processTsConfig(config);
819
+ plugin.processTsConfig?.(config);
767
820
  }
768
821
  if (!isEqual(originalConfig, config)) {
769
822
  needWrite = true;
@@ -784,13 +837,16 @@ function loadPlugins(pkg) {
784
837
  execute();
785
838
  async function execute() {
786
839
  const time = Date.now();
787
- logger.createLogger().update(' '); // blank line
788
840
  const mainLogger = logger.createLogger();
789
- mainLogger.update('preparing...');
841
+ mainLogger.update('preparing..');
790
842
  try {
791
843
  const [pkgPath, pkg] = await getJson('package.json');
792
844
  const plugins = await loadPlugins(pkg);
793
- const options = getCliOptions(plugins);
845
+ mainLogger.update('');
846
+ process.stdout.moveCursor?.(0, -1);
847
+ const options = getCliOptions(plugins, pkg);
848
+ process.stdout.moveCursor?.(0, 1);
849
+ mainLogger.update('preparing...');
794
850
  checkTsConfig(options, mainLogger, plugins);
795
851
  const inputs = processPackage(pkg, options, plugins);
796
852
  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,7 +1,7 @@
1
1
  {
2
- "version": "1.16.7",
3
- "license": "MIT",
2
+ "version": "1.17.1",
4
3
  "name": "pkgbld",
4
+ "license": "MIT",
5
5
  "author": "Konstantin Shutkin",
6
6
  "bin": "./dist/index.js",
7
7
  "main": "./dist/index.js",
@@ -14,22 +14,18 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/kshutkin/package-build.git"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/kshutkin/rollup-extras/issues"
17
+ "url": "git+https://github.com/kshutkin/package-build.git",
18
+ "directory": "pkgbld"
21
19
  },
20
+ "bugs": "https://github.com/kshutkin/package-build/issues",
22
21
  "homepage": "https://github.com/kshutkin/package-build/blob/main/pkgbld/README.md",
22
+ "readme": "README.md",
23
23
  "keywords": [
24
24
  "pkgbld",
25
25
  "build",
26
26
  "exports",
27
27
  "rollup"
28
28
  ],
29
- "devDependencies": {
30
- "@types/lodash": "^4.14.192",
31
- "@types/minimist": "^1.2.2"
32
- },
33
29
  "dependencies": {
34
30
  "@niceties/logger": "^1.1.10",
35
31
  "@niceties/draftlog-appender": "^1.3.0",
@@ -48,11 +44,15 @@
48
44
  "@slimlib/smart-mock": "^0.1.2",
49
45
  "is-builtin-module": "^3.2.1",
50
46
  "terser": "^5.16.8",
51
- "minimist": "^1.2.8",
52
- "kleur": "^4.1.5"
47
+ "kleur": "^4.1.5",
48
+ "cleye": "^1.3.2"
49
+ },
50
+ "devDependencies": {
51
+ "@types/lodash": "^4.14.192",
52
+ "@total-typescript/ts-reset": "^0.5.1"
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",