@ohos-ports/rolldown 1.2.6-beta.0

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.
Files changed (54) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +11 -0
  3. package/THIRD-PARTY-LICENSE +33 -0
  4. package/bin/cli.mjs +11 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.mjs +1208 -0
  7. package/dist/config.d.mts +26 -0
  8. package/dist/config.mjs +4 -0
  9. package/dist/experimental-default-runtime.mjs +116 -0
  10. package/dist/experimental-index.d.mts +324 -0
  11. package/dist/experimental-index.mjs +383 -0
  12. package/dist/experimental-runtime-base.mjs +95 -0
  13. package/dist/experimental-runtime-types.d.ts +177 -0
  14. package/dist/experimental-runtime.d.ts +177 -0
  15. package/dist/experimental-runtime.mjs +257 -0
  16. package/dist/filter-index.d.mts +196 -0
  17. package/dist/filter-index.mjs +376 -0
  18. package/dist/get-log-filter.d.mts +3 -0
  19. package/dist/get-log-filter.mjs +68 -0
  20. package/dist/index.d.mts +4 -0
  21. package/dist/index.mjs +56 -0
  22. package/dist/parallel-plugin-worker.d.mts +1 -0
  23. package/dist/parallel-plugin-worker.mjs +29 -0
  24. package/dist/parallel-plugin.d.mts +12 -0
  25. package/dist/parallel-plugin.mjs +6 -0
  26. package/dist/parse-ast-index.d.mts +30 -0
  27. package/dist/parse-ast-index.mjs +60 -0
  28. package/dist/plugins-index.d.mts +32 -0
  29. package/dist/plugins-index.mjs +40 -0
  30. package/dist/shared/binding-CtPG-2KR.mjs +675 -0
  31. package/dist/shared/binding-Og__jmUi.d.mts +2065 -0
  32. package/dist/shared/bindingify-input-options-4JJxbZl2.mjs +2416 -0
  33. package/dist/shared/constructors-Qrp2Xr6w.d.mts +35 -0
  34. package/dist/shared/constructors-ltBDfHX1.mjs +69 -0
  35. package/dist/shared/create-bundler-option-DSPiA5F7.mjs +3220 -0
  36. package/dist/shared/define-config-Demdg3_4.mjs +6 -0
  37. package/dist/shared/define-config-Nbz-lniw.d.mts +4101 -0
  38. package/dist/shared/dist-DKbukT1H.mjs +154 -0
  39. package/dist/shared/error-HDibX49O.mjs +85 -0
  40. package/dist/shared/get-log-filter-AjBknEEO.d.mts +34 -0
  41. package/dist/shared/load-config-BMUrE9HH.mjs +137 -0
  42. package/dist/shared/logging-xuHO4mAy.d.mts +50 -0
  43. package/dist/shared/logs-DmYCAKcW.mjs +192 -0
  44. package/dist/shared/misc-DOSKtd97.mjs +29 -0
  45. package/dist/shared/normalize-string-or-regex-DWz4it3p.mjs +68 -0
  46. package/dist/shared/parse-D0g29RgN.mjs +74 -0
  47. package/dist/shared/prompt-CH6TK0bC.mjs +885 -0
  48. package/dist/shared/resolve-tsconfig-CLYpUIZC.mjs +128 -0
  49. package/dist/shared/rolldown-C9Hfg50O.mjs +179 -0
  50. package/dist/shared/transform-DR4CXeQm.d.mts +152 -0
  51. package/dist/shared/watch-UbzgabQn.mjs +377 -0
  52. package/dist/utils-index.d.mts +375 -0
  53. package/dist/utils-index.mjs +2416 -0
  54. package/package.json +159 -0
@@ -0,0 +1,128 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-CtPG-2KR.mjs";
2
+ import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-HDibX49O.mjs";
3
+ //#region src/utils/minify.ts
4
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
5
+ /**
6
+ * Minify asynchronously.
7
+ *
8
+ * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
9
+ *
10
+ * @category Utilities
11
+ * @experimental
12
+ */
13
+ async function minify(filename, sourceText, options) {
14
+ const inputMap = bindingifySourcemap(options?.inputMap);
15
+ const result = await (0, import_binding.minify)(filename, sourceText, options);
16
+ if (result.map && inputMap) result.map = {
17
+ version: 3,
18
+ ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
19
+ };
20
+ return result;
21
+ }
22
+ /**
23
+ * Minify synchronously.
24
+ *
25
+ * @category Utilities
26
+ * @experimental
27
+ */
28
+ function minifySync(filename, sourceText, options) {
29
+ const inputMap = bindingifySourcemap(options?.inputMap);
30
+ const result = (0, import_binding.minifySync)(filename, sourceText, options);
31
+ if (result.map && inputMap) result.map = {
32
+ version: 3,
33
+ ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
34
+ };
35
+ return result;
36
+ }
37
+ //#endregion
38
+ //#region src/utils/transform.ts
39
+ const yarnPnp$1 = typeof process === "object" && !!process.versions?.pnp;
40
+ function normalizeBindingWarning(warning) {
41
+ if (warning.type === "JsError") return warning.field0;
42
+ return {
43
+ code: warning.field0.kind,
44
+ message: warning.field0.message,
45
+ id: warning.field0.id,
46
+ exporter: warning.field0.exporter,
47
+ loc: warning.field0.loc,
48
+ pos: warning.field0.pos
49
+ };
50
+ }
51
+ /**
52
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
53
+ *
54
+ * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
55
+ *
56
+ * @param filename The name of the file being transformed. If this is a
57
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
58
+ * @param sourceText The source code to transform.
59
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
60
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
61
+ * Used when `options.tsconfig` is `true` or a path. For a path, construct the
62
+ * cache with the same path.
63
+ *
64
+ * @returns a promise that resolves to an object containing the transformed code,
65
+ * source maps, and any errors that occurred during parsing or transformation.
66
+ *
67
+ * @category Utilities
68
+ * @experimental
69
+ */
70
+ async function transform(filename, sourceText, options, cache) {
71
+ const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache, yarnPnp$1);
72
+ return {
73
+ ...result,
74
+ errors: result.errors.map(normalizeBindingError),
75
+ warnings: result.warnings.map(normalizeBindingWarning)
76
+ };
77
+ }
78
+ /**
79
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
80
+ *
81
+ * @param filename The name of the file being transformed. If this is a
82
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
83
+ * @param sourceText The source code to transform.
84
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
85
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
86
+ * Used when `options.tsconfig` is `true` or a path. For a path, construct the
87
+ * cache with the same path.
88
+ *
89
+ * @returns an object containing the transformed code, source maps, and any errors
90
+ * that occurred during parsing or transformation.
91
+ *
92
+ * @category Utilities
93
+ * @experimental
94
+ */
95
+ function transformSync(filename, sourceText, options, cache) {
96
+ const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache, yarnPnp$1);
97
+ return {
98
+ ...result,
99
+ errors: result.errors.map(normalizeBindingError),
100
+ warnings: result.warnings.map(normalizeBindingWarning)
101
+ };
102
+ }
103
+ //#endregion
104
+ //#region src/utils/resolve-tsconfig.ts
105
+ const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
106
+ /**
107
+ * Cache for tsconfig resolution to avoid redundant file system operations.
108
+ *
109
+ * The cache stores resolved tsconfig configurations keyed by their file paths.
110
+ * When transforming multiple files in the same project, tsconfig lookups are
111
+ * deduplicated, improving performance.
112
+ * Pass a tsconfig path to use that configuration for every lookup. When the
113
+ * path is omitted, the nearest tsconfig is discovered automatically.
114
+ *
115
+ * @category Utilities
116
+ * @experimental
117
+ */
118
+ var TsconfigCache = class extends import_binding.TsconfigCache {
119
+ constructor(pathToTsconfig) {
120
+ super(yarnPnp, pathToTsconfig);
121
+ }
122
+ };
123
+ /** @hidden This is only expected to be used by Vite */
124
+ function resolveTsconfig(filename, cache) {
125
+ return (0, import_binding.resolveTsconfig)(filename, cache, yarnPnp);
126
+ }
127
+ //#endregion
128
+ export { minify as a, transformSync as i, resolveTsconfig as n, minifySync as o, transform as r, TsconfigCache as t };
@@ -0,0 +1,179 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-CtPG-2KR.mjs";
2
+ import { f as __decorate, h as PlainObjectLike, m as lazyProp, u as transformToRollupOutput } from "./bindingify-input-options-4JJxbZl2.mjs";
3
+ import { l as PluginDriver, s as validateOption, t as createBundlerOptions } from "./create-bundler-option-DSPiA5F7.mjs";
4
+ import { i as unwrapBindingResult } from "./error-HDibX49O.mjs";
5
+ //#region src/types/rolldown-output-impl.ts
6
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
7
+ var RolldownOutputImpl = class extends PlainObjectLike {
8
+ bindingOutputs;
9
+ constructor(bindingOutputs) {
10
+ super();
11
+ this.bindingOutputs = bindingOutputs;
12
+ if (bindingOutputs.mangleCache !== void 0) this.mangleCache = bindingOutputs.mangleCache;
13
+ }
14
+ get output() {
15
+ return transformToRollupOutput(this.bindingOutputs).output;
16
+ }
17
+ __rolldown_external_memory_handle__(keepDataAlive) {
18
+ const results = this.output.map((item) => item.__rolldown_external_memory_handle__(keepDataAlive));
19
+ if (!results.every((r) => r.freed)) {
20
+ const reasons = results.filter((r) => !r.freed).map((r) => r.reason).filter(Boolean);
21
+ return {
22
+ freed: false,
23
+ reason: `Failed to free ${reasons.length} item(s): ${reasons.join("; ")}`
24
+ };
25
+ }
26
+ return { freed: true };
27
+ }
28
+ };
29
+ __decorate([lazyProp], RolldownOutputImpl.prototype, "output", null);
30
+ //#endregion
31
+ //#region src/api/rolldown/rolldown-build.ts
32
+ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
33
+ /**
34
+ * The bundle object returned by {@linkcode rolldown} function.
35
+ *
36
+ * @category Programmatic APIs
37
+ */
38
+ var RolldownBuild = class {
39
+ #inputOptions;
40
+ #bundler;
41
+ #stopWorkers;
42
+ #asyncRuntimeReleased = false;
43
+ /** @hidden should not be used directly */
44
+ constructor(inputOptions) {
45
+ this.#inputOptions = inputOptions;
46
+ this.#bundler = new import_binding.BindingBundler();
47
+ (0, import_binding.startAsyncRuntime)();
48
+ }
49
+ /**
50
+ * Whether the bundle has been closed.
51
+ *
52
+ * If the bundle is closed, calling other methods will throw an error.
53
+ */
54
+ get closed() {
55
+ return this.#bundler.closed;
56
+ }
57
+ /**
58
+ * Generate bundles in-memory.
59
+ *
60
+ * If you directly want to write bundles to disk, use the {@linkcode write} method instead.
61
+ *
62
+ * @param outputOptions The output options.
63
+ * @returns The generated bundle.
64
+ * @throws {@linkcode BundleError} When an error occurs during the build.
65
+ */
66
+ async generate(outputOptions = {}) {
67
+ return this.#build(false, outputOptions);
68
+ }
69
+ /**
70
+ * Generate and write bundles to disk.
71
+ *
72
+ * If you want to generate bundles in-memory, use the {@linkcode generate} method instead.
73
+ *
74
+ * @param outputOptions The output options.
75
+ * @returns The generated bundle.
76
+ * @throws {@linkcode BundleError} When an error occurs during the build.
77
+ */
78
+ async write(outputOptions = {}) {
79
+ return this.#build(true, outputOptions);
80
+ }
81
+ /**
82
+ * Close the bundle and free resources.
83
+ *
84
+ * This method should be called even if the {@linkcode generate} method
85
+ * or the {@linkcode write} method threw an error. It should be called
86
+ * even if neither of the methods are called.
87
+ *
88
+ * This method is called automatically when using `using` syntax.
89
+ *
90
+ * @example
91
+ * ```js
92
+ * import { rolldown } from 'rolldown';
93
+ *
94
+ * {
95
+ * using bundle = await rolldown({ input: 'src/main.js' });
96
+ * const output = await bundle.generate({ format: 'esm' });
97
+ * console.log(output);
98
+ * // bundle.close() is called automatically here
99
+ * }
100
+ * ```
101
+ */
102
+ async close() {
103
+ const shouldRelease = !this.#asyncRuntimeReleased;
104
+ this.#asyncRuntimeReleased = true;
105
+ try {
106
+ await this.#stopWorkers?.();
107
+ await this.#bundler.close();
108
+ this.#stopWorkers = void 0;
109
+ } finally {
110
+ if (shouldRelease) (0, import_binding.shutdownAsyncRuntime)();
111
+ }
112
+ }
113
+ /** @hidden documented in close method */
114
+ async [Symbol.asyncDispose]() {
115
+ await this.close();
116
+ }
117
+ /**
118
+ * @experimental
119
+ * @hidden not ready for public usage yet
120
+ */
121
+ get watchFiles() {
122
+ return Promise.resolve(this.#bundler.getWatchFiles());
123
+ }
124
+ async #build(isWrite, outputOptions) {
125
+ validateOption("output", outputOptions);
126
+ await this.#stopWorkers?.();
127
+ const option = await createBundlerOptions(this.#inputOptions, outputOptions, false, true);
128
+ try {
129
+ this.#stopWorkers = option.stopWorkers;
130
+ let output;
131
+ if (isWrite) output = await this.#bundler.write(option.bundlerOptions);
132
+ else output = await this.#bundler.generate(option.bundlerOptions);
133
+ return new RolldownOutputImpl(unwrapBindingResult(output));
134
+ } catch (e) {
135
+ await option.stopWorkers?.();
136
+ throw e;
137
+ }
138
+ }
139
+ };
140
+ //#endregion
141
+ //#region src/api/rolldown/index.ts
142
+ /**
143
+ * The API compatible with Rollup's `rollup` function.
144
+ *
145
+ * Unlike Rollup, the module graph is not built until the methods of the bundle object are called.
146
+ *
147
+ * @param input The input options object.
148
+ * @returns A Promise that resolves to a bundle object.
149
+ *
150
+ * @example
151
+ * ```js
152
+ * import { rolldown } from 'rolldown';
153
+ *
154
+ * let bundle, failed = false;
155
+ * try {
156
+ * bundle = await rolldown({
157
+ * input: 'src/main.js',
158
+ * });
159
+ * await bundle.write({
160
+ * format: 'esm',
161
+ * });
162
+ * } catch (e) {
163
+ * console.error(e);
164
+ * failed = true;
165
+ * }
166
+ * if (bundle) {
167
+ * await bundle.close();
168
+ * }
169
+ * process.exitCode = failed ? 1 : 0;
170
+ * ```
171
+ *
172
+ * @category Programmatic APIs
173
+ */
174
+ const rolldown = async (input) => {
175
+ validateOption("input", input);
176
+ return new RolldownBuild(await PluginDriver.callOptionsHook(input));
177
+ };
178
+ //#endregion
179
+ export { rolldown as t };
@@ -0,0 +1,152 @@
1
+ import { a as RolldownLog } from "./logging-xuHO4mAy.mjs";
2
+ import { H as ParserOptions$1, J as TsconfigCache$1, K as SourceMap, R as MinifyOptions$1, V as ParseResult$1, a as BindingEnhancedTransformOptions, o as BindingEnhancedTransformResult, x as BindingTsconfigResult, z as MinifyResult$1 } from "./binding-Og__jmUi.mjs";
3
+ //#region src/utils/resolve-tsconfig.d.ts
4
+ /**
5
+ * Cache for tsconfig resolution to avoid redundant file system operations.
6
+ *
7
+ * The cache stores resolved tsconfig configurations keyed by their file paths.
8
+ * When transforming multiple files in the same project, tsconfig lookups are
9
+ * deduplicated, improving performance.
10
+ * Pass a tsconfig path to use that configuration for every lookup. When the
11
+ * path is omitted, the nearest tsconfig is discovered automatically.
12
+ *
13
+ * @category Utilities
14
+ * @experimental
15
+ */
16
+ declare class TsconfigCache extends TsconfigCache$1 {
17
+ constructor(pathToTsconfig?: string);
18
+ }
19
+ /** @hidden This is only expected to be used by Vite */
20
+ declare function resolveTsconfig(filename: string, cache?: TsconfigCache | null): BindingTsconfigResult | null;
21
+ //#endregion
22
+ //#region src/utils/parse.d.ts
23
+ /**
24
+ * Result of parsing a code
25
+ *
26
+ * @category Utilities
27
+ */
28
+ interface ParseResult extends ParseResult$1 {}
29
+ /**
30
+ * Options for parsing a code
31
+ *
32
+ * @category Utilities
33
+ */
34
+ interface ParserOptions extends ParserOptions$1 {}
35
+ /**
36
+ * Parse JS/TS source asynchronously on a separate thread.
37
+ *
38
+ * Note that not all of the workload can happen on a separate thread.
39
+ * Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
40
+ * has to happen on current thread. This synchronous deserialization work typically outweighs
41
+ * the asynchronous parsing by a factor of between 3 and 20.
42
+ *
43
+ * i.e. the majority of the workload cannot be parallelized by using this method.
44
+ *
45
+ * Generally {@linkcode parseSync} is preferable to use as it does not have the overhead of spawning a thread.
46
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads.
47
+ *
48
+ * @category Utilities
49
+ */
50
+ declare function parse(filename: string, sourceText: string, options?: ParserOptions | null): Promise<ParseResult>;
51
+ /**
52
+ * Parse JS/TS source synchronously on current thread.
53
+ *
54
+ * This is generally preferable over {@linkcode parse} (async) as it does not have the overhead
55
+ * of spawning a thread, and the majority of the workload cannot be parallelized anyway
56
+ * (see {@linkcode parse} documentation for details).
57
+ *
58
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads
59
+ * with {@linkcode parseSync} rather than using {@linkcode parse}.
60
+ *
61
+ * @category Utilities
62
+ */
63
+ declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | null): ParseResult;
64
+ //#endregion
65
+ //#region src/utils/minify.d.ts
66
+ /**
67
+ * Options for minification.
68
+ *
69
+ * @category Utilities
70
+ */
71
+ interface MinifyOptions extends MinifyOptions$1 {
72
+ inputMap?: SourceMap;
73
+ }
74
+ /**
75
+ * The result of minification.
76
+ *
77
+ * @category Utilities
78
+ */
79
+ interface MinifyResult extends MinifyResult$1 {}
80
+ /**
81
+ * Minify asynchronously.
82
+ *
83
+ * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
84
+ *
85
+ * @category Utilities
86
+ * @experimental
87
+ */
88
+ declare function minify(filename: string, sourceText: string, options?: MinifyOptions | null): Promise<MinifyResult>;
89
+ /**
90
+ * Minify synchronously.
91
+ *
92
+ * @category Utilities
93
+ * @experimental
94
+ */
95
+ declare function minifySync(filename: string, sourceText: string, options?: MinifyOptions | null): MinifyResult;
96
+ //#endregion
97
+ //#region src/utils/transform.d.ts
98
+ /**
99
+ * Options for transforming a code.
100
+ *
101
+ * @category Utilities
102
+ */
103
+ interface TransformOptions extends BindingEnhancedTransformOptions {}
104
+ /**
105
+ * Result of transforming a code.
106
+ *
107
+ * @category Utilities
108
+ */
109
+ type TransformResult = Omit<BindingEnhancedTransformResult, "errors" | "warnings"> & {
110
+ errors: Error[];
111
+ warnings: RolldownLog[];
112
+ };
113
+ /**
114
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
115
+ *
116
+ * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
117
+ *
118
+ * @param filename The name of the file being transformed. If this is a
119
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
120
+ * @param sourceText The source code to transform.
121
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
122
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
123
+ * Used when `options.tsconfig` is `true` or a path. For a path, construct the
124
+ * cache with the same path.
125
+ *
126
+ * @returns a promise that resolves to an object containing the transformed code,
127
+ * source maps, and any errors that occurred during parsing or transformation.
128
+ *
129
+ * @category Utilities
130
+ * @experimental
131
+ */
132
+ declare function transform(filename: string, sourceText: string, options?: TransformOptions | null, cache?: TsconfigCache | null): Promise<TransformResult>;
133
+ /**
134
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
135
+ *
136
+ * @param filename The name of the file being transformed. If this is a
137
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
138
+ * @param sourceText The source code to transform.
139
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
140
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
141
+ * Used when `options.tsconfig` is `true` or a path. For a path, construct the
142
+ * cache with the same path.
143
+ *
144
+ * @returns an object containing the transformed code, source maps, and any errors
145
+ * that occurred during parsing or transformation.
146
+ *
147
+ * @category Utilities
148
+ * @experimental
149
+ */
150
+ declare function transformSync(filename: string, sourceText: string, options?: TransformOptions | null, cache?: TsconfigCache | null): TransformResult;
151
+ //#endregion
152
+ export { MinifyOptions as a, minifySync as c, parse as d, parseSync as f, transformSync as i, ParseResult as l, resolveTsconfig as m, TransformResult as n, MinifyResult as o, TsconfigCache as p, transform as r, minify as s, TransformOptions as t, ParserOptions as u };