pkgbld 1.15.0 → 1.15.2
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/eject.d.ts +1 -1
- package/dist/get-plugins.d.ts +1 -1
- package/dist/index.js +21 -10
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/eject.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { PackageJson, PkgbldRollupPlugin, Provider } from './types';
|
|
|
2
2
|
import type { RollupOptions } from 'rollup';
|
|
3
3
|
import { getCliOptions } from './get-cli-options';
|
|
4
4
|
import { getHelpers } from './helpers';
|
|
5
|
-
export declare function createEjectProvider(): Promise<[Provider, PkgbldRollupPlugin[]]>;
|
|
5
|
+
export declare function createEjectProvider(preimportMap: Map<string, Promise<never>>): Promise<[Provider, PkgbldRollupPlugin[]]>;
|
|
6
6
|
export declare function ejectConfig(config: RollupOptions[], pkgPath: string, options: ReturnType<typeof getCliOptions>, inputs: string[], helpers: ReturnType<typeof getHelpers>, pkg: PackageJson): Promise<void>;
|
package/dist/get-plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PkgbldRollupPlugin, Provider } from './types';
|
|
2
2
|
import externals from './builtin-plugins/externals';
|
|
3
3
|
export declare const plugins: (typeof externals)[];
|
|
4
|
-
export declare function createProvider(): [Provider, PkgbldRollupPlugin[]];
|
|
4
|
+
export declare function createProvider(preimportMap: Map<string, Promise<never>>): [Provider, PkgbldRollupPlugin[]];
|
package/dist/index.js
CHANGED
|
@@ -106,14 +106,16 @@ async function externals (provider, config, inputs) {
|
|
|
106
106
|
provider.provide(() => pluginExternals(), 2000 /* Priotiry.externals */, { format });
|
|
107
107
|
}
|
|
108
108
|
if (!allowGenericUmd && config.umdInputs.length > 0) {
|
|
109
|
+
const curry = (await provider.import('lodash/curry.js'));
|
|
109
110
|
for (const currentInput of config.umdInputs) {
|
|
111
|
+
const isExternal = curry((currentInput, id, external) => external || isExternalInput(currentInput, inputs, id, config))(currentInput);
|
|
110
112
|
provider.provide(() => pluginExternals({
|
|
111
|
-
external:
|
|
113
|
+
external: isExternal
|
|
112
114
|
}), 2000 /* Priotiry.externals */, { format: 'umd', inputs: [`./${config.sourceDir}/${currentInput}.ts`] });
|
|
113
115
|
}
|
|
114
116
|
// for eject config
|
|
115
117
|
provider.globalImport('path', 'path');
|
|
116
|
-
provider.
|
|
118
|
+
provider.globalSetup(isExternalInput);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
function isExternalInput(currentInput, inputs, id, config) {
|
|
@@ -207,18 +209,18 @@ const plugins = [
|
|
|
207
209
|
binify
|
|
208
210
|
];
|
|
209
211
|
const noop = () => undefined;
|
|
210
|
-
function createProvider() {
|
|
212
|
+
function createProvider(preimportMap) {
|
|
211
213
|
const plugins = [];
|
|
212
214
|
return [{
|
|
213
215
|
provide: (plugin, priority, options) => {
|
|
214
216
|
plugins.push({ priority, plugin, format: options?.format, inputs: options?.inputs, outputPlugin: options?.outputPlugin });
|
|
215
217
|
},
|
|
216
218
|
import: async (name, exportName) => {
|
|
217
|
-
const result = await import(name);
|
|
219
|
+
const result = preimportMap.has(name) ? await preimportMap.get(name) : await import(name);
|
|
218
220
|
return result[exportName ?? 'default'];
|
|
219
221
|
},
|
|
220
222
|
globalImport: noop,
|
|
221
|
-
|
|
223
|
+
globalSetup: noop
|
|
222
224
|
}, plugins];
|
|
223
225
|
}
|
|
224
226
|
|
|
@@ -532,7 +534,7 @@ async function writeJson(path, json) {
|
|
|
532
534
|
const imports = new Map;
|
|
533
535
|
const setup = new Set;
|
|
534
536
|
let generate, generateGlobals;
|
|
535
|
-
async function createEjectProvider() {
|
|
537
|
+
async function createEjectProvider(preimportMap) {
|
|
536
538
|
const createMockProvider = (await import('@slimlib/smart-mock')).default;
|
|
537
539
|
const provider = createMockProvider();
|
|
538
540
|
const createMock = provider.createMock;
|
|
@@ -544,7 +546,7 @@ async function createEjectProvider() {
|
|
|
544
546
|
plugins.push({ priority, plugin, format: options?.format, inputs: options?.inputs, outputPlugin: options?.outputPlugin });
|
|
545
547
|
},
|
|
546
548
|
import: async (name, exportName) => {
|
|
547
|
-
const result = await import(name);
|
|
549
|
+
const result = preimportMap.has(name) ? await preimportMap.get(name) : await import(name);
|
|
548
550
|
const exports = result[exportName ?? 'default'];
|
|
549
551
|
const mangledName = lodash.camelCase(name);
|
|
550
552
|
imports.set(name, mangledName);
|
|
@@ -554,7 +556,7 @@ async function createEjectProvider() {
|
|
|
554
556
|
imports.set(module, exportName ?? 'default');
|
|
555
557
|
},
|
|
556
558
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
557
|
-
|
|
559
|
+
globalSetup: (code) => {
|
|
558
560
|
if (typeof code === 'function') {
|
|
559
561
|
setup.add(code.toString());
|
|
560
562
|
}
|
|
@@ -583,6 +585,7 @@ async function ejectConfig(config, pkgPath, options, inputs, helpers, pkg) {
|
|
|
583
585
|
.join('\n');
|
|
584
586
|
const setupString = Array.from(setup)
|
|
585
587
|
.join('\n');
|
|
588
|
+
console.log(setupString);
|
|
586
589
|
const { minify } = await import('terser');
|
|
587
590
|
const result = await minify(`${importsString}\n${setupString}\nexport default ${text};`, {
|
|
588
591
|
module: true,
|
|
@@ -643,6 +646,7 @@ async function checkTsConfig(options, mainLogger) {
|
|
|
643
646
|
mainLogger('done');
|
|
644
647
|
}
|
|
645
648
|
|
|
649
|
+
execute();
|
|
646
650
|
async function execute() {
|
|
647
651
|
const time = Date.now();
|
|
648
652
|
logger.createLogger().update(' '); // blank line
|
|
@@ -654,7 +658,8 @@ async function execute() {
|
|
|
654
658
|
checkTsConfig(options, mainLogger);
|
|
655
659
|
const inputs = processPackage(pkg, options);
|
|
656
660
|
const helpers = getHelpers(pkg.name);
|
|
657
|
-
const
|
|
661
|
+
const preimportMap = preimport();
|
|
662
|
+
const provider = options.eject ? await createEjectProvider(preimportMap) : createProvider(preimportMap);
|
|
658
663
|
const rollupConfigs = await getRollupConfigs(provider, inputs, options, helpers);
|
|
659
664
|
if (options.eject) {
|
|
660
665
|
await ejectConfig(rollupConfigs, pkgPath, options, inputs, helpers, pkg);
|
|
@@ -687,4 +692,10 @@ async function execute() {
|
|
|
687
692
|
mainLogger.update(updater());
|
|
688
693
|
}
|
|
689
694
|
}
|
|
690
|
-
|
|
695
|
+
function preimport() {
|
|
696
|
+
return (process.env.PKGBLD_INTERNAL ? new Map([
|
|
697
|
+
['@rollup-extras/plugin-binify', import('@rollup-extras/plugin-binify')],
|
|
698
|
+
['@rollup-extras/plugin-clean', import('@rollup-extras/plugin-clean')],
|
|
699
|
+
['@rollup-extras/plugin-externals', import('@rollup-extras/plugin-externals')]
|
|
700
|
+
]) : new Map);
|
|
701
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type Provider = {
|
|
|
32
32
|
provide: ProvideFunction;
|
|
33
33
|
import: (module: string, exportName?: string) => Promise<((...args: unknown[]) => Plugin)>;
|
|
34
34
|
globalImport: (module: string, exportName?: string | string[]) => void;
|
|
35
|
-
|
|
35
|
+
globalSetup: (code: Function | string) => void;
|
|
36
36
|
};
|
|
37
37
|
export type PkgbldRollupPlugin = {
|
|
38
38
|
plugin: () => Plugin;
|
package/package.json
CHANGED