pkgbld 1.12.0 → 1.13.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
@@ -81,6 +81,14 @@ pkgbld --sourcedir=src
81
81
 
82
82
  Directory to search for input files.
83
83
 
84
+ ### bin
85
+
86
+ ```
87
+ pkgbld --bin=./dist/index.cjs,./dist/index.mjs
88
+ ```
89
+
90
+ File(s) to make executable. First entry will be added to package.json
91
+
84
92
  # License
85
93
 
86
94
  [MIT](./LICENSE)
@@ -0,0 +1,3 @@
1
+ import { getCliOptions } from '../get-cli-options';
2
+ import { Provider } from '../types';
3
+ export default function (provide: Provider, config: ReturnType<typeof getCliOptions>): Promise<void>;
@@ -3,7 +3,9 @@ export declare function getCliOptions(): {
3
3
  compressFormats: string[];
4
4
  sourcemapFormats: string[];
5
5
  formats: string[];
6
+ formatsOverriden: boolean;
6
7
  preprocess: string[];
7
8
  dir: string;
8
9
  sourceDir: string;
10
+ bin?: string[] | undefined;
9
11
  };
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ const defaults = {
36
36
  sourceDir: 'src'
37
37
  };
38
38
  function getCliOptions() {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
40
40
  const parsedArgs = minimist(process.argv.slice(2));
41
41
  const umdInputs = (_b = (_a = parsedArgs.umd) === null || _a === void 0 ? void 0 : _a.split(',').map((arg) => arg.trim())) !== null && _b !== void 0 ? _b : defaults.umdInputs;
42
42
  const compressFormats = (_d = (_c = parsedArgs.compress) === null || _c === void 0 ? void 0 : _c.split(',').map((arg) => arg.trim())) !== null && _d !== void 0 ? _d : defaults.compressFormats;
@@ -45,14 +45,17 @@ function getCliOptions() {
45
45
  const preprocess = (_k = (_j = parsedArgs.preprocess) === null || _j === void 0 ? void 0 : _j.split(',').map((arg) => arg.trim())) !== null && _k !== void 0 ? _k : defaults.preprocess;
46
46
  const dir = (_l = parsedArgs.dir) !== null && _l !== void 0 ? _l : defaults.dir;
47
47
  const sourceDir = (_m = parsedArgs.sourceDir) !== null && _m !== void 0 ? _m : defaults.sourceDir;
48
+ const bin = (_o = parsedArgs.bin) === null || _o === void 0 ? void 0 : _o.split(',').map((arg) => arg.trim());
48
49
  return {
49
50
  umdInputs,
50
51
  compressFormats,
51
52
  sourcemapFormats,
52
53
  formats,
54
+ formatsOverriden: 'formats' in parsedArgs,
53
55
  preprocess,
54
56
  dir,
55
- sourceDir
57
+ sourceDir,
58
+ bin
56
59
  };
57
60
  }
58
61
 
@@ -65,7 +68,7 @@ async function getPackage() {
65
68
  async function clean (provide) {
66
69
  const { default: pluginClean } = await import('@rollup-extras/plugin-clean');
67
70
  const pluginInstance = pluginClean();
68
- provide(pluginFactory, 100 /* Priotiry.cleanup */, { outputPlugin: true });
71
+ provide(pluginFactory, 1000 /* Priotiry.cleanup */, { outputPlugin: true });
69
72
  let firstPluginInstance = true;
70
73
  function pluginFactory() {
71
74
  const result = firstPluginInstance ? pluginInstance : pluginInstance.api.addInstance();
@@ -76,7 +79,7 @@ async function clean (provide) {
76
79
 
77
80
  async function commonjs (provide) {
78
81
  const { default: pluginCommonjs } = await import('@rollup/plugin-commonjs');
79
- provide(() => pluginCommonjs(), 400 /* Priotiry.commonjs */);
82
+ provide(() => pluginCommonjs(), 4000 /* Priotiry.commonjs */);
80
83
  }
81
84
 
82
85
  async function externals (provide, config, inputs) {
@@ -84,13 +87,13 @@ async function externals (provide, config, inputs) {
84
87
  const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
85
88
  if (config.formats.length > 0) {
86
89
  const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
87
- provide(() => pluginExternals(), 200 /* Priotiry.externals */, { format });
90
+ provide(() => pluginExternals(), 2000 /* Priotiry.externals */, { format });
88
91
  }
89
92
  if (!allowGenericUmd && config.umdInputs.length > 0) {
90
93
  for (const currentInput of config.umdInputs) {
91
94
  provide(() => pluginExternals({
92
95
  external: (id, external) => external || isExternalInput(currentInput, inputs, id, config)
93
- }), 200 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
96
+ }), 2000 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
94
97
  }
95
98
  }
96
99
  }
@@ -114,11 +117,11 @@ async function preprocess (provide, config) {
114
117
  const include = config.preprocess.map(name => `${config.sourceDir}/${name}.ts`);
115
118
  for (const format of config.formats) {
116
119
  if (format !== 'umd') {
117
- provide(() => pluginPreprocess({ include, context: { [format]: true } }), 100 /* Priotiry.preprocess */, { format });
120
+ provide(() => pluginPreprocess({ include, context: { [format]: true } }), 1000 /* Priotiry.preprocess */, { format });
118
121
  }
119
122
  else {
120
123
  for (const currentInput of config.umdInputs) {
121
- provide(() => pluginPreprocess({ include, context: { umd: true } }), 100 /* Priotiry.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
124
+ provide(() => pluginPreprocess({ include, context: { umd: true } }), 1000 /* Priotiry.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
122
125
  }
123
126
  }
124
127
  }
@@ -127,7 +130,7 @@ async function preprocess (provide, config) {
127
130
 
128
131
  async function resolve (provide) {
129
132
  const { default: pluginResolve } = await import('@rollup/plugin-node-resolve');
130
- provide(() => pluginResolve(), 300 /* Priotiry.resolve */);
133
+ provide(() => pluginResolve(), 3000 /* Priotiry.resolve */);
131
134
  }
132
135
 
133
136
  async function terser (provide, config) {
@@ -158,7 +161,21 @@ async function terser (provide, config) {
158
161
 
159
162
  async function typescript (provide) {
160
163
  const { default: pluginTypescript } = await import('rollup-plugin-typescript2');
161
- provide(() => pluginTypescript(), 600 /* Priotiry.transpile */);
164
+ provide(() => pluginTypescript(), 6000 /* Priotiry.transpile */);
165
+ }
166
+
167
+ async function binify (provide, config) {
168
+ var _a;
169
+ if (config.bin != null) {
170
+ const { default: pluginBinify } = await import('@rollup-extras/plugin-binify');
171
+ const format = (_a = {
172
+ 'cjs': 'cjs',
173
+ 'mjs': 'es'
174
+ }[path.extname(config.bin[0])]) !== null && _a !== void 0 ? _a : 'cjs';
175
+ provide(() => pluginBinify({
176
+ filter: (item) => item.type === 'chunk' && item.isEntry && config.bin.some(input => input === `./${config.dir}/${item.fileName}`)
177
+ }), 20000 /* Priotiry.finalize */, { outputPlugin: true, format });
178
+ }
162
179
  }
163
180
 
164
181
  const plugins = [
@@ -168,7 +185,8 @@ const plugins = [
168
185
  preprocess,
169
186
  resolve,
170
187
  terser,
171
- typescript
188
+ typescript,
189
+ binify
172
190
  ];
173
191
  function createProvider() {
174
192
  const plugins = [];
@@ -383,6 +401,9 @@ function processPackage(pkg, config) {
383
401
  var _a;
384
402
  const input = [];
385
403
  const logger$1 = logger.createLogger();
404
+ const allowEsm = (config.formatsOverriden && config.formats.includes('es') || !config.formatsOverriden);
405
+ const allowCjs = (config.formatsOverriden && config.formats.includes('cjs') || !config.formatsOverriden);
406
+ const allowUmd = (config.formatsOverriden && config.formats.includes('umd') || !config.formatsOverriden || config.umdInputs);
386
407
  if (typeof pkg !== 'object' || Array.isArray(pkg)) {
387
408
  logger$1.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
388
409
  process.exit(-1);
@@ -404,25 +425,47 @@ function processPackage(pkg, config) {
404
425
  pkg.exports['.'] = {};
405
426
  }
406
427
  pkg.exports['./package.json'] = './package.json';
407
- if (typeof pkg.umd === 'string') {
428
+ if (allowUmd && typeof pkg.umd === 'string') {
408
429
  pkg.umd = `./${config.dir}/index.umd.js`;
409
430
  if (!config.umdInputs.includes('index')) {
410
431
  config.umdInputs.push('index');
411
432
  }
412
433
  }
413
- if (typeof pkg.main !== 'string') {
434
+ if (config.bin) {
435
+ if (config.bin.length > 0) {
436
+ if (config.bin[0] === '') {
437
+ delete pkg.bin;
438
+ }
439
+ else {
440
+ pkg.bin = config.bin[0];
441
+ }
442
+ config.bin = config.bin.filter(Boolean);
443
+ if (config.bin.length === 0) {
444
+ delete config.bin;
445
+ }
446
+ }
447
+ }
448
+ else {
449
+ if (typeof pkg.bin === 'string') {
450
+ config.bin = [pkg.bin];
451
+ }
452
+ else {
453
+ delete pkg.bin;
454
+ }
455
+ }
456
+ if (allowCjs && typeof pkg.main !== 'string') {
414
457
  pkg.main = `./${config.dir}/index.cjs`;
415
458
  }
416
- if (pkg.main !== pkg.exports['.'].require) {
459
+ if (allowCjs && pkg.main !== pkg.exports['.'].require) {
417
460
  pkg.exports['.'].require = pkg.main;
418
461
  }
419
- if (typeof pkg.module !== 'string') {
462
+ if (allowEsm && typeof pkg.module !== 'string') {
420
463
  pkg.module = `./${config.dir}/index.mjs`;
421
464
  }
422
- if (pkg.module !== ((_a = pkg.exports['.']) === null || _a === void 0 ? void 0 : _a.default)) {
465
+ if (allowEsm && pkg.module !== ((_a = pkg.exports['.']) === null || _a === void 0 ? void 0 : _a.default)) {
423
466
  pkg.exports['.'].default = pkg.module;
424
467
  }
425
- if (config.umdInputs.includes('index')) {
468
+ if (allowUmd && config.umdInputs.includes('index')) {
426
469
  pkg.unpkg = `./${config.dir}/index.umd.js`;
427
470
  }
428
471
  for (const id in pkg.exports) {
@@ -432,8 +475,12 @@ function processPackage(pkg, config) {
432
475
  if (typeof pkg.exports[id] !== 'object') {
433
476
  pkg.exports[id] = {};
434
477
  }
435
- pkg.exports[id].require = `./${config.dir}/${basename}.cjs`;
436
- pkg.exports[id].default = `./${config.dir}/${basename}.mjs`;
478
+ if (allowCjs) {
479
+ pkg.exports[id].require = `./${config.dir}/${basename}.cjs`;
480
+ }
481
+ if (allowEsm) {
482
+ pkg.exports[id].default = `./${config.dir}/${basename}.mjs`;
483
+ }
437
484
  if (basename !== 'index') {
438
485
  if (!pkg.files.includes(basename)) {
439
486
  pkg.files.push(basename);
@@ -441,7 +488,7 @@ function processPackage(pkg, config) {
441
488
  }
442
489
  input.push(`./${config.sourceDir}/${basename}.ts`);
443
490
  }
444
- if (config.umdInputs.length > 0 && !config.formats.includes('umd')) {
491
+ if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
445
492
  config.formats.push('umd');
446
493
  }
447
494
  return input;
package/dist/types.d.ts CHANGED
@@ -8,13 +8,14 @@ export type Json = null | string | number | boolean | Json[] | {
8
8
  [name: string]: Json;
9
9
  };
10
10
  export declare const enum Priotiry {
11
- preprocess = 100,
12
- cleanup = 100,
13
- externals = 200,
14
- resolve = 300,
15
- commonjs = 400,
16
- transpile = 600,
17
- compress = 10000
11
+ preprocess = 1000,
12
+ cleanup = 1000,
13
+ externals = 2000,
14
+ resolve = 3000,
15
+ commonjs = 4000,
16
+ transpile = 6000,
17
+ compress = 10000,
18
+ finalize = 20000
18
19
  }
19
20
  export type Provider = (factory: () => Plugin, priority: Priotiry, options?: {
20
21
  format?: InternalModuleFormat | InternalModuleFormat[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.12.0",
2
+ "version": "1.13.0",
3
3
  "license": "MIT",
4
4
  "name": "pkgbld",
5
5
  "author": {
@@ -9,7 +9,8 @@
9
9
  "main": "./dist/index.js",
10
10
  "typings": "./dist/index.d.ts",
11
11
  "files": [
12
- "dist"
12
+ "dist",
13
+ "LICENSE"
13
14
  ],
14
15
  "engines": {
15
16
  "node": ">=16"
@@ -45,7 +46,6 @@
45
46
  "conventional-changelog-angular": "5.0.13",
46
47
  "eslint": "8.33.0",
47
48
  "semantic-release": "19.0.5",
48
- "@rollup-extras/plugin-binify": "1.1.5",
49
49
  "@types/node": "18.11.18"
50
50
  },
51
51
  "dependencies": {
@@ -59,6 +59,7 @@
59
59
  "@rollup/plugin-terser": "0.4.0",
60
60
  "@rollup/plugin-node-resolve": "15.0.1",
61
61
  "@rollup-extras/plugin-clean": "1.3.4",
62
+ "@rollup-extras/plugin-binify": "1.1.5",
62
63
  "@rollup-extras/plugin-externals": "1.1.7",
63
64
  "@slimlib/refine-partition": "1.0.0",
64
65
  "typescript": "4.9.4",