-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve module import compress (#1953)
* feat: improve module import compress * fix: update test case & jsx for module concatenation example
- Loading branch information
1 parent
d61762a
commit 9508598
Showing
49 changed files
with
997 additions
and
412 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
crates/compiler/tests/fixtures/bundle/concatenate_module/circle/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"concatenateModules": true, | ||
"output": { | ||
"targetEnv": "browser" | ||
}, | ||
"comments": true, | ||
"minify": false | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/compiler/tests/fixtures/bundle/concatenate_module/circle/foo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { reexport } from './reexport'; | ||
|
||
|
||
export const foo = reexport + 'foo'; |
3 changes: 3 additions & 0 deletions
3
crates/compiler/tests/fixtures/bundle/concatenate_module/circle/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as ns from './reexport'; | ||
|
||
console.log(ns); |
53 changes: 53 additions & 0 deletions
53
crates/compiler/tests/fixtures/bundle/concatenate_module/circle/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
3 changes: 3 additions & 0 deletions
3
crates/compiler/tests/fixtures/bundle/concatenate_module/circle/reexport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
export const reexport = 'reexport'; | ||
export * from './foo'; |
6 changes: 6 additions & 0 deletions
6
crates/compiler/tests/fixtures/bundle/concatenate_module/export/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"concatenateModules": true, | ||
"output": { | ||
"targetEnv": "browser" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
crates/compiler/tests/fixtures/bundle/concatenate_module/export/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createEmotion } from './reexport'; | ||
|
||
console.log(createEmotion); |
33 changes: 33 additions & 0 deletions
33
crates/compiler/tests/fixtures/bundle/concatenate_module/export/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
2 changes: 2 additions & 0 deletions
2
crates/compiler/tests/fixtures/bundle/concatenate_module/export/reexport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @ts-ignore | ||
export { default as createEmotion } from 'xxx'; |
5 changes: 5 additions & 0 deletions
5
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/config.cjs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"output": { | ||
"format": "cjs" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/foo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Worker } from './reexport'; |
7 changes: 7 additions & 0 deletions
7
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
import { readFile } from './reexport'; | ||
import { Worker } from './foo' | ||
|
||
console.log({ readFile, Worker }); | ||
|
||
export * from './reexport'; |
96 changes: 96 additions & 0 deletions
96
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
53 changes: 53 additions & 0 deletions
53
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
5 changes: 5 additions & 0 deletions
5
crates/compiler/tests/fixtures/bundle/export/doubleReexportAll/reexport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from 'node:fs'; | ||
export * from 'node:cluster'; | ||
|
||
const readFile = 123; | ||
module.exports.name = 123; |
1 change: 1 addition & 0 deletions
1
crates/compiler/tests/fixtures/bundle/export/reexportExternal/foo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const foo = 'foo'; |
1 change: 1 addition & 0 deletions
1
crates/compiler/tests/fixtures/bundle/export/reexportExternal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './reexport'; |
14 changes: 14 additions & 0 deletions
14
crates/compiler/tests/fixtures/bundle/export/reexportExternal/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
2 changes: 2 additions & 0 deletions
2
crates/compiler/tests/fixtures/bundle/export/reexportExternal/reexport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { readFile as rf } from 'node:fs'; | ||
export { foo as bar } from './foo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../compiler/tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/star/config.cjs.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"output": { | ||
"targetEnv": "library-node", | ||
"format": "cjs" | ||
} | ||
} |
Oops, something went wrong.