@netlify/plugin-nextjs 4.25.0 → 4.26.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/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib')
@@ -27,26 +27,34 @@ const sanitizeName = (name) => `next_${name.replace(/\W/g, '_')}`;
27
27
  /**
28
28
  * Initialization added to the top of the edge function bundle
29
29
  */
30
- const bootstrap = /* js */ `
30
+ const preamble = /* js */ `
31
+
31
32
  globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT_PRIVATE_MINIMAL_MODE': '1' } }
32
- globalThis._ENTRIES ||= {}
33
+ let _ENTRIES = {}
33
34
  // Deno defines "window", but naughty libraries think this means it's a browser
34
35
  delete globalThis.window
35
-
36
+ // Next uses "self" as a function-scoped global-like object
37
+ const self = {}
36
38
  `;
39
+ // Slightly different spacing in different versions!
40
+ const IMPORT_UNSUPPORTED = [
41
+ `Object.defineProperty(globalThis,"__import_unsupported"`,
42
+ ` Object.defineProperty(globalThis, "__import_unsupported"`,
43
+ ];
37
44
  /**
38
45
  * Concatenates the Next edge function code with the required chunks and adds an export
39
46
  */
40
47
  const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) => {
41
48
  const { publish } = netlifyConfig.build;
42
- const chunks = [bootstrap];
49
+ const chunks = [preamble];
43
50
  for (const file of edgeFunctionDefinition.files) {
44
51
  const filePath = (0, path_1.join)(publish, file);
45
- const data = await fs_1.promises.readFile(filePath, 'utf8');
52
+ let data = await fs_1.promises.readFile(filePath, 'utf8');
53
+ // Next defines an immutable global variable, which is fine unless you have more than one in the bundle
54
+ // This adds a check to see if the global is already defined
55
+ data = IMPORT_UNSUPPORTED.reduce((acc, val) => acc.replace(val, `('__import_unsupported' in globalThis)||${val}`), data);
46
56
  chunks.push('{', data, '}');
47
57
  }
48
- const middleware = await fs_1.promises.readFile((0, path_1.join)(publish, `server`, `${edgeFunctionDefinition.name}.js`), 'utf8');
49
- chunks.push(middleware);
50
58
  const exports = /* js */ `export default _ENTRIES["middleware_${edgeFunctionDefinition.name}"].default;`;
51
59
  chunks.push(exports);
52
60
  return chunks.join('\n');
@@ -79,7 +87,7 @@ const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, net
79
87
  // We add a defintion for each matching path
80
88
  return matchers.map((matcher) => {
81
89
  const pattern = matcher.regexp;
82
- return { function: name, pattern };
90
+ return { function: name, pattern, name: edgeFunctionDefinition.name };
83
91
  });
84
92
  };
85
93
  const cleanupEdgeFunctions = ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions', }) => (0, fs_extra_1.emptyDir)(INTERNAL_EDGE_FUNCTIONS_SRC);
@@ -89,6 +97,7 @@ const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/ed
89
97
  functions: [
90
98
  {
91
99
  function: 'next-dev',
100
+ name: 'netlify dev handler',
92
101
  path: '/*',
93
102
  },
94
103
  ],
@@ -128,6 +137,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
128
137
  await (0, fs_extra_1.copyFile)((0, path_1.join)('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'), (0, path_1.join)(edgeFunctionDir, 'imageconfig.json'));
129
138
  manifest.functions.push({
130
139
  function: 'ipx',
140
+ name: 'next/image handler',
131
141
  path: '/_next/image*',
132
142
  });
133
143
  }
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.25.0",
3
+ "version": "4.26.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
- "main": "lib/index.js",
5
+ "main": "index.js",
6
6
  "files": [
7
7
  "lib/**/*",
8
8
  "src/templates/edge/*",
9
9
  "src/templates/edge-shared/*",
10
+ "index.js",
10
11
  "manifest.yml"
11
12
  ],
12
13
  "dependencies": {
13
14
  "@netlify/esbuild": "0.14.39",
14
15
  "@netlify/functions": "^1.3.0",
15
- "@netlify/ipx": "^1.3.0",
16
+ "@netlify/ipx": "^1.3.1",
16
17
  "@vercel/node-bridge": "^2.1.0",
17
18
  "chalk": "^4.1.2",
18
19
  "destr": "^1.1.1",