@rolldown/browser 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.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/dist/cli.mjs +961 -1551
- package/dist/config.d.mts +9 -6
- package/dist/config.mjs +9 -11
- package/dist/constructors-DsfxKD6A.js +68 -0
- package/dist/error-BeZaDkS8.js +157 -0
- package/dist/experimental-index.browser.mjs +278 -44
- package/dist/experimental-index.d.mts +228 -68
- package/dist/experimental-index.mjs +274 -55
- package/dist/experimental-runtime-types.d.ts +98 -0
- package/dist/filter-index.d.mts +104 -2
- package/dist/filter-index.mjs +144 -5
- package/dist/get-log-filter.d.mts +3 -0
- package/dist/get-log-filter.mjs +68 -0
- package/dist/index.browser.mjs +238 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +53 -6
- package/dist/{shared/parse-ast-index-BHaE0ECV.cjs → normalize-string-or-regex-TtAGUp42.js} +74 -147
- package/dist/parallel-plugin-worker.mjs +27 -35
- package/dist/parallel-plugin.d.mts +7 -7
- package/dist/parallel-plugin.mjs +1 -2
- package/dist/parse-ast-index.d.mts +28 -5
- package/dist/parse-ast-index.mjs +60 -4
- package/dist/plugins-index.browser.mjs +40 -0
- package/dist/plugins-index.d.mts +33 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/resolve-tsconfig-DThkUPSZ.js +112 -0
- package/dist/rolldown-binding.wasi-browser.js +46 -24
- package/dist/rolldown-binding.wasi.cjs +67 -24
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/rolldown-build-Chx5S-TB.js +5349 -0
- package/dist/shared/bindingify-input-options-Czbczr8Z.mjs +2168 -0
- package/dist/shared/composable-filters-B2ByPP8y.mjs +224 -0
- package/dist/shared/constructors-BVnf_fH1.d.mts +37 -0
- package/dist/shared/constructors-CemeNi29.mjs +68 -0
- package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
- package/dist/shared/define-config-i6TWE2hm.d.mts +3855 -0
- package/dist/shared/error-CQ6njWsV.mjs +86 -0
- package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
- package/dist/shared/{load-config-D7UduHRZ.mjs → load-config-CxvL5JxT.mjs} +32 -36
- package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
- package/dist/shared/{parse-ast-index-vu376yZ1.mjs → logs-D80CXhvg.mjs} +25 -123
- package/dist/shared/normalize-string-or-regex-CF3Uz6aU.mjs +57 -0
- package/dist/shared/parse-CRhjbrcT.mjs +73 -0
- package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-BYQIwEjg.mjs} +301 -310
- package/dist/shared/resolve-tsconfig-Cwoo4h_o.mjs +112 -0
- package/dist/shared/rolldown-C3wFxOwq.mjs +40 -0
- package/dist/shared/rolldown-build-ChZOz6BP.mjs +3318 -0
- package/dist/shared/transform-DEgNAQOQ.d.mts +149 -0
- package/dist/shared/types-Cx3HYorz.d.mts +1302 -0
- package/dist/shared/utils-6wxe_LMG.d.mts +22 -0
- package/dist/shared/watch-C1jC1oFT.mjs +373 -0
- package/dist/utils-index.browser.mjs +2414 -0
- package/dist/utils-index.d.mts +374 -0
- package/dist/utils-index.mjs +2415 -0
- package/package.json +33 -38
- package/dist/cli.cjs +0 -1748
- package/dist/cli.d.cts +0 -1
- package/dist/config.cjs +0 -12
- package/dist/config.d.cts +0 -11
- package/dist/experimental-index.cjs +0 -129
- package/dist/experimental-index.d.cts +0 -96
- package/dist/filter-index.cjs +0 -53
- package/dist/filter-index.d.cts +0 -3
- package/dist/index.cjs +0 -9
- package/dist/index.d.cts +0 -3
- package/dist/parallel-plugin-worker.cjs +0 -33
- package/dist/parallel-plugin-worker.d.cts +0 -1
- package/dist/parallel-plugin.cjs +0 -8
- package/dist/parallel-plugin.d.cts +0 -14
- package/dist/parse-ast-index.cjs +0 -4
- package/dist/parse-ast-index.d.cts +0 -9
- package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
- package/dist/shared/chunk-DSsiIF1Z.mjs +0 -30
- package/dist/shared/define-config.d-D4lKXE9V.d.cts +0 -1165
- package/dist/shared/define-config.d-Dm9iNdt9.d.mts +0 -1165
- package/dist/shared/dist-BMVjvV-v.cjs +0 -249
- package/dist/shared/dist-CAn6dxW6.mjs +0 -153
- package/dist/shared/load-config-CtKjQ8Mn.cjs +0 -125
- package/dist/shared/prompt-GFYxfPw7.mjs +0 -854
- package/dist/shared/src-D0nc44MQ.mjs +0 -4691
- package/dist/shared/src-s89s870G.cjs +0 -4647
- package/dist/src-CeWghjQt.js +0 -4329
package/dist/filter-index.mjs
CHANGED
|
@@ -1,7 +1,124 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { a as id, c as interpreter, d as not, f as or, g as isPromiseLike, h as arraify, i as exprInterpreter, l as interpreterImpl, m as query, n as code, o as importerId, p as queries, r as exclude, s as include, t as and, u as moduleType } from "./shared/composable-filters-B2ByPP8y.mjs";
|
|
2
|
+
//#region ../pluginutils/dist/filter/filter-vite-plugins.js
|
|
3
|
+
/**
|
|
4
|
+
* Filters out Vite plugins that have `apply: 'serve'` set.
|
|
5
|
+
*
|
|
6
|
+
* Since Rolldown operates in build mode, plugins marked with `apply: 'serve'`
|
|
7
|
+
* are intended only for Vite's dev server and should be excluded from the build process.
|
|
8
|
+
*
|
|
9
|
+
* @param plugins - Array of plugins (can include nested arrays)
|
|
10
|
+
* @returns Filtered array with serve-only plugins removed
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { defineConfig } from 'rolldown';
|
|
15
|
+
* import { filterVitePlugins } from '@rolldown/pluginutils';
|
|
16
|
+
* import viteReact from '@vitejs/plugin-react';
|
|
17
|
+
*
|
|
18
|
+
* export default defineConfig({
|
|
19
|
+
* plugins: filterVitePlugins([
|
|
20
|
+
* viteReact(),
|
|
21
|
+
* {
|
|
22
|
+
* name: 'dev-only',
|
|
23
|
+
* apply: 'serve', // This will be filtered out
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* ])
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function filterVitePlugins(plugins) {
|
|
31
|
+
if (!plugins) return [];
|
|
32
|
+
const pluginArray = Array.isArray(plugins) ? plugins : [plugins];
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const plugin of pluginArray) {
|
|
35
|
+
if (!plugin) continue;
|
|
36
|
+
if (Array.isArray(plugin)) {
|
|
37
|
+
result.push(...filterVitePlugins(plugin));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const pluginWithApply = plugin;
|
|
41
|
+
if ("apply" in pluginWithApply) {
|
|
42
|
+
const applyValue = pluginWithApply.apply;
|
|
43
|
+
if (typeof applyValue === "function") try {
|
|
44
|
+
if (applyValue({}, {
|
|
45
|
+
command: "build",
|
|
46
|
+
mode: "production"
|
|
47
|
+
})) result.push(plugin);
|
|
48
|
+
} catch {
|
|
49
|
+
result.push(plugin);
|
|
50
|
+
}
|
|
51
|
+
else if (applyValue === "serve") continue;
|
|
52
|
+
else result.push(plugin);
|
|
53
|
+
} else result.push(plugin);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region ../pluginutils/dist/filter/simple-filters.js
|
|
59
|
+
/**
|
|
60
|
+
* Constructs a RegExp that matches the exact string specified.
|
|
61
|
+
*
|
|
62
|
+
* This is useful for plugin hook filters.
|
|
63
|
+
*
|
|
64
|
+
* @param str the string to match.
|
|
65
|
+
* @param flags flags for the RegExp.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { exactRegex } from '@rolldown/pluginutils';
|
|
70
|
+
* const plugin = {
|
|
71
|
+
* name: 'plugin',
|
|
72
|
+
* resolveId: {
|
|
73
|
+
* filter: { id: exactRegex('foo') },
|
|
74
|
+
* handler(id) {} // will only be called for `foo`
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function exactRegex(str, flags) {
|
|
80
|
+
return new RegExp(`^${escapeRegex(str)}$`, flags);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Constructs a RegExp that matches a value that has the specified prefix.
|
|
84
|
+
*
|
|
85
|
+
* This is useful for plugin hook filters.
|
|
86
|
+
*
|
|
87
|
+
* @param str the string to match.
|
|
88
|
+
* @param flags flags for the RegExp.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { prefixRegex } from '@rolldown/pluginutils';
|
|
93
|
+
* const plugin = {
|
|
94
|
+
* name: 'plugin',
|
|
95
|
+
* resolveId: {
|
|
96
|
+
* filter: { id: prefixRegex('foo') },
|
|
97
|
+
* handler(id) {} // will only be called for IDs starting with `foo`
|
|
98
|
+
* }
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function prefixRegex(str, flags) {
|
|
103
|
+
return new RegExp(`^${escapeRegex(str)}`, flags);
|
|
104
|
+
}
|
|
105
|
+
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g;
|
|
106
|
+
function escapeRegex(str) {
|
|
107
|
+
return str.replace(escapeRegexRE, "\\$&");
|
|
108
|
+
}
|
|
109
|
+
function makeIdFiltersToMatchWithQuery(input) {
|
|
110
|
+
if (!Array.isArray(input)) return makeIdFilterToMatchWithQuery(input);
|
|
111
|
+
return input.map((i) => makeIdFilterToMatchWithQuery(i));
|
|
112
|
+
}
|
|
113
|
+
function makeIdFilterToMatchWithQuery(input) {
|
|
114
|
+
if (typeof input === "string") return `${input}{?*,}`;
|
|
115
|
+
return makeRegexIdFilterToMatchWithQuery(input);
|
|
116
|
+
}
|
|
117
|
+
function makeRegexIdFilterToMatchWithQuery(input) {
|
|
118
|
+
return new RegExp(input.source.replace(/(?<!\\)\$/g, "(?:\\?.*)?$"), input.flags);
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
3
121
|
//#region src/plugin/with-filter.ts
|
|
4
|
-
init_misc();
|
|
5
122
|
function withFilterImpl(pluginOption, filterObjectList) {
|
|
6
123
|
if (isPromiseLike(pluginOption)) return pluginOption.then((p) => withFilter(p, filterObjectList));
|
|
7
124
|
if (pluginOption == false || pluginOption == null) return pluginOption;
|
|
@@ -27,6 +144,29 @@ function withFilterImpl(pluginOption, filterObjectList) {
|
|
|
27
144
|
});
|
|
28
145
|
return plugin;
|
|
29
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* A helper function to add plugin hook filters to a plugin or an array of plugins.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import yaml from '@rollup/plugin-yaml';
|
|
153
|
+
* import { defineConfig } from 'rolldown';
|
|
154
|
+
* import { withFilter } from 'rolldown/filter';
|
|
155
|
+
*
|
|
156
|
+
* export default defineConfig({
|
|
157
|
+
* plugins: [
|
|
158
|
+
* // Run the transform hook of the `yaml` plugin
|
|
159
|
+
* // only for modules which end in `.yaml`
|
|
160
|
+
* withFilter(
|
|
161
|
+
* yaml({}),
|
|
162
|
+
* { transform: { id: /\.yaml$/ } },
|
|
163
|
+
* ),
|
|
164
|
+
* ],
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @category Config
|
|
169
|
+
*/
|
|
30
170
|
function withFilter(pluginOption, filterObject) {
|
|
31
171
|
return withFilterImpl(pluginOption, arraify(filterObject));
|
|
32
172
|
}
|
|
@@ -39,6 +179,5 @@ function findMatchedFilterObject(pluginName, overrideFilterObjectList) {
|
|
|
39
179
|
}
|
|
40
180
|
return -1;
|
|
41
181
|
}
|
|
42
|
-
|
|
43
182
|
//#endregion
|
|
44
|
-
export { and, code, exclude, id, include, moduleType, not, or, queries, query, withFilter };
|
|
183
|
+
export { and, code, exactRegex, exclude, exprInterpreter, filterVitePlugins, id, importerId, include, interpreter, interpreterImpl, makeIdFiltersToMatchWithQuery, moduleType, not, or, prefixRegex, queries, query, withFilter };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/get-log-filter.ts
|
|
2
|
+
/**
|
|
3
|
+
* A helper function to generate log filters using the same syntax as the CLI.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { defineConfig } from 'rolldown';
|
|
8
|
+
* import { getLogFilter } from 'rolldown/getLogFilter';
|
|
9
|
+
*
|
|
10
|
+
* const logFilter = getLogFilter(['code:FOO', 'code:BAR']);
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* input: 'main.js',
|
|
14
|
+
* onLog(level, log, handler) {
|
|
15
|
+
* if (logFilter(log)) {
|
|
16
|
+
* handler(level, log);
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @category Config
|
|
23
|
+
*/
|
|
24
|
+
const getLogFilter = (filters) => {
|
|
25
|
+
if (filters.length === 0) return () => true;
|
|
26
|
+
const normalizedFilters = filters.map((filter) => filter.split("&").map((subFilter) => {
|
|
27
|
+
const inverted = subFilter.startsWith("!");
|
|
28
|
+
if (inverted) subFilter = subFilter.slice(1);
|
|
29
|
+
const [key, ...value] = subFilter.split(":");
|
|
30
|
+
return {
|
|
31
|
+
inverted,
|
|
32
|
+
key: key.split("."),
|
|
33
|
+
parts: value.join(":").split("*")
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
return (log) => {
|
|
37
|
+
nextIntersectedFilter: for (const intersectedFilters of normalizedFilters) {
|
|
38
|
+
for (const { inverted, key, parts } of intersectedFilters) {
|
|
39
|
+
const isFilterSatisfied = testFilter(log, key, parts);
|
|
40
|
+
if (inverted ? isFilterSatisfied : !isFilterSatisfied) continue nextIntersectedFilter;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const testFilter = (log, key, parts) => {
|
|
48
|
+
let rawValue = log;
|
|
49
|
+
for (let index = 0; index < key.length; index++) {
|
|
50
|
+
if (!rawValue) return false;
|
|
51
|
+
const part = key[index];
|
|
52
|
+
if (!(part in rawValue)) return false;
|
|
53
|
+
rawValue = rawValue[part];
|
|
54
|
+
}
|
|
55
|
+
let value = typeof rawValue === "object" ? JSON.stringify(rawValue) : String(rawValue);
|
|
56
|
+
if (parts.length === 1) return value === parts[0];
|
|
57
|
+
if (!value.startsWith(parts[0])) return false;
|
|
58
|
+
const lastPartIndex = parts.length - 1;
|
|
59
|
+
for (let index = 1; index < lastPartIndex; index++) {
|
|
60
|
+
const part = parts[index];
|
|
61
|
+
const position = value.indexOf(part);
|
|
62
|
+
if (position === -1) return false;
|
|
63
|
+
value = value.slice(position + part.length);
|
|
64
|
+
}
|
|
65
|
+
return value.endsWith(parts[lastPartIndex]);
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { getLogFilter as default };
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1,3 +1,238 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { d as logMultipleWatcherOption } from "./normalize-string-or-regex-TtAGUp42.js";
|
|
2
|
+
import { a as validateOption, c as arraify, l as RUNTIME_MODULE_ID, n as createBundlerOptions, o as PluginDriver, r as RolldownMagicString, s as LOG_LEVEL_WARN, t as RolldownBuild, u as VERSION } from "./rolldown-build-Chx5S-TB.js";
|
|
3
|
+
import { t as aggregateBindingErrorsIntoJsError } from "./error-BeZaDkS8.js";
|
|
4
|
+
import { BindingWatcher, shutdownAsyncRuntime } from "./rolldown-binding.wasi-browser.js";
|
|
5
|
+
//#region src/api/rolldown/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* The API compatible with Rollup's `rollup` function.
|
|
8
|
+
*
|
|
9
|
+
* Unlike Rollup, the module graph is not built until the methods of the bundle object are called.
|
|
10
|
+
*
|
|
11
|
+
* @param input The input options object.
|
|
12
|
+
* @returns A Promise that resolves to a bundle object.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* import { rolldown } from 'rolldown';
|
|
17
|
+
*
|
|
18
|
+
* let bundle, failed = false;
|
|
19
|
+
* try {
|
|
20
|
+
* bundle = await rolldown({
|
|
21
|
+
* input: 'src/main.js',
|
|
22
|
+
* });
|
|
23
|
+
* await bundle.write({
|
|
24
|
+
* format: 'esm',
|
|
25
|
+
* });
|
|
26
|
+
* } catch (e) {
|
|
27
|
+
* console.error(e);
|
|
28
|
+
* failed = true;
|
|
29
|
+
* }
|
|
30
|
+
* if (bundle) {
|
|
31
|
+
* await bundle.close();
|
|
32
|
+
* }
|
|
33
|
+
* process.exitCode = failed ? 1 : 0;
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @category Programmatic APIs
|
|
37
|
+
*/
|
|
38
|
+
const rolldown = async (input) => {
|
|
39
|
+
validateOption("input", input);
|
|
40
|
+
return new RolldownBuild(await PluginDriver.callOptionsHook(input));
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/api/build.ts
|
|
44
|
+
/**
|
|
45
|
+
* The API similar to esbuild's `build` function.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* import { build } from 'rolldown';
|
|
50
|
+
*
|
|
51
|
+
* const result = await build({
|
|
52
|
+
* input: 'src/main.js',
|
|
53
|
+
* output: {
|
|
54
|
+
* file: 'bundle.js',
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* console.log(result);
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @experimental
|
|
61
|
+
* @category Programmatic APIs
|
|
62
|
+
*/
|
|
63
|
+
async function build(options) {
|
|
64
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
65
|
+
else {
|
|
66
|
+
const { output, write = true, ...inputOptions } = options;
|
|
67
|
+
const build = await rolldown(inputOptions);
|
|
68
|
+
try {
|
|
69
|
+
if (write) return await build.write(output);
|
|
70
|
+
else return await build.generate(output);
|
|
71
|
+
} finally {
|
|
72
|
+
await build.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/api/watch/watch-emitter.ts
|
|
78
|
+
var WatcherEmitter = class {
|
|
79
|
+
listeners = /* @__PURE__ */ new Map();
|
|
80
|
+
on(event, listener) {
|
|
81
|
+
const listeners = this.listeners.get(event);
|
|
82
|
+
if (listeners) listeners.push(listener);
|
|
83
|
+
else this.listeners.set(event, [listener]);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
off(event, listener) {
|
|
87
|
+
const listeners = this.listeners.get(event);
|
|
88
|
+
if (listeners) {
|
|
89
|
+
const index = listeners.indexOf(listener);
|
|
90
|
+
if (index !== -1) listeners.splice(index, 1);
|
|
91
|
+
}
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
clear(event) {
|
|
95
|
+
this.listeners.delete(event);
|
|
96
|
+
}
|
|
97
|
+
/** Async emit — sequential dispatch so side effects from earlier handlers
|
|
98
|
+
* (e.g. `event.result.close()` triggering `closeBundle`) are visible to later handlers. */
|
|
99
|
+
async emit(event, ...args) {
|
|
100
|
+
const handlers = this.listeners.get(event);
|
|
101
|
+
if (handlers?.length) for (const h of handlers) await h(...args);
|
|
102
|
+
}
|
|
103
|
+
async close() {}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/api/watch/watcher.ts
|
|
107
|
+
function createEventCallback(emitter) {
|
|
108
|
+
return async (event) => {
|
|
109
|
+
switch (event.eventKind()) {
|
|
110
|
+
case "event": {
|
|
111
|
+
const code = event.bundleEventKind();
|
|
112
|
+
if (code === "BUNDLE_END") {
|
|
113
|
+
const { duration, output, result } = event.bundleEndData();
|
|
114
|
+
await emitter.emit("event", {
|
|
115
|
+
code: "BUNDLE_END",
|
|
116
|
+
duration,
|
|
117
|
+
output: [output],
|
|
118
|
+
result
|
|
119
|
+
});
|
|
120
|
+
} else if (code === "ERROR") {
|
|
121
|
+
const data = event.bundleErrorData();
|
|
122
|
+
await emitter.emit("event", {
|
|
123
|
+
code: "ERROR",
|
|
124
|
+
error: aggregateBindingErrorsIntoJsError(data.error),
|
|
125
|
+
result: data.result
|
|
126
|
+
});
|
|
127
|
+
} else await emitter.emit("event", { code });
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "change": {
|
|
131
|
+
const { path, kind } = event.watchChangeData();
|
|
132
|
+
await emitter.emit("change", path, { event: kind });
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case "restart":
|
|
136
|
+
await emitter.emit("restart");
|
|
137
|
+
break;
|
|
138
|
+
case "close":
|
|
139
|
+
await emitter.emit("close");
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
var Watcher = class {
|
|
145
|
+
closed;
|
|
146
|
+
inner;
|
|
147
|
+
emitter;
|
|
148
|
+
stopWorkers;
|
|
149
|
+
constructor(emitter, inner, stopWorkers) {
|
|
150
|
+
this.closed = false;
|
|
151
|
+
this.inner = inner;
|
|
152
|
+
this.emitter = emitter;
|
|
153
|
+
const originClose = emitter.close.bind(emitter);
|
|
154
|
+
emitter.close = async () => {
|
|
155
|
+
await this.close();
|
|
156
|
+
originClose();
|
|
157
|
+
};
|
|
158
|
+
this.stopWorkers = stopWorkers;
|
|
159
|
+
process.nextTick(() => this.run());
|
|
160
|
+
}
|
|
161
|
+
async close() {
|
|
162
|
+
if (this.closed) return;
|
|
163
|
+
this.closed = true;
|
|
164
|
+
for (const stop of this.stopWorkers) await stop?.();
|
|
165
|
+
await this.inner.close();
|
|
166
|
+
shutdownAsyncRuntime();
|
|
167
|
+
}
|
|
168
|
+
async run() {
|
|
169
|
+
await this.inner.run();
|
|
170
|
+
this.inner.waitForClose();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
async function createWatcher(emitter, input) {
|
|
174
|
+
const options = arraify(input);
|
|
175
|
+
const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
|
|
176
|
+
return createBundlerOptions(await PluginDriver.callOptionsHook(option, true), output, true);
|
|
177
|
+
})).flat());
|
|
178
|
+
warnMultiplePollingOptions(bundlerOptions);
|
|
179
|
+
const callback = createEventCallback(emitter);
|
|
180
|
+
new Watcher(emitter, new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), callback), bundlerOptions.map((option) => option.stopWorkers));
|
|
181
|
+
}
|
|
182
|
+
function warnMultiplePollingOptions(bundlerOptions) {
|
|
183
|
+
let found = false;
|
|
184
|
+
for (const option of bundlerOptions) {
|
|
185
|
+
const watch = option.inputOptions.watch;
|
|
186
|
+
const watcher = watch && typeof watch === "object" ? watch.watcher ?? watch.notify : void 0;
|
|
187
|
+
if (watcher && (watcher.usePolling != null || watcher.pollInterval != null)) {
|
|
188
|
+
if (found) {
|
|
189
|
+
option.onLog(LOG_LEVEL_WARN, logMultipleWatcherOption());
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
found = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/api/watch/index.ts
|
|
198
|
+
/**
|
|
199
|
+
* The API compatible with Rollup's `watch` function.
|
|
200
|
+
*
|
|
201
|
+
* This function will rebuild the bundle when it detects that the individual modules have changed on disk.
|
|
202
|
+
*
|
|
203
|
+
* Note that when using this function, it is your responsibility to call `event.result.close()` in response to the `BUNDLE_END` event to avoid resource leaks.
|
|
204
|
+
*
|
|
205
|
+
* @param input The watch options object or the list of them.
|
|
206
|
+
* @returns A watcher object.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```js
|
|
210
|
+
* import { watch } from 'rolldown';
|
|
211
|
+
*
|
|
212
|
+
* const watcher = watch({ /* ... *\/ });
|
|
213
|
+
* watcher.on('event', (event) => {
|
|
214
|
+
* if (event.code === 'BUNDLE_END') {
|
|
215
|
+
* console.log(event.duration);
|
|
216
|
+
* event.result.close();
|
|
217
|
+
* }
|
|
218
|
+
* });
|
|
219
|
+
*
|
|
220
|
+
* // Stop watching
|
|
221
|
+
* watcher.close();
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @experimental
|
|
225
|
+
* @category Programmatic APIs
|
|
226
|
+
*/
|
|
227
|
+
function watch(input) {
|
|
228
|
+
const emitter = new WatcherEmitter();
|
|
229
|
+
createWatcher(emitter, input);
|
|
230
|
+
return emitter;
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/utils/define-config.ts
|
|
234
|
+
function defineConfig(config) {
|
|
235
|
+
return config;
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
export { RUNTIME_MODULE_ID, RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { a as RolldownLog, i as RolldownError, n as LogLevelOption, o as RolldownLogWithString, r as LogOrStringHandler, t as LogLevel } from "./shared/logging-C6h4g8dA.mjs";
|
|
2
|
+
import { $ as VERSION, $t as MinifyOptions, A as SourceDescription, At as WarningHandlerWithDefault, Bt as build, C as PartialResolvedId, Ct as RolldownFsModule, D as ResolvedId, Dt as TransformOptions, E as ResolveIdResult, Et as NormalizedInputOptions, Ft as RolldownWatcherWatcherEventMap, Gt as ChunkingContext, Ht as AdvancedChunksGroup, It as WatchOptions, Jt as CodeSplittingOptions, Kt as CodeSplittingGroup, Lt as rolldown, Mt as watch, Nt as RolldownWatcher, O as RolldownPlugin, Ot as ChecksOptions, Pt as RolldownWatcherEvent, Q as RUNTIME_MODULE_ID, Qt as GlobalsFunction, Rt as RolldownBuild, S as ParallelPluginHooks, St as RolldownFileStats, T as ResolveIdExtraOptions, Tt as NormalizedOutputOptions, Ut as AdvancedChunksOptions, Vt as AddonFunction, Wt as ChunkFileNamesFunction, Xt as GeneratedCodeOptions, Yt as CommentsOptions, Z as PreRenderedChunk, Zt as GeneratedCodePreset, _ as ImportKind, _t as GeneralHookFilter, a as ExternalOption, an as RenderedChunk, at as TransformPluginContext, b as ModuleType, bt as BufferEncoding, c as InputOptions, cn as SourceMap, ct as EmittedFile, d as WatcherFileWatcherOptions, dn as SourcemapIgnoreListOption, dt as PluginContext, en as ModuleFormat, et as BundleError, f as WatcherOptions, ft as PluginContextResolveOptions, g as HookFilterExtension, gt as PluginContextMeta, h as FunctionPluginHooks, ht as MinimalPluginContext, i as RolldownOptions, in as OutputChunk, it as TreeshakingOptions, j as TransformResult, jt as RolldownMagicString, k as RolldownPluginOption, kt as LoggingFunction, l as ModuleTypes, lt as EmittedPrebuiltChunk, m as CustomPluginOptions, n as RolldownOptionsFunction, nn as PreRenderedAsset, nt as SourceMapInput, o as ExternalOptionFunction, on as RenderedModule, ot as EmittedAsset, p as AsyncPluginHooks, pt as DefineParallelPluginResult, qt as CodeSplittingNameFunction, r as defineConfig, rn as OutputAsset, rt as OutputBundle, s as InputOption, sn as RolldownOutput, st as EmittedChunk, t as ConfigExport, tn as OutputOptions, tt as ExistingRawSourceMap, u as OptimizationOptions, un as ModuleInfo, ut as GetModuleInfo, v as LoadResult, vt as HookFilter, w as Plugin, wt as InternalModuleFormat, x as ObjectHook, xt as RolldownDirectoryEntry, y as ModuleOptions, yt as ModuleTypeFilter, zt as BuildOptions } from "./shared/define-config-i6TWE2hm.mjs";
|
|
3
|
+
import { o as PartialNull } from "./shared/utils-6wxe_LMG.mjs";
|
|
4
|
+
export { AddonFunction, AdvancedChunksGroup, AdvancedChunksOptions, AsyncPluginHooks, BufferEncoding, BuildOptions, BundleError, ChecksOptions, ChunkFileNamesFunction, ChunkingContext, CodeSplittingGroup, CodeSplittingNameFunction, CodeSplittingOptions, CommentsOptions, ConfigExport, CustomPluginOptions, DefineParallelPluginResult, EmittedAsset, EmittedChunk, EmittedFile, EmittedPrebuiltChunk, ExistingRawSourceMap, ExternalOption, ExternalOptionFunction, FunctionPluginHooks, GeneralHookFilter, GeneratedCodeOptions, GeneratedCodePreset, GetModuleInfo, GlobalsFunction, HookFilter, HookFilterExtension, ImportKind, InputOption, InputOptions, InternalModuleFormat, LoadResult, LogLevel, LogLevelOption, LogOrStringHandler, LoggingFunction, MinifyOptions, MinimalPluginContext, ModuleFormat, ModuleInfo, ModuleOptions, ModuleType, ModuleTypeFilter, ModuleTypes, NormalizedInputOptions, NormalizedOutputOptions, ObjectHook, OptimizationOptions, OutputAsset, OutputBundle, OutputChunk, OutputOptions, ParallelPluginHooks, PartialNull, PartialResolvedId, Plugin, PluginContext, PluginContextMeta, PluginContextResolveOptions, PreRenderedAsset, PreRenderedChunk, RUNTIME_MODULE_ID, RenderedChunk, RenderedModule, ResolveIdExtraOptions, ResolveIdResult, ResolvedId, RolldownBuild, RolldownDirectoryEntry, RolldownError, RolldownError as RollupError, RolldownFileStats, RolldownFsModule, RolldownLog, RolldownLog as RollupLog, RolldownLogWithString, RolldownLogWithString as RollupLogWithString, RolldownMagicString, RolldownOptions, RolldownOptionsFunction, RolldownOutput, RolldownPlugin, RolldownPluginOption, RolldownWatcher, RolldownWatcherEvent, RolldownWatcherWatcherEventMap, SourceDescription, SourceMap, SourceMapInput, SourcemapIgnoreListOption, TransformOptions, TransformPluginContext, TransformResult, TreeshakingOptions, VERSION, WarningHandlerWithDefault, WatchOptions, WatcherFileWatcherOptions, WatcherOptions, build, defineConfig, rolldown, watch };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./shared/
|
|
3
|
-
import "./shared/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { n as onExit, t as watch } from "./shared/watch-C1jC1oFT.mjs";
|
|
2
|
+
import "./shared/normalize-string-or-regex-CF3Uz6aU.mjs";
|
|
3
|
+
import { a as RolldownMagicString, b as RUNTIME_MODULE_ID, x as VERSION } from "./shared/bindingify-input-options-Czbczr8Z.mjs";
|
|
4
|
+
import "./shared/rolldown-build-ChZOz6BP.mjs";
|
|
5
|
+
import "./shared/error-CQ6njWsV.mjs";
|
|
6
|
+
import "./shared/parse-CRhjbrcT.mjs";
|
|
7
|
+
import { t as rolldown } from "./shared/rolldown-C3wFxOwq.mjs";
|
|
8
|
+
import { t as defineConfig } from "./shared/define-config-DJOr6Iwt.mjs";
|
|
9
|
+
import { isMainThread } from "node:worker_threads";
|
|
10
|
+
import { initTraceSubscriber } from "./rolldown-binding.wasi.cjs";
|
|
11
|
+
//#region src/setup.ts
|
|
12
|
+
if (isMainThread) {
|
|
13
|
+
const subscriberGuard = initTraceSubscriber();
|
|
14
|
+
onExit(() => {
|
|
15
|
+
subscriberGuard?.close();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/api/build.ts
|
|
20
|
+
/**
|
|
21
|
+
* The API similar to esbuild's `build` function.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* import { build } from 'rolldown';
|
|
26
|
+
*
|
|
27
|
+
* const result = await build({
|
|
28
|
+
* input: 'src/main.js',
|
|
29
|
+
* output: {
|
|
30
|
+
* file: 'bundle.js',
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* console.log(result);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @experimental
|
|
37
|
+
* @category Programmatic APIs
|
|
38
|
+
*/
|
|
39
|
+
async function build(options) {
|
|
40
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
41
|
+
else {
|
|
42
|
+
const { output, write = true, ...inputOptions } = options;
|
|
43
|
+
const build = await rolldown(inputOptions);
|
|
44
|
+
try {
|
|
45
|
+
if (write) return await build.write(output);
|
|
46
|
+
else return await build.generate(output);
|
|
47
|
+
} finally {
|
|
48
|
+
await build.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { RUNTIME_MODULE_ID, RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };
|