rolldown 1.0.0-beta.3-commit.06372d4 → 1.0.0-beta.3-commit.558ea78
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 +1 -1
- package/dist/cjs/experimental-index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/parallel-plugin-worker.cjs +1 -1
- package/dist/esm/cli.mjs +1 -1
- package/dist/esm/experimental-index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{src-CLOW1Jzp.mjs → src-Cis0qYEg.mjs} +35 -15
- package/dist/shared/{src-D2D9kPjA.cjs → src-Z84gVvFu.cjs} +35 -15
- package/dist/types/binding.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/log/logging.d.ts +1 -0
- package/dist/types/options/input-options.d.ts +3 -3
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/package.json +15 -15
- package/dist/types/api/build.js +0 -22
- package/dist/types/api/experimental.js +0 -13
- package/dist/types/api/rolldown/index.js +0 -7
- package/dist/types/api/rolldown/rolldown-build.js +0 -43
- package/dist/types/api/watch/index.js +0 -8
- package/dist/types/api/watch/watch-emitter.js +0 -69
- package/dist/types/api/watch/watcher.js +0 -66
- package/dist/types/builtin-plugin/alias-plugin.js +0 -4
- package/dist/types/builtin-plugin/constructors.js +0 -68
- package/dist/types/builtin-plugin/replace-plugin.js +0 -29
- package/dist/types/builtin-plugin/transform-plugin.js +0 -16
- package/dist/types/builtin-plugin/utils.js +0 -19
- package/dist/types/cli/arguments/alias.js +0 -63
- package/dist/types/cli/arguments/index.js +0 -127
- package/dist/types/cli/arguments/normalize.js +0 -48
- package/dist/types/cli/arguments/utils.js +0 -67
- package/dist/types/cli/colors.js +0 -17
- package/dist/types/cli/commands/bundle.js +0 -203
- package/dist/types/cli/commands/help.js +0 -88
- package/dist/types/cli/index.js +0 -27
- package/dist/types/cli/load-config.js +0 -95
- package/dist/types/cli/logger.js +0 -35
- package/dist/types/constants/plugin-context.js +0 -7
- package/dist/types/constants/plugin.js +0 -69
- package/dist/types/experimental-index.js +0 -9
- package/dist/types/index.js +0 -7
- package/dist/types/log/logHandler.js +0 -25
- package/dist/types/log/logger.js +0 -107
- package/dist/types/log/logging.js +0 -11
- package/dist/types/log/logs.js +0 -86
- package/dist/types/options/input-options.js +0 -1
- package/dist/types/options/normalized-input-options.js +0 -21
- package/dist/types/options/normalized-output-options.js +0 -99
- package/dist/types/options/output-options.js +0 -1
- package/dist/types/options/watch-options.js +0 -1
- package/dist/types/parallel-plugin-worker.js +0 -31
- package/dist/types/parallel-plugin.js +0 -1
- package/dist/types/parse-ast-index.js +0 -73
- package/dist/types/plugin/bindingify-build-hooks.js +0 -213
- package/dist/types/plugin/bindingify-hook-filter.js +0 -39
- package/dist/types/plugin/bindingify-output-hooks.js +0 -189
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
- package/dist/types/plugin/bindingify-plugin.js +0 -124
- package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
- package/dist/types/plugin/hook-filter.js +0 -1
- package/dist/types/plugin/index.js +0 -1
- package/dist/types/plugin/minimal-plugin-context.js +0 -25
- package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
- package/dist/types/plugin/parallel-plugin.js +0 -6
- package/dist/types/plugin/plugin-context-data.js +0 -55
- package/dist/types/plugin/plugin-context.js +0 -124
- package/dist/types/plugin/plugin-driver.js +0 -88
- package/dist/types/plugin/transform-plugin-context.js +0 -37
- package/dist/types/types/assert.js +0 -1
- package/dist/types/types/config-export.js +0 -1
- package/dist/types/types/misc.js +0 -1
- package/dist/types/types/module-info.js +0 -1
- package/dist/types/types/module-side-effects.js +0 -1
- package/dist/types/types/output-bundle.js +0 -1
- package/dist/types/types/rolldown-options.js +0 -1
- package/dist/types/types/rolldown-output.js +0 -1
- package/dist/types/types/schema.js +0 -1
- package/dist/types/types/sourcemap.js +0 -16
- package/dist/types/types/utils.js +0 -1
- package/dist/types/utils/asset-source.js +0 -8
- package/dist/types/utils/async-flatten.js +0 -7
- package/dist/types/utils/bindingify-input-options.js +0 -226
- package/dist/types/utils/bindingify-output-options.js +0 -107
- package/dist/types/utils/code-frame.js +0 -46
- package/dist/types/utils/compose-js-plugins.js +0 -400
- package/dist/types/utils/create-bundler-option.js +0 -53
- package/dist/types/utils/create-bundler.js +0 -15
- package/dist/types/utils/define-config.js +0 -3
- package/dist/types/utils/error.js +0 -65
- package/dist/types/utils/initialize-parallel-plugins.js +0 -54
- package/dist/types/utils/misc.js +0 -22
- package/dist/types/utils/normalize-hook.js +0 -21
- package/dist/types/utils/normalize-plugin-option.js +0 -35
- package/dist/types/utils/normalize-string-or-regex.js +0 -14
- package/dist/types/utils/plugin/index.js +0 -7
- package/dist/types/utils/transform-module-info.js +0 -19
- package/dist/types/utils/transform-rendered-chunk.js +0 -43
- package/dist/types/utils/transform-rendered-module.js +0 -10
- package/dist/types/utils/transform-side-effects.js +0 -16
- package/dist/types/utils/transform-sourcemap.js +0 -29
- package/dist/types/utils/transform-to-rollup-output.js +0 -165
- package/dist/types/utils/validator.js +0 -276
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const LOG_LEVEL_SILENT = 'silent';
|
|
2
|
-
export const LOG_LEVEL_ERROR = 'error';
|
|
3
|
-
export const LOG_LEVEL_WARN = 'warn';
|
|
4
|
-
export const LOG_LEVEL_INFO = 'info';
|
|
5
|
-
export const LOG_LEVEL_DEBUG = 'debug';
|
|
6
|
-
export const logLevelPriority = {
|
|
7
|
-
[LOG_LEVEL_DEBUG]: 0,
|
|
8
|
-
[LOG_LEVEL_INFO]: 1,
|
|
9
|
-
[LOG_LEVEL_WARN]: 2,
|
|
10
|
-
[LOG_LEVEL_SILENT]: 3,
|
|
11
|
-
};
|
package/dist/types/log/logs.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { getCodeFrame } from '../utils/code-frame';
|
|
2
|
-
import { locate } from './locate-character';
|
|
3
|
-
import { colors } from '../cli/colors';
|
|
4
|
-
const INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', PLUGIN_ERROR = 'PLUGIN_ERROR', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', CYCLE_LOADING = 'CYCLE_LOADING', MULTIPLY_NOTIFY_OPTION = 'MULTIPLY_NOTIFY_OPTION', MINIFY_WARNING = 'MINIFY_WARNING', PARSE_ERROR = 'PARSE_ERROR';
|
|
5
|
-
export function logParseError(message) {
|
|
6
|
-
return {
|
|
7
|
-
code: PARSE_ERROR,
|
|
8
|
-
message,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export function logMinifyWarning() {
|
|
12
|
-
return {
|
|
13
|
-
code: MINIFY_WARNING,
|
|
14
|
-
message: colors.yellow('The built-in minifier is still under development. Setting "minify: true" is not recommended for production use.'),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export function logInvalidLogPosition(pluginName) {
|
|
18
|
-
return {
|
|
19
|
-
code: INVALID_LOG_POSITION,
|
|
20
|
-
message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export function logInputHookInOutputPlugin(pluginName, hookName) {
|
|
24
|
-
return {
|
|
25
|
-
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
|
|
26
|
-
message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export function logCycleLoading(pluginName, moduleId) {
|
|
30
|
-
return {
|
|
31
|
-
code: CYCLE_LOADING,
|
|
32
|
-
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export function logMultiplyNotifyOption() {
|
|
36
|
-
return {
|
|
37
|
-
code: MULTIPLY_NOTIFY_OPTION,
|
|
38
|
-
message: `Found multiply notify option at watch options, using first one to start notify watcher.`,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function logPluginError(error, plugin, { hook, id } = {}) {
|
|
42
|
-
const code = error.code;
|
|
43
|
-
if (!error.pluginCode &&
|
|
44
|
-
code != null &&
|
|
45
|
-
(typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
|
|
46
|
-
error.pluginCode = code;
|
|
47
|
-
}
|
|
48
|
-
error.code = PLUGIN_ERROR;
|
|
49
|
-
error.plugin = plugin;
|
|
50
|
-
if (hook) {
|
|
51
|
-
error.hook = hook;
|
|
52
|
-
}
|
|
53
|
-
if (id) {
|
|
54
|
-
error.id = id;
|
|
55
|
-
}
|
|
56
|
-
return error;
|
|
57
|
-
}
|
|
58
|
-
export function error(base) {
|
|
59
|
-
if (!(base instanceof Error)) {
|
|
60
|
-
base = Object.assign(new Error(base.message), base);
|
|
61
|
-
Object.defineProperty(base, 'name', {
|
|
62
|
-
value: 'RollupError',
|
|
63
|
-
writable: true,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
throw base;
|
|
67
|
-
}
|
|
68
|
-
export function augmentCodeLocation(properties, pos, source, id) {
|
|
69
|
-
if (typeof pos === 'object') {
|
|
70
|
-
const { line, column } = pos;
|
|
71
|
-
properties.loc = { column, file: id, line };
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
properties.pos = pos;
|
|
75
|
-
const location = locate(source, pos, { offsetLine: 1 });
|
|
76
|
-
if (!location) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { line, column } = location;
|
|
80
|
-
properties.loc = { column, file: id, line };
|
|
81
|
-
}
|
|
82
|
-
if (properties.frame === undefined) {
|
|
83
|
-
const { line, column } = properties.loc;
|
|
84
|
-
properties.frame = getCodeFrame(source, line, column);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// TODO: I guess we make these getters enumerable so it act more like a plain object
|
|
2
|
-
export class NormalizedInputOptionsImpl {
|
|
3
|
-
onLog;
|
|
4
|
-
inner;
|
|
5
|
-
constructor(inner, onLog) {
|
|
6
|
-
this.onLog = onLog;
|
|
7
|
-
this.inner = inner;
|
|
8
|
-
}
|
|
9
|
-
get shimMissingExports() {
|
|
10
|
-
return this.inner.shimMissingExports;
|
|
11
|
-
}
|
|
12
|
-
get input() {
|
|
13
|
-
return this.inner.input;
|
|
14
|
-
}
|
|
15
|
-
get cwd() {
|
|
16
|
-
return this.inner.cwd ?? undefined;
|
|
17
|
-
}
|
|
18
|
-
get platform() {
|
|
19
|
-
return this.inner.platform;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { unsupported } from '../utils/misc';
|
|
2
|
-
function mapFunctionOption(option, name) {
|
|
3
|
-
return typeof option === 'undefined'
|
|
4
|
-
? () => {
|
|
5
|
-
unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
|
|
6
|
-
}
|
|
7
|
-
: option;
|
|
8
|
-
}
|
|
9
|
-
// TODO: I guess we make these getters enumerable so it act more like a plain object
|
|
10
|
-
export class NormalizedOutputOptionsImpl {
|
|
11
|
-
inner;
|
|
12
|
-
constructor(inner) {
|
|
13
|
-
this.inner = inner;
|
|
14
|
-
}
|
|
15
|
-
get dir() {
|
|
16
|
-
return this.inner.dir ?? undefined;
|
|
17
|
-
}
|
|
18
|
-
get entryFileNames() {
|
|
19
|
-
return mapFunctionOption(this.inner.entryFilenames, 'entryFileNames');
|
|
20
|
-
}
|
|
21
|
-
get chunkFileNames() {
|
|
22
|
-
return mapFunctionOption(this.inner.chunkFilenames, 'chunkFileNames');
|
|
23
|
-
}
|
|
24
|
-
get assetFileNames() {
|
|
25
|
-
return mapFunctionOption(this.inner.assetFilenames, 'assetFilenames');
|
|
26
|
-
}
|
|
27
|
-
get format() {
|
|
28
|
-
return this.inner.format;
|
|
29
|
-
}
|
|
30
|
-
get exports() {
|
|
31
|
-
return this.inner.exports;
|
|
32
|
-
}
|
|
33
|
-
get sourcemap() {
|
|
34
|
-
return this.inner.sourcemap;
|
|
35
|
-
}
|
|
36
|
-
get cssEntryFileNames() {
|
|
37
|
-
return mapFunctionOption(this.inner.cssEntryFilenames, 'cssEntryFileNames');
|
|
38
|
-
}
|
|
39
|
-
get cssChunkFileNames() {
|
|
40
|
-
return mapFunctionOption(this.inner.cssChunkFilenames, 'cssChunkFileNames');
|
|
41
|
-
}
|
|
42
|
-
get shimMissingExports() {
|
|
43
|
-
return this.inner.shimMissingExports;
|
|
44
|
-
}
|
|
45
|
-
get name() {
|
|
46
|
-
return this.inner.name ?? undefined;
|
|
47
|
-
}
|
|
48
|
-
get file() {
|
|
49
|
-
return this.inner.file ?? undefined;
|
|
50
|
-
}
|
|
51
|
-
get inlineDynamicImports() {
|
|
52
|
-
return this.inner.inlineDynamicImports;
|
|
53
|
-
}
|
|
54
|
-
get externalLiveBindings() {
|
|
55
|
-
return this.inner.externalLiveBindings;
|
|
56
|
-
}
|
|
57
|
-
get banner() {
|
|
58
|
-
return mapFunctionOption(this.inner.banner, 'banner') ?? undefined;
|
|
59
|
-
}
|
|
60
|
-
get footer() {
|
|
61
|
-
return mapFunctionOption(this.inner.footer, 'footer') ?? undefined;
|
|
62
|
-
}
|
|
63
|
-
get intro() {
|
|
64
|
-
return mapFunctionOption(this.inner.intro, 'intro') ?? undefined;
|
|
65
|
-
}
|
|
66
|
-
get outro() {
|
|
67
|
-
return mapFunctionOption(this.inner.outro, 'outro') ?? undefined;
|
|
68
|
-
}
|
|
69
|
-
get esModule() {
|
|
70
|
-
return this.inner.esModule;
|
|
71
|
-
}
|
|
72
|
-
get extend() {
|
|
73
|
-
return this.inner.extend;
|
|
74
|
-
}
|
|
75
|
-
get globals() {
|
|
76
|
-
return mapFunctionOption(this.inner.globals, 'globals');
|
|
77
|
-
}
|
|
78
|
-
get hashCharacters() {
|
|
79
|
-
return this.inner.hashCharacters;
|
|
80
|
-
}
|
|
81
|
-
get sourcemapDebugIds() {
|
|
82
|
-
return this.inner.sourcemapDebugIds;
|
|
83
|
-
}
|
|
84
|
-
get sourcemapIgnoreList() {
|
|
85
|
-
return mapFunctionOption(void 0, 'sourcemapIgnoreList');
|
|
86
|
-
}
|
|
87
|
-
get sourcemapPathTransform() {
|
|
88
|
-
return mapFunctionOption(void 0, 'sourcemapPathTransform');
|
|
89
|
-
}
|
|
90
|
-
get minify() {
|
|
91
|
-
return this.inner.minify;
|
|
92
|
-
}
|
|
93
|
-
get comments() {
|
|
94
|
-
return this.inner.comments;
|
|
95
|
-
}
|
|
96
|
-
get polyfillRequire() {
|
|
97
|
-
return this.inner.polyfillRequire;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import { registerPlugins } from './binding';
|
|
3
|
-
import { bindingifyPlugin } from './plugin/bindingify-plugin';
|
|
4
|
-
import { PluginContextData } from './plugin/plugin-context-data';
|
|
5
|
-
const { registryId, pluginInfos, threadNumber } = workerData;
|
|
6
|
-
(async () => {
|
|
7
|
-
try {
|
|
8
|
-
const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
|
|
9
|
-
const pluginModule = await import(pluginInfo.fileUrl);
|
|
10
|
-
const definePluginImpl = pluginModule.default;
|
|
11
|
-
const plugin = await definePluginImpl(pluginInfo.options, {
|
|
12
|
-
threadNumber,
|
|
13
|
-
});
|
|
14
|
-
return {
|
|
15
|
-
index: pluginInfo.index,
|
|
16
|
-
// TODO(sapphi-red): support inputOptions and outputOptions
|
|
17
|
-
plugin: bindingifyPlugin(plugin, {}, {},
|
|
18
|
-
// TODO need to find a way to share pluginContextData
|
|
19
|
-
new PluginContextData(), () => { }, 'info'),
|
|
20
|
-
};
|
|
21
|
-
}));
|
|
22
|
-
registerPlugins(registryId, plugins);
|
|
23
|
-
parentPort.postMessage({ type: 'success' });
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
parentPort.postMessage({ type: 'error', error });
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
29
|
-
parentPort.unref();
|
|
30
|
-
}
|
|
31
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { defineParallelPluginImplementation, } from './plugin/parallel-plugin-implementation';
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { parseSync, parseAsync } from './binding';
|
|
2
|
-
import { locate } from './log/locate-character';
|
|
3
|
-
import { error, logParseError } from './log/logs';
|
|
4
|
-
import { getCodeFrame } from './utils/code-frame';
|
|
5
|
-
// The oxc program is a string in the result, we need to parse it to a object.
|
|
6
|
-
// Copy from https://github.com/oxc-project/oxc/blob/main/napi/parser/index.js#L12
|
|
7
|
-
function wrap(result, sourceText) {
|
|
8
|
-
let program, module, comments, errors, magicString;
|
|
9
|
-
return {
|
|
10
|
-
get program() {
|
|
11
|
-
if (!errors)
|
|
12
|
-
errors = result.errors;
|
|
13
|
-
if (errors.length > 0) {
|
|
14
|
-
return normalizeParseError(sourceText, errors);
|
|
15
|
-
}
|
|
16
|
-
// @ts-expect-error the result.program typing is `Program`
|
|
17
|
-
if (!program)
|
|
18
|
-
program = JSON.parse(result.program);
|
|
19
|
-
return program;
|
|
20
|
-
},
|
|
21
|
-
get module() {
|
|
22
|
-
if (!module)
|
|
23
|
-
module = result.module;
|
|
24
|
-
return module;
|
|
25
|
-
},
|
|
26
|
-
get comments() {
|
|
27
|
-
if (!comments)
|
|
28
|
-
comments = result.comments;
|
|
29
|
-
return comments;
|
|
30
|
-
},
|
|
31
|
-
get errors() {
|
|
32
|
-
if (!errors)
|
|
33
|
-
errors = result.errors;
|
|
34
|
-
return errors;
|
|
35
|
-
},
|
|
36
|
-
get magicString() {
|
|
37
|
-
if (!magicString)
|
|
38
|
-
magicString = result.magicString;
|
|
39
|
-
return magicString;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function normalizeParseError(sourceText, errors) {
|
|
44
|
-
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? '' : 's'}:\n`;
|
|
45
|
-
for (let i = 0; i < errors.length; i++) {
|
|
46
|
-
if (i >= 5) {
|
|
47
|
-
message += '\n...';
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
const e = errors[i];
|
|
51
|
-
message +=
|
|
52
|
-
e.message +
|
|
53
|
-
'\n' +
|
|
54
|
-
e.labels
|
|
55
|
-
.map((label) => {
|
|
56
|
-
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
57
|
-
if (!location) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
return getCodeFrame(sourceText, location.line, location.column);
|
|
61
|
-
})
|
|
62
|
-
.filter(Boolean)
|
|
63
|
-
.join('\n');
|
|
64
|
-
}
|
|
65
|
-
return error(logParseError(message));
|
|
66
|
-
}
|
|
67
|
-
// The api compat to rollup `parseAst` and `parseAstAsync`.
|
|
68
|
-
export function parseAst(filename, sourceText, options) {
|
|
69
|
-
return wrap(parseSync(filename, sourceText, options), sourceText);
|
|
70
|
-
}
|
|
71
|
-
export async function parseAstAsync(filename, sourceText, options) {
|
|
72
|
-
return wrap(await parseAsync(filename, sourceText, options), sourceText);
|
|
73
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { normalizeHook } from '../utils/normalize-hook';
|
|
2
|
-
import { isEmptySourcemapFiled, normalizeTransformHookSourcemap, } from '../utils/transform-sourcemap';
|
|
3
|
-
import { transformModuleInfo } from '../utils/transform-module-info';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { bindingifySourcemap } from '../types/sourcemap';
|
|
6
|
-
import { PluginContext, } from './plugin-context';
|
|
7
|
-
import { TransformPluginContext } from './transform-plugin-context';
|
|
8
|
-
import { bindingifySideEffects } from '../utils/transform-side-effects';
|
|
9
|
-
import { bindingifyPluginHookMeta, } from './bindingify-plugin-hook-meta';
|
|
10
|
-
import { SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF } from '../constants/plugin-context';
|
|
11
|
-
import { bindingifyLoadFilter, bindingifyResolveIdFilter, bindingifyTransformFilter, } from './bindingify-hook-filter';
|
|
12
|
-
import { NormalizedInputOptionsImpl } from '../options/normalized-input-options';
|
|
13
|
-
import { normalizeErrors } from '../utils/error';
|
|
14
|
-
export function bindingifyBuildStart(args) {
|
|
15
|
-
const hook = args.plugin.buildStart;
|
|
16
|
-
if (!hook) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
const { handler, meta } = normalizeHook(hook);
|
|
20
|
-
return {
|
|
21
|
-
plugin: async (ctx, opts) => {
|
|
22
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedInputOptionsImpl(opts, args.onLog));
|
|
23
|
-
},
|
|
24
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export function bindingifyBuildEnd(args) {
|
|
28
|
-
const hook = args.plugin.buildEnd;
|
|
29
|
-
if (!hook) {
|
|
30
|
-
return {};
|
|
31
|
-
}
|
|
32
|
-
const { handler, meta } = normalizeHook(hook);
|
|
33
|
-
return {
|
|
34
|
-
plugin: async (ctx, err) => {
|
|
35
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
|
|
36
|
-
},
|
|
37
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export function bindingifyResolveId(args) {
|
|
41
|
-
const hook = args.plugin.resolveId;
|
|
42
|
-
if (!hook) {
|
|
43
|
-
return {};
|
|
44
|
-
}
|
|
45
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
46
|
-
return {
|
|
47
|
-
plugin: async (ctx, specifier, importer, extraOptions) => {
|
|
48
|
-
const contextResolveOptions = extraOptions.custom != null
|
|
49
|
-
? args.pluginContextData.getSavedResolveOptions(extraOptions.custom)
|
|
50
|
-
: undefined;
|
|
51
|
-
const newExtraOptions = {
|
|
52
|
-
...extraOptions,
|
|
53
|
-
custom: contextResolveOptions?.custom,
|
|
54
|
-
[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF],
|
|
55
|
-
};
|
|
56
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined, newExtraOptions);
|
|
57
|
-
if (ret == null) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (ret === false) {
|
|
61
|
-
return {
|
|
62
|
-
id: specifier,
|
|
63
|
-
external: true,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (typeof ret === 'string') {
|
|
67
|
-
return {
|
|
68
|
-
id: ret,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
args.pluginContextData.updateModuleOption(ret.id, {
|
|
72
|
-
meta: ret.meta || {},
|
|
73
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
74
|
-
});
|
|
75
|
-
return {
|
|
76
|
-
id: ret.id,
|
|
77
|
-
external: ret.external,
|
|
78
|
-
sideEffects: bindingifySideEffects(ret.moduleSideEffects),
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
82
|
-
filter: bindingifyResolveIdFilter(options.filter),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
export function bindingifyResolveDynamicImport(args) {
|
|
86
|
-
const hook = args.plugin.resolveDynamicImport;
|
|
87
|
-
if (!hook) {
|
|
88
|
-
return {};
|
|
89
|
-
}
|
|
90
|
-
const { handler, meta } = normalizeHook(hook);
|
|
91
|
-
return {
|
|
92
|
-
plugin: async (ctx, specifier, importer) => {
|
|
93
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined);
|
|
94
|
-
if (ret == null) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (ret === false) {
|
|
98
|
-
return {
|
|
99
|
-
id: specifier,
|
|
100
|
-
external: true,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (typeof ret === 'string') {
|
|
104
|
-
return {
|
|
105
|
-
id: ret,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
const result = {
|
|
109
|
-
id: ret.id,
|
|
110
|
-
external: ret.external,
|
|
111
|
-
};
|
|
112
|
-
if (ret.moduleSideEffects !== null) {
|
|
113
|
-
result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
|
|
114
|
-
}
|
|
115
|
-
args.pluginContextData.updateModuleOption(ret.id, {
|
|
116
|
-
meta: ret.meta || {},
|
|
117
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
118
|
-
});
|
|
119
|
-
return result;
|
|
120
|
-
},
|
|
121
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
export function bindingifyTransform(args) {
|
|
125
|
-
const hook = args.plugin.transform;
|
|
126
|
-
if (!hook) {
|
|
127
|
-
return {};
|
|
128
|
-
}
|
|
129
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
130
|
-
return {
|
|
131
|
-
plugin: async (ctx, code, id, meta) => {
|
|
132
|
-
const ret = await handler.call(new TransformPluginContext(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel), code, id, meta);
|
|
133
|
-
if (ret == null) {
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
if (typeof ret === 'string') {
|
|
137
|
-
return { code: ret };
|
|
138
|
-
}
|
|
139
|
-
args.pluginContextData.updateModuleOption(id, {
|
|
140
|
-
meta: ret.meta || {},
|
|
141
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
142
|
-
});
|
|
143
|
-
return {
|
|
144
|
-
code: ret.code,
|
|
145
|
-
map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, ret.map)),
|
|
146
|
-
sideEffects: bindingifySideEffects(ret.moduleSideEffects),
|
|
147
|
-
moduleType: ret.moduleType,
|
|
148
|
-
};
|
|
149
|
-
},
|
|
150
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
151
|
-
filter: bindingifyTransformFilter(options.filter),
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export function bindingifyLoad(args) {
|
|
155
|
-
const hook = args.plugin.load;
|
|
156
|
-
if (!hook) {
|
|
157
|
-
return {};
|
|
158
|
-
}
|
|
159
|
-
const { handler, meta, options } = normalizeHook(hook);
|
|
160
|
-
return {
|
|
161
|
-
plugin: async (ctx, id) => {
|
|
162
|
-
const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, id), id);
|
|
163
|
-
if (ret == null) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (typeof ret === 'string') {
|
|
167
|
-
return { code: ret };
|
|
168
|
-
}
|
|
169
|
-
args.pluginContextData.updateModuleOption(id, {
|
|
170
|
-
meta: ret.meta || {},
|
|
171
|
-
moduleSideEffects: ret.moduleSideEffects || null,
|
|
172
|
-
});
|
|
173
|
-
let map = preProcessSourceMap(ret, id);
|
|
174
|
-
return {
|
|
175
|
-
code: ret.code,
|
|
176
|
-
map: bindingifySourcemap(map),
|
|
177
|
-
moduleType: ret.moduleType,
|
|
178
|
-
sideEffects: bindingifySideEffects(ret.moduleSideEffects),
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
182
|
-
filter: bindingifyLoadFilter(options.filter),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function preProcessSourceMap(ret, id) {
|
|
186
|
-
if (!ret.map) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
let map = typeof ret.map === 'object'
|
|
190
|
-
? ret.map
|
|
191
|
-
: JSON.parse(ret.map);
|
|
192
|
-
if (!isEmptySourcemapFiled(map.sources)) {
|
|
193
|
-
// normalize original sourcemap sources
|
|
194
|
-
// Port form https://github.com/rollup/rollup/blob/master/src/utils/collapseSourcemaps.ts#L180-L188.
|
|
195
|
-
const directory = path.dirname(id) || '.';
|
|
196
|
-
const sourceRoot = map.sourceRoot || '.';
|
|
197
|
-
map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
|
|
198
|
-
}
|
|
199
|
-
return map;
|
|
200
|
-
}
|
|
201
|
-
export function bindingifyModuleParsed(args) {
|
|
202
|
-
const hook = args.plugin.moduleParsed;
|
|
203
|
-
if (!hook) {
|
|
204
|
-
return {};
|
|
205
|
-
}
|
|
206
|
-
const { handler, meta } = normalizeHook(hook);
|
|
207
|
-
return {
|
|
208
|
-
plugin: async (ctx, moduleInfo) => {
|
|
209
|
-
await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
210
|
-
},
|
|
211
|
-
meta: bindingifyPluginHookMeta(meta),
|
|
212
|
-
};
|
|
213
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { arraify } from '../utils/misc';
|
|
2
|
-
export function bindingifyStringFilter(matcher) {
|
|
3
|
-
if (typeof matcher === 'string' || matcher instanceof RegExp) {
|
|
4
|
-
return { include: [matcher] };
|
|
5
|
-
}
|
|
6
|
-
if (Array.isArray(matcher)) {
|
|
7
|
-
return { include: matcher };
|
|
8
|
-
}
|
|
9
|
-
return {
|
|
10
|
-
include: matcher.include ? arraify(matcher.include) : undefined,
|
|
11
|
-
exclude: matcher.exclude ? arraify(matcher.exclude) : undefined,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export function bindingifyResolveIdFilter(filterOption) {
|
|
15
|
-
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
|
|
16
|
-
}
|
|
17
|
-
export function bindingifyLoadFilter(filterOption) {
|
|
18
|
-
return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
|
|
19
|
-
}
|
|
20
|
-
export function bindingifyTransformFilter(filterOption) {
|
|
21
|
-
if (!filterOption) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
const { id, code, moduleType } = filterOption;
|
|
25
|
-
let moduleTypeRet;
|
|
26
|
-
if (moduleType) {
|
|
27
|
-
if (Array.isArray(moduleType)) {
|
|
28
|
-
moduleTypeRet = moduleType;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
moduleTypeRet = moduleType.include;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
id: id ? bindingifyStringFilter(id) : undefined,
|
|
36
|
-
code: code ? bindingifyStringFilter(code) : undefined,
|
|
37
|
-
moduleType: moduleTypeRet,
|
|
38
|
-
};
|
|
39
|
-
}
|