rolldown-plugin-concurrent-top-level-await 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
> [!Warning]
|
|
2
|
+
> This plugin is currently in development. A filter option will be added soon. For more information, see [this issue](https://github.com/zOadT/concurrent-top-level-await-plugins/issues/35).
|
|
3
|
+
|
|
4
|
+
# rolldown-plugin-concurrent-top-level-await
|
|
5
|
+
|
|
6
|
+
Rolldown (and therefore also Vite) will change the behavior of modules containing top level await (TLA):
|
|
7
|
+
they run sequentially instead of concurrently, as described in
|
|
8
|
+
[the Rolldown docs](https://github.com/rolldown/rolldown/blob/main/docs/in-depth/tla-in-rolldown.md).
|
|
9
|
+
This Vite-compatible plugin enables concurrent execution of TLA modules.
|
|
10
|
+
|
|
11
|
+
Note that this plugin requires TLA support at runtime; it does _not_ provide a TLA polyfill.
|
|
12
|
+
For that, check out [vite-plugin-top-level-await](https://www.npmjs.com/package/vite-plugin-top-level-await).
|
|
13
|
+
|
|
14
|
+
<!-- ### Evaluation Order
|
|
15
|
+
|
|
16
|
+
The evaluation order closely matches V8's behavior according to [tla-fuzzer](https://github.com/evanw/tla-fuzzer).
|
|
17
|
+
Minor deviations can still occur though.
|
|
18
|
+
|
|
19
|
+
| Variant | Rollup | Rollup with Plugin |
|
|
20
|
+
| ------------------------ | ------ | ------------------ |
|
|
21
|
+
| Simple | 80% | 99% |
|
|
22
|
+
| Trailing Promise | 10% | 99% |
|
|
23
|
+
| Cyclic | 69% | 99% |
|
|
24
|
+
| Cyclic, Trailing Promise | 15% | 99% | -->
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Using npm:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install rolldown-plugin-concurrent-top-level-await --save-dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import concurrentTopLevelAwait from "rolldown-plugin-concurrent-top-level-await";
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
experimental: { nativeMagicString: true },
|
|
41
|
+
plugins: [concurrentTopLevelAwait()],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| ------------------------- | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| `generatedVariablePrefix` | `string` | `"__tla"` | Prefix used for internal variables generated by the plugin. Change this if it conflicts with variable names in your code. |
|
|
50
|
+
|
|
51
|
+
### Which modules to include?
|
|
52
|
+
|
|
53
|
+
The plugin needs to handle not only modules that directly contain a top-level `await`, but also their ancestor modules up to the lowest common ancestor. Ancestor modules must be transformed to handle the asynchronous completion of their children concurrently. If an ancestor module is not transformed, its direct dependencies will become blocking and therefore alter the evaluation order.
|
|
54
|
+
|
|
55
|
+
Consider the following module structure as an example:
|
|
56
|
+
|
|
57
|
+
```mermaid
|
|
58
|
+
flowchart LR
|
|
59
|
+
app[app.js]
|
|
60
|
+
moduleA[moduleA.js]
|
|
61
|
+
moduleB[moduleB.js]
|
|
62
|
+
moduleC[moduleC.js]
|
|
63
|
+
tla1[tla1.js]
|
|
64
|
+
tla2[tla2.js]
|
|
65
|
+
tla3[tla3.js]
|
|
66
|
+
other[other.js]
|
|
67
|
+
|
|
68
|
+
app --> moduleA
|
|
69
|
+
moduleA --> moduleB
|
|
70
|
+
moduleA --> moduleC
|
|
71
|
+
moduleB --> tla1
|
|
72
|
+
moduleC --> tla2
|
|
73
|
+
moduleC --> tla3
|
|
74
|
+
app --> other
|
|
75
|
+
|
|
76
|
+
classDef tla fill:#ffe6e6,stroke:#ff0000,color:#660000
|
|
77
|
+
classDef ancestor fill:#fff4cc,stroke:#ffcc00,color:#663300
|
|
78
|
+
classDef unaffected fill:#e6ffe6,stroke:#00cc00,color:#006600
|
|
79
|
+
|
|
80
|
+
class tla1,tla2,tla3 tla
|
|
81
|
+
class moduleA,moduleB,moduleC ancestor
|
|
82
|
+
class app,other unaffected
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If the red modules contain top level awaits, these and their yellow ancestors should be included in the plugin's `include` option.
|
|
86
|
+
|
|
87
|
+
## Known Limitations
|
|
88
|
+
|
|
89
|
+
### Circular Dependencies
|
|
90
|
+
|
|
91
|
+
There is a known issue where modules in a circular dependency don't get executed.
|
|
92
|
+
|
|
93
|
+
### Evaluation Order
|
|
94
|
+
|
|
95
|
+
As can be seen in the table above, the plugin does not guarantee 100% matching of V8's evaluation order, although the deviations should be pretty minor in practice. If you encounter significant deviations, please open an issue.
|
|
96
|
+
|
|
97
|
+
Additionally, some scenarios are known to cause deviations, e.g. when the [`include` option is not correctly configured](#which-modules-to-include) or when there is a dependency cycle that is split across multiple chunks.
|
|
98
|
+
|
|
99
|
+
### Build Performance
|
|
100
|
+
|
|
101
|
+
To transform a module, the plugin needs to check if any of its dependencies is async. Hence, the transformation is
|
|
102
|
+
postponed until the subgraph is analyzed. This may lead to slower builds.
|
|
103
|
+
|
|
104
|
+
If you notice significant performance degradation, please open an issue.
|
|
105
|
+
|
|
106
|
+
### Exposed Module Structure
|
|
107
|
+
|
|
108
|
+
Because the execution of modules gets wrapped in functions, the bundled output will contain more information about the source module structure. This may be a consideration for projects where code obfuscation is important.
|
|
109
|
+
|
|
110
|
+
### Tree Shaking
|
|
111
|
+
|
|
112
|
+
Wrapping code in functions may reduce tree shaking effectiveness. We mitigate this where possible, such as by not wrapping declarations.
|
|
113
|
+
|
|
114
|
+
### Changing Variable Types
|
|
115
|
+
|
|
116
|
+
In the process of transforming the code, top level `const` declarations may get replaced with `let` declarations. This
|
|
117
|
+
can lead to `const` variables being assignable at runtime instead of throwing an invalid assignment error.
|
|
118
|
+
|
|
119
|
+
Additionally, variable declarations may be hoisted, which removes temporal dead zone (TDZ) checks.
|
|
120
|
+
|
|
121
|
+
### Default export class name
|
|
122
|
+
|
|
123
|
+
When using `export default class {}`, the runtime `.name` of the exported value will be `<generatedVariablePrefix>_default` (e.g. `__tla_default`) instead of `default`.
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rolldown-plugin-concurrent-top-level-await",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Rolldown (and Vite) plugin enabling concurrent execution of modules that contain top level await.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rolldown-plugin",
|
|
7
|
+
"vite-plugin",
|
|
8
|
+
"top-level-await",
|
|
9
|
+
"tla",
|
|
10
|
+
"concurrent",
|
|
11
|
+
"async",
|
|
12
|
+
"modules",
|
|
13
|
+
"es2022"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"main": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsdown --dts"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/zOadT/concurrent-top-level-await-plugins.git"
|
|
31
|
+
},
|
|
32
|
+
"author": "Oliver Zell",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/zOadT/concurrent-top-level-await-plugins/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/zOadT/concurrent-top-level-await-plugins/tree/main/packages/rolldown-plugin#readme",
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"rolldown": "^1.0.0-rc.0",
|
|
40
|
+
"vite": "^8.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"rolldown": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"vite": {
|
|
47
|
+
"optional": true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"compatiblePackages": {
|
|
51
|
+
"schemaVersion": 1,
|
|
52
|
+
"rollup": {
|
|
53
|
+
"type": "incompatible",
|
|
54
|
+
"reason": "Uses Rolldown-specific APIs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@rolldown/pluginutils": "1.0.0-rc.9"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/estree": "^1.0.8",
|
|
62
|
+
"prettier": "3.7.4",
|
|
63
|
+
"rolldown": "1.0.0-rc.9"
|
|
64
|
+
}
|
|
65
|
+
}
|