pkgbld 1.11.2 → 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 +8 -0
- package/dist/builtin-plugins/binify.d.ts +3 -0
- package/dist/builtin-plugins/clean.d.ts +2 -0
- package/dist/builtin-plugins/commonjs.d.ts +2 -0
- package/dist/builtin-plugins/externals.d.ts +3 -0
- package/dist/builtin-plugins/preprocess.d.ts +3 -0
- package/dist/builtin-plugins/resolve.d.ts +2 -0
- package/dist/builtin-plugins/terser.d.ts +3 -0
- package/dist/builtin-plugins/typescript.d.ts +2 -0
- package/dist/get-cli-options.d.ts +5 -3
- package/dist/get-plugins.d.ts +11 -4
- package/dist/get-rollup-configs.d.ts +54 -4
- package/dist/helpers.d.ts +1 -4
- package/dist/index.js +343 -124
- package/dist/types.d.ts +19 -2
- package/package.json +14 -12
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)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare function getCliOptions(): {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
umdInputs: string[];
|
|
3
|
+
compressFormats: string[];
|
|
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/get-plugins.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare
|
|
1
|
+
import { Plugin, InternalModuleFormat } from 'rollup';
|
|
2
|
+
import { Priotiry, Provider } from './types';
|
|
3
|
+
import externals from './builtin-plugins/externals';
|
|
4
|
+
export declare const plugins: (typeof externals)[];
|
|
5
|
+
export declare function createProvider(): [Provider, {
|
|
6
|
+
plugin: () => Plugin;
|
|
7
|
+
priority: Priotiry;
|
|
8
|
+
format?: InternalModuleFormat | InternalModuleFormat[];
|
|
9
|
+
inputs?: string[];
|
|
10
|
+
outputPlugin?: true;
|
|
11
|
+
}[]];
|
|
@@ -1,4 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { getCliOptions } from './get-cli-options';
|
|
2
|
+
import type { getHelpers } from './helpers';
|
|
3
|
+
export declare function getRollupConfigs(inputs: string[], config: ReturnType<typeof getCliOptions>, helpers: ReturnType<typeof getHelpers>): Promise<{
|
|
4
|
+
input: string[];
|
|
5
|
+
output: {
|
|
6
|
+
amd?: import("rollup").AmdOptions | undefined;
|
|
7
|
+
assetFileNames?: string | ((chunkInfo: import("rollup").PreRenderedAsset) => string) | undefined;
|
|
8
|
+
banner?: string | import("rollup").AddonFunction | undefined;
|
|
9
|
+
chunkFileNames?: string | ((chunkInfo: import("rollup").PreRenderedChunk) => string) | undefined;
|
|
10
|
+
compact?: boolean | undefined;
|
|
11
|
+
dir: string;
|
|
12
|
+
dynamicImportFunction?: string | undefined;
|
|
13
|
+
dynamicImportInCjs?: boolean | undefined;
|
|
14
|
+
entryFileNames: string | ((chunkInfo: import("rollup").PreRenderedChunk) => string);
|
|
15
|
+
esModule?: boolean | "if-default-prop" | undefined;
|
|
16
|
+
experimentalMinChunkSize?: number | undefined;
|
|
17
|
+
exports?: "default" | "named" | "none" | "auto" | undefined;
|
|
18
|
+
extend?: boolean | undefined;
|
|
19
|
+
externalImportAssertions?: boolean | undefined;
|
|
20
|
+
externalLiveBindings?: boolean | undefined;
|
|
21
|
+
file?: string | undefined;
|
|
22
|
+
footer?: string | import("rollup").AddonFunction | undefined;
|
|
23
|
+
format: "amd" | "cjs" | "es" | "iife" | "system" | "umd" | "commonjs" | "esm" | "module" | "systemjs";
|
|
24
|
+
freeze?: boolean | undefined;
|
|
25
|
+
generatedCode?: import("rollup").GeneratedCodePreset | import("rollup").GeneratedCodeOptions | undefined;
|
|
26
|
+
globals?: import("rollup").GlobalsOption | undefined;
|
|
27
|
+
hoistTransitiveImports?: boolean | undefined;
|
|
28
|
+
indent?: string | boolean | undefined;
|
|
29
|
+
inlineDynamicImports?: boolean | undefined;
|
|
30
|
+
interop?: import("rollup").InteropType | import("rollup").GetInterop | undefined;
|
|
31
|
+
intro?: string | import("rollup").AddonFunction | undefined;
|
|
32
|
+
manualChunks?: import("rollup").ManualChunksOption | undefined;
|
|
33
|
+
minifyInternalExports?: boolean | undefined;
|
|
34
|
+
name?: string | undefined;
|
|
35
|
+
namespaceToStringTag?: boolean | undefined;
|
|
36
|
+
noConflict?: boolean | undefined;
|
|
37
|
+
outro?: string | import("rollup").AddonFunction | undefined;
|
|
38
|
+
paths?: import("rollup").OptionsPaths | undefined;
|
|
39
|
+
plugins: false | import("rollup").OutputPlugin | import("rollup").OutputPluginOption[] | Promise<false | import("rollup").OutputPlugin | import("rollup").NullValue | import("rollup").OutputPluginOption[]> | null;
|
|
40
|
+
preferConst?: boolean | undefined;
|
|
41
|
+
preserveModules?: boolean | undefined;
|
|
42
|
+
preserveModulesRoot?: string | undefined;
|
|
43
|
+
sanitizeFileName?: boolean | ((fileName: string) => string) | undefined;
|
|
44
|
+
sourcemap: boolean | "inline" | "hidden";
|
|
45
|
+
sourcemapBaseUrl?: string | undefined;
|
|
46
|
+
sourcemapExcludeSources?: boolean | undefined;
|
|
47
|
+
sourcemapFile?: string | undefined;
|
|
48
|
+
sourcemapPathTransform?: import("rollup").SourcemapPathTransformOption | undefined;
|
|
49
|
+
strict?: boolean | undefined;
|
|
50
|
+
systemNullSetters?: boolean | undefined;
|
|
51
|
+
validate?: boolean | undefined;
|
|
52
|
+
}[];
|
|
53
|
+
plugins: import("rollup").Plugin[];
|
|
54
|
+
}[]>;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { getCliOptions } from './get-cli-options';
|
|
2
1
|
import { OutputOptions } from 'rollup';
|
|
3
2
|
export declare function getHelpers(name: string): {
|
|
4
3
|
getGlobalName: (anInput: string) => string;
|
|
5
4
|
getExternalGlobalName: (id: string) => string;
|
|
6
|
-
umdFilter: typeof umdFilter;
|
|
7
5
|
};
|
|
8
|
-
export declare function umdFilter(config: ReturnType<typeof getCliOptions>, filename: string): boolean;
|
|
9
6
|
export declare function toArray<T>(object: T | T[] | undefined): T[];
|
|
10
|
-
export declare function isExternalInput(id: string, inputs: string | string[], currentInput: string, config: ReturnType<typeof getCliOptions>): boolean;
|
|
11
7
|
export declare function formatInput(input: string[] | string): string;
|
|
12
8
|
export declare function formatOutput(output: OutputOptions | OutputOptions[] | undefined, field: 'dir' | 'format'): string;
|
|
13
9
|
export declare function getTimeDiff(starting: number): string;
|
|
14
10
|
export declare function getDefaultExport<T extends {
|
|
15
11
|
default?: unknown;
|
|
16
12
|
}>(importedModule: T): {};
|
|
13
|
+
export declare const areSetsEqual: <T>(a: Set<T>, b: Set<T>) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -7,13 +7,7 @@ var rollup = require('rollup');
|
|
|
7
7
|
var fs = require('fs/promises');
|
|
8
8
|
var path = require('path');
|
|
9
9
|
var minimist = require('minimist');
|
|
10
|
-
var
|
|
11
|
-
var commonjs = require('@rollup/plugin-commonjs');
|
|
12
|
-
var resolve = require('@rollup/plugin-node-resolve');
|
|
13
|
-
var preprocess = require('rollup-plugin-preprocess');
|
|
14
|
-
var terser = require('@rollup/plugin-terser');
|
|
15
|
-
var cleanFactory = require('@rollup-extras/plugin-clean');
|
|
16
|
-
var externals = require('@rollup-extras/plugin-externals');
|
|
10
|
+
var refiner = require('@slimlib/refine-partition');
|
|
17
11
|
var camelCase = require('lodash/camelCase');
|
|
18
12
|
var kleur = require('kleur');
|
|
19
13
|
|
|
@@ -34,31 +28,34 @@ async function createSubpackages(inputs, config) {
|
|
|
34
28
|
|
|
35
29
|
const defaults = {
|
|
36
30
|
formats: ['es', 'cjs'],
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
umdInputs: [],
|
|
32
|
+
compressFormats: ['umd'],
|
|
33
|
+
sourcemapFormats: ['umd'],
|
|
40
34
|
preprocess: [],
|
|
41
35
|
dir: 'dist',
|
|
42
36
|
sourceDir: 'src'
|
|
43
37
|
};
|
|
44
38
|
function getCliOptions() {
|
|
45
|
-
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;
|
|
46
40
|
const parsedArgs = minimist(process.argv.slice(2));
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
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
|
+
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;
|
|
43
|
+
const sourcemapFormats = (_f = (_e = parsedArgs.sourcemaps) === null || _e === void 0 ? void 0 : _e.split(',').map((arg) => arg.trim())) !== null && _f !== void 0 ? _f : defaults.sourcemapFormats;
|
|
50
44
|
const formats = (_h = (_g = parsedArgs.formats) === null || _g === void 0 ? void 0 : _g.split(',').map((arg) => arg.trim())) !== null && _h !== void 0 ? _h : defaults.formats;
|
|
51
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;
|
|
52
46
|
const dir = (_l = parsedArgs.dir) !== null && _l !== void 0 ? _l : defaults.dir;
|
|
53
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());
|
|
54
49
|
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
umdInputs,
|
|
51
|
+
compressFormats,
|
|
52
|
+
sourcemapFormats,
|
|
58
53
|
formats,
|
|
54
|
+
formatsOverriden: 'formats' in parsedArgs,
|
|
59
55
|
preprocess,
|
|
60
56
|
dir,
|
|
61
|
-
sourceDir
|
|
57
|
+
sourceDir,
|
|
58
|
+
bin
|
|
62
59
|
};
|
|
63
60
|
}
|
|
64
61
|
|
|
@@ -68,6 +65,136 @@ async function getPackage() {
|
|
|
68
65
|
return [pkgPath, JSON.parse(buffer.toString())];
|
|
69
66
|
}
|
|
70
67
|
|
|
68
|
+
async function clean (provide) {
|
|
69
|
+
const { default: pluginClean } = await import('@rollup-extras/plugin-clean');
|
|
70
|
+
const pluginInstance = pluginClean();
|
|
71
|
+
provide(pluginFactory, 1000 /* Priotiry.cleanup */, { outputPlugin: true });
|
|
72
|
+
let firstPluginInstance = true;
|
|
73
|
+
function pluginFactory() {
|
|
74
|
+
const result = firstPluginInstance ? pluginInstance : pluginInstance.api.addInstance();
|
|
75
|
+
firstPluginInstance = false;
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function commonjs (provide) {
|
|
81
|
+
const { default: pluginCommonjs } = await import('@rollup/plugin-commonjs');
|
|
82
|
+
provide(() => pluginCommonjs(), 4000 /* Priotiry.commonjs */);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function externals (provide, config, inputs) {
|
|
86
|
+
const { default: pluginExternals } = await import('@rollup-extras/plugin-externals');
|
|
87
|
+
const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
|
|
88
|
+
if (config.formats.length > 0) {
|
|
89
|
+
const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
|
|
90
|
+
provide(() => pluginExternals(), 2000 /* Priotiry.externals */, { format });
|
|
91
|
+
}
|
|
92
|
+
if (!allowGenericUmd && config.umdInputs.length > 0) {
|
|
93
|
+
for (const currentInput of config.umdInputs) {
|
|
94
|
+
provide(() => pluginExternals({
|
|
95
|
+
external: (id, external) => external || isExternalInput(currentInput, inputs, id, config)
|
|
96
|
+
}), 2000 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isExternalInput(currentInput, inputs, id, config) {
|
|
101
|
+
let normalizedPath;
|
|
102
|
+
if (path.isAbsolute(currentInput)) {
|
|
103
|
+
normalizedPath = './' + path.relative(process.cwd(), currentInput);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
normalizedPath = './' + path.join(config.sourceDir, currentInput + '.ts');
|
|
107
|
+
}
|
|
108
|
+
if (path.isAbsolute(id)) {
|
|
109
|
+
id = './' + path.relative(process.cwd(), id);
|
|
110
|
+
}
|
|
111
|
+
return normalizedPath !== id && inputs.includes(normalizedPath);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function preprocess (provide, config) {
|
|
115
|
+
if (config.preprocess.length > 0) {
|
|
116
|
+
const { default: pluginPreprocess } = await import('rollup-plugin-preprocess');
|
|
117
|
+
const include = config.preprocess.map(name => `${config.sourceDir}/${name}.ts`);
|
|
118
|
+
for (const format of config.formats) {
|
|
119
|
+
if (format !== 'umd') {
|
|
120
|
+
provide(() => pluginPreprocess({ include, context: { [format]: true } }), 1000 /* Priotiry.preprocess */, { format });
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
for (const currentInput of config.umdInputs) {
|
|
124
|
+
provide(() => pluginPreprocess({ include, context: { umd: true } }), 1000 /* Priotiry.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function resolve (provide) {
|
|
132
|
+
const { default: pluginResolve } = await import('@rollup/plugin-node-resolve');
|
|
133
|
+
provide(() => pluginResolve(), 3000 /* Priotiry.resolve */);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function terser (provide, config) {
|
|
137
|
+
if (config.compressFormats.length > 0) {
|
|
138
|
+
const { default: pluginTerser } = await import('@rollup/plugin-terser');
|
|
139
|
+
const options = {
|
|
140
|
+
mangle: {
|
|
141
|
+
properties: {
|
|
142
|
+
regex: /_$/
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const filteredFormats = config.compressFormats.filter(format => config.formats.includes(format));
|
|
147
|
+
if (filteredFormats.length > 0) {
|
|
148
|
+
for (const format of filteredFormats) {
|
|
149
|
+
if (format !== 'umd') {
|
|
150
|
+
provide(() => pluginTerser(options), 10000 /* Priotiry.compress */, { format, outputPlugin: true });
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
for (const currentInput of config.umdInputs) {
|
|
154
|
+
provide(() => pluginTerser(options), 10000 /* Priotiry.compress */, { format, outputPlugin: true, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function typescript (provide) {
|
|
163
|
+
const { default: pluginTypescript } = await import('rollup-plugin-typescript2');
|
|
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
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const plugins = [
|
|
182
|
+
clean,
|
|
183
|
+
commonjs,
|
|
184
|
+
externals,
|
|
185
|
+
preprocess,
|
|
186
|
+
resolve,
|
|
187
|
+
terser,
|
|
188
|
+
typescript,
|
|
189
|
+
binify
|
|
190
|
+
];
|
|
191
|
+
function createProvider() {
|
|
192
|
+
const plugins = [];
|
|
193
|
+
return [(plugin, priority, options) => {
|
|
194
|
+
plugins.push({ priority, plugin, format: options === null || options === void 0 ? void 0 : options.format, inputs: options === null || options === void 0 ? void 0 : options.inputs, outputPlugin: options === null || options === void 0 ? void 0 : options.outputPlugin });
|
|
195
|
+
}, plugins];
|
|
196
|
+
}
|
|
197
|
+
|
|
71
198
|
function getHelpers(name) {
|
|
72
199
|
function getGlobalName(anInput) {
|
|
73
200
|
return camelCase(path.join(name, path.basename(anInput, '.ts') !== 'index' ? path.basename(anInput, '.ts') : ''));
|
|
@@ -80,14 +207,9 @@ function getHelpers(name) {
|
|
|
80
207
|
}
|
|
81
208
|
return {
|
|
82
209
|
getGlobalName,
|
|
83
|
-
getExternalGlobalName
|
|
84
|
-
umdFilter
|
|
210
|
+
getExternalGlobalName
|
|
85
211
|
};
|
|
86
212
|
}
|
|
87
|
-
function umdFilter(config, filename) {
|
|
88
|
-
const id = path.basename(filename, '.ts');
|
|
89
|
-
return config.umdTargets.includes(id);
|
|
90
|
-
}
|
|
91
213
|
function toArray(object) {
|
|
92
214
|
if (Array.isArray(object)) {
|
|
93
215
|
return object;
|
|
@@ -97,21 +219,11 @@ function toArray(object) {
|
|
|
97
219
|
}
|
|
98
220
|
return [object];
|
|
99
221
|
}
|
|
100
|
-
function isExternalInput(id, inputs, currentInput, config) {
|
|
101
|
-
let normalizedPath;
|
|
102
|
-
if (path.isAbsolute(id)) {
|
|
103
|
-
normalizedPath = './' + path.relative(process.cwd(), id);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
normalizedPath = './' + path.join(config.sourceDir, id + '.ts');
|
|
107
|
-
}
|
|
108
|
-
return normalizedPath !== currentInput && inputs.includes(normalizedPath);
|
|
109
|
-
}
|
|
110
222
|
function formatInput(input) {
|
|
111
223
|
return (Array.isArray(input) ? input : [input !== null && input !== void 0 ? input : '']).map(item => kleur.magenta(path.basename(item, '.ts'))).join(', ');
|
|
112
224
|
}
|
|
113
225
|
function formatOutput(output, field) {
|
|
114
|
-
|
|
226
|
+
//? can we avoid it
|
|
115
227
|
if (output == null) {
|
|
116
228
|
return '';
|
|
117
229
|
}
|
|
@@ -123,89 +235,164 @@ function getTimeDiff(starting) {
|
|
|
123
235
|
return `${((now - starting) / 1000).toFixed(1)}s`;
|
|
124
236
|
}
|
|
125
237
|
return `${now - starting}ms`;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const clean = cleanFactory();
|
|
129
|
-
function getBuildPlugins(format, config, inputs, currentInput) {
|
|
130
|
-
const result = [
|
|
131
|
-
externals({
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
133
|
-
external: (id, external) => external || (format === 'umd' ? isExternalInput(id, inputs, currentInput, config) : false)
|
|
134
|
-
}),
|
|
135
|
-
resolve(),
|
|
136
|
-
commonjs(),
|
|
137
|
-
typescript()
|
|
138
|
-
];
|
|
139
|
-
if (config.preprocess.length) {
|
|
140
|
-
const context = { [format]: true };
|
|
141
|
-
result.unshift(preprocess({ include: config.preprocess.map(name => `${config.sourceDir}/${name}.ts`), context }));
|
|
142
|
-
}
|
|
143
|
-
return result;
|
|
144
238
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
239
|
+
const areSetsEqual = (a, b) => a.size === b.size ? [...a].every(value => b.has(value)) : false;
|
|
240
|
+
|
|
241
|
+
const fileNamePatterns = {
|
|
242
|
+
'es': '[name].mjs',
|
|
243
|
+
'cjs': '[name].cjs',
|
|
244
|
+
'umd': '[name].umd.js',
|
|
245
|
+
};
|
|
246
|
+
async function getRollupConfigs(inputs, config, helpers) {
|
|
247
|
+
var _a;
|
|
248
|
+
const [provide, plugins$1] = createProvider();
|
|
249
|
+
for (const factory of plugins) {
|
|
250
|
+
await factory(provide, config, inputs);
|
|
251
|
+
}
|
|
252
|
+
const expandInputs = new Set;
|
|
253
|
+
for (const plugin of plugins$1) {
|
|
254
|
+
if (plugin.format && ((_a = plugin.inputs) === null || _a === void 0 ? void 0 : _a.length) && !plugin.outputPlugin) {
|
|
255
|
+
for (const format of toArray(plugin.format)) {
|
|
256
|
+
expandInputs.add(format);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const refineNext = refiner();
|
|
261
|
+
refineNext(doExpandInputs(toArray(config.formats)));
|
|
262
|
+
for (const plugin of plugins$1) {
|
|
263
|
+
if (plugin.format && !plugin.outputPlugin) {
|
|
264
|
+
const formats = toArray(plugin.format);
|
|
265
|
+
if (!plugin.inputs || plugin.inputs.length === 0) {
|
|
266
|
+
refineNext(doExpandInputs(formats));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
if (inputs.length === 1) {
|
|
270
|
+
refineNext(formats);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
const expanded = [];
|
|
274
|
+
for (const format of formats) {
|
|
275
|
+
for (const input of plugin.inputs) {
|
|
276
|
+
expanded.push(`${format}.${input}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
refineNext(expanded);
|
|
154
280
|
}
|
|
155
281
|
}
|
|
156
|
-
}
|
|
282
|
+
}
|
|
157
283
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
284
|
+
const refined = refineNext();
|
|
285
|
+
const partitions = [];
|
|
286
|
+
for (const partition of refined) {
|
|
287
|
+
const result = [];
|
|
288
|
+
for (const format of partition) {
|
|
289
|
+
if (format.includes('.')) {
|
|
290
|
+
const [, realFormat, input] = format.split(/(.*?)\.(.*)/gm);
|
|
291
|
+
result.push({ format: realFormat, input });
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
result.push({ format });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const mapFormatInputs = new Map;
|
|
298
|
+
const formatsWithoutInputs = new Set;
|
|
299
|
+
for (const { format, input } of result) {
|
|
300
|
+
if (input) {
|
|
301
|
+
if (mapFormatInputs.has(format)) {
|
|
302
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
303
|
+
mapFormatInputs.get(format).add(input);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
mapFormatInputs.set(format, new Set([input]));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
formatsWithoutInputs.add(format);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
for (const format of formatsWithoutInputs) {
|
|
314
|
+
if (mapFormatInputs.has(format)) {
|
|
315
|
+
throw new Error(`${format} is both used with inputs and without in plugins configuration and was not expanded / handled correctly. Please file an issue for pkgbld.`);
|
|
316
|
+
}
|
|
317
|
+
mapFormatInputs.set(format, new Set(inputs));
|
|
318
|
+
}
|
|
319
|
+
let prevInputs;
|
|
320
|
+
for (const inputs of mapFormatInputs.values()) {
|
|
321
|
+
if (prevInputs) {
|
|
322
|
+
if (!areSetsEqual(inputs, prevInputs)) {
|
|
323
|
+
throw new Error(`unbalanced inputs for partition: ${JSON.stringify(partition)}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
prevInputs = inputs;
|
|
327
|
+
}
|
|
328
|
+
partitions.push({ formats: [...mapFormatInputs.keys()], inputs: [...prevInputs] });
|
|
329
|
+
}
|
|
330
|
+
return partitions.map(({ formats, inputs }) => {
|
|
331
|
+
return {
|
|
179
332
|
input: inputs,
|
|
180
|
-
output: {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
333
|
+
output: formats.map(format => (Object.assign({ format, dir: config.dir, entryFileNames: fileNamePatterns[format], plugins: getPlugins([format], inputs, true), sourcemap: config.sourcemapFormats.includes(format) }, getExtraOutputSettings(format, inputs)))),
|
|
334
|
+
plugins: getPlugins(formats, inputs, false)
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
function getExtraOutputSettings(format, inputs) {
|
|
338
|
+
switch (format) {
|
|
339
|
+
case 'cjs':
|
|
340
|
+
case 'es':
|
|
341
|
+
return { chunkFileNames: fileNamePatterns[format] };
|
|
342
|
+
case 'umd':
|
|
343
|
+
if (inputs.length <= 0) {
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
if (inputs.length > 1) {
|
|
347
|
+
throw new Error(`Cannot produce global name for mutliple umd inputs in one output: ${inputs}`);
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
name: helpers.getGlobalName(inputs[0]),
|
|
351
|
+
globals: helpers.getExternalGlobalName,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
return {};
|
|
355
|
+
}
|
|
356
|
+
function getPlugins(formats, inputs, outputPlugin) {
|
|
357
|
+
const filteredPlugins = [];
|
|
358
|
+
for (const plugin of plugins$1) {
|
|
359
|
+
if ((!!plugin.outputPlugin) === outputPlugin) {
|
|
360
|
+
if ((!plugin.format || toArray(plugin.format).some(format => formats.includes(format)))
|
|
361
|
+
&& (!plugin.inputs || plugin.inputs.every(input => inputs.includes(input)))) {
|
|
362
|
+
filteredPlugins.push({
|
|
363
|
+
instance: plugin.plugin(),
|
|
364
|
+
priority: plugin.priority
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
filteredPlugins.sort((a, b) => a.priority - b.priority);
|
|
370
|
+
return filteredPlugins.map(plugin => plugin.instance);
|
|
371
|
+
}
|
|
372
|
+
function doExpandInputs(formats) {
|
|
373
|
+
if (inputs.length === 1) {
|
|
374
|
+
return formats;
|
|
375
|
+
}
|
|
376
|
+
const expanded = [];
|
|
377
|
+
for (const format of formats) {
|
|
378
|
+
if (expandInputs.has(format)) {
|
|
379
|
+
if (format !== 'umd') {
|
|
380
|
+
for (const input of inputs) {
|
|
381
|
+
expanded.push(`${format}.${input}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
for (const input of config.umdInputs) {
|
|
386
|
+
expanded.push(`${format}../${config.sourceDir}/${input}.ts`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
expanded.push(format);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return expanded;
|
|
395
|
+
}
|
|
209
396
|
}
|
|
210
397
|
|
|
211
398
|
const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
|
|
@@ -214,6 +401,9 @@ function processPackage(pkg, config) {
|
|
|
214
401
|
var _a;
|
|
215
402
|
const input = [];
|
|
216
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);
|
|
217
407
|
if (typeof pkg !== 'object' || Array.isArray(pkg)) {
|
|
218
408
|
logger$1.finish('expecting object on top level of package.json', 3 /* LogLevel.error */);
|
|
219
409
|
process.exit(-1);
|
|
@@ -235,25 +425,47 @@ function processPackage(pkg, config) {
|
|
|
235
425
|
pkg.exports['.'] = {};
|
|
236
426
|
}
|
|
237
427
|
pkg.exports['./package.json'] = './package.json';
|
|
238
|
-
if (typeof pkg.umd === 'string') {
|
|
428
|
+
if (allowUmd && typeof pkg.umd === 'string') {
|
|
239
429
|
pkg.umd = `./${config.dir}/index.umd.js`;
|
|
240
|
-
if (!config.
|
|
241
|
-
config.
|
|
430
|
+
if (!config.umdInputs.includes('index')) {
|
|
431
|
+
config.umdInputs.push('index');
|
|
432
|
+
}
|
|
433
|
+
}
|
|
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
|
+
}
|
|
242
446
|
}
|
|
243
447
|
}
|
|
244
|
-
|
|
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') {
|
|
245
457
|
pkg.main = `./${config.dir}/index.cjs`;
|
|
246
458
|
}
|
|
247
|
-
if (pkg.main !== pkg.exports['.'].require) {
|
|
459
|
+
if (allowCjs && pkg.main !== pkg.exports['.'].require) {
|
|
248
460
|
pkg.exports['.'].require = pkg.main;
|
|
249
461
|
}
|
|
250
|
-
if (typeof pkg.module !== 'string') {
|
|
462
|
+
if (allowEsm && typeof pkg.module !== 'string') {
|
|
251
463
|
pkg.module = `./${config.dir}/index.mjs`;
|
|
252
464
|
}
|
|
253
|
-
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)) {
|
|
254
466
|
pkg.exports['.'].default = pkg.module;
|
|
255
467
|
}
|
|
256
|
-
if (
|
|
468
|
+
if (allowUmd && config.umdInputs.includes('index')) {
|
|
257
469
|
pkg.unpkg = `./${config.dir}/index.umd.js`;
|
|
258
470
|
}
|
|
259
471
|
for (const id in pkg.exports) {
|
|
@@ -263,8 +475,12 @@ function processPackage(pkg, config) {
|
|
|
263
475
|
if (typeof pkg.exports[id] !== 'object') {
|
|
264
476
|
pkg.exports[id] = {};
|
|
265
477
|
}
|
|
266
|
-
|
|
267
|
-
|
|
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
|
+
}
|
|
268
484
|
if (basename !== 'index') {
|
|
269
485
|
if (!pkg.files.includes(basename)) {
|
|
270
486
|
pkg.files.push(basename);
|
|
@@ -272,6 +488,9 @@ function processPackage(pkg, config) {
|
|
|
272
488
|
}
|
|
273
489
|
input.push(`./${config.sourceDir}/${basename}.ts`);
|
|
274
490
|
}
|
|
491
|
+
if (allowUmd && config.umdInputs.length > 0 && !config.formats.includes('umd')) {
|
|
492
|
+
config.formats.push('umd');
|
|
493
|
+
}
|
|
275
494
|
return input;
|
|
276
495
|
}
|
|
277
496
|
|
|
@@ -290,7 +509,7 @@ async function execute() {
|
|
|
290
509
|
const options = getCliOptions();
|
|
291
510
|
const inputs = processPackage(pkg, options);
|
|
292
511
|
const helpers = getHelpers(pkg.name);
|
|
293
|
-
const rollupConfigs = getRollupConfigs(inputs, options, helpers);
|
|
512
|
+
const rollupConfigs = await getRollupConfigs(inputs, options, helpers);
|
|
294
513
|
const updater = mainLoggerText(options.sourceDir, options.dir, rollupConfigs.length, time);
|
|
295
514
|
mainLogger.start(updater());
|
|
296
515
|
await Promise.all(rollupConfigs.map(config => buildConfig(config, updater)));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { Plugin, InternalModuleFormat } from 'rollup';
|
|
2
|
+
/**
|
|
3
|
+
* export interface Replacer {
|
|
2
4
|
name: string;
|
|
3
5
|
used: () => void;
|
|
4
|
-
}
|
|
6
|
+
}*/
|
|
5
7
|
export type Json = null | string | number | boolean | Json[] | {
|
|
6
8
|
[name: string]: Json;
|
|
7
9
|
};
|
|
10
|
+
export declare const enum Priotiry {
|
|
11
|
+
preprocess = 1000,
|
|
12
|
+
cleanup = 1000,
|
|
13
|
+
externals = 2000,
|
|
14
|
+
resolve = 3000,
|
|
15
|
+
commonjs = 4000,
|
|
16
|
+
transpile = 6000,
|
|
17
|
+
compress = 10000,
|
|
18
|
+
finalize = 20000
|
|
19
|
+
}
|
|
20
|
+
export type Provider = (factory: () => Plugin, priority: Priotiry, options?: {
|
|
21
|
+
format?: InternalModuleFormat | InternalModuleFormat[];
|
|
22
|
+
inputs?: string[];
|
|
23
|
+
outputPlugin?: true;
|
|
24
|
+
}) => void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
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"
|
|
@@ -34,32 +35,33 @@
|
|
|
34
35
|
"semantic-release": "npx semantic-release"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@semantic-release/changelog": "6.0.
|
|
38
|
+
"@semantic-release/changelog": "6.0.2",
|
|
38
39
|
"@semantic-release/commit-analyzer": "9.0.2",
|
|
39
40
|
"@semantic-release/git": "10.0.1",
|
|
40
|
-
"@semantic-release/npm": "9.0.
|
|
41
|
+
"@semantic-release/npm": "9.0.2",
|
|
41
42
|
"@semantic-release/release-notes-generator": "10.0.3",
|
|
42
|
-
"@types/lodash": "4.14.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
44
|
-
"@typescript-eslint/parser": "5.
|
|
43
|
+
"@types/lodash": "4.14.191",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "5.48.1",
|
|
45
|
+
"@typescript-eslint/parser": "5.48.1",
|
|
45
46
|
"conventional-changelog-angular": "5.0.13",
|
|
46
|
-
"eslint": "8.
|
|
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": {
|
|
52
52
|
"@niceties/logger": "1.1.10",
|
|
53
53
|
"@niceties/draftlog-appender": "1.3.0",
|
|
54
54
|
"lodash": "4.17.21",
|
|
55
|
-
"rollup": "3.
|
|
55
|
+
"rollup": "3.12.0",
|
|
56
56
|
"rollup-plugin-typescript2": "0.34.1",
|
|
57
57
|
"rollup-plugin-preprocess": "0.0.4",
|
|
58
|
-
"@rollup/plugin-commonjs": "24.0.
|
|
59
|
-
"@rollup/plugin-terser": "0.
|
|
58
|
+
"@rollup/plugin-commonjs": "24.0.1",
|
|
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",
|
|
64
|
+
"@slimlib/refine-partition": "1.0.0",
|
|
63
65
|
"typescript": "4.9.4",
|
|
64
66
|
"minimist": "1.2.7",
|
|
65
67
|
"kleur": "4.1.5"
|