pkgbld 1.11.2 → 1.12.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/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 +3 -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 +287 -115
- package/dist/types.d.ts +18 -2
- package/package.json +11 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare function getCliOptions(): {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
umdInputs: string[];
|
|
3
|
+
compressFormats: string[];
|
|
4
|
+
sourcemapFormats: string[];
|
|
5
5
|
formats: string[];
|
|
6
6
|
preprocess: string[];
|
|
7
7
|
dir: string;
|
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,9 +28,9 @@ 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'
|
|
@@ -44,17 +38,17 @@ const defaults = {
|
|
|
44
38
|
function getCliOptions() {
|
|
45
39
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
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;
|
|
54
48
|
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
umdInputs,
|
|
50
|
+
compressFormats,
|
|
51
|
+
sourcemapFormats,
|
|
58
52
|
formats,
|
|
59
53
|
preprocess,
|
|
60
54
|
dir,
|
|
@@ -68,6 +62,121 @@ async function getPackage() {
|
|
|
68
62
|
return [pkgPath, JSON.parse(buffer.toString())];
|
|
69
63
|
}
|
|
70
64
|
|
|
65
|
+
async function clean (provide) {
|
|
66
|
+
const { default: pluginClean } = await import('@rollup-extras/plugin-clean');
|
|
67
|
+
const pluginInstance = pluginClean();
|
|
68
|
+
provide(pluginFactory, 100 /* Priotiry.cleanup */, { outputPlugin: true });
|
|
69
|
+
let firstPluginInstance = true;
|
|
70
|
+
function pluginFactory() {
|
|
71
|
+
const result = firstPluginInstance ? pluginInstance : pluginInstance.api.addInstance();
|
|
72
|
+
firstPluginInstance = false;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function commonjs (provide) {
|
|
78
|
+
const { default: pluginCommonjs } = await import('@rollup/plugin-commonjs');
|
|
79
|
+
provide(() => pluginCommonjs(), 400 /* Priotiry.commonjs */);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function externals (provide, config, inputs) {
|
|
83
|
+
const { default: pluginExternals } = await import('@rollup-extras/plugin-externals');
|
|
84
|
+
const allowGenericUmd = config.umdInputs.length === 1 && inputs.length === 1;
|
|
85
|
+
if (config.formats.length > 0) {
|
|
86
|
+
const format = (allowGenericUmd ? undefined : config.formats.filter(format => format !== 'umd'));
|
|
87
|
+
provide(() => pluginExternals(), 200 /* Priotiry.externals */, { format });
|
|
88
|
+
}
|
|
89
|
+
if (!allowGenericUmd && config.umdInputs.length > 0) {
|
|
90
|
+
for (const currentInput of config.umdInputs) {
|
|
91
|
+
provide(() => pluginExternals({
|
|
92
|
+
external: (id, external) => external || isExternalInput(currentInput, inputs, id, config)
|
|
93
|
+
}), 200 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isExternalInput(currentInput, inputs, id, config) {
|
|
98
|
+
let normalizedPath;
|
|
99
|
+
if (path.isAbsolute(currentInput)) {
|
|
100
|
+
normalizedPath = './' + path.relative(process.cwd(), currentInput);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
normalizedPath = './' + path.join(config.sourceDir, currentInput + '.ts');
|
|
104
|
+
}
|
|
105
|
+
if (path.isAbsolute(id)) {
|
|
106
|
+
id = './' + path.relative(process.cwd(), id);
|
|
107
|
+
}
|
|
108
|
+
return normalizedPath !== id && inputs.includes(normalizedPath);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function preprocess (provide, config) {
|
|
112
|
+
if (config.preprocess.length > 0) {
|
|
113
|
+
const { default: pluginPreprocess } = await import('rollup-plugin-preprocess');
|
|
114
|
+
const include = config.preprocess.map(name => `${config.sourceDir}/${name}.ts`);
|
|
115
|
+
for (const format of config.formats) {
|
|
116
|
+
if (format !== 'umd') {
|
|
117
|
+
provide(() => pluginPreprocess({ include, context: { [format]: true } }), 100 /* Priotiry.preprocess */, { format });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
for (const currentInput of config.umdInputs) {
|
|
121
|
+
provide(() => pluginPreprocess({ include, context: { umd: true } }), 100 /* Priotiry.preprocess */, { format, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function resolve (provide) {
|
|
129
|
+
const { default: pluginResolve } = await import('@rollup/plugin-node-resolve');
|
|
130
|
+
provide(() => pluginResolve(), 300 /* Priotiry.resolve */);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function terser (provide, config) {
|
|
134
|
+
if (config.compressFormats.length > 0) {
|
|
135
|
+
const { default: pluginTerser } = await import('@rollup/plugin-terser');
|
|
136
|
+
const options = {
|
|
137
|
+
mangle: {
|
|
138
|
+
properties: {
|
|
139
|
+
regex: /_$/
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const filteredFormats = config.compressFormats.filter(format => config.formats.includes(format));
|
|
144
|
+
if (filteredFormats.length > 0) {
|
|
145
|
+
for (const format of filteredFormats) {
|
|
146
|
+
if (format !== 'umd') {
|
|
147
|
+
provide(() => pluginTerser(options), 10000 /* Priotiry.compress */, { format, outputPlugin: true });
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
for (const currentInput of config.umdInputs) {
|
|
151
|
+
provide(() => pluginTerser(options), 10000 /* Priotiry.compress */, { format, outputPlugin: true, inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function typescript (provide) {
|
|
160
|
+
const { default: pluginTypescript } = await import('rollup-plugin-typescript2');
|
|
161
|
+
provide(() => pluginTypescript(), 600 /* Priotiry.transpile */);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const plugins = [
|
|
165
|
+
clean,
|
|
166
|
+
commonjs,
|
|
167
|
+
externals,
|
|
168
|
+
preprocess,
|
|
169
|
+
resolve,
|
|
170
|
+
terser,
|
|
171
|
+
typescript
|
|
172
|
+
];
|
|
173
|
+
function createProvider() {
|
|
174
|
+
const plugins = [];
|
|
175
|
+
return [(plugin, priority, options) => {
|
|
176
|
+
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 });
|
|
177
|
+
}, plugins];
|
|
178
|
+
}
|
|
179
|
+
|
|
71
180
|
function getHelpers(name) {
|
|
72
181
|
function getGlobalName(anInput) {
|
|
73
182
|
return camelCase(path.join(name, path.basename(anInput, '.ts') !== 'index' ? path.basename(anInput, '.ts') : ''));
|
|
@@ -80,14 +189,9 @@ function getHelpers(name) {
|
|
|
80
189
|
}
|
|
81
190
|
return {
|
|
82
191
|
getGlobalName,
|
|
83
|
-
getExternalGlobalName
|
|
84
|
-
umdFilter
|
|
192
|
+
getExternalGlobalName
|
|
85
193
|
};
|
|
86
194
|
}
|
|
87
|
-
function umdFilter(config, filename) {
|
|
88
|
-
const id = path.basename(filename, '.ts');
|
|
89
|
-
return config.umdTargets.includes(id);
|
|
90
|
-
}
|
|
91
195
|
function toArray(object) {
|
|
92
196
|
if (Array.isArray(object)) {
|
|
93
197
|
return object;
|
|
@@ -97,21 +201,11 @@ function toArray(object) {
|
|
|
97
201
|
}
|
|
98
202
|
return [object];
|
|
99
203
|
}
|
|
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
204
|
function formatInput(input) {
|
|
111
205
|
return (Array.isArray(input) ? input : [input !== null && input !== void 0 ? input : '']).map(item => kleur.magenta(path.basename(item, '.ts'))).join(', ');
|
|
112
206
|
}
|
|
113
207
|
function formatOutput(output, field) {
|
|
114
|
-
|
|
208
|
+
//? can we avoid it
|
|
115
209
|
if (output == null) {
|
|
116
210
|
return '';
|
|
117
211
|
}
|
|
@@ -123,89 +217,164 @@ function getTimeDiff(starting) {
|
|
|
123
217
|
return `${((now - starting) / 1000).toFixed(1)}s`;
|
|
124
218
|
}
|
|
125
219
|
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
220
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
221
|
+
const areSetsEqual = (a, b) => a.size === b.size ? [...a].every(value => b.has(value)) : false;
|
|
222
|
+
|
|
223
|
+
const fileNamePatterns = {
|
|
224
|
+
'es': '[name].mjs',
|
|
225
|
+
'cjs': '[name].cjs',
|
|
226
|
+
'umd': '[name].umd.js',
|
|
227
|
+
};
|
|
228
|
+
async function getRollupConfigs(inputs, config, helpers) {
|
|
229
|
+
var _a;
|
|
230
|
+
const [provide, plugins$1] = createProvider();
|
|
231
|
+
for (const factory of plugins) {
|
|
232
|
+
await factory(provide, config, inputs);
|
|
233
|
+
}
|
|
234
|
+
const expandInputs = new Set;
|
|
235
|
+
for (const plugin of plugins$1) {
|
|
236
|
+
if (plugin.format && ((_a = plugin.inputs) === null || _a === void 0 ? void 0 : _a.length) && !plugin.outputPlugin) {
|
|
237
|
+
for (const format of toArray(plugin.format)) {
|
|
238
|
+
expandInputs.add(format);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const refineNext = refiner();
|
|
243
|
+
refineNext(doExpandInputs(toArray(config.formats)));
|
|
244
|
+
for (const plugin of plugins$1) {
|
|
245
|
+
if (plugin.format && !plugin.outputPlugin) {
|
|
246
|
+
const formats = toArray(plugin.format);
|
|
247
|
+
if (!plugin.inputs || plugin.inputs.length === 0) {
|
|
248
|
+
refineNext(doExpandInputs(formats));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
if (inputs.length === 1) {
|
|
252
|
+
refineNext(formats);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const expanded = [];
|
|
256
|
+
for (const format of formats) {
|
|
257
|
+
for (const input of plugin.inputs) {
|
|
258
|
+
expanded.push(`${format}.${input}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
refineNext(expanded);
|
|
154
262
|
}
|
|
155
263
|
}
|
|
156
|
-
}
|
|
264
|
+
}
|
|
157
265
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
266
|
+
const refined = refineNext();
|
|
267
|
+
const partitions = [];
|
|
268
|
+
for (const partition of refined) {
|
|
269
|
+
const result = [];
|
|
270
|
+
for (const format of partition) {
|
|
271
|
+
if (format.includes('.')) {
|
|
272
|
+
const [, realFormat, input] = format.split(/(.*?)\.(.*)/gm);
|
|
273
|
+
result.push({ format: realFormat, input });
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
result.push({ format });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const mapFormatInputs = new Map;
|
|
280
|
+
const formatsWithoutInputs = new Set;
|
|
281
|
+
for (const { format, input } of result) {
|
|
282
|
+
if (input) {
|
|
283
|
+
if (mapFormatInputs.has(format)) {
|
|
284
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
285
|
+
mapFormatInputs.get(format).add(input);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
mapFormatInputs.set(format, new Set([input]));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
formatsWithoutInputs.add(format);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
for (const format of formatsWithoutInputs) {
|
|
296
|
+
if (mapFormatInputs.has(format)) {
|
|
297
|
+
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.`);
|
|
298
|
+
}
|
|
299
|
+
mapFormatInputs.set(format, new Set(inputs));
|
|
300
|
+
}
|
|
301
|
+
let prevInputs;
|
|
302
|
+
for (const inputs of mapFormatInputs.values()) {
|
|
303
|
+
if (prevInputs) {
|
|
304
|
+
if (!areSetsEqual(inputs, prevInputs)) {
|
|
305
|
+
throw new Error(`unbalanced inputs for partition: ${JSON.stringify(partition)}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
prevInputs = inputs;
|
|
309
|
+
}
|
|
310
|
+
partitions.push({ formats: [...mapFormatInputs.keys()], inputs: [...prevInputs] });
|
|
311
|
+
}
|
|
312
|
+
return partitions.map(({ formats, inputs }) => {
|
|
313
|
+
return {
|
|
179
314
|
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
|
-
|
|
315
|
+
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)))),
|
|
316
|
+
plugins: getPlugins(formats, inputs, false)
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
function getExtraOutputSettings(format, inputs) {
|
|
320
|
+
switch (format) {
|
|
321
|
+
case 'cjs':
|
|
322
|
+
case 'es':
|
|
323
|
+
return { chunkFileNames: fileNamePatterns[format] };
|
|
324
|
+
case 'umd':
|
|
325
|
+
if (inputs.length <= 0) {
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
if (inputs.length > 1) {
|
|
329
|
+
throw new Error(`Cannot produce global name for mutliple umd inputs in one output: ${inputs}`);
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
name: helpers.getGlobalName(inputs[0]),
|
|
333
|
+
globals: helpers.getExternalGlobalName,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
function getPlugins(formats, inputs, outputPlugin) {
|
|
339
|
+
const filteredPlugins = [];
|
|
340
|
+
for (const plugin of plugins$1) {
|
|
341
|
+
if ((!!plugin.outputPlugin) === outputPlugin) {
|
|
342
|
+
if ((!plugin.format || toArray(plugin.format).some(format => formats.includes(format)))
|
|
343
|
+
&& (!plugin.inputs || plugin.inputs.every(input => inputs.includes(input)))) {
|
|
344
|
+
filteredPlugins.push({
|
|
345
|
+
instance: plugin.plugin(),
|
|
346
|
+
priority: plugin.priority
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
filteredPlugins.sort((a, b) => a.priority - b.priority);
|
|
352
|
+
return filteredPlugins.map(plugin => plugin.instance);
|
|
353
|
+
}
|
|
354
|
+
function doExpandInputs(formats) {
|
|
355
|
+
if (inputs.length === 1) {
|
|
356
|
+
return formats;
|
|
357
|
+
}
|
|
358
|
+
const expanded = [];
|
|
359
|
+
for (const format of formats) {
|
|
360
|
+
if (expandInputs.has(format)) {
|
|
361
|
+
if (format !== 'umd') {
|
|
362
|
+
for (const input of inputs) {
|
|
363
|
+
expanded.push(`${format}.${input}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
for (const input of config.umdInputs) {
|
|
368
|
+
expanded.push(`${format}../${config.sourceDir}/${input}.ts`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
expanded.push(format);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return expanded;
|
|
377
|
+
}
|
|
209
378
|
}
|
|
210
379
|
|
|
211
380
|
const mainLoggerText = (sourceDir, dir, configsCount, startingTime, finishedCount = 0) => (final = false) => `${sourceDir} → ${dir} ${final ? configsCount : finishedCount++} / ${configsCount}${final ? (' in ' + getTimeDiff(startingTime)) : ''}`;
|
|
@@ -237,8 +406,8 @@ function processPackage(pkg, config) {
|
|
|
237
406
|
pkg.exports['./package.json'] = './package.json';
|
|
238
407
|
if (typeof pkg.umd === 'string') {
|
|
239
408
|
pkg.umd = `./${config.dir}/index.umd.js`;
|
|
240
|
-
if (!config.
|
|
241
|
-
config.
|
|
409
|
+
if (!config.umdInputs.includes('index')) {
|
|
410
|
+
config.umdInputs.push('index');
|
|
242
411
|
}
|
|
243
412
|
}
|
|
244
413
|
if (typeof pkg.main !== 'string') {
|
|
@@ -253,7 +422,7 @@ function processPackage(pkg, config) {
|
|
|
253
422
|
if (pkg.module !== ((_a = pkg.exports['.']) === null || _a === void 0 ? void 0 : _a.default)) {
|
|
254
423
|
pkg.exports['.'].default = pkg.module;
|
|
255
424
|
}
|
|
256
|
-
if (
|
|
425
|
+
if (config.umdInputs.includes('index')) {
|
|
257
426
|
pkg.unpkg = `./${config.dir}/index.umd.js`;
|
|
258
427
|
}
|
|
259
428
|
for (const id in pkg.exports) {
|
|
@@ -272,6 +441,9 @@ function processPackage(pkg, config) {
|
|
|
272
441
|
}
|
|
273
442
|
input.push(`./${config.sourceDir}/${basename}.ts`);
|
|
274
443
|
}
|
|
444
|
+
if (config.umdInputs.length > 0 && !config.formats.includes('umd')) {
|
|
445
|
+
config.formats.push('umd');
|
|
446
|
+
}
|
|
275
447
|
return input;
|
|
276
448
|
}
|
|
277
449
|
|
|
@@ -290,7 +462,7 @@ async function execute() {
|
|
|
290
462
|
const options = getCliOptions();
|
|
291
463
|
const inputs = processPackage(pkg, options);
|
|
292
464
|
const helpers = getHelpers(pkg.name);
|
|
293
|
-
const rollupConfigs = getRollupConfigs(inputs, options, helpers);
|
|
465
|
+
const rollupConfigs = await getRollupConfigs(inputs, options, helpers);
|
|
294
466
|
const updater = mainLoggerText(options.sourceDir, options.dir, rollupConfigs.length, time);
|
|
295
467
|
mainLogger.start(updater());
|
|
296
468
|
await Promise.all(rollupConfigs.map(config => buildConfig(config, updater)));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
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 = 100,
|
|
12
|
+
cleanup = 100,
|
|
13
|
+
externals = 200,
|
|
14
|
+
resolve = 300,
|
|
15
|
+
commonjs = 400,
|
|
16
|
+
transpile = 600,
|
|
17
|
+
compress = 10000
|
|
18
|
+
}
|
|
19
|
+
export type Provider = (factory: () => Plugin, priority: Priotiry, options?: {
|
|
20
|
+
format?: InternalModuleFormat | InternalModuleFormat[];
|
|
21
|
+
inputs?: string[];
|
|
22
|
+
outputPlugin?: true;
|
|
23
|
+
}) => void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.12.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "pkgbld",
|
|
5
5
|
"author": {
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"semantic-release": "npx semantic-release"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@semantic-release/changelog": "6.0.
|
|
37
|
+
"@semantic-release/changelog": "6.0.2",
|
|
38
38
|
"@semantic-release/commit-analyzer": "9.0.2",
|
|
39
39
|
"@semantic-release/git": "10.0.1",
|
|
40
|
-
"@semantic-release/npm": "9.0.
|
|
40
|
+
"@semantic-release/npm": "9.0.2",
|
|
41
41
|
"@semantic-release/release-notes-generator": "10.0.3",
|
|
42
|
-
"@types/lodash": "4.14.
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
44
|
-
"@typescript-eslint/parser": "5.
|
|
42
|
+
"@types/lodash": "4.14.191",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "5.48.1",
|
|
44
|
+
"@typescript-eslint/parser": "5.48.1",
|
|
45
45
|
"conventional-changelog-angular": "5.0.13",
|
|
46
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.33.0",
|
|
47
47
|
"semantic-release": "19.0.5",
|
|
48
48
|
"@rollup-extras/plugin-binify": "1.1.5",
|
|
49
49
|
"@types/node": "18.11.18"
|
|
@@ -52,14 +52,15 @@
|
|
|
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
62
|
"@rollup-extras/plugin-externals": "1.1.7",
|
|
63
|
+
"@slimlib/refine-partition": "1.0.0",
|
|
63
64
|
"typescript": "4.9.4",
|
|
64
65
|
"minimist": "1.2.7",
|
|
65
66
|
"kleur": "4.1.5"
|