rollup-plugin-concurrent-top-level-await 0.2.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/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { FilterPattern } from "@rollup/pluginutils";
2
2
  import * as magic_string0 from "magic-string";
3
3
  import * as rollup0 from "rollup";
4
+ import { TransformPluginContext } from "rollup";
4
5
 
5
6
  //#region src/index.d.ts
6
7
  declare function concurrentTopLevelAwait(options?: {
@@ -17,7 +18,10 @@ declare function concurrentTopLevelAwait(options?: {
17
18
  name: string;
18
19
  apply: "build";
19
20
  transform: {
20
- handler(this: rollup0.TransformPluginContext, code: string, id: string): Promise<{
21
+ handler(this: TransformPluginContext, code: string, id: string, transformOptions: {
22
+ ssr?: boolean | undefined;
23
+ attributes?: Record<string, string>;
24
+ } | undefined): Promise<{
21
25
  code: string;
22
26
  map: magic_string0.SourceMap | null;
23
27
  } | undefined>;
@@ -25,6 +29,7 @@ declare function concurrentTopLevelAwait(options?: {
25
29
  resolveImportMeta(this: rollup0.PluginContext, property: string | null, {
26
30
  moduleId
27
31
  }: {
32
+ attributes: Record<string, string>;
28
33
  chunkId: string;
29
34
  format: rollup0.InternalModuleFormat;
30
35
  moduleId: string;
package/dist/index.mjs CHANGED
@@ -243,13 +243,20 @@ function getNames(pattern) {
243
243
 
244
244
  //#endregion
245
245
  //#region src/index.ts
246
+ function resolveDeclarationSource(context, id, importerAttributes = {}, declaration) {
247
+ return context.resolve(declaration.source.value, id, {
248
+ attributes: Object.fromEntries(declaration.attributes.map((attr) => [attr.key.type === "Identifier" ? attr.key.name : attr.key.value, attr.value.value])),
249
+ importerAttributes,
250
+ custom: {}
251
+ });
252
+ }
246
253
  function concurrentTopLevelAwait(options = {}) {
247
254
  const filter = createFilter(options.include, options.exclude);
248
255
  const asyncTracker = new AsyncModuleTracker();
249
256
  return {
250
257
  name: "rollup-plugin-concurrent-tla-plugin",
251
258
  apply: "build",
252
- transform: { async handler(code, id) {
259
+ transform: { async handler(code, id, transformOptions) {
253
260
  if (!filter(id)) return;
254
261
  const ast = this.parse(code);
255
262
  const importDeclarations = ast.body.filter((a) => a.type === "ImportDeclaration");
@@ -258,14 +265,14 @@ function concurrentTopLevelAwait(options = {}) {
258
265
  if (hasAwait) asyncTracker.setDependencies(id, []);
259
266
  else {
260
267
  const childrenIds = (await Promise.all(importDeclarations.map(async (declaration) => {
261
- const importId = await this.resolve(declaration.source.value, id);
268
+ const importId = await resolveDeclarationSource(this, id, transformOptions?.attributes, declaration);
262
269
  if (!importId || !filter(importId.id)) return null;
263
270
  return importId.id;
264
271
  }))).filter((a) => a != null);
265
272
  asyncTracker.setDependencies(id, childrenIds);
266
273
  }
267
274
  const asyncImports = (await Promise.all(importDeclarations.map(async (declaration) => {
268
- const importId = await this.resolve(declaration.source.value, id);
275
+ const importId = await resolveDeclarationSource(this, id, transformOptions?.attributes, declaration);
269
276
  if (!importId || !filter(importId.id)) return null;
270
277
  this.load(importId);
271
278
  if (!await asyncTracker.isAsync(importId.id)) return null;
@@ -282,9 +289,9 @@ function concurrentTopLevelAwait(options = {}) {
282
289
  resolveImportMeta(property, { moduleId }) {
283
290
  if (property !== "useTla") return;
284
291
  const moduleInfo = this.getModuleInfo(moduleId);
285
- const importers = moduleInfo?.importers;
286
- if (moduleInfo?.isEntry || !importers?.length) return "true";
287
- if (importers.some((id) => !filter(id))) return "true";
292
+ if (moduleInfo?.isEntry) return "true";
293
+ if (moduleInfo?.dynamicImporters.length) return "true";
294
+ if ((moduleInfo?.importers)?.some((id) => !filter(id))) return "true";
288
295
  return "false";
289
296
  }
290
297
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-concurrent-top-level-await",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Rollup (and Vite) plugin enabling concurrent execution of modules that contain top level await.",
5
5
  "keywords": [
6
6
  "rollup-plugin",
@@ -46,7 +46,8 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/estree": "^1.0.8",
49
- "prettier": "3.7.4"
49
+ "prettier": "3.7.4",
50
+ "rollup": "^4.57.1"
50
51
  },
51
52
  "scripts": {
52
53
  "build": "tsdown --dts"