rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.10
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/bin/cli.mjs +2 -0
- package/dist/cli.cjs +1748 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1745 -0
- package/dist/config.cjs +12 -0
- package/dist/config.d.cts +12 -0
- package/dist/config.d.mts +12 -0
- package/dist/config.mjs +10 -0
- package/dist/experimental-index.cjs +132 -0
- package/dist/experimental-index.d.cts +96 -0
- package/dist/experimental-index.d.mts +96 -0
- package/dist/experimental-index.mjs +91 -0
- package/dist/filter-index.cjs +105 -0
- package/dist/filter-index.d.cts +5 -0
- package/dist/filter-index.d.mts +5 -0
- package/dist/filter-index.mjs +44 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +5 -0
- package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +7 -14
- package/dist/parallel-plugin-worker.d.cts +1 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -11
- package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
- package/dist/parallel-plugin.d.cts +15 -0
- package/dist/parallel-plugin.d.mts +15 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.cjs +4 -0
- package/dist/parse-ast-index.d.cts +9 -0
- package/dist/parse-ast-index.d.mts +9 -0
- package/dist/parse-ast-index.mjs +3 -0
- package/dist/shared/binding.d-Bl5Vi4GH.d.mts +1702 -0
- package/dist/shared/binding.d-DcFBMcjI.d.cts +1702 -0
- package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
- package/dist/shared/define-config.d-B2xOSmbM.d.cts +1082 -0
- package/dist/shared/define-config.d-USfUuKiR.d.mts +1082 -0
- package/dist/shared/load-config-D6gW8FDa.cjs +125 -0
- package/dist/shared/load-config-eyuttVHY.mjs +119 -0
- package/dist/shared/misc-BKp5iIef.cjs +67 -0
- package/dist/shared/misc-BN0nse6C.mjs +25 -0
- package/dist/shared/{binding-fhgdIkpS.cjs → parse-ast-index-BvK1MT-L.cjs} +347 -309
- package/dist/shared/{binding-Bl7VQy7c.mjs → parse-ast-index-PSQWLeSo.mjs} +334 -277
- package/dist/shared/prompt-8EeOGx1_.cjs +854 -0
- package/dist/shared/prompt-C3zHEaSG.mjs +852 -0
- package/dist/shared/src-C2v46mL8.cjs +4654 -0
- package/dist/shared/src-D-VRn8rI.mjs +4456 -0
- package/package.json +62 -61
- package/bin/cli.js +0 -2
- package/dist/cjs/cli.cjs +0 -769
- package/dist/cjs/experimental-index.cjs +0 -79
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parse-ast-index.cjs +0 -57
- package/dist/esm/cli.mjs +0 -766
- package/dist/esm/experimental-index.mjs +0 -56
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parse-ast-index.mjs +0 -55
- 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/shared/src-CPCP99Z9.mjs +0 -2641
- package/dist/shared/src-lBcHSsjm.cjs +0 -2822
- package/dist/tsconfig.dts.tsbuildinfo +0 -1
- package/dist/types/api/build.d.ts +0 -18
- package/dist/types/api/experimental.d.ts +0 -7
- package/dist/types/api/rolldown/index.d.ts +0 -3
- package/dist/types/api/rolldown/rolldown-build.d.ts +0 -12
- package/dist/types/api/watch/index.d.ts +0 -3
- package/dist/types/api/watch/watch-emitter.d.ts +0 -31
- package/dist/types/api/watch/watcher.d.ts +0 -13
- package/dist/types/binding.d.ts +0 -1288
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/constructors.d.ts +0 -20
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
- package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
- package/dist/types/builtin-plugin/utils.d.ts +0 -8
- package/dist/types/cli/arguments/alias.d.ts +0 -16
- package/dist/types/cli/arguments/index.d.ts +0 -15
- package/dist/types/cli/arguments/normalize.d.ts +0 -12
- package/dist/types/cli/arguments/utils.d.ts +0 -8
- package/dist/types/cli/colors.d.ts +0 -11
- package/dist/types/cli/commands/bundle.d.ts +0 -3
- package/dist/types/cli/commands/help.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/load-config.d.ts +0 -3
- package/dist/types/cli/logger.d.ts +0 -5
- package/dist/types/constants/plugin-context.d.ts +0 -7
- package/dist/types/constants/plugin.d.ts +0 -45
- package/dist/types/experimental-index.d.ts +0 -9
- package/dist/types/index.d.ts +0 -28
- package/dist/types/log/logHandler.d.ts +0 -4
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logging.d.ts +0 -11
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/options/input-options.d.ts +0 -125
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-output-options.d.ts +0 -67
- package/dist/types/options/output-options.d.ts +0 -80
- package/dist/types/options/watch-options.d.ts +0 -5
- package/dist/types/parallel-plugin-worker.d.ts +0 -1
- package/dist/types/parallel-plugin.d.ts +0 -1
- package/dist/types/parse-ast-index.d.ts +0 -4
- package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
- package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
- package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
- package/dist/types/plugin/bindingify-plugin.d.ts +0 -15
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
- package/dist/types/plugin/hook-filter.d.ts +0 -48
- package/dist/types/plugin/index.d.ts +0 -126
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -15
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
- package/dist/types/plugin/parallel-plugin.d.ts +0 -9
- package/dist/types/plugin/plugin-context-data.d.ts +0 -16
- package/dist/types/plugin/plugin-context.d.ts +0 -52
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -17
- package/dist/types/types/assert.d.ts +0 -13
- package/dist/types/types/config-export.d.ts +0 -5
- package/dist/types/types/misc.d.ts +0 -40
- package/dist/types/types/module-info.d.ts +0 -15
- package/dist/types/types/module-side-effects.d.ts +0 -10
- package/dist/types/types/output-bundle.d.ts +0 -4
- package/dist/types/types/rolldown-options.d.ts +0 -5
- package/dist/types/types/rolldown-output.d.ts +0 -63
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/sourcemap.d.ts +0 -13
- package/dist/types/types/utils.d.ts +0 -13
- package/dist/types/utils/asset-source.d.ts +0 -4
- package/dist/types/utils/async-flatten.d.ts +0 -1
- package/dist/types/utils/bindingify-input-options.d.ts +0 -7
- package/dist/types/utils/bindingify-output-options.d.ts +0 -3
- package/dist/types/utils/code-frame.d.ts +0 -1
- package/dist/types/utils/compose-js-plugins.d.ts +0 -2
- package/dist/types/utils/create-bundler-option.d.ts +0 -11
- package/dist/types/utils/create-bundler.d.ts +0 -8
- package/dist/types/utils/define-config.d.ts +0 -5
- package/dist/types/utils/error.d.ts +0 -2
- package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
- package/dist/types/utils/misc.d.ts +0 -6
- package/dist/types/utils/normalize-hook.d.ts +0 -7
- package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
- package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
- package/dist/types/utils/plugin/index.d.ts +0 -2
- package/dist/types/utils/transform-module-info.d.ts +0 -4
- package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
- package/dist/types/utils/transform-rendered-module.d.ts +0 -3
- package/dist/types/utils/transform-side-effects.d.ts +0 -3
- package/dist/types/utils/transform-sourcemap.d.ts +0 -3
- package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
- package/dist/types/utils/validator.d.ts +0 -7
|
@@ -1,261 +1,33 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
2
|
-
const node_process = require_chunk.__toESM(require("node:process"));
|
|
3
|
-
const tty = require_chunk.__toESM(require("tty"));
|
|
1
|
+
const require_chunk = require('./chunk-DDkG_k5U.cjs');
|
|
4
2
|
|
|
5
|
-
//#region src/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
while (!/\S/.test(lines[lines.length - 1])) {
|
|
25
|
-
lines.pop();
|
|
26
|
-
frameEnd -= 1;
|
|
27
|
-
}
|
|
28
|
-
const digits = String(frameEnd).length;
|
|
29
|
-
return lines.map((sourceLine, index) => {
|
|
30
|
-
const isErrorLine = frameStart + index + 1 === line;
|
|
31
|
-
let lineNumber = String(index + frameStart + 1);
|
|
32
|
-
while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
33
|
-
let displayedLine = tabsToSpaces(sourceLine);
|
|
34
|
-
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
35
|
-
if (isErrorLine) {
|
|
36
|
-
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
|
|
37
|
-
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
38
|
-
}
|
|
39
|
-
return `${lineNumber}: ${displayedLine}`;
|
|
40
|
-
}).join("\n");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/log/locate-character/index.js
|
|
45
|
-
/** @typedef {import('./types').Location} Location */
|
|
46
|
-
/**
|
|
47
|
-
* @param {import('./types').Range} range
|
|
48
|
-
* @param {number} index
|
|
49
|
-
*/
|
|
50
|
-
function rangeContains(range, index) {
|
|
51
|
-
return range.start <= index && index < range.end;
|
|
52
|
-
}
|
|
53
|
-
function getLocator(source, options = {}) {
|
|
54
|
-
const { offsetLine = 0, offsetColumn = 0 } = options;
|
|
55
|
-
let start = 0;
|
|
56
|
-
const ranges = source.split("\n").map((line, i$1) => {
|
|
57
|
-
const end = start + line.length + 1;
|
|
58
|
-
/** @type {import('./types').Range} */
|
|
59
|
-
const range = {
|
|
60
|
-
start,
|
|
61
|
-
end,
|
|
62
|
-
line: i$1
|
|
63
|
-
};
|
|
64
|
-
start = end;
|
|
65
|
-
return range;
|
|
66
|
-
});
|
|
67
|
-
let i = 0;
|
|
68
|
-
/**
|
|
69
|
-
* @param {string | number} search
|
|
70
|
-
* @param {number} [index]
|
|
71
|
-
* @returns {Location | undefined}
|
|
72
|
-
*/
|
|
73
|
-
function locator(search, index) {
|
|
74
|
-
if (typeof search === "string") search = source.indexOf(search, index ?? 0);
|
|
75
|
-
if (search === -1) return undefined;
|
|
76
|
-
let range = ranges[i];
|
|
77
|
-
const d = search >= range.end ? 1 : -1;
|
|
78
|
-
while (range) {
|
|
79
|
-
if (rangeContains(range, search)) return {
|
|
80
|
-
line: offsetLine + range.line,
|
|
81
|
-
column: offsetColumn + search - range.start,
|
|
82
|
-
character: search
|
|
83
|
-
};
|
|
84
|
-
i += d;
|
|
85
|
-
range = ranges[i];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return locator;
|
|
89
|
-
}
|
|
90
|
-
function locate(source, search, options) {
|
|
91
|
-
return getLocator(source, options)(search, options && options.startIndex);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
96
|
-
const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
97
|
-
const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
|
|
98
|
-
const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
|
|
99
|
-
const isWindows = platform === "win32";
|
|
100
|
-
const isDumbTerminal = env$1.TERM === "dumb";
|
|
101
|
-
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
|
|
102
|
-
const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
|
|
103
|
-
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
104
|
-
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
105
|
-
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
106
|
-
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
107
|
-
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
108
|
-
const colors$1 = {
|
|
109
|
-
reset: init(0, 0),
|
|
110
|
-
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
111
|
-
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
112
|
-
italic: init(3, 23),
|
|
113
|
-
underline: init(4, 24),
|
|
114
|
-
inverse: init(7, 27),
|
|
115
|
-
hidden: init(8, 28),
|
|
116
|
-
strikethrough: init(9, 29),
|
|
117
|
-
black: init(30, 39),
|
|
118
|
-
red: init(31, 39),
|
|
119
|
-
green: init(32, 39),
|
|
120
|
-
yellow: init(33, 39),
|
|
121
|
-
blue: init(34, 39),
|
|
122
|
-
magenta: init(35, 39),
|
|
123
|
-
cyan: init(36, 39),
|
|
124
|
-
white: init(37, 39),
|
|
125
|
-
gray: init(90, 39),
|
|
126
|
-
bgBlack: init(40, 49),
|
|
127
|
-
bgRed: init(41, 49),
|
|
128
|
-
bgGreen: init(42, 49),
|
|
129
|
-
bgYellow: init(43, 49),
|
|
130
|
-
bgBlue: init(44, 49),
|
|
131
|
-
bgMagenta: init(45, 49),
|
|
132
|
-
bgCyan: init(46, 49),
|
|
133
|
-
bgWhite: init(47, 49),
|
|
134
|
-
blackBright: init(90, 39),
|
|
135
|
-
redBright: init(91, 39),
|
|
136
|
-
greenBright: init(92, 39),
|
|
137
|
-
yellowBright: init(93, 39),
|
|
138
|
-
blueBright: init(94, 39),
|
|
139
|
-
magentaBright: init(95, 39),
|
|
140
|
-
cyanBright: init(96, 39),
|
|
141
|
-
whiteBright: init(97, 39),
|
|
142
|
-
bgBlackBright: init(100, 49),
|
|
143
|
-
bgRedBright: init(101, 49),
|
|
144
|
-
bgGreenBright: init(102, 49),
|
|
145
|
-
bgYellowBright: init(103, 49),
|
|
146
|
-
bgBlueBright: init(104, 49),
|
|
147
|
-
bgMagentaBright: init(105, 49),
|
|
148
|
-
bgCyanBright: init(106, 49),
|
|
149
|
-
bgWhiteBright: init(107, 49)
|
|
150
|
-
};
|
|
151
|
-
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors$1 : Object.keys(colors$1).reduce((colors$2, key) => ({
|
|
152
|
-
...colors$2,
|
|
153
|
-
[key]: String
|
|
154
|
-
}), {});
|
|
155
|
-
const { reset, bold: bold$1, dim: dim$1, italic, underline: underline$1, inverse, hidden, strikethrough, black, red: red$1, green: green$1, yellow: yellow$1, blue, magenta, cyan: cyan$1, white, gray: gray$1, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
|
|
156
|
-
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/cli/colors.ts
|
|
159
|
-
const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({ useColor: node_process.env.FORCE_COLOR !== "0" && !node_process.env.NO_COLOR });
|
|
160
|
-
const colors = {
|
|
161
|
-
bold,
|
|
162
|
-
cyan,
|
|
163
|
-
dim,
|
|
164
|
-
gray,
|
|
165
|
-
green,
|
|
166
|
-
red,
|
|
167
|
-
underline,
|
|
168
|
-
yellow
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/log/logs.ts
|
|
173
|
-
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";
|
|
174
|
-
function logParseError(message) {
|
|
175
|
-
return {
|
|
176
|
-
code: PARSE_ERROR,
|
|
177
|
-
message
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function logMinifyWarning() {
|
|
181
|
-
return {
|
|
182
|
-
code: MINIFY_WARNING,
|
|
183
|
-
message: colors.yellow("The built-in minifier is still under development. Setting \"minify: true\" is not recommended for production use.")
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function logInvalidLogPosition(pluginName) {
|
|
187
|
-
return {
|
|
188
|
-
code: INVALID_LOG_POSITION,
|
|
189
|
-
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.`
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function logInputHookInOutputPlugin(pluginName, hookName) {
|
|
193
|
-
return {
|
|
194
|
-
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
|
|
195
|
-
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.`
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function logCycleLoading(pluginName, moduleId) {
|
|
199
|
-
return {
|
|
200
|
-
code: CYCLE_LOADING,
|
|
201
|
-
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function logMultiplyNotifyOption() {
|
|
205
|
-
return {
|
|
206
|
-
code: MULTIPLY_NOTIFY_OPTION,
|
|
207
|
-
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
211
|
-
const code = error$1.code;
|
|
212
|
-
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
213
|
-
error$1.code = PLUGIN_ERROR;
|
|
214
|
-
error$1.plugin = plugin;
|
|
215
|
-
if (hook) error$1.hook = hook;
|
|
216
|
-
if (id) error$1.id = id;
|
|
217
|
-
return error$1;
|
|
218
|
-
}
|
|
219
|
-
function error(base) {
|
|
220
|
-
if (!(base instanceof Error)) {
|
|
221
|
-
base = Object.assign(new Error(base.message), base);
|
|
222
|
-
Object.defineProperty(base, "name", {
|
|
223
|
-
value: "RollupError",
|
|
224
|
-
writable: true
|
|
3
|
+
//#region src/webcontainer-fallback.js
|
|
4
|
+
var require_webcontainer_fallback = require_chunk.__commonJS({ "src/webcontainer-fallback.js"(exports, module) {
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const childProcess = require("node:child_process");
|
|
7
|
+
const rolldownPkg = JSON.parse(fs.readFileSync(require.resolve("rolldown/package.json"), "utf-8"));
|
|
8
|
+
const version = rolldownPkg.version;
|
|
9
|
+
const baseDir = `/tmp/rolldown-${version}`;
|
|
10
|
+
const bindingEntry = `${baseDir}/node_modules/@rolldown/binding-wasm32-wasi/rolldown-binding.wasi.cjs`;
|
|
11
|
+
if (!fs.existsSync(bindingEntry)) {
|
|
12
|
+
const bindingPkg = `@rolldown/binding-wasm32-wasi@${version}`;
|
|
13
|
+
fs.rmSync(baseDir, {
|
|
14
|
+
recursive: true,
|
|
15
|
+
force: true
|
|
16
|
+
});
|
|
17
|
+
fs.mkdirSync(baseDir, { recursive: true });
|
|
18
|
+
console.log(`[rolldown] Downloading ${bindingPkg} on WebContainer...`);
|
|
19
|
+
childProcess.execFileSync("pnpm", ["i", bindingPkg], {
|
|
20
|
+
cwd: baseDir,
|
|
21
|
+
stdio: "inherit"
|
|
225
22
|
});
|
|
226
23
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
function augmentCodeLocation(properties, pos, source, id) {
|
|
230
|
-
if (typeof pos === "object") {
|
|
231
|
-
const { line, column } = pos;
|
|
232
|
-
properties.loc = {
|
|
233
|
-
column,
|
|
234
|
-
file: id,
|
|
235
|
-
line
|
|
236
|
-
};
|
|
237
|
-
} else {
|
|
238
|
-
properties.pos = pos;
|
|
239
|
-
const location = locate(source, pos, { offsetLine: 1 });
|
|
240
|
-
if (!location) return;
|
|
241
|
-
const { line, column } = location;
|
|
242
|
-
properties.loc = {
|
|
243
|
-
column,
|
|
244
|
-
file: id,
|
|
245
|
-
line
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
if (properties.frame === undefined) {
|
|
249
|
-
const { line, column } = properties.loc;
|
|
250
|
-
properties.frame = getCodeFrame(source, line, column);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
24
|
+
module.exports = require(bindingEntry);
|
|
25
|
+
} });
|
|
253
26
|
|
|
254
27
|
//#endregion
|
|
255
28
|
//#region src/binding.js
|
|
256
29
|
var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, module) {
|
|
257
30
|
const { createRequire } = require("node:module");
|
|
258
|
-
require = createRequire(__filename);
|
|
259
31
|
const { readFileSync } = require("node:fs");
|
|
260
32
|
let nativeBinding = null;
|
|
261
33
|
const loadErrors = [];
|
|
@@ -277,7 +49,11 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
277
49
|
}
|
|
278
50
|
};
|
|
279
51
|
const isMuslFromReport = () => {
|
|
280
|
-
|
|
52
|
+
let report = null;
|
|
53
|
+
if (typeof process.report?.getReport === "function") {
|
|
54
|
+
process.report.excludeNetwork = true;
|
|
55
|
+
report = process.report.getReport();
|
|
56
|
+
}
|
|
281
57
|
if (!report) return null;
|
|
282
58
|
if (report.header && report.header.glibcVersionRuntime) return false;
|
|
283
59
|
if (Array.isArray(report.sharedObjects)) {
|
|
@@ -293,9 +69,14 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
293
69
|
}
|
|
294
70
|
};
|
|
295
71
|
function requireNative() {
|
|
296
|
-
if (process.
|
|
72
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) try {
|
|
73
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
loadErrors.push(err);
|
|
76
|
+
}
|
|
77
|
+
else if (process.platform === "android") if (process.arch === "arm64") {
|
|
297
78
|
try {
|
|
298
|
-
return require("
|
|
79
|
+
return require("../rolldown-binding.android-arm64.node");
|
|
299
80
|
} catch (e) {
|
|
300
81
|
loadErrors.push(e);
|
|
301
82
|
}
|
|
@@ -306,7 +87,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
306
87
|
}
|
|
307
88
|
} else if (process.arch === "arm") {
|
|
308
89
|
try {
|
|
309
|
-
return require("
|
|
90
|
+
return require("../rolldown-binding.android-arm-eabi.node");
|
|
310
91
|
} catch (e) {
|
|
311
92
|
loadErrors.push(e);
|
|
312
93
|
}
|
|
@@ -318,7 +99,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
318
99
|
} else loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
|
|
319
100
|
else if (process.platform === "win32") if (process.arch === "x64") {
|
|
320
101
|
try {
|
|
321
|
-
return require("
|
|
102
|
+
return require("../rolldown-binding.win32-x64-msvc.node");
|
|
322
103
|
} catch (e) {
|
|
323
104
|
loadErrors.push(e);
|
|
324
105
|
}
|
|
@@ -329,7 +110,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
329
110
|
}
|
|
330
111
|
} else if (process.arch === "ia32") {
|
|
331
112
|
try {
|
|
332
|
-
return require("
|
|
113
|
+
return require("../rolldown-binding.win32-ia32-msvc.node");
|
|
333
114
|
} catch (e) {
|
|
334
115
|
loadErrors.push(e);
|
|
335
116
|
}
|
|
@@ -340,7 +121,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
340
121
|
}
|
|
341
122
|
} else if (process.arch === "arm64") {
|
|
342
123
|
try {
|
|
343
|
-
return require("
|
|
124
|
+
return require("../rolldown-binding.win32-arm64-msvc.node");
|
|
344
125
|
} catch (e) {
|
|
345
126
|
loadErrors.push(e);
|
|
346
127
|
}
|
|
@@ -352,7 +133,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
352
133
|
} else loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
|
|
353
134
|
else if (process.platform === "darwin") {
|
|
354
135
|
try {
|
|
355
|
-
return require("
|
|
136
|
+
return require("../rolldown-binding.darwin-universal.node");
|
|
356
137
|
} catch (e) {
|
|
357
138
|
loadErrors.push(e);
|
|
358
139
|
}
|
|
@@ -363,7 +144,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
363
144
|
}
|
|
364
145
|
if (process.arch === "x64") {
|
|
365
146
|
try {
|
|
366
|
-
return require("
|
|
147
|
+
return require("../rolldown-binding.darwin-x64.node");
|
|
367
148
|
} catch (e) {
|
|
368
149
|
loadErrors.push(e);
|
|
369
150
|
}
|
|
@@ -374,7 +155,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
374
155
|
}
|
|
375
156
|
} else if (process.arch === "arm64") {
|
|
376
157
|
try {
|
|
377
|
-
return require("
|
|
158
|
+
return require("../rolldown-binding.darwin-arm64.node");
|
|
378
159
|
} catch (e) {
|
|
379
160
|
loadErrors.push(e);
|
|
380
161
|
}
|
|
@@ -386,7 +167,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
386
167
|
} else loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
|
|
387
168
|
} else if (process.platform === "freebsd") if (process.arch === "x64") {
|
|
388
169
|
try {
|
|
389
|
-
return require("
|
|
170
|
+
return require("../rolldown-binding.freebsd-x64.node");
|
|
390
171
|
} catch (e) {
|
|
391
172
|
loadErrors.push(e);
|
|
392
173
|
}
|
|
@@ -397,7 +178,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
397
178
|
}
|
|
398
179
|
} else if (process.arch === "arm64") {
|
|
399
180
|
try {
|
|
400
|
-
return require("
|
|
181
|
+
return require("../rolldown-binding.freebsd-arm64.node");
|
|
401
182
|
} catch (e) {
|
|
402
183
|
loadErrors.push(e);
|
|
403
184
|
}
|
|
@@ -409,7 +190,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
409
190
|
} else loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
|
|
410
191
|
else if (process.platform === "linux") if (process.arch === "x64") if (isMusl()) {
|
|
411
192
|
try {
|
|
412
|
-
return require("
|
|
193
|
+
return require("../rolldown-binding.linux-x64-musl.node");
|
|
413
194
|
} catch (e) {
|
|
414
195
|
loadErrors.push(e);
|
|
415
196
|
}
|
|
@@ -420,7 +201,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
420
201
|
}
|
|
421
202
|
} else {
|
|
422
203
|
try {
|
|
423
|
-
return require("
|
|
204
|
+
return require("../rolldown-binding.linux-x64-gnu.node");
|
|
424
205
|
} catch (e) {
|
|
425
206
|
loadErrors.push(e);
|
|
426
207
|
}
|
|
@@ -432,7 +213,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
432
213
|
}
|
|
433
214
|
else if (process.arch === "arm64") if (isMusl()) {
|
|
434
215
|
try {
|
|
435
|
-
return require("
|
|
216
|
+
return require("../rolldown-binding.linux-arm64-musl.node");
|
|
436
217
|
} catch (e) {
|
|
437
218
|
loadErrors.push(e);
|
|
438
219
|
}
|
|
@@ -443,7 +224,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
443
224
|
}
|
|
444
225
|
} else {
|
|
445
226
|
try {
|
|
446
|
-
return require("
|
|
227
|
+
return require("../rolldown-binding.linux-arm64-gnu.node");
|
|
447
228
|
} catch (e) {
|
|
448
229
|
loadErrors.push(e);
|
|
449
230
|
}
|
|
@@ -455,7 +236,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
455
236
|
}
|
|
456
237
|
else if (process.arch === "arm") if (isMusl()) {
|
|
457
238
|
try {
|
|
458
|
-
return require("
|
|
239
|
+
return require("../rolldown-binding.linux-arm-musleabihf.node");
|
|
459
240
|
} catch (e) {
|
|
460
241
|
loadErrors.push(e);
|
|
461
242
|
}
|
|
@@ -466,7 +247,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
466
247
|
}
|
|
467
248
|
} else {
|
|
468
249
|
try {
|
|
469
|
-
return require("
|
|
250
|
+
return require("../rolldown-binding.linux-arm-gnueabihf.node");
|
|
470
251
|
} catch (e) {
|
|
471
252
|
loadErrors.push(e);
|
|
472
253
|
}
|
|
@@ -478,7 +259,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
478
259
|
}
|
|
479
260
|
else if (process.arch === "riscv64") if (isMusl()) {
|
|
480
261
|
try {
|
|
481
|
-
return require("
|
|
262
|
+
return require("../rolldown-binding.linux-riscv64-musl.node");
|
|
482
263
|
} catch (e) {
|
|
483
264
|
loadErrors.push(e);
|
|
484
265
|
}
|
|
@@ -489,7 +270,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
489
270
|
}
|
|
490
271
|
} else {
|
|
491
272
|
try {
|
|
492
|
-
return require("
|
|
273
|
+
return require("../rolldown-binding.linux-riscv64-gnu.node");
|
|
493
274
|
} catch (e) {
|
|
494
275
|
loadErrors.push(e);
|
|
495
276
|
}
|
|
@@ -501,7 +282,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
501
282
|
}
|
|
502
283
|
else if (process.arch === "ppc64") {
|
|
503
284
|
try {
|
|
504
|
-
return require("
|
|
285
|
+
return require("../rolldown-binding.linux-ppc64-gnu.node");
|
|
505
286
|
} catch (e) {
|
|
506
287
|
loadErrors.push(e);
|
|
507
288
|
}
|
|
@@ -512,7 +293,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
512
293
|
}
|
|
513
294
|
} else if (process.arch === "s390x") {
|
|
514
295
|
try {
|
|
515
|
-
return require("
|
|
296
|
+
return require("../rolldown-binding.linux-s390x-gnu.node");
|
|
516
297
|
} catch (e) {
|
|
517
298
|
loadErrors.push(e);
|
|
518
299
|
}
|
|
@@ -527,7 +308,7 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
527
308
|
nativeBinding = requireNative();
|
|
528
309
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
529
310
|
try {
|
|
530
|
-
nativeBinding = require("
|
|
311
|
+
nativeBinding = require("../rolldown-binding.wasi.cjs");
|
|
531
312
|
} catch (err) {
|
|
532
313
|
if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
|
|
533
314
|
}
|
|
@@ -537,48 +318,323 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
|
|
|
537
318
|
if (process.env.NAPI_RS_FORCE_WASI) loadErrors.push(err);
|
|
538
319
|
}
|
|
539
320
|
}
|
|
321
|
+
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) try {
|
|
322
|
+
nativeBinding = require_webcontainer_fallback();
|
|
323
|
+
} catch (err) {
|
|
324
|
+
loadErrors.push(err);
|
|
325
|
+
}
|
|
540
326
|
if (!nativeBinding) {
|
|
541
327
|
if (loadErrors.length > 0) throw new Error("Failed to load native binding", { cause: loadErrors });
|
|
542
328
|
throw new Error(`Failed to load native binding`);
|
|
543
329
|
}
|
|
330
|
+
module.exports = nativeBinding;
|
|
544
331
|
module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
|
|
332
|
+
module.exports.BindingBundleErrorEventData = nativeBinding.BindingBundleErrorEventData;
|
|
545
333
|
module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
|
|
546
334
|
module.exports.BindingError = nativeBinding.BindingError;
|
|
547
|
-
module.exports.BindingLog = nativeBinding.BindingLog;
|
|
548
335
|
module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
|
|
549
336
|
module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
|
|
550
337
|
module.exports.BindingOutputAsset = nativeBinding.BindingOutputAsset;
|
|
551
338
|
module.exports.BindingOutputChunk = nativeBinding.BindingOutputChunk;
|
|
552
339
|
module.exports.BindingOutputs = nativeBinding.BindingOutputs;
|
|
553
340
|
module.exports.BindingPluginContext = nativeBinding.BindingPluginContext;
|
|
341
|
+
module.exports.BindingRenderedChunk = nativeBinding.BindingRenderedChunk;
|
|
342
|
+
module.exports.BindingRenderedChunkMeta = nativeBinding.BindingRenderedChunkMeta;
|
|
554
343
|
module.exports.BindingRenderedModule = nativeBinding.BindingRenderedModule;
|
|
555
344
|
module.exports.BindingTransformPluginContext = nativeBinding.BindingTransformPluginContext;
|
|
556
345
|
module.exports.BindingWatcher = nativeBinding.BindingWatcher;
|
|
557
346
|
module.exports.BindingWatcherChangeData = nativeBinding.BindingWatcherChangeData;
|
|
558
347
|
module.exports.BindingWatcherEvent = nativeBinding.BindingWatcherEvent;
|
|
559
348
|
module.exports.Bundler = nativeBinding.Bundler;
|
|
560
|
-
module.exports.MagicString = nativeBinding.MagicString;
|
|
561
349
|
module.exports.ParallelJsPluginRegistry = nativeBinding.ParallelJsPluginRegistry;
|
|
562
350
|
module.exports.ParseResult = nativeBinding.ParseResult;
|
|
563
|
-
module.exports.
|
|
351
|
+
module.exports.ResolverFactory = nativeBinding.ResolverFactory;
|
|
564
352
|
module.exports.BindingBuiltinPluginName = nativeBinding.BindingBuiltinPluginName;
|
|
565
353
|
module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
|
|
354
|
+
module.exports.BindingJsx = nativeBinding.BindingJsx;
|
|
566
355
|
module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
|
|
567
356
|
module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
|
|
357
|
+
module.exports.EnforceExtension = nativeBinding.EnforceExtension;
|
|
568
358
|
module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind;
|
|
569
359
|
module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind;
|
|
570
360
|
module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind;
|
|
361
|
+
module.exports.FilterTokenKind = nativeBinding.FilterTokenKind;
|
|
362
|
+
module.exports.getBufferOffset = nativeBinding.getBufferOffset;
|
|
571
363
|
module.exports.HelperMode = nativeBinding.HelperMode;
|
|
572
364
|
module.exports.ImportNameKind = nativeBinding.ImportNameKind;
|
|
573
365
|
module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
|
|
366
|
+
module.exports.moduleRunnerTransform = nativeBinding.moduleRunnerTransform;
|
|
367
|
+
module.exports.ModuleType = nativeBinding.ModuleType;
|
|
574
368
|
module.exports.parseAsync = nativeBinding.parseAsync;
|
|
369
|
+
module.exports.parseAsyncRaw = nativeBinding.parseAsyncRaw;
|
|
575
370
|
module.exports.parseSync = nativeBinding.parseSync;
|
|
576
|
-
module.exports.
|
|
371
|
+
module.exports.parseSyncRaw = nativeBinding.parseSyncRaw;
|
|
372
|
+
module.exports.rawTransferSupported = nativeBinding.rawTransferSupported;
|
|
577
373
|
module.exports.registerPlugins = nativeBinding.registerPlugins;
|
|
578
374
|
module.exports.Severity = nativeBinding.Severity;
|
|
375
|
+
module.exports.shutdownAsyncRuntime = nativeBinding.shutdownAsyncRuntime;
|
|
376
|
+
module.exports.startAsyncRuntime = nativeBinding.startAsyncRuntime;
|
|
377
|
+
module.exports.sync = nativeBinding.sync;
|
|
579
378
|
module.exports.transform = nativeBinding.transform;
|
|
580
379
|
} });
|
|
380
|
+
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/utils/code-frame.ts
|
|
383
|
+
function spaces(index) {
|
|
384
|
+
let result = "";
|
|
385
|
+
while (index--) result += " ";
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
function tabsToSpaces(value) {
|
|
389
|
+
return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
|
|
390
|
+
}
|
|
391
|
+
const LINE_TRUNCATE_LENGTH = 120;
|
|
392
|
+
const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
|
|
393
|
+
const ELLIPSIS = "...";
|
|
394
|
+
function getCodeFrame(source, line, column) {
|
|
395
|
+
let lines = source.split("\n");
|
|
396
|
+
if (line > lines.length) return "";
|
|
397
|
+
const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
|
|
398
|
+
const frameStart = Math.max(0, line - 3);
|
|
399
|
+
let frameEnd = Math.min(line + 2, lines.length);
|
|
400
|
+
lines = lines.slice(frameStart, frameEnd);
|
|
401
|
+
while (!/\S/.test(lines[lines.length - 1])) {
|
|
402
|
+
lines.pop();
|
|
403
|
+
frameEnd -= 1;
|
|
404
|
+
}
|
|
405
|
+
const digits = String(frameEnd).length;
|
|
406
|
+
return lines.map((sourceLine, index) => {
|
|
407
|
+
const isErrorLine = frameStart + index + 1 === line;
|
|
408
|
+
let lineNumber = String(index + frameStart + 1);
|
|
409
|
+
while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
|
|
410
|
+
let displayedLine = tabsToSpaces(sourceLine);
|
|
411
|
+
if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
|
|
412
|
+
if (isErrorLine) {
|
|
413
|
+
const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
|
|
414
|
+
return `${lineNumber}: ${displayedLine}\n${indicator}`;
|
|
415
|
+
}
|
|
416
|
+
return `${lineNumber}: ${displayedLine}`;
|
|
417
|
+
}).join("\n");
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/log/locate-character/index.js
|
|
422
|
+
/** @typedef {import('./types').Location} Location */
|
|
423
|
+
/**
|
|
424
|
+
* @param {import('./types').Range} range
|
|
425
|
+
* @param {number} index
|
|
426
|
+
*/
|
|
427
|
+
function rangeContains(range, index) {
|
|
428
|
+
return range.start <= index && index < range.end;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* @param {string} source
|
|
432
|
+
* @param {import('./types').Options} [options]
|
|
433
|
+
*/
|
|
434
|
+
function getLocator(source, options = {}) {
|
|
435
|
+
const { offsetLine = 0, offsetColumn = 0 } = options;
|
|
436
|
+
let start = 0;
|
|
437
|
+
const ranges = source.split("\n").map((line, i$1) => {
|
|
438
|
+
const end = start + line.length + 1;
|
|
439
|
+
/** @type {import('./types').Range} */
|
|
440
|
+
const range = {
|
|
441
|
+
start,
|
|
442
|
+
end,
|
|
443
|
+
line: i$1
|
|
444
|
+
};
|
|
445
|
+
start = end;
|
|
446
|
+
return range;
|
|
447
|
+
});
|
|
448
|
+
let i = 0;
|
|
449
|
+
/**
|
|
450
|
+
* @param {string | number} search
|
|
451
|
+
* @param {number} [index]
|
|
452
|
+
* @returns {Location | undefined}
|
|
453
|
+
*/
|
|
454
|
+
function locator(search, index) {
|
|
455
|
+
if (typeof search === "string") search = source.indexOf(search, index ?? 0);
|
|
456
|
+
if (search === -1) return void 0;
|
|
457
|
+
let range = ranges[i];
|
|
458
|
+
const d = search >= range.end ? 1 : -1;
|
|
459
|
+
while (range) {
|
|
460
|
+
if (rangeContains(range, search)) return {
|
|
461
|
+
line: offsetLine + range.line,
|
|
462
|
+
column: offsetColumn + search - range.start,
|
|
463
|
+
character: search
|
|
464
|
+
};
|
|
465
|
+
i += d;
|
|
466
|
+
range = ranges[i];
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return locator;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* @param {string} source
|
|
473
|
+
* @param {string | number} search
|
|
474
|
+
* @param {import('./types').Options} [options]
|
|
475
|
+
* @returns {Location | undefined}
|
|
476
|
+
*/
|
|
477
|
+
function locate(source, search, options) {
|
|
478
|
+
return getLocator(source, options)(search, options && options.startIndex);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/log/logs.ts
|
|
483
|
+
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", PARSE_ERROR = "PARSE_ERROR";
|
|
484
|
+
function logParseError(message) {
|
|
485
|
+
return {
|
|
486
|
+
code: PARSE_ERROR,
|
|
487
|
+
message
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function logInvalidLogPosition(pluginName) {
|
|
491
|
+
return {
|
|
492
|
+
code: INVALID_LOG_POSITION,
|
|
493
|
+
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.`
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function logInputHookInOutputPlugin(pluginName, hookName) {
|
|
497
|
+
return {
|
|
498
|
+
code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
|
|
499
|
+
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.`
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function logCycleLoading(pluginName, moduleId) {
|
|
503
|
+
return {
|
|
504
|
+
code: CYCLE_LOADING,
|
|
505
|
+
message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function logMultiplyNotifyOption() {
|
|
509
|
+
return {
|
|
510
|
+
code: MULTIPLY_NOTIFY_OPTION,
|
|
511
|
+
message: `Found multiply notify option at watch options, using first one to start notify watcher.`
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function logPluginError(error$1, plugin, { hook, id } = {}) {
|
|
515
|
+
try {
|
|
516
|
+
const code = error$1.code;
|
|
517
|
+
if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
|
|
518
|
+
error$1.code = PLUGIN_ERROR;
|
|
519
|
+
error$1.plugin = plugin;
|
|
520
|
+
if (hook) error$1.hook = hook;
|
|
521
|
+
if (id) error$1.id = id;
|
|
522
|
+
} catch (_) {} finally {
|
|
523
|
+
return error$1;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function error(base) {
|
|
527
|
+
if (!(base instanceof Error)) {
|
|
528
|
+
base = Object.assign(new Error(base.message), base);
|
|
529
|
+
Object.defineProperty(base, "name", {
|
|
530
|
+
value: "RollupError",
|
|
531
|
+
writable: true
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
throw base;
|
|
535
|
+
}
|
|
536
|
+
function augmentCodeLocation(properties, pos, source, id) {
|
|
537
|
+
if (typeof pos === "object") {
|
|
538
|
+
const { line, column } = pos;
|
|
539
|
+
properties.loc = {
|
|
540
|
+
column,
|
|
541
|
+
file: id,
|
|
542
|
+
line
|
|
543
|
+
};
|
|
544
|
+
} else {
|
|
545
|
+
properties.pos = pos;
|
|
546
|
+
const location = locate(source, pos, { offsetLine: 1 });
|
|
547
|
+
if (!location) return;
|
|
548
|
+
const { line, column } = location;
|
|
549
|
+
properties.loc = {
|
|
550
|
+
column,
|
|
551
|
+
file: id,
|
|
552
|
+
line
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
if (properties.frame === void 0) {
|
|
556
|
+
const { line, column } = properties.loc;
|
|
557
|
+
properties.frame = getCodeFrame(source, line, column);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region ../../node_modules/.pnpm/oxc-parser@0.72.1/node_modules/oxc-parser/wrap.mjs
|
|
563
|
+
function wrap$1(result) {
|
|
564
|
+
let program, module$1, comments, errors;
|
|
565
|
+
return {
|
|
566
|
+
get program() {
|
|
567
|
+
if (!program) program = jsonParseAst(result.program);
|
|
568
|
+
return program;
|
|
569
|
+
},
|
|
570
|
+
get module() {
|
|
571
|
+
if (!module$1) module$1 = result.module;
|
|
572
|
+
return module$1;
|
|
573
|
+
},
|
|
574
|
+
get comments() {
|
|
575
|
+
if (!comments) comments = result.comments;
|
|
576
|
+
return comments;
|
|
577
|
+
},
|
|
578
|
+
get errors() {
|
|
579
|
+
if (!errors) errors = result.errors;
|
|
580
|
+
return errors;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
function jsonParseAst(programJson) {
|
|
585
|
+
const { node: program, fixes } = JSON.parse(programJson);
|
|
586
|
+
for (const fixPath of fixes) applyFix(program, fixPath);
|
|
587
|
+
return program;
|
|
588
|
+
}
|
|
589
|
+
function applyFix(program, fixPath) {
|
|
590
|
+
let node = program;
|
|
591
|
+
for (const key of fixPath) node = node[key];
|
|
592
|
+
if (node.bigint) node.value = BigInt(node.bigint);
|
|
593
|
+
else try {
|
|
594
|
+
node.value = RegExp(node.regex.pattern, node.regex.flags);
|
|
595
|
+
} catch (_err) {}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/parse-ast-index.ts
|
|
581
600
|
var import_binding = require_chunk.__toESM(require_binding());
|
|
601
|
+
function wrap(result, sourceText) {
|
|
602
|
+
result = wrap$1(result);
|
|
603
|
+
if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
|
|
604
|
+
return result.program;
|
|
605
|
+
}
|
|
606
|
+
function normalizeParseError(sourceText, errors) {
|
|
607
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
608
|
+
for (let i = 0; i < errors.length; i++) {
|
|
609
|
+
if (i >= 5) {
|
|
610
|
+
message += "\n...";
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
const e = errors[i];
|
|
614
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
615
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
616
|
+
if (!location) return;
|
|
617
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
618
|
+
}).filter(Boolean).join("\n");
|
|
619
|
+
}
|
|
620
|
+
return error(logParseError(message));
|
|
621
|
+
}
|
|
622
|
+
const defaultParserOptions = {
|
|
623
|
+
lang: "js",
|
|
624
|
+
preserveParens: false
|
|
625
|
+
};
|
|
626
|
+
function parseAst(sourceText, options, filename) {
|
|
627
|
+
return wrap((0, import_binding.parseSync)(filename ?? "file.js", sourceText, {
|
|
628
|
+
...defaultParserOptions,
|
|
629
|
+
...options
|
|
630
|
+
}), sourceText);
|
|
631
|
+
}
|
|
632
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
633
|
+
return wrap(await (0, import_binding.parseAsync)(filename ?? "file.js", sourceText, {
|
|
634
|
+
...defaultParserOptions,
|
|
635
|
+
...options
|
|
636
|
+
}), sourceText);
|
|
637
|
+
}
|
|
582
638
|
|
|
583
639
|
//#endregion
|
|
584
640
|
Object.defineProperty(exports, 'augmentCodeLocation', {
|
|
@@ -587,36 +643,12 @@ Object.defineProperty(exports, 'augmentCodeLocation', {
|
|
|
587
643
|
return augmentCodeLocation;
|
|
588
644
|
}
|
|
589
645
|
});
|
|
590
|
-
Object.defineProperty(exports, 'colors', {
|
|
591
|
-
enumerable: true,
|
|
592
|
-
get: function () {
|
|
593
|
-
return colors;
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
646
|
Object.defineProperty(exports, 'error', {
|
|
597
647
|
enumerable: true,
|
|
598
648
|
get: function () {
|
|
599
649
|
return error;
|
|
600
650
|
}
|
|
601
651
|
});
|
|
602
|
-
Object.defineProperty(exports, 'getCodeFrame', {
|
|
603
|
-
enumerable: true,
|
|
604
|
-
get: function () {
|
|
605
|
-
return getCodeFrame;
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
Object.defineProperty(exports, 'import_binding', {
|
|
609
|
-
enumerable: true,
|
|
610
|
-
get: function () {
|
|
611
|
-
return import_binding;
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
Object.defineProperty(exports, 'locate', {
|
|
615
|
-
enumerable: true,
|
|
616
|
-
get: function () {
|
|
617
|
-
return locate;
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
652
|
Object.defineProperty(exports, 'logCycleLoading', {
|
|
621
653
|
enumerable: true,
|
|
622
654
|
get: function () {
|
|
@@ -635,27 +667,33 @@ Object.defineProperty(exports, 'logInvalidLogPosition', {
|
|
|
635
667
|
return logInvalidLogPosition;
|
|
636
668
|
}
|
|
637
669
|
});
|
|
638
|
-
Object.defineProperty(exports, '
|
|
670
|
+
Object.defineProperty(exports, 'logMultiplyNotifyOption', {
|
|
639
671
|
enumerable: true,
|
|
640
672
|
get: function () {
|
|
641
|
-
return
|
|
673
|
+
return logMultiplyNotifyOption;
|
|
642
674
|
}
|
|
643
675
|
});
|
|
644
|
-
Object.defineProperty(exports, '
|
|
676
|
+
Object.defineProperty(exports, 'logPluginError', {
|
|
645
677
|
enumerable: true,
|
|
646
678
|
get: function () {
|
|
647
|
-
return
|
|
679
|
+
return logPluginError;
|
|
648
680
|
}
|
|
649
681
|
});
|
|
650
|
-
Object.defineProperty(exports, '
|
|
682
|
+
Object.defineProperty(exports, 'parseAst', {
|
|
651
683
|
enumerable: true,
|
|
652
684
|
get: function () {
|
|
653
|
-
return
|
|
685
|
+
return parseAst;
|
|
654
686
|
}
|
|
655
687
|
});
|
|
656
|
-
Object.defineProperty(exports, '
|
|
688
|
+
Object.defineProperty(exports, 'parseAstAsync', {
|
|
657
689
|
enumerable: true,
|
|
658
690
|
get: function () {
|
|
659
|
-
return
|
|
691
|
+
return parseAstAsync;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
Object.defineProperty(exports, 'require_binding', {
|
|
695
|
+
enumerable: true,
|
|
696
|
+
get: function () {
|
|
697
|
+
return require_binding;
|
|
660
698
|
}
|
|
661
699
|
});
|