rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.2-commit.afd0727
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 +981 -25
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +981 -26
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{binding-Bl7VQy7c.mjs → binding-l7VLSKnB.mjs} +3 -3
- package/dist/shared/{binding-fhgdIkpS.cjs → binding-orkvONpS.cjs} +3 -3
- package/dist/shared/prompt-B7tq3GL9.cjs +854 -0
- package/dist/shared/prompt-Nfm4Xz36.mjs +851 -0
- package/dist/shared/{src-lBcHSsjm.cjs → src-Db20iysW.cjs} +12 -6
- package/dist/shared/{src-CPCP99Z9.mjs → src-mclDryX0.mjs} +12 -6
- package/dist/types/api/build.js +22 -0
- package/dist/types/api/experimental.js +13 -0
- package/dist/types/api/rolldown/index.js +7 -0
- package/dist/types/api/rolldown/rolldown-build.js +43 -0
- package/dist/types/api/watch/index.js +8 -0
- package/dist/types/api/watch/watch-emitter.js +69 -0
- package/dist/types/api/watch/watcher.js +66 -0
- package/dist/types/binding.d.ts +40 -2
- package/dist/types/builtin-plugin/alias-plugin.js +4 -0
- package/dist/types/builtin-plugin/constructors.d.ts +2 -2
- package/dist/types/builtin-plugin/constructors.js +68 -0
- package/dist/types/builtin-plugin/replace-plugin.js +29 -0
- package/dist/types/builtin-plugin/transform-plugin.js +16 -0
- package/dist/types/builtin-plugin/utils.js +19 -0
- package/dist/types/cli/arguments/alias.js +63 -0
- package/dist/types/cli/arguments/index.js +127 -0
- package/dist/types/cli/arguments/normalize.js +48 -0
- package/dist/types/cli/arguments/utils.js +67 -0
- package/dist/types/cli/colors.js +17 -0
- package/dist/types/cli/commands/bundle.js +203 -0
- package/dist/types/cli/commands/help.js +88 -0
- package/dist/types/cli/index.js +27 -0
- package/dist/types/cli/load-config.js +95 -0
- package/dist/types/cli/logger.js +35 -0
- package/dist/types/constants/plugin-context.js +7 -0
- package/dist/types/constants/plugin.js +69 -0
- package/dist/types/experimental-index.js +9 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +7 -0
- package/dist/types/log/logHandler.js +25 -0
- package/dist/types/log/logger.js +107 -0
- package/dist/types/log/logging.js +11 -0
- package/dist/types/log/logs.js +86 -0
- package/dist/types/options/input-options.d.ts +47 -2
- package/dist/types/options/input-options.js +1 -0
- package/dist/types/options/normalized-input-options.js +21 -0
- package/dist/types/options/normalized-output-options.js +99 -0
- package/dist/types/options/output-options.d.ts +6 -0
- package/dist/types/options/output-options.js +1 -0
- package/dist/types/options/watch-options.js +1 -0
- package/dist/types/parallel-plugin-worker.js +31 -0
- package/dist/types/parallel-plugin.js +1 -0
- package/dist/types/parse-ast-index.js +73 -0
- package/dist/types/plugin/bindingify-build-hooks.js +213 -0
- package/dist/types/plugin/bindingify-hook-filter.js +39 -0
- package/dist/types/plugin/bindingify-output-hooks.js +189 -0
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +19 -0
- package/dist/types/plugin/bindingify-plugin.js +124 -0
- package/dist/types/plugin/bindingify-watch-hooks.js +29 -0
- package/dist/types/plugin/hook-filter.js +1 -0
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/minimal-plugin-context.js +25 -0
- package/dist/types/plugin/parallel-plugin-implementation.js +3 -0
- package/dist/types/plugin/parallel-plugin.js +6 -0
- package/dist/types/plugin/plugin-context-data.js +55 -0
- package/dist/types/plugin/plugin-context.js +108 -0
- package/dist/types/plugin/plugin-driver.js +88 -0
- package/dist/types/plugin/transform-plugin-context.js +37 -0
- package/dist/types/types/assert.js +1 -0
- package/dist/types/types/config-export.js +1 -0
- package/dist/types/types/misc.js +1 -0
- package/dist/types/types/module-info.js +1 -0
- package/dist/types/types/module-side-effects.js +1 -0
- package/dist/types/types/output-bundle.js +1 -0
- package/dist/types/types/rolldown-options.js +1 -0
- package/dist/types/types/rolldown-output.js +1 -0
- package/dist/types/types/schema.js +1 -0
- package/dist/types/types/sourcemap.js +16 -0
- package/dist/types/types/utils.js +1 -0
- package/dist/types/utils/asset-source.js +8 -0
- package/dist/types/utils/async-flatten.js +7 -0
- package/dist/types/utils/bindingify-input-options.js +225 -0
- package/dist/types/utils/bindingify-output-options.js +92 -0
- package/dist/types/utils/code-frame.js +46 -0
- package/dist/types/utils/compose-js-plugins.js +400 -0
- package/dist/types/utils/create-bundler-option.js +53 -0
- package/dist/types/utils/create-bundler.js +15 -0
- package/dist/types/utils/define-config.js +3 -0
- package/dist/types/utils/error.js +65 -0
- package/dist/types/utils/initialize-parallel-plugins.js +54 -0
- package/dist/types/utils/misc.js +22 -0
- package/dist/types/utils/normalize-hook.js +21 -0
- package/dist/types/utils/normalize-plugin-option.js +35 -0
- package/dist/types/utils/normalize-string-or-regex.js +14 -0
- package/dist/types/utils/plugin/index.js +7 -0
- package/dist/types/utils/transform-module-info.js +19 -0
- package/dist/types/utils/transform-rendered-chunk.js +43 -0
- package/dist/types/utils/transform-rendered-module.js +10 -0
- package/dist/types/utils/transform-side-effects.js +16 -0
- package/dist/types/utils/transform-sourcemap.js +29 -0
- package/dist/types/utils/transform-to-rollup-output.js +165 -0
- package/dist/types/utils/validator.js +275 -0
- package/package.json +28 -25
- package/dist/shared/consola_36c0034f-Cx52UqEq.mjs +0 -832
- package/dist/shared/consola_36c0034f-CynBWXXO.cjs +0 -859
- package/dist/shared/prompt-B58MxVuU.cjs +0 -762
- package/dist/shared/prompt-DjjlOckE.mjs +0 -758
- package/dist/tsconfig.dts.tsbuildinfo +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
2
|
+
import { availableParallelism } from 'node:os';
|
|
3
|
+
import { ParallelJsPluginRegistry } from '../binding';
|
|
4
|
+
export async function initializeParallelPlugins(plugins) {
|
|
5
|
+
const pluginInfos = [];
|
|
6
|
+
for (const [index, plugin] of plugins.entries()) {
|
|
7
|
+
if ('_parallel' in plugin) {
|
|
8
|
+
const { fileUrl, options } = plugin._parallel;
|
|
9
|
+
pluginInfos.push({ index, fileUrl, options });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (pluginInfos.length <= 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const count = Math.min(availableParallelism(), 8);
|
|
16
|
+
const parallelJsPluginRegistry = new ParallelJsPluginRegistry(count);
|
|
17
|
+
const registryId = parallelJsPluginRegistry.id;
|
|
18
|
+
const workers = await initializeWorkers(registryId, count, pluginInfos);
|
|
19
|
+
const stopWorkers = async () => {
|
|
20
|
+
await Promise.all(workers.map((worker) => worker.terminate()));
|
|
21
|
+
};
|
|
22
|
+
return { registry: parallelJsPluginRegistry, stopWorkers };
|
|
23
|
+
}
|
|
24
|
+
export function initializeWorkers(registryId, count, pluginInfos) {
|
|
25
|
+
return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
|
|
26
|
+
}
|
|
27
|
+
async function initializeWorker(registryId, pluginInfos, threadNumber) {
|
|
28
|
+
const urlString = import.meta.resolve('#parallel-plugin-worker');
|
|
29
|
+
const workerData = {
|
|
30
|
+
registryId,
|
|
31
|
+
pluginInfos,
|
|
32
|
+
threadNumber,
|
|
33
|
+
};
|
|
34
|
+
let worker;
|
|
35
|
+
try {
|
|
36
|
+
worker = new Worker(new URL(urlString), { workerData });
|
|
37
|
+
worker.unref();
|
|
38
|
+
await new Promise((resolve, reject) => {
|
|
39
|
+
worker.once('message', async (message) => {
|
|
40
|
+
if (message.type === 'error') {
|
|
41
|
+
reject(message.error);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
resolve();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return worker;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
worker?.terminate();
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function arraify(value) {
|
|
2
|
+
return Array.isArray(value) ? value : [value];
|
|
3
|
+
}
|
|
4
|
+
export function isNullish(value) {
|
|
5
|
+
return value === null || value === undefined;
|
|
6
|
+
}
|
|
7
|
+
export function unimplemented(info) {
|
|
8
|
+
if (info) {
|
|
9
|
+
throw new Error(`unimplemented: ${info}`);
|
|
10
|
+
}
|
|
11
|
+
throw new Error('unimplemented');
|
|
12
|
+
}
|
|
13
|
+
export function unreachable(info) {
|
|
14
|
+
if (info) {
|
|
15
|
+
throw new Error(`unreachable: ${info}`);
|
|
16
|
+
}
|
|
17
|
+
throw new Error('unreachable');
|
|
18
|
+
}
|
|
19
|
+
export function unsupported(info) {
|
|
20
|
+
throw new Error(`UNSUPPORTED: ${info}`);
|
|
21
|
+
}
|
|
22
|
+
export function noop(..._args) { }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { unreachable } from './misc';
|
|
2
|
+
export function normalizeHook(hook) {
|
|
3
|
+
if (typeof hook === 'function' || typeof hook === 'string') {
|
|
4
|
+
return {
|
|
5
|
+
handler: hook,
|
|
6
|
+
options: {},
|
|
7
|
+
meta: {},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (typeof hook === 'object' && hook !== null) {
|
|
11
|
+
const { handler, order, ...options } = hook;
|
|
12
|
+
return {
|
|
13
|
+
handler,
|
|
14
|
+
options,
|
|
15
|
+
meta: {
|
|
16
|
+
order,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
unreachable('Invalid hook type');
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { asyncFlatten } from './async-flatten';
|
|
2
|
+
import { ENUMERATED_INPUT_PLUGIN_HOOK_NAMES } from '../constants/plugin';
|
|
3
|
+
import { logInputHookInOutputPlugin } from '../log/logs';
|
|
4
|
+
import { LOG_LEVEL_WARN } from '../log/logging';
|
|
5
|
+
import { BuiltinPlugin } from '../builtin-plugin/constructors';
|
|
6
|
+
export const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
|
|
7
|
+
export function checkOutputPluginOption(plugins, onLog) {
|
|
8
|
+
for (const plugin of plugins) {
|
|
9
|
+
for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) {
|
|
10
|
+
if (hook in plugin) {
|
|
11
|
+
// remove the hook from the plugin if it is not an output plugin hook, avoid the plugin to be called
|
|
12
|
+
// @ts-expect-error Here the plugin typing should be RolldownPlugin
|
|
13
|
+
delete plugin[hook];
|
|
14
|
+
onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return plugins;
|
|
19
|
+
}
|
|
20
|
+
export function normalizePlugins(plugins, anonymousPrefix) {
|
|
21
|
+
for (const [index, plugin] of plugins.entries()) {
|
|
22
|
+
if ('_parallel' in plugin) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (plugin instanceof BuiltinPlugin) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!plugin.name) {
|
|
29
|
+
plugin.name = `${anonymousPrefix}${index + 1}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return plugins;
|
|
33
|
+
}
|
|
34
|
+
export const ANONYMOUS_PLUGIN_PREFIX = 'at position ';
|
|
35
|
+
export const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = 'at output position ';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Normalize single or multiple string or regex patterns to an array of BindingStringOrRegex
|
|
3
|
+
* convert a type that is dx friendly to a type that is friendly for binding usage
|
|
4
|
+
*
|
|
5
|
+
* */
|
|
6
|
+
export function normalizedStringOrRegex(pattern) {
|
|
7
|
+
if (!pattern) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(pattern)) {
|
|
11
|
+
pattern = [pattern];
|
|
12
|
+
}
|
|
13
|
+
return pattern;
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ENUMERATED_PLUGIN_HOOK_NAMES, } from '../../constants/plugin';
|
|
2
|
+
export const isPluginHookName = (function () {
|
|
3
|
+
const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
|
|
4
|
+
return function isPluginHookName(hookName) {
|
|
5
|
+
return PLUGIN_HOOK_NAMES_SET.has(hookName);
|
|
6
|
+
};
|
|
7
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { unsupported } from './misc';
|
|
2
|
+
export function transformModuleInfo(info, option) {
|
|
3
|
+
return {
|
|
4
|
+
get ast() {
|
|
5
|
+
return unsupported('ModuleInfo#ast');
|
|
6
|
+
},
|
|
7
|
+
get code() {
|
|
8
|
+
return info.code;
|
|
9
|
+
},
|
|
10
|
+
id: info.id,
|
|
11
|
+
importers: info.importers,
|
|
12
|
+
dynamicImporters: info.dynamicImporters,
|
|
13
|
+
importedIds: info.importedIds,
|
|
14
|
+
dynamicallyImportedIds: info.dynamicallyImportedIds,
|
|
15
|
+
exports: info.exports,
|
|
16
|
+
isEntry: info.isEntry,
|
|
17
|
+
...option,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { transformToRenderedModule } from './transform-rendered-module';
|
|
2
|
+
export function transformRenderedChunk(chunk) {
|
|
3
|
+
return {
|
|
4
|
+
get name() {
|
|
5
|
+
return chunk.name;
|
|
6
|
+
},
|
|
7
|
+
get isEntry() {
|
|
8
|
+
return chunk.isEntry;
|
|
9
|
+
},
|
|
10
|
+
get isDynamicEntry() {
|
|
11
|
+
return chunk.isDynamicEntry;
|
|
12
|
+
},
|
|
13
|
+
get facadeModuleId() {
|
|
14
|
+
return chunk.facadeModuleId;
|
|
15
|
+
},
|
|
16
|
+
get moduleIds() {
|
|
17
|
+
return chunk.moduleIds;
|
|
18
|
+
},
|
|
19
|
+
get exports() {
|
|
20
|
+
return chunk.exports;
|
|
21
|
+
},
|
|
22
|
+
get fileName() {
|
|
23
|
+
return chunk.fileName;
|
|
24
|
+
},
|
|
25
|
+
get imports() {
|
|
26
|
+
return chunk.imports;
|
|
27
|
+
},
|
|
28
|
+
get dynamicImports() {
|
|
29
|
+
return chunk.dynamicImports;
|
|
30
|
+
},
|
|
31
|
+
get modules() {
|
|
32
|
+
return transformChunkModules(chunk.modules);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function transformChunkModules(modules) {
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [id, index] of Object.entries(modules.idToIndex)) {
|
|
39
|
+
let mod = modules.value[index];
|
|
40
|
+
result[id] = transformToRenderedModule(mod);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BindingHookSideEffects } from '../binding';
|
|
2
|
+
export function bindingifySideEffects(sideEffects) {
|
|
3
|
+
switch (sideEffects) {
|
|
4
|
+
case true:
|
|
5
|
+
return BindingHookSideEffects.True;
|
|
6
|
+
case false:
|
|
7
|
+
return BindingHookSideEffects.False;
|
|
8
|
+
case 'no-treeshake':
|
|
9
|
+
return BindingHookSideEffects.NoTreeshake;
|
|
10
|
+
case null:
|
|
11
|
+
case undefined:
|
|
12
|
+
return undefined;
|
|
13
|
+
default:
|
|
14
|
+
throw new Error(`Unexpected side effects: ${sideEffects}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function isEmptySourcemapFiled(array) {
|
|
2
|
+
if (!array) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (array.length === 0 || !array[0] /* null or '' */) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
export function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
|
|
11
|
+
if (!rawMap) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// If sourcemap hasn't `sourcesContent` and `sources`, using original code to fill it.
|
|
15
|
+
// The rust side already has the feature at `crates/rolldown_plugin/src/plugin_driver/build_hooks.rs#transform`.
|
|
16
|
+
// but it could be failed at `rolldown_sourcemap::SourceMap::from_json`, because the map is invalid.
|
|
17
|
+
let map = typeof rawMap === 'object'
|
|
18
|
+
? rawMap
|
|
19
|
+
: JSON.parse(rawMap);
|
|
20
|
+
if (isEmptySourcemapFiled(map.sourcesContent)) {
|
|
21
|
+
map.sourcesContent = [originalCode];
|
|
22
|
+
}
|
|
23
|
+
if (isEmptySourcemapFiled(map.sources) ||
|
|
24
|
+
(map.sources && map.sources.length === 1 && map.sources[0] !== id) // the transform sourcemaps maybe contain multiple sources
|
|
25
|
+
) {
|
|
26
|
+
map.sources = [id];
|
|
27
|
+
}
|
|
28
|
+
return map;
|
|
29
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { bindingAssetSource, transformAssetSource, } from './asset-source';
|
|
2
|
+
import { bindingifySourcemap } from '../types/sourcemap';
|
|
3
|
+
import { normalizeErrors } from './error';
|
|
4
|
+
import { transformChunkModules } from './transform-rendered-chunk';
|
|
5
|
+
import { Buffer } from 'node:buffer';
|
|
6
|
+
function transformToRollupSourceMap(map) {
|
|
7
|
+
const parsed = JSON.parse(map);
|
|
8
|
+
const obj = {
|
|
9
|
+
...parsed,
|
|
10
|
+
toString() {
|
|
11
|
+
return JSON.stringify(obj);
|
|
12
|
+
},
|
|
13
|
+
toUrl() {
|
|
14
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), 'utf-8').toString('base64')}`;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
function transformToRollupOutputChunk(bindingChunk, changed) {
|
|
20
|
+
const chunk = {
|
|
21
|
+
type: 'chunk',
|
|
22
|
+
get code() {
|
|
23
|
+
return bindingChunk.code;
|
|
24
|
+
},
|
|
25
|
+
fileName: bindingChunk.fileName,
|
|
26
|
+
name: bindingChunk.name,
|
|
27
|
+
get modules() {
|
|
28
|
+
return transformChunkModules(bindingChunk.modules);
|
|
29
|
+
},
|
|
30
|
+
get imports() {
|
|
31
|
+
return bindingChunk.imports;
|
|
32
|
+
},
|
|
33
|
+
get dynamicImports() {
|
|
34
|
+
return bindingChunk.dynamicImports;
|
|
35
|
+
},
|
|
36
|
+
exports: bindingChunk.exports,
|
|
37
|
+
isEntry: bindingChunk.isEntry,
|
|
38
|
+
facadeModuleId: bindingChunk.facadeModuleId || null,
|
|
39
|
+
isDynamicEntry: bindingChunk.isDynamicEntry,
|
|
40
|
+
get moduleIds() {
|
|
41
|
+
return bindingChunk.moduleIds;
|
|
42
|
+
},
|
|
43
|
+
get map() {
|
|
44
|
+
return bindingChunk.map
|
|
45
|
+
? transformToRollupSourceMap(bindingChunk.map)
|
|
46
|
+
: null;
|
|
47
|
+
},
|
|
48
|
+
sourcemapFileName: bindingChunk.sourcemapFileName || null,
|
|
49
|
+
preliminaryFileName: bindingChunk.preliminaryFileName,
|
|
50
|
+
};
|
|
51
|
+
const cache = {};
|
|
52
|
+
return new Proxy(chunk, {
|
|
53
|
+
get(target, p) {
|
|
54
|
+
if (p in cache) {
|
|
55
|
+
return cache[p];
|
|
56
|
+
}
|
|
57
|
+
return target[p];
|
|
58
|
+
},
|
|
59
|
+
set(target, p, newValue) {
|
|
60
|
+
cache[p] = newValue;
|
|
61
|
+
changed?.updated.add(bindingChunk.fileName);
|
|
62
|
+
return true;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function transformToRollupOutputAsset(bindingAsset, changed) {
|
|
67
|
+
const asset = {
|
|
68
|
+
type: 'asset',
|
|
69
|
+
fileName: bindingAsset.fileName,
|
|
70
|
+
originalFileName: bindingAsset.originalFileName || null,
|
|
71
|
+
originalFileNames: bindingAsset.originalFileNames,
|
|
72
|
+
get source() {
|
|
73
|
+
return transformAssetSource(bindingAsset.source);
|
|
74
|
+
},
|
|
75
|
+
name: bindingAsset.name ?? undefined,
|
|
76
|
+
names: bindingAsset.names,
|
|
77
|
+
};
|
|
78
|
+
const cache = {};
|
|
79
|
+
return new Proxy(asset, {
|
|
80
|
+
get(target, p) {
|
|
81
|
+
if (p in cache) {
|
|
82
|
+
return cache[p];
|
|
83
|
+
}
|
|
84
|
+
return target[p];
|
|
85
|
+
},
|
|
86
|
+
set(target, p, newValue) {
|
|
87
|
+
cache[p] = newValue;
|
|
88
|
+
changed?.updated.add(bindingAsset.fileName);
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export function transformToRollupOutput(output, changed) {
|
|
94
|
+
handleOutputErrors(output);
|
|
95
|
+
const { chunks, assets } = output;
|
|
96
|
+
return {
|
|
97
|
+
output: [
|
|
98
|
+
...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)),
|
|
99
|
+
...assets.map((asset) => transformToRollupOutputAsset(asset, changed)),
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function handleOutputErrors(output) {
|
|
104
|
+
const rawErrors = output.errors;
|
|
105
|
+
if (rawErrors.length > 0) {
|
|
106
|
+
throw normalizeErrors(rawErrors);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function transformToOutputBundle(output, changed) {
|
|
110
|
+
const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [
|
|
111
|
+
item.fileName,
|
|
112
|
+
item,
|
|
113
|
+
]));
|
|
114
|
+
return new Proxy(bundle, {
|
|
115
|
+
deleteProperty(target, property) {
|
|
116
|
+
if (typeof property === 'string') {
|
|
117
|
+
changed.deleted.add(property);
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// TODO find a way only transfer the changed part to rust side.
|
|
124
|
+
export function collectChangedBundle(changed, bundle) {
|
|
125
|
+
const assets = [];
|
|
126
|
+
const chunks = [];
|
|
127
|
+
for (const key in bundle) {
|
|
128
|
+
if (changed.deleted.has(key) || !changed.updated.has(key)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const item = bundle[key];
|
|
132
|
+
if (item.type === 'asset') {
|
|
133
|
+
assets.push({
|
|
134
|
+
filename: item.fileName,
|
|
135
|
+
originalFileNames: item.originalFileNames,
|
|
136
|
+
source: bindingAssetSource(item.source),
|
|
137
|
+
names: item.names,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
// not all properties modifications are reflected to rust side
|
|
142
|
+
chunks.push({
|
|
143
|
+
code: item.code,
|
|
144
|
+
filename: item.fileName,
|
|
145
|
+
name: item.name,
|
|
146
|
+
isEntry: item.isEntry,
|
|
147
|
+
exports: item.exports,
|
|
148
|
+
modules: {},
|
|
149
|
+
imports: item.imports,
|
|
150
|
+
dynamicImports: item.dynamicImports,
|
|
151
|
+
facadeModuleId: item.facadeModuleId || undefined,
|
|
152
|
+
isDynamicEntry: item.isDynamicEntry,
|
|
153
|
+
moduleIds: item.moduleIds,
|
|
154
|
+
map: bindingifySourcemap(item.map),
|
|
155
|
+
sourcemapFilename: item.sourcemapFileName || undefined,
|
|
156
|
+
preliminaryFilename: item.preliminaryFileName,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
assets,
|
|
162
|
+
chunks,
|
|
163
|
+
deleted: Array.from(changed.deleted),
|
|
164
|
+
};
|
|
165
|
+
}
|