rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.2-commit.afd0727
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/cjs/cli.cjs +981 -25
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +981 -26
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{binding-Bl7VQy7c.mjs → binding-l7VLSKnB.mjs} +3 -3
- package/dist/shared/{binding-fhgdIkpS.cjs → binding-orkvONpS.cjs} +3 -3
- package/dist/shared/prompt-B7tq3GL9.cjs +854 -0
- package/dist/shared/prompt-Nfm4Xz36.mjs +851 -0
- package/dist/shared/{src-lBcHSsjm.cjs → src-Db20iysW.cjs} +12 -6
- package/dist/shared/{src-CPCP99Z9.mjs → src-mclDryX0.mjs} +12 -6
- package/dist/types/api/build.js +22 -0
- package/dist/types/api/experimental.js +13 -0
- package/dist/types/api/rolldown/index.js +7 -0
- package/dist/types/api/rolldown/rolldown-build.js +43 -0
- package/dist/types/api/watch/index.js +8 -0
- package/dist/types/api/watch/watch-emitter.js +69 -0
- package/dist/types/api/watch/watcher.js +66 -0
- package/dist/types/binding.d.ts +40 -2
- package/dist/types/builtin-plugin/alias-plugin.js +4 -0
- package/dist/types/builtin-plugin/constructors.d.ts +2 -2
- package/dist/types/builtin-plugin/constructors.js +68 -0
- package/dist/types/builtin-plugin/replace-plugin.js +29 -0
- package/dist/types/builtin-plugin/transform-plugin.js +16 -0
- package/dist/types/builtin-plugin/utils.js +19 -0
- package/dist/types/cli/arguments/alias.js +63 -0
- package/dist/types/cli/arguments/index.js +127 -0
- package/dist/types/cli/arguments/normalize.js +48 -0
- package/dist/types/cli/arguments/utils.js +67 -0
- package/dist/types/cli/colors.js +17 -0
- package/dist/types/cli/commands/bundle.js +203 -0
- package/dist/types/cli/commands/help.js +88 -0
- package/dist/types/cli/index.js +27 -0
- package/dist/types/cli/load-config.js +95 -0
- package/dist/types/cli/logger.js +35 -0
- package/dist/types/constants/plugin-context.js +7 -0
- package/dist/types/constants/plugin.js +69 -0
- package/dist/types/experimental-index.js +9 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +7 -0
- package/dist/types/log/logHandler.js +25 -0
- package/dist/types/log/logger.js +107 -0
- package/dist/types/log/logging.js +11 -0
- package/dist/types/log/logs.js +86 -0
- package/dist/types/options/input-options.d.ts +47 -2
- package/dist/types/options/input-options.js +1 -0
- package/dist/types/options/normalized-input-options.js +21 -0
- package/dist/types/options/normalized-output-options.js +99 -0
- package/dist/types/options/output-options.d.ts +6 -0
- package/dist/types/options/output-options.js +1 -0
- package/dist/types/options/watch-options.js +1 -0
- package/dist/types/parallel-plugin-worker.js +31 -0
- package/dist/types/parallel-plugin.js +1 -0
- package/dist/types/parse-ast-index.js +73 -0
- package/dist/types/plugin/bindingify-build-hooks.js +213 -0
- package/dist/types/plugin/bindingify-hook-filter.js +39 -0
- package/dist/types/plugin/bindingify-output-hooks.js +189 -0
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +19 -0
- package/dist/types/plugin/bindingify-plugin.js +124 -0
- package/dist/types/plugin/bindingify-watch-hooks.js +29 -0
- package/dist/types/plugin/hook-filter.js +1 -0
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/minimal-plugin-context.js +25 -0
- package/dist/types/plugin/parallel-plugin-implementation.js +3 -0
- package/dist/types/plugin/parallel-plugin.js +6 -0
- package/dist/types/plugin/plugin-context-data.js +55 -0
- package/dist/types/plugin/plugin-context.js +108 -0
- package/dist/types/plugin/plugin-driver.js +88 -0
- package/dist/types/plugin/transform-plugin-context.js +37 -0
- package/dist/types/types/assert.js +1 -0
- package/dist/types/types/config-export.js +1 -0
- package/dist/types/types/misc.js +1 -0
- package/dist/types/types/module-info.js +1 -0
- package/dist/types/types/module-side-effects.js +1 -0
- package/dist/types/types/output-bundle.js +1 -0
- package/dist/types/types/rolldown-options.js +1 -0
- package/dist/types/types/rolldown-output.js +1 -0
- package/dist/types/types/schema.js +1 -0
- package/dist/types/types/sourcemap.js +16 -0
- package/dist/types/types/utils.js +1 -0
- package/dist/types/utils/asset-source.js +8 -0
- package/dist/types/utils/async-flatten.js +7 -0
- package/dist/types/utils/bindingify-input-options.js +225 -0
- package/dist/types/utils/bindingify-output-options.js +92 -0
- package/dist/types/utils/code-frame.js +46 -0
- package/dist/types/utils/compose-js-plugins.js +400 -0
- package/dist/types/utils/create-bundler-option.js +53 -0
- package/dist/types/utils/create-bundler.js +15 -0
- package/dist/types/utils/define-config.js +3 -0
- package/dist/types/utils/error.js +65 -0
- package/dist/types/utils/initialize-parallel-plugins.js +54 -0
- package/dist/types/utils/misc.js +22 -0
- package/dist/types/utils/normalize-hook.js +21 -0
- package/dist/types/utils/normalize-plugin-option.js +35 -0
- package/dist/types/utils/normalize-string-or-regex.js +14 -0
- package/dist/types/utils/plugin/index.js +7 -0
- package/dist/types/utils/transform-module-info.js +19 -0
- package/dist/types/utils/transform-rendered-chunk.js +43 -0
- package/dist/types/utils/transform-rendered-module.js +10 -0
- package/dist/types/utils/transform-side-effects.js +16 -0
- package/dist/types/utils/transform-sourcemap.js +29 -0
- package/dist/types/utils/transform-to-rollup-output.js +165 -0
- package/dist/types/utils/validator.js +275 -0
- package/package.json +28 -25
- package/dist/shared/consola_36c0034f-Cx52UqEq.mjs +0 -832
- package/dist/shared/consola_36c0034f-CynBWXXO.cjs +0 -859
- package/dist/shared/prompt-B58MxVuU.cjs +0 -762
- package/dist/shared/prompt-DjjlOckE.mjs +0 -758
- package/dist/tsconfig.dts.tsbuildinfo +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN } from '../log/logging';
|
|
2
|
+
import { error, logPluginError } from '../log/logs';
|
|
3
|
+
import { getLogHandler, normalizeLog } from '../log/logHandler';
|
|
4
|
+
import { VERSION } from '..';
|
|
5
|
+
export class MinimalPluginContext {
|
|
6
|
+
pluginName;
|
|
7
|
+
info;
|
|
8
|
+
warn;
|
|
9
|
+
debug;
|
|
10
|
+
meta;
|
|
11
|
+
constructor(onLog, logLevel, pluginName) {
|
|
12
|
+
this.pluginName = pluginName;
|
|
13
|
+
this.debug = getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
14
|
+
this.info = getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', onLog, pluginName, logLevel);
|
|
15
|
+
this.warn = getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', onLog, pluginName, logLevel);
|
|
16
|
+
this.meta = {
|
|
17
|
+
rollupVersion: '4.23.0',
|
|
18
|
+
rolldownVersion: VERSION,
|
|
19
|
+
watchMode: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
error(e) {
|
|
23
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { transformModuleInfo } from '../utils/transform-module-info';
|
|
2
|
+
export class PluginContextData {
|
|
3
|
+
moduleOptionMap = new Map();
|
|
4
|
+
resolveOptionsMap = new Map();
|
|
5
|
+
loadModulePromiseMap = new Map();
|
|
6
|
+
updateModuleOption(id, option) {
|
|
7
|
+
const existing = this.moduleOptionMap.get(id);
|
|
8
|
+
if (existing) {
|
|
9
|
+
if (option.moduleSideEffects != null) {
|
|
10
|
+
existing.moduleSideEffects = option.moduleSideEffects;
|
|
11
|
+
}
|
|
12
|
+
if (option.meta != null) {
|
|
13
|
+
Object.assign(existing.meta, option.meta);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.moduleOptionMap.set(id, option);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
getModuleOption(id) {
|
|
21
|
+
const option = this.moduleOptionMap.get(id);
|
|
22
|
+
if (!option) {
|
|
23
|
+
const raw = {
|
|
24
|
+
moduleSideEffects: null,
|
|
25
|
+
meta: {},
|
|
26
|
+
};
|
|
27
|
+
this.moduleOptionMap.set(id, raw);
|
|
28
|
+
return raw;
|
|
29
|
+
}
|
|
30
|
+
return option;
|
|
31
|
+
}
|
|
32
|
+
getModuleInfo(id, context) {
|
|
33
|
+
const bindingInfo = context.getModuleInfo(id);
|
|
34
|
+
if (bindingInfo) {
|
|
35
|
+
const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
|
|
36
|
+
return info;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
getModuleIds(context) {
|
|
41
|
+
const moduleIds = context.getModuleIds();
|
|
42
|
+
return moduleIds.values();
|
|
43
|
+
}
|
|
44
|
+
saveResolveOptions(options) {
|
|
45
|
+
const index = this.resolveOptionsMap.size;
|
|
46
|
+
this.resolveOptionsMap.set(index, options);
|
|
47
|
+
return index;
|
|
48
|
+
}
|
|
49
|
+
getSavedResolveOptions(receipt) {
|
|
50
|
+
return this.resolveOptionsMap.get(receipt);
|
|
51
|
+
}
|
|
52
|
+
removeSavedResolveOptions(receipt) {
|
|
53
|
+
this.resolveOptionsMap.delete(receipt);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { MinimalPluginContext } from '../plugin/minimal-plugin-context';
|
|
2
|
+
import { bindingAssetSource } from '../utils/asset-source';
|
|
3
|
+
import { unimplemented, unsupported } from '../utils/misc';
|
|
4
|
+
import { SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF } from '../constants/plugin-context';
|
|
5
|
+
import { bindingifySideEffects } from '../utils/transform-side-effects';
|
|
6
|
+
import { LOG_LEVEL_WARN } from '../log/logging';
|
|
7
|
+
import { logCycleLoading } from '../log/logs';
|
|
8
|
+
export class PluginContext extends MinimalPluginContext {
|
|
9
|
+
context;
|
|
10
|
+
data;
|
|
11
|
+
onLog;
|
|
12
|
+
currentLoadingModule;
|
|
13
|
+
constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
|
|
14
|
+
super(onLog, logLevel, plugin.name);
|
|
15
|
+
this.context = context;
|
|
16
|
+
this.data = data;
|
|
17
|
+
this.onLog = onLog;
|
|
18
|
+
this.currentLoadingModule = currentLoadingModule;
|
|
19
|
+
}
|
|
20
|
+
async load(options) {
|
|
21
|
+
const id = options.id;
|
|
22
|
+
if (id === this.currentLoadingModule) {
|
|
23
|
+
this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
|
|
24
|
+
}
|
|
25
|
+
// resolveDependencies always true at rolldown
|
|
26
|
+
const moduleInfo = this.data.getModuleInfo(id, this.context);
|
|
27
|
+
if (moduleInfo && moduleInfo.code !== null /* module already parsed */) {
|
|
28
|
+
return moduleInfo;
|
|
29
|
+
}
|
|
30
|
+
const rawOptions = {
|
|
31
|
+
meta: options.meta || {},
|
|
32
|
+
moduleSideEffects: options.moduleSideEffects || null,
|
|
33
|
+
};
|
|
34
|
+
this.data.updateModuleOption(id, rawOptions);
|
|
35
|
+
async function createLoadModulePromise(context, data) {
|
|
36
|
+
const loadPromise = data.loadModulePromiseMap.get(id);
|
|
37
|
+
if (loadPromise) {
|
|
38
|
+
return loadPromise;
|
|
39
|
+
}
|
|
40
|
+
let resolveFn;
|
|
41
|
+
// TODO: If is not resolved, we need to set a time to avoid waiting.
|
|
42
|
+
const promise = new Promise((resolve, _) => {
|
|
43
|
+
resolveFn = resolve;
|
|
44
|
+
});
|
|
45
|
+
data.loadModulePromiseMap.set(id, promise);
|
|
46
|
+
try {
|
|
47
|
+
await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
// If the load module has failed, avoid it re-load using unresolved promise.
|
|
51
|
+
data.loadModulePromiseMap.delete(id);
|
|
52
|
+
}
|
|
53
|
+
return promise;
|
|
54
|
+
}
|
|
55
|
+
// Here using one promise to avoid pass more callback to rust side, it only accept one callback, other will be ignored.
|
|
56
|
+
await createLoadModulePromise(this.context, this.data);
|
|
57
|
+
return this.data.getModuleInfo(id, this.context);
|
|
58
|
+
}
|
|
59
|
+
async resolve(source, importer, options) {
|
|
60
|
+
let receipt = undefined;
|
|
61
|
+
if (options != null) {
|
|
62
|
+
receipt = this.data.saveResolveOptions(options);
|
|
63
|
+
}
|
|
64
|
+
const res = await this.context.resolve(source, importer, {
|
|
65
|
+
custom: receipt,
|
|
66
|
+
skipSelf: options?.skipSelf,
|
|
67
|
+
});
|
|
68
|
+
if (receipt != null) {
|
|
69
|
+
this.data.removeSavedResolveOptions(receipt);
|
|
70
|
+
}
|
|
71
|
+
if (res == null)
|
|
72
|
+
return null;
|
|
73
|
+
const info = this.data.getModuleOption(res.id) || {};
|
|
74
|
+
return { ...res, ...info };
|
|
75
|
+
}
|
|
76
|
+
emitFile(file) {
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
if (file.type === 'prebuilt-chunk') {
|
|
79
|
+
return unimplemented('PluginContext.emitFile with type prebuilt-chunk');
|
|
80
|
+
}
|
|
81
|
+
if (file.type === 'chunk') {
|
|
82
|
+
return this.context.emitChunk(file);
|
|
83
|
+
}
|
|
84
|
+
return this.context.emitFile({
|
|
85
|
+
...file,
|
|
86
|
+
originalFileName: file.originalFileName || undefined,
|
|
87
|
+
source: bindingAssetSource(file.source),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getFileName(referenceId) {
|
|
91
|
+
return this.context.getFileName(referenceId);
|
|
92
|
+
}
|
|
93
|
+
getModuleInfo(id) {
|
|
94
|
+
return this.data.getModuleInfo(id, this.context);
|
|
95
|
+
}
|
|
96
|
+
getModuleIds() {
|
|
97
|
+
return this.data.getModuleIds(this.context);
|
|
98
|
+
}
|
|
99
|
+
addWatchFile(id) {
|
|
100
|
+
this.context.addWatchFile(id);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
|
|
104
|
+
*/
|
|
105
|
+
parse(_input, _options) {
|
|
106
|
+
unsupported('`PluginContext#parse` is not supported by rolldown.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getLogHandler, normalizeLog } from '../log/logHandler';
|
|
2
|
+
import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN } from '../log/logging';
|
|
3
|
+
import { error, logPluginError } from '../log/logs';
|
|
4
|
+
import { normalizeHook } from '../utils/normalize-hook';
|
|
5
|
+
import { VERSION } from '..';
|
|
6
|
+
import { getLogger, getOnLog } from '../log/logger';
|
|
7
|
+
import { BuiltinPlugin } from '../builtin-plugin/constructors';
|
|
8
|
+
import { normalizePluginOption } from '../utils/normalize-plugin-option';
|
|
9
|
+
export class PluginDriver {
|
|
10
|
+
static async callOptionsHook(inputOptions) {
|
|
11
|
+
const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
|
|
12
|
+
const plugins = getSortedPlugins('options', getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
|
|
13
|
+
const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
|
|
14
|
+
for (const plugin of plugins) {
|
|
15
|
+
const name = plugin.name || 'unknown';
|
|
16
|
+
const options = plugin.options;
|
|
17
|
+
if (options) {
|
|
18
|
+
const { handler } = normalizeHook(options);
|
|
19
|
+
const result = await handler.call({
|
|
20
|
+
debug: getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
|
|
21
|
+
error: (e) => error(logPluginError(normalizeLog(e), name, { hook: 'onLog' })),
|
|
22
|
+
info: getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
|
|
23
|
+
meta: {
|
|
24
|
+
rollupVersion: '4.23.0',
|
|
25
|
+
rolldownVersion: VERSION,
|
|
26
|
+
watchMode: false,
|
|
27
|
+
},
|
|
28
|
+
warn: getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel),
|
|
29
|
+
pluginName: name,
|
|
30
|
+
}, inputOptions);
|
|
31
|
+
if (result) {
|
|
32
|
+
inputOptions = result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return inputOptions;
|
|
37
|
+
}
|
|
38
|
+
static callOutputOptionsHook(rawPlugins, outputOptions) {
|
|
39
|
+
const sortedPlugins = getSortedPlugins('outputOptions', getObjectPlugins(rawPlugins));
|
|
40
|
+
for (const plugin of sortedPlugins) {
|
|
41
|
+
const options = plugin.outputOptions;
|
|
42
|
+
if (options) {
|
|
43
|
+
const { handler } = normalizeHook(options);
|
|
44
|
+
const result = handler.call(null, outputOptions);
|
|
45
|
+
if (result) {
|
|
46
|
+
outputOptions = result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return outputOptions;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function getObjectPlugins(plugins) {
|
|
54
|
+
return plugins.filter((plugin) => {
|
|
55
|
+
if (!plugin) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
if ('_parallel' in plugin) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (plugin instanceof BuiltinPlugin) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
return plugin;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function getSortedPlugins(hookName, plugins) {
|
|
68
|
+
const pre = [];
|
|
69
|
+
const normal = [];
|
|
70
|
+
const post = [];
|
|
71
|
+
for (const plugin of plugins) {
|
|
72
|
+
const hook = plugin[hookName];
|
|
73
|
+
if (hook) {
|
|
74
|
+
if (typeof hook === 'object') {
|
|
75
|
+
if (hook.order === 'pre') {
|
|
76
|
+
pre.push(plugin);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (hook.order === 'post') {
|
|
80
|
+
post.push(plugin);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
normal.push(plugin);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return [...pre, ...normal, ...post];
|
|
88
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { normalizeLog } from '../log/logHandler';
|
|
2
|
+
import { PluginContext } from './plugin-context';
|
|
3
|
+
import { augmentCodeLocation, error, logPluginError } from '../log/logs';
|
|
4
|
+
export class TransformPluginContext extends PluginContext {
|
|
5
|
+
inner;
|
|
6
|
+
moduleId;
|
|
7
|
+
moduleSource;
|
|
8
|
+
constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
|
|
9
|
+
super(context, plugin, data, onLog, LogLevelOption, moduleId);
|
|
10
|
+
this.inner = inner;
|
|
11
|
+
this.moduleId = moduleId;
|
|
12
|
+
this.moduleSource = moduleSource;
|
|
13
|
+
const getLogHandler = (handler) => (log, pos) => {
|
|
14
|
+
log = normalizeLog(log);
|
|
15
|
+
if (pos)
|
|
16
|
+
augmentCodeLocation(log, pos, moduleSource, moduleId);
|
|
17
|
+
log.id = moduleId;
|
|
18
|
+
log.hook = 'transform';
|
|
19
|
+
handler(log);
|
|
20
|
+
};
|
|
21
|
+
this.debug = getLogHandler(this.debug);
|
|
22
|
+
this.warn = getLogHandler(this.warn);
|
|
23
|
+
this.info = getLogHandler(this.info);
|
|
24
|
+
}
|
|
25
|
+
error(e, pos) {
|
|
26
|
+
if (typeof e === 'string')
|
|
27
|
+
e = { message: e };
|
|
28
|
+
if (pos)
|
|
29
|
+
augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
|
|
30
|
+
e.id = this.moduleId;
|
|
31
|
+
e.hook = 'transform';
|
|
32
|
+
return error(logPluginError(normalizeLog(e), this.pluginName));
|
|
33
|
+
}
|
|
34
|
+
getCombinedSourcemap() {
|
|
35
|
+
return JSON.parse(this.inner.getCombinedSourcemap());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function bindingifySourcemap(map) {
|
|
2
|
+
if (map == null)
|
|
3
|
+
return;
|
|
4
|
+
return {
|
|
5
|
+
inner: typeof map === 'string'
|
|
6
|
+
? map
|
|
7
|
+
: {
|
|
8
|
+
file: map.file ?? undefined,
|
|
9
|
+
mappings: map.mappings,
|
|
10
|
+
sourceRoot: map.sourceRoot,
|
|
11
|
+
sources: map.sources?.map((s) => s ?? undefined),
|
|
12
|
+
sourcesContent: map.sourcesContent?.map((s) => s ?? undefined),
|
|
13
|
+
names: map.names,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copied from https://github.com/rollup/rollup/blob/3b560f7c889a63968dabc9b6970aabf52a77d3fd/src/utils/asyncFlatten.ts
|
|
2
|
+
export async function asyncFlatten(array) {
|
|
3
|
+
do {
|
|
4
|
+
array = (await Promise.all(array)).flat(Infinity);
|
|
5
|
+
} while (array.some((v) => v?.then));
|
|
6
|
+
return array;
|
|
7
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { BindingLogLevel } from '../binding';
|
|
2
|
+
import { bindingifyPlugin } from '../plugin/bindingify-plugin';
|
|
3
|
+
import { PluginContextData } from '../plugin/plugin-context-data';
|
|
4
|
+
import { bindingifyBuiltInPlugin } from '../builtin-plugin/utils';
|
|
5
|
+
import { BuiltinPlugin } from '../builtin-plugin/constructors';
|
|
6
|
+
import { arraify, unsupported } from './misc';
|
|
7
|
+
import { normalizedStringOrRegex } from './normalize-string-or-regex';
|
|
8
|
+
export function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
|
|
9
|
+
const pluginContextData = new PluginContextData();
|
|
10
|
+
const plugins = rawPlugins.map((plugin) => {
|
|
11
|
+
if ('_parallel' in plugin) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (plugin instanceof BuiltinPlugin) {
|
|
15
|
+
return bindingifyBuiltInPlugin(plugin);
|
|
16
|
+
}
|
|
17
|
+
return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, onLog, logLevel);
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
input: bindingifyInput(inputOptions.input),
|
|
21
|
+
plugins,
|
|
22
|
+
cwd: inputOptions.cwd ?? process.cwd(),
|
|
23
|
+
external: bindingifyExternal(inputOptions.external),
|
|
24
|
+
resolve: bindingifyResolve(inputOptions.resolve),
|
|
25
|
+
platform: inputOptions.platform,
|
|
26
|
+
shimMissingExports: inputOptions.shimMissingExports,
|
|
27
|
+
logLevel: bindingifyLogLevel(logLevel),
|
|
28
|
+
onLog,
|
|
29
|
+
// After normalized, `false` will be converted to `undefined`, otherwise, default value will be assigned
|
|
30
|
+
// Because it is hard to represent Enum in napi, ref: https://github.com/napi-rs/napi-rs/issues/507
|
|
31
|
+
// So we use `undefined | NormalizedTreeshakingOptions` (or Option<NormalizedTreeshakingOptions> in rust side), to represent `false | NormalizedTreeshakingOptions`
|
|
32
|
+
treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
|
|
33
|
+
moduleTypes: inputOptions.moduleTypes,
|
|
34
|
+
define: inputOptions.define
|
|
35
|
+
? Object.entries(inputOptions.define)
|
|
36
|
+
: undefined,
|
|
37
|
+
inject: bindingifyInject(inputOptions.inject),
|
|
38
|
+
experimental: {
|
|
39
|
+
strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
|
|
40
|
+
disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
|
|
41
|
+
viteMode: inputOptions.experimental?.viteMode,
|
|
42
|
+
resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset,
|
|
43
|
+
},
|
|
44
|
+
profilerNames: inputOptions?.profilerNames,
|
|
45
|
+
jsx: bindingifyJsx(inputOptions.jsx),
|
|
46
|
+
watch: bindingifyWatch(inputOptions.watch),
|
|
47
|
+
dropLabels: inputOptions.dropLabels,
|
|
48
|
+
keepNames: inputOptions.keepNames,
|
|
49
|
+
checks: inputOptions.checks,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function bindingifyExternal(external) {
|
|
53
|
+
if (external) {
|
|
54
|
+
if (typeof external === 'function') {
|
|
55
|
+
return (id, importer, isResolved) => {
|
|
56
|
+
if (id.startsWith('\0'))
|
|
57
|
+
return false;
|
|
58
|
+
return external(id, importer, isResolved) ?? false;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const externalArr = arraify(external);
|
|
62
|
+
return (id, _importer, _isResolved) => {
|
|
63
|
+
return externalArr.some((pat) => {
|
|
64
|
+
if (pat instanceof RegExp) {
|
|
65
|
+
return pat.test(id);
|
|
66
|
+
}
|
|
67
|
+
return id === pat;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function bindingifyResolve(resolve) {
|
|
73
|
+
if (resolve) {
|
|
74
|
+
const { alias, extensionAlias, ...rest } = resolve;
|
|
75
|
+
return {
|
|
76
|
+
alias: alias
|
|
77
|
+
? Object.entries(alias).map(([name, replacement]) => ({
|
|
78
|
+
find: name,
|
|
79
|
+
replacements: arraify(replacement),
|
|
80
|
+
}))
|
|
81
|
+
: undefined,
|
|
82
|
+
extensionAlias: extensionAlias
|
|
83
|
+
? Object.entries(extensionAlias).map(([name, value]) => ({
|
|
84
|
+
target: name,
|
|
85
|
+
replacements: value,
|
|
86
|
+
}))
|
|
87
|
+
: undefined,
|
|
88
|
+
...rest,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function bindingifyInject(inject) {
|
|
93
|
+
if (inject) {
|
|
94
|
+
return Object.entries(inject).map(([alias, item]) => {
|
|
95
|
+
if (Array.isArray(item)) {
|
|
96
|
+
// import * as fs from 'node:fs'
|
|
97
|
+
// fs: ['node:fs', '*' ],
|
|
98
|
+
if (item[1] === '*') {
|
|
99
|
+
return {
|
|
100
|
+
tagNamespace: true,
|
|
101
|
+
alias,
|
|
102
|
+
from: item[0],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// import { Promise } from 'es6-promise'
|
|
106
|
+
// Promise: [ 'es6-promise', 'Promise' ],
|
|
107
|
+
// import { Promise as P } from 'es6-promise'
|
|
108
|
+
// P: [ 'es6-promise', 'Promise' ],
|
|
109
|
+
return {
|
|
110
|
+
tagNamed: true,
|
|
111
|
+
alias,
|
|
112
|
+
from: item[0],
|
|
113
|
+
imported: item[1],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// import $ from 'jquery'
|
|
118
|
+
// $: 'jquery',
|
|
119
|
+
// 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
|
|
120
|
+
return {
|
|
121
|
+
tagNamed: true,
|
|
122
|
+
imported: 'default',
|
|
123
|
+
alias,
|
|
124
|
+
from: item,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function bindingifyLogLevel(logLevel) {
|
|
131
|
+
switch (logLevel) {
|
|
132
|
+
case 'silent':
|
|
133
|
+
return BindingLogLevel.Silent;
|
|
134
|
+
case 'debug':
|
|
135
|
+
return BindingLogLevel.Debug;
|
|
136
|
+
case 'warn':
|
|
137
|
+
return BindingLogLevel.Warn;
|
|
138
|
+
case 'info':
|
|
139
|
+
return BindingLogLevel.Info;
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(`Unexpected log level: ${logLevel}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function bindingifyInput(input) {
|
|
145
|
+
if (input === undefined) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
if (typeof input === 'string') {
|
|
149
|
+
return [{ import: input }];
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(input)) {
|
|
152
|
+
return input.map((src) => ({ import: src }));
|
|
153
|
+
}
|
|
154
|
+
return Object.entries(input).map((value) => {
|
|
155
|
+
return { name: value[0], import: value[1] };
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// The `automatic` is most user usages, so it is different rollup's default value `false`
|
|
159
|
+
function bindingifyJsx(input) {
|
|
160
|
+
if (input === false) {
|
|
161
|
+
return { type: 'Disable' };
|
|
162
|
+
}
|
|
163
|
+
if (input) {
|
|
164
|
+
if (input.mode === 'preserve') {
|
|
165
|
+
return { type: 'Preserve' };
|
|
166
|
+
}
|
|
167
|
+
const mode = input.mode ?? 'automatic';
|
|
168
|
+
return {
|
|
169
|
+
type: 'Enable',
|
|
170
|
+
field0: {
|
|
171
|
+
runtime: mode,
|
|
172
|
+
importSource: mode === 'classic'
|
|
173
|
+
? input.importSource
|
|
174
|
+
: mode === 'automatic'
|
|
175
|
+
? input.jsxImportSource
|
|
176
|
+
: undefined,
|
|
177
|
+
pragma: input.factory,
|
|
178
|
+
pragmaFrag: input.fragment,
|
|
179
|
+
development: input.development,
|
|
180
|
+
refresh: input.refresh,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function bindingifyWatch(watch) {
|
|
186
|
+
if (watch) {
|
|
187
|
+
let value = {
|
|
188
|
+
skipWrite: watch.skipWrite,
|
|
189
|
+
include: normalizedStringOrRegex(watch.include),
|
|
190
|
+
exclude: normalizedStringOrRegex(watch.exclude),
|
|
191
|
+
};
|
|
192
|
+
if (watch.chokidar) {
|
|
193
|
+
unsupported('The watch chokidar option is deprecated, please use notify options instead of it.');
|
|
194
|
+
}
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function bindingifyTreeshakeOptions(config) {
|
|
199
|
+
if (config === false) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
if (config === true || config === undefined) {
|
|
203
|
+
return {
|
|
204
|
+
moduleSideEffects: true,
|
|
205
|
+
annotations: true,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
let normalizedConfig = {
|
|
209
|
+
moduleSideEffects: true,
|
|
210
|
+
};
|
|
211
|
+
if (config.moduleSideEffects === undefined) {
|
|
212
|
+
normalizedConfig.moduleSideEffects = true;
|
|
213
|
+
}
|
|
214
|
+
else if (config.moduleSideEffects === 'no-external') {
|
|
215
|
+
normalizedConfig.moduleSideEffects = [
|
|
216
|
+
{ external: true, sideEffects: false },
|
|
217
|
+
{ external: false, sideEffects: true },
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
normalizedConfig.moduleSideEffects = config.moduleSideEffects;
|
|
222
|
+
}
|
|
223
|
+
normalizedConfig.annotations = config.annotations ?? true;
|
|
224
|
+
return normalizedConfig;
|
|
225
|
+
}
|