Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78945df

Browse files
authored
feat(advancedChunks): ensure strict execution order if advancedChunksenabled (#2620)
<!-- Thank you for contributing! --> ### Description People start to use rolldown now. We need to make sure exposed functionalites work well automatically instead of telling people to manually make it work. <!-- Please insert your description here and provide especially info about the "what" this PR is solving -->
1 parent 73229c4 commit 78945df

9 files changed

Lines changed: 226 additions & 58 deletions

File tree

crates/rolldown/src/utils/normalize_options.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ pub fn normalize_options(mut raw_options: crate::BundlerOptions) -> NormalizeOpt
7474
.unwrap_or_default(),
7575
);
7676

77+
let mut experimental = raw_options.experimental.unwrap_or_default();
78+
let is_advanced_chunks_enabled = raw_options
79+
.advanced_chunks
80+
.as_ref()
81+
.is_some_and(|inner| inner.groups.as_ref().is_some_and(|inner| !inner.is_empty()));
82+
if experimental.strict_execution_order.is_none() && is_advanced_chunks_enabled {
83+
experimental.strict_execution_order = Some(true);
84+
}
85+
7786
let normalized = NormalizedBundlerOptions {
7887
input: raw_options.input.unwrap_or_default(),
7988
cwd: raw_options
@@ -113,7 +122,7 @@ pub fn normalize_options(mut raw_options: crate::BundlerOptions) -> NormalizeOpt
113122
sourcemap_debug_ids: raw_options.sourcemap_debug_ids.unwrap_or(false),
114123
shim_missing_exports: raw_options.shim_missing_exports.unwrap_or(false),
115124
module_types: loaders,
116-
experimental: raw_options.experimental.unwrap_or_default(),
125+
experimental,
117126
minify: raw_options.minify.unwrap_or(false),
118127
define: raw_options.define.map(|inner| inner.into_iter().collect()).unwrap_or_default(),
119128
inject: raw_options.inject.unwrap_or_default(),
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
---
22
source: crates/rolldown_testing/src/integration_test.rs
3+
snapshot_kind: text
34
---
45
# Assets
56

67
## a.js
78

89
```js
9-
import { a } from "./common.js";
10+
import { a, init_a } from "./common.js";
1011
12+
init_a();
1113
export { a };
1214
```
1315
## b.js
1416

1517
```js
16-
import { b } from "./common.js";
18+
import { b, init_b } from "./common.js";
1719
20+
init_b();
1821
export { b };
1922
```
2023
## common.js
2124

2225
```js
2326
27+
2428
//#region a.js
25-
const a = "a";
29+
var a;
30+
var init_a = __esm({ "a.js"() {
31+
a = "a";
32+
} });
2633
2734
//#endregion
2835
//#region b.js
29-
const b = "a";
36+
var b;
37+
var init_b = __esm({ "b.js"() {
38+
b = "a";
39+
} });
3040
3141
//#endregion
32-
export { a, b };
42+
export { a, b, init_a, init_b };
3343
```

crates/rolldown/tests/rolldown/function/advanced_chunks/issue_2617/artifacts.snap

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,33 @@ snapshot_kind: text
77
## main.js
88

99
```js
10-
import { lib_default } from "./splited_lib.js";
10+
import { __esm, init_lib, lib_default } from "./splited_lib.js";
1111
1212
//#region main.js
13-
console.log("lib", lib_default);
13+
var init_main = __esm({ "main.js"() {
14+
init_lib();
15+
console.log("lib", lib_default);
16+
} });
1417
1518
//#endregion
19+
init_main();
1620
```
1721
## splited_lib.js
1822

1923
```js
2024
25+
26+
//#region shaked.js
27+
var init_shaked = __esm({ "shaked.js"() {} });
28+
29+
//#endregion
2130
//#region lib.js
22-
var lib_default = "hello, world";
31+
var lib_default;
32+
var init_lib = __esm({ "lib.js"() {
33+
init_shaked();
34+
lib_default = "hello, world";
35+
} });
2336
2437
//#endregion
25-
export { lib_default };
38+
export { __esm, init_lib, lib_default };
2639
```
Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,73 @@
11
---
22
source: crates/rolldown_testing/src/integration_test.rs
3+
snapshot_kind: text
34
---
45
# Assets
56

67
## a.js
78

89
```js
9-
import "./at_least_share_by_2.js";
10+
import { __esm, init_share_by_2, init_share_by_3 } from "./at_least_share_by_2.js";
1011
1112
//#region share-by-1.js
12-
console.log("share-by-1");
13+
var init_share_by_1 = __esm({ "share-by-1.js"() {
14+
console.log("share-by-1");
15+
} });
1316
1417
//#endregion
18+
//#region a.js
19+
var init_a = __esm({ "a.js"() {
20+
init_share_by_1();
21+
init_share_by_2();
22+
init_share_by_3();
23+
} });
24+
25+
//#endregion
26+
init_a();
1527
```
1628
## at_least_share_by_2.js
1729

1830
```js
1931
32+
2033
//#region share-by-2.js
21-
console.log("share-by-2");
34+
var init_share_by_2 = __esm({ "share-by-2.js"() {
35+
console.log("share-by-2");
36+
} });
2237
2338
//#endregion
2439
//#region share-by-3.js
25-
console.log("share-by-3");
40+
var init_share_by_3 = __esm({ "share-by-3.js"() {
41+
console.log("share-by-3");
42+
} });
2643
2744
//#endregion
45+
export { __esm, init_share_by_2, init_share_by_3 };
2846
```
2947
## b.js
3048

3149
```js
32-
import "./at_least_share_by_2.js";
50+
import { __esm, init_share_by_2, init_share_by_3 } from "./at_least_share_by_2.js";
51+
52+
//#region b.js
53+
var init_b = __esm({ "b.js"() {
54+
init_share_by_2();
55+
init_share_by_3();
56+
} });
3357
58+
//#endregion
59+
init_b();
3460
```
3561
## c.js
3662

3763
```js
38-
import "./at_least_share_by_2.js";
64+
import { __esm, init_share_by_3 } from "./at_least_share_by_2.js";
65+
66+
//#region c.js
67+
var init_c = __esm({ "c.js"() {
68+
init_share_by_3();
69+
} });
3970
71+
//#endregion
72+
init_c();
4073
```
Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,73 @@
11
---
22
source: crates/rolldown_testing/src/integration_test.rs
3+
snapshot_kind: text
34
---
45
# Assets
56

67
## a.js
78

89
```js
9-
import "./at_least_share_by_2.js";
10+
import { __esm, init_share_by_2, init_share_by_3 } from "./at_least_share_by_2.js";
1011
1112
//#region share-by-1.js
12-
console.log("share-by-1");
13+
var init_share_by_1 = __esm({ "share-by-1.js"() {
14+
console.log("share-by-1");
15+
} });
1316
1417
//#endregion
18+
//#region a.js
19+
var init_a = __esm({ "a.js"() {
20+
init_share_by_1();
21+
init_share_by_2();
22+
init_share_by_3();
23+
} });
24+
25+
//#endregion
26+
init_a();
1527
```
1628
## at_least_share_by_2.js
1729

1830
```js
1931
32+
2033
//#region share-by-2.js
21-
console.log("share-by-2");
34+
var init_share_by_2 = __esm({ "share-by-2.js"() {
35+
console.log("share-by-2");
36+
} });
2237
2338
//#endregion
2439
//#region share-by-3.js
25-
console.log("share-by-3");
40+
var init_share_by_3 = __esm({ "share-by-3.js"() {
41+
console.log("share-by-3");
42+
} });
2643
2744
//#endregion
45+
export { __esm, init_share_by_2, init_share_by_3 };
2846
```
2947
## b.js
3048

3149
```js
32-
import "./at_least_share_by_2.js";
50+
import { __esm, init_share_by_2, init_share_by_3 } from "./at_least_share_by_2.js";
51+
52+
//#region b.js
53+
var init_b = __esm({ "b.js"() {
54+
init_share_by_2();
55+
init_share_by_3();
56+
} });
3357
58+
//#endregion
59+
init_b();
3460
```
3561
## c.js
3662

3763
```js
38-
import "./at_least_share_by_2.js";
64+
import { __esm, init_share_by_3 } from "./at_least_share_by_2.js";
65+
66+
//#region c.js
67+
var init_c = __esm({ "c.js"() {
68+
init_share_by_3();
69+
} });
3970
71+
//#endregion
72+
init_c();
4073
```
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
---
22
source: crates/rolldown_testing/src/integration_test.rs
3+
snapshot_kind: text
34
---
45
# Assets
56

7+
## common_a.js
8+
9+
```js
10+
11+
12+
//#region a.js
13+
var init_a = __esm({ "a.js"() {
14+
console.log("a");
15+
} });
16+
17+
//#endregion
18+
export { __esm, init_a };
19+
```
620
## common_b.js
721

822
```js
23+
import { __esm } from "./common_a.js";
924
1025
//#region b.js
11-
console.log("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
26+
var init_b = __esm({ "b.js"() {
27+
console.log("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
28+
} });
1229
1330
//#endregion
31+
export { init_b };
1432
```
1533
## main.js
1634

1735
```js
18-
import "./common_b.js";
36+
import { __esm, init_a } from "./common_a.js";
37+
import { init_b } from "./common_b.js";
1938
20-
//#region a.js
21-
console.log("a");
39+
//#region main.js
40+
var init_main = __esm({ "main.js"() {
41+
init_a();
42+
init_b();
43+
} });
2244
2345
//#endregion
46+
init_main();
2447
```
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11
---
22
source: crates/rolldown_testing/src/integration_test.rs
3+
snapshot_kind: text
34
---
45
# Assets
56

7+
## common_a.js
8+
9+
```js
10+
11+
12+
//#region a.js
13+
var init_a = __esm({ "a.js"() {
14+
console.log("a");
15+
} });
16+
17+
//#endregion
18+
export { __esm, init_a };
19+
```
620
## common_b.js
721

822
```js
23+
import { __esm } from "./common_a.js";
924
1025
//#region b.js
11-
console.log("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
26+
var init_b = __esm({ "b.js"() {
27+
console.log("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
28+
} });
1229
1330
//#endregion
31+
export { init_b };
1432
```
1533
## main.js
1634

1735
```js
18-
import "./common_b.js";
36+
import { __esm, init_a } from "./common_a.js";
37+
import { init_b } from "./common_b.js";
1938
20-
//#region a.js
21-
console.log("a");
39+
//#region main.js
40+
var init_main = __esm({ "main.js"() {
41+
init_a();
42+
init_b();
43+
} });
2244
2345
//#endregion
46+
init_main();
2447
```

0 commit comments

Comments
 (0)