rolldown-plugin-concurrent-top-level-await 0.1.0 → 0.2.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 +1 -1
- package/dist/index.mjs +26 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ export default defineConfig({
|
|
|
47
47
|
| Option | Type | Default | Description |
|
|
48
48
|
| ------------------------- | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
49
49
|
| `include` | `RegExp | RegExp[]` | `undefined` | A RegExp specifying which files to include. See [below](#which-modules-to-include) to determine which modules to include. |
|
|
50
|
-
| `exclude` | `RegExp | RegExp[]` |
|
|
50
|
+
| `exclude` | `RegExp | RegExp[]` | `[/\/node_modules\//, /\.html$/]` | A RegExp specifying which files to exclude. Must still follow the [same considerations](#which-modules-to-include) as `include`. |
|
|
51
51
|
| `generatedVariablePrefix` | `string` | `"__tla"` | Prefix used for internal variables generated by the plugin. Change this if it conflicts with variable names in your code. |
|
|
52
52
|
|
|
53
53
|
### Which modules to include?
|
package/dist/index.mjs
CHANGED
|
@@ -46,17 +46,18 @@ function awaitEntrypointsPlugin(options) {
|
|
|
46
46
|
order: "pre",
|
|
47
47
|
async handler(source, importer, extraOptions) {
|
|
48
48
|
if (importer?.startsWith(proxyPrefix)) {
|
|
49
|
-
const key
|
|
50
|
-
const resolved
|
|
51
|
-
if (!resolved
|
|
52
|
-
return resolved
|
|
49
|
+
const key = importer.slice(proxyPrefix.length);
|
|
50
|
+
const resolved = awaitedEntriesMap.get(key);
|
|
51
|
+
if (!resolved) throw new Error("Name collision in concurrent-tla plugin, please change the generatedVariablePrefix option");
|
|
52
|
+
return resolved;
|
|
53
|
+
}
|
|
54
|
+
if (extraOptions.isEntry || extraOptions.kind === "dynamic-import" || importer != null && !options.filter.includes(importer)) {
|
|
55
|
+
const resolved = await this.resolve(source, importer, extraOptions);
|
|
56
|
+
if (resolved == null || !options.filter.includes(resolved.id)) return;
|
|
57
|
+
const key = randomUUID();
|
|
58
|
+
awaitedEntriesMap.set(key, resolved);
|
|
59
|
+
return `${proxyPrefix}${key}`;
|
|
53
60
|
}
|
|
54
|
-
if (!extraOptions.isEntry && extraOptions.kind !== "dynamic-import") return;
|
|
55
|
-
const resolved = await this.resolve(source, importer, extraOptions);
|
|
56
|
-
if (resolved == null || !options.filter.includes(resolved.id)) return;
|
|
57
|
-
const key = randomUUID();
|
|
58
|
-
awaitedEntriesMap.set(key, resolved);
|
|
59
|
-
return `${proxyPrefix}${key}`;
|
|
60
61
|
}
|
|
61
62
|
},
|
|
62
63
|
load: {
|
|
@@ -65,12 +66,16 @@ function awaitEntrypointsPlugin(options) {
|
|
|
65
66
|
if (id.startsWith(proxyPrefix)) {
|
|
66
67
|
const resolved = awaitedEntriesMap.get(id.slice(proxyPrefix.length));
|
|
67
68
|
if (!resolved) throw new Error("Name collision in concurrent-tla plugin, please change the generatedVariablePrefix option");
|
|
68
|
-
|
|
69
|
+
const module = await this.load(resolved);
|
|
70
|
+
let code = "";
|
|
71
|
+
if (module.meta[generatedVariablePrefix + "_async"]) code += `import { ${generatedVariablePrefix}_access } from "${resolved.id}";
|
|
69
72
|
await new Promise(${generatedVariablePrefix}_access);
|
|
70
|
-
export * from "${resolved.id}";
|
|
71
73
|
`;
|
|
72
|
-
|
|
74
|
+
if (module.exports.includes("default")) code += `import ${generatedVariablePrefix}_default from "${resolved.id}";
|
|
75
|
+
export default ${generatedVariablePrefix}_default;
|
|
73
76
|
`;
|
|
77
|
+
code += `export * from "${resolved.id}";\n`;
|
|
78
|
+
return code;
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
}
|
|
@@ -361,7 +366,7 @@ function isFunctionDeclaration(type) {
|
|
|
361
366
|
return type === "FunctionDeclaration";
|
|
362
367
|
}
|
|
363
368
|
function getClassDeclarationStart(node) {
|
|
364
|
-
return node.decorators[0]?.start ?? node.start;
|
|
369
|
+
return node.decorators?.[0]?.start ?? node.start;
|
|
365
370
|
}
|
|
366
371
|
function moveVariableDeclarationToModuleScope(s, node, declarationsEnd) {
|
|
367
372
|
const kind = replaceConstWithLet(node.kind);
|
|
@@ -411,6 +416,7 @@ const supportedModuleTypes = new Set([
|
|
|
411
416
|
"ts",
|
|
412
417
|
"tsx"
|
|
413
418
|
]);
|
|
419
|
+
let nativeMagicStringWarned = false;
|
|
414
420
|
function resolveDeclarationSource(context, id, declaration) {
|
|
415
421
|
return context.resolve(declaration.source.value, id, { custom: {} });
|
|
416
422
|
}
|
|
@@ -450,10 +456,13 @@ function transformPlugin(options) {
|
|
|
450
456
|
if (!(asyncImports.length > 0 || hasAwait)) return;
|
|
451
457
|
const { magicString: _magicString } = transformOptions;
|
|
452
458
|
const magicString = new RolldownMagicString(code);
|
|
453
|
-
if (!_magicString
|
|
459
|
+
if (!_magicString && !nativeMagicStringWarned) {
|
|
460
|
+
this.warn("Enable experimental.nativeMagicString for source maps support");
|
|
461
|
+
nativeMagicStringWarned = true;
|
|
462
|
+
}
|
|
454
463
|
transform$1(magicString, ast, options.registerModuleSource, asyncImports, hasAwait, generatedVariablePrefix);
|
|
455
464
|
return {
|
|
456
|
-
code: magicString,
|
|
465
|
+
code: _magicString != null ? magicString : magicString.toString(),
|
|
457
466
|
meta: { [generatedVariablePrefix + "_async"]: true }
|
|
458
467
|
};
|
|
459
468
|
}
|
|
@@ -469,7 +478,7 @@ function concurrentTopLevelAwait(options = {}) {
|
|
|
469
478
|
...options,
|
|
470
479
|
generatedVariablePrefix,
|
|
471
480
|
registerModuleSource: `\0${generatedVariablePrefix}Register`,
|
|
472
|
-
filter: createFilter(options.include, options.exclude ?? /\/node_modules
|
|
481
|
+
filter: createFilter(options.include, options.exclude ?? [/\/node_modules\//, /\.html$/])
|
|
473
482
|
};
|
|
474
483
|
return [
|
|
475
484
|
awaitEntrypointsPlugin(enrichedOptions),
|
package/package.json
CHANGED