rolldown 0.15.0-commit.ac58858 → 0.15.0-commit.f0c42f8

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,15 +1,16 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-BFvIen8E.cjs');
3
- const require_src = require('../shared/src-Bs7g4_us.cjs');
3
+ const require_src = require('../shared/src-DO0qfKnj.cjs');
4
4
  const require_consola_36c0034f = require('../shared/consola_36c0034f-B7L-radJ.cjs');
5
+ const node_fs = require_chunk.__toESM(require("node:fs"));
5
6
  const zod = require_chunk.__toESM(require("zod"));
6
7
  const node_path = require_chunk.__toESM(require("node:path"));
7
8
  const node_process = require_chunk.__toESM(require("node:process"));
8
9
  const node_perf_hooks = require_chunk.__toESM(require("node:perf_hooks"));
9
10
  const tty = require_chunk.__toESM(require("tty"));
10
- const node_url = require_chunk.__toESM(require("node:url"));
11
11
  const node_util = require_chunk.__toESM(require("node:util"));
12
12
  const node_tty = require_chunk.__toESM(require("node:tty"));
13
+ const node_url = require_chunk.__toESM(require("node:url"));
13
14
 
14
15
  //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
15
16
  const signals = [];
@@ -260,7 +261,7 @@ const colors = {
260
261
  };
261
262
 
262
263
  //#endregion
263
- //#region src/cli/utils.ts
264
+ //#region src/cli/logger.ts
264
265
  const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : require_consola_36c0034f.createConsola({ formatOptions: { date: false } });
265
266
  function createTestingLogger() {
266
267
  const types = [
@@ -283,35 +284,82 @@ function createTestingLogger() {
283
284
  for (const type of types) ret[type] = console.log;
284
285
  return ret;
285
286
  }
286
- async function ensureConfig(configPath) {
287
- const fileUrl = (0, node_url.pathToFileURL)(configPath).toString();
288
- let configExports;
287
+
288
+ //#endregion
289
+ //#region src/cli/load-config.ts
290
+ async function loadTsConfig(configFile) {
291
+ const file = await bundleTsConfig(configFile);
289
292
  try {
290
- configExports = await import(fileUrl);
291
- } catch (err) {
292
- let errorMessage = "Error happened while loading config.";
293
- if (!isSupportedFormat(configPath)) errorMessage += ` Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${node_path.default.extname(configPath)}\``;
294
- throw new Error(errorMessage, { cause: err });
293
+ return (await import((0, node_url.pathToFileURL)(file).href)).default;
294
+ } finally {
295
+ node_fs.default.unlink(file, () => {});
295
296
  }
296
- return configExports.default;
297
297
  }
298
- const SUPPORTED_CONFIG_FORMATS = [
298
+ async function bundleTsConfig(configFile) {
299
+ const dirnameVarName = "injected_original_dirname";
300
+ const filenameVarName = "injected_original_filename";
301
+ const importMetaUrlVarName = "injected_original_import_meta_url";
302
+ const bundle = await require_src.rolldown({
303
+ input: configFile,
304
+ platform: "node",
305
+ resolve: { mainFields: ["main"] },
306
+ define: {
307
+ __dirname: dirnameVarName,
308
+ __filename: filenameVarName,
309
+ "import.meta.url": importMetaUrlVarName,
310
+ "import.meta.dirname": dirnameVarName,
311
+ "import.meta.filename": filenameVarName
312
+ },
313
+ treeshake: false,
314
+ external: [/^[\w@][^:]/],
315
+ plugins: [{
316
+ name: "inject-file-scope-variables",
317
+ transform: {
318
+ filter: { id: /\.[cm]?[jt]s$/ },
319
+ async handler(code, id) {
320
+ const injectValues = `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};`;
321
+ return {
322
+ code: injectValues + code,
323
+ map: null
324
+ };
325
+ }
326
+ }
327
+ }]
328
+ });
329
+ const result = await bundle.write({
330
+ dir: node_path.default.dirname(configFile),
331
+ format: "esm",
332
+ sourcemap: "inline",
333
+ entryFileNames: "rolldown.config.[hash].js"
334
+ });
335
+ return result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
336
+ }
337
+ const SUPPORTED_JS_CONFIG_FORMATS = [
299
338
  ".js",
300
339
  ".mjs",
301
340
  ".cjs"
302
341
  ];
303
- /**
304
- * Check whether the configuration file is supported
305
- */
306
- function isSupportedFormat(configPath) {
342
+ const SUPPORTED_TS_CONFIG_FORMATS = [
343
+ ".ts",
344
+ ".mts",
345
+ ".cts"
346
+ ];
347
+ const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
348
+ async function loadConfig(configPath) {
307
349
  const ext = node_path.default.extname(configPath);
308
- return SUPPORTED_CONFIG_FORMATS.includes(ext);
350
+ try {
351
+ if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import((0, node_url.pathToFileURL)(configPath).href)).default;
352
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(configPath);
353
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
354
+ } catch (err) {
355
+ throw new Error("Error happened while loading config.", { cause: err });
356
+ }
309
357
  }
310
358
 
311
359
  //#endregion
312
360
  //#region src/cli/commands/bundle.ts
313
361
  async function bundleWithConfig(configPath, cliOptions) {
314
- const config = await ensureConfig(configPath);
362
+ const config = await loadConfig(configPath);
315
363
  if (!config) {
316
364
  logger.error(`No configuration found at ${config}`);
317
365
  process.exit(1);
@@ -339,7 +387,7 @@ async function bundleWithCliOptions(cliOptions) {
339
387
  }
340
388
  for (const file of outputs) {
341
389
  if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
342
- logger.log(file.type === "asset" ? file.source : file.code);
390
+ console.log(file.type === "asset" ? file.source : file.code);
343
391
  }
344
392
  } finally {
345
393
  await build.close();
@@ -348,7 +396,11 @@ async function bundleWithCliOptions(cliOptions) {
348
396
  async function watchInner(options$1, cliOptions) {
349
397
  const watcher = await require_src.watch({
350
398
  ...options$1,
351
- ...cliOptions.input
399
+ ...cliOptions.input,
400
+ output: {
401
+ ...options$1?.output,
402
+ ...cliOptions.output
403
+ }
352
404
  });
353
405
  onExit((code) => {
354
406
  Promise.resolve(watcher.close()).finally(() => {
@@ -450,9 +502,9 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
450
502
  }
451
503
  }
452
504
  }
453
- function withTrailingSlash(path$1) {
454
- if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
455
- return path$1;
505
+ function withTrailingSlash(path$2) {
506
+ if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
507
+ return path$2;
456
508
  }
457
509
  function ms(duration) {
458
510
  return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
@@ -1718,8 +1770,8 @@ else base[key] = value;
1718
1770
  }
1719
1771
  return base;
1720
1772
  }
1721
- function setNestedProperty(obj, path$1, value) {
1722
- const keys = path$1.split(".");
1773
+ function setNestedProperty(obj, path$2, value) {
1774
+ const keys = path$2.split(".");
1723
1775
  let current = obj;
1724
1776
  for (let i = 0; i < keys.length - 1; i++) {
1725
1777
  if (!current[keys[i]]) current[keys[i]] = {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-BFvIen8E.cjs');
3
- const require_src = require('../shared/src-Bs7g4_us.cjs');
3
+ const require_src = require('../shared/src-DO0qfKnj.cjs');
4
4
  const node_url = require_chunk.__toESM(require("node:url"));
5
5
 
6
6
  //#region src/plugin/parallel-plugin.ts
@@ -1,4 +1,4 @@
1
- const require_src = require('../shared/src-Bs7g4_us.cjs');
1
+ const require_src = require('../shared/src-DO0qfKnj.cjs');
2
2
 
3
3
  exports.VERSION = require_src.VERSION
4
4
  exports.build = require_src.build
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const require_chunk = require('../shared/chunk-BFvIen8E.cjs');
3
- const require_src = require('../shared/src-Bs7g4_us.cjs');
3
+ const require_src = require('../shared/src-DO0qfKnj.cjs');
4
4
  const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
5
5
 
6
6
  //#region src/parallel-plugin-worker.ts
package/dist/esm/cli.mjs CHANGED
@@ -1,12 +1,13 @@
1
- import { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, arraify, description, rolldown, version, watch } from "../shared/src-C-NQjnqV.mjs";
1
+ import { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, arraify, description, rolldown, version, watch } from "../shared/src-DF6eJFya.mjs";
2
2
  import { createConsola } from "../shared/consola_36c0034f-D9ce-831.mjs";
3
+ import fs from "node:fs";
3
4
  import { ZodFirstPartyTypeKind, z } from "zod";
4
- import nodePath, { default as path } from "node:path";
5
+ import path, { default as path$1 } from "node:path";
5
6
  import process$1, { env } from "node:process";
6
7
  import { performance } from "node:perf_hooks";
7
8
  import * as tty from "tty";
8
- import { pathToFileURL } from "node:url";
9
9
  import { parseArgs } from "node:util";
10
+ import { pathToFileURL } from "node:url";
10
11
 
11
12
  //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
12
13
  const signals = [];
@@ -257,7 +258,7 @@ const colors = {
257
258
  };
258
259
 
259
260
  //#endregion
260
- //#region src/cli/utils.ts
261
+ //#region src/cli/logger.ts
261
262
  const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
262
263
  function createTestingLogger() {
263
264
  const types = [
@@ -280,35 +281,82 @@ function createTestingLogger() {
280
281
  for (const type of types) ret[type] = console.log;
281
282
  return ret;
282
283
  }
283
- async function ensureConfig(configPath) {
284
- const fileUrl = pathToFileURL(configPath).toString();
285
- let configExports;
284
+
285
+ //#endregion
286
+ //#region src/cli/load-config.ts
287
+ async function loadTsConfig(configFile) {
288
+ const file = await bundleTsConfig(configFile);
286
289
  try {
287
- configExports = await import(fileUrl);
288
- } catch (err) {
289
- let errorMessage = "Error happened while loading config.";
290
- if (!isSupportedFormat(configPath)) errorMessage += ` Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${nodePath.extname(configPath)}\``;
291
- throw new Error(errorMessage, { cause: err });
290
+ return (await import(pathToFileURL(file).href)).default;
291
+ } finally {
292
+ fs.unlink(file, () => {});
292
293
  }
293
- return configExports.default;
294
294
  }
295
- const SUPPORTED_CONFIG_FORMATS = [
295
+ async function bundleTsConfig(configFile) {
296
+ const dirnameVarName = "injected_original_dirname";
297
+ const filenameVarName = "injected_original_filename";
298
+ const importMetaUrlVarName = "injected_original_import_meta_url";
299
+ const bundle = await rolldown({
300
+ input: configFile,
301
+ platform: "node",
302
+ resolve: { mainFields: ["main"] },
303
+ define: {
304
+ __dirname: dirnameVarName,
305
+ __filename: filenameVarName,
306
+ "import.meta.url": importMetaUrlVarName,
307
+ "import.meta.dirname": dirnameVarName,
308
+ "import.meta.filename": filenameVarName
309
+ },
310
+ treeshake: false,
311
+ external: [/^[\w@][^:]/],
312
+ plugins: [{
313
+ name: "inject-file-scope-variables",
314
+ transform: {
315
+ filter: { id: /\.[cm]?[jt]s$/ },
316
+ async handler(code, id) {
317
+ const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path$1.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
318
+ return {
319
+ code: injectValues + code,
320
+ map: null
321
+ };
322
+ }
323
+ }
324
+ }]
325
+ });
326
+ const result = await bundle.write({
327
+ dir: path$1.dirname(configFile),
328
+ format: "esm",
329
+ sourcemap: "inline",
330
+ entryFileNames: "rolldown.config.[hash].js"
331
+ });
332
+ return result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
333
+ }
334
+ const SUPPORTED_JS_CONFIG_FORMATS = [
296
335
  ".js",
297
336
  ".mjs",
298
337
  ".cjs"
299
338
  ];
300
- /**
301
- * Check whether the configuration file is supported
302
- */
303
- function isSupportedFormat(configPath) {
304
- const ext = nodePath.extname(configPath);
305
- return SUPPORTED_CONFIG_FORMATS.includes(ext);
339
+ const SUPPORTED_TS_CONFIG_FORMATS = [
340
+ ".ts",
341
+ ".mts",
342
+ ".cts"
343
+ ];
344
+ const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
345
+ async function loadConfig(configPath) {
346
+ const ext = path$1.extname(configPath);
347
+ try {
348
+ if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
349
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(configPath);
350
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
351
+ } catch (err) {
352
+ throw new Error("Error happened while loading config.", { cause: err });
353
+ }
306
354
  }
307
355
 
308
356
  //#endregion
309
357
  //#region src/cli/commands/bundle.ts
310
358
  async function bundleWithConfig(configPath, cliOptions) {
311
- const config = await ensureConfig(configPath);
359
+ const config = await loadConfig(configPath);
312
360
  if (!config) {
313
361
  logger.error(`No configuration found at ${config}`);
314
362
  process.exit(1);
@@ -336,7 +384,7 @@ async function bundleWithCliOptions(cliOptions) {
336
384
  }
337
385
  for (const file of outputs) {
338
386
  if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
339
- logger.log(file.type === "asset" ? file.source : file.code);
387
+ console.log(file.type === "asset" ? file.source : file.code);
340
388
  }
341
389
  } finally {
342
390
  await build.close();
@@ -345,7 +393,11 @@ async function bundleWithCliOptions(cliOptions) {
345
393
  async function watchInner(options$1, cliOptions) {
346
394
  const watcher = await watch({
347
395
  ...options$1,
348
- ...cliOptions.input
396
+ ...cliOptions.input,
397
+ output: {
398
+ ...options$1?.output,
399
+ ...cliOptions.output
400
+ }
349
401
  });
350
402
  onExit((code) => {
351
403
  Promise.resolve(watcher.close()).finally(() => {
@@ -447,9 +499,9 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
447
499
  }
448
500
  }
449
501
  }
450
- function withTrailingSlash(path$1) {
451
- if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
452
- return path$1;
502
+ function withTrailingSlash(path$2) {
503
+ if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
504
+ return path$2;
453
505
  }
454
506
  function ms(duration) {
455
507
  return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
@@ -1715,8 +1767,8 @@ else base[key] = value;
1715
1767
  }
1716
1768
  return base;
1717
1769
  }
1718
- function setNestedProperty(obj, path$1, value) {
1719
- const keys = path$1.split(".");
1770
+ function setNestedProperty(obj, path$2, value) {
1771
+ const keys = path$2.split(".");
1720
1772
  let current = obj;
1721
1773
  for (let i = 0; i < keys.length - 1; i++) {
1722
1774
  if (!current[keys[i]]) current[keys[i]] = {};
@@ -1,4 +1,4 @@
1
- import { BuiltinPlugin, __toESM, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-C-NQjnqV.mjs";
1
+ import { BuiltinPlugin, __toESM, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-DF6eJFya.mjs";
2
2
  import { pathToFileURL } from "node:url";
3
3
 
4
4
  //#region src/plugin/parallel-plugin.ts
@@ -1,3 +1,3 @@
1
- import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-C-NQjnqV.mjs";
1
+ import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-DF6eJFya.mjs";
2
2
 
3
3
  export { VERSION, build, defineConfig, rolldown, watch };
@@ -1,4 +1,4 @@
1
- import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/src-C-NQjnqV.mjs";
1
+ import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/src-DF6eJFya.mjs";
2
2
  import { parentPort, workerData } from "node:worker_threads";
3
3
 
4
4
  //#region src/parallel-plugin-worker.ts