rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.2-commit.f069c5d
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-BRzD1T3r.cjs} +12 -6
- package/dist/shared/{src-CPCP99Z9.mjs → src-Cmr3pg11.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,73 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
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(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(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(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(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(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(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(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
|
|
210
|
+
},
|
|
211
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { normalizeHook } from '../utils/normalize-hook';
|
|
2
|
+
import { collectChangedBundle, transformToOutputBundle, } from '../utils/transform-to-rollup-output';
|
|
3
|
+
import { PluginContext } from './plugin-context';
|
|
4
|
+
import { bindingifySourcemap } from '../types/sourcemap';
|
|
5
|
+
import { bindingifyPluginHookMeta, } from './bindingify-plugin-hook-meta';
|
|
6
|
+
import { NormalizedInputOptionsImpl } from '../options/normalized-input-options';
|
|
7
|
+
import { NormalizedOutputOptionsImpl } from '../options/normalized-output-options';
|
|
8
|
+
import { transformRenderedChunk } from '../utils/transform-rendered-chunk';
|
|
9
|
+
import { normalizeErrors } from '../utils/error';
|
|
10
|
+
export function bindingifyRenderStart(args) {
|
|
11
|
+
const hook = args.plugin.renderStart;
|
|
12
|
+
if (!hook) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const { handler, meta } = normalizeHook(hook);
|
|
16
|
+
return {
|
|
17
|
+
plugin: async (ctx, opts) => {
|
|
18
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), new NormalizedInputOptionsImpl(opts, args.onLog));
|
|
19
|
+
},
|
|
20
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function bindingifyRenderChunk(args) {
|
|
24
|
+
const hook = args.plugin.renderChunk;
|
|
25
|
+
if (!hook) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
const { handler, meta } = normalizeHook(hook);
|
|
29
|
+
return {
|
|
30
|
+
plugin: async (ctx, code, chunk, opts) => {
|
|
31
|
+
const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts));
|
|
32
|
+
if (ret == null) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof ret === 'string') {
|
|
36
|
+
return { code: ret };
|
|
37
|
+
}
|
|
38
|
+
if (!ret.map) {
|
|
39
|
+
return { code: ret.code };
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
code: ret.code,
|
|
43
|
+
map: bindingifySourcemap(ret.map),
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function bindingifyAugmentChunkHash(args) {
|
|
50
|
+
const hook = args.plugin.augmentChunkHash;
|
|
51
|
+
if (!hook) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
const { handler, meta } = normalizeHook(hook);
|
|
55
|
+
return {
|
|
56
|
+
plugin: async (ctx, chunk) => {
|
|
57
|
+
return await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
58
|
+
},
|
|
59
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function bindingifyRenderError(args) {
|
|
63
|
+
const hook = args.plugin.renderError;
|
|
64
|
+
if (!hook) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
const { handler, meta } = normalizeHook(hook);
|
|
68
|
+
return {
|
|
69
|
+
plugin: async (ctx, err) => {
|
|
70
|
+
handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
|
|
71
|
+
},
|
|
72
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function bindingifyGenerateBundle(args) {
|
|
76
|
+
const hook = args.plugin.generateBundle;
|
|
77
|
+
if (!hook) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const { handler, meta } = normalizeHook(hook);
|
|
81
|
+
return {
|
|
82
|
+
plugin: async (ctx, bundle, isWrite, opts) => {
|
|
83
|
+
const changed = {
|
|
84
|
+
updated: new Set(),
|
|
85
|
+
deleted: new Set(),
|
|
86
|
+
};
|
|
87
|
+
const output = transformToOutputBundle(bundle, changed);
|
|
88
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output, isWrite);
|
|
89
|
+
return collectChangedBundle(changed, output);
|
|
90
|
+
},
|
|
91
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function bindingifyWriteBundle(args) {
|
|
95
|
+
const hook = args.plugin.writeBundle;
|
|
96
|
+
if (!hook) {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
const { handler, meta } = normalizeHook(hook);
|
|
100
|
+
return {
|
|
101
|
+
plugin: async (ctx, bundle, opts) => {
|
|
102
|
+
const changed = {
|
|
103
|
+
updated: new Set(),
|
|
104
|
+
deleted: new Set(),
|
|
105
|
+
};
|
|
106
|
+
const output = transformToOutputBundle(bundle, changed);
|
|
107
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output);
|
|
108
|
+
return collectChangedBundle(changed, output);
|
|
109
|
+
},
|
|
110
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function bindingifyCloseBundle(args) {
|
|
114
|
+
const hook = args.plugin.closeBundle;
|
|
115
|
+
if (!hook) {
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
const { handler, meta } = normalizeHook(hook);
|
|
119
|
+
return {
|
|
120
|
+
plugin: async (ctx) => {
|
|
121
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
|
|
122
|
+
},
|
|
123
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function bindingifyBanner(args) {
|
|
127
|
+
const hook = args.plugin.banner;
|
|
128
|
+
if (!hook) {
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
const { handler, meta } = normalizeHook(hook);
|
|
132
|
+
return {
|
|
133
|
+
plugin: async (ctx, chunk) => {
|
|
134
|
+
if (typeof handler === 'string') {
|
|
135
|
+
return handler;
|
|
136
|
+
}
|
|
137
|
+
return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
138
|
+
},
|
|
139
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function bindingifyFooter(args) {
|
|
143
|
+
const hook = args.plugin.footer;
|
|
144
|
+
if (!hook) {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
const { handler, meta } = normalizeHook(hook);
|
|
148
|
+
return {
|
|
149
|
+
plugin: async (ctx, chunk) => {
|
|
150
|
+
if (typeof handler === 'string') {
|
|
151
|
+
return handler;
|
|
152
|
+
}
|
|
153
|
+
return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
154
|
+
},
|
|
155
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export function bindingifyIntro(args) {
|
|
159
|
+
const hook = args.plugin.intro;
|
|
160
|
+
if (!hook) {
|
|
161
|
+
return {};
|
|
162
|
+
}
|
|
163
|
+
const { handler, meta } = normalizeHook(hook);
|
|
164
|
+
return {
|
|
165
|
+
plugin: async (ctx, chunk) => {
|
|
166
|
+
if (typeof handler === 'string') {
|
|
167
|
+
return handler;
|
|
168
|
+
}
|
|
169
|
+
return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
170
|
+
},
|
|
171
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function bindingifyOutro(args) {
|
|
175
|
+
const hook = args.plugin.outro;
|
|
176
|
+
if (!hook) {
|
|
177
|
+
return {};
|
|
178
|
+
}
|
|
179
|
+
const { handler, meta } = normalizeHook(hook);
|
|
180
|
+
return {
|
|
181
|
+
plugin: async (ctx, chunk) => {
|
|
182
|
+
if (typeof handler === 'string') {
|
|
183
|
+
return handler;
|
|
184
|
+
}
|
|
185
|
+
return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
|
|
186
|
+
},
|
|
187
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BindingPluginOrder } from '../binding';
|
|
2
|
+
export function bindingifyPluginHookMeta(options) {
|
|
3
|
+
return {
|
|
4
|
+
order: bindingPluginOrder(options.order),
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
function bindingPluginOrder(order) {
|
|
8
|
+
switch (order) {
|
|
9
|
+
case 'post':
|
|
10
|
+
return BindingPluginOrder.Post;
|
|
11
|
+
case 'pre':
|
|
12
|
+
return BindingPluginOrder.Pre;
|
|
13
|
+
case null:
|
|
14
|
+
case undefined:
|
|
15
|
+
return undefined;
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(`Unknown plugin order: ${order}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { bindingifyBuildEnd, bindingifyBuildStart, bindingifyLoad, bindingifyModuleParsed, bindingifyResolveDynamicImport, bindingifyResolveId, bindingifyTransform, } from './bindingify-build-hooks';
|
|
2
|
+
import { bindingifyRenderStart, bindingifyRenderChunk, bindingifyGenerateBundle, bindingifyWriteBundle, bindingifyRenderError, bindingifyAugmentChunkHash, bindingifyBanner, bindingifyFooter, bindingifyIntro, bindingifyOutro, bindingifyCloseBundle, } from './bindingify-output-hooks';
|
|
3
|
+
import { bindingifyCloseWatcher, bindingifyWatchChange, } from './bindingify-watch-hooks';
|
|
4
|
+
import { error, logPluginError } from '../log/logs';
|
|
5
|
+
// Note: because napi not catch error, so we need to catch error and print error to debugger in adapter.
|
|
6
|
+
export function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, onLog, logLevel) {
|
|
7
|
+
const args = {
|
|
8
|
+
plugin,
|
|
9
|
+
options,
|
|
10
|
+
outputOptions,
|
|
11
|
+
pluginContextData,
|
|
12
|
+
onLog,
|
|
13
|
+
logLevel,
|
|
14
|
+
};
|
|
15
|
+
const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
|
|
16
|
+
const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter, } = bindingifyResolveId(args);
|
|
17
|
+
const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
|
|
18
|
+
const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
|
|
19
|
+
const { plugin: transform, meta: transformMeta, filter: transformFilter, } = bindingifyTransform(args);
|
|
20
|
+
const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
|
|
21
|
+
const { plugin: load, meta: loadMeta, filter: loadFilter, } = bindingifyLoad(args);
|
|
22
|
+
const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args);
|
|
23
|
+
const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
|
|
24
|
+
const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
|
|
25
|
+
const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
|
|
26
|
+
const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
|
|
27
|
+
const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
|
|
28
|
+
const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
|
|
29
|
+
const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
|
|
30
|
+
const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
|
|
31
|
+
const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
|
|
32
|
+
const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
|
|
33
|
+
const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
|
|
34
|
+
const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
|
|
35
|
+
const result = {
|
|
36
|
+
// The plugin name already normalized at `normalizePlugins`, see `packages/rolldown/src/utils/normalize-plugin-option.ts`
|
|
37
|
+
name: plugin.name,
|
|
38
|
+
buildStart,
|
|
39
|
+
buildStartMeta,
|
|
40
|
+
resolveId,
|
|
41
|
+
resolveIdMeta,
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
resolveIdFilter,
|
|
44
|
+
resolveDynamicImport,
|
|
45
|
+
resolveDynamicImportMeta,
|
|
46
|
+
buildEnd,
|
|
47
|
+
buildEndMeta,
|
|
48
|
+
transform,
|
|
49
|
+
transformMeta,
|
|
50
|
+
transformFilter,
|
|
51
|
+
moduleParsed,
|
|
52
|
+
moduleParsedMeta,
|
|
53
|
+
load,
|
|
54
|
+
loadMeta,
|
|
55
|
+
loadFilter,
|
|
56
|
+
renderChunk,
|
|
57
|
+
renderChunkMeta,
|
|
58
|
+
augmentChunkHash,
|
|
59
|
+
augmentChunkHashMeta,
|
|
60
|
+
renderStart,
|
|
61
|
+
renderStartMeta,
|
|
62
|
+
renderError,
|
|
63
|
+
renderErrorMeta,
|
|
64
|
+
generateBundle,
|
|
65
|
+
generateBundleMeta,
|
|
66
|
+
writeBundle,
|
|
67
|
+
writeBundleMeta,
|
|
68
|
+
closeBundle,
|
|
69
|
+
closeBundleMeta,
|
|
70
|
+
banner,
|
|
71
|
+
bannerMeta,
|
|
72
|
+
footer,
|
|
73
|
+
footerMeta,
|
|
74
|
+
intro,
|
|
75
|
+
introMeta,
|
|
76
|
+
outro,
|
|
77
|
+
outroMeta,
|
|
78
|
+
watchChange,
|
|
79
|
+
watchChangeMeta,
|
|
80
|
+
closeWatcher,
|
|
81
|
+
closeWatcherMeta,
|
|
82
|
+
};
|
|
83
|
+
return wrapHandlers(result);
|
|
84
|
+
}
|
|
85
|
+
function wrapHandlers(plugin) {
|
|
86
|
+
for (const hookName of [
|
|
87
|
+
'buildStart',
|
|
88
|
+
'resolveId',
|
|
89
|
+
'resolveDynamicImport',
|
|
90
|
+
'buildEnd',
|
|
91
|
+
'transform',
|
|
92
|
+
'moduleParsed',
|
|
93
|
+
'load',
|
|
94
|
+
'renderChunk',
|
|
95
|
+
'augmentChunkHash',
|
|
96
|
+
'renderStart',
|
|
97
|
+
'renderError',
|
|
98
|
+
'generateBundle',
|
|
99
|
+
'writeBundle',
|
|
100
|
+
'closeBundle',
|
|
101
|
+
'banner',
|
|
102
|
+
'footer',
|
|
103
|
+
'intro',
|
|
104
|
+
'outro',
|
|
105
|
+
'watchChange',
|
|
106
|
+
'closeWatcher',
|
|
107
|
+
]) {
|
|
108
|
+
const handler = plugin[hookName];
|
|
109
|
+
if (handler) {
|
|
110
|
+
plugin[hookName] = async (...args) => {
|
|
111
|
+
try {
|
|
112
|
+
return await handler(...args);
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
return error(logPluginError(e, plugin.name, {
|
|
116
|
+
hook: hookName,
|
|
117
|
+
id: hookName === 'transform' ? args[2] : undefined,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return plugin;
|
|
124
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { normalizeHook } from '../utils/normalize-hook';
|
|
2
|
+
import { PluginContext } from './plugin-context';
|
|
3
|
+
import { bindingifyPluginHookMeta, } from './bindingify-plugin-hook-meta';
|
|
4
|
+
export function bindingifyWatchChange(args) {
|
|
5
|
+
const hook = args.plugin.watchChange;
|
|
6
|
+
if (!hook) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
const { handler, meta } = normalizeHook(hook);
|
|
10
|
+
return {
|
|
11
|
+
plugin: async (ctx, id, event) => {
|
|
12
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event: event });
|
|
13
|
+
},
|
|
14
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function bindingifyCloseWatcher(args) {
|
|
18
|
+
const hook = args.plugin.closeWatcher;
|
|
19
|
+
if (!hook) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
const { handler, meta } = normalizeHook(hook);
|
|
23
|
+
return {
|
|
24
|
+
plugin: async (ctx) => {
|
|
25
|
+
await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
|
|
26
|
+
},
|
|
27
|
+
meta: bindingifyPluginHookMeta(meta),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|