pkgbld 1.23.0 → 1.24.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 +8 -0
- package/dist/index.js +110 -26
- package/dist/src/get-cli-options.d.ts +4 -0
- package/dist/src/prune.d.ts +5 -0
- package/dist/src/types.d.ts +4 -1
- package/package.json +1 -10
package/README.md
CHANGED
|
@@ -178,6 +178,14 @@ pkgbld --format-package-json
|
|
|
178
178
|
|
|
179
179
|
Formats package.json file.
|
|
180
180
|
|
|
181
|
+
### prune (command)
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
pkgbld prune
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
prune devDependencies and redundunt scripts from package.json
|
|
188
|
+
|
|
181
189
|
## Plugin API
|
|
182
190
|
|
|
183
191
|
`pkgbld` reads all installed packages named `pkgbld-plugin-*` and assumes they are plugins
|
package/dist/index.js
CHANGED
|
@@ -159,6 +159,7 @@ const packageJsonFieldsOrder = new Set([
|
|
|
159
159
|
'browser',
|
|
160
160
|
'unpkg',
|
|
161
161
|
'module',
|
|
162
|
+
'svelte',
|
|
162
163
|
'exports',
|
|
163
164
|
'imports',
|
|
164
165
|
'types',
|
|
@@ -212,32 +213,54 @@ function getCliOptions(plugins, pkg) {
|
|
|
212
213
|
const cliOptions = cleye.cli({
|
|
213
214
|
name: 'pkgbld',
|
|
214
215
|
version: pkg.version ?? '<unknown>',
|
|
215
|
-
flags: cliFlags
|
|
216
|
+
flags: cliFlags,
|
|
217
|
+
commands: [
|
|
218
|
+
cleye.command({
|
|
219
|
+
name: 'prune',
|
|
220
|
+
description: 'prune devDependencies and redundunt scripts from package.json',
|
|
221
|
+
flags: {
|
|
222
|
+
profile: {
|
|
223
|
+
type: String,
|
|
224
|
+
description: 'profile to use',
|
|
225
|
+
default: 'library'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
]
|
|
216
230
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
if (cliOptions.command === 'prune') {
|
|
232
|
+
return {
|
|
233
|
+
kind: 'prune',
|
|
234
|
+
profile: cliOptions.flags.profile
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const flags = cliOptions.flags;
|
|
239
|
+
const options = {
|
|
240
|
+
kind: 'build',
|
|
241
|
+
umdInputs: flags.umd,
|
|
242
|
+
compressFormats: flags.compress,
|
|
243
|
+
sourcemapFormats: flags.sourcemaps,
|
|
244
|
+
formats: flags.formats,
|
|
245
|
+
formatsOverridden: flags.formats !== cliFlagsDefaults.formats,
|
|
246
|
+
preprocess: flags.preprocess,
|
|
247
|
+
dir: flags.dest,
|
|
248
|
+
sourceDir: flags.src,
|
|
249
|
+
bin: flags.bin,
|
|
250
|
+
includeExternals: flags.includeExternals,
|
|
251
|
+
eject: flags.eject,
|
|
252
|
+
noTsConfig: flags.noTsConfig,
|
|
253
|
+
noUpdatePackageJson: flags.noUpdatePackageJson,
|
|
254
|
+
commonjsPattern: flags.commonjsPattern,
|
|
255
|
+
esPattern: flags.esmPattern,
|
|
256
|
+
umdPattern: flags.umdPattern,
|
|
257
|
+
formatPackageJson: flags.formatPackageJson
|
|
258
|
+
};
|
|
259
|
+
for (const plugin of plugins) {
|
|
260
|
+
plugin.options?.(flags, options);
|
|
261
|
+
}
|
|
262
|
+
return options;
|
|
239
263
|
}
|
|
240
|
-
return options;
|
|
241
264
|
}
|
|
242
265
|
|
|
243
266
|
async function getJson(fileName) {
|
|
@@ -660,6 +683,12 @@ function processPackage(pkg, config, plugins) {
|
|
|
660
683
|
if (typeof pkg.exports !== 'object' && pkg.exports !== null) {
|
|
661
684
|
pkg.exports = {};
|
|
662
685
|
}
|
|
686
|
+
if (typeof pkg.scripts !== 'object' && pkg.scripts !== null) {
|
|
687
|
+
pkg.scripts = {};
|
|
688
|
+
}
|
|
689
|
+
if (!('prepack' in pkg.scripts)) {
|
|
690
|
+
pkg.scripts.prepack = 'pkgbld prune';
|
|
691
|
+
}
|
|
663
692
|
if (pkg.exports['.'] == null) {
|
|
664
693
|
pkg.exports['.'] = {};
|
|
665
694
|
}
|
|
@@ -729,6 +758,7 @@ function processPackage(pkg, config, plugins) {
|
|
|
729
758
|
if (allowCjs) {
|
|
730
759
|
pkg.exports[id].require = `./${config.dir}/${patternToName(config.commonjsPattern, basename)}`;
|
|
731
760
|
}
|
|
761
|
+
pkg.exports[id] = orderFields(pkg.exports[id]);
|
|
732
762
|
if (basename !== 'index') {
|
|
733
763
|
if (!pkg.files.includes(basename)) {
|
|
734
764
|
pkg.files.push(basename);
|
|
@@ -747,12 +777,33 @@ function processPackage(pkg, config, plugins) {
|
|
|
747
777
|
function patternToName(pattern, input) {
|
|
748
778
|
return pattern.replace('[name]', input);
|
|
749
779
|
}
|
|
780
|
+
const fieldsOrder = new Set([
|
|
781
|
+
'types',
|
|
782
|
+
'import',
|
|
783
|
+
'require',
|
|
784
|
+
'svelte',
|
|
785
|
+
'default'
|
|
786
|
+
]);
|
|
787
|
+
function orderFields(exports) {
|
|
788
|
+
const ordered = {};
|
|
789
|
+
for (const key of fieldsOrder) {
|
|
790
|
+
if (key in exports) {
|
|
791
|
+
ordered[key] = exports[key];
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
for (const key in exports) {
|
|
795
|
+
if (!fieldsOrder.has(key)) {
|
|
796
|
+
ordered[key] = exports[key];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return ordered;
|
|
800
|
+
}
|
|
750
801
|
|
|
751
802
|
async function writeJson(path, json) {
|
|
752
803
|
await fs.writeFile(path, toFormattedJson(json));
|
|
753
804
|
}
|
|
754
805
|
|
|
755
|
-
var version = "1.
|
|
806
|
+
var version = "1.24.1";
|
|
756
807
|
var name = "pkgbld";
|
|
757
808
|
var license = "MIT";
|
|
758
809
|
var author = "Konstantin Shutkin";
|
|
@@ -781,7 +832,8 @@ var keywords = [
|
|
|
781
832
|
];
|
|
782
833
|
var scripts = {
|
|
783
834
|
build: "rollup -c",
|
|
784
|
-
lint: "eslint ./src"
|
|
835
|
+
lint: "eslint ./src",
|
|
836
|
+
prepack: "node ./dist/index.js prune"
|
|
785
837
|
};
|
|
786
838
|
var dependencies = {
|
|
787
839
|
"@niceties/logger": "^1.1.12",
|
|
@@ -977,6 +1029,33 @@ function loadPlugins(pkg) {
|
|
|
977
1029
|
.map(packageName => import(packageName)));
|
|
978
1030
|
}
|
|
979
1031
|
|
|
1032
|
+
const scriptsToKeep = new Set([
|
|
1033
|
+
'preinstall',
|
|
1034
|
+
'install',
|
|
1035
|
+
'postinstall',
|
|
1036
|
+
'prepublish',
|
|
1037
|
+
'preprepare',
|
|
1038
|
+
'prepare',
|
|
1039
|
+
'postprepare'
|
|
1040
|
+
]);
|
|
1041
|
+
function prunePkg(pkg, options) {
|
|
1042
|
+
if (options.kind !== 'prune') {
|
|
1043
|
+
throw new Error('prunePkg should only be called in prune mode');
|
|
1044
|
+
}
|
|
1045
|
+
if (options.profile !== 'library') {
|
|
1046
|
+
throw new Error('only library profile is supported');
|
|
1047
|
+
}
|
|
1048
|
+
delete pkg.devDependencies;
|
|
1049
|
+
for (const key of Object.keys(pkg.scripts)) {
|
|
1050
|
+
if (!scriptsToKeep.has(key)) {
|
|
1051
|
+
delete pkg.scripts[key];
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
if (Object.keys(pkg.scripts).length === 0) {
|
|
1055
|
+
delete pkg.scripts;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
980
1059
|
execute();
|
|
981
1060
|
async function execute() {
|
|
982
1061
|
const time = Date.now();
|
|
@@ -991,6 +1070,11 @@ async function execute() {
|
|
|
991
1070
|
mainLogger.update('');
|
|
992
1071
|
process.stdout.moveCursor?.(0, -1);
|
|
993
1072
|
const options = getCliOptions(plugins, pkg);
|
|
1073
|
+
if (options.kind === 'prune') {
|
|
1074
|
+
prunePkg(pkg, options);
|
|
1075
|
+
await writeJson(pkgPath, pkg);
|
|
1076
|
+
process.exit(0);
|
|
1077
|
+
}
|
|
994
1078
|
process.stdout.moveCursor?.(0, 1);
|
|
995
1079
|
mainLogger.update('preparing...');
|
|
996
1080
|
checkTsConfig(options, mainLogger, plugins);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PackageJson, PkgbldPlugin } from './types';
|
|
2
2
|
export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: PackageJson): {
|
|
3
|
+
kind: 'build';
|
|
3
4
|
umdInputs: string[];
|
|
4
5
|
compressFormats: string[];
|
|
5
6
|
sourcemapFormats: string[];
|
|
@@ -17,4 +18,7 @@ export declare function getCliOptions(plugins: Partial<PkgbldPlugin>[], pkg: Pac
|
|
|
17
18
|
esPattern: string;
|
|
18
19
|
umdPattern: string;
|
|
19
20
|
formatPackageJson: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "prune";
|
|
23
|
+
readonly profile: string;
|
|
20
24
|
};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type PackageJson = {
|
|
|
10
10
|
dependencies?: Record<string, string>;
|
|
11
11
|
devDependencies?: Record<string, string>;
|
|
12
12
|
peerDependencies: Record<string, string>;
|
|
13
|
+
scripts?: Record<string, string>;
|
|
13
14
|
};
|
|
14
15
|
export declare const enum Priority {
|
|
15
16
|
preprocess = 1000,
|
|
@@ -39,7 +40,9 @@ export type PkgbldRollupPlugin = {
|
|
|
39
40
|
inputs?: string[];
|
|
40
41
|
outputPlugin?: true;
|
|
41
42
|
};
|
|
42
|
-
export type CliOptions = NonNullable<ReturnType<typeof getCliOptions
|
|
43
|
+
export type CliOptions = NonNullable<Extract<ReturnType<typeof getCliOptions>, {
|
|
44
|
+
kind: 'build';
|
|
45
|
+
}>>;
|
|
43
46
|
export type ParsedOptions = Record<string, string | number | string[] | number[] | boolean | undefined>;
|
|
44
47
|
export interface PkgbldPlugin {
|
|
45
48
|
options(parsedArgs: ParsedOptions, options: CliOptions): void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.24.1",
|
|
3
3
|
"name": "pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -47,16 +47,7 @@
|
|
|
47
47
|
"kleur": "^4.1.5",
|
|
48
48
|
"cleye": "^1.3.2"
|
|
49
49
|
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
"@types/lodash": "^4.14.199",
|
|
52
|
-
"@total-typescript/ts-reset": "^0.5.1",
|
|
53
|
-
"options": "0.1.0"
|
|
54
|
-
},
|
|
55
50
|
"peerDependencies": {
|
|
56
51
|
"typescript": "^5.2.2"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"build": "rollup -c",
|
|
60
|
-
"lint": "eslint ./src"
|
|
61
52
|
}
|
|
62
53
|
}
|