pkgbld 1.19.0 → 1.21.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 +8 -0
- package/dist/index.js +176 -95
- package/dist/src/get-cli-options.d.ts +1 -0
- package/dist/src/get-rollup-configs.d.ts +1 -1
- package/dist/src/helpers.d.ts +2 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -170,6 +170,14 @@ pkgbld --umd-pattern=[name].js
|
|
|
170
170
|
|
|
171
171
|
Defines the pattern for umd output files. Default is `[name].umd.js`.
|
|
172
172
|
|
|
173
|
+
### format-package-json
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
pkgbld --format-package-json
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Formats package.json file.
|
|
180
|
+
|
|
173
181
|
## Plugin API
|
|
174
182
|
|
|
175
183
|
`pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,19 @@ async function createSubpackages(inputs, config) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
function CommaSeparatedString(value) {
|
|
34
|
+
return value.split(',').map((arg) => arg.trim());
|
|
35
|
+
}
|
|
36
|
+
function CommaSeparatedStringOrBoolean(value) {
|
|
37
|
+
if (typeof value === 'boolean') {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return CommaSeparatedString(value);
|
|
44
|
+
}
|
|
45
|
+
const cliFlagsDefaults = {
|
|
34
46
|
formats: ['es', 'cjs'],
|
|
35
47
|
umdInputs: [],
|
|
36
48
|
compressFormats: ['umd'],
|
|
@@ -44,100 +56,158 @@ const defaults = {
|
|
|
44
56
|
noUpdatePackageJson: false,
|
|
45
57
|
commonjsPattern: '[name].cjs',
|
|
46
58
|
esPattern: '[name].mjs',
|
|
47
|
-
umdPattern: '[name].umd.js'
|
|
59
|
+
umdPattern: '[name].umd.js',
|
|
60
|
+
formatPackageJson: false
|
|
48
61
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
const cliFlags = {
|
|
63
|
+
umd: {
|
|
64
|
+
type: CommaSeparatedString,
|
|
65
|
+
description: 'Package subpath exports in UMD format',
|
|
66
|
+
default: cliFlagsDefaults.umdInputs
|
|
67
|
+
},
|
|
68
|
+
compress: {
|
|
69
|
+
type: CommaSeparatedString,
|
|
70
|
+
description: 'Compress formats using terser',
|
|
71
|
+
default: cliFlagsDefaults.compressFormats
|
|
72
|
+
},
|
|
73
|
+
sourcemaps: {
|
|
74
|
+
type: CommaSeparatedString,
|
|
75
|
+
description: 'Emit sourcemaps for the specified formats',
|
|
76
|
+
default: cliFlagsDefaults.sourcemapFormats
|
|
77
|
+
},
|
|
78
|
+
formats: {
|
|
79
|
+
type: CommaSeparatedString,
|
|
80
|
+
description: 'Formats to emit',
|
|
81
|
+
default: cliFlagsDefaults.formats
|
|
82
|
+
},
|
|
83
|
+
preprocess: {
|
|
84
|
+
type: CommaSeparatedString,
|
|
85
|
+
description: 'Preprocess entry points / subpath exports',
|
|
86
|
+
default: cliFlagsDefaults.preprocess
|
|
87
|
+
},
|
|
88
|
+
dir: {
|
|
89
|
+
type: String,
|
|
90
|
+
description: 'Output directory',
|
|
91
|
+
default: cliFlagsDefaults.dir
|
|
92
|
+
},
|
|
93
|
+
sourceDir: {
|
|
94
|
+
type: String,
|
|
95
|
+
description: 'Source directory',
|
|
96
|
+
default: cliFlagsDefaults.sourceDir
|
|
97
|
+
},
|
|
98
|
+
bin: {
|
|
99
|
+
type: CommaSeparatedString,
|
|
100
|
+
description: 'Executable files'
|
|
101
|
+
},
|
|
102
|
+
includeExternals: {
|
|
103
|
+
type: CommaSeparatedStringOrBoolean,
|
|
104
|
+
description: 'Include all/specified externals into result bundle(s)',
|
|
105
|
+
default: cliFlagsDefaults.includeExternals
|
|
106
|
+
},
|
|
107
|
+
eject: {
|
|
108
|
+
type: Boolean,
|
|
109
|
+
description: 'Eject config',
|
|
110
|
+
default: cliFlagsDefaults.eject
|
|
111
|
+
},
|
|
112
|
+
noTsConfig: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
description: 'Do not create / update tsconfig.json',
|
|
115
|
+
default: cliFlagsDefaults.noTsConfig
|
|
116
|
+
},
|
|
117
|
+
noUpdatePackageJson: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
description: 'Do not create / update package.json',
|
|
120
|
+
default: cliFlagsDefaults.noUpdatePackageJson
|
|
121
|
+
},
|
|
122
|
+
commonjsPattern: {
|
|
123
|
+
type: String,
|
|
124
|
+
description: 'CommonJS output file name pattern',
|
|
125
|
+
default: cliFlagsDefaults.commonjsPattern
|
|
126
|
+
},
|
|
127
|
+
esmPattern: {
|
|
128
|
+
type: String,
|
|
129
|
+
description: 'ES output file name pattern',
|
|
130
|
+
default: cliFlagsDefaults.esPattern
|
|
131
|
+
},
|
|
132
|
+
umdPattern: {
|
|
133
|
+
type: String,
|
|
134
|
+
description: 'UMD output file name pattern',
|
|
135
|
+
default: cliFlagsDefaults.umdPattern
|
|
136
|
+
},
|
|
137
|
+
formatPackageJson: {
|
|
138
|
+
type: Boolean,
|
|
139
|
+
description: 'Format package.json',
|
|
140
|
+
default: cliFlagsDefaults.formatPackageJson
|
|
55
141
|
}
|
|
56
|
-
|
|
57
|
-
|
|
142
|
+
};
|
|
143
|
+
const packageJsonFieldsOrder = new Set([
|
|
144
|
+
'private',
|
|
145
|
+
'type',
|
|
146
|
+
'version',
|
|
147
|
+
'name',
|
|
148
|
+
'description',
|
|
149
|
+
'license',
|
|
150
|
+
'author',
|
|
151
|
+
'contributors',
|
|
152
|
+
'funding',
|
|
153
|
+
'bin',
|
|
154
|
+
'main',
|
|
155
|
+
'browser',
|
|
156
|
+
'unpkg',
|
|
157
|
+
'module',
|
|
158
|
+
'exports',
|
|
159
|
+
'imports',
|
|
160
|
+
'types',
|
|
161
|
+
'typings',
|
|
162
|
+
'files',
|
|
163
|
+
'packageManager',
|
|
164
|
+
'sideEffects',
|
|
165
|
+
'engines',
|
|
166
|
+
'os',
|
|
167
|
+
'cpu',
|
|
168
|
+
'man',
|
|
169
|
+
'directories',
|
|
170
|
+
'repository',
|
|
171
|
+
'bugs',
|
|
172
|
+
'homepage',
|
|
173
|
+
'readme',
|
|
174
|
+
'keywords',
|
|
175
|
+
'scripts',
|
|
176
|
+
'config',
|
|
177
|
+
'dependencies',
|
|
178
|
+
'devDependencies',
|
|
179
|
+
'peerDependencies',
|
|
180
|
+
'peerDependenciesMeta',
|
|
181
|
+
'bundleDependencies',
|
|
182
|
+
'bundledDependencies',
|
|
183
|
+
'optionalDependencies',
|
|
184
|
+
'overrides',
|
|
185
|
+
'publishConfig',
|
|
186
|
+
'workspaces'
|
|
187
|
+
]);
|
|
188
|
+
function processPackageJson(pkg, needTreatment, treatKey) {
|
|
189
|
+
const newPkg = {};
|
|
190
|
+
for (const key of packageJsonFieldsOrder) {
|
|
191
|
+
if (needTreatment(key)) {
|
|
192
|
+
newPkg[key] = treatKey(key);
|
|
193
|
+
}
|
|
58
194
|
}
|
|
59
|
-
|
|
195
|
+
for (const key in pkg) {
|
|
196
|
+
if (!packageJsonFieldsOrder.has(key)) {
|
|
197
|
+
newPkg[key] = pkg[key];
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return newPkg;
|
|
201
|
+
}
|
|
202
|
+
function toFormattedJson(json) {
|
|
203
|
+
return JSON.stringify(json, null, 2) + '\n';
|
|
60
204
|
}
|
|
205
|
+
|
|
61
206
|
function getCliOptions(plugins, pkg) {
|
|
62
207
|
const cliOptions = cleye.cli({
|
|
63
208
|
name: 'pkgbld',
|
|
64
209
|
version: pkg.version ?? '<unknown>',
|
|
65
|
-
flags:
|
|
66
|
-
umd: {
|
|
67
|
-
type: CommaSeparatedString,
|
|
68
|
-
description: 'Package subpath exports in UMD format',
|
|
69
|
-
default: defaults.umdInputs
|
|
70
|
-
},
|
|
71
|
-
compress: {
|
|
72
|
-
type: CommaSeparatedString,
|
|
73
|
-
description: 'Compress formats using terser',
|
|
74
|
-
default: defaults.compressFormats
|
|
75
|
-
},
|
|
76
|
-
sourcemaps: {
|
|
77
|
-
type: CommaSeparatedString,
|
|
78
|
-
description: 'Emit sourcemaps for the specified formats',
|
|
79
|
-
default: defaults.sourcemapFormats
|
|
80
|
-
},
|
|
81
|
-
formats: {
|
|
82
|
-
type: CommaSeparatedString,
|
|
83
|
-
description: 'Formats to emit',
|
|
84
|
-
default: defaults.formats
|
|
85
|
-
},
|
|
86
|
-
preprocess: {
|
|
87
|
-
type: CommaSeparatedString,
|
|
88
|
-
description: 'Preprocess entry points / subpath exports',
|
|
89
|
-
default: defaults.preprocess
|
|
90
|
-
},
|
|
91
|
-
dir: {
|
|
92
|
-
type: String,
|
|
93
|
-
description: 'Output directory',
|
|
94
|
-
default: defaults.dir
|
|
95
|
-
},
|
|
96
|
-
sourceDir: {
|
|
97
|
-
type: String,
|
|
98
|
-
description: 'Source directory',
|
|
99
|
-
default: defaults.sourceDir
|
|
100
|
-
},
|
|
101
|
-
bin: {
|
|
102
|
-
type: CommaSeparatedString,
|
|
103
|
-
description: 'Executable files'
|
|
104
|
-
},
|
|
105
|
-
includeExternals: {
|
|
106
|
-
type: CommaSeparatedStringOrBoolean,
|
|
107
|
-
description: 'Include all/specified externals into result bundle(s)',
|
|
108
|
-
default: defaults.includeExternals
|
|
109
|
-
},
|
|
110
|
-
eject: {
|
|
111
|
-
type: Boolean,
|
|
112
|
-
description: 'Eject config',
|
|
113
|
-
default: defaults.eject
|
|
114
|
-
},
|
|
115
|
-
noTsConfig: {
|
|
116
|
-
type: Boolean,
|
|
117
|
-
description: 'Do not create / update tsconfig.json',
|
|
118
|
-
default: defaults.noTsConfig
|
|
119
|
-
},
|
|
120
|
-
noUpdatePackageJson: {
|
|
121
|
-
type: Boolean,
|
|
122
|
-
description: 'Do not create / update package.json',
|
|
123
|
-
default: defaults.noUpdatePackageJson
|
|
124
|
-
},
|
|
125
|
-
commonjsPattern: {
|
|
126
|
-
type: String,
|
|
127
|
-
description: 'CommonJS output file name pattern',
|
|
128
|
-
default: defaults.commonjsPattern
|
|
129
|
-
},
|
|
130
|
-
esmPattern: {
|
|
131
|
-
type: String,
|
|
132
|
-
description: 'ES output file name pattern',
|
|
133
|
-
default: defaults.esPattern
|
|
134
|
-
},
|
|
135
|
-
umdPattern: {
|
|
136
|
-
type: String,
|
|
137
|
-
description: 'UMD output file name pattern',
|
|
138
|
-
default: defaults.umdPattern
|
|
139
|
-
}
|
|
140
|
-
}
|
|
210
|
+
flags: cliFlags
|
|
141
211
|
});
|
|
142
212
|
const flags = cliOptions.flags;
|
|
143
213
|
const options = {
|
|
@@ -145,7 +215,7 @@ function getCliOptions(plugins, pkg) {
|
|
|
145
215
|
compressFormats: flags.compress,
|
|
146
216
|
sourcemapFormats: flags.sourcemaps,
|
|
147
217
|
formats: flags.formats,
|
|
148
|
-
formatsOverridden: flags.formats !==
|
|
218
|
+
formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
|
|
149
219
|
preprocess: flags.preprocess,
|
|
150
220
|
dir: flags.dir,
|
|
151
221
|
sourceDir: flags.sourceDir,
|
|
@@ -156,7 +226,8 @@ function getCliOptions(plugins, pkg) {
|
|
|
156
226
|
noUpdatePackageJson: flags.noUpdatePackageJson,
|
|
157
227
|
commonjsPattern: flags.commonjsPattern,
|
|
158
228
|
esPattern: flags.esmPattern,
|
|
159
|
-
umdPattern: flags.umdPattern
|
|
229
|
+
umdPattern: flags.umdPattern,
|
|
230
|
+
formatPackageJson: flags.formatPackageJson
|
|
160
231
|
};
|
|
161
232
|
for (const plugin of plugins) {
|
|
162
233
|
plugin.options?.(flags, options);
|
|
@@ -224,7 +295,7 @@ function includeExternals(importer, external, id, config) {
|
|
|
224
295
|
if (!external)
|
|
225
296
|
return false;
|
|
226
297
|
if (path.isAbsolute(id)) {
|
|
227
|
-
id =
|
|
298
|
+
id = path.relative(path.join(process.cwd(), '..'), id);
|
|
228
299
|
}
|
|
229
300
|
const internals = config.includeExternals;
|
|
230
301
|
if (internals.includes(id) || internals.some(internal => id.startsWith(internal))) {
|
|
@@ -384,6 +455,9 @@ function getTimeDiff(starting) {
|
|
|
384
455
|
return `${now - starting}ms`;
|
|
385
456
|
}
|
|
386
457
|
const areSetsEqual = (a, b) => a.size === b.size ? [...a].every(value => b.has(value)) : false;
|
|
458
|
+
function formatPackageJson(pkg) {
|
|
459
|
+
return processPackageJson(pkg, key => key in pkg, key => pkg[key]);
|
|
460
|
+
}
|
|
387
461
|
|
|
388
462
|
async function getRollupConfigs([provider, plugins$1], inputs, config, helpers, externalPlugins) {
|
|
389
463
|
const factoryInProgress = [];
|
|
@@ -669,10 +743,10 @@ function patternToName(pattern, input) {
|
|
|
669
743
|
}
|
|
670
744
|
|
|
671
745
|
async function writeJson(path, json) {
|
|
672
|
-
await fs.writeFile(path,
|
|
746
|
+
await fs.writeFile(path, toFormattedJson(json));
|
|
673
747
|
}
|
|
674
748
|
|
|
675
|
-
var version = "1.
|
|
749
|
+
var version = "1.21.0";
|
|
676
750
|
var name = "pkgbld";
|
|
677
751
|
var license = "MIT";
|
|
678
752
|
var author = "Konstantin Shutkin";
|
|
@@ -708,7 +782,7 @@ var dependencies = {
|
|
|
708
782
|
"@niceties/draftlog-appender": "^1.3.0",
|
|
709
783
|
lodash: "^4.17.21",
|
|
710
784
|
rollup: "^3.20.2",
|
|
711
|
-
"rollup-plugin-typescript2": "^0.
|
|
785
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
712
786
|
"rollup-plugin-preprocess": "^0.0.4",
|
|
713
787
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
714
788
|
"@rollup/plugin-terser": "^0.4.0",
|
|
@@ -726,7 +800,8 @@ var dependencies = {
|
|
|
726
800
|
};
|
|
727
801
|
var devDependencies = {
|
|
728
802
|
"@types/lodash": "^4.14.192",
|
|
729
|
-
"@total-typescript/ts-reset": "^0.5.1"
|
|
803
|
+
"@total-typescript/ts-reset": "^0.5.1",
|
|
804
|
+
options: "workspace:*"
|
|
730
805
|
};
|
|
731
806
|
var peerDependencies = {
|
|
732
807
|
typescript: "^5.2.2"
|
|
@@ -899,7 +974,10 @@ async function execute() {
|
|
|
899
974
|
const mainLogger = logger.createLogger();
|
|
900
975
|
mainLogger.update('preparing..');
|
|
901
976
|
try {
|
|
902
|
-
|
|
977
|
+
let pkg;
|
|
978
|
+
let pkgPath;
|
|
979
|
+
// eslint-disable-next-line prefer-const
|
|
980
|
+
[pkgPath, pkg] = await getJson('package.json');
|
|
903
981
|
const plugins = await loadPlugins(pkg);
|
|
904
982
|
mainLogger.update('');
|
|
905
983
|
process.stdout.moveCursor?.(0, -1);
|
|
@@ -908,6 +986,9 @@ async function execute() {
|
|
|
908
986
|
mainLogger.update('preparing...');
|
|
909
987
|
checkTsConfig(options, mainLogger, plugins);
|
|
910
988
|
const inputs = processPackage(pkg, options, plugins);
|
|
989
|
+
if (options.formatPackageJson) {
|
|
990
|
+
pkg = formatPackageJson(pkg);
|
|
991
|
+
}
|
|
911
992
|
const helpers = getHelpers(pkg.name);
|
|
912
993
|
const preimportMap = preimport();
|
|
913
994
|
const provider = options.eject ? await createEjectProvider(preimportMap) : createProvider(preimportMap);
|
|
@@ -21,7 +21,7 @@ export declare function getRollupConfigs([provider, plugins]: [Provider, PkgbldR
|
|
|
21
21
|
externalLiveBindings?: boolean | undefined;
|
|
22
22
|
file?: string | undefined;
|
|
23
23
|
footer?: string | import("rollup").AddonFunction | undefined;
|
|
24
|
-
format: "umd" | "
|
|
24
|
+
format: "umd" | "amd" | "cjs" | "es" | "iife" | "system" | "commonjs" | "esm" | "module" | "systemjs";
|
|
25
25
|
freeze?: boolean | undefined;
|
|
26
26
|
generatedCode?: import("rollup").GeneratedCodePreset | import("rollup").GeneratedCodeOptions | undefined;
|
|
27
27
|
globals?: import("rollup").GlobalsOption | undefined;
|
package/dist/src/helpers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OutputOptions } from 'rollup';
|
|
2
|
+
import { PackageJson } from './types';
|
|
2
3
|
export declare function getHelpers(pkgName: string): {
|
|
3
4
|
getGlobalName: (anInput: string) => string;
|
|
4
5
|
getExternalGlobalName: (id: string) => string;
|
|
@@ -8,3 +9,4 @@ export declare function formatInput(input: string[] | string): string;
|
|
|
8
9
|
export declare function formatOutput(output: OutputOptions | OutputOptions[] | undefined, field: 'dir' | 'format'): string;
|
|
9
10
|
export declare function getTimeDiff(starting: number): string;
|
|
10
11
|
export declare const areSetsEqual: <T>(a: Set<T>, b: Set<T>) => boolean;
|
|
12
|
+
export declare function formatPackageJson(pkg: PackageJson): PackageJson;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.21.0",
|
|
3
3
|
"name": "pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@niceties/draftlog-appender": "^1.3.0",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
33
|
"rollup": "^3.20.2",
|
|
34
|
-
"rollup-plugin-typescript2": "^0.
|
|
34
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
35
35
|
"rollup-plugin-preprocess": "^0.0.4",
|
|
36
36
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
37
37
|
"@rollup/plugin-terser": "^0.4.0",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/lodash": "^4.14.192",
|
|
52
|
-
"@total-typescript/ts-reset": "^0.5.1"
|
|
52
|
+
"@total-typescript/ts-reset": "^0.5.1",
|
|
53
|
+
"options": "0.0.0"
|
|
53
54
|
},
|
|
54
55
|
"peerDependencies": {
|
|
55
56
|
"typescript": "^5.2.2"
|