@rollipop/rolldown 0.0.0 → 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/LICENSE +25 -0
- package/README.md +11 -1
- package/bin/cli.mjs +2 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1191 -0
- package/dist/config.d.mts +14 -0
- package/dist/config.mjs +4 -0
- package/dist/experimental-index.d.mts +316 -0
- package/dist/experimental-index.mjs +350 -0
- package/dist/experimental-runtime-types.d.ts +98 -0
- package/dist/filter-index.d.mts +196 -0
- package/dist/filter-index.mjs +386 -0
- package/dist/get-log-filter.d.mts +3 -0
- package/dist/get-log-filter.mjs +68 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +50 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/parallel-plugin-worker.mjs +28 -0
- package/dist/parallel-plugin.d.mts +13 -0
- package/dist/parallel-plugin.mjs +6 -0
- package/dist/parse-ast-index.d.mts +32 -0
- package/dist/parse-ast-index.mjs +60 -0
- package/dist/plugins-index.d.mts +33 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/shared/binding-D_jQsHun.mjs +583 -0
- package/dist/shared/binding-hSQGgsUz.d.mts +1877 -0
- package/dist/shared/bindingify-input-options-DfXGy4QO.mjs +2193 -0
- package/dist/shared/constructors-B-HbV10G.mjs +68 -0
- package/dist/shared/constructors-DMl58KN5.d.mts +37 -0
- package/dist/shared/define-config-BSxBeCq6.d.mts +3810 -0
- package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
- package/dist/shared/error-D5tMcn3l.mjs +85 -0
- package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
- package/dist/shared/load-config-CNjYgiQv.mjs +120 -0
- package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
- package/dist/shared/logs-D80CXhvg.mjs +180 -0
- package/dist/shared/misc-DJYbNKZX.mjs +21 -0
- package/dist/shared/normalize-string-or-regex-B8PEhdn1.mjs +66 -0
- package/dist/shared/parse-iQx2ihYn.mjs +74 -0
- package/dist/shared/prompt-BYQIwEjg.mjs +845 -0
- package/dist/shared/resolve-tsconfig-CxoM-bno.mjs +113 -0
- package/dist/shared/rolldown-C0o3hS3w.mjs +40 -0
- package/dist/shared/rolldown-build-80GULIOI.mjs +3326 -0
- package/dist/shared/transform-DY2pi3Qm.d.mts +149 -0
- package/dist/shared/watch-C2am0Ahc.mjs +374 -0
- package/dist/utils-index.d.mts +376 -0
- package/dist/utils-index.mjs +2414 -0
- package/package.json +130 -2
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
|
@@ -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.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
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 { V as PreRenderedChunk } from "./shared/binding-hSQGgsUz.mjs";
|
|
3
|
+
import { $ as GeneralHookFilter, A as SourceDescription, At as CodeSplittingOptions, B as TreeshakingOptions, Bt as PartialNull, C as PartialResolvedId, Ct as AddonFunction, D as ResolvedId, Dt as ChunkingContext, E as ResolveIdResult, Et as ChunkFileNamesFunction, F as VERSION, Ft as MinifyOptions, G as EmittedPrebuiltChunk, Gt as RenderedModule, H as EmittedAsset, Ht as OutputAsset, I as BundleError, It as ModuleFormat, J as PluginContextResolveOptions, K as GetModuleInfo, Kt as RolldownOutput, L as ExistingRawSourceMap, Lt as OutputOptions, Mt as GeneratedCodeOptions, Nt as GeneratedCodePreset, O as RolldownPlugin, Ot as CodeSplittingGroup, P as RUNTIME_MODULE_ID, Pt as GlobalsFunction, Q as PluginContextMeta, R as SourceMapInput, Rt as PreRenderedAsset, S as ParallelPluginHooks, St as build, T as ResolveIdExtraOptions, Tt as AdvancedChunksOptions, U as EmittedChunk, Ut as OutputChunk, V as TransformPluginContext, W as EmittedFile, Wt as RenderedChunk, Xt as SourcemapIgnoreListOption, Y as DefineParallelPluginResult, Yt as ModuleInfo, Z as MinimalPluginContext, _ as ImportKind, _t as RolldownWatcherWatcherEventMap, a as ExternalOption, at as RolldownFsModule, b as ModuleType, bt as RolldownBuild, c as InputOptions, ct as NormalizedInputOptions, d as WatcherFileWatcherOptions, dt as LoggingFunction, et as HookFilter, f as WatcherOptions, ft as WarningHandlerWithDefault, g as HookFilterExtension, gt as RolldownWatcherEvent, h as FunctionPluginHooks, ht as RolldownWatcher, i as RolldownOptions, it as RolldownFileStats, j as TransformResult, jt as CommentsOptions, k as RolldownPluginOption, kt as CodeSplittingNameFunction, l as ModuleTypes, lt as TransformOptions, m as CustomPluginOptions, mt as watch, n as RolldownOptionsFunction, nt as BufferEncoding, o as ExternalOptionFunction, ot as InternalModuleFormat, p as AsyncPluginHooks, pt as RolldownMagicString, q as PluginContext, qt as SourceMap, r as defineConfig, rt as RolldownDirectoryEntry, s as InputOption, st as NormalizedOutputOptions, t as ConfigExport, tt as ModuleTypeFilter, u as OptimizationOptions, ut as ChecksOptions, v as LoadResult, vt as WatchOptions, w as Plugin, wt as AdvancedChunksGroup, x as ObjectHook, xt as BuildOptions, y as ModuleOptions, yt as rolldown, z as OutputBundle } from "./shared/define-config-BSxBeCq6.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
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./shared/binding-D_jQsHun.mjs";
|
|
2
|
+
import { n as onExit, t as watch } from "./shared/watch-C2am0Ahc.mjs";
|
|
3
|
+
import { a as RolldownMagicString, b as RUNTIME_MODULE_ID, x as VERSION } from "./shared/bindingify-input-options-DfXGy4QO.mjs";
|
|
4
|
+
import { t as rolldown } from "./shared/rolldown-C0o3hS3w.mjs";
|
|
5
|
+
import { t as defineConfig } from "./shared/define-config-DJOr6Iwt.mjs";
|
|
6
|
+
import { isMainThread } from "node:worker_threads";
|
|
7
|
+
//#region src/setup.ts
|
|
8
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
9
|
+
if (isMainThread) {
|
|
10
|
+
const subscriberGuard = (0, import_binding.initTraceSubscriber)();
|
|
11
|
+
onExit(() => {
|
|
12
|
+
subscriberGuard?.close();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/api/build.ts
|
|
17
|
+
/**
|
|
18
|
+
* The API similar to esbuild's `build` function.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```js
|
|
22
|
+
* import { build } from 'rolldown';
|
|
23
|
+
*
|
|
24
|
+
* const result = await build({
|
|
25
|
+
* input: 'src/main.js',
|
|
26
|
+
* output: {
|
|
27
|
+
* file: 'bundle.js',
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
* console.log(result);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @experimental
|
|
34
|
+
* @category Programmatic APIs
|
|
35
|
+
*/
|
|
36
|
+
async function build(options) {
|
|
37
|
+
if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
|
|
38
|
+
else {
|
|
39
|
+
const { output, write = true, ...inputOptions } = options;
|
|
40
|
+
const build = await rolldown(inputOptions);
|
|
41
|
+
try {
|
|
42
|
+
if (write) return await build.write(output);
|
|
43
|
+
else return await build.generate(output);
|
|
44
|
+
} finally {
|
|
45
|
+
await build.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { RUNTIME_MODULE_ID, RolldownMagicString, VERSION, build, defineConfig, rolldown, watch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { n as __toESM, t as require_binding } from "./shared/binding-D_jQsHun.mjs";
|
|
2
|
+
import { n as PluginContextData, r as bindingifyPlugin } from "./shared/bindingify-input-options-DfXGy4QO.mjs";
|
|
3
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
+
//#region src/parallel-plugin-worker.ts
|
|
5
|
+
var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
|
|
6
|
+
const { registryId, pluginInfos, threadNumber } = workerData;
|
|
7
|
+
(async () => {
|
|
8
|
+
try {
|
|
9
|
+
(0, import_binding.registerPlugins)(registryId, await Promise.all(pluginInfos.map(async (pluginInfo) => {
|
|
10
|
+
const definePluginImpl = (await import(pluginInfo.fileUrl)).default;
|
|
11
|
+
const plugin = await definePluginImpl(pluginInfo.options, { threadNumber });
|
|
12
|
+
return {
|
|
13
|
+
index: pluginInfo.index,
|
|
14
|
+
plugin: bindingifyPlugin(plugin, {}, {}, new PluginContextData(() => {}, {}, [], []), [], () => {}, "info", false)
|
|
15
|
+
};
|
|
16
|
+
})));
|
|
17
|
+
parentPort.postMessage({ type: "success" });
|
|
18
|
+
} catch (error) {
|
|
19
|
+
parentPort.postMessage({
|
|
20
|
+
type: "error",
|
|
21
|
+
error
|
|
22
|
+
});
|
|
23
|
+
} finally {
|
|
24
|
+
parentPort.unref();
|
|
25
|
+
}
|
|
26
|
+
})();
|
|
27
|
+
//#endregion
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { w as Plugin, zt as MaybePromise } from "./shared/define-config-BSxBeCq6.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/parallel-plugin-implementation.d.ts
|
|
4
|
+
type ParallelPluginImplementation = Plugin;
|
|
5
|
+
type Context = {
|
|
6
|
+
/**
|
|
7
|
+
* Thread number
|
|
8
|
+
*/
|
|
9
|
+
threadNumber: number;
|
|
10
|
+
};
|
|
11
|
+
declare function defineParallelPluginImplementation<Options>(plugin: (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>): (Options: Options, context: Context) => MaybePromise<ParallelPluginImplementation>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { type Context, type ParallelPluginImplementation, defineParallelPluginImplementation };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { B as ParserOptions$1, z as ParseResult$1 } from "./shared/binding-hSQGgsUz.mjs";
|
|
2
|
+
import { Program } from "@oxc-project/types";
|
|
3
|
+
|
|
4
|
+
//#region src/parse-ast-index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
8
|
+
type ParseResult = ParseResult$1;
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
type ParserOptions = ParserOptions$1;
|
|
13
|
+
/**
|
|
14
|
+
* Parse code synchronously and return the AST.
|
|
15
|
+
*
|
|
16
|
+
* This function is similar to Rollup's `parseAst` function.
|
|
17
|
+
* Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
|
|
18
|
+
*
|
|
19
|
+
* @category Utilities
|
|
20
|
+
*/
|
|
21
|
+
declare function parseAst(sourceText: string, options?: ParserOptions | null, filename?: string): Program;
|
|
22
|
+
/**
|
|
23
|
+
* Parse code asynchronously and return the AST.
|
|
24
|
+
*
|
|
25
|
+
* This function is similar to Rollup's `parseAstAsync` function.
|
|
26
|
+
* Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
|
|
27
|
+
*
|
|
28
|
+
* @category Utilities
|
|
29
|
+
*/
|
|
30
|
+
declare function parseAstAsync(sourceText: string, options?: ParserOptions | null, filename?: string): Promise<Program>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ParseResult, ParserOptions, parseAst, parseAstAsync };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { l as locate, n as error, s as logParseError, t as augmentCodeLocation, u as getCodeFrame } from "./shared/logs-D80CXhvg.mjs";
|
|
2
|
+
import { n as parseSync, t as parse } from "./shared/parse-iQx2ihYn.mjs";
|
|
3
|
+
//#region src/parse-ast-index.ts
|
|
4
|
+
function wrap(result, filename, sourceText) {
|
|
5
|
+
if (result.errors.length > 0) return normalizeParseError(filename, sourceText, result.errors);
|
|
6
|
+
return result.program;
|
|
7
|
+
}
|
|
8
|
+
function normalizeParseError(filename, sourceText, errors) {
|
|
9
|
+
let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
|
|
10
|
+
const pos = errors[0]?.labels?.[0]?.start;
|
|
11
|
+
for (let i = 0; i < errors.length; i++) {
|
|
12
|
+
if (i >= 5) {
|
|
13
|
+
message += "\n...";
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
const e = errors[i];
|
|
17
|
+
message += e.message + "\n" + e.labels.map((label) => {
|
|
18
|
+
const location = locate(sourceText, label.start, { offsetLine: 1 });
|
|
19
|
+
if (!location) return;
|
|
20
|
+
return getCodeFrame(sourceText, location.line, location.column);
|
|
21
|
+
}).filter(Boolean).join("\n");
|
|
22
|
+
}
|
|
23
|
+
const log = logParseError(message, filename, pos);
|
|
24
|
+
if (pos !== void 0 && filename) augmentCodeLocation(log, pos, sourceText, filename);
|
|
25
|
+
return error(log);
|
|
26
|
+
}
|
|
27
|
+
const defaultParserOptions = {
|
|
28
|
+
lang: "js",
|
|
29
|
+
preserveParens: false
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Parse code synchronously and return the AST.
|
|
33
|
+
*
|
|
34
|
+
* This function is similar to Rollup's `parseAst` function.
|
|
35
|
+
* Prefer using {@linkcode parseSync} instead of this function as it has more information in the return value.
|
|
36
|
+
*
|
|
37
|
+
* @category Utilities
|
|
38
|
+
*/
|
|
39
|
+
function parseAst(sourceText, options, filename) {
|
|
40
|
+
return wrap(parseSync(filename ?? "file.js", sourceText, {
|
|
41
|
+
...defaultParserOptions,
|
|
42
|
+
...options
|
|
43
|
+
}), filename, sourceText);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse code asynchronously and return the AST.
|
|
47
|
+
*
|
|
48
|
+
* This function is similar to Rollup's `parseAstAsync` function.
|
|
49
|
+
* Prefer using {@linkcode parseAsync} instead of this function as it has more information in the return value.
|
|
50
|
+
*
|
|
51
|
+
* @category Utilities
|
|
52
|
+
*/
|
|
53
|
+
async function parseAstAsync(sourceText, options, filename) {
|
|
54
|
+
return wrap(await parse(filename ?? "file.js", sourceText, {
|
|
55
|
+
...defaultParserOptions,
|
|
56
|
+
...options
|
|
57
|
+
}), filename, sourceText);
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { parseAst, parseAstAsync };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { m as BindingReplacePluginConfig } from "./shared/binding-hSQGgsUz.mjs";
|
|
2
|
+
import { N as BuiltinPlugin } from "./shared/define-config-BSxBeCq6.mjs";
|
|
3
|
+
import { t as esmExternalRequirePlugin } from "./shared/constructors-DMl58KN5.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/builtin-plugin/replace-plugin.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Replaces targeted strings in files while bundling.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* **Basic usage**
|
|
11
|
+
* ```js
|
|
12
|
+
* replacePlugin({
|
|
13
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
14
|
+
* __buildVersion: 15
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
* @example
|
|
18
|
+
* **With options**
|
|
19
|
+
* ```js
|
|
20
|
+
* replacePlugin({
|
|
21
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
22
|
+
* __buildVersion: 15
|
|
23
|
+
* }, {
|
|
24
|
+
* preventAssignment: false,
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @see https://rolldown.rs/builtin-plugins/replace
|
|
29
|
+
* @category Builtin Plugins
|
|
30
|
+
*/
|
|
31
|
+
declare function replacePlugin(values?: BindingReplacePluginConfig["values"], options?: Omit<BindingReplacePluginConfig, "values">): BuiltinPlugin;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { esmExternalRequirePlugin, replacePlugin };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { a as makeBuiltinPluginCallable, n as BuiltinPlugin } from "./shared/normalize-string-or-regex-B8PEhdn1.mjs";
|
|
2
|
+
import { t as esmExternalRequirePlugin } from "./shared/constructors-B-HbV10G.mjs";
|
|
3
|
+
//#region src/builtin-plugin/replace-plugin.ts
|
|
4
|
+
/**
|
|
5
|
+
* Replaces targeted strings in files while bundling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* **Basic usage**
|
|
9
|
+
* ```js
|
|
10
|
+
* replacePlugin({
|
|
11
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
12
|
+
* __buildVersion: 15
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
* @example
|
|
16
|
+
* **With options**
|
|
17
|
+
* ```js
|
|
18
|
+
* replacePlugin({
|
|
19
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
20
|
+
* __buildVersion: 15
|
|
21
|
+
* }, {
|
|
22
|
+
* preventAssignment: false,
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see https://rolldown.rs/builtin-plugins/replace
|
|
27
|
+
* @category Builtin Plugins
|
|
28
|
+
*/
|
|
29
|
+
function replacePlugin(values = {}, options = {}) {
|
|
30
|
+
Object.keys(values).forEach((key) => {
|
|
31
|
+
const value = values[key];
|
|
32
|
+
if (typeof value !== "string") values[key] = String(value);
|
|
33
|
+
});
|
|
34
|
+
return makeBuiltinPluginCallable(new BuiltinPlugin("builtin:replace", {
|
|
35
|
+
...options,
|
|
36
|
+
values
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { esmExternalRequirePlugin, replacePlugin };
|