From 9508598ba2c9511136dbbff6e78abc9f5ed82a06 Mon Sep 17 00:00:00 2001 From: shulan Date: Thu, 21 Nov 2024 09:39:14 +0800 Subject: [PATCH] feat: improve module import compress (#1953) * feat: improve module import compress * fix: update test case & jsx for module concatenation example --- .../concatenate_module/circle/config.json | 8 + .../bundle/concatenate_module/circle/foo.ts | 4 + .../bundle/concatenate_module/circle/index.ts | 3 + .../concatenate_module/circle/output.js | 53 ++++ .../concatenate_module/circle/reexport.ts | 3 + .../concatenate_module/export/config.json | 6 + .../bundle/concatenate_module/export/index.ts | 3 + .../concatenate_module/export/output.js | 33 +++ .../concatenate_module/export/reexport.ts | 2 + .../export/doubleReexportAll/config.cjs.json | 5 + .../bundle/export/doubleReexportAll/foo.ts | 1 + .../bundle/export/doubleReexportAll/index.ts | 7 + .../export/doubleReexportAll/output.cjs.js | 96 +++++++ .../bundle/export/doubleReexportAll/output.js | 53 ++++ .../export/doubleReexportAll/reexport.ts | 5 + .../bundle/export/reexportExternal/foo.ts | 1 + .../bundle/export/reexportExternal/index.ts | 1 + .../bundle/export/reexportExternal/output.js | 14 + .../export/reexportExternal/reexport.ts | 2 + .../external/importNamespace/output.cjs.js | 1 - .../external/importNamespace/output.js | 2 +- .../library/reexport/esm/star/output.js | 6 - .../library/reexport/reexport/output.js | 5 - .../reexport_hybrid_cjs/default/output.js | 5 - .../reexport_hybrid_cjs/star/config.cjs.json | 6 + .../reexport_hybrid_cjs/star/output.cjs.js | 107 +++++++ .../reexport/use_external_reexport/output.js | 8 +- .../cjs/export/entryExportStar/output.js | 4 - .../bundle/export/entryExport3/output.js | 6 +- .../export/from_source/export_all/output.js | 5 - .../export/from_source/export_named/output.js | 32 ++- .../from_source/export_namespace/output.js | 5 - crates/core/src/module/module_graph.rs | 23 +- .../bundle/bundle_analyzer.rs | 272 ++++++++++-------- .../bundle/bundle_reference.rs | 240 +++++++--------- .../src/resource_pot_to_bundle/bundle/mod.rs | 66 +++-- .../bundle/reference.rs | 27 +- .../src/resource_pot_to_bundle/mod.rs | 1 + .../modules_analyzer/module_analyzer.rs | 70 +++-- .../resource_pot_to_bundle/targets/cjs/mod.rs | 5 + .../targets/cjs/patch.rs | 6 +- .../targets/cjs/util.rs | 4 +- .../targets/generate.rs | 28 +- .../src/resource_pot_to_bundle/uniq_name.rs | 105 ++++--- .../src/render_resource_pot/mod.rs | 11 +- .../src/render_resource_pot/scope_hoisting.rs | 19 +- crates/toolkit/src/script/mod.rs | 3 +- examples/module-concatenation/farm.config.ts | 4 +- pnpm-lock.yaml | 33 ++- 49 files changed, 997 insertions(+), 412 deletions(-) create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/circle/config.json create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/circle/foo.ts create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/circle/index.ts create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/circle/output.js create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/circle/reexport.ts create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/export/config.json create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/export/index.ts create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/export/output.js create mode 100644 crates/compiler/tests/fixtures/bundle/concatenate_module/export/reexport.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/config.cjs.json create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/foo.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/index.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.cjs.js create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.js create mode 100644 crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/reexport.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/reexportExternal/foo.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/reexportExternal/index.ts create mode 100644 crates/compiler/tests/fixtures/bundle/export/reexportExternal/output.js create mode 100644 crates/compiler/tests/fixtures/bundle/export/reexportExternal/reexport.ts create mode 100644 crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/config.cjs.json create mode 100644 crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/output.cjs.js diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/config.json b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/config.json new file mode 100644 index 0000000000..fc58f11aa3 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/config.json @@ -0,0 +1,8 @@ +{ + "concatenateModules": true, + "output": { + "targetEnv": "browser" + }, + "comments": true, + "minify": false +} \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/foo.ts b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/foo.ts new file mode 100644 index 0000000000..8f652274aa --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/foo.ts @@ -0,0 +1,4 @@ +import { reexport } from './reexport'; + + +export const foo = reexport + 'foo'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/index.ts b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/index.ts new file mode 100644 index 0000000000..3084b71bf1 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/index.ts @@ -0,0 +1,3 @@ +import * as ns from './reexport'; + +console.log(ns); \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/output.js b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/output.js new file mode 100644 index 0000000000..48d38073f7 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/output.js @@ -0,0 +1,53 @@ +//index.js: + window['__farm_default_namespace__'] = {__FARM_TARGET_ENV__: 'browser'};;((function(){// module_id: ../../../_internal/runtime/index.js.farm-runtime +function __commonJs(mod) { + var module; + return ()=>{ + if (module) { + return module.exports; + } + module = { + exports: {} + }; + if (typeof mod === "function") { + mod(module, module.exports); + } else { + mod[Object.keys(mod)[0]](module, module.exports); + } + return module.exports; + }; +} +var index_js_cjs = __commonJs({ + "../../../_internal/runtime/index.js.farm-runtime": (module, exports)=>{ + "use strict"; + console.log('runtime/index.js'); + window['__farm_default_namespace__'].__farm_module_system__.setPlugins([]); + } +}); +index_js_cjs(); +})());(function(_){for(var r in _){_[r].__farm_resource_pot__='index_830e.js';window['__farm_default_namespace__'].__farm_module_system__.register(r,_[r])}})({"foo.ts":function (module, exports, farmRequire, farmDynamicRequire) { + module._m(exports); + module.o(exports, "foo", function() { + return foo; + }); + var _f_reexport = farmRequire("reexport.ts"); + var foo = _f_reexport.reexport + 'foo'; +} +, +"index.ts":function (module, exports, farmRequire, farmDynamicRequire) { + module._m(exports); + var _f_reexport = module.w(farmRequire("reexport.ts")); + var ns = _f_reexport; + console.log(ns); +} +, +"reexport.ts":function (module, exports, farmRequire, farmDynamicRequire) { + module._m(exports); + module.o(exports, "reexport", function() { + return reexport; + }); + var reexport = 'reexport'; + var _f_foo = farmRequire("foo.ts"); + module._e(exports, _f_foo); +} +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("index.ts"); \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/reexport.ts b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/reexport.ts new file mode 100644 index 0000000000..de4f783757 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/circle/reexport.ts @@ -0,0 +1,3 @@ + +export const reexport = 'reexport'; +export * from './foo'; diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/export/config.json b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/config.json new file mode 100644 index 0000000000..d376774c4e --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/config.json @@ -0,0 +1,6 @@ +{ + "concatenateModules": true, + "output": { + "targetEnv": "browser" + } +} \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/export/index.ts b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/index.ts new file mode 100644 index 0000000000..d165b1eaae --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/index.ts @@ -0,0 +1,3 @@ +import { createEmotion } from './reexport'; + +console.log(createEmotion); diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/export/output.js b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/output.js new file mode 100644 index 0000000000..e44d78495a --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/output.js @@ -0,0 +1,33 @@ +//index.js: + window['__farm_default_namespace__'] = {__FARM_TARGET_ENV__: 'browser'};;((function(){// module_id: ../../../_internal/runtime/index.js.farm-runtime +function __commonJs(mod) { + var module; + return ()=>{ + if (module) { + return module.exports; + } + module = { + exports: {} + }; + if (typeof mod === "function") { + mod(module, module.exports); + } else { + mod[Object.keys(mod)[0]](module, module.exports); + } + return module.exports; + }; +} +var index_js_cjs = __commonJs({ + "../../../_internal/runtime/index.js.farm-runtime": (module, exports)=>{ + "use strict"; + console.log('runtime/index.js'); + window['__farm_default_namespace__'].__farm_module_system__.setPlugins([]); + } +}); +index_js_cjs(); +})());(function(_){for(var r in _){_[r].__farm_resource_pot__='index_b752.js';window['__farm_default_namespace__'].__farm_module_system__.register(r,_[r])}})({"index.ts":function (module, exports, farmRequire, farmDynamicRequire) { + module._m(exports); + var _f_xxx = farmRequire("xxx"); + console.log(_f_xxx.default); +} +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("index.ts"); \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/concatenate_module/export/reexport.ts b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/reexport.ts new file mode 100644 index 0000000000..ad41e147eb --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/concatenate_module/export/reexport.ts @@ -0,0 +1,2 @@ +// @ts-ignore +export { default as createEmotion } from 'xxx'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/config.cjs.json b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/config.cjs.json new file mode 100644 index 0000000000..a54e6cace5 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/config.cjs.json @@ -0,0 +1,5 @@ +{ + "output": { + "format": "cjs" + } +} \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/foo.ts b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/foo.ts new file mode 100644 index 0000000000..6e0a357a60 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/foo.ts @@ -0,0 +1 @@ +export { Worker } from './reexport'; diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/index.ts b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/index.ts new file mode 100644 index 0000000000..e2a0cb45c4 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/index.ts @@ -0,0 +1,7 @@ + +import { readFile } from './reexport'; +import { Worker } from './foo' + +console.log({ readFile, Worker }); + +export * from './reexport'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.cjs.js b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.cjs.js new file mode 100644 index 0000000000..e12bcba320 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.cjs.js @@ -0,0 +1,96 @@ +//farm_runtime.js: + // module_id: __FARM_BUNDLE_POLYFILL_SLOT__ +function __commonJs(mod) { + var module; + return ()=>{ + if (module) { + return module.exports; + } + module = { + exports: {} + }; + if (typeof mod === "function") { + mod(module, module.exports); + } else { + mod[Object.keys(mod)[0]](module, module.exports); + } + return module.exports; + }; +} +function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} +function _interop_require_wildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) return obj; + if (obj === null || typeof obj !== "object" && typeof obj !== "function") return { + default: obj + }; + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) return cache.get(obj); + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc); + else newObj[key] = obj[key]; + } + } + newObj.default = obj; + if (cache) cache.set(obj, newObj); + return newObj; +} +function _export_star(from, to) { + Object.keys(from).forEach(function(k) { + if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) { + Object.defineProperty(to, k, { + enumerable: true, + get: function() { + return from[k]; + } + }); + } + }); + return from; +} +module.exports.__commonJs = __commonJs; +module.exports._export_star = _export_star; +module.exports._interop_require_wildcard = _interop_require_wildcard; +Object.defineProperty(exports, "__esModule", { + value: true +}); + + +//index.js: + // module_id: reexport.ts +var farm_runtime_js_ns = require("./farm_runtime.js"); +var __commonJs = farm_runtime_js_ns.__commonJs, _export_star = farm_runtime_js_ns._export_star, _interop_require_wildcard = farm_runtime_js_ns._interop_require_wildcard; +var reexport_cjs = __commonJs({ + "reexport.ts": (module, exports)=>{ + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _export_star(require("node:fs"), exports); + _export_star(require("node:cluster"), exports); + const readFile = 123; + module.exports.name = 123; + } +}); +var reexport_ns = _interop_require_wildcard(reexport_cjs()), Worker = reexport_cjs()["Worker"], readFile = reexport_cjs()["readFile"]; + +// module_id: foo.ts + +// module_id: index.ts +console.log({ + readFile: readFile, + Worker: Worker +}); +_export_star(reexport_ns, module.exports); diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.js b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.js new file mode 100644 index 0000000000..1b957a730f --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.js @@ -0,0 +1,53 @@ +//farm_runtime.js: + // module_id: __FARM_BUNDLE_POLYFILL_SLOT__ +function __commonJs(mod) { + var module; + return ()=>{ + if (module) { + return module.exports; + } + module = { + exports: {} + }; + if (typeof mod === "function") { + mod(module, module.exports); + } else { + mod[Object.keys(mod)[0]](module, module.exports); + } + return module.exports; + }; +} +import __farmNodeModule from 'module'; +var __nodeRequireInstance = __farmNodeModule.createRequire(import.meta.url); +function _nodeRequire() { + return __nodeRequireInstance.apply(null, arguments); +} +export { __commonJs, _nodeRequire }; + + +//index.js: + // module_id: reexport.ts +import { __commonJs, _nodeRequire } from "./farm_runtime.js"; +var reexport_cjs = __commonJs({ + "reexport.ts": (module, exports)=>{ + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + _export_star(_nodeRequire("node:fs"), exports); + _export_star(_nodeRequire("node:cluster"), exports); + const readFile = 123; + module.exports.name = 123; + } +}); +var Worker = reexport_cjs()["Worker"], readFile = reexport_cjs()["readFile"]; + +// module_id: foo.ts + +// module_id: index.ts +console.log({ + readFile: readFile, + Worker: Worker +}); +export * from "node:cluster"; +export * from "node:fs"; diff --git a/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/reexport.ts b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/reexport.ts new file mode 100644 index 0000000000..09cbdc7b00 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/reexport.ts @@ -0,0 +1,5 @@ +export * from 'node:fs'; +export * from 'node:cluster'; + +const readFile = 123; +module.exports.name = 123; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/reexportExternal/foo.ts b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/foo.ts new file mode 100644 index 0000000000..f4596d5406 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/foo.ts @@ -0,0 +1 @@ +export const foo = 'foo'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/reexportExternal/index.ts b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/index.ts new file mode 100644 index 0000000000..66662bf8a4 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/index.ts @@ -0,0 +1 @@ +export * from './reexport'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/export/reexportExternal/output.js b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/output.js new file mode 100644 index 0000000000..477db36232 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/output.js @@ -0,0 +1,14 @@ +//farm_runtime.js: + // module_id: __FARM_BUNDLE_POLYFILL_SLOT__ + + +//index.js: + // module_id: foo.ts +import { readFile } from "node:fs"; +const foo = 'foo'; + +// module_id: reexport.ts + +// module_id: index.ts +export { foo as bar }; +export { readFile as rf } from "node:fs"; diff --git a/crates/compiler/tests/fixtures/bundle/export/reexportExternal/reexport.ts b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/reexport.ts new file mode 100644 index 0000000000..1b7b69ce19 --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/export/reexportExternal/reexport.ts @@ -0,0 +1,2 @@ +export { readFile as rf } from 'node:fs'; +export { foo as bar } from './foo'; \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.cjs.js b/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.cjs.js index 9ecaeea132..61d139a305 100644 --- a/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.cjs.js +++ b/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.cjs.js @@ -47,7 +47,6 @@ Object.defineProperty(exports, "__esModule", { var farm_runtime_js_ns = require("./farm_runtime.js"); var _interop_require_default = farm_runtime_js_ns._interop_require_default, _interop_require_wildcard = farm_runtime_js_ns._interop_require_wildcard; var node_fs_ns = _interop_require_wildcard(require("node:fs")); -var node_fs_ns = require("node:fs"); var fs$1 = _interop_require_default(node_fs_ns).default; const fs = 'a.ts'; console.log(fs); diff --git a/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.js b/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.js index 3f3db2e961..63444e0925 100644 --- a/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.js +++ b/crates/compiler/tests/fixtures/bundle/library/external/importNamespace/output.js @@ -4,8 +4,8 @@ //index.js: // module_id: a.ts -import * as node_fs_ns from "node:fs"; import fs$1 from "node:fs"; +import * as node_fs_ns from "node:fs"; const fs = 'a.ts'; console.log(fs); var a_default = 'a.ts'; diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/esm/star/output.js b/crates/compiler/tests/fixtures/bundle/library/reexport/esm/star/output.js index 2906dc539b..eb92c361c2 100644 --- a/crates/compiler/tests/fixtures/bundle/library/reexport/esm/star/output.js +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/esm/star/output.js @@ -7,12 +7,6 @@ var foo_default = 'foo'; const foo = 'foo'; const bar = 'bar'; -var foo_ns = { - bar: bar, - foo: foo, - "default": foo_default, - __esModule: true -}; // module_id: index.ts export { bar, foo, foo_default as default }; diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport/output.js b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport/output.js index 22a4e6214c..d7dddc2f7e 100644 --- a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport/output.js +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport/output.js @@ -6,11 +6,6 @@ // module_id: reexport.ts import { default as Foo1 } from "foo1"; import { default as Foo2 } from "foo2"; -var reexport_ns = { - Foo2: Foo2, - Foo1: Foo1, - __esModule: true -}; // module_id: index.ts const Foo1 = '123'; diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/default/output.js b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/default/output.js index 1fee85dc98..cb89a80a0e 100644 --- a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/default/output.js +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/default/output.js @@ -10,11 +10,6 @@ class foo { } } const bar = 'foo'; -var reexport_ns = { - bar: bar, - default: foo, - __esModule: true -}; // module_id: index.ts export { bar, foo as default }; diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/config.cjs.json b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/config.cjs.json new file mode 100644 index 0000000000..932c1085fb --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/config.cjs.json @@ -0,0 +1,6 @@ +{ + "output": { + "targetEnv": "library-node", + "format": "cjs" + } +} \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/output.cjs.js b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/output.cjs.js new file mode 100644 index 0000000000..cd8381c3da --- /dev/null +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/output.cjs.js @@ -0,0 +1,107 @@ +//farm_runtime.js: + // module_id: __FARM_BUNDLE_POLYFILL_SLOT__ +function __commonJs(mod) { + var module; + return ()=>{ + if (module) { + return module.exports; + } + module = { + exports: {} + }; + if (typeof mod === "function") { + mod(module, module.exports); + } else { + mod[Object.keys(mod)[0]](module, module.exports); + } + return module.exports; + }; +} +function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} +function _interop_require_wildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) return obj; + if (obj === null || typeof obj !== "object" && typeof obj !== "function") return { + default: obj + }; + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) return cache.get(obj); + var newObj = { + __proto__: null + }; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc); + else newObj[key] = obj[key]; + } + } + newObj.default = obj; + if (cache) cache.set(obj, newObj); + return newObj; +} +function _export_star(from, to) { + Object.keys(from).forEach(function(k) { + if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) { + Object.defineProperty(to, k, { + enumerable: true, + get: function() { + return from[k]; + } + }); + } + }); + return from; +} +module.exports.__commonJs = __commonJs; +module.exports._export_star = _export_star; +module.exports._interop_require_wildcard = _interop_require_wildcard; +Object.defineProperty(exports, "__esModule", { + value: true +}); + + +//index.js: + // module_id: foo.ts +var farm_runtime_js_ns = require("./farm_runtime.js"); +var __commonJs = farm_runtime_js_ns.__commonJs, _export_star = farm_runtime_js_ns._export_star, _interop_require_wildcard = farm_runtime_js_ns._interop_require_wildcard; +var foo_cjs = __commonJs({ + "foo.ts": (module, exports)=>{ + "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); + function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); + } + _export(exports, { + bar: function() { + return bar; + }, + default: function() { + return _default; + }, + foo: function() { + return foo; + } + }); + var _default = 'foo'; + const foo = 'foo'; + const bar = 'bar'; + module.exports.cjs = true; + } +}); +var foo_ns = _interop_require_wildcard(foo_cjs()); + +// module_id: index.ts +_export_star(foo_ns, module.exports); diff --git a/crates/compiler/tests/fixtures/bundle/library/reexport/use_external_reexport/output.js b/crates/compiler/tests/fixtures/bundle/library/reexport/use_external_reexport/output.js index 6d63e5d7fd..49c4bb5900 100644 --- a/crates/compiler/tests/fixtures/bundle/library/reexport/use_external_reexport/output.js +++ b/crates/compiler/tests/fixtures/bundle/library/reexport/use_external_reexport/output.js @@ -6,15 +6,15 @@ // module_id: reexport.ts import { foo } from "foo"; import { readFile } from "node:fs"; -import { unstable_batchedUpdates as unstable_batchedUpdates$1 } from "react-dom"; +import { unstable_batchedUpdates } from "react-dom"; // module_id: index.ts -const unstable_batchedUpdates = 123; +const unstable_batchedUpdates$1 = 123; console.log({ - unstable_batchedUpdates: unstable_batchedUpdates + unstable_batchedUpdates: unstable_batchedUpdates$1 }); console.log({ r1: readFile, foo: foo, - batch: unstable_batchedUpdates$1 + batch: unstable_batchedUpdates }); diff --git a/crates/compiler/tests/fixtures/runtime/bundle/cjs/export/entryExportStar/output.js b/crates/compiler/tests/fixtures/runtime/bundle/cjs/export/entryExportStar/output.js index f9c13cbea1..fa1bfd0066 100644 --- a/crates/compiler/tests/fixtures/runtime/bundle/cjs/export/entryExportStar/output.js +++ b/crates/compiler/tests/fixtures/runtime/bundle/cjs/export/entryExportStar/output.js @@ -65,10 +65,6 @@ var cjsExport_ts_cjs = __commonJs((module, exports)=>{ var cjsExport_ts_ns = _interop_require_wildcard(cjsExport_ts_cjs()); const foo = "foo"; -var esmExport_ts_ns = { - foo: foo, - __esModule: true -}; const esmName = 'repeat-esm-shulan'; global['__farm_default_namespace__'].__farm_module_system__.setPlugins([]); diff --git a/crates/compiler/tests/fixtures/runtime/bundle/export/entryExport3/output.js b/crates/compiler/tests/fixtures/runtime/bundle/export/entryExport3/output.js index 98aefc6500..ac8a576687 100644 --- a/crates/compiler/tests/fixtures/runtime/bundle/export/entryExport3/output.js +++ b/crates/compiler/tests/fixtures/runtime/bundle/export/entryExport3/output.js @@ -29,19 +29,19 @@ var exportAll_ts_ns = { const bundle2A = 'bundle2A'; const bundle2B = 'bundle2B'; -var bundle2_dep_ts_ns = { + +var exportOtherBundle_ts_ns = { bundle2A: bundle2A, bundle2B: bundle2B, __esModule: true }; -var exportOtherBundle_ts_ns = { +var bundle2_index_ts_ns = { bundle2A: bundle2A, bundle2B: bundle2B, __esModule: true }; - global['__farm_default_namespace__'].__farm_module_system__.setPlugins([]); (function(_){for(var r in _){_[r].__farm_resource_pot__='index_dcdc.js';global['__farm_default_namespace__'].__farm_module_system__.register(r,_[r])}})({"b5d64806":function (module, exports, farmRequire, farmDynamicRequire) {} ,});global['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);global['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = global['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); \ No newline at end of file diff --git a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_all/output.js b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_all/output.js index 981c50be7b..0aba30491e 100644 --- a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_all/output.js +++ b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_all/output.js @@ -24,11 +24,6 @@ var exportAll_ts_ns = _mergeNamespaces({ const bundle2A = 'bundle2A'; const bundle2B = 'bundle2B'; -var bundle2_dep_ts_ns = { - bundle2A: bundle2A, - bundle2B: bundle2B, - __esModule: true -}; var bundle2_index_ts_ns = { bundle2A: bundle2A, diff --git a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_named/output.js b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_named/output.js index 637d0ea951..38c3108000 100644 --- a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_named/output.js +++ b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_named/output.js @@ -1,13 +1,33 @@ //index.js: - import __farmNodeModule from 'node:module';global.nodeRequire = __farmNodeModule.createRequire(import.meta.url);global['__farm_default_namespace__'] = {__FARM_TARGET_ENV__: 'node'};import { readFileSync, readSync } from "node:fs.farm-runtime"; + import __farmNodeModule from 'node:module';global.nodeRequire = __farmNodeModule.createRequire(import.meta.url);global['__farm_default_namespace__'] = {__FARM_TARGET_ENV__: 'node'};function _mergeNamespaces(n, m) { + m.forEach(function(e) { + e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function(k) { + if (k !== 'default' && !(k in n)) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function() { + return e[k]; + } + }); + } + }); + }); + return Object.freeze(n); +} +import { readFileSync, readSync } from "node:fs.farm-runtime"; +import * as node_fs_ns from "node:fs.farm-runtime"; +var exportNamed_ts_ns = _mergeNamespaces({ + readFileSync: readFileSync, + readSync: readSync, + __esModule: true +}, [ + node_fs_ns +]); +var readFile = exportNamed_ts_ns["readFile"], writeFileSync = exportNamed_ts_ns["writeFileSync"]; const bundle2A = 'bundle2A'; const bundle2B = 'bundle2B'; -var bundle2_dep_ts_ns = { - bundle2A: bundle2A, - bundle2B: bundle2B, - __esModule: true -}; var bundle2_index_ts_ns = { bundle2A: bundle2A, diff --git a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_namespace/output.js b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_namespace/output.js index e4afd31048..197ab1f202 100644 --- a/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_namespace/output.js +++ b/crates/compiler/tests/fixtures/runtime/bundle/external/export/from_source/export_namespace/output.js @@ -40,11 +40,6 @@ var exportNamespace_ts_ns = { // module_id: bundle2-dep.ts.farm-runtime const bundle2A = 'bundle2A'; const bundle2B = 'bundle2B'; -var bundle2_dep_ts_ns = { - bundle2A: bundle2A, - bundle2B: bundle2B, - __esModule: true -}; // module_id: bundle2-index.ts.farm-runtime var bundle2_index_ts_ns = { diff --git a/crates/core/src/module/module_graph.rs b/crates/core/src/module/module_graph.rs index 7c6dffbc9c..88c6b1103d 100644 --- a/crates/core/src/module/module_graph.rs +++ b/crates/core/src/module/module_graph.rs @@ -101,6 +101,23 @@ impl ModuleGraphEdge { } } +#[derive(Debug, Default)] +pub struct CircleRecord { + sets: HashSet, +} + +impl CircleRecord { + pub fn new(circles: Vec>) -> Self { + Self { + sets: circles.into_iter().flatten().collect(), + } + } + + pub fn is_in_circle(&self, module_id: &ModuleId) -> bool { + self.sets.contains(module_id) + } +} + pub struct ModuleGraph { /// internal graph g: StableDiGraph, @@ -111,6 +128,7 @@ pub struct ModuleGraph { /// entry modules of this module graph. /// (Entry Module Id, Entry Name) pub entries: HashMap, + pub circle_record: CircleRecord, } impl ModuleGraph { @@ -120,6 +138,7 @@ impl ModuleGraph { id_index_map: HashMap::new(), file_module_ids_map: HashMap::new(), entries: HashMap::new(), + circle_record: CircleRecord::default(), } } @@ -562,7 +581,7 @@ impl ModuleGraph { } pub fn update_execution_order_for_modules(&mut self) { - let (mut topo_sorted_modules, _) = self.toposort(); + let (mut topo_sorted_modules, circles) = self.toposort(); topo_sorted_modules.reverse(); @@ -573,6 +592,8 @@ impl ModuleGraph { let module = self.module_mut(module_id).unwrap(); module.execution_order = order; }); + + self.circle_record = CircleRecord::new(circles); } pub fn internal_graph(&self) -> &StableDiGraph { diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_analyzer.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_analyzer.rs index b3afe0219a..99972fb532 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_analyzer.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_analyzer.rs @@ -16,7 +16,8 @@ use farmfe_core::{ error::{CompilationError, Result}, farm_profile_function, farm_profile_scope, module::{module_graph::ModuleGraph, ModuleId, ModuleSystem}, - resource::resource_pot::{ResourcePotId, ResourcePotType}, + plugin::ResolveKind, + resource::resource_pot::ResourcePotType, swc_common::{comments::SingleThreadedComments, util::take::Take}, }; use farmfe_toolkit::{ @@ -42,7 +43,7 @@ use crate::resource_pot_to_bundle::{ }; use super::{ - bundle_reference::{BundleReference, BundleReferenceManager}, + bundle_reference::{BundleReferenceManager, CombineBundleReference}, ModuleAnalyzerManager, }; @@ -247,8 +248,7 @@ impl<'a> BundleAnalyzer<'a> { }); let bundle_reference1 = bundle_reference_manager.reference_mut(&group_id); - let mut bundle_reference_1 = bundle_reference1.borrow_mut(); - let bundle_reference1 = bundle_reference_1.fetch_mut(module_id, module_analyzer_manager); + let mut bundle_reference1 = bundle_reference1.borrow_mut(); // reexport as namespace if module_analyzer_manager @@ -260,8 +260,11 @@ impl<'a> BundleAnalyzer<'a> { .module_global_uniq_name .namespace_name_result(module_id)?; - bundle_reference1 - .add_local_export(&ExportSpecifierInfo::Namespace(ns), module_system.clone()); + bundle_reference1.add_local_export( + &ExportSpecifierInfo::Namespace(ns), + module_system.clone(), + is_entry, + ); } let mut is_contain_export = false; @@ -316,8 +319,11 @@ impl<'a> BundleAnalyzer<'a> { let is_common_js = target.is_common_js(); match target { - FindModuleExportResult::Local(_, target_module_id, _) => { - if let Some(mut local) = module_analyzer_manager + FindModuleExportResult::Local { + source: target_module_id, + .. + } => { + if let Some(local) = module_analyzer_manager .module_global_uniq_name .namespace_name(&target_module_id) { @@ -380,12 +386,11 @@ impl<'a> BundleAnalyzer<'a> { let other_bundle_reference = bundle_reference_manager .reference_mut_by_module(&target_id, &module_analyzer_manager); let mut other_bundle_reference = other_bundle_reference.borrow_mut(); - let other_bundle_reference = - other_bundle_reference.fetch_mut(&target_id, module_analyzer_manager); other_bundle_reference.add_local_export( &ExportSpecifierInfo::Named((namespace).into()), module_system.clone(), + is_entry, ); import_rename = bundle_reference1.add_import( @@ -420,8 +425,13 @@ impl<'a> BundleAnalyzer<'a> { if let Some(target) = target { let is_common_js = target.is_common_js(); match target { - FindModuleExportResult::Local(mut index, target_source, _) => { - if is_common_js { + FindModuleExportResult::Local { + mut index, + source: target_source, + dynamic_reference, + .. + } => { + if is_common_js || dynamic_reference { index = bundle_reference1.add_declare_commonjs_import( specify, target_source.clone().into(), @@ -436,21 +446,18 @@ impl<'a> BundleAnalyzer<'a> { } FindModuleExportResult::External(index, target, _) => { - let mut rename = index; + let mut bundle_variable = self.bundle_variable.borrow_mut(); - // not reexport external - if target == import.source { - rename = bundle_reference1.add_import( - specify, - target.into(), - &self.bundle_variable.borrow(), - )?; - } + let rename = bundle_reference1.add_import( + &ImportSpecifierInfo::Named { + local: *local, + imported: Some(index), + }, + target.into(), + &bundle_variable, + )?; - self - .bundle_variable - .borrow_mut() - .set_uniq_name_both(rename, *local); + bundle_variable.set_uniq_name_both(rename, *local); } FindModuleExportResult::Bundle(index, target_id, _, _) => { @@ -517,7 +524,8 @@ impl<'a> BundleAnalyzer<'a> { // import person from "person" ImportSpecifierInfo::Default(default) => { - let target = self.bundle_variable.borrow().find_ident_by_index( + let mut bundle_variable = self.bundle_variable.borrow_mut(); + let target = bundle_variable.find_ident_by_index( *default, &import.source, module_analyzer_manager, @@ -529,9 +537,11 @@ impl<'a> BundleAnalyzer<'a> { if let Some(target) = target { let is_common_js = target.is_common_js(); match target { - FindModuleExportResult::Local(mut index, target_source, _) => { - let mut bundle_variable = self.bundle_variable.borrow_mut(); - + FindModuleExportResult::Local { + mut index, + source: target_source, + .. + } => { if is_common_js { index = bundle_reference1.add_declare_commonjs_import( specify, @@ -542,21 +552,21 @@ impl<'a> BundleAnalyzer<'a> { bundle_variable.set_uniq_name_both(index, *default); } - FindModuleExportResult::External(_, target, _) => { - let rename = bundle_reference1.add_import( - specify, - target.into(), - &self.bundle_variable.borrow(), - )?; + FindModuleExportResult::External(index, target, _) => { + let mut rename = index; - self - .bundle_variable - .borrow_mut() - .set_uniq_name_both(rename, *default); + if target == import.source { + rename = bundle_reference1.add_import( + &ImportSpecifierInfo::Default(index), + target.into(), + &bundle_variable, + )?; + } + + bundle_variable.set_uniq_name_both(rename, *default); } FindModuleExportResult::Bundle(target_default_index, target_id, _, _) => { - let mut bundle_variable = self.bundle_variable.borrow_mut(); let mut name = target_default_index; if is_common_js { @@ -637,8 +647,11 @@ impl<'a> BundleAnalyzer<'a> { .module_global_uniq_name .namespace_name(module_id) { - bundle_reference1 - .add_local_export(&ExportSpecifierInfo::Named(x.into()), module_system.clone()); + bundle_reference1.add_local_export( + &ExportSpecifierInfo::Named(x.into()), + module_system.clone(), + is_entry, + ); } } @@ -659,16 +672,17 @@ impl<'a> BundleAnalyzer<'a> { module_system: module_system.clone(), config: &options, module_id: &module_id, + is_entry, })?; } // export { name as personName } // export { name as personName } from './person'; ExportSpecifierInfo::Named(variable) => { + let mut bundle_variable = self.bundle_variable.borrow_mut(); if let Some(source) = &export.source { - let is_find_default = - self.bundle_variable.borrow().name(variable.local()) == "default"; - let target = self.bundle_variable.borrow_mut().find_ident_by_index( + let is_find_default = bundle_variable.is_default_key(variable.local()); + let target = bundle_variable.find_ident_by_index( variable.local(), source, module_analyzer_manager, @@ -676,7 +690,6 @@ impl<'a> BundleAnalyzer<'a> { is_find_default, false, ); - if let Some(target) = target { let is_common_js = target.is_common_js(); let mut is_confirmed_import = false; @@ -685,9 +698,14 @@ impl<'a> BundleAnalyzer<'a> { module_system.merge(target.module_system().unwrap_or(module_system.clone())); match target { - FindModuleExportResult::Local(local, target_source, _) => { + FindModuleExportResult::Local { + index: local, + source: target_source, + dynamic_reference, + .. + } => { is_confirmed_import = true; - let is_default_key = self.bundle_variable.borrow().is_default_key(local); + let is_default_key = bundle_variable.is_default_key(local); let name = if is_default_key { module_analyzer_manager @@ -697,8 +715,8 @@ impl<'a> BundleAnalyzer<'a> { local }; - if is_common_js { - self.bundle_variable.borrow_mut().set_var_uniq_rename(local); + if is_common_js || dynamic_reference { + bundle_variable.set_var_uniq_rename(local); bundle_reference1.add_declare_commonjs_import( &if is_default_key { @@ -713,7 +731,7 @@ impl<'a> BundleAnalyzer<'a> { } }, target_source.into(), - &self.bundle_variable.borrow(), + &bundle_variable, )?; } @@ -721,40 +739,59 @@ impl<'a> BundleAnalyzer<'a> { bundle_reference1.add_local_export( &ExportSpecifierInfo::Named(Variable(name, Some(variable.export_as()))), module_system, + is_entry, ); } } FindModuleExportResult::External(_, target_source, _) => { - let mut bundle_variable = self.bundle_variable.borrow_mut(); + // TODO: should used in + let is_reference_by_self_bundle = self + .module_graph + .dependents(&target_source) + .iter() + .any(|(m, edge)| { + module_analyzer_manager.is_same_bundle(module_id, m) + && edge.iter().any(|edge| { + matches!( + edge.kind, + ResolveKind::DynamicImport + | ResolveKind::Require + | ResolveKind::Import + | ResolveKind::ExportFrom + ) + }) + }); is_confirmed_import = true; if is_reference_by_another { bundle_reference1.add_reference_export( specify, - target_source.into(), + target_source.clone().into(), module_system, + is_entry, ); - } else { - let is_default = bundle_variable.is_default_key(variable.export_as()); + } - if is_default { + { + if !bundle_variable.is_default_key(variable.export_from()) { bundle_variable .set_uniq_name_both(variable.export_from(), variable.export_as()); } - bundle_reference1.add_import( - &ImportSpecifierInfo::Named { - local: variable.export_as(), - imported: Some(variable.export_from()), - }, - target_source.into(), - &bundle_variable, - )?; + if is_reference_by_self_bundle { + bundle_reference1.add_import( + &ImportSpecifierInfo::Named { + local: variable.export_as(), + imported: Some(variable.export_from()), + }, + target_source.into(), + &bundle_variable, + )?; + } } } FindModuleExportResult::Bundle(index, target_id, _, _) => { - let bundle_variable = self.bundle_variable.borrow_mut(); is_confirmed_import = true; let is_same_bundle = if is_common_js { module_analyzer_manager.is_same_bundle(module_id, &target_id) @@ -771,6 +808,7 @@ impl<'a> BundleAnalyzer<'a> { bundle_reference1.add_local_export( &ExportSpecifierInfo::Named((variable.local()).into()), module_system, + is_entry, ); } else { bundle_reference1.add_import( @@ -785,6 +823,7 @@ impl<'a> BundleAnalyzer<'a> { bundle_reference1.add_local_export( &ExportSpecifierInfo::Named((variable.local()).into()), module_system, + is_entry, ); } } @@ -795,17 +834,11 @@ impl<'a> BundleAnalyzer<'a> { } } } else { - self - .bundle_variable - .borrow_mut() - .set_var_uniq_rename(variable.local()); + bundle_variable.set_var_uniq_rename(variable.local()); if is_reference_by_another { if module_analyzer_manager.is_commonjs(module_id) { - let is_default_key = self - .bundle_variable - .borrow() - .is_default_key(variable.local()); + let is_default_key = bundle_variable.is_default_key(variable.local()); bundle_reference1.add_declare_commonjs_import( &ImportSpecifierInfo::Named { @@ -819,11 +852,11 @@ impl<'a> BundleAnalyzer<'a> { imported: Some(variable.export_as()), }, ReferenceKind::Module((*module_id).clone()), - &self.bundle_variable.borrow(), + &bundle_variable, )?; } - bundle_reference1.add_local_export(specify, module_system.clone()); + bundle_reference1.add_local_export(specify, module_system.clone(), is_entry); } } } @@ -859,11 +892,12 @@ impl<'a> BundleAnalyzer<'a> { } if is_entry { - bundle_reference1.add_local_export(specify, module_system.clone()); + bundle_reference1.add_local_export(specify, module_system.clone(), is_entry); } else { bundle_reference1.add_local_export( &ExportSpecifierInfo::Named((*var).into()), module_system.clone(), + is_entry, ); } } @@ -897,7 +931,7 @@ impl<'a> BundleAnalyzer<'a> { let module_system = module_system.merge(target.module_system().unwrap_or(module_system.clone())); match target { - FindModuleExportResult::Local(_, _, _) => { + FindModuleExportResult::Local { .. } => { let local_name = bundle_variable.render_name(local_var); bundle_variable.set_rename(*ns, local_name); @@ -915,6 +949,7 @@ impl<'a> BundleAnalyzer<'a> { bundle_reference1.add_local_export( &ExportSpecifierInfo::Named((local_var, Some(*ns)).into()), module_system, + is_entry, ); } } @@ -939,6 +974,7 @@ impl<'a> BundleAnalyzer<'a> { specify, source.clone().into(), module_system, + is_entry, ); } } @@ -993,14 +1029,9 @@ impl<'a> BundleAnalyzer<'a> { } if is_reference_by_another { - // let target_reference = - // bundle_reference_manager.reference1_mut(&target_id); - // let mut target_reference = target_reference.borrow_mut(); let target_reference = bundle_reference_manager .reference_mut_by_module(&target_id, &module_analyzer_manager); let mut target_reference = target_reference.borrow_mut(); - let target_reference = - target_reference.fetch_mut(&target_id, module_analyzer_manager); target_reference.add_local_export( &ExportSpecifierInfo::Named( @@ -1016,12 +1047,16 @@ impl<'a> BundleAnalyzer<'a> { .into(), ), module_system.clone(), + is_entry, ); } } - bundle_reference1 - .add_local_export(&ExportSpecifierInfo::Named((*ns).into()), module_system); + bundle_reference1.add_local_export( + &ExportSpecifierInfo::Named((*ns).into()), + module_system, + is_entry, + ); } } @@ -1048,6 +1083,7 @@ impl<'a> BundleAnalyzer<'a> { .into(), ), ModuleSystem::CommonJs, + is_entry, ); } } @@ -1093,14 +1129,14 @@ impl<'a> BundleAnalyzer<'a> { let bundle_reference = bundle_reference_manager.reference_mut_by_module(&module_id, &module_analyzer_manager); let mut bundle_reference = bundle_reference.borrow_mut(); - let module_of_bundle_reference = - bundle_reference.fetch_mut(module_id, module_analyzer_manager); + // let module_of_bundle_reference = + // bundle_reference.fetch_mut(module_id, module_analyzer_manager); module_analyzer_manager.patch_module_analyzer_ast( module_id, &self.context, &mut self.bundle_variable.borrow_mut(), - module_of_bundle_reference, + &mut bundle_reference, &mut commonjs_import_executed, order_index_map, &mut self.polyfill, @@ -1108,20 +1144,28 @@ impl<'a> BundleAnalyzer<'a> { ctx, )?; - if let Some(f) = bundle_reference.query_redeclare_both(&module_id) { - already_redeclare.insert(module_id.clone().into()); - let result = CjsModuleAnalyzer::redeclare_commonjs_export( + let reference_kind = module_id.clone().into(); + + let result = if let Some(map) = bundle_reference + .redeclare_commonjs_import + .get(&reference_kind) + { + already_redeclare.insert(reference_kind.clone()); + let map = HashMap::from([(reference_kind, map.clone())]); + CjsModuleAnalyzer::redeclare_commonjs_export( &self.bundle_variable.borrow(), - &f.redeclare_commonjs_import, + &map, &module_analyzer_manager.module_global_uniq_name, &mut self.polyfill, ctx, - )?; + )? + } else { + vec![] + }; - let module_analyzer = module_analyzer_manager.module_analyzer_mut_unchecked(&module_id); + let module_analyzer = module_analyzer_manager.module_analyzer_mut_unchecked(&module_id); - module_analyzer.ast.body.extend(result); - } + module_analyzer.ast.body.extend(result); } let bundle_commonjs_declare_map: CommonJsImportMap = CommonJsImportMap::new(); @@ -1129,11 +1173,12 @@ impl<'a> BundleAnalyzer<'a> { let bundle_reference = bundle_reference_manager.reference_mut(&self.group.id); let mut bundle_reference = bundle_reference.borrow_mut(); - let mut map = bundle_reference.query_all_redeclare(); - - for item in already_redeclare { - map.remove(&item); - } + let map = bundle_reference + .redeclare_commonjs_import + .clone() + .into_iter() + .filter(|(key, _)| !already_redeclare.contains(&key)) + .collect(); patch_after_import_to_module.extend(CjsModuleAnalyzer::redeclare_commonjs_export( &self.bundle_variable.borrow(), @@ -1184,22 +1229,22 @@ impl<'a> BundleAnalyzer<'a> { patch_import_to_module.extend(generate_bundle_import_by_bundle_reference( &ctx.options.format, &self.bundle_variable.borrow(), - &bundle_reference.bundle_reference1, + &bundle_reference, module_analyzer_manager, &mut self.polyfill, &self.group.id, ctx, )?); - patch_import_to_module.extend(generate_bundle_import_by_bundle_reference( - &ctx.options.format, - &self.bundle_variable.borrow(), - &bundle_reference.reexport_raw, - module_analyzer_manager, - &mut self.polyfill, - &self.group.id, - ctx, - )?); + // patch_import_to_module.extend(generate_bundle_import_by_bundle_reference( + // &ctx.options.format, + // &self.bundle_variable.borrow(), + // &bundle_reference, + // module_analyzer_manager, + // &mut self.polyfill, + // &self.group.id, + // ctx, + // )?); patch_import_to_module.extend(patch_after_import_to_module); @@ -1246,7 +1291,7 @@ impl<'a> BundleAnalyzer<'a> { if let Some(module_id) = self.ordered_modules.first() { let module_analyzer = module_analyzer_manager.module_analyzer_mut_unchecked(module_id); - let mut bundle_reference = BundleReference::new(); + let mut bundle_reference = CombineBundleReference::new(); let bundle_variable = self.bundle_variable.borrow_mut(); @@ -1325,13 +1370,14 @@ impl<'a> BundleAnalyzer<'a> { ] .concat(); - let mut bundle_reference = BundleReference::new(); + let mut bundle_reference = CombineBundleReference::new(); for name in polyfill.to_export() { if let Some(index) = &self.bundle_variable.borrow().polyfill_index_map.get(&name) { bundle_reference.add_local_export( &ExportSpecifierInfo::Named((**index).into()), module_analyzer.module_system.clone(), + false, ); } } @@ -1342,7 +1388,7 @@ impl<'a> BundleAnalyzer<'a> { &group_id, false, &self.bundle_variable.borrow(), - &mut bundle_reference, + &mut bundle_reference.bundle_reference1, &module_analyzer_manager, &self.context, &mut SimplePolyfill::default(), diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_reference.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_reference.rs index 2062685d9c..98e4e46f87 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_reference.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/bundle_reference.rs @@ -222,27 +222,6 @@ pub type CommonJsImportMap = HashMap; #[derive(Debug, Default)] pub struct BundleReference { - /// import { xxx } from './external_bundle_module' | './other_bundle_module' - pub import_map: HashMap, - - /// - /// ```ts - /// export { } from "./cjs_module"; - /// export * as ns from "./cjs_module"; - /// export { default } ns from "./cjs_module"; - /// // => - /// const cjs_module_cjs = cjs_module()["default"]; - /// - /// { - /// "cjs_module": { - /// default: None, - /// named: {} - /// } - /// } - /// ``` - /// - pub redeclare_commonjs_import: CommonJsImportMap, - // pub declare_commonjs_export: HashMap, /// export xxx from './external_bundle_module' /// export * as ns from './external_bundle_module' @@ -252,19 +231,13 @@ pub struct BundleReference { /// export default local pub export: Option, } - impl BundleReference { pub fn new() -> Self { Self::default() } +} - pub fn is_empty(&self) -> bool { - self.import_map.is_empty() - && self.redeclare_commonjs_import.is_empty() - && self.external_export_map.is_empty() - && self.export.is_none() - } - +impl CombineBundleReference { /// import "./cjs" pub fn execute_module_for_cjs(&mut self, import_kind: ReferenceKind) { self @@ -280,12 +253,22 @@ impl BundleReference { .or_insert_with(ExternalReferenceImport::new); } - pub fn add_local_export(&mut self, specify: &ExportSpecifierInfo, module_system: ModuleSystem) { - if self.export.is_none() { - self.export = Some(ExternalReferenceExport::new(module_system)); + pub fn add_local_export( + &mut self, + specify: &ExportSpecifierInfo, + module_system: ModuleSystem, + is_entry: bool, + ) { + let map = if is_entry { + &mut self.reexport_raw.export + } else { + &mut self.bundle_reference1.export + }; + if map.is_none() { + *map = Some(ExternalReferenceExport::new(module_system)); } - if let Some(ref mut export) = self.export { + if let Some(ref mut export) = map { export.insert(specify.clone()) }; } @@ -295,19 +278,25 @@ impl BundleReference { specify: &ExportSpecifierInfo, source: ReferenceKind, module_system: ModuleSystem, + is_entry: bool, ) { - if self.external_export_map.contains_key(&source) { - let map = self.external_export_map.get_mut(&source).unwrap(); + let external_export_map = if is_entry { + &mut self.reexport_raw.external_export_map + } else { + &mut self.bundle_reference1.external_export_map + }; + if external_export_map.contains_key(&source) { + let map = external_export_map.get_mut(&source).unwrap(); map.insert(specify.clone()); } else { let mut map = ExternalReferenceExport::new(module_system); map.insert(specify.clone()); - self.external_export_map.insert(source, map); + external_export_map.insert(source, map); } } pub fn change_to_hybrid_dynamic(&mut self, source: ReferenceKind) { - if let Some(map) = self.external_export_map.get_mut(&source) { + if let Some(map) = self.bundle_reference1.external_export_map.get_mut(&source) { map.module_system.merge(ModuleSystem::Hybrid); } } @@ -390,6 +379,7 @@ impl BundleReference { &ExportSpecifierInfo::All(None), module_id.clone().into(), ModuleSystem::CommonJs, + false, ); Result::<()>::Ok(()) @@ -400,29 +390,31 @@ impl BundleReference { return Ok(()); } - let reexport_commonjs = |module_id: &ModuleId, bundle_reference: &mut BundleReference| { - bundle_reference.change_to_hybrid_dynamic(module_id.clone().into()); - - bundle_reference.add_declare_commonjs_import( - &ImportSpecifierInfo::Namespace( - reference_builder - .module_analyzer_manager - .module_global_uniq_name - .namespace_name(module_id) - .unwrap(), - ), - module_id.clone().into(), - reference_builder.bundle_variable, - )?; - - bundle_reference.add_reference_export( - &ExportSpecifierInfo::All(None), - module_id.clone().into(), - ModuleSystem::CommonJs, - ); - - Result::<()>::Ok(()) - }; + let reexport_commonjs = + |module_id: &ModuleId, bundle_reference: &mut CombineBundleReference| { + bundle_reference.change_to_hybrid_dynamic(module_id.clone().into()); + + bundle_reference.add_declare_commonjs_import( + &ImportSpecifierInfo::Namespace( + reference_builder + .module_analyzer_manager + .module_global_uniq_name + .namespace_name(module_id) + .unwrap(), + ), + module_id.clone().into(), + reference_builder.bundle_variable, + )?; + + bundle_reference.add_reference_export( + &ExportSpecifierInfo::All(None), + module_id.clone().into(), + ModuleSystem::CommonJs, + reference_builder.is_entry, + ); + + Result::<()>::Ok(()) + }; let is_external = reference_builder.is_external(reference_builder.source); let is_commonjs = reference_builder @@ -432,11 +424,6 @@ impl BundleReference { reference_builder.config.options.format, ModuleFormat::CommonJs ); - let redeclare_commonjs = !reference_builder.module_analyzer.entry - || matches!( - reference_builder.module_analyzer.module_type, - ModuleType::Runtime - ); if is_external { // export * from "node:fs" @@ -462,13 +449,17 @@ impl BundleReference { &ExportSpecifierInfo::All(None), reference_builder.source.clone().into(), reference_builder.module_system.clone(), + reference_builder.is_entry, ); - } else if is_commonjs && redeclare_commonjs { + } + // will be format commonjs, esm cannot reexport fields, should export as many fields as possible + else if is_commonjs && is_format_to_cjs { reexport_commonjs(reference_builder.source, self)?; } else { let export_names = &*reference_builder .module_analyzer_manager .get_export_names(reference_builder.source); + let export_type = export_names .export_type .merge(reference_builder.module_system.clone()); @@ -489,6 +480,7 @@ impl BundleReference { ExportSpecifierInfo::Named((*local, Some(*export_as)).into()) }, export_type.clone(), + reference_builder.is_entry, ); if is_commonjs { @@ -526,6 +518,7 @@ impl BundleReference { *item }), export_type.clone(), + reference_builder.is_entry, ); if is_commonjs { @@ -558,6 +551,7 @@ impl BundleReference { &ExportSpecifierInfo::Named((*export_as, Some(*from)).into()), module_id.clone().into(), export_type.clone(), + reference_builder.is_entry, ); } @@ -567,6 +561,7 @@ impl BundleReference { &ExportSpecifierInfo::Default(*item), module_id.clone().into(), export_type.clone(), + reference_builder.is_entry, ); } @@ -590,6 +585,7 @@ impl BundleReference { &ExportSpecifierInfo::All(None), module_id.clone().into(), export_type.clone(), + reference_builder.is_entry, ); } } else if is_commonjs_source { @@ -630,17 +626,48 @@ pub struct BundleReferenceManager { /// /// but there is one place to be careful that entry module/bundle, it should export raw named bundle_reference: HashMap>>, - bundle_reference1: HashMap>>, + // bundle_reference1: HashMap>>, } #[derive(Debug, Default)] pub struct CombineBundleReference { pub reexport_raw: BundleReference, pub bundle_reference1: BundleReference, + + /// import { xxx } from './external_bundle_module' | './other_bundle_module' + pub import_map: HashMap, + + /// + /// ```ts + /// export { } from "./cjs_module"; + /// export * as ns from "./cjs_module"; + /// export { default } ns from "./cjs_module"; + /// // => + /// const cjs_module_cjs = cjs_module()["default"]; + /// + /// { + /// "cjs_module": { + /// default: None, + /// named: {} + /// } + /// } + /// ``` + /// + pub redeclare_commonjs_import: CommonJsImportMap, } +impl CombineBundleReference {} + // TODO: improve logic impl CombineBundleReference { + pub fn new() -> Self { + Self { + reexport_raw: BundleReference::new(), + bundle_reference1: BundleReference::new(), + import_map: HashMap::default(), + redeclare_commonjs_import: HashMap::default(), + } + } pub fn fetch( &self, module_id: &ModuleId, @@ -664,64 +691,6 @@ impl CombineBundleReference { &mut self.bundle_reference1 } } - - pub fn query_redeclare_both(&mut self, module_id: &ModuleId) -> Option { - let mut bundle_reference = BundleReference::new(); - let reference_kind: ReferenceKind = module_id.clone().into(); - - let mut is_empty = true; - for item in [ - &self.bundle_reference1.redeclare_commonjs_import, - &self.reexport_raw.redeclare_commonjs_import, - ] { - if let Some(m) = item.get(&reference_kind) { - is_empty = false; - bundle_reference - .redeclare_commonjs_import - .entry(reference_kind.clone()) - .or_insert_with(|| ExternalReferenceImport::new()) - .extend(m); - }; - } - - // for item in [ - // &self.bundle_reference1.import_map, - // &self.reexport_raw.import_map, - // ] { - // if let Some(m) = item.get(&reference_kind) { - // is_empty = false; - // bundle_reference - // .import_map - // .entry(reference_kind.clone()) - // .or_insert_with(|| ExternalReferenceImport::new()) - // .extend(m); - // } - // } - - if is_empty { - None - } else { - Some(bundle_reference) - } - } - - pub fn query_all_redeclare(&self) -> CommonJsImportMap { - let mut bundle_reference = CommonJsImportMap::new(); - - for map in [ - &self.bundle_reference1.redeclare_commonjs_import, - &self.reexport_raw.redeclare_commonjs_import, - ] { - for (key, item) in map { - bundle_reference - .entry(key.clone()) - .or_insert_with(|| ExternalReferenceImport::new()) - .extend(item); - } - } - - bundle_reference - } } impl BundleReferenceManager { @@ -746,16 +715,16 @@ impl BundleReferenceManager { self.reference_mut(group_id) } - pub fn reference1_mut(&mut self, module_id: &ModuleId) -> Rc> { - Rc::clone(if self.bundle_reference1.contains_key(module_id) { - self.bundle_reference1.get(module_id).unwrap() - } else { - self - .bundle_reference1 - .entry(module_id.clone()) - .or_insert_with(|| Rc::new(RefCell::new(BundleReference::new()))) - }) - } + // pub fn reference1_mut(&mut self, module_id: &ModuleId) -> Rc> { + // Rc::clone(if self.bundle_reference1.contains_key(module_id) { + // self.bundle_reference1.get(module_id).unwrap() + // } else { + // self + // .bundle_reference1 + // .entry(module_id.clone()) + // .or_insert_with(|| Rc::new(RefCell::new(BundleReference::new()))) + // }) + // } } pub struct ReferenceBuilder<'a> { @@ -767,6 +736,7 @@ pub struct ReferenceBuilder<'a> { pub module_system: ModuleSystem, pub config: &'a ShareBundleContext, pub module_id: &'a ModuleId, + pub is_entry: bool, } impl<'a> ReferenceBuilder<'a> { diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/mod.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/mod.rs index 7b6486dbab..d5e37210c1 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/mod.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/mod.rs @@ -5,7 +5,7 @@ use std::{ sync::{Arc, Mutex, RwLock}, }; -use bundle_reference::{BundleReference, CommonJsImportMap, ReferenceKind}; +use bundle_reference::{CombineBundleReference, CommonJsImportMap, ReferenceKind}; use farmfe_core::{ config::external::ExternalConfig, context::CompilationContext, @@ -20,7 +20,9 @@ use farmfe_core::{ Module as ModuleAst, ModuleDecl, ModuleItem, Stmt, VarDecl, VarDeclarator, }, }; -use farmfe_toolkit::{itertools::Itertools, script::swc_try_with::try_with, swc_ecma_visit::VisitMutWith}; +use farmfe_toolkit::{ + itertools::Itertools, script::swc_try_with::try_with, swc_ecma_visit::VisitMutWith, +}; pub mod bundle_analyzer; pub mod bundle_reference; @@ -476,16 +478,23 @@ impl<'a> ModuleAnalyzerManager<'a> { ExportSpecifierInfo::Named(export) => { let export_map = self.build_export_names(source, bundle_variable); - if let Some(i) = export_map.query(export.export_from(), bundle_variable) { - // bundle_variable.set_var_root(export.export_as(), i); + if let Some(i) = export_map.query(export.export_from(), bundle_variable) { map.add_local(&ExportSpecifierInfo::Named( (i, Some(export.export_as())).into(), )) }; } - ExportSpecifierInfo::Default(_) | ExportSpecifierInfo::Namespace(_) => { + ExportSpecifierInfo::Default(default) => { + let export_map = self.build_export_names(source, bundle_variable); + + if let Some(i) = export_map.query(*default, bundle_variable) { + map.add_local(&ExportSpecifierInfo::Default(i)); + } + } + + ExportSpecifierInfo::Namespace(_) => { map.add_local(specify); } } @@ -519,7 +528,7 @@ impl<'a> ModuleAnalyzerManager<'a> { module_id: &ModuleId, context: &Arc, bundle_variable: &mut BundleVariable, - bundle_reference: &mut BundleReference, + bundle_reference: &mut CombineBundleReference, commonjs_import_executed: &mut HashSet, order_index_map: &HashMap, polyfill: &mut SimplePolyfill, @@ -552,7 +561,7 @@ impl<'a> ModuleAnalyzerManager<'a> { module_id: &ModuleId, namespace: Option, bundle_variable: &BundleVariable, - bundle_reference: &mut BundleReference, + bundle_reference: &mut CombineBundleReference, patch_asts: &mut Vec, order_index_map: &HashMap, polyfill: &mut SimplePolyfill, @@ -730,7 +739,7 @@ impl<'a> ModuleAnalyzerManager<'a> { context: &Arc, bundle_variable: &mut BundleVariable, namespace: Option, - bundle_reference: &mut BundleReference, + bundle_reference: &mut CombineBundleReference, commonjs_import_executed: &mut HashSet, order_index_map: &HashMap, polyfill: &mut SimplePolyfill, @@ -773,7 +782,7 @@ impl<'a> ModuleAnalyzerManager<'a> { module_id, context, bundle_variable, - bundle_reference, + // bundle_reference, polyfill, ctx, ) @@ -855,6 +864,7 @@ impl<'a> ModuleAnalyzerManager<'a> { .unwrap(); } + // more accurate generation pub fn link( &mut self, bundle_variable: &mut BundleVariable, @@ -962,22 +972,42 @@ impl<'a> ModuleAnalyzerManager<'a> { for specify in &s.specifiers { match specify { - ExportSpecifierInfo::Default(n) => { + ExportSpecifierInfo::Default(_) => { // TODO: only add default when it is export default expression e.g: export default 1 + 1 self .module_global_uniq_name .add_default(&module_analyzer.module_id, |s| { - bundle_variable.register_used_name_by_module_id(&module_analyzer.module_id, s, root) + bundle_variable.register_used_name_by_module_id( + &module_analyzer.module_id, + s, + root, + ) }); } - ExportSpecifierInfo::Namespace(_) | + ExportSpecifierInfo::Namespace(_) => { + if let Some(source) = &s.source { + if self.module_map.contains_key(source) { + self.module_global_uniq_name.add_namespace(source, |s| { + bundle_variable.register_used_name_by_module_id(source, s, root) + }); + } + } + } + // maybe used in namespace ExportSpecifierInfo::All(_) => { if let Some(source) = &s.source { - self - .module_global_uniq_name - .add_namespace(source, |s| bundle_variable.register_used_name_by_module_id(source, s, root)); + if self.is_commonjs(source) { + self.module_global_uniq_name.add_namespace(source, |s| { + bundle_variable.register_used_name_by_module_id(source, s, root) + }); + } + } + if !module_analyzer.entry { + self.module_global_uniq_name.add_namespace(module_id, |s| { + bundle_variable.register_used_name_by_module_id(module_id, s, root) + }); } } ExportSpecifierInfo::Named(var) => { @@ -985,7 +1015,11 @@ impl<'a> ModuleAnalyzerManager<'a> { self .module_global_uniq_name .add_default(&module_analyzer.module_id, |s| { - bundle_variable.register_used_name_by_module_id(&module_analyzer.module_id, s, root) + bundle_variable.register_used_name_by_module_id( + &module_analyzer.module_id, + s, + root, + ) }); } } diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/reference.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/reference.rs index 08cd6de359..4cfe6281cc 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/reference.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/bundle/reference.rs @@ -1,9 +1,9 @@ -use std::collections::HashMap; +use std::{collections::HashMap, ops::Deref}; use farmfe_core::module::{ModuleId, ModuleSystem}; use crate::resource_pot_to_bundle::{ - modules_analyzer::module_analyzer::ExportSpecifierInfo, uniq_name::BundleVariable, + modules_analyzer::module_analyzer::ExportSpecifierInfo, uniq_name::BundleVariable, Var, }; #[derive(Debug, Clone, Default)] @@ -82,9 +82,17 @@ impl ReferenceExport { } pub fn query(&self, export_from: &str, bundle_variable: &BundleVariable) -> Option { - if let Some(index) = self.namespace { - if &bundle_variable.name(index) == export_from { - return Some(index); + let is_find_default = export_from == "default"; + + if is_find_default && self.default.is_some() { + return self.default; + } + + if !is_find_default { + if let Some(index) = self.namespace { + if bundle_variable.name(index) == export_from { + return Some(index); + } } } @@ -108,7 +116,7 @@ impl ReferenceExport { } if let Some(index) = self.namespace { - if &bundle_variable.name(index) == export_from { + if &bundle_variable.name(index.into()) == export_from { return Some(index); } } @@ -152,6 +160,7 @@ impl ReferenceMap { } let reference = self.reexport_map.get_mut(module_id).unwrap(); + reference.insert(export); } @@ -186,6 +195,12 @@ impl ReferenceMap { } } + pub fn query_local(&self, export_from: &str, bundle_variable: &BundleVariable) -> Option { + self + .export + .raw_query(export_from, bundle_variable, export_from == "default") + } + pub fn query_by_str(&self, export_from: &str, bundle_variable: &BundleVariable) -> Option { let find_default = export_from == "default"; diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/mod.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/mod.rs index 07f21476a1..2912098569 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/mod.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/mod.rs @@ -262,6 +262,7 @@ impl<'a> SharedBundle<'a> { let mut reserved_word = SimplePolyfill::reserved_word(); reserved_word.push("module".to_string()); + reserved_word.push("default".to_string()); if let Some(bundle_analyzer) = self .module_analyzer_manager diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/modules_analyzer/module_analyzer.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/modules_analyzer/module_analyzer.rs index 2577c7f52f..ff36128a9a 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/modules_analyzer/module_analyzer.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/modules_analyzer/module_analyzer.rs @@ -232,6 +232,7 @@ pub struct ModuleAnalyzer { pub external: bool, pub is_dynamic: bool, pub is_runtime: bool, + pub is_should_dynamic_reexport: bool, pub cjs_module_analyzer: CjsModuleAnalyzer, pub mark: (Mark, Mark), pub module_system: ModuleSystem, @@ -293,6 +294,7 @@ impl ModuleAnalyzer { bundle_group_id: group_id, external: module.external, entry: is_entry, + is_should_dynamic_reexport: false, is_dynamic, is_runtime, cjs_module_analyzer: CjsModuleAnalyzer::new(), @@ -345,30 +347,54 @@ impl ModuleAnalyzer { ) -> Result<()> { farm_profile_function!(""); try_with(self.cm.clone(), &context.meta.script.globals, || { - for (statement_id, stmt) in self.ast.body.iter().enumerate() { - let statement = analyze::analyze_imports_and_exports( - statement_id, - stmt, - &self.module_id, - module_graph, - self.mark.1, - &mut |ident, strict, is_placeholder| { - if is_placeholder { - bundle_variable.register_placeholder(&self.module_id, ident) - } else { - bundle_variable.register_var(&self.module_id, ident, strict) + let mut is_should_dynamic_reexport = false; + self + .ast + .body + .iter() + .enumerate() + .for_each(|(statement_id, stmt)| { + let statement = analyze::analyze_imports_and_exports( + statement_id, + stmt, + &self.module_id, + module_graph, + self.mark.1, + &mut |ident, strict, is_placeholder| { + if is_placeholder { + bundle_variable.register_placeholder(&self.module_id, ident) + } else { + bundle_variable.register_var(&self.module_id, ident, strict) + } + }, + ) + .unwrap(); + + if statement.export.is_none() + && statement.import.is_none() + && statement.defined.is_empty() + { + return; + } + + if let Some(ExportInfo { + source, specifiers, .. + }) = statement.export.as_ref() + { + if source + .as_ref() + .is_some_and(|m| module_graph.module(m).is_some_and(|m| m.external)) + && specifiers.iter().any(|specify| match specify { + ExportSpecifierInfo::All(_) => true, + _ => false, + }) + { + is_should_dynamic_reexport = true; } - }, - ) - .unwrap(); + } - if statement.export.is_none() && statement.import.is_none() && statement.defined.is_empty() - { - continue; - } - - self.statements.push(statement); - } + self.statements.push(statement); + }); // unresolved is write to global, so, we need to avoid having the same declaration as unresolved ident in the bundle self.collect_unresolved_ident(bundle_variable); diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/mod.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/mod.rs index 38248e0ae4..ef63e000c6 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/mod.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/mod.rs @@ -193,6 +193,11 @@ impl CjsModuleAnalyzer { type_args: None, })), ) + } else if let Some(m) = module_global_uniq_name.namespace_name(module_id) { + ( + module_id.to_string(), + Box::new(Expr::Ident(bundle_variable.render_name(m).as_str().into())), + ) } else { return Ok(None); }; diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/patch.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/patch.rs index 29f1080375..df586e5e49 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/patch.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/patch.rs @@ -27,7 +27,7 @@ use farmfe_toolkit::{ }; use crate::resource_pot_to_bundle::{ - bundle::{bundle_reference::BundleReference, ModuleAnalyzerManager, ModuleGlobalUniqName}, + bundle::{bundle_reference::{BundleReference, CombineBundleReference}, ModuleAnalyzerManager, ModuleGlobalUniqName}, modules_analyzer::module_analyzer::ModuleAnalyzer, polyfill::{Polyfill, SimplePolyfill}, targets::util::wrap_commonjs, @@ -164,7 +164,7 @@ impl CjsPatch { module_id: &ModuleId, context: &Arc, bundle_variable: &BundleVariable, - bundle_reference: &mut BundleReference, + // bundle_reference: &mut BundleReference, polyfill: &mut SimplePolyfill, options: &ShareBundleContext, ) -> Result<()> { @@ -213,7 +213,7 @@ impl CjsPatch { config: &'a Config, polyfill: &'a mut SimplePolyfill, external_config: &'a ExternalConfig, - bundle_reference: &'a mut BundleReference, + bundle_reference: &'a mut CombineBundleReference, module_graph: &ModuleGraph, module_global_uniq_name: &ModuleGlobalUniqName, module_map: &HashMap, diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/util.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/util.rs index 3218a28e3d..9962d6bc0b 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/util.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/cjs/util.rs @@ -15,7 +15,7 @@ use farmfe_toolkit::{ }; use crate::resource_pot_to_bundle::{ - bundle::{bundle_reference::BundleReference, ModuleGlobalUniqName}, modules_analyzer::module_analyzer::{ImportSpecifierInfo, ModuleAnalyzer}, uniq_name::BundleVariable, Polyfill, ShareBundleContext, ShareBundleOptions, SimplePolyfill + bundle::{bundle_reference::{BundleReference, CombineBundleReference}, ModuleGlobalUniqName}, modules_analyzer::module_analyzer::{ImportSpecifierInfo, ModuleAnalyzer}, uniq_name::BundleVariable, Polyfill, ShareBundleContext, ShareBundleOptions, SimplePolyfill }; enum ReplaceType { @@ -64,7 +64,7 @@ pub struct CJSReplace<'a> { pub context: &'a ShareBundleContext, pub polyfill: &'a mut SimplePolyfill, pub external_config: &'a ExternalConfig, - pub bundle_reference: &'a mut BundleReference, + pub bundle_reference: &'a mut CombineBundleReference, pub module_map: &'a HashMap, } diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/generate.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/generate.rs index 77d2fc1f4c..68500bb63e 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/targets/generate.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/targets/generate.rs @@ -15,7 +15,9 @@ use farmfe_toolkit::itertools::Itertools; use crate::resource_pot_to_bundle::{ bundle::{ - bundle_reference::{BundleReference, ExternalReferenceExport, ReferenceKind}, + bundle_reference::{ + BundleReference, CombineBundleReference, ExternalReferenceExport, ReferenceKind, + }, reference::{ReferenceExport, ReferenceMap}, ModuleAnalyzerManager, }, @@ -32,7 +34,7 @@ pub fn generate_namespace_by_reference_map( module_id: &ModuleId, local: usize, bundle_variable: &BundleVariable, - bundle_reference: &mut BundleReference, + bundle_reference: &mut CombineBundleReference, map: &ReferenceMap, module_analyzer_manager: &ModuleAnalyzerManager, order_index_map: &HashMap, @@ -59,19 +61,19 @@ pub fn generate_namespace_by_reference_map( if module_analyzer_manager.is_external(module_id) || !module_analyzer_manager.contain(module_id) { if reference_export.is_empty() || reference_export.all { - let ns_index = module_analyzer_manager + if let Some(ns_index) = module_analyzer_manager .module_global_uniq_name .namespace_name(module_id) - .unwrap(); - - bundle_reference.add_import( - &ImportSpecifierInfo::Namespace(ns_index), - module_id.clone().into(), - bundle_variable, - )?; + { + bundle_reference.add_import( + &ImportSpecifierInfo::Namespace(ns_index), + module_id.clone().into(), + bundle_variable, + )?; - reexport_namespace.push(bundle_variable.name(ns_index).as_str().into()); - continue; + reexport_namespace.push(bundle_variable.name(ns_index).as_str().into()); + continue; + }; } // TODO: export import from external @@ -283,7 +285,7 @@ pub fn generate_export_as_module_export( pub fn generate_bundle_import_by_bundle_reference( format: &ModuleFormat, bundle_variable: &BundleVariable, - bundle_reference: &BundleReference, + bundle_reference: &CombineBundleReference, module_analyzer_manager: &ModuleAnalyzerManager, polyfill: &mut SimplePolyfill, group_id: &str, diff --git a/crates/plugin_bundle/src/resource_pot_to_bundle/uniq_name.rs b/crates/plugin_bundle/src/resource_pot_to_bundle/uniq_name.rs index e6c6b8004a..df107fa82b 100644 --- a/crates/plugin_bundle/src/resource_pot_to_bundle/uniq_name.rs +++ b/crates/plugin_bundle/src/resource_pot_to_bundle/uniq_name.rs @@ -461,7 +461,11 @@ impl BundleVariable { }; match res { - FindModuleExportResult::Local(i, target, _) + FindModuleExportResult::Local { + index: i, + source: target, + .. + } | FindModuleExportResult::External(i, target, _) => { let is_reexport = module_analyzers .module_analyzer(&target) @@ -478,58 +482,73 @@ impl BundleVariable { } } - if let Some(ReferenceQueryResult { index, is_reexport }) = - reference_map.query_by_var_str_and_meta(&var_ident, self) - { + if let Some(index) = reference_map.query_by_str(&var_ident, self) { return Some(FindModuleExportResult::Bundle( index, module_analyzer.module_id.clone(), // support cjs module_system, - is_reexport, + false, )); } } if find_namespace || module_analyzers.is_commonjs(source) { - return Some(FindModuleExportResult::Local( + return Some(FindModuleExportResult::Local { index, - source.clone(), + source: source.clone(), module_system, - )); + dynamic_reference: false, + }); } + let try_query_ident = |ident: &str, module_system: ModuleSystem| { + // find from local + if let Some(d) = reference_map.export.query(&ident, self) { + return Some(FindModuleExportResult::Local { + index: d, + source: source.clone(), + module_system, + dynamic_reference: false, + }); + } + + // find from reference external or bundle + for (module_id, export) in &reference_map.reexport_map { + if let Some(d) = export.query(&ident, self) { + if module_analyzers.is_external(module_id) || !module_analyzers.contain(module_id) { + return Some(FindModuleExportResult::External(d, module_id.clone(), true)); + } else { + return Some(FindModuleExportResult::Local { + index: d, + source: module_id.clone(), + module_system, + dynamic_reference: false, + }); + } + } + } + + None + }; + if find_default { - return reference_map - .export - .default - .or_else(|| reference_map.query_by_str("default", self)) - // .or_else(|| reference_map.export.query(&"default".to_string(), self)) - .map(|i| FindModuleExportResult::Local(i, source.clone(), module_system)); + return try_query_ident("default", module_system); } - // find from local - if let Some(d) = reference_map.export.query(&var_ident, self) { - return Some(FindModuleExportResult::Local( - d, - source.clone(), - module_system, - )); + let v = try_query_ident(&var_ident, module_system.clone()); + + if v.is_some() { + return v; } - // find from reference external or bundle - for (module_id, export) in &reference_map.reexport_map { - if let Some(d) = export.query(&var_ident, self) { - if module_analyzers.is_external(module_id) || !module_analyzers.contain(module_id) { - return Some(FindModuleExportResult::External(d, module_id.clone(), true)); - } else { - return Some(FindModuleExportResult::Local( - d, - module_id.clone(), - module_system, - )); - } - } + if reference_map.reexport_map.iter().any(|(_, i)| i.all) { + return Some(FindModuleExportResult::Local { + index, + source: source.clone(), + module_system, + dynamic_reference: true, + }); } } else { return Some(FindModuleExportResult::External( @@ -545,7 +564,12 @@ impl BundleVariable { #[derive(Debug)] pub enum FindModuleExportResult { - Local(usize, ModuleId, ModuleSystem), + Local { + index: usize, + source: ModuleId, + module_system: ModuleSystem, + dynamic_reference: bool, + }, External(usize, ModuleId, bool), Bundle(usize, ModuleId, ModuleSystem, bool), } @@ -553,7 +577,7 @@ pub enum FindModuleExportResult { impl FindModuleExportResult { pub fn is_common_js(&self) -> bool { match self { - FindModuleExportResult::Local(_, _, module_system) + FindModuleExportResult::Local { module_system, .. } | FindModuleExportResult::Bundle(_, _, module_system, _) => { matches!(module_system, ModuleSystem::CommonJs | ModuleSystem::Hybrid) } @@ -564,7 +588,7 @@ impl FindModuleExportResult { pub fn module_system(&self) -> Option { match self { - FindModuleExportResult::Local(_, _, module_system) + FindModuleExportResult::Local { module_system, .. } | FindModuleExportResult::Bundle(_, _, module_system, _) => Some(module_system.clone()), FindModuleExportResult::External(_, _, _) => None, } @@ -572,7 +596,10 @@ impl FindModuleExportResult { pub fn target_source(&self) -> ReferenceKind { match self { - FindModuleExportResult::Local(_, target_source, _) => target_source.clone().into(), + FindModuleExportResult::Local { + source: target_source, + .. + } => target_source.clone().into(), FindModuleExportResult::External(_, target_source, _) => target_source.clone().into(), FindModuleExportResult::Bundle(_, target_bundle, _, _) => target_bundle.clone().into(), } @@ -580,7 +607,7 @@ impl FindModuleExportResult { pub fn is_reexport(&self) -> bool { match self { - FindModuleExportResult::Local(_, _, _) => false, + FindModuleExportResult::Local { .. } => false, FindModuleExportResult::External(_, _, reexport) => *reexport, FindModuleExportResult::Bundle(_, _, _, reexport) => *reexport, } diff --git a/crates/plugin_runtime/src/render_resource_pot/mod.rs b/crates/plugin_runtime/src/render_resource_pot/mod.rs index 4c0f551807..1202a5a43e 100644 --- a/crates/plugin_runtime/src/render_resource_pot/mod.rs +++ b/crates/plugin_runtime/src/render_resource_pot/mod.rs @@ -89,6 +89,14 @@ pub fn resource_pot_to_runtime_object( let hoisted_code_bundle = hoisted_group.render(module_graph, context)?; let code = hoisted_code_bundle.to_string(); + // println!( + // "module_id: {}\nmodules: {:#?}\ncode: {}\n\nend module_id: {}", + // hoisted_group.target_hoisted_module_id.to_string(), + // hoisted_group.hoisted_module_ids, + // code, + // hoisted_group.target_hoisted_module_id.to_string(), + // ); + let mut meta = context .plugin_driver .parse( @@ -101,7 +109,8 @@ pub fn resource_pot_to_runtime_object( }, context, &Default::default(), - )? + ) + .unwrap() .unwrap(); ( Some(meta.as_script_mut().take_ast()), diff --git a/crates/plugin_runtime/src/render_resource_pot/scope_hoisting.rs b/crates/plugin_runtime/src/render_resource_pot/scope_hoisting.rs index 75ee53e86d..d79803fe92 100644 --- a/crates/plugin_runtime/src/render_resource_pot/scope_hoisting.rs +++ b/crates/plugin_runtime/src/render_resource_pot/scope_hoisting.rs @@ -162,11 +162,14 @@ pub fn build_scope_hoisted_module_groups( let dependents_hoisted_group_module = module_graph.module(&dependents_hoisted_group_id).unwrap(); - if dependents_hoisted_group_module.execution_order - < module_graph - .module(&group.target_hoisted_module_id) - .unwrap() - .execution_order + if module_graph + .circle_record + .is_in_circle(&dependents_hoisted_group_id) + || dependents_hoisted_group_module.execution_order + < module_graph + .module(&group.target_hoisted_module_id) + .unwrap() + .execution_order { continue; } @@ -257,12 +260,16 @@ mod tests { vec![ super::ScopeHoistedModuleGroup { target_hoisted_module_id: "A".into(), - hoisted_module_ids: HashSet::from(["A".into(), "C".into(),]), + hoisted_module_ids: HashSet::from(["A".into()]), }, super::ScopeHoistedModuleGroup { target_hoisted_module_id: "B".into(), hoisted_module_ids: HashSet::from(["B".into(), "E".into(), "G".into(),]), }, + super::ScopeHoistedModuleGroup { + target_hoisted_module_id: "C".into(), + hoisted_module_ids: HashSet::from(["C".into()]), + }, super::ScopeHoistedModuleGroup { target_hoisted_module_id: "D".into(), hoisted_module_ids: HashSet::from(["D".into(),]), diff --git a/crates/toolkit/src/script/mod.rs b/crates/toolkit/src/script/mod.rs index 654abc5254..0c615d4ede 100644 --- a/crates/toolkit/src/script/mod.rs +++ b/crates/toolkit/src/script/mod.rs @@ -63,7 +63,6 @@ pub fn parse_module( return Ok(ParseScriptModuleResult { ast: m, comments }); } } - try_with_handler(cm, Default::default(), |handler| { for err in recovered_errors { err.into_diagnostic(handler).emit(); @@ -74,8 +73,10 @@ pub fn parse_module( .map_err(|e| CompilationError::ParseError { resolved_path: id.to_string(), msg: if let Some(s) = e.downcast_ref::() { + eprintln!("recovered_errors: {}", s); s.to_string() } else if let Some(s) = e.downcast_ref::<&str>() { + eprintln!("recovered_errors: {}", s); s.to_string() } else { "failed to handle with unknown panic message".to_string() diff --git a/examples/module-concatenation/farm.config.ts b/examples/module-concatenation/farm.config.ts index 7f8cccc943..3fe69d9caa 100644 --- a/examples/module-concatenation/farm.config.ts +++ b/examples/module-concatenation/farm.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from "@farmfe/core"; +import react from '@farmfe/plugin-react'; export default defineConfig({ compilation: { @@ -8,5 +9,6 @@ export default defineConfig({ }, server: { writeToDisk: true, - } + }, + plugins: [react()] }) \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c426e3c415..83b1f9049f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2096,10 +2096,10 @@ importers: dependencies: tdesign-icons-vue: specifier: latest - version: 0.2.5(vue@2.6.14) + version: 0.3.2(vue@2.6.14) tdesign-vue: specifier: latest - version: 1.10.4(vue@2.6.14) + version: 1.10.5(vue@2.6.14) vite-plugin-vue2-svg: specifier: ^0.4.0 version: 0.4.0(ejs@3.1.10)(lodash@4.17.21)(vue-template-compiler@2.6.14(vue@2.6.14)) @@ -2130,10 +2130,10 @@ importers: dependencies: tdesign-icons-vue: specifier: latest - version: 0.2.5(vue@2.7.16) + version: 0.3.2(vue@2.7.16) tdesign-vue: specifier: latest - version: 1.10.4(vue@2.7.16) + version: 1.10.5(vue@2.7.16) vite-plugin-vue2-svg: specifier: ^0.4.0 version: 0.4.0(ejs@3.1.10)(lodash@4.17.21)(vue-template-compiler@2.7.16(vue@2.7.16)) @@ -18567,8 +18567,13 @@ packages: peerDependencies: vue: ^2.6.12 - tdesign-vue@1.10.4: - resolution: {integrity: sha512-ej4QgA/E9DsxlMzr1++pomREgpncniP1llMT2qGIkZ4vtpHJV3CjBIf6eDLtWTUWz3c8B5RM8lAqm2ZxSvGCEg==} + tdesign-icons-vue@0.3.2: + resolution: {integrity: sha512-FW1hqOoIBjnPzTOcGvWidVrWvyf0wHafxt7eAciz62hLU/Ix8TZ1AtFcG3QOafT0vpFPaBcCMVNNXvE5PSzuIA==} + peerDependencies: + vue: ^2.6.12 + + tdesign-vue@1.10.5: + resolution: {integrity: sha512-D/833QpG7N0zH7lN7zhuegKJN0AVklAhrUKG7zmKcPrEZKaL7jjGz9lr6UOU/CJAEae0dij8YQtcscEIq3ugqw==} peerDependencies: vue: ~2.6.10 @@ -42353,7 +42358,19 @@ snapshots: classnames: 2.3.2 vue: 2.7.16 - tdesign-vue@1.10.4(vue@2.6.14): + tdesign-icons-vue@0.3.2(vue@2.6.14): + dependencies: + '@babel/runtime': 7.23.2 + classnames: 2.3.2 + vue: 2.6.14 + + tdesign-icons-vue@0.3.2(vue@2.7.16): + dependencies: + '@babel/runtime': 7.23.2 + classnames: 2.3.2 + vue: 2.7.16 + + tdesign-vue@1.10.5(vue@2.6.14): dependencies: '@babel/runtime': 7.23.2 '@popperjs/core': 2.11.8 @@ -42375,7 +42392,7 @@ snapshots: validator: 13.11.0 vue: 2.6.14 - tdesign-vue@1.10.4(vue@2.7.16): + tdesign-vue@1.10.5(vue@2.7.16): dependencies: '@babel/runtime': 7.23.2 '@popperjs/core': 2.11.8