pkgbld 1.12.0 → 1.14.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 +43 -1
- package/dist/builtin-plugins/binify.d.ts +3 -0
- package/dist/get-cli-options.d.ts +3 -0
- package/dist/index.js +74 -21
- package/dist/types.d.ts +8 -7
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ It is simple building tool that supports building to different targets like: `es
|
|
|
6
6
|
|
|
7
7
|
## Why
|
|
8
8
|
|
|
9
|
-
It is created to easily build libraries that contains mutliple
|
|
9
|
+
It is created to easily build libraries that contains mutliple subpath exports (entry points, subpackages) because it is not that easy to do at the moment with `microbundle`, `tsdx` or `ng-packagr` (if you are on Typescript).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
@@ -15,6 +15,32 @@ Using npm:
|
|
|
15
15
|
npm install --save-dev pkgbld
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
### Getting started (minimalistic start from scratch)
|
|
19
|
+
|
|
20
|
+
1. Start from creating pcakage.json using `npm init`
|
|
21
|
+
2. Add pkgbld `npm install --save-dev pkgbld`
|
|
22
|
+
3. Add `tsconfig.json` file into root project directory
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"compilerOptions": {
|
|
26
|
+
"target": "esnext",
|
|
27
|
+
"module": "esnext",
|
|
28
|
+
"esModuleInterop": true,
|
|
29
|
+
"strict": true,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
4. Create `src/index.ts`
|
|
35
|
+
5. Add pkgbld in scripts field of your package.json like:
|
|
36
|
+
```json
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "pkgbld"
|
|
39
|
+
},
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run `npm run build`.
|
|
43
|
+
|
|
18
44
|
## package.json
|
|
19
45
|
|
|
20
46
|
`pkgbld` expects name field to be filled in the package.json file. `exports` field defines what entries/outputs should be build for this package.
|
|
@@ -81,6 +107,22 @@ pkgbld --sourcedir=src
|
|
|
81
107
|
|
|
82
108
|
Directory to search for input files.
|
|
83
109
|
|
|
110
|
+
### bin
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
pkgbld --bin=./dist/index.cjs,./dist/index.mjs
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
File(s) to make executable. First entry will be added to package.json
|
|
117
|
+
|
|
118
|
+
### include-externals
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
pkgbld --include-externals
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Bundles all externals into package.
|
|
125
|
+
|
|
84
126
|
# License
|
|
85
127
|
|
|
86
128
|
[MIT](./LICENSE)
|
|
@@ -3,7 +3,10 @@ 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;
|
|
11
|
+
includeExternals: boolean;
|
|
9
12
|
};
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,11 @@ const defaults = {
|
|
|
33
33
|
sourcemapFormats: ['umd'],
|
|
34
34
|
preprocess: [],
|
|
35
35
|
dir: 'dist',
|
|
36
|
-
sourceDir: 'src'
|
|
36
|
+
sourceDir: 'src',
|
|
37
|
+
includeExternals: false
|
|
37
38
|
};
|
|
38
39
|
function getCliOptions() {
|
|
39
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
40
41
|
const parsedArgs = minimist(process.argv.slice(2));
|
|
41
42
|
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
43
|
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 +46,19 @@ function getCliOptions() {
|
|
|
45
46
|
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
47
|
const dir = (_l = parsedArgs.dir) !== null && _l !== void 0 ? _l : defaults.dir;
|
|
47
48
|
const sourceDir = (_m = parsedArgs.sourceDir) !== null && _m !== void 0 ? _m : defaults.sourceDir;
|
|
49
|
+
const bin = (_o = parsedArgs.bin) === null || _o === void 0 ? void 0 : _o.split(',').map((arg) => arg.trim());
|
|
50
|
+
const includeExternals = (_p = parsedArgs['include-externals']) !== null && _p !== void 0 ? _p : defaults.includeExternals;
|
|
48
51
|
return {
|
|
49
52
|
umdInputs,
|
|
50
53
|
compressFormats,
|
|
51
54
|
sourcemapFormats,
|
|
52
55
|
formats,
|
|
56
|
+
formatsOverriden: 'formats' in parsedArgs,
|
|
53
57
|
preprocess,
|
|
54
58
|
dir,
|
|
55
|
-
sourceDir
|
|
59
|
+
sourceDir,
|
|
60
|
+
bin,
|
|
61
|
+
includeExternals
|
|
56
62
|
};
|
|
57
63
|
}
|
|
58
64
|
|
|
@@ -65,7 +71,7 @@ async function getPackage() {
|
|
|
65
71
|
async function clean (provide) {
|
|
66
72
|
const { default: pluginClean } = await import('@rollup-extras/plugin-clean');
|
|
67
73
|
const pluginInstance = pluginClean();
|
|
68
|
-
provide(pluginFactory,
|
|
74
|
+
provide(pluginFactory, 1000 /* Priotiry.cleanup */, { outputPlugin: true });
|
|
69
75
|
let firstPluginInstance = true;
|
|
70
76
|
function pluginFactory() {
|
|
71
77
|
const result = firstPluginInstance ? pluginInstance : pluginInstance.api.addInstance();
|
|
@@ -76,21 +82,24 @@ async function clean (provide) {
|
|
|
76
82
|
|
|
77
83
|
async function commonjs (provide) {
|
|
78
84
|
const { default: pluginCommonjs } = await import('@rollup/plugin-commonjs');
|
|
79
|
-
provide(() => pluginCommonjs(),
|
|
85
|
+
provide(() => pluginCommonjs(), 4000 /* Priotiry.commonjs */);
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
async function externals (provide, config, inputs) {
|
|
89
|
+
if (config.includeExternals) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
83
92
|
const { default: pluginExternals } = await import('@rollup-extras/plugin-externals');
|
|
84
93
|
const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
|
|
85
94
|
if (config.formats.length > 0) {
|
|
86
95
|
const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
|
|
87
|
-
provide(() => pluginExternals(),
|
|
96
|
+
provide(() => pluginExternals(), 2000 /* Priotiry.externals */, { format });
|
|
88
97
|
}
|
|
89
98
|
if (!allowGenericUmd && config.umdInputs.length > 0) {
|
|
90
99
|
for (const currentInput of config.umdInputs) {
|
|
91
100
|
provide(() => pluginExternals({
|
|
92
101
|
external: (id, external) => external || isExternalInput(currentInput, inputs, id, config)
|
|
93
|
-
}),
|
|
102
|
+
}), 2000 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
105
|
}
|
|
@@ -114,11 +123,11 @@ async function preprocess (provide, config) {
|
|
|
114
123
|
const include = config.preprocess.map(name => `${config.sourceDir}/${name}.ts`);
|
|
115
124
|
for (const format of config.formats) {
|
|
116
125
|
if (format !== 'umd') {
|
|
117
|
-
provide(() => pluginPreprocess({ include, context: { [format]: true } }),
|
|
126
|
+
provide(() => pluginPreprocess({ include, context: { [format]: true } }), 1000 /* Priotiry.preprocess */, { format });
|
|
118
127
|
}
|
|
119
128
|
else {
|
|
120
129
|
for (const currentInput of config.umdInputs) {
|
|
121
|
-
provide(() => pluginPreprocess({ include, context: { umd: true } }),
|
|
130
|
+
provide(() => pluginPreprocess({ include, context: { umd: true } }), 1000 /* Priotiry.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
122
131
|
}
|
|
123
132
|
}
|
|
124
133
|
}
|
|
@@ -127,7 +136,7 @@ async function preprocess (provide, config) {
|
|
|
127
136
|
|
|
128
137
|
async function resolve (provide) {
|
|
129
138
|
const { default: pluginResolve } = await import('@rollup/plugin-node-resolve');
|
|
130
|
-
provide(() => pluginResolve(),
|
|
139
|
+
provide(() => pluginResolve(), 3000 /* Priotiry.resolve */);
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
async function terser (provide, config) {
|
|
@@ -158,7 +167,21 @@ async function terser (provide, config) {
|
|
|
158
167
|
|
|
159
168
|
async function typescript (provide) {
|
|
160
169
|
const { default: pluginTypescript } = await import('rollup-plugin-typescript2');
|
|
161
|
-
provide(() => pluginTypescript(),
|
|
170
|
+
provide(() => pluginTypescript(), 6000 /* Priotiry.transpile */);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function binify (provide, config) {
|
|
174
|
+
var _a;
|
|
175
|
+
if (config.bin != null) {
|
|
176
|
+
const { default: pluginBinify } = await import('@rollup-extras/plugin-binify');
|
|
177
|
+
const format = (_a = {
|
|
178
|
+
'cjs': 'cjs',
|
|
179
|
+
'mjs': 'es'
|
|
180
|
+
}[path.extname(config.bin[0])]) !== null && _a !== void 0 ? _a : 'cjs';
|
|
181
|
+
provide(() => pluginBinify({
|
|
182
|
+
filter: (item) => item.type === 'chunk' && item.isEntry && config.bin.some(input => input === `./${config.dir}/${item.fileName}`)
|
|
183
|
+
}), 20000 /* Priotiry.finalize */, { outputPlugin: true, format });
|
|
184
|
+
}
|
|
162
185
|
}
|
|
163
186
|
|
|
164
187
|
const plugins = [
|
|
@@ -168,7 +191,8 @@ const plugins = [
|
|
|
168
191
|
preprocess,
|
|
169
192
|
resolve,
|
|
170
193
|
terser,
|
|
171
|
-
typescript
|
|
194
|
+
typescript,
|
|
195
|
+
binify
|
|
172
196
|
];
|
|
173
197
|
function createProvider() {
|
|
174
198
|
const plugins = [];
|
|
@@ -383,6 +407,9 @@ function processPackage(pkg, config) {
|
|
|
383
407
|
var _a;
|
|
384
408
|
const input = [];
|
|
385
409
|
const logger$1 = logger.createLogger();
|
|
410
|
+
const allowEsm = (config.formatsOverriden && config.formats.includes('es') || !config.formatsOverriden);
|
|
411
|
+
const allowCjs = (config.formatsOverriden && config.formats.includes('cjs') || !config.formatsOverriden);
|
|
412
|
+
const allowUmd = (config.formatsOverriden && config.formats.includes('umd') || !config.formatsOverriden || config.umdInputs);
|
|
386
413
|
if (typeof pkg !== 'object' || Array.isArray(pkg)) {
|
|
387
414
|
logger$1.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
|
|
388
415
|
process.exit(-1);
|
|
@@ -404,25 +431,47 @@ function processPackage(pkg, config) {
|
|
|
404
431
|
pkg.exports['.'] = {};
|
|
405
432
|
}
|
|
406
433
|
pkg.exports['./package.json'] = './package.json';
|
|
407
|
-
if (typeof pkg.umd === 'string') {
|
|
434
|
+
if (allowUmd && typeof pkg.umd === 'string') {
|
|
408
435
|
pkg.umd = `./${config.dir}/index.umd.js`;
|
|
409
436
|
if (!config.umdInputs.includes('index')) {
|
|
410
437
|
config.umdInputs.push('index');
|
|
411
438
|
}
|
|
412
439
|
}
|
|
413
|
-
if (
|
|
440
|
+
if (config.bin) {
|
|
441
|
+
if (config.bin.length > 0) {
|
|
442
|
+
if (config.bin[0] === '') {
|
|
443
|
+
delete pkg.bin;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
pkg.bin = config.bin[0];
|
|
447
|
+
}
|
|
448
|
+
config.bin = config.bin.filter(Boolean);
|
|
449
|
+
if (config.bin.length === 0) {
|
|
450
|
+
delete config.bin;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
if (typeof pkg.bin === 'string') {
|
|
456
|
+
config.bin = [pkg.bin];
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
delete pkg.bin;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (allowCjs && typeof pkg.main !== 'string') {
|
|
414
463
|
pkg.main = `./${config.dir}/index.cjs`;
|
|
415
464
|
}
|
|
416
|
-
if (pkg.main !== pkg.exports['.'].require) {
|
|
465
|
+
if (allowCjs && pkg.main !== pkg.exports['.'].require) {
|
|
417
466
|
pkg.exports['.'].require = pkg.main;
|
|
418
467
|
}
|
|
419
|
-
if (typeof pkg.module !== 'string') {
|
|
468
|
+
if (allowEsm && typeof pkg.module !== 'string') {
|
|
420
469
|
pkg.module = `./${config.dir}/index.mjs`;
|
|
421
470
|
}
|
|
422
|
-
if (pkg.module !== ((_a = pkg.exports['.']) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
471
|
+
if (allowEsm && pkg.module !== ((_a = pkg.exports['.']) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
423
472
|
pkg.exports['.'].default = pkg.module;
|
|
424
473
|
}
|
|
425
|
-
if (config.umdInputs.includes('index')) {
|
|
474
|
+
if (allowUmd && config.umdInputs.includes('index')) {
|
|
426
475
|
pkg.unpkg = `./${config.dir}/index.umd.js`;
|
|
427
476
|
}
|
|
428
477
|
for (const id in pkg.exports) {
|
|
@@ -432,8 +481,12 @@ function processPackage(pkg, config) {
|
|
|
432
481
|
if (typeof pkg.exports[id] !== 'object') {
|
|
433
482
|
pkg.exports[id] = {};
|
|
434
483
|
}
|
|
435
|
-
|
|
436
|
-
|
|
484
|
+
if (allowCjs) {
|
|
485
|
+
pkg.exports[id].require = `./${config.dir}/${basename}.cjs`;
|
|
486
|
+
}
|
|
487
|
+
if (allowEsm) {
|
|
488
|
+
pkg.exports[id].default = `./${config.dir}/${basename}.mjs`;
|
|
489
|
+
}
|
|
437
490
|
if (basename !== 'index') {
|
|
438
491
|
if (!pkg.files.includes(basename)) {
|
|
439
492
|
pkg.files.push(basename);
|
|
@@ -441,7 +494,7 @@ function processPackage(pkg, config) {
|
|
|
441
494
|
}
|
|
442
495
|
input.push(`./${config.sourceDir}/${basename}.ts`);
|
|
443
496
|
}
|
|
444
|
-
if (config.umdInputs.length > 0 && !config.formats.includes('umd')) {
|
|
497
|
+
if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
|
|
445
498
|
config.formats.push('umd');
|
|
446
499
|
}
|
|
447
500
|
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 =
|
|
12
|
-
cleanup =
|
|
13
|
-
externals =
|
|
14
|
-
resolve =
|
|
15
|
-
commonjs =
|
|
16
|
-
transpile =
|
|
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.
|
|
2
|
+
"version": "1.14.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",
|