@vercel/build-utils 14.9.2 → 14.9.3

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/lazy-entry.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { transform } from 'esbuild';
3
+
4
+ // Keep the public CommonJS barrel's getters, but initialize each re-exported
5
+ // module on first use. All exports still share one bundled module cache.
6
+ export function lazyEntryPlugin() {
7
+ return {
8
+ name: 'lazy-build-utils-entry',
9
+ setup(build) {
10
+ build.onLoad(
11
+ { filter: /[/\\]build-utils[/\\]src[/\\]index\.ts$/ },
12
+ async args => {
13
+ const source = await readFile(args.path, 'utf8');
14
+ let { code } = await transform(source, {
15
+ loader: 'ts',
16
+ format: 'cjs',
17
+ });
18
+ const imports = [];
19
+ code = code.replace(
20
+ /^var (import_\w+) = (.+);$/gm,
21
+ (_, name, initializer) => {
22
+ imports.push(name);
23
+ return `var ${name};\nvar load_${name} = () => ${name} ??= ${initializer};`;
24
+ }
25
+ );
26
+ if (imports.length === 0) {
27
+ throw new Error(
28
+ 'Expected CommonJS imports in the build-utils barrel'
29
+ );
30
+ }
31
+ for (const name of imports) {
32
+ code = code.replaceAll(`() => ${name}.`, `() => load_${name}().`);
33
+ }
34
+ return { contents: code, loader: 'js' };
35
+ }
36
+ );
37
+ },
38
+ };
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "14.9.2",
3
+ "version": "14.9.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -52,8 +52,8 @@
52
52
  "vitest": "4.1.10",
53
53
  "typescript": "4.9.5",
54
54
  "yazl": "2.5.1",
55
- "@vercel/error-utils": "2.2.1",
56
- "@vercel/routing-utils": "6.5.0"
55
+ "@vercel/routing-utils": "6.5.0",
56
+ "@vercel/error-utils": "2.2.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "node build.mjs",