rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.2-commit.f069c5d

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 (114) hide show
  1. package/dist/cjs/cli.cjs +981 -25
  2. package/dist/cjs/experimental-index.cjs +2 -2
  3. package/dist/cjs/index.cjs +2 -2
  4. package/dist/cjs/parallel-plugin-worker.cjs +2 -2
  5. package/dist/cjs/parse-ast-index.cjs +1 -1
  6. package/dist/esm/cli.mjs +981 -26
  7. package/dist/esm/experimental-index.mjs +2 -2
  8. package/dist/esm/index.mjs +2 -2
  9. package/dist/esm/parallel-plugin-worker.mjs +2 -2
  10. package/dist/esm/parse-ast-index.mjs +1 -1
  11. package/dist/shared/{binding-Bl7VQy7c.mjs → binding-l7VLSKnB.mjs} +3 -3
  12. package/dist/shared/{binding-fhgdIkpS.cjs → binding-orkvONpS.cjs} +3 -3
  13. package/dist/shared/prompt-B7tq3GL9.cjs +854 -0
  14. package/dist/shared/prompt-Nfm4Xz36.mjs +851 -0
  15. package/dist/shared/{src-lBcHSsjm.cjs → src-BRzD1T3r.cjs} +12 -6
  16. package/dist/shared/{src-CPCP99Z9.mjs → src-Cmr3pg11.mjs} +12 -6
  17. package/dist/types/api/build.js +22 -0
  18. package/dist/types/api/experimental.js +13 -0
  19. package/dist/types/api/rolldown/index.js +7 -0
  20. package/dist/types/api/rolldown/rolldown-build.js +43 -0
  21. package/dist/types/api/watch/index.js +8 -0
  22. package/dist/types/api/watch/watch-emitter.js +69 -0
  23. package/dist/types/api/watch/watcher.js +66 -0
  24. package/dist/types/binding.d.ts +40 -2
  25. package/dist/types/builtin-plugin/alias-plugin.js +4 -0
  26. package/dist/types/builtin-plugin/constructors.d.ts +2 -2
  27. package/dist/types/builtin-plugin/constructors.js +68 -0
  28. package/dist/types/builtin-plugin/replace-plugin.js +29 -0
  29. package/dist/types/builtin-plugin/transform-plugin.js +16 -0
  30. package/dist/types/builtin-plugin/utils.js +19 -0
  31. package/dist/types/cli/arguments/alias.js +63 -0
  32. package/dist/types/cli/arguments/index.js +127 -0
  33. package/dist/types/cli/arguments/normalize.js +48 -0
  34. package/dist/types/cli/arguments/utils.js +67 -0
  35. package/dist/types/cli/colors.js +17 -0
  36. package/dist/types/cli/commands/bundle.js +203 -0
  37. package/dist/types/cli/commands/help.js +88 -0
  38. package/dist/types/cli/index.js +27 -0
  39. package/dist/types/cli/load-config.js +95 -0
  40. package/dist/types/cli/logger.js +35 -0
  41. package/dist/types/constants/plugin-context.js +7 -0
  42. package/dist/types/constants/plugin.js +69 -0
  43. package/dist/types/experimental-index.js +9 -0
  44. package/dist/types/index.d.ts +2 -2
  45. package/dist/types/index.js +7 -0
  46. package/dist/types/log/logHandler.js +25 -0
  47. package/dist/types/log/logger.js +107 -0
  48. package/dist/types/log/logging.js +11 -0
  49. package/dist/types/log/logs.js +86 -0
  50. package/dist/types/options/input-options.d.ts +47 -2
  51. package/dist/types/options/input-options.js +1 -0
  52. package/dist/types/options/normalized-input-options.js +21 -0
  53. package/dist/types/options/normalized-output-options.js +99 -0
  54. package/dist/types/options/output-options.d.ts +6 -0
  55. package/dist/types/options/output-options.js +1 -0
  56. package/dist/types/options/watch-options.js +1 -0
  57. package/dist/types/parallel-plugin-worker.js +31 -0
  58. package/dist/types/parallel-plugin.js +1 -0
  59. package/dist/types/parse-ast-index.js +73 -0
  60. package/dist/types/plugin/bindingify-build-hooks.js +213 -0
  61. package/dist/types/plugin/bindingify-hook-filter.js +39 -0
  62. package/dist/types/plugin/bindingify-output-hooks.js +189 -0
  63. package/dist/types/plugin/bindingify-plugin-hook-meta.js +19 -0
  64. package/dist/types/plugin/bindingify-plugin.js +124 -0
  65. package/dist/types/plugin/bindingify-watch-hooks.js +29 -0
  66. package/dist/types/plugin/hook-filter.js +1 -0
  67. package/dist/types/plugin/index.js +1 -0
  68. package/dist/types/plugin/minimal-plugin-context.js +25 -0
  69. package/dist/types/plugin/parallel-plugin-implementation.js +3 -0
  70. package/dist/types/plugin/parallel-plugin.js +6 -0
  71. package/dist/types/plugin/plugin-context-data.js +55 -0
  72. package/dist/types/plugin/plugin-context.js +108 -0
  73. package/dist/types/plugin/plugin-driver.js +88 -0
  74. package/dist/types/plugin/transform-plugin-context.js +37 -0
  75. package/dist/types/types/assert.js +1 -0
  76. package/dist/types/types/config-export.js +1 -0
  77. package/dist/types/types/misc.js +1 -0
  78. package/dist/types/types/module-info.js +1 -0
  79. package/dist/types/types/module-side-effects.js +1 -0
  80. package/dist/types/types/output-bundle.js +1 -0
  81. package/dist/types/types/rolldown-options.js +1 -0
  82. package/dist/types/types/rolldown-output.js +1 -0
  83. package/dist/types/types/schema.js +1 -0
  84. package/dist/types/types/sourcemap.js +16 -0
  85. package/dist/types/types/utils.js +1 -0
  86. package/dist/types/utils/asset-source.js +8 -0
  87. package/dist/types/utils/async-flatten.js +7 -0
  88. package/dist/types/utils/bindingify-input-options.js +225 -0
  89. package/dist/types/utils/bindingify-output-options.js +92 -0
  90. package/dist/types/utils/code-frame.js +46 -0
  91. package/dist/types/utils/compose-js-plugins.js +400 -0
  92. package/dist/types/utils/create-bundler-option.js +53 -0
  93. package/dist/types/utils/create-bundler.js +15 -0
  94. package/dist/types/utils/define-config.js +3 -0
  95. package/dist/types/utils/error.js +65 -0
  96. package/dist/types/utils/initialize-parallel-plugins.js +54 -0
  97. package/dist/types/utils/misc.js +22 -0
  98. package/dist/types/utils/normalize-hook.js +21 -0
  99. package/dist/types/utils/normalize-plugin-option.js +35 -0
  100. package/dist/types/utils/normalize-string-or-regex.js +14 -0
  101. package/dist/types/utils/plugin/index.js +7 -0
  102. package/dist/types/utils/transform-module-info.js +19 -0
  103. package/dist/types/utils/transform-rendered-chunk.js +43 -0
  104. package/dist/types/utils/transform-rendered-module.js +10 -0
  105. package/dist/types/utils/transform-side-effects.js +16 -0
  106. package/dist/types/utils/transform-sourcemap.js +29 -0
  107. package/dist/types/utils/transform-to-rollup-output.js +165 -0
  108. package/dist/types/utils/validator.js +275 -0
  109. package/package.json +28 -25
  110. package/dist/shared/consola_36c0034f-Cx52UqEq.mjs +0 -832
  111. package/dist/shared/consola_36c0034f-CynBWXXO.cjs +0 -859
  112. package/dist/shared/prompt-B58MxVuU.cjs +0 -762
  113. package/dist/shared/prompt-DjjlOckE.mjs +0 -758
  114. package/dist/tsconfig.dts.tsbuildinfo +0 -1
@@ -0,0 +1,35 @@
1
+ import { createConsola } from 'consola';
2
+ /**
3
+ * Console logger
4
+ */
5
+ export const logger = process.env
6
+ .ROLLDOWN_TEST
7
+ ? createTestingLogger()
8
+ : createConsola({
9
+ formatOptions: {
10
+ date: false,
11
+ },
12
+ });
13
+ function createTestingLogger() {
14
+ const types = [
15
+ 'silent',
16
+ 'fatal',
17
+ 'error',
18
+ 'warn',
19
+ 'log',
20
+ 'info',
21
+ 'success',
22
+ 'fail',
23
+ 'ready',
24
+ 'start',
25
+ 'box',
26
+ 'debug',
27
+ 'trace',
28
+ 'verbose',
29
+ ];
30
+ const ret = Object.create(null);
31
+ for (const type of types) {
32
+ ret[type] = console.log;
33
+ }
34
+ return ret;
35
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * If Composed plugins call `this.resolve` with `skipSelf: true`, the composed plugins will be skipped as a whole.
3
+ * To prevent that, we use this symbol to store the actual caller of `this.resolve` with `skipSelf: true`. And we
4
+ * will modify the skipSelf option to `false` and use this symbol to skip the caller itself in the composed plugins
5
+ * internally.
6
+ */
7
+ export const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol('plugin-context-resolve-caller');
@@ -0,0 +1,69 @@
1
+ export const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
2
+ 'options',
3
+ 'buildStart',
4
+ 'resolveId',
5
+ 'load',
6
+ 'transform',
7
+ 'moduleParsed',
8
+ 'buildEnd',
9
+ 'onLog',
10
+ 'resolveDynamicImport',
11
+ 'closeBundle',
12
+ 'closeWatcher',
13
+ 'watchChange',
14
+ ];
15
+ export const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
16
+ 'augmentChunkHash',
17
+ 'outputOptions',
18
+ 'renderChunk',
19
+ 'renderStart',
20
+ 'renderError',
21
+ 'writeBundle',
22
+ 'generateBundle',
23
+ ];
24
+ export const ENUMERATED_PLUGIN_HOOK_NAMES = [
25
+ // build hooks
26
+ ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
27
+ // generate hooks
28
+ ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
29
+ // addon hooks
30
+ 'footer',
31
+ 'banner',
32
+ 'intro',
33
+ 'outro',
34
+ ];
35
+ /**
36
+ * Names of all defined hooks. It's like
37
+ * ```js
38
+ * const DEFINED_HOOK_NAMES ={
39
+ * options: 'options',
40
+ * buildStart: 'buildStart',
41
+ * ...
42
+ * }
43
+ * ```
44
+ */
45
+ export const DEFINED_HOOK_NAMES = {
46
+ [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
47
+ [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
48
+ [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
49
+ [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
50
+ [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
51
+ [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
52
+ [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
53
+ [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
54
+ [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
55
+ [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
56
+ [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
57
+ [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
58
+ [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
59
+ [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
60
+ [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
61
+ [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
62
+ [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
63
+ [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
64
+ [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
65
+ [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
66
+ [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
67
+ [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
68
+ [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22],
69
+ };
@@ -0,0 +1,9 @@
1
+ export { defineParallelPlugin } from './plugin/parallel-plugin';
2
+ export { experimental_scan as scan } from './api/experimental';
3
+ export { transform } from './binding';
4
+ export { composeJsPlugins as composePlugins } from './utils/compose-js-plugins';
5
+ // Builtin plugin factory
6
+ export { modulePreloadPolyfillPlugin, dynamicImportVarsPlugin, wasmHelperPlugin, wasmFallbackPlugin, importGlobPlugin, manifestPlugin, loadFallbackPlugin, jsonPlugin, buildImportAnalysisPlugin, viteResolvePlugin, moduleFederationPlugin, } from './builtin-plugin/constructors';
7
+ export { transformPlugin } from './builtin-plugin/transform-plugin';
8
+ export { replacePlugin } from './builtin-plugin/replace-plugin';
9
+ export { aliasPlugin } from './builtin-plugin/alias-plugin';
@@ -2,7 +2,7 @@ import { RolldownOutput, OutputAsset, OutputChunk, RenderedChunk, SourceMap } fr
2
2
  import type { InputOptions, InputOption, ExternalOption, JsxOptions } from './options/input-options';
3
3
  import type { ModuleFormat, OutputOptions } from './options/output-options';
4
4
  import type { RolldownOptions } from './types/rolldown-options';
5
- import type { AsyncPluginHooks, CustomPluginOptions, FunctionPluginHooks, ImportKind, LoadResult, ModuleOptions, ModuleType, ObjectHook, ParallelPluginHooks, PartialResolvedId, Plugin, RolldownPlugin, ResolveIdResult, ResolvedId, SourceDescription, TransformResult } from './plugin';
5
+ import type { AsyncPluginHooks, CustomPluginOptions, FunctionPluginHooks, ImportKind, LoadResult, ModuleOptions, ModuleType, ObjectHook, ParallelPluginHooks, PartialResolvedId, Plugin, RolldownPlugin, RolldownPluginOption, ResolveIdResult, ResolvedId, SourceDescription, TransformResult } from './plugin';
6
6
  import { DefineParallelPluginResult } from './plugin/parallel-plugin';
7
7
  import { defineConfig } from './utils/define-config';
8
8
  import { rolldown } from './api/rolldown';
@@ -24,5 +24,5 @@ import { RolldownWatcher } from './api/watch/watch-emitter';
24
24
  import { build, type BuildOptions } from './api/build';
25
25
  export { defineConfig, rolldown, watch, build };
26
26
  export declare const VERSION: string;
27
- export type { OutputAsset, OutputChunk, RolldownOptions, RolldownOutput, RolldownBuild, InputOptions, NormalizedInputOptions, OutputOptions, NormalizedOutputOptions, Plugin, RolldownPlugin, DefineParallelPluginResult, ConfigExport, ImportKind, InputOption, ExternalOption, ModuleFormat, ModuleType, InternalModuleFormat, LoadResult, TransformResult, ResolveIdResult, PluginContext, TransformPluginContext, ObjectHook, PreRenderedChunk, SourceMap, SourceDescription, PartialNull, PartialResolvedId, ResolvedId, ModuleOptions, ModuleInfo, MinimalPluginContext, EmittedFile, EmittedAsset, CustomPluginOptions, AsyncPluginHooks, ParallelPluginHooks, FunctionPluginHooks, ExistingRawSourceMap, SourceMapInput, OutputBundle, JsxOptions, WatchOptions, RolldownWatcher, BuildOptions, RenderedChunk, };
27
+ export type { OutputAsset, OutputChunk, RolldownOptions, RolldownOutput, RolldownBuild, InputOptions, NormalizedInputOptions, OutputOptions, NormalizedOutputOptions, Plugin, RolldownPlugin, RolldownPluginOption, DefineParallelPluginResult, ConfigExport, ImportKind, InputOption, ExternalOption, ModuleFormat, ModuleType, InternalModuleFormat, LoadResult, TransformResult, ResolveIdResult, PluginContext, TransformPluginContext, ObjectHook, PreRenderedChunk, SourceMap, SourceDescription, PartialNull, PartialResolvedId, ResolvedId, ModuleOptions, ModuleInfo, MinimalPluginContext, EmittedFile, EmittedAsset, CustomPluginOptions, AsyncPluginHooks, ParallelPluginHooks, FunctionPluginHooks, ExistingRawSourceMap, SourceMapInput, OutputBundle, JsxOptions, WatchOptions, RolldownWatcher, BuildOptions, RenderedChunk, };
28
28
  export type { RollupError, RollupLog, LoggingFunction } from './types/misc';
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from './utils/define-config';
2
+ import { rolldown } from './api/rolldown';
3
+ import { watch } from './api/watch';
4
+ import { version } from '../package.json';
5
+ import { build } from './api/build';
6
+ export { defineConfig, rolldown, watch, build };
7
+ export const VERSION = version;
@@ -0,0 +1,25 @@
1
+ import { noop } from '../utils/misc';
2
+ import { LOG_LEVEL_WARN, logLevelPriority, } from './logging';
3
+ import { logInvalidLogPosition } from './logs';
4
+ export const normalizeLog = (log) => typeof log === 'string'
5
+ ? { message: log }
6
+ : typeof log === 'function'
7
+ ? normalizeLog(log())
8
+ : log;
9
+ export function getLogHandler(level, code, logger, pluginName, logLevel) {
10
+ if (logLevelPriority[level] < logLevelPriority[logLevel]) {
11
+ return noop;
12
+ }
13
+ return (log, pos) => {
14
+ if (pos != null) {
15
+ logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
16
+ }
17
+ log = normalizeLog(log);
18
+ if (log.code && !log.pluginCode) {
19
+ log.pluginCode = log.code;
20
+ }
21
+ log.code = code;
22
+ log.plugin = pluginName;
23
+ logger(level, log);
24
+ };
25
+ }
@@ -0,0 +1,107 @@
1
+ import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERROR, logLevelPriority, } from './logging';
2
+ import { error } from './logs';
3
+ import { normalizeLog } from './logHandler';
4
+ import path from 'node:path';
5
+ import { VERSION } from '..';
6
+ import { getSortedPlugins } from '../plugin/plugin-driver';
7
+ export function getLogger(plugins, onLog, logLevel) {
8
+ const minimalPriority = logLevelPriority[logLevel];
9
+ const logger = (level, log, skipped = new Set()) => {
10
+ const logPriority = logLevelPriority[level];
11
+ if (logPriority < minimalPriority) {
12
+ return;
13
+ }
14
+ for (const plugin of getSortedPlugins('onLog', plugins)) {
15
+ if (skipped.has(plugin))
16
+ continue;
17
+ const { onLog: pluginOnLog } = plugin;
18
+ if (pluginOnLog) {
19
+ const getLogHandler = (level) => {
20
+ if (logLevelPriority[level] < minimalPriority) {
21
+ return () => { };
22
+ }
23
+ return (log) => logger(level, normalizeLog(log), new Set(skipped).add(plugin));
24
+ };
25
+ const handler = 'handler' in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
26
+ if (handler.call({
27
+ debug: getLogHandler(LOG_LEVEL_DEBUG),
28
+ error: (log) => error(normalizeLog(log)),
29
+ info: getLogHandler(LOG_LEVEL_INFO),
30
+ meta: {
31
+ rollupVersion: '4.23.0',
32
+ rolldownVersion: VERSION,
33
+ watchMode: false,
34
+ },
35
+ warn: getLogHandler(LOG_LEVEL_WARN),
36
+ pluginName: plugin.name || 'unknown',
37
+ }, level, log) === false) {
38
+ return;
39
+ }
40
+ }
41
+ }
42
+ onLog(level, log);
43
+ };
44
+ return logger;
45
+ }
46
+ export const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
47
+ const { onwarn, onLog } = config;
48
+ const defaultOnLog = getDefaultOnLog(printLog, onwarn);
49
+ if (onLog) {
50
+ const minimalPriority = logLevelPriority[logLevel];
51
+ return (level, log) => onLog(level, addLogToString(log), (level, handledLog) => {
52
+ if (level === LOG_LEVEL_ERROR) {
53
+ return error(normalizeLog(handledLog));
54
+ }
55
+ if (logLevelPriority[level] >= minimalPriority) {
56
+ defaultOnLog(level, normalizeLog(handledLog));
57
+ }
58
+ });
59
+ }
60
+ return defaultOnLog;
61
+ };
62
+ const getDefaultOnLog = (printLog, onwarn) => onwarn
63
+ ? (level, log) => {
64
+ if (level === LOG_LEVEL_WARN) {
65
+ onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
66
+ }
67
+ else {
68
+ printLog(level, log);
69
+ }
70
+ }
71
+ : printLog;
72
+ const addLogToString = (log) => {
73
+ Object.defineProperty(log, 'toString', {
74
+ value: () => getExtendedLogMessage(log),
75
+ writable: true,
76
+ });
77
+ return log;
78
+ };
79
+ const defaultPrintLog = (level, log) => {
80
+ const message = getExtendedLogMessage(log);
81
+ switch (level) {
82
+ case LOG_LEVEL_WARN: {
83
+ return console.warn(message);
84
+ }
85
+ case LOG_LEVEL_DEBUG: {
86
+ return console.debug(message);
87
+ }
88
+ default: {
89
+ return console.info(message);
90
+ }
91
+ }
92
+ };
93
+ const getExtendedLogMessage = (log) => {
94
+ let prefix = '';
95
+ if (log.plugin) {
96
+ prefix += `(${log.plugin} plugin) `;
97
+ }
98
+ if (log.loc) {
99
+ prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
100
+ }
101
+ return prefix + log.message;
102
+ };
103
+ function relativeId(id) {
104
+ if (!path.isAbsolute(id))
105
+ return id;
106
+ return path.relative(path.resolve(), id);
107
+ }
@@ -0,0 +1,11 @@
1
+ export const LOG_LEVEL_SILENT = 'silent';
2
+ export const LOG_LEVEL_ERROR = 'error';
3
+ export const LOG_LEVEL_WARN = 'warn';
4
+ export const LOG_LEVEL_INFO = 'info';
5
+ export const LOG_LEVEL_DEBUG = 'debug';
6
+ export const logLevelPriority = {
7
+ [LOG_LEVEL_DEBUG]: 0,
8
+ [LOG_LEVEL_INFO]: 1,
9
+ [LOG_LEVEL_WARN]: 2,
10
+ [LOG_LEVEL_SILENT]: 3,
11
+ };
@@ -0,0 +1,86 @@
1
+ import { getCodeFrame } from '../utils/code-frame';
2
+ import { locate } from './locate-character';
3
+ import { colors } from '../cli/colors';
4
+ const INVALID_LOG_POSITION = 'INVALID_LOG_POSITION', PLUGIN_ERROR = 'PLUGIN_ERROR', INPUT_HOOK_IN_OUTPUT_PLUGIN = 'INPUT_HOOK_IN_OUTPUT_PLUGIN', CYCLE_LOADING = 'CYCLE_LOADING', MULTIPLY_NOTIFY_OPTION = 'MULTIPLY_NOTIFY_OPTION', MINIFY_WARNING = 'MINIFY_WARNING', PARSE_ERROR = 'PARSE_ERROR';
5
+ export function logParseError(message) {
6
+ return {
7
+ code: PARSE_ERROR,
8
+ message,
9
+ };
10
+ }
11
+ export function logMinifyWarning() {
12
+ return {
13
+ code: MINIFY_WARNING,
14
+ message: colors.yellow('The built-in minifier is still under development. Setting "minify: true" is not recommended for production use.'),
15
+ };
16
+ }
17
+ export function logInvalidLogPosition(pluginName) {
18
+ return {
19
+ code: INVALID_LOG_POSITION,
20
+ message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`,
21
+ };
22
+ }
23
+ export function logInputHookInOutputPlugin(pluginName, hookName) {
24
+ return {
25
+ code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
26
+ message: `The "${hookName}" hook used by the output plugin ${pluginName} is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.`,
27
+ };
28
+ }
29
+ export function logCycleLoading(pluginName, moduleId) {
30
+ return {
31
+ code: CYCLE_LOADING,
32
+ message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`,
33
+ };
34
+ }
35
+ export function logMultiplyNotifyOption() {
36
+ return {
37
+ code: MULTIPLY_NOTIFY_OPTION,
38
+ message: `Found multiply notify option at watch options, using first one to start notify watcher.`,
39
+ };
40
+ }
41
+ export function logPluginError(error, plugin, { hook, id } = {}) {
42
+ const code = error.code;
43
+ if (!error.pluginCode &&
44
+ code != null &&
45
+ (typeof code !== 'string' || !code.startsWith('PLUGIN_'))) {
46
+ error.pluginCode = code;
47
+ }
48
+ error.code = PLUGIN_ERROR;
49
+ error.plugin = plugin;
50
+ if (hook) {
51
+ error.hook = hook;
52
+ }
53
+ if (id) {
54
+ error.id = id;
55
+ }
56
+ return error;
57
+ }
58
+ export function error(base) {
59
+ if (!(base instanceof Error)) {
60
+ base = Object.assign(new Error(base.message), base);
61
+ Object.defineProperty(base, 'name', {
62
+ value: 'RollupError',
63
+ writable: true,
64
+ });
65
+ }
66
+ throw base;
67
+ }
68
+ export function augmentCodeLocation(properties, pos, source, id) {
69
+ if (typeof pos === 'object') {
70
+ const { line, column } = pos;
71
+ properties.loc = { column, file: id, line };
72
+ }
73
+ else {
74
+ properties.pos = pos;
75
+ const location = locate(source, pos, { offsetLine: 1 });
76
+ if (!location) {
77
+ return;
78
+ }
79
+ const { line, column } = location;
80
+ properties.loc = { column, file: id, line };
81
+ }
82
+ if (properties.frame === undefined) {
83
+ const { line, column } = properties.loc;
84
+ properties.frame = getCodeFrame(source, line, column);
85
+ }
86
+ }
@@ -26,7 +26,7 @@ export interface WatchOptions {
26
26
  }
27
27
  export interface ChecksOptions {
28
28
  /**
29
- * Wether to emit warnings when detecting circular dependencies.
29
+ * Whether to emit warnings when detecting circular dependencies.
30
30
  * @default false
31
31
  */
32
32
  circularDependency?: boolean;
@@ -76,6 +76,52 @@ export interface InputOptions {
76
76
  viteMode?: boolean;
77
77
  resolveNewUrlToAsset?: boolean;
78
78
  };
79
+ /**
80
+ * Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values.
81
+ *
82
+ * # Examples
83
+ *
84
+ * - Replace the global variable `IS_PROD` with `true`
85
+ *
86
+ * ```js rolldown.config.js
87
+ * export default defineConfig({ define: { IS_PROD: 'true' // or JSON.stringify(true) } })
88
+ * ```
89
+ *
90
+ * Result:
91
+ *
92
+ * ```js
93
+ * // Input
94
+ * if (IS_PROD) {
95
+ * console.log('Production mode')
96
+ * }
97
+ *
98
+ * // After bundling
99
+ * if (true) {
100
+ * console.log('Production mode')
101
+ * }
102
+ *```
103
+ *
104
+ * - Replace the property accessor `process.env.NODE_ENV` with `'production'`
105
+ *
106
+ * ```js rolldown.config.js
107
+ * export default defineConfig({ define: { 'process.env.NODE_ENV': "'production'" } })
108
+ * ```
109
+ *
110
+ * Result:
111
+ *
112
+ * ```js
113
+ * // Input
114
+ * if (process.env.NODE_ENV === 'production') {
115
+ * console.log('Production mode')
116
+ * }
117
+ *
118
+ * // After bundling
119
+ * if ('production' === 'production') {
120
+ * console.log('Production mode')
121
+ * }
122
+ *
123
+ * ```
124
+ */
79
125
  define?: Record<string, string>;
80
126
  /**
81
127
  * Inject import statements on demand.
@@ -103,7 +149,6 @@ export interface InputOptions {
103
149
  inject?: Record<string, string | [string, string]>;
104
150
  profilerNames?: boolean;
105
151
  /**
106
- * JSX options.
107
152
  * The `false` is disabled jsx parser, it will give you a syntax error if you use jsx syntax
108
153
  * The `mode: preserve` is disabled jsx transformer, it perverse original jsx syntax in the output.
109
154
  * The `mode: classic` is enabled jsx `classic` transformer.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ // TODO: I guess we make these getters enumerable so it act more like a plain object
2
+ export class NormalizedInputOptionsImpl {
3
+ onLog;
4
+ inner;
5
+ constructor(inner, onLog) {
6
+ this.onLog = onLog;
7
+ this.inner = inner;
8
+ }
9
+ get shimMissingExports() {
10
+ return this.inner.shimMissingExports;
11
+ }
12
+ get input() {
13
+ return this.inner.input;
14
+ }
15
+ get cwd() {
16
+ return this.inner.cwd ?? undefined;
17
+ }
18
+ get platform() {
19
+ return this.inner.platform;
20
+ }
21
+ }
@@ -0,0 +1,99 @@
1
+ import { unsupported } from '../utils/misc';
2
+ function mapFunctionOption(option, name) {
3
+ return typeof option === 'undefined'
4
+ ? () => {
5
+ unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
6
+ }
7
+ : option;
8
+ }
9
+ // TODO: I guess we make these getters enumerable so it act more like a plain object
10
+ export class NormalizedOutputOptionsImpl {
11
+ inner;
12
+ constructor(inner) {
13
+ this.inner = inner;
14
+ }
15
+ get dir() {
16
+ return this.inner.dir ?? undefined;
17
+ }
18
+ get entryFileNames() {
19
+ return mapFunctionOption(this.inner.entryFilenames, 'entryFileNames');
20
+ }
21
+ get chunkFileNames() {
22
+ return mapFunctionOption(this.inner.chunkFilenames, 'chunkFileNames');
23
+ }
24
+ get assetFileNames() {
25
+ return this.inner.assetFilenames;
26
+ }
27
+ get format() {
28
+ return this.inner.format;
29
+ }
30
+ get exports() {
31
+ return this.inner.exports;
32
+ }
33
+ get sourcemap() {
34
+ return this.inner.sourcemap;
35
+ }
36
+ get cssEntryFileNames() {
37
+ return mapFunctionOption(this.inner.cssEntryFilenames, 'cssEntryFileNames');
38
+ }
39
+ get cssChunkFileNames() {
40
+ return mapFunctionOption(this.inner.cssChunkFilenames, 'cssChunkFileNames');
41
+ }
42
+ get shimMissingExports() {
43
+ return this.inner.shimMissingExports;
44
+ }
45
+ get name() {
46
+ return this.inner.name ?? undefined;
47
+ }
48
+ get file() {
49
+ return this.inner.file ?? undefined;
50
+ }
51
+ get inlineDynamicImports() {
52
+ return this.inner.inlineDynamicImports;
53
+ }
54
+ get externalLiveBindings() {
55
+ return this.inner.externalLiveBindings;
56
+ }
57
+ get banner() {
58
+ return mapFunctionOption(this.inner.banner, 'banner') ?? undefined;
59
+ }
60
+ get footer() {
61
+ return mapFunctionOption(this.inner.footer, 'footer') ?? undefined;
62
+ }
63
+ get intro() {
64
+ return mapFunctionOption(this.inner.intro, 'intro') ?? undefined;
65
+ }
66
+ get outro() {
67
+ return mapFunctionOption(this.inner.outro, 'outro') ?? undefined;
68
+ }
69
+ get esModule() {
70
+ return this.inner.esModule;
71
+ }
72
+ get extend() {
73
+ return this.inner.extend;
74
+ }
75
+ get globals() {
76
+ return mapFunctionOption(this.inner.globals, 'globals');
77
+ }
78
+ get hashCharacters() {
79
+ return this.inner.hashCharacters;
80
+ }
81
+ get sourcemapDebugIds() {
82
+ return this.inner.sourcemapDebugIds;
83
+ }
84
+ get sourcemapIgnoreList() {
85
+ return mapFunctionOption(void 0, 'sourcemapIgnoreList');
86
+ }
87
+ get sourcemapPathTransform() {
88
+ return mapFunctionOption(void 0, 'sourcemapPathTransform');
89
+ }
90
+ get minify() {
91
+ return this.inner.minify;
92
+ }
93
+ get comments() {
94
+ return this.inner.comments;
95
+ }
96
+ get polyfillRequire() {
97
+ return this.inner.polyfillRequire;
98
+ }
99
+ }
@@ -44,6 +44,9 @@ export interface OutputOptions {
44
44
  inlineDynamicImports?: boolean;
45
45
  advancedChunks?: {
46
46
  minSize?: number;
47
+ maxSize?: number;
48
+ maxModuleSize?: number;
49
+ minModuleSize?: number;
47
50
  minShareCount?: number;
48
51
  groups?: {
49
52
  name: string;
@@ -51,6 +54,9 @@ export interface OutputOptions {
51
54
  priority?: number;
52
55
  minSize?: number;
53
56
  minShareCount?: number;
57
+ maxSize?: number;
58
+ maxModuleSize?: number;
59
+ minModuleSize?: number;
54
60
  }[];
55
61
  };
56
62
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { registerPlugins } from './binding';
3
+ import { bindingifyPlugin } from './plugin/bindingify-plugin';
4
+ import { PluginContextData } from './plugin/plugin-context-data';
5
+ const { registryId, pluginInfos, threadNumber } = workerData;
6
+ (async () => {
7
+ try {
8
+ const plugins = await Promise.all(pluginInfos.map(async (pluginInfo) => {
9
+ const pluginModule = await import(pluginInfo.fileUrl);
10
+ const definePluginImpl = pluginModule.default;
11
+ const plugin = await definePluginImpl(pluginInfo.options, {
12
+ threadNumber,
13
+ });
14
+ return {
15
+ index: pluginInfo.index,
16
+ // TODO(sapphi-red): support inputOptions and outputOptions
17
+ plugin: bindingifyPlugin(plugin, {}, {},
18
+ // TODO need to find a way to share pluginContextData
19
+ new PluginContextData(), () => { }, 'info'),
20
+ };
21
+ }));
22
+ registerPlugins(registryId, plugins);
23
+ parentPort.postMessage({ type: 'success' });
24
+ }
25
+ catch (error) {
26
+ parentPort.postMessage({ type: 'error', error });
27
+ }
28
+ finally {
29
+ parentPort.unref();
30
+ }
31
+ })();
@@ -0,0 +1 @@
1
+ export { defineParallelPluginImplementation, } from './plugin/parallel-plugin-implementation';