rolldown 1.0.0-beta.3-commit.d298c0b → 1.0.0-beta.3-commit.73fa972

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/cjs/cli.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-qZFfknuJ.cjs');
3
- const require_src = require('../shared/src-GI88yV1N.cjs');
4
- const require_parse_ast_index = require('../shared/parse-ast-index-CQpWnODq.cjs');
3
+ const require_src = require('../shared/src-Ddi0ioIv.cjs');
4
+ const require_parse_ast_index = require('../shared/parse-ast-index-Dh_sWnMa.cjs');
5
5
  const node_process = require_chunk.__toESM(require("node:process"));
6
6
  const node_path = require_chunk.__toESM(require("node:path"));
7
7
  const node_fs = require_chunk.__toESM(require("node:fs"));
@@ -1166,7 +1166,7 @@ function createTestingLogger() {
1166
1166
 
1167
1167
  //#endregion
1168
1168
  //#region src/cli/load-config.ts
1169
- async function bundleTsConfig(configFile) {
1169
+ async function bundleTsConfig(configFile, isEsm) {
1170
1170
  const dirnameVarName = "injected_original_dirname";
1171
1171
  const filenameVarName = "injected_original_filename";
1172
1172
  const importMetaUrlVarName = "injected_original_import_meta_url";
@@ -1200,9 +1200,9 @@ async function bundleTsConfig(configFile) {
1200
1200
  const outputDir = node_path.default.dirname(configFile);
1201
1201
  const result = await bundle.write({
1202
1202
  dir: outputDir,
1203
- format: "esm",
1203
+ format: isEsm ? "esm" : "cjs",
1204
1204
  sourcemap: "inline",
1205
- entryFileNames: "rolldown.config.[hash].js"
1205
+ entryFileNames: `rolldown.config.[hash]${node_path.default.extname(configFile).replace("ts", "js")}`
1206
1206
  });
1207
1207
  const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1208
1208
  return node_path.default.join(outputDir, fileName);
@@ -1228,13 +1228,40 @@ async function findConfigFileNameInCwd() {
1228
1228
  throw new Error("No `rolldown.config` configuration file found.");
1229
1229
  }
1230
1230
  async function loadTsConfig(configFile) {
1231
- const file = await bundleTsConfig(configFile);
1231
+ const isEsm = isFilePathESM(configFile);
1232
+ const file = await bundleTsConfig(configFile, isEsm);
1232
1233
  try {
1233
1234
  return (await import((0, node_url.pathToFileURL)(file).href)).default;
1234
1235
  } finally {
1235
1236
  node_fs.default.unlink(file, () => {});
1236
1237
  }
1237
1238
  }
1239
+ function isFilePathESM(filePath) {
1240
+ if (/\.m[jt]s$/.test(filePath)) return true;
1241
+ else if (/\.c[jt]s$/.test(filePath)) return false;
1242
+ else {
1243
+ const pkg = findNearestPackageData(node_path.default.dirname(filePath));
1244
+ if (pkg) return pkg.type === "module";
1245
+ return false;
1246
+ }
1247
+ }
1248
+ function findNearestPackageData(basedir) {
1249
+ while (basedir) {
1250
+ const pkgPath = node_path.default.join(basedir, "package.json");
1251
+ if (tryStatSync(pkgPath)?.isFile()) try {
1252
+ return JSON.parse(node_fs.default.readFileSync(pkgPath, "utf-8"));
1253
+ } catch {}
1254
+ const nextBasedir = node_path.default.dirname(basedir);
1255
+ if (nextBasedir === basedir) break;
1256
+ basedir = nextBasedir;
1257
+ }
1258
+ return null;
1259
+ }
1260
+ function tryStatSync(file) {
1261
+ try {
1262
+ return node_fs.default.statSync(file, { throwIfNoEntry: false });
1263
+ } catch {}
1264
+ }
1238
1265
  async function loadConfig(configPath) {
1239
1266
  const ext = node_path.default.extname(configPath = configPath || await findConfigFileNameInCwd());
1240
1267
  try {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-qZFfknuJ.cjs');
3
- const require_src = require('../shared/src-GI88yV1N.cjs');
4
- const require_parse_ast_index = require('../shared/parse-ast-index-CQpWnODq.cjs');
3
+ const require_src = require('../shared/src-Ddi0ioIv.cjs');
4
+ const require_parse_ast_index = require('../shared/parse-ast-index-Dh_sWnMa.cjs');
5
5
  const node_url = require_chunk.__toESM(require("node:url"));
6
6
 
7
7
  //#region src/plugin/parallel-plugin.ts
@@ -1,5 +1,5 @@
1
- const require_src = require('../shared/src-GI88yV1N.cjs');
2
- require('../shared/parse-ast-index-CQpWnODq.cjs');
1
+ const require_src = require('../shared/src-Ddi0ioIv.cjs');
2
+ require('../shared/parse-ast-index-Dh_sWnMa.cjs');
3
3
 
4
4
  exports.VERSION = require_src.VERSION
5
5
  exports.build = require_src.build
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-qZFfknuJ.cjs');
3
- const require_src = require('../shared/src-GI88yV1N.cjs');
4
- const require_parse_ast_index = require('../shared/parse-ast-index-CQpWnODq.cjs');
3
+ const require_src = require('../shared/src-Ddi0ioIv.cjs');
4
+ const require_parse_ast_index = require('../shared/parse-ast-index-Dh_sWnMa.cjs');
5
5
  const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
6
6
 
7
7
  //#region src/parallel-plugin-worker.ts
@@ -1,4 +1,4 @@
1
- const require_parse_ast_index = require('../shared/parse-ast-index-CQpWnODq.cjs');
1
+ const require_parse_ast_index = require('../shared/parse-ast-index-Dh_sWnMa.cjs');
2
2
 
3
3
  exports.parseAst = require_parse_ast_index.parseAst
4
4
  exports.parseAstAsync = require_parse_ast_index.parseAstAsync
package/dist/esm/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { colors } from "../shared/parse-ast-index-Aeq00bwr.mjs";
2
- import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-CeA4I13P.mjs";
1
+ import { colors } from "../shared/parse-ast-index-DIxeQDpE.mjs";
2
+ import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-COxk9RoQ.mjs";
3
3
  import process$1, { cwd } from "node:process";
4
4
  import path, { sep } from "node:path";
5
5
  import fs from "node:fs";
@@ -1162,7 +1162,7 @@ function createTestingLogger() {
1162
1162
 
1163
1163
  //#endregion
1164
1164
  //#region src/cli/load-config.ts
1165
- async function bundleTsConfig(configFile) {
1165
+ async function bundleTsConfig(configFile, isEsm) {
1166
1166
  const dirnameVarName = "injected_original_dirname";
1167
1167
  const filenameVarName = "injected_original_filename";
1168
1168
  const importMetaUrlVarName = "injected_original_import_meta_url";
@@ -1196,9 +1196,9 @@ async function bundleTsConfig(configFile) {
1196
1196
  const outputDir = path.dirname(configFile);
1197
1197
  const result = await bundle.write({
1198
1198
  dir: outputDir,
1199
- format: "esm",
1199
+ format: isEsm ? "esm" : "cjs",
1200
1200
  sourcemap: "inline",
1201
- entryFileNames: "rolldown.config.[hash].js"
1201
+ entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
1202
1202
  });
1203
1203
  const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1204
1204
  return path.join(outputDir, fileName);
@@ -1224,13 +1224,40 @@ async function findConfigFileNameInCwd() {
1224
1224
  throw new Error("No `rolldown.config` configuration file found.");
1225
1225
  }
1226
1226
  async function loadTsConfig(configFile) {
1227
- const file = await bundleTsConfig(configFile);
1227
+ const isEsm = isFilePathESM(configFile);
1228
+ const file = await bundleTsConfig(configFile, isEsm);
1228
1229
  try {
1229
1230
  return (await import(pathToFileURL(file).href)).default;
1230
1231
  } finally {
1231
1232
  fs.unlink(file, () => {});
1232
1233
  }
1233
1234
  }
1235
+ function isFilePathESM(filePath) {
1236
+ if (/\.m[jt]s$/.test(filePath)) return true;
1237
+ else if (/\.c[jt]s$/.test(filePath)) return false;
1238
+ else {
1239
+ const pkg = findNearestPackageData(path.dirname(filePath));
1240
+ if (pkg) return pkg.type === "module";
1241
+ return false;
1242
+ }
1243
+ }
1244
+ function findNearestPackageData(basedir) {
1245
+ while (basedir) {
1246
+ const pkgPath = path.join(basedir, "package.json");
1247
+ if (tryStatSync(pkgPath)?.isFile()) try {
1248
+ return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1249
+ } catch {}
1250
+ const nextBasedir = path.dirname(basedir);
1251
+ if (nextBasedir === basedir) break;
1252
+ basedir = nextBasedir;
1253
+ }
1254
+ return null;
1255
+ }
1256
+ function tryStatSync(file) {
1257
+ try {
1258
+ return fs.statSync(file, { throwIfNoEntry: false });
1259
+ } catch {}
1260
+ }
1234
1261
  async function loadConfig(configPath) {
1235
1262
  const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
1236
1263
  try {
@@ -1,5 +1,5 @@
1
- import { import_binding } from "../shared/parse-ast-index-Aeq00bwr.mjs";
2
- import { BuiltinPlugin, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, moduleFederationPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-CeA4I13P.mjs";
1
+ import { import_binding } from "../shared/parse-ast-index-DIxeQDpE.mjs";
2
+ import { BuiltinPlugin, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, moduleFederationPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-COxk9RoQ.mjs";
3
3
  import { pathToFileURL } from "node:url";
4
4
 
5
5
  //#region src/plugin/parallel-plugin.ts
@@ -1,4 +1,4 @@
1
- import "../shared/parse-ast-index-Aeq00bwr.mjs";
2
- import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-CeA4I13P.mjs";
1
+ import "../shared/parse-ast-index-DIxeQDpE.mjs";
2
+ import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-COxk9RoQ.mjs";
3
3
 
4
4
  export { VERSION, build, defineConfig, rolldown, watch };
@@ -1,5 +1,5 @@
1
- import { import_binding } from "../shared/parse-ast-index-Aeq00bwr.mjs";
2
- import { PluginContextData, bindingifyPlugin } from "../shared/src-CeA4I13P.mjs";
1
+ import { import_binding } from "../shared/parse-ast-index-DIxeQDpE.mjs";
2
+ import { PluginContextData, bindingifyPlugin } from "../shared/src-COxk9RoQ.mjs";
3
3
  import { parentPort, workerData } from "node:worker_threads";
4
4
 
5
5
  //#region src/parallel-plugin-worker.ts
@@ -1,3 +1,3 @@
1
- import { parseAst, parseAstAsync } from "../shared/parse-ast-index-Aeq00bwr.mjs";
1
+ import { parseAst, parseAstAsync } from "../shared/parse-ast-index-DIxeQDpE.mjs";
2
2
 
3
3
  export { parseAst, parseAstAsync };
@@ -597,11 +597,15 @@ var require_binding = __commonJS({ "src/binding.js"(exports, module) {
597
597
  module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind;
598
598
  module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind;
599
599
  module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind;
600
+ module.exports.getBufferOffset = nativeBinding.getBufferOffset;
600
601
  module.exports.HelperMode = nativeBinding.HelperMode;
601
602
  module.exports.ImportNameKind = nativeBinding.ImportNameKind;
602
603
  module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
604
+ module.exports.moduleRunnerTransform = nativeBinding.moduleRunnerTransform;
603
605
  module.exports.parseAsync = nativeBinding.parseAsync;
604
606
  module.exports.parseSync = nativeBinding.parseSync;
607
+ module.exports.parseSyncRaw = nativeBinding.parseSyncRaw;
608
+ module.exports.rawTransferSupported = nativeBinding.rawTransferSupported;
605
609
  module.exports.registerPlugins = nativeBinding.registerPlugins;
606
610
  module.exports.Severity = nativeBinding.Severity;
607
611
  module.exports.transform = nativeBinding.transform;
@@ -571,11 +571,15 @@ var require_binding = require_chunk.__commonJS({ "src/binding.js"(exports, modul
571
571
  module.exports.ExportExportNameKind = nativeBinding.ExportExportNameKind;
572
572
  module.exports.ExportImportNameKind = nativeBinding.ExportImportNameKind;
573
573
  module.exports.ExportLocalNameKind = nativeBinding.ExportLocalNameKind;
574
+ module.exports.getBufferOffset = nativeBinding.getBufferOffset;
574
575
  module.exports.HelperMode = nativeBinding.HelperMode;
575
576
  module.exports.ImportNameKind = nativeBinding.ImportNameKind;
576
577
  module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
578
+ module.exports.moduleRunnerTransform = nativeBinding.moduleRunnerTransform;
577
579
  module.exports.parseAsync = nativeBinding.parseAsync;
578
580
  module.exports.parseSync = nativeBinding.parseSync;
581
+ module.exports.parseSyncRaw = nativeBinding.parseSyncRaw;
582
+ module.exports.rawTransferSupported = nativeBinding.rawTransferSupported;
579
583
  module.exports.registerPlugins = nativeBinding.registerPlugins;
580
584
  module.exports.Severity = nativeBinding.Severity;
581
585
  module.exports.transform = nativeBinding.transform;
@@ -1,4 +1,4 @@
1
- import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-Aeq00bwr.mjs";
1
+ import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-DIxeQDpE.mjs";
2
2
  import path from "node:path";
3
3
  import * as v from "valibot";
4
4
  import { toJsonSchema } from "@valibot/to-json-schema";
@@ -455,6 +455,42 @@ const JsxOptionsSchema = v.strictObject({
455
455
  ])), v.description("Jsx transformation mode")),
456
456
  refresh: v.pipe(v.optional(v.boolean()), v.description("React refresh transformation"))
457
457
  });
458
+ const HelperModeSchema = v.union([v.literal("Runtime"), v.literal("External")]);
459
+ const DecoratorOptionSchema = v.object({
460
+ legacy: v.optional(v.boolean()),
461
+ emitDecoratorMetadata: v.optional(v.boolean())
462
+ });
463
+ const HelpersSchema = v.object({ mode: v.optional(HelperModeSchema) });
464
+ const RewriteImportExtensionsSchema = v.union([
465
+ v.literal("rewrite"),
466
+ v.literal("remove"),
467
+ v.boolean()
468
+ ]);
469
+ const TypescriptSchema = v.object({
470
+ jsxPragma: v.optional(v.string()),
471
+ jsxPragmaFrag: v.optional(v.string()),
472
+ onlyRemoveTypeImports: v.optional(v.boolean()),
473
+ allowNamespaces: v.optional(v.boolean()),
474
+ allowDeclareFields: v.optional(v.boolean()),
475
+ declaration: v.optional(v.object({
476
+ stripInternal: v.optional(v.boolean()),
477
+ sourcemap: v.optional(v.boolean())
478
+ })),
479
+ rewriteImportExtensions: v.optional(RewriteImportExtensionsSchema)
480
+ });
481
+ const AssumptionsSchema = v.object({
482
+ ignoreFunctionLength: v.optional(v.boolean()),
483
+ noDocumentAll: v.optional(v.boolean()),
484
+ objectRestNoSymbols: v.optional(v.boolean()),
485
+ pureGetters: v.optional(v.boolean()),
486
+ setPublicClassFields: v.optional(v.boolean())
487
+ });
488
+ const TransformOptionsSchema = v.object({
489
+ assumptions: v.optional(AssumptionsSchema),
490
+ typescript: v.optional(TypescriptSchema),
491
+ helpers: v.optional(HelpersSchema),
492
+ decorators: v.optional(DecoratorOptionSchema)
493
+ });
458
494
  const WatchOptionsSchema = v.strictObject({
459
495
  chokidar: v.optional(v.never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
460
496
  exclude: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
@@ -520,7 +556,14 @@ const InputOptionsSchema = v.strictObject({
520
556
  define: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Define global variables")),
521
557
  inject: v.optional(v.record(v.string(), v.union([v.string(), v.tuple([v.string(), v.string()])]))),
522
558
  profilerNames: v.optional(v.boolean()),
523
- jsx: v.optional(v.union([v.boolean(), JsxOptionsSchema])),
559
+ jsx: v.optional(v.union([
560
+ v.boolean(),
561
+ JsxOptionsSchema,
562
+ v.string("react"),
563
+ v.string("react-jsx"),
564
+ v.string("preserve")
565
+ ])),
566
+ transform: v.optional(TransformOptionsSchema),
524
567
  watch: v.optional(v.union([WatchOptionsSchema, v.literal(false)])),
525
568
  dropLabels: v.pipe(v.optional(v.array(v.string())), v.description("Remove labeled statements with these label names")),
526
569
  checks: v.optional(ChecksOptionsSchema),
@@ -545,7 +588,7 @@ const InputCliOptionsSchema = v.omit(v.strictObject({
545
588
  "profilerNames",
546
589
  "watch"
547
590
  ]);
548
- var ESTarget = function(ESTarget$1) {
591
+ var ESTarget = /* @__PURE__ */ function(ESTarget$1) {
549
592
  ESTarget$1["ES6"] = "es6";
550
593
  ESTarget$1["ES2015"] = "es2015";
551
594
  ESTarget$1["ES2016"] = "es2016";
@@ -1993,6 +2036,7 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normali
1993
2036
  },
1994
2037
  profilerNames: inputOptions?.profilerNames,
1995
2038
  jsx: bindingifyJsx(inputOptions.jsx),
2039
+ transform: inputOptions.transform,
1996
2040
  watch: bindingifyWatch(inputOptions.watch),
1997
2041
  dropLabels: inputOptions.dropLabels,
1998
2042
  keepNames: inputOptions.keepNames,
@@ -2075,30 +2119,34 @@ function bindingifyInput(input) {
2075
2119
  if (input === void 0) return [];
2076
2120
  if (typeof input === "string") return [{ import: input }];
2077
2121
  if (Array.isArray(input)) return input.map((src) => ({ import: src }));
2078
- return Object.entries(input).map((value) => {
2122
+ return Object.entries(input).map(([name, import_path]) => {
2079
2123
  return {
2080
- name: value[0],
2081
- import: value[1]
2124
+ name,
2125
+ import: import_path
2082
2126
  };
2083
2127
  });
2084
2128
  }
2085
2129
  function bindingifyJsx(input) {
2086
- if (input === false) return { type: "Disable" };
2087
- if (input) {
2088
- if (input.mode === "preserve") return { type: "Preserve" };
2089
- const mode = input.mode ?? "automatic";
2090
- return {
2091
- type: "Enable",
2092
- field0: {
2093
- runtime: mode,
2094
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
2095
- pragma: input.factory,
2096
- pragmaFrag: input.fragment,
2097
- development: input.development,
2098
- refresh: input.refresh
2099
- }
2100
- };
2130
+ switch (input) {
2131
+ case false: return { type: "Disable" };
2132
+ case "react": return { type: "React" };
2133
+ case "react-jsx": return { type: "ReactJsx" };
2134
+ case "preserve": return { type: "Preserve" };
2135
+ case void 0: return void 0;
2101
2136
  }
2137
+ if (input.mode === "preserve") return { type: "Preserve" };
2138
+ const mode = input.mode ?? "automatic";
2139
+ return {
2140
+ type: "Enable",
2141
+ field0: {
2142
+ runtime: mode,
2143
+ importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
2144
+ pragma: input.factory,
2145
+ pragmaFrag: input.fragment,
2146
+ development: input.development,
2147
+ refresh: input.refresh
2148
+ }
2149
+ };
2102
2150
  }
2103
2151
  function bindingifyWatch(watch$1) {
2104
2152
  if (watch$1) return {
@@ -2739,7 +2787,7 @@ const watch = (input) => {
2739
2787
 
2740
2788
  //#endregion
2741
2789
  //#region package.json
2742
- var version = "1.0.0-beta.3-commit.d298c0b";
2790
+ var version = "1.0.0-beta.3-commit.73fa972";
2743
2791
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2744
2792
 
2745
2793
  //#endregion
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const require_chunk = require('./chunk-qZFfknuJ.cjs');
3
- const require_parse_ast_index = require('./parse-ast-index-CQpWnODq.cjs');
3
+ const require_parse_ast_index = require('./parse-ast-index-Dh_sWnMa.cjs');
4
4
  const node_path = require_chunk.__toESM(require("node:path"));
5
5
  const valibot = require_chunk.__toESM(require("valibot"));
6
6
  const __valibot_to_json_schema = require_chunk.__toESM(require("@valibot/to-json-schema"));
@@ -457,6 +457,42 @@ const JsxOptionsSchema = valibot.strictObject({
457
457
  ])), valibot.description("Jsx transformation mode")),
458
458
  refresh: valibot.pipe(valibot.optional(valibot.boolean()), valibot.description("React refresh transformation"))
459
459
  });
460
+ const HelperModeSchema = valibot.union([valibot.literal("Runtime"), valibot.literal("External")]);
461
+ const DecoratorOptionSchema = valibot.object({
462
+ legacy: valibot.optional(valibot.boolean()),
463
+ emitDecoratorMetadata: valibot.optional(valibot.boolean())
464
+ });
465
+ const HelpersSchema = valibot.object({ mode: valibot.optional(HelperModeSchema) });
466
+ const RewriteImportExtensionsSchema = valibot.union([
467
+ valibot.literal("rewrite"),
468
+ valibot.literal("remove"),
469
+ valibot.boolean()
470
+ ]);
471
+ const TypescriptSchema = valibot.object({
472
+ jsxPragma: valibot.optional(valibot.string()),
473
+ jsxPragmaFrag: valibot.optional(valibot.string()),
474
+ onlyRemoveTypeImports: valibot.optional(valibot.boolean()),
475
+ allowNamespaces: valibot.optional(valibot.boolean()),
476
+ allowDeclareFields: valibot.optional(valibot.boolean()),
477
+ declaration: valibot.optional(valibot.object({
478
+ stripInternal: valibot.optional(valibot.boolean()),
479
+ sourcemap: valibot.optional(valibot.boolean())
480
+ })),
481
+ rewriteImportExtensions: valibot.optional(RewriteImportExtensionsSchema)
482
+ });
483
+ const AssumptionsSchema = valibot.object({
484
+ ignoreFunctionLength: valibot.optional(valibot.boolean()),
485
+ noDocumentAll: valibot.optional(valibot.boolean()),
486
+ objectRestNoSymbols: valibot.optional(valibot.boolean()),
487
+ pureGetters: valibot.optional(valibot.boolean()),
488
+ setPublicClassFields: valibot.optional(valibot.boolean())
489
+ });
490
+ const TransformOptionsSchema = valibot.object({
491
+ assumptions: valibot.optional(AssumptionsSchema),
492
+ typescript: valibot.optional(TypescriptSchema),
493
+ helpers: valibot.optional(HelpersSchema),
494
+ decorators: valibot.optional(DecoratorOptionSchema)
495
+ });
460
496
  const WatchOptionsSchema = valibot.strictObject({
461
497
  chokidar: valibot.optional(valibot.never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
462
498
  exclude: valibot.optional(valibot.union([StringOrRegExpSchema, valibot.array(StringOrRegExpSchema)])),
@@ -522,7 +558,14 @@ const InputOptionsSchema = valibot.strictObject({
522
558
  define: valibot.pipe(valibot.optional(valibot.record(valibot.string(), valibot.string())), valibot.description("Define global variables")),
523
559
  inject: valibot.optional(valibot.record(valibot.string(), valibot.union([valibot.string(), valibot.tuple([valibot.string(), valibot.string()])]))),
524
560
  profilerNames: valibot.optional(valibot.boolean()),
525
- jsx: valibot.optional(valibot.union([valibot.boolean(), JsxOptionsSchema])),
561
+ jsx: valibot.optional(valibot.union([
562
+ valibot.boolean(),
563
+ JsxOptionsSchema,
564
+ valibot.string("react"),
565
+ valibot.string("react-jsx"),
566
+ valibot.string("preserve")
567
+ ])),
568
+ transform: valibot.optional(TransformOptionsSchema),
526
569
  watch: valibot.optional(valibot.union([WatchOptionsSchema, valibot.literal(false)])),
527
570
  dropLabels: valibot.pipe(valibot.optional(valibot.array(valibot.string())), valibot.description("Remove labeled statements with these label names")),
528
571
  checks: valibot.optional(ChecksOptionsSchema),
@@ -547,7 +590,7 @@ const InputCliOptionsSchema = valibot.omit(valibot.strictObject({
547
590
  "profilerNames",
548
591
  "watch"
549
592
  ]);
550
- var ESTarget = function(ESTarget$1) {
593
+ var ESTarget = /* @__PURE__ */ function(ESTarget$1) {
551
594
  ESTarget$1["ES6"] = "es6";
552
595
  ESTarget$1["ES2015"] = "es2015";
553
596
  ESTarget$1["ES2016"] = "es2016";
@@ -1995,6 +2038,7 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normali
1995
2038
  },
1996
2039
  profilerNames: inputOptions?.profilerNames,
1997
2040
  jsx: bindingifyJsx(inputOptions.jsx),
2041
+ transform: inputOptions.transform,
1998
2042
  watch: bindingifyWatch(inputOptions.watch),
1999
2043
  dropLabels: inputOptions.dropLabels,
2000
2044
  keepNames: inputOptions.keepNames,
@@ -2077,30 +2121,34 @@ function bindingifyInput(input) {
2077
2121
  if (input === void 0) return [];
2078
2122
  if (typeof input === "string") return [{ import: input }];
2079
2123
  if (Array.isArray(input)) return input.map((src) => ({ import: src }));
2080
- return Object.entries(input).map((value) => {
2124
+ return Object.entries(input).map(([name, import_path]) => {
2081
2125
  return {
2082
- name: value[0],
2083
- import: value[1]
2126
+ name,
2127
+ import: import_path
2084
2128
  };
2085
2129
  });
2086
2130
  }
2087
2131
  function bindingifyJsx(input) {
2088
- if (input === false) return { type: "Disable" };
2089
- if (input) {
2090
- if (input.mode === "preserve") return { type: "Preserve" };
2091
- const mode = input.mode ?? "automatic";
2092
- return {
2093
- type: "Enable",
2094
- field0: {
2095
- runtime: mode,
2096
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
2097
- pragma: input.factory,
2098
- pragmaFrag: input.fragment,
2099
- development: input.development,
2100
- refresh: input.refresh
2101
- }
2102
- };
2132
+ switch (input) {
2133
+ case false: return { type: "Disable" };
2134
+ case "react": return { type: "React" };
2135
+ case "react-jsx": return { type: "ReactJsx" };
2136
+ case "preserve": return { type: "Preserve" };
2137
+ case void 0: return void 0;
2103
2138
  }
2139
+ if (input.mode === "preserve") return { type: "Preserve" };
2140
+ const mode = input.mode ?? "automatic";
2141
+ return {
2142
+ type: "Enable",
2143
+ field0: {
2144
+ runtime: mode,
2145
+ importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0,
2146
+ pragma: input.factory,
2147
+ pragmaFrag: input.fragment,
2148
+ development: input.development,
2149
+ refresh: input.refresh
2150
+ }
2151
+ };
2104
2152
  }
2105
2153
  function bindingifyWatch(watch$1) {
2106
2154
  if (watch$1) return {
@@ -2741,7 +2789,7 @@ const watch = (input) => {
2741
2789
 
2742
2790
  //#endregion
2743
2791
  //#region package.json
2744
- var version = "1.0.0-beta.3-commit.d298c0b";
2792
+ var version = "1.0.0-beta.3-commit.73fa972";
2745
2793
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2746
2794
 
2747
2795
  //#endregion
@@ -375,6 +375,7 @@ export interface BindingInputOptions {
375
375
  experimental?: BindingExperimentalOptions
376
376
  profilerNames?: boolean
377
377
  jsx?: BindingJsx
378
+ transform?: TransformOptions
378
379
  watch?: BindingWatchOption
379
380
  keepNames?: boolean
380
381
  checks?: BindingChecksOptions
@@ -405,9 +406,12 @@ export interface BindingJsWatchChangeEvent {
405
406
  event: string
406
407
  }
407
408
 
409
+ /** TODO: support `preserve-react` mode */
408
410
  export type BindingJsx =
409
411
  | { type: 'Disable' }
410
412
  | { type: 'Preserve' }
413
+ | { type: 'React' }
414
+ | { type: 'ReactJsx' }
411
415
  | { type: 'Enable', field0: JsxOptions }
412
416
 
413
417
  export interface BindingLog {
@@ -823,6 +827,14 @@ export interface ExtensionAliasItem {
823
827
  replacements: Array<string>
824
828
  }
825
829
 
830
+ /**
831
+ * Get offset within a `Uint8Array` which is aligned on 4 GiB.
832
+ *
833
+ * Does not check that the offset is within bounds of `buffer`.
834
+ * To ensure it always is, provide a `Uint8Array` of at least 4 GiB size.
835
+ */
836
+ export declare function getBufferOffset(buffer: Uint8Array): number
837
+
826
838
  export type HelperMode = /**
827
839
  * Runtime mode (default): Helper functions are imported from a runtime package.
828
840
  *
@@ -1010,6 +1022,59 @@ export interface JsxOptions {
1010
1022
  refresh?: boolean | ReactRefreshOptions
1011
1023
  }
1012
1024
 
1025
+ /**
1026
+ * Transform JavaScript code to a Vite Node runnable module.
1027
+ *
1028
+ * @param filename The name of the file being transformed.
1029
+ * @param sourceText the source code itself
1030
+ * @param options The options for the transformation. See {@link
1031
+ * ModuleRunnerTransformOptions} for more information.
1032
+ *
1033
+ * @returns an object containing the transformed code, source maps, and any
1034
+ * errors that occurred during parsing or transformation.
1035
+ *
1036
+ * @deprecated Only works for Vite.
1037
+ */
1038
+ export declare function moduleRunnerTransform(filename: string, sourceText: string, options?: ModuleRunnerTransformOptions | undefined | null): ModuleRunnerTransformResult
1039
+
1040
+ export interface ModuleRunnerTransformOptions {
1041
+ /**
1042
+ * Enable source map generation.
1043
+ *
1044
+ * When `true`, the `sourceMap` field of transform result objects will be populated.
1045
+ *
1046
+ * @default false
1047
+ *
1048
+ * @see {@link SourceMap}
1049
+ */
1050
+ sourcemap?: boolean
1051
+ }
1052
+
1053
+ export interface ModuleRunnerTransformResult {
1054
+ /**
1055
+ * The transformed code.
1056
+ *
1057
+ * If parsing failed, this will be an empty string.
1058
+ */
1059
+ code: string
1060
+ /**
1061
+ * The source map for the transformed code.
1062
+ *
1063
+ * This will be set if {@link TransformOptions#sourcemap} is `true`.
1064
+ */
1065
+ map?: SourceMap
1066
+ deps: Array<string>
1067
+ dynamicDeps: Array<string>
1068
+ /**
1069
+ * Parse and transformation errors.
1070
+ *
1071
+ * Oxc's parser recovers from common syntax errors, meaning that
1072
+ * transformed code may still be available even if there are errors in this
1073
+ * list.
1074
+ */
1075
+ errors: Array<OxcError>
1076
+ }
1077
+
1013
1078
  export interface OxcError {
1014
1079
  severity: Severity
1015
1080
  message: string
@@ -1028,6 +1093,14 @@ export interface ParserOptions {
1028
1093
  sourceType?: 'script' | 'module' | 'unambiguous' | undefined
1029
1094
  /** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
1030
1095
  lang?: 'js' | 'jsx' | 'ts' | 'tsx'
1096
+ /**
1097
+ * Return an AST which includes TypeScript-related properties, or excludes them.
1098
+ *
1099
+ * `'js'` is default for JS / JSX files.
1100
+ * `'ts'` is default for TS / TSX files.
1101
+ * The type of the file is determined from `lang` option, or extension of provided `filename`.
1102
+ */
1103
+ astType?: 'js' | 'ts'
1031
1104
  /**
1032
1105
  * Emit `ParenthesizedExpression` in AST.
1033
1106
  *
@@ -1051,6 +1124,34 @@ export interface ParserOptions {
1051
1124
  /** Parse synchronously. */
1052
1125
  export declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): ParseResult
1053
1126
 
1127
+ /**
1128
+ * Parses AST into provided `Uint8Array` buffer.
1129
+ *
1130
+ * Source text must be written into the start of the buffer, and its length (in UTF-8 bytes)
1131
+ * provided as `source_len`.
1132
+ *
1133
+ * This function will parse the source, and write the AST into the buffer, starting at the end.
1134
+ *
1135
+ * It also writes to the very end of the buffer the offset of `Program` within the buffer.
1136
+ *
1137
+ * Caller can deserialize data from the buffer on JS side.
1138
+ *
1139
+ * # SAFETY
1140
+ *
1141
+ * Caller must ensure:
1142
+ * * Source text is written into start of the buffer.
1143
+ * * Source text's UTF-8 byte length is `source_len`.
1144
+ * * The 1st `source_len` bytes of the buffer comprises a valid UTF-8 string.
1145
+ *
1146
+ * If source text is originally a JS string on JS side, and converted to a buffer with
1147
+ * `Buffer.from(str)` or `new TextEncoder().encode(str)`, this guarantees it's valid UTF-8.
1148
+ *
1149
+ * # Panics
1150
+ *
1151
+ * Panics if source text is too long, or AST takes more memory than is available in the buffer.
1152
+ */
1153
+ export declare function parseSyncRaw(filename: string, buffer: Uint8Array, sourceLen: number, options?: ParserOptions | undefined | null): void
1154
+
1054
1155
  export interface PreRenderedChunk {
1055
1156
  name: string
1056
1157
  isEntry: boolean
@@ -1060,6 +1161,9 @@ export interface PreRenderedChunk {
1060
1161
  exports: Array<string>
1061
1162
  }
1062
1163
 
1164
+ /** Returns `true` if raw transfer is supported on this platform. */
1165
+ export declare function rawTransferSupported(): boolean
1166
+
1063
1167
  export interface ReactRefreshOptions {
1064
1168
  /**
1065
1169
  * Specify the identifier of the refresh registration variable.
@@ -1,3 +1,5 @@
1
1
  import type { ConfigExport } from '../types/config-export';
2
2
  export declare function loadTsConfig(configFile: string): Promise<ConfigExport>;
3
+ export declare function isFilePathESM(filePath: string): boolean;
4
+ export declare function findNearestPackageData(basedir: string): any | null;
3
5
  export declare function loadConfig(configPath: string): Promise<ConfigExport>;
@@ -2,7 +2,9 @@ import type { RolldownPluginOption } from '../plugin';
2
2
  import type { LogLevel, LogLevelOption, LogOrStringHandler, RollupLog, RollupLogWithString } from '../log/logging';
3
3
  import type { NullValue, StringOrRegExp } from '../types/utils';
4
4
  import type { TreeshakingOptions } from '../types/module-side-effects';
5
+ import { TransformOptions } from '../binding';
5
6
  export type InputOption = string | string[] | Record<string, string>;
7
+ type OxcTransformOption = Omit<TransformOptions, 'sourceType' | 'lang' | 'cwd' | 'sourcemap' | 'jsx' | 'define' | 'inject' | 'target'>;
6
8
  export type ExternalOption = StringOrRegExp | StringOrRegExp[] | ((id: string, parentId: string | undefined, isResolved: boolean) => NullValue<boolean>);
7
9
  export type ModuleTypes = Record<string, 'js' | 'jsx' | 'ts' | 'tsx' | 'json' | 'text' | 'base64' | 'dataurl' | 'binary' | 'empty' | 'css'>;
8
10
  export interface JsxOptions {
@@ -156,13 +158,15 @@ export interface InputOptions {
156
158
  inject?: Record<string, string | [string, string]>;
157
159
  profilerNames?: boolean;
158
160
  /**
159
- * The `false` is disabled jsx parser, it will give you a syntax error if you use jsx syntax
160
- * The `mode: preserve` is disabled jsx transformer, it perverse original jsx syntax in the output.
161
- * The `mode: classic` is enabled jsx `classic` transformer.
162
- * The `mode: automatic` is enabled jsx `automatic` transformer.
163
- * @default mode = 'automatic'
161
+ * - `false` disables the JSX parser, resulting in a syntax error if JSX syntax is used.
162
+ * - `"preserve"` disables the JSX transformer, preserving the original JSX syntax in the output.
163
+ * - `"react"` enables the `classic` JSX transformer.
164
+ * - `"react-jsx"` enables the `automatic` JSX transformer.
165
+ *
166
+ * @default mode = "automatic"
164
167
  */
165
- jsx?: false | JsxOptions;
168
+ jsx?: false | 'react' | 'react-jsx' | 'preserve' | JsxOptions;
169
+ transform?: OxcTransformOption;
166
170
  watch?: WatchOptions | false;
167
171
  dropLabels?: string[];
168
172
  keepNames?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown",
3
- "version": "1.0.0-beta.3-commit.d298c0b",
3
+ "version": "1.0.0-beta.3-commit.73fa972",
4
4
  "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
5
5
  "homepage": "https://rolldown.rs/",
6
6
  "repository": {
@@ -84,12 +84,12 @@
84
84
  "dtsHeader": "type MaybePromise<T> = T | Promise<T>\ntype Nullable<T> = T | null | undefined\ntype VoidNullable<T = void> = T | null | undefined | void\nexport type BindingStringOrRegex = string | RegExp\n\n"
85
85
  },
86
86
  "dependencies": {
87
- "@oxc-project/types": "0.54.0",
87
+ "@oxc-project/types": "0.56.0",
88
88
  "@valibot/to-json-schema": "1.0.0-rc.0",
89
89
  "valibot": "1.0.0-rc.3"
90
90
  },
91
91
  "peerDependencies": {
92
- "@oxc-project/runtime": "0.54.0"
92
+ "@oxc-project/runtime": "0.56.0"
93
93
  },
94
94
  "peerDependenciesMeta": {
95
95
  "@oxc-project/runtime": {
@@ -122,26 +122,26 @@
122
122
  "unbuild": "^3.0.0",
123
123
  "why-is-node-running": "^3.0.0",
124
124
  "@rolldown/testing": "0.0.1",
125
- "rolldown": "1.0.0-beta.3-commit.d298c0b"
125
+ "rolldown": "1.0.0-beta.3-commit.73fa972"
126
126
  },
127
127
  "optionalDependencies": {
128
- "@rolldown/binding-darwin-arm64": "1.0.0-beta.3-commit.d298c0b",
129
- "@rolldown/binding-linux-arm-gnueabihf": "1.0.0-beta.3-commit.d298c0b",
130
- "@rolldown/binding-linux-arm64-gnu": "1.0.0-beta.3-commit.d298c0b",
131
- "@rolldown/binding-darwin-x64": "1.0.0-beta.3-commit.d298c0b",
132
- "@rolldown/binding-freebsd-x64": "1.0.0-beta.3-commit.d298c0b",
133
- "@rolldown/binding-linux-arm64-musl": "1.0.0-beta.3-commit.d298c0b",
134
- "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.3-commit.d298c0b",
135
- "@rolldown/binding-linux-x64-musl": "1.0.0-beta.3-commit.d298c0b",
136
- "@rolldown/binding-wasm32-wasi": "1.0.0-beta.3-commit.d298c0b",
137
- "@rolldown/binding-win32-arm64-msvc": "1.0.0-beta.3-commit.d298c0b",
138
- "@rolldown/binding-win32-ia32-msvc": "1.0.0-beta.3-commit.d298c0b",
139
- "@rolldown/binding-win32-x64-msvc": "1.0.0-beta.3-commit.d298c0b"
128
+ "@rolldown/binding-darwin-arm64": "1.0.0-beta.3-commit.73fa972",
129
+ "@rolldown/binding-darwin-x64": "1.0.0-beta.3-commit.73fa972",
130
+ "@rolldown/binding-freebsd-x64": "1.0.0-beta.3-commit.73fa972",
131
+ "@rolldown/binding-linux-arm-gnueabihf": "1.0.0-beta.3-commit.73fa972",
132
+ "@rolldown/binding-linux-arm64-gnu": "1.0.0-beta.3-commit.73fa972",
133
+ "@rolldown/binding-linux-x64-gnu": "1.0.0-beta.3-commit.73fa972",
134
+ "@rolldown/binding-linux-x64-musl": "1.0.0-beta.3-commit.73fa972",
135
+ "@rolldown/binding-linux-arm64-musl": "1.0.0-beta.3-commit.73fa972",
136
+ "@rolldown/binding-wasm32-wasi": "1.0.0-beta.3-commit.73fa972",
137
+ "@rolldown/binding-win32-arm64-msvc": "1.0.0-beta.3-commit.73fa972",
138
+ "@rolldown/binding-win32-x64-msvc": "1.0.0-beta.3-commit.73fa972",
139
+ "@rolldown/binding-win32-ia32-msvc": "1.0.0-beta.3-commit.73fa972"
140
140
  },
141
141
  "scripts": {
142
142
  "# Scrips for binding #": "_",
143
143
  "artifacts": "napi artifacts --cwd ./src --package-json-path ../package.json -o=../artifacts --npm-dir ../npm",
144
- "build-binding": "napi build -o=./src --manifest-path ../../crates/rolldown_binding/Cargo.toml --platform -p rolldown_binding --js binding.js --dts binding.d.ts --no-const-enum --no-dts-cache",
144
+ "build-binding": "node ./build-binding.js",
145
145
  "build-binding:release": "pnpm build-binding --release",
146
146
  "build-binding:wasi": "pnpm build-binding --target wasm32-wasip1-threads",
147
147
  "build-binding:wasi:release": "pnpm build-binding --profile release-wasi --target wasm32-wasip1-threads",
@@ -149,8 +149,9 @@
149
149
  "bak_build-node": "unbuild",
150
150
  "build-node": "tsx ./build.ts",
151
151
  "build-types": "tsc -p ./tsconfig.json",
152
- "build-native:debug": "run-s build-binding build-types build-node build-types-check",
153
- "build-native:release": "run-s build-binding:release build-types build-node build-types-check",
152
+ "build-js-glue": "run-s build-types build-node build-types-check",
153
+ "build-native:debug": "run-s build-binding build-js-glue",
154
+ "build-native:release": "run-s build-binding:release build-js-glue",
154
155
  "build-wasi:debug": "run-s build-binding build-binding:wasi build-node",
155
156
  "build-wasi:release": "run-s build-binding build-binding:wasi:release build-node",
156
157
  "build-types-check": "tsc -p ./tsconfig.check.json",