pkgbld 1.15.7 → 1.16.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 +23 -6
- package/dist/index.js +78 -30
- package/dist/src/get-cli-options.d.ts +2 -1
- package/dist/src/get-json.d.ts +2 -0
- package/dist/src/get-rollup-configs.d.ts +2 -2
- package/dist/src/load-plugins.d.ts +2 -0
- package/dist/src/process-pkg.d.ts +2 -2
- package/dist/src/{check-ts-config.d.ts → process-ts-config.d.ts} +2 -1
- package/dist/src/types.d.ts +13 -6
- package/package.json +4 -2
- package/dist/src/get-pkg.d.ts +0 -2
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
Rollup based build tool for building libraries based on package.json config and simple CLI options.
|
|
6
6
|
|
|
7
|
-
It is simple building tool that supports building to different targets like: `es`, `cjs`, `umd` without additional
|
|
7
|
+
It is a simple building tool that supports building to different targets like: `es`, `cjs`, `umd` without additional transformation other than minification using `terser` or preprocess using `rollup-plugin-preprocess`.
|
|
8
8
|
|
|
9
|
-
[
|
|
9
|
+
[Changelog](./CHANGELOG.md)
|
|
10
10
|
|
|
11
11
|
## Why
|
|
12
12
|
|
|
13
|
-
It is created to easily build libraries that contains
|
|
13
|
+
It is created to easily build libraries that contains multiple 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).
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -36,7 +36,7 @@ Run `npm run build`.
|
|
|
36
36
|
|
|
37
37
|
## package.json
|
|
38
38
|
|
|
39
|
-
`pkgbld` expects name field to be filled in the package.json file. `exports` field defines what entries/outputs should be
|
|
39
|
+
`pkgbld` expects the name field to be filled in the package.json file. `exports` field defines what entries/outputs should be built for this package.
|
|
40
40
|
|
|
41
41
|
## CLI options
|
|
42
42
|
|
|
@@ -82,7 +82,7 @@ Defines what formats to build, only supports `es` and `cjs` at the moment. Use `
|
|
|
82
82
|
pkgbld --preprocess=index
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
Defines what entry points/files should be preprocessed using `rollup-plugin-preprocess`.
|
|
85
|
+
Defines what entry points/files should be preprocessed using `rollup-plugin-preprocess`. The entry point will be defined as variable es (for esm target), cjs (for commonjs) and umd (for umd) depending on the target type. Please request more variables / more granular logic if you want more.
|
|
86
86
|
|
|
87
87
|
### dir
|
|
88
88
|
|
|
@@ -114,7 +114,7 @@ File(s) to make executable. First entry will be added to package.json
|
|
|
114
114
|
pkgbld --include-externals
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
Bundles all externals into package.
|
|
117
|
+
Bundles all externals into a package.
|
|
118
118
|
|
|
119
119
|
### eject
|
|
120
120
|
|
|
@@ -140,6 +140,23 @@ pkgbld --no-update-package-json
|
|
|
140
140
|
|
|
141
141
|
Do not write package.json.
|
|
142
142
|
|
|
143
|
+
## Plugin API
|
|
144
|
+
|
|
145
|
+
`pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
|
|
146
|
+
|
|
147
|
+
Plugins suppose to implement one or more of following interface methods as their package exports:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
interface PkgbldPlugin {
|
|
151
|
+
options(parsedArgs: {[key: string]: string | number}, options: ReturnType<typeof getCliOptions>): void;
|
|
152
|
+
processPackageJson(packageJson: PackageJson, inputs: string[], logger: Logger): void;
|
|
153
|
+
processTsConfig(config: Json): void;
|
|
154
|
+
providePlugins(provider: Provider, config: Record<string, string | string[] | boolean>, inputs: string[]): Promise<void>;
|
|
155
|
+
getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
|
|
156
|
+
buildEnd(): Promise<void>;
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
143
160
|
# License
|
|
144
161
|
|
|
145
162
|
[MIT](https://github.com/kshutkin/package-build/blob/main/LICENSE)
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,9 @@ var refiner = require('@slimlib/refine-partition');
|
|
|
11
11
|
var camelCase = require('lodash/camelCase');
|
|
12
12
|
var kleur = require('kleur');
|
|
13
13
|
var lodash = require('lodash');
|
|
14
|
-
var
|
|
14
|
+
var fsSync = require('fs');
|
|
15
|
+
var cloneDeep = require('lodash/cloneDeep');
|
|
16
|
+
var isEqual = require('lodash/isEqual');
|
|
15
17
|
|
|
16
18
|
async function createSubpackages(inputs, config) {
|
|
17
19
|
for (const input of inputs) {
|
|
@@ -41,7 +43,7 @@ const defaults = {
|
|
|
41
43
|
noTsConfig: false,
|
|
42
44
|
noUpdatePackageJson: false
|
|
43
45
|
};
|
|
44
|
-
function getCliOptions() {
|
|
46
|
+
function getCliOptions(plugins) {
|
|
45
47
|
const parsedArgs = minimist(process.argv.slice(2));
|
|
46
48
|
const umdInputs = parsedArgs.umd?.split(',').map((arg) => arg.trim()) ?? defaults.umdInputs;
|
|
47
49
|
const compressFormats = parsedArgs.compress?.split(',').map((arg) => arg.trim()) ?? defaults.compressFormats;
|
|
@@ -55,7 +57,7 @@ function getCliOptions() {
|
|
|
55
57
|
const eject = !!parsedArgs.eject ?? defaults.eject;
|
|
56
58
|
const noTsConfig = !!parsedArgs.noTsConfig ?? defaults.noTsConfig;
|
|
57
59
|
const noUpdatePackageJson = !!parsedArgs.noUpdatePackageJson ?? defaults.noUpdatePackageJson;
|
|
58
|
-
|
|
60
|
+
const options = {
|
|
59
61
|
umdInputs,
|
|
60
62
|
compressFormats,
|
|
61
63
|
sourcemapFormats,
|
|
@@ -70,10 +72,14 @@ function getCliOptions() {
|
|
|
70
72
|
noTsConfig,
|
|
71
73
|
noUpdatePackageJson
|
|
72
74
|
};
|
|
75
|
+
for (const plugin of plugins) {
|
|
76
|
+
plugin.options && plugin.options(parsedArgs, options);
|
|
77
|
+
}
|
|
78
|
+
return options;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
async function
|
|
76
|
-
const pkgPath = path.resolve(
|
|
81
|
+
async function getJson(fileName) {
|
|
82
|
+
const pkgPath = path.resolve(fileName);
|
|
77
83
|
const buffer = await fs.readFile(pkgPath);
|
|
78
84
|
return [pkgPath, JSON.parse(buffer.toString())];
|
|
79
85
|
}
|
|
@@ -186,7 +192,7 @@ async function typescript (provider) {
|
|
|
186
192
|
}
|
|
187
193
|
|
|
188
194
|
async function binify (provider, config) {
|
|
189
|
-
if (config.bin != null) {
|
|
195
|
+
if (config.bin != null && config.bin.length > 0) {
|
|
190
196
|
const pluginBinify = await provider.import('@rollup-extras/plugin-binify');
|
|
191
197
|
const format = {
|
|
192
198
|
'cjs': 'cjs',
|
|
@@ -272,10 +278,15 @@ const fileNamePatterns = {
|
|
|
272
278
|
'cjs': '[name].cjs',
|
|
273
279
|
'umd': '[name].umd.js',
|
|
274
280
|
};
|
|
275
|
-
async function getRollupConfigs([provider, plugins$1], inputs, config, helpers) {
|
|
281
|
+
async function getRollupConfigs([provider, plugins$1], inputs, config, helpers, externalPlugins) {
|
|
282
|
+
const factoryInProgress = [];
|
|
276
283
|
for (const factory of plugins) {
|
|
277
|
-
|
|
284
|
+
factoryInProgress.push(factory(provider, config, inputs));
|
|
278
285
|
}
|
|
286
|
+
for (const ePlugin of externalPlugins) {
|
|
287
|
+
ePlugin.providePlugins && factoryInProgress.push(ePlugin.providePlugins(provider, config, inputs));
|
|
288
|
+
}
|
|
289
|
+
await Promise.all(factoryInProgress);
|
|
279
290
|
const expandInputs = new Set;
|
|
280
291
|
for (const plugin of plugins$1) {
|
|
281
292
|
if (plugin.format && plugin.inputs?.length && !plugin.outputPlugin) {
|
|
@@ -369,10 +380,12 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers)
|
|
|
369
380
|
};
|
|
370
381
|
});
|
|
371
382
|
function getExtraOutputSettings(format, inputs) {
|
|
383
|
+
let result = {};
|
|
372
384
|
switch (format) {
|
|
373
385
|
case 'cjs':
|
|
374
386
|
case 'es':
|
|
375
|
-
|
|
387
|
+
result = { chunkFileNames: fileNamePatterns[format] };
|
|
388
|
+
break;
|
|
376
389
|
case 'umd':
|
|
377
390
|
if (inputs.length <= 0) {
|
|
378
391
|
break;
|
|
@@ -380,12 +393,16 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers)
|
|
|
380
393
|
if (inputs.length > 1) {
|
|
381
394
|
throw new Error(`Cannot produce global name for mutliple umd inputs in one output: ${inputs}`);
|
|
382
395
|
}
|
|
383
|
-
|
|
384
|
-
name: helpers.getGlobalName(inputs
|
|
396
|
+
result = {
|
|
397
|
+
name: helpers.getGlobalName(inputs.join('_')),
|
|
385
398
|
globals: helpers.getExternalGlobalName,
|
|
386
399
|
};
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
for (const ePlugin of externalPlugins) {
|
|
403
|
+
ePlugin.getExtraOutputSettings && Object.assign(result, ePlugin.getExtraOutputSettings(format, inputs));
|
|
387
404
|
}
|
|
388
|
-
return
|
|
405
|
+
return result;
|
|
389
406
|
}
|
|
390
407
|
function getPlugins(formats, inputs, outputPlugin) {
|
|
391
408
|
const filteredPlugins = [];
|
|
@@ -431,8 +448,8 @@ async function getRollupConfigs([provider, plugins$1], inputs, config, helpers)
|
|
|
431
448
|
|
|
432
449
|
const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
|
|
433
450
|
|
|
434
|
-
function processPackage(pkg, config) {
|
|
435
|
-
const
|
|
451
|
+
function processPackage(pkg, config, plugins) {
|
|
452
|
+
const inputs = [];
|
|
436
453
|
const logger$1 = logger.createLogger();
|
|
437
454
|
const allowEsm = (config.formatsOverriden && config.formats.includes('es') || !config.formatsOverriden);
|
|
438
455
|
const allowCjs = (config.formatsOverriden && config.formats.includes('cjs') || !config.formatsOverriden);
|
|
@@ -519,19 +536,22 @@ function processPackage(pkg, config) {
|
|
|
519
536
|
pkg.files.push(basename);
|
|
520
537
|
}
|
|
521
538
|
}
|
|
522
|
-
|
|
539
|
+
inputs.push(`./${config.sourceDir}/${basename}.ts`);
|
|
523
540
|
}
|
|
524
541
|
if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
|
|
525
542
|
config.formats.push('umd');
|
|
526
543
|
}
|
|
527
|
-
|
|
544
|
+
for (const plugin of plugins) {
|
|
545
|
+
plugin.processPackageJson && plugin.processPackageJson(pkg, inputs, logger$1);
|
|
546
|
+
}
|
|
547
|
+
return inputs;
|
|
528
548
|
}
|
|
529
549
|
|
|
530
550
|
async function writeJson(path, json) {
|
|
531
551
|
await fs.writeFile(path, JSON.stringify(json, null, 2) + '\n');
|
|
532
552
|
}
|
|
533
553
|
|
|
534
|
-
var version = "1.
|
|
554
|
+
var version = "1.16.1";
|
|
535
555
|
var license = "MIT";
|
|
536
556
|
var name = "pkgbld";
|
|
537
557
|
var author = {
|
|
@@ -586,11 +606,13 @@ var dependencies = {
|
|
|
586
606
|
"@slimlib/refine-partition": "^1.0.0",
|
|
587
607
|
"@slimlib/smart-mock": "^0.1.2",
|
|
588
608
|
"is-builtin-module": "^3.2.1",
|
|
589
|
-
typescript: "^5.0.2",
|
|
590
609
|
terser: "^5.16.8",
|
|
591
610
|
minimist: "^1.2.8",
|
|
592
611
|
kleur: "^4.1.5"
|
|
593
612
|
};
|
|
613
|
+
var peerDependencies = {
|
|
614
|
+
typescript: "^5.0.2"
|
|
615
|
+
};
|
|
594
616
|
var pkgbldPkg = {
|
|
595
617
|
version: version,
|
|
596
618
|
license: license,
|
|
@@ -607,7 +629,8 @@ var pkgbldPkg = {
|
|
|
607
629
|
keywords: keywords,
|
|
608
630
|
scripts: scripts,
|
|
609
631
|
devDependencies: devDependencies,
|
|
610
|
-
dependencies: dependencies
|
|
632
|
+
dependencies: dependencies,
|
|
633
|
+
peerDependencies: peerDependencies
|
|
611
634
|
};
|
|
612
635
|
|
|
613
636
|
const imports = new Map;
|
|
@@ -713,21 +736,42 @@ const defaultTsConfig = {
|
|
|
713
736
|
module: 'esnext',
|
|
714
737
|
esModuleInterop: true,
|
|
715
738
|
strict: true,
|
|
739
|
+
noUncheckedIndexedAccess: true,
|
|
716
740
|
declaration: true,
|
|
717
741
|
moduleResolution: 'node'
|
|
718
742
|
}
|
|
719
743
|
};
|
|
720
|
-
async function checkTsConfig(options, mainLogger) {
|
|
744
|
+
async function checkTsConfig(options, mainLogger, plugins) {
|
|
721
745
|
if (options.noTsConfig) {
|
|
722
746
|
return;
|
|
723
747
|
}
|
|
724
748
|
const tsConfigPath = path.resolve('tsconfig.json');
|
|
725
|
-
|
|
726
|
-
|
|
749
|
+
let config, needWrite = false;
|
|
750
|
+
if (fsSync.existsSync(tsConfigPath)) {
|
|
751
|
+
[, config] = await getJson('tsconfig.json');
|
|
727
752
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
753
|
+
else {
|
|
754
|
+
config = defaultTsConfig;
|
|
755
|
+
needWrite = true;
|
|
756
|
+
}
|
|
757
|
+
const originalConfig = cloneDeep(config);
|
|
758
|
+
for (const plugin of plugins) {
|
|
759
|
+
plugin.processTsConfig && plugin.processTsConfig(config);
|
|
760
|
+
}
|
|
761
|
+
if (!isEqual(originalConfig, config)) {
|
|
762
|
+
needWrite = true;
|
|
763
|
+
}
|
|
764
|
+
if (needWrite) {
|
|
765
|
+
mainLogger('no tsconfig.json and --no-ts-config not specified, writing tsconfig...');
|
|
766
|
+
await writeJson(tsConfigPath, config);
|
|
767
|
+
mainLogger('done');
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function loadPlugins(pkg) {
|
|
772
|
+
return Promise.all(Object.keys(pkg.devDependencies || {})
|
|
773
|
+
.filter(packageName => packageName.startsWith('pkgbld-plugin-'))
|
|
774
|
+
.map(packageName => import(packageName)));
|
|
731
775
|
}
|
|
732
776
|
|
|
733
777
|
execute();
|
|
@@ -737,14 +781,15 @@ async function execute() {
|
|
|
737
781
|
const mainLogger = logger.createLogger();
|
|
738
782
|
mainLogger.update('preparing...');
|
|
739
783
|
try {
|
|
740
|
-
const [pkgPath, pkg] = await
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
784
|
+
const [pkgPath, pkg] = await getJson('package.json');
|
|
785
|
+
const plugins = await loadPlugins(pkg);
|
|
786
|
+
const options = getCliOptions(plugins);
|
|
787
|
+
checkTsConfig(options, mainLogger, plugins);
|
|
788
|
+
const inputs = processPackage(pkg, options, plugins);
|
|
744
789
|
const helpers = getHelpers(pkg.name);
|
|
745
790
|
const preimportMap = preimport();
|
|
746
791
|
const provider = options.eject ? await createEjectProvider(preimportMap) : createProvider(preimportMap);
|
|
747
|
-
const rollupConfigs = await getRollupConfigs(provider, inputs, options, helpers);
|
|
792
|
+
const rollupConfigs = await getRollupConfigs(provider, inputs, options, helpers, plugins);
|
|
748
793
|
if (options.eject) {
|
|
749
794
|
await ejectConfig(rollupConfigs, pkgPath, options, inputs, helpers, pkg);
|
|
750
795
|
mainLogger.finish(`ejected config in ${getTimeDiff(time)}`);
|
|
@@ -760,6 +805,9 @@ async function execute() {
|
|
|
760
805
|
await writeJson(pkgPath, pkg);
|
|
761
806
|
}
|
|
762
807
|
await createSubpackages(inputs, options);
|
|
808
|
+
await Promise.all(plugins
|
|
809
|
+
.filter(plugin => plugin.buildEnd)
|
|
810
|
+
.map(plugin => plugin.buildEnd()));
|
|
763
811
|
mainLogger.finish(updater(true));
|
|
764
812
|
}
|
|
765
813
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { getCliOptions } from './get-cli-options';
|
|
2
2
|
import type { getHelpers } from './helpers';
|
|
3
|
-
import type { PkgbldRollupPlugin, Provider } from './types';
|
|
4
|
-
export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldRollupPlugin[]], inputs: string[], config: ReturnType<typeof getCliOptions>, helpers: ReturnType<typeof getHelpers>): Promise<{
|
|
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<{
|
|
5
5
|
input: string[];
|
|
6
6
|
output: {
|
|
7
7
|
amd?: import("rollup").AmdOptions | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { getCliOptions } from './get-cli-options';
|
|
2
|
-
import { Json } from './types';
|
|
3
|
-
export declare function processPackage(pkg: Json, config: ReturnType<typeof getCliOptions>): string[];
|
|
2
|
+
import { Json, PkgbldPlugin } from './types';
|
|
3
|
+
export declare function processPackage(pkg: Json, config: ReturnType<typeof getCliOptions>, plugins: Partial<PkgbldPlugin>[]): string[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Logger } from '@niceties/logger';
|
|
2
2
|
import { getCliOptions } from './get-cli-options';
|
|
3
|
-
|
|
3
|
+
import { PkgbldPlugin } from './types';
|
|
4
|
+
export declare function checkTsConfig(options: ReturnType<typeof getCliOptions>, mainLogger: Logger, plugins: Partial<PkgbldPlugin>[]): Promise<void>;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { Plugin, InternalModuleFormat } from 'rollup';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
used: () => void;
|
|
6
|
-
}*/
|
|
1
|
+
import type { Plugin, InternalModuleFormat, OutputOptions } from 'rollup';
|
|
2
|
+
import type { getCliOptions } from './get-cli-options';
|
|
3
|
+
import { Logger } from '@niceties/logger';
|
|
7
4
|
export type Json = null | string | number | boolean | Json[] | {
|
|
8
5
|
[name: string]: Json;
|
|
9
6
|
};
|
|
@@ -41,3 +38,13 @@ export type PkgbldRollupPlugin = {
|
|
|
41
38
|
inputs?: string[];
|
|
42
39
|
outputPlugin?: true;
|
|
43
40
|
};
|
|
41
|
+
export interface PkgbldPlugin {
|
|
42
|
+
options(parsedArgs: {
|
|
43
|
+
[key: string]: string | number;
|
|
44
|
+
}, options: ReturnType<typeof getCliOptions>): void;
|
|
45
|
+
processPackageJson(packageJson: PackageJson, inputs: string[], logger: Logger): void;
|
|
46
|
+
processTsConfig(config: Json): void;
|
|
47
|
+
providePlugins(provider: Provider, config: Record<string, string | string[] | boolean>, inputs: string[]): Promise<void>;
|
|
48
|
+
getExtraOutputSettings(format: InternalModuleFormat, inputs: string[]): Partial<OutputOptions>;
|
|
49
|
+
buildEnd(): Promise<void>;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.16.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "pkgbld",
|
|
5
5
|
"author": {
|
|
@@ -50,11 +50,13 @@
|
|
|
50
50
|
"@slimlib/refine-partition": "^1.0.0",
|
|
51
51
|
"@slimlib/smart-mock": "^0.1.2",
|
|
52
52
|
"is-builtin-module": "^3.2.1",
|
|
53
|
-
"typescript": "^5.0.2",
|
|
54
53
|
"terser": "^5.16.8",
|
|
55
54
|
"minimist": "^1.2.8",
|
|
56
55
|
"kleur": "^4.1.5"
|
|
57
56
|
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"typescript": "^5.0.2"
|
|
59
|
+
},
|
|
58
60
|
"scripts": {
|
|
59
61
|
"build": "rollup -c",
|
|
60
62
|
"lint": "eslint ./src"
|
package/dist/src/get-pkg.d.ts
DELETED