Skip to content

Commit 63908eb

Browse files
shulandmimiwre232114fu050409wumingliang
authored
feat: cache module metadata & cacheable deserialize (#2082)
* feat: support ast merge sourcemap generation * chore(refactor): custom moudle meta data * chore: stash code * chore: bundle adapting ast merge * feat: bundle support merge sourceMap & comment * fix: type issue * chore: stash code * feat: support dynamic input * feat: refactor runtime * chore: stash code * chore: support dynamic entries bundle * chore: support generate dynamic entry resource pots * feat: full support dynamic entry * chore: stash code * chore: stash code * chore: script entry example test passed * feat: arco pro dev available * feat: cache module metadata & cachable deserialize * feat: improve cache api * feat: write cache * feat: combine cache item to files * feat: conflict & clippy * chore: stash code * feat: stash code * feat: use matedate api for plugin * feat: improve matedata * feat: improve cache write * chore: remove not exists dependent * feat: remove unnecessary code * feat: optimize deserialize usage * chore: ci pnpm version unified version * fix: cspell & mangle_export test case fix * fix: lint --------- Co-authored-by: brightwu <[email protected]> Co-authored-by: 苏向夜 <[email protected]> Co-authored-by: wumingliang <[email protected]>
1 parent 2049b52 commit 63908eb

File tree

49 files changed

+1260
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1260
-679
lines changed

.changeset/beige-ligers-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@farmfe/core": patch
3+
---
4+
5+
add module metadata cache & cache api

.github/workflows/rust-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
- name: Setup pnpm
125125
uses: pnpm/action-setup@v4
126126
with:
127-
version: 9.1.0
127+
version: 9.4.0
128128
run_install: false
129129
- name: Setup Node.js
130130
uses: actions/setup-node@v4

crates/compiler/src/build/module_cache.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub fn set_module_graph_cache(module_ids: Vec<ModuleId>, context: &Arc<Compilati
233233
})
234234
.collect(),
235235
is_expired: false,
236+
metadata: Default::default(),
236237
};
237238

238239
context
@@ -242,6 +243,16 @@ pub fn set_module_graph_cache(module_ids: Vec<ModuleId>, context: &Arc<Compilati
242243
});
243244
}
244245

246+
pub fn handle_module_metadata(cached_module: &mut CachedModule, context: &Arc<CompilationContext>) {
247+
if let Some(map) = cached_module.metadata.take() {
248+
context
249+
.cache_manager
250+
.module_cache
251+
.module_metadata
252+
.set_map(cached_module.module.id.clone(), map);
253+
};
254+
}
255+
245256
/// recreate syntax context for the cached module
246257
pub fn handle_cached_modules(
247258
cached_module: &mut CachedModule,
@@ -284,6 +295,8 @@ pub fn handle_cached_modules(
284295
context,
285296
)?;
286297

298+
handle_module_metadata(cached_module, context);
299+
287300
// clear module groups and resource pot as it will be re-resolved later
288301
cached_module.module.module_groups.clear();
289302
cached_module.module.resource_pots = Default::default();

crates/compiler/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ impl Compiler {
228228
fn write_cache(context: Arc<CompilationContext>) {
229229
farm_profile_function!("write_cache".to_string());
230230
context.cache_manager.write_cache();
231-
context.cache_manager.custom.write_manifest();
232231
}
233232

234233
pub fn write_cache_async(context: Arc<CompilationContext>) {

crates/compiler/tests/bundle.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ fn test(file: String, crate_path: String, f: Option<impl Fn(&mut Config)>) {
8080
}
8181
}
8282

83-
fn single_bundle_test(file: String, crate_path: String) {
84-
test(file, crate_path, None::<fn(&mut Config)>);
85-
}
83+
// fn single_bundle_test(file: String, crate_path: String) {
84+
// test(file, crate_path, None::<fn(&mut Config)>);
85+
// }
8686

87-
fn multiple_bundle_test(file: String, crate_path: String) {
88-
test(
89-
file,
90-
crate_path,
91-
Some(|config: &mut Config| {
92-
config.partial_bundling.enforce_resources = vec![PartialBundlingEnforceResourceConfig {
93-
name: "bundle1".to_string(),
94-
test: vec![ConfigRegex::new("^bundle2.+")],
95-
}];
96-
}),
97-
);
98-
}
87+
// fn multiple_bundle_test(file: String, crate_path: String) {
88+
// test(
89+
// file,
90+
// crate_path,
91+
// Some(|config: &mut Config| {
92+
// config.partial_bundling.enforce_resources = vec![PartialBundlingEnforceResourceConfig {
93+
// name: "bundle1".to_string(),
94+
// test: vec![ConfigRegex::new("^bundle2.+")],
95+
// }];
96+
// }),
97+
// );
98+
// }
9999

100100
// farmfe_testing::testing! {"tests/fixtures/bundle/library/reexport/reexport_hybrid_cjs/namespace/**/index.ts", single_bundle_test}
101101

crates/compiler/tests/fixtures/mangle_exports/basic/output.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ initModuleSystem(__farm_internal_module_system__);
1212
})(window["__farm_default_namespace__"].m, {
1313
"44a34200": function(module, exports, farmRequire, farmDynamicRequire) {
1414
farmRequire._m(exports);
15-
farmRequire.o(exports, "b", function() {
15+
farmRequire.o(exports, "world", function() {
1616
return world;
1717
});
1818
farmRequire.o(exports, "default", function() {
1919
return sayHello;
2020
});
21-
farmRequire.o(exports, "a", function() {
21+
farmRequire.o(exports, "hello", function() {
2222
return hello;
2323
});
2424
const hello = 'hello';
@@ -31,7 +31,7 @@ initModuleSystem(__farm_internal_module_system__);
3131
farmRequire._m(exports);
3232
var _f_export = farmRequire.w(farmRequire("44a34200"));
3333
farmRequire.f(_f_export)();
34-
console.log(_f_export.a, _f_export.b);
34+
console.log(_f_export.hello, _f_export.world);
3535
}
3636
});
3737
var __farm_ms__ = window['__farm_default_namespace__'].m;__farm_ms__.b();var __farm_entry__=__farm_ms__.r("b5d64806");

crates/compiler/tests/fixtures/mangle_exports/cyclic-import/output.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ initModuleSystem(__farm_internal_module_system__);
1212
})(window["__farm_default_namespace__"].m, {
1313
"44a34200": function(module, exports, farmRequire, farmDynamicRequire) {
1414
farmRequire._m(exports);
15-
farmRequire.o(exports, "a", function() {
15+
farmRequire.o(exports, "hello", function() {
1616
return hello;
1717
});
18-
farmRequire.o(exports, "c", function() {
18+
farmRequire.o(exports, "world", function() {
1919
return world;
2020
});
21-
farmRequire.o(exports, "b", function() {
21+
farmRequire.o(exports, "sayHello", function() {
2222
return sayHello;
2323
});
2424
var _f_zoo = farmRequire("774fba3e");
2525
const hello = "hello";
2626
const world = "world";
2727
function sayHello() {
2828
console.log(hello, world);
29-
_f_zoo.a();
29+
_f_zoo.sayZoo();
3030
}
3131
},
3232
"774fba3e": function(module, exports, farmRequire, farmDynamicRequire) {
3333
farmRequire._m(exports);
34-
farmRequire.o(exports, "a", function() {
34+
farmRequire.o(exports, "sayZoo", function() {
3535
return sayZoo;
3636
});
37-
farmRequire.o(exports, "b", function() {
37+
farmRequire.o(exports, "zoo", function() {
3838
return zoo;
3939
});
4040
var _f_export = farmRequire("44a34200");
4141
const zoo = "zoo";
4242
function sayZoo() {
4343
console.log(zoo);
44-
_f_export.b();
44+
_f_export.sayHello();
4545
}
4646
},
4747
"b5d64806": function(module, exports, farmRequire, farmDynamicRequire) {
4848
farmRequire._m(exports);
4949
var _f_export = farmRequire("44a34200");
50-
console.log(_f_export.b);
50+
console.log(_f_export.sayHello);
5151
}
5252
});
5353
var __farm_ms__ = window['__farm_default_namespace__'].m;__farm_ms__.b();var __farm_entry__=__farm_ms__.r("b5d64806");

crates/compiler/tests/fixtures/mangle_exports/export-all/output.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ initModuleSystem(__farm_internal_module_system__);
1212
})(window["__farm_default_namespace__"].m, {
1313
"027594c8": function(module, exports, farmRequire, farmDynamicRequire) {
1414
farmRequire._m(exports);
15-
farmRequire.o(exports, "a", function() {
15+
farmRequire.o(exports, "Comp1", function() {
1616
return Comp1;
1717
});
18-
farmRequire.o(exports, "b", function() {
18+
farmRequire.o(exports, "Comp2", function() {
1919
return Comp2;
2020
});
2121
function Comp1() {
@@ -25,34 +25,30 @@ initModuleSystem(__farm_internal_module_system__);
2525
console.log('Comp2');
2626
}
2727
var _f_exports3 = farmRequire("69233311");
28-
farmRequire._(exports, "c", _f_exports3, "a");
28+
farmRequire._e(exports, _f_exports3);
2929
},
3030
"05ee5ec7": function(module, exports, farmRequire, farmDynamicRequire) {
3131
farmRequire._m(exports);
32-
farmRequire.o(exports, "a", function() {
32+
farmRequire.o(exports, "unstable_batchUpdate", function() {
3333
return unstable_batchUpdate;
3434
});
3535
var _f_exports = farmRequire("52961596");
36-
farmRequire._(exports, "b", _f_exports, "a");
37-
farmRequire._(exports, "c", _f_exports, "b");
38-
farmRequire._(exports, "d", _f_exports, "c");
36+
farmRequire._e(exports, _f_exports);
3937
var _f_exports1 = farmRequire("027594c8");
40-
farmRequire._(exports, "e", _f_exports1, "b");
41-
farmRequire._(exports, "f", _f_exports1, "c");
42-
farmRequire._(exports, "g", _f_exports1, "a");
38+
farmRequire._e(exports, _f_exports1);
4339
function unstable_batchUpdate() {
4440
console.log('unstable_batchUpdate');
4541
}
4642
},
4743
"52961596": function(module, exports, farmRequire, farmDynamicRequire) {
4844
farmRequire._m(exports);
49-
farmRequire.o(exports, "a", function() {
45+
farmRequire.o(exports, "Provider", function() {
5046
return Provider;
5147
});
52-
farmRequire.o(exports, "b", function() {
48+
farmRequire.o(exports, "useDispatch", function() {
5349
return useDispatch;
5450
});
55-
farmRequire.o(exports, "c", function() {
51+
farmRequire.o(exports, "useStore", function() {
5652
return useStore;
5753
});
5854
function Provider() {
@@ -67,7 +63,7 @@ initModuleSystem(__farm_internal_module_system__);
6763
},
6864
"69233311": function(module, exports, farmRequire, farmDynamicRequire) {
6965
farmRequire._m(exports);
70-
farmRequire.o(exports, "a", function() {
66+
farmRequire.o(exports, "Comp3", function() {
7167
return Comp3;
7268
});
7369
function Comp3() {
@@ -77,7 +73,7 @@ initModuleSystem(__farm_internal_module_system__);
7773
"b5d64806": function(module, exports, farmRequire, farmDynamicRequire) {
7874
farmRequire._m(exports);
7975
var _f_dep = farmRequire("05ee5ec7");
80-
console.log(_f_dep.b, _f_dep.a, _f_dep.g, _f_dep.e, _f_dep.f);
76+
console.log(_f_dep.Provider, _f_dep.unstable_batchUpdate, _f_dep.Comp1, _f_dep.Comp2, _f_dep.Comp3);
8177
}
8278
});
8379
var __farm_ms__ = window['__farm_default_namespace__'].m;__farm_ms__.b();var __farm_entry__=__farm_ms__.r("b5d64806");

crates/compiler/tests/fixtures/mangle_exports/external-import-conflicts/output.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ initModuleSystem(__farm_internal_module_system__);
5151
var _f_node_fs1 = farmRequire('node:fs');
5252
farmRequire._(exports, "existsSync", _f_node_fs1);
5353
var _f_zoo = farmRequire("774fba3e");
54-
farmRequire._(exports, "unresolvedDeep", _f_zoo);
55-
farmRequire._(exports, "createRequire", _f_zoo);
56-
farmRequire._(exports, "unresolved", _f_zoo);
57-
var _f_zoo1 = farmRequire("774fba3e");
58-
farmRequire._e(exports, _f_zoo1);
54+
farmRequire._e(exports, _f_zoo);
5955
}
6056
});
6157
var __farm_ms__ = window['__farm_default_namespace__'].m;__farm_ms__.b();var __farm_entry__=__farm_ms__.r("b5d64806");

crates/compiler/tests/fixtures/mangle_exports/reexport-named/output.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@ initModuleSystem(__farm_internal_module_system__);
1212
})(window["__farm_default_namespace__"].m, {
1313
"027594c8": function(module, exports, farmRequire, farmDynamicRequire) {
1414
farmRequire._m(exports);
15-
farmRequire.o(exports, "a", function() {
15+
farmRequire.o(exports, "Alpha", function() {
1616
return Alpha;
1717
});
1818
function Alpha() {
1919
return 'Alpha';
2020
}
2121
exports.default = Alpha;
2222
var _f_exports2 = farmRequire("405aeea7");
23-
farmRequire._(exports, "b", _f_exports2, "a");
23+
farmRequire._e(exports, _f_exports2);
2424
},
2525
"05ee5ec7": function(module, exports, farmRequire, farmDynamicRequire) {
2626
farmRequire._m(exports);
27-
farmRequire.o(exports, "a", function() {
27+
farmRequire.o(exports, "MyAlpha", function() {
2828
return MyAlpha;
2929
});
3030
var _f_exports1 = farmRequire("027594c8");
3131
var _f_exports11 = farmRequire("027594c8");
32-
farmRequire._(exports, "b", _f_exports11, "a");
33-
farmRequire._(exports, "c", _f_exports11, "b");
32+
farmRequire._(exports, "Alpha", _f_exports11);
33+
farmRequire._(exports, "Checkboard", _f_exports11);
3434
class MyAlpha {
3535
constructor(){
36-
return _f_exports1.a;
36+
return _f_exports1.Alpha;
3737
}
3838
}
3939
},
4040
"405aeea7": function(module, exports, farmRequire, farmDynamicRequire) {
4141
farmRequire._m(exports);
42-
farmRequire.o(exports, "a", function() {
42+
farmRequire.o(exports, "Checkboard", function() {
4343
return Checkboard;
4444
});
4545
function Checkboard() {
@@ -50,7 +50,7 @@ initModuleSystem(__farm_internal_module_system__);
5050
"b5d64806": function(module, exports, farmRequire, farmDynamicRequire) {
5151
farmRequire._m(exports);
5252
var _f_dep = farmRequire("05ee5ec7");
53-
console.log(_f_dep.b, _f_dep.c, _f_dep.a);
53+
console.log(_f_dep.Alpha, _f_dep.Checkboard, _f_dep.MyAlpha);
5454
}
5555
});
5656
var __farm_ms__ = window['__farm_default_namespace__'].m;__farm_ms__.b();var __farm_entry__=__farm_ms__.r("b5d64806");

0 commit comments

Comments
 (0)