wesl-fetch 0.0.6 → 0.0.8

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.js CHANGED
@@ -1,22 +1,19 @@
1
- import { init, parse } from "es-module-lexer";
2
1
  import { gunzipSync } from "fflate";
3
2
  import { parseTar } from "nanotar";
4
3
  import { RecordResolver, fileToModulePath, findUnboundIdents, modulePartsToRelativePath, npmNameVariations, parseSrcModule, partition } from "wesl";
5
4
  import { resolve } from "resolve.exports";
6
5
 
7
6
  //#region src/BundleHydrator.ts
8
- const initPromise = init;
7
+ const importPattern = /import\s+(?:\*\s+as\s+)?(\w+)\s+from\s+["']([^"']+)["']/g;
9
8
  const nestedBundlePattern = /package\/dist\/(.+)\/weslBundle\.js$/;
10
9
  const rootBundlePattern = /package\/dist\/weslBundle\.js$/;
11
10
  const weslBundleExportPattern = /export\s+const\s+weslBundle\s*=\s*({[\s\S]+});?\s*$/m;
12
- const importVarPattern = /import\s+(\w+)\s+from/;
13
11
  /** Load WeslBundle objects from BundleFile sources. */
14
12
  async function loadBundlesFromFiles(bundleFiles) {
15
13
  return hydrateBundleRegistry(await bundleRegistry(bundleFiles));
16
14
  }
17
15
  /** Parse bundle files into a registry without hydrating. */
18
16
  async function bundleRegistry(bundleFiles, registry = /* @__PURE__ */ new Map()) {
19
- await initPromise;
20
17
  for (const file of bundleFiles) {
21
18
  const { content, packagePath, packageName } = file;
22
19
  const bundleInfo = parseBundleImports(content);
@@ -32,19 +29,14 @@ async function hydrateBundleRegistry(registry, fetcher) {
32
29
  for (const path of registry.keys()) bundles.push(await hydrateBundle(path, registry, hydrated, fetcher));
33
30
  return bundles;
34
31
  }
35
- /** Parse ES module imports from bundle code using es-module-lexer. */
32
+ /** Parse ES module imports from bundle code. */
36
33
  function parseBundleImports(code) {
37
34
  const exportMatch = code.match(weslBundleExportPattern);
38
35
  if (!exportMatch) throw new Error("Could not find weslBundle export in bundle");
39
- const [imports] = parse(code);
40
- const parsedImports = imports.map((imp) => {
41
- const statement = code.slice(imp.ss, imp.se);
42
- const match = statement.match(importVarPattern);
43
- if (!match) throw new Error(`Could not parse import variable name from: ${statement}`);
44
- return {
45
- varName: match[1],
46
- path: imp.n.replace(/\//g, "::")
47
- };
36
+ const parsedImports = [];
37
+ for (const match of code.matchAll(importPattern)) parsedImports.push({
38
+ varName: match[1],
39
+ path: match[2].replace(/\//g, "::")
48
40
  });
49
41
  return {
50
42
  bundleLiteral: exportMatch[1],
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "wesl-fetch",
3
3
  "description": "Browser-based HTTP fetching for WESL packages from npm",
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "type": "module",
6
6
  "repository": "github:wgsl-tooling-wg/wesl-js",
7
7
  "exports": {
8
8
  ".": "./src/index.ts"
9
9
  },
10
10
  "dependencies": {
11
- "es-module-lexer": "^1.7.0",
12
11
  "fflate": "^0.8.2",
13
12
  "nanotar": "^0.2.0",
14
13
  "resolve.exports": "^2.0.3",
15
- "wesl": "0.7.19"
14
+ "wesl": "0.7.20"
16
15
  },
17
16
  "scripts": {
18
17
  "build": "tsdown",
@@ -1,4 +1,3 @@
1
- import { init, parse } from "es-module-lexer";
2
1
  import type { WeslBundle } from "wesl";
3
2
 
4
3
  /**
@@ -12,7 +11,7 @@ import type { WeslBundle } from "wesl";
12
11
  * import dependency from "other-package";
13
12
  * export const weslBundle = { ..., dependencies: [dependency] };
14
13
  *
15
- * We use es-module-lexer to parse imports without executing code, reconstruct
14
+ * We use regex to parse imports without executing code, reconstruct
16
15
  * the dependency graph, then hydrate bundles in dependency order using
17
16
  * Function() constructor with dependency injection. Returns WeslBundle objects
18
17
  * where dependency references are resolved to actual bundle objects.
@@ -45,8 +44,9 @@ interface BundleInfo {
45
44
  /** Fetcher callback for loading missing packages on-demand. */
46
45
  type PackageFetcher = (pkgName: string) => Promise<WeslBundleFile[]>;
47
46
 
48
- // Initialize es-module-lexer WASM once at module load
49
- const initPromise = init;
47
+ // Matches default and namespace imports (captures var name and path)
48
+ const importPattern =
49
+ /import\s+(?:\*\s+as\s+)?(\w+)\s+from\s+["']([^"']+)["']/g;
50
50
 
51
51
  // Matches: package/dist/foo/bar/weslBundle.js (captures "foo/bar")
52
52
  const nestedBundlePattern = /package\/dist\/(.+)\/weslBundle\.js$/;
@@ -58,9 +58,6 @@ const rootBundlePattern = /package\/dist\/weslBundle\.js$/;
58
58
  const weslBundleExportPattern =
59
59
  /export\s+const\s+weslBundle\s*=\s*({[\s\S]+});?\s*$/m;
60
60
 
61
- // Matches: import foo from "package" (captures "foo")
62
- const importVarPattern = /import\s+(\w+)\s+from/;
63
-
64
61
  /** Load WeslBundle objects from BundleFile sources. */
65
62
  export async function loadBundlesFromFiles(
66
63
  bundleFiles: WeslBundleFile[],
@@ -74,7 +71,6 @@ export async function bundleRegistry(
74
71
  bundleFiles: WeslBundleFile[],
75
72
  registry: BundleRegistry = new Map(),
76
73
  ): Promise<BundleRegistry> {
77
- await initPromise;
78
74
  for (const file of bundleFiles) {
79
75
  const { content, packagePath, packageName } = file;
80
76
  const bundleInfo = parseBundleImports(content);
@@ -97,24 +93,20 @@ export async function hydrateBundleRegistry(
97
93
  return bundles;
98
94
  }
99
95
 
100
- /** Parse ES module imports from bundle code using es-module-lexer. */
96
+ /** Parse ES module imports from bundle code. */
101
97
  function parseBundleImports(code: string): BundleInfo {
102
98
  const exportMatch = code.match(weslBundleExportPattern);
103
99
  if (!exportMatch) {
104
100
  throw new Error("Could not find weslBundle export in bundle");
105
101
  }
106
102
 
107
- const [imports] = parse(code);
108
- const parsedImports = imports.map(imp => {
109
- const statement = code.slice(imp.ss, imp.se);
110
- const match = statement.match(importVarPattern);
111
- if (!match) {
112
- throw new Error(
113
- `Could not parse import variable name from: ${statement}`,
114
- );
115
- }
116
- return { varName: match[1], path: imp.n!.replace(/\//g, "::") };
117
- });
103
+ const parsedImports: BundleInfo["imports"] = [];
104
+ for (const match of code.matchAll(importPattern)) {
105
+ parsedImports.push({
106
+ varName: match[1],
107
+ path: match[2].replace(/\//g, "::"),
108
+ });
109
+ }
118
110
 
119
111
  return { bundleLiteral: exportMatch[1], imports: parsedImports };
120
112
  }