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