rolldown-plugin-concurrent-top-level-await 0.1.0 → 0.2.0
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 +18 -13
- 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: {
|
|
@@ -411,6 +412,7 @@ const supportedModuleTypes = new Set([
|
|
|
411
412
|
"ts",
|
|
412
413
|
"tsx"
|
|
413
414
|
]);
|
|
415
|
+
let nativeMagicStringWarned = false;
|
|
414
416
|
function resolveDeclarationSource(context, id, declaration) {
|
|
415
417
|
return context.resolve(declaration.source.value, id, { custom: {} });
|
|
416
418
|
}
|
|
@@ -450,10 +452,13 @@ function transformPlugin(options) {
|
|
|
450
452
|
if (!(asyncImports.length > 0 || hasAwait)) return;
|
|
451
453
|
const { magicString: _magicString } = transformOptions;
|
|
452
454
|
const magicString = new RolldownMagicString(code);
|
|
453
|
-
if (!_magicString
|
|
455
|
+
if (!_magicString && !nativeMagicStringWarned) {
|
|
456
|
+
this.warn("Enable experimental.nativeMagicString for source maps support");
|
|
457
|
+
nativeMagicStringWarned = true;
|
|
458
|
+
}
|
|
454
459
|
transform$1(magicString, ast, options.registerModuleSource, asyncImports, hasAwait, generatedVariablePrefix);
|
|
455
460
|
return {
|
|
456
|
-
code: magicString,
|
|
461
|
+
code: _magicString != null ? magicString : magicString.toString(),
|
|
457
462
|
meta: { [generatedVariablePrefix + "_async"]: true }
|
|
458
463
|
};
|
|
459
464
|
}
|
|
@@ -469,7 +474,7 @@ function concurrentTopLevelAwait(options = {}) {
|
|
|
469
474
|
...options,
|
|
470
475
|
generatedVariablePrefix,
|
|
471
476
|
registerModuleSource: `\0${generatedVariablePrefix}Register`,
|
|
472
|
-
filter: createFilter(options.include, options.exclude ?? /\/node_modules
|
|
477
|
+
filter: createFilter(options.include, options.exclude ?? [/\/node_modules\//, /\.html$/])
|
|
473
478
|
};
|
|
474
479
|
return [
|
|
475
480
|
awaitEntrypointsPlugin(enrichedOptions),
|
package/package.json
CHANGED