rolldown 1.0.0-beta.3-commit.306867e → 1.0.0-beta.3-commit.f65bde3

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 (108) hide show
  1. package/dist/cjs/cli.cjs +2 -2
  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 +2 -2
  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-_xN4hdfO.mjs → binding-CFTx0Fs7.mjs} +3 -3
  12. package/dist/shared/{binding-B9_Bsc0_.cjs → binding-DTKqYZn-.cjs} +3 -3
  13. package/dist/shared/{src-BGJCTYiA.mjs → src-46qAwcxx.mjs} +54 -17
  14. package/dist/shared/{src-BL6ftzBh.cjs → src-CoQJ2u3O.cjs} +54 -17
  15. package/dist/types/binding.d.ts +7 -0
  16. package/dist/types/index.d.ts +4 -3
  17. package/dist/types/log/logging.d.ts +1 -0
  18. package/dist/types/options/input-options.d.ts +2 -2
  19. package/dist/types/plugin/index.d.ts +1 -0
  20. package/dist/types/plugin/plugin-context-data.d.ts +2 -1
  21. package/package.json +19 -19
  22. package/dist/types/api/build.js +0 -22
  23. package/dist/types/api/experimental.js +0 -13
  24. package/dist/types/api/rolldown/index.js +0 -7
  25. package/dist/types/api/rolldown/rolldown-build.js +0 -43
  26. package/dist/types/api/watch/index.js +0 -8
  27. package/dist/types/api/watch/watch-emitter.js +0 -69
  28. package/dist/types/api/watch/watcher.js +0 -66
  29. package/dist/types/builtin-plugin/alias-plugin.js +0 -4
  30. package/dist/types/builtin-plugin/constructors.js +0 -68
  31. package/dist/types/builtin-plugin/replace-plugin.js +0 -29
  32. package/dist/types/builtin-plugin/transform-plugin.js +0 -16
  33. package/dist/types/builtin-plugin/utils.js +0 -19
  34. package/dist/types/cli/arguments/alias.js +0 -63
  35. package/dist/types/cli/arguments/index.js +0 -127
  36. package/dist/types/cli/arguments/normalize.js +0 -48
  37. package/dist/types/cli/arguments/utils.js +0 -67
  38. package/dist/types/cli/colors.js +0 -17
  39. package/dist/types/cli/commands/bundle.js +0 -203
  40. package/dist/types/cli/commands/help.js +0 -88
  41. package/dist/types/cli/index.js +0 -27
  42. package/dist/types/cli/load-config.js +0 -95
  43. package/dist/types/cli/logger.js +0 -35
  44. package/dist/types/constants/plugin-context.js +0 -7
  45. package/dist/types/constants/plugin.js +0 -69
  46. package/dist/types/experimental-index.js +0 -9
  47. package/dist/types/index.js +0 -7
  48. package/dist/types/log/logHandler.js +0 -25
  49. package/dist/types/log/logger.js +0 -107
  50. package/dist/types/log/logging.js +0 -11
  51. package/dist/types/log/logs.js +0 -86
  52. package/dist/types/options/input-options.js +0 -1
  53. package/dist/types/options/normalized-input-options.js +0 -21
  54. package/dist/types/options/normalized-output-options.js +0 -99
  55. package/dist/types/options/output-options.js +0 -1
  56. package/dist/types/options/watch-options.js +0 -1
  57. package/dist/types/parallel-plugin-worker.js +0 -31
  58. package/dist/types/parallel-plugin.js +0 -1
  59. package/dist/types/parse-ast-index.js +0 -73
  60. package/dist/types/plugin/bindingify-build-hooks.js +0 -213
  61. package/dist/types/plugin/bindingify-hook-filter.js +0 -39
  62. package/dist/types/plugin/bindingify-output-hooks.js +0 -189
  63. package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
  64. package/dist/types/plugin/bindingify-plugin.js +0 -124
  65. package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
  66. package/dist/types/plugin/hook-filter.js +0 -1
  67. package/dist/types/plugin/index.js +0 -1
  68. package/dist/types/plugin/minimal-plugin-context.js +0 -25
  69. package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
  70. package/dist/types/plugin/parallel-plugin.js +0 -6
  71. package/dist/types/plugin/plugin-context-data.js +0 -55
  72. package/dist/types/plugin/plugin-context.js +0 -124
  73. package/dist/types/plugin/plugin-driver.js +0 -88
  74. package/dist/types/plugin/transform-plugin-context.js +0 -37
  75. package/dist/types/types/assert.js +0 -1
  76. package/dist/types/types/config-export.js +0 -1
  77. package/dist/types/types/misc.js +0 -1
  78. package/dist/types/types/module-info.js +0 -1
  79. package/dist/types/types/module-side-effects.js +0 -1
  80. package/dist/types/types/output-bundle.js +0 -1
  81. package/dist/types/types/rolldown-options.js +0 -1
  82. package/dist/types/types/rolldown-output.js +0 -1
  83. package/dist/types/types/schema.js +0 -1
  84. package/dist/types/types/sourcemap.js +0 -16
  85. package/dist/types/types/utils.js +0 -1
  86. package/dist/types/utils/asset-source.js +0 -8
  87. package/dist/types/utils/async-flatten.js +0 -7
  88. package/dist/types/utils/bindingify-input-options.js +0 -226
  89. package/dist/types/utils/bindingify-output-options.js +0 -107
  90. package/dist/types/utils/code-frame.js +0 -46
  91. package/dist/types/utils/compose-js-plugins.js +0 -400
  92. package/dist/types/utils/create-bundler-option.js +0 -53
  93. package/dist/types/utils/create-bundler.js +0 -15
  94. package/dist/types/utils/define-config.js +0 -3
  95. package/dist/types/utils/error.js +0 -65
  96. package/dist/types/utils/initialize-parallel-plugins.js +0 -54
  97. package/dist/types/utils/misc.js +0 -22
  98. package/dist/types/utils/normalize-hook.js +0 -21
  99. package/dist/types/utils/normalize-plugin-option.js +0 -35
  100. package/dist/types/utils/normalize-string-or-regex.js +0 -14
  101. package/dist/types/utils/plugin/index.js +0 -7
  102. package/dist/types/utils/transform-module-info.js +0 -19
  103. package/dist/types/utils/transform-rendered-chunk.js +0 -43
  104. package/dist/types/utils/transform-rendered-module.js +0 -10
  105. package/dist/types/utils/transform-side-effects.js +0 -16
  106. package/dist/types/utils/transform-sourcemap.js +0 -29
  107. package/dist/types/utils/transform-to-rollup-output.js +0 -165
  108. package/dist/types/utils/validator.js +0 -276
@@ -1,189 +0,0 @@
1
- import { normalizeHook } from '../utils/normalize-hook';
2
- import { collectChangedBundle, transformToOutputBundle, } from '../utils/transform-to-rollup-output';
3
- import { PluginContext } from './plugin-context';
4
- import { bindingifySourcemap } from '../types/sourcemap';
5
- import { bindingifyPluginHookMeta, } from './bindingify-plugin-hook-meta';
6
- import { NormalizedInputOptionsImpl } from '../options/normalized-input-options';
7
- import { NormalizedOutputOptionsImpl } from '../options/normalized-output-options';
8
- import { transformRenderedChunk } from '../utils/transform-rendered-chunk';
9
- import { normalizeErrors } from '../utils/error';
10
- export function bindingifyRenderStart(args) {
11
- const hook = args.plugin.renderStart;
12
- if (!hook) {
13
- return {};
14
- }
15
- const { handler, meta } = normalizeHook(hook);
16
- return {
17
- plugin: async (ctx, opts) => {
18
- handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), new NormalizedInputOptionsImpl(opts, args.onLog));
19
- },
20
- meta: bindingifyPluginHookMeta(meta),
21
- };
22
- }
23
- export function bindingifyRenderChunk(args) {
24
- const hook = args.plugin.renderChunk;
25
- if (!hook) {
26
- return {};
27
- }
28
- const { handler, meta } = normalizeHook(hook);
29
- return {
30
- plugin: async (ctx, code, chunk, opts) => {
31
- const ret = await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts));
32
- if (ret == null) {
33
- return;
34
- }
35
- if (typeof ret === 'string') {
36
- return { code: ret };
37
- }
38
- if (!ret.map) {
39
- return { code: ret.code };
40
- }
41
- return {
42
- code: ret.code,
43
- map: bindingifySourcemap(ret.map),
44
- };
45
- },
46
- meta: bindingifyPluginHookMeta(meta),
47
- };
48
- }
49
- export function bindingifyAugmentChunkHash(args) {
50
- const hook = args.plugin.augmentChunkHash;
51
- if (!hook) {
52
- return {};
53
- }
54
- const { handler, meta } = normalizeHook(hook);
55
- return {
56
- plugin: async (ctx, chunk) => {
57
- return await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
58
- },
59
- meta: bindingifyPluginHookMeta(meta),
60
- };
61
- }
62
- export function bindingifyRenderError(args) {
63
- const hook = args.plugin.renderError;
64
- if (!hook) {
65
- return {};
66
- }
67
- const { handler, meta } = normalizeHook(hook);
68
- return {
69
- plugin: async (ctx, err) => {
70
- handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
71
- },
72
- meta: bindingifyPluginHookMeta(meta),
73
- };
74
- }
75
- export function bindingifyGenerateBundle(args) {
76
- const hook = args.plugin.generateBundle;
77
- if (!hook) {
78
- return {};
79
- }
80
- const { handler, meta } = normalizeHook(hook);
81
- return {
82
- plugin: async (ctx, bundle, isWrite, opts) => {
83
- const changed = {
84
- updated: new Set(),
85
- deleted: new Set(),
86
- };
87
- const output = transformToOutputBundle(bundle, changed);
88
- await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output, isWrite);
89
- return collectChangedBundle(changed, output);
90
- },
91
- meta: bindingifyPluginHookMeta(meta),
92
- };
93
- }
94
- export function bindingifyWriteBundle(args) {
95
- const hook = args.plugin.writeBundle;
96
- if (!hook) {
97
- return {};
98
- }
99
- const { handler, meta } = normalizeHook(hook);
100
- return {
101
- plugin: async (ctx, bundle, opts) => {
102
- const changed = {
103
- updated: new Set(),
104
- deleted: new Set(),
105
- };
106
- const output = transformToOutputBundle(bundle, changed);
107
- await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output);
108
- return collectChangedBundle(changed, output);
109
- },
110
- meta: bindingifyPluginHookMeta(meta),
111
- };
112
- }
113
- export function bindingifyCloseBundle(args) {
114
- const hook = args.plugin.closeBundle;
115
- if (!hook) {
116
- return {};
117
- }
118
- const { handler, meta } = normalizeHook(hook);
119
- return {
120
- plugin: async (ctx) => {
121
- await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
122
- },
123
- meta: bindingifyPluginHookMeta(meta),
124
- };
125
- }
126
- export function bindingifyBanner(args) {
127
- const hook = args.plugin.banner;
128
- if (!hook) {
129
- return {};
130
- }
131
- const { handler, meta } = normalizeHook(hook);
132
- return {
133
- plugin: async (ctx, chunk) => {
134
- if (typeof handler === 'string') {
135
- return handler;
136
- }
137
- return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
138
- },
139
- meta: bindingifyPluginHookMeta(meta),
140
- };
141
- }
142
- export function bindingifyFooter(args) {
143
- const hook = args.plugin.footer;
144
- if (!hook) {
145
- return {};
146
- }
147
- const { handler, meta } = normalizeHook(hook);
148
- return {
149
- plugin: async (ctx, chunk) => {
150
- if (typeof handler === 'string') {
151
- return handler;
152
- }
153
- return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
154
- },
155
- meta: bindingifyPluginHookMeta(meta),
156
- };
157
- }
158
- export function bindingifyIntro(args) {
159
- const hook = args.plugin.intro;
160
- if (!hook) {
161
- return {};
162
- }
163
- const { handler, meta } = normalizeHook(hook);
164
- return {
165
- plugin: async (ctx, chunk) => {
166
- if (typeof handler === 'string') {
167
- return handler;
168
- }
169
- return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
170
- },
171
- meta: bindingifyPluginHookMeta(meta),
172
- };
173
- }
174
- export function bindingifyOutro(args) {
175
- const hook = args.plugin.outro;
176
- if (!hook) {
177
- return {};
178
- }
179
- const { handler, meta } = normalizeHook(hook);
180
- return {
181
- plugin: async (ctx, chunk) => {
182
- if (typeof handler === 'string') {
183
- return handler;
184
- }
185
- return handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
186
- },
187
- meta: bindingifyPluginHookMeta(meta),
188
- };
189
- }
@@ -1,19 +0,0 @@
1
- import { BindingPluginOrder } from '../binding';
2
- export function bindingifyPluginHookMeta(options) {
3
- return {
4
- order: bindingPluginOrder(options.order),
5
- };
6
- }
7
- function bindingPluginOrder(order) {
8
- switch (order) {
9
- case 'post':
10
- return BindingPluginOrder.Post;
11
- case 'pre':
12
- return BindingPluginOrder.Pre;
13
- case null:
14
- case undefined:
15
- return undefined;
16
- default:
17
- throw new Error(`Unknown plugin order: ${order}`);
18
- }
19
- }
@@ -1,124 +0,0 @@
1
- import { bindingifyBuildEnd, bindingifyBuildStart, bindingifyLoad, bindingifyModuleParsed, bindingifyResolveDynamicImport, bindingifyResolveId, bindingifyTransform, } from './bindingify-build-hooks';
2
- import { bindingifyRenderStart, bindingifyRenderChunk, bindingifyGenerateBundle, bindingifyWriteBundle, bindingifyRenderError, bindingifyAugmentChunkHash, bindingifyBanner, bindingifyFooter, bindingifyIntro, bindingifyOutro, bindingifyCloseBundle, } from './bindingify-output-hooks';
3
- import { bindingifyCloseWatcher, bindingifyWatchChange, } from './bindingify-watch-hooks';
4
- import { error, logPluginError } from '../log/logs';
5
- // Note: because napi not catch error, so we need to catch error and print error to debugger in adapter.
6
- export function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, onLog, logLevel) {
7
- const args = {
8
- plugin,
9
- options,
10
- outputOptions,
11
- pluginContextData,
12
- onLog,
13
- logLevel,
14
- };
15
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
16
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter, } = bindingifyResolveId(args);
17
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
18
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
19
- const { plugin: transform, meta: transformMeta, filter: transformFilter, } = bindingifyTransform(args);
20
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
21
- const { plugin: load, meta: loadMeta, filter: loadFilter, } = bindingifyLoad(args);
22
- const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args);
23
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
24
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
25
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
26
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
27
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
28
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
29
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
30
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
31
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
32
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
33
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
34
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
35
- const result = {
36
- // The plugin name already normalized at `normalizePlugins`, see `packages/rolldown/src/utils/normalize-plugin-option.ts`
37
- name: plugin.name,
38
- buildStart,
39
- buildStartMeta,
40
- resolveId,
41
- resolveIdMeta,
42
- // @ts-ignore
43
- resolveIdFilter,
44
- resolveDynamicImport,
45
- resolveDynamicImportMeta,
46
- buildEnd,
47
- buildEndMeta,
48
- transform,
49
- transformMeta,
50
- transformFilter,
51
- moduleParsed,
52
- moduleParsedMeta,
53
- load,
54
- loadMeta,
55
- loadFilter,
56
- renderChunk,
57
- renderChunkMeta,
58
- augmentChunkHash,
59
- augmentChunkHashMeta,
60
- renderStart,
61
- renderStartMeta,
62
- renderError,
63
- renderErrorMeta,
64
- generateBundle,
65
- generateBundleMeta,
66
- writeBundle,
67
- writeBundleMeta,
68
- closeBundle,
69
- closeBundleMeta,
70
- banner,
71
- bannerMeta,
72
- footer,
73
- footerMeta,
74
- intro,
75
- introMeta,
76
- outro,
77
- outroMeta,
78
- watchChange,
79
- watchChangeMeta,
80
- closeWatcher,
81
- closeWatcherMeta,
82
- };
83
- return wrapHandlers(result);
84
- }
85
- function wrapHandlers(plugin) {
86
- for (const hookName of [
87
- 'buildStart',
88
- 'resolveId',
89
- 'resolveDynamicImport',
90
- 'buildEnd',
91
- 'transform',
92
- 'moduleParsed',
93
- 'load',
94
- 'renderChunk',
95
- 'augmentChunkHash',
96
- 'renderStart',
97
- 'renderError',
98
- 'generateBundle',
99
- 'writeBundle',
100
- 'closeBundle',
101
- 'banner',
102
- 'footer',
103
- 'intro',
104
- 'outro',
105
- 'watchChange',
106
- 'closeWatcher',
107
- ]) {
108
- const handler = plugin[hookName];
109
- if (handler) {
110
- plugin[hookName] = async (...args) => {
111
- try {
112
- return await handler(...args);
113
- }
114
- catch (e) {
115
- return error(logPluginError(e, plugin.name, {
116
- hook: hookName,
117
- id: hookName === 'transform' ? args[2] : undefined,
118
- }));
119
- }
120
- };
121
- }
122
- }
123
- return plugin;
124
- }
@@ -1,29 +0,0 @@
1
- import { normalizeHook } from '../utils/normalize-hook';
2
- import { PluginContext } from './plugin-context';
3
- import { bindingifyPluginHookMeta, } from './bindingify-plugin-hook-meta';
4
- export function bindingifyWatchChange(args) {
5
- const hook = args.plugin.watchChange;
6
- if (!hook) {
7
- return {};
8
- }
9
- const { handler, meta } = normalizeHook(hook);
10
- return {
11
- plugin: async (ctx, id, event) => {
12
- await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event: event });
13
- },
14
- meta: bindingifyPluginHookMeta(meta),
15
- };
16
- }
17
- export function bindingifyCloseWatcher(args) {
18
- const hook = args.plugin.closeWatcher;
19
- if (!hook) {
20
- return {};
21
- }
22
- const { handler, meta } = normalizeHook(hook);
23
- return {
24
- plugin: async (ctx) => {
25
- await handler.call(new PluginContext(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
26
- },
27
- meta: bindingifyPluginHookMeta(meta),
28
- };
29
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN } from '../log/logging';
2
- import { error, logPluginError } from '../log/logs';
3
- import { getLogHandler, normalizeLog } from '../log/logHandler';
4
- import { VERSION } from '..';
5
- export class MinimalPluginContext {
6
- pluginName;
7
- info;
8
- warn;
9
- debug;
10
- meta;
11
- constructor(onLog, logLevel, pluginName) {
12
- this.pluginName = pluginName;
13
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', onLog, pluginName, logLevel);
14
- this.info = getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', onLog, pluginName, logLevel);
15
- this.warn = getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', onLog, pluginName, logLevel);
16
- this.meta = {
17
- rollupVersion: '4.23.0',
18
- rolldownVersion: VERSION,
19
- watchMode: false,
20
- };
21
- }
22
- error(e) {
23
- return error(logPluginError(normalizeLog(e), this.pluginName));
24
- }
25
- }
@@ -1,3 +0,0 @@
1
- export function defineParallelPluginImplementation(plugin) {
2
- return plugin;
3
- }
@@ -1,6 +0,0 @@
1
- import { pathToFileURL } from 'node:url';
2
- export function defineParallelPlugin(pluginPath) {
3
- return (options) => {
4
- return { _parallel: { fileUrl: pathToFileURL(pluginPath).href, options } };
5
- };
6
- }
@@ -1,55 +0,0 @@
1
- import { transformModuleInfo } from '../utils/transform-module-info';
2
- export class PluginContextData {
3
- moduleOptionMap = new Map();
4
- resolveOptionsMap = new Map();
5
- loadModulePromiseMap = new Map();
6
- updateModuleOption(id, option) {
7
- const existing = this.moduleOptionMap.get(id);
8
- if (existing) {
9
- if (option.moduleSideEffects != null) {
10
- existing.moduleSideEffects = option.moduleSideEffects;
11
- }
12
- if (option.meta != null) {
13
- Object.assign(existing.meta, option.meta);
14
- }
15
- }
16
- else {
17
- this.moduleOptionMap.set(id, option);
18
- }
19
- }
20
- getModuleOption(id) {
21
- const option = this.moduleOptionMap.get(id);
22
- if (!option) {
23
- const raw = {
24
- moduleSideEffects: null,
25
- meta: {},
26
- };
27
- this.moduleOptionMap.set(id, raw);
28
- return raw;
29
- }
30
- return option;
31
- }
32
- getModuleInfo(id, context) {
33
- const bindingInfo = context.getModuleInfo(id);
34
- if (bindingInfo) {
35
- const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
36
- return info;
37
- }
38
- return null;
39
- }
40
- getModuleIds(context) {
41
- const moduleIds = context.getModuleIds();
42
- return moduleIds.values();
43
- }
44
- saveResolveOptions(options) {
45
- const index = this.resolveOptionsMap.size;
46
- this.resolveOptionsMap.set(index, options);
47
- return index;
48
- }
49
- getSavedResolveOptions(receipt) {
50
- return this.resolveOptionsMap.get(receipt);
51
- }
52
- removeSavedResolveOptions(receipt) {
53
- this.resolveOptionsMap.delete(receipt);
54
- }
55
- }
@@ -1,124 +0,0 @@
1
- import { MinimalPluginContext } from '../plugin/minimal-plugin-context';
2
- import { bindingAssetSource } from '../utils/asset-source';
3
- import { unimplemented, unsupported } from '../utils/misc';
4
- import { SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF } from '../constants/plugin-context';
5
- import { bindingifySideEffects } from '../utils/transform-side-effects';
6
- import { LOG_LEVEL_WARN } from '../log/logging';
7
- import { logCycleLoading } from '../log/logs';
8
- export class PluginContext extends MinimalPluginContext {
9
- outputOptions;
10
- context;
11
- data;
12
- onLog;
13
- currentLoadingModule;
14
- constructor(outputOptions, context, plugin, data, onLog, logLevel, currentLoadingModule) {
15
- super(onLog, logLevel, plugin.name);
16
- this.outputOptions = outputOptions;
17
- this.context = context;
18
- this.data = data;
19
- this.onLog = onLog;
20
- this.currentLoadingModule = currentLoadingModule;
21
- }
22
- async load(options) {
23
- const id = options.id;
24
- if (id === this.currentLoadingModule) {
25
- this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
26
- }
27
- // resolveDependencies always true at rolldown
28
- const moduleInfo = this.data.getModuleInfo(id, this.context);
29
- if (moduleInfo && moduleInfo.code !== null /* module already parsed */) {
30
- return moduleInfo;
31
- }
32
- const rawOptions = {
33
- meta: options.meta || {},
34
- moduleSideEffects: options.moduleSideEffects || null,
35
- };
36
- this.data.updateModuleOption(id, rawOptions);
37
- async function createLoadModulePromise(context, data) {
38
- const loadPromise = data.loadModulePromiseMap.get(id);
39
- if (loadPromise) {
40
- return loadPromise;
41
- }
42
- let resolveFn;
43
- // TODO: If is not resolved, we need to set a time to avoid waiting.
44
- const promise = new Promise((resolve, _) => {
45
- resolveFn = resolve;
46
- });
47
- data.loadModulePromiseMap.set(id, promise);
48
- try {
49
- await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
50
- }
51
- finally {
52
- // If the load module has failed, avoid it re-load using unresolved promise.
53
- data.loadModulePromiseMap.delete(id);
54
- }
55
- return promise;
56
- }
57
- // Here using one promise to avoid pass more callback to rust side, it only accept one callback, other will be ignored.
58
- await createLoadModulePromise(this.context, this.data);
59
- return this.data.getModuleInfo(id, this.context);
60
- }
61
- async resolve(source, importer, options) {
62
- let receipt = undefined;
63
- if (options != null) {
64
- receipt = this.data.saveResolveOptions(options);
65
- }
66
- const res = await this.context.resolve(source, importer, {
67
- custom: receipt,
68
- skipSelf: options?.skipSelf,
69
- });
70
- if (receipt != null) {
71
- this.data.removeSavedResolveOptions(receipt);
72
- }
73
- if (res == null)
74
- return null;
75
- const info = this.data.getModuleOption(res.id) || {};
76
- return { ...res, ...info };
77
- }
78
- emitFile(file) {
79
- // @ts-expect-error
80
- if (file.type === 'prebuilt-chunk') {
81
- return unimplemented('PluginContext.emitFile with type prebuilt-chunk');
82
- }
83
- if (file.type === 'chunk') {
84
- return this.context.emitChunk(file);
85
- }
86
- const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== 'function'
87
- ? undefined
88
- : this.outputOptions.sanitizeFileName(file.name || 'asset');
89
- const filename = file.fileName ? undefined : this.getAssetFileNames(file);
90
- return this.context.emitFile({
91
- ...file,
92
- originalFileName: file.originalFileName || undefined,
93
- source: bindingAssetSource(file.source),
94
- }, filename, fnSanitizedFileName);
95
- }
96
- getAssetFileNames(file) {
97
- if (typeof this.outputOptions.assetFileNames === 'function') {
98
- return this.outputOptions.assetFileNames({
99
- names: file.name ? [file.name] : [],
100
- originalFileNames: file.originalFileName ? [file.originalFileName] : [],
101
- source: file.source,
102
- type: 'asset',
103
- });
104
- }
105
- }
106
- getFileName(referenceId) {
107
- return this.context.getFileName(referenceId);
108
- }
109
- getModuleInfo(id) {
110
- return this.data.getModuleInfo(id, this.context);
111
- }
112
- getModuleIds() {
113
- return this.data.getModuleIds(this.context);
114
- }
115
- addWatchFile(id) {
116
- this.context.addWatchFile(id);
117
- }
118
- /**
119
- * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
120
- */
121
- parse(_input, _options) {
122
- unsupported('`PluginContext#parse` is not supported by rolldown.');
123
- }
124
- }
@@ -1,88 +0,0 @@
1
- import { getLogHandler, normalizeLog } from '../log/logHandler';
2
- import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN } from '../log/logging';
3
- import { error, logPluginError } from '../log/logs';
4
- import { normalizeHook } from '../utils/normalize-hook';
5
- import { VERSION } from '..';
6
- import { getLogger, getOnLog } from '../log/logger';
7
- import { BuiltinPlugin } from '../builtin-plugin/constructors';
8
- import { normalizePluginOption } from '../utils/normalize-plugin-option';
9
- export class PluginDriver {
10
- static async callOptionsHook(inputOptions) {
11
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
12
- const plugins = getSortedPlugins('options', getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
13
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
14
- for (const plugin of plugins) {
15
- const name = plugin.name || 'unknown';
16
- const options = plugin.options;
17
- if (options) {
18
- const { handler } = normalizeHook(options);
19
- const result = await handler.call({
20
- debug: getLogHandler(LOG_LEVEL_DEBUG, 'PLUGIN_LOG', logger, name, logLevel),
21
- error: (e) => error(logPluginError(normalizeLog(e), name, { hook: 'onLog' })),
22
- info: getLogHandler(LOG_LEVEL_INFO, 'PLUGIN_LOG', logger, name, logLevel),
23
- meta: {
24
- rollupVersion: '4.23.0',
25
- rolldownVersion: VERSION,
26
- watchMode: false,
27
- },
28
- warn: getLogHandler(LOG_LEVEL_WARN, 'PLUGIN_WARNING', logger, name, logLevel),
29
- pluginName: name,
30
- }, inputOptions);
31
- if (result) {
32
- inputOptions = result;
33
- }
34
- }
35
- }
36
- return inputOptions;
37
- }
38
- static callOutputOptionsHook(rawPlugins, outputOptions) {
39
- const sortedPlugins = getSortedPlugins('outputOptions', getObjectPlugins(rawPlugins));
40
- for (const plugin of sortedPlugins) {
41
- const options = plugin.outputOptions;
42
- if (options) {
43
- const { handler } = normalizeHook(options);
44
- const result = handler.call(null, outputOptions);
45
- if (result) {
46
- outputOptions = result;
47
- }
48
- }
49
- }
50
- return outputOptions;
51
- }
52
- }
53
- export function getObjectPlugins(plugins) {
54
- return plugins.filter((plugin) => {
55
- if (!plugin) {
56
- return undefined;
57
- }
58
- if ('_parallel' in plugin) {
59
- return undefined;
60
- }
61
- if (plugin instanceof BuiltinPlugin) {
62
- return undefined;
63
- }
64
- return plugin;
65
- });
66
- }
67
- export function getSortedPlugins(hookName, plugins) {
68
- const pre = [];
69
- const normal = [];
70
- const post = [];
71
- for (const plugin of plugins) {
72
- const hook = plugin[hookName];
73
- if (hook) {
74
- if (typeof hook === 'object') {
75
- if (hook.order === 'pre') {
76
- pre.push(plugin);
77
- continue;
78
- }
79
- if (hook.order === 'post') {
80
- post.push(plugin);
81
- continue;
82
- }
83
- }
84
- normal.push(plugin);
85
- }
86
- }
87
- return [...pre, ...normal, ...post];
88
- }