@netlify/edge-bundler 10.1.0 → 10.1.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.
@@ -156,7 +156,7 @@ const safelyVendorNPMSpecifiers = async ({ basePath, functions, importMap, logge
156
156
  functions: functions.map(({ path }) => path),
157
157
  importMap,
158
158
  logger,
159
- referenceTypes: false,
159
+ environment: 'production',
160
160
  rootPath,
161
161
  });
162
162
  }
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import { access, readdir, readFile, rm, writeFile } from 'fs/promises';
2
3
  import { join, resolve } from 'path';
3
4
  import process from 'process';
@@ -430,3 +431,27 @@ test('Loads JSON modules', async () => {
430
431
  await cleanup();
431
432
  await rm(vendorDirectory.path, { force: true, recursive: true });
432
433
  });
434
+ test('Supports TSX and process.env', async () => {
435
+ const { basePath, cleanup, distPath } = await useFixture('tsx');
436
+ const sourceDirectory = join(basePath, 'functions');
437
+ const declarations = [
438
+ {
439
+ function: 'func1',
440
+ path: '/func1',
441
+ },
442
+ ];
443
+ const vendorDirectory = await tmp.dir();
444
+ await bundle([sourceDirectory], distPath, declarations, {
445
+ basePath,
446
+ vendorDirectory: vendorDirectory.path,
447
+ });
448
+ const manifestFile = await readFile(resolve(distPath, 'manifest.json'), 'utf8');
449
+ const manifest = JSON.parse(manifestFile);
450
+ const bundlePath = join(distPath, manifest.bundles[0].asset);
451
+ process.env.FOO = 'bar';
452
+ const { func1 } = await runESZIP(bundlePath, vendorDirectory.path);
453
+ expect(Buffer.from(func1, 'base64').toString()).toBe(`hippedy hoppedy, createElement is now a production property. Here, take this env var: FOO=bar`);
454
+ await cleanup();
455
+ await rm(vendorDirectory.path, { force: true, recursive: true });
456
+ delete process.env.FOO;
457
+ });
@@ -7,10 +7,10 @@ interface VendorNPMSpecifiersOptions {
7
7
  functions: string[];
8
8
  importMap: ImportMap;
9
9
  logger: Logger;
10
- referenceTypes: boolean;
10
+ environment: 'production' | 'development';
11
11
  rootPath?: string;
12
12
  }
13
- export declare const vendorNPMSpecifiers: ({ basePath, directory, functions, importMap, referenceTypes, rootPath, }: VendorNPMSpecifiersOptions) => Promise<{
13
+ export declare const vendorNPMSpecifiers: ({ basePath, directory, functions, importMap, environment, rootPath, }: VendorNPMSpecifiersOptions) => Promise<{
14
14
  cleanup: () => Promise<void>;
15
15
  directory: string;
16
16
  importMap: {
@@ -9,7 +9,7 @@ import { findUp } from 'find-up';
9
9
  import getPackageName from 'get-package-name';
10
10
  import tmp from 'tmp-promise';
11
11
  import { pathsBetween } from './utils/fs.js';
12
- const TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.cts', '.mts']);
12
+ const TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.cts', '.ctsx', '.mts', '.mtsx']);
13
13
  const slugifyPackageName = (specifier) => {
14
14
  if (!specifier.startsWith('@'))
15
15
  return specifier;
@@ -66,6 +66,10 @@ const safelyDetectTypes = async (packageJsonPath) => {
66
66
  // Workaround for https://github.com/evanw/esbuild/issues/1921.
67
67
  const banner = {
68
68
  js: `
69
+ import process from "node:process";
70
+ import {setImmediate, clearImmediate} from "node:timers";
71
+ import {Buffer} from "node:buffer";
72
+
69
73
  import {createRequire as ___nfyCreateRequire} from "node:module";
70
74
  import {fileURLToPath as ___nfyFileURLToPath} from "node:url";
71
75
  import {dirname as ___nfyPathDirname} from "node:path";
@@ -78,7 +82,7 @@ const banner = {
78
82
  * Parses a set of functions and returns a list of specifiers that correspond
79
83
  * to npm modules.
80
84
  */
81
- const getNPMSpecifiers = async ({ basePath, functions, importMap, referenceTypes, rootPath, }) => {
85
+ const getNPMSpecifiers = async ({ basePath, functions, importMap, environment, rootPath }) => {
82
86
  const baseURL = pathToFileURL(basePath);
83
87
  const { reasons } = await nodeFileTrace(functions, {
84
88
  base: rootPath,
@@ -153,7 +157,7 @@ const getNPMSpecifiers = async ({ basePath, functions, importMap, referenceTypes
153
157
  if (isDirectDependency) {
154
158
  npmSpecifiers.push({
155
159
  specifier: packageName,
156
- types: referenceTypes ? await safelyDetectTypes(path.join(basePath, filePath)) : undefined,
160
+ types: environment === 'development' ? await safelyDetectTypes(path.join(basePath, filePath)) : undefined,
157
161
  });
158
162
  }
159
163
  }
@@ -162,7 +166,7 @@ const getNPMSpecifiers = async ({ basePath, functions, importMap, referenceTypes
162
166
  npmSpecifiersWithExtraneousFiles: [...npmSpecifiersWithExtraneousFiles],
163
167
  };
164
168
  };
165
- export const vendorNPMSpecifiers = async ({ basePath, directory, functions, importMap, referenceTypes, rootPath = basePath, }) => {
169
+ export const vendorNPMSpecifiers = async ({ basePath, directory, functions, importMap, environment, rootPath = basePath, }) => {
166
170
  // The directories that esbuild will use when resolving Node modules. We must
167
171
  // set these manually because esbuild will be operating from a temporary
168
172
  // directory that will not live inside the project root, so the normal
@@ -176,7 +180,7 @@ export const vendorNPMSpecifiers = async ({ basePath, directory, functions, impo
176
180
  basePath,
177
181
  functions,
178
182
  importMap: importMap.getContentsWithURLObjects(),
179
- referenceTypes,
183
+ environment,
180
184
  rootPath,
181
185
  });
182
186
  // If we found no specifiers, there's nothing left to do here.
@@ -210,6 +214,11 @@ export const vendorNPMSpecifiers = async ({ basePath, directory, functions, impo
210
214
  splitting: true,
211
215
  target: 'es2020',
212
216
  write: false,
217
+ define: environment === 'production'
218
+ ? {
219
+ 'process.env.NODE_ENV': '"production"',
220
+ }
221
+ : undefined,
213
222
  });
214
223
  await Promise.all(outputFiles.map(async (file) => {
215
224
  var _a;
@@ -48,7 +48,7 @@ const prepareServer = ({ basePath, bootstrapURL, deno, distDirectory, distImport
48
48
  functions: functions.map(({ path }) => path),
49
49
  importMap,
50
50
  logger,
51
- referenceTypes: true,
51
+ environment: 'development',
52
52
  rootPath,
53
53
  });
54
54
  if (vendor) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/edge-bundler",
3
- "version": "10.1.0",
3
+ "version": "10.1.1",
4
4
  "description": "Intelligently prepare Netlify Edge Functions for deployment",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",