@netlify/plugin-nextjs 4.27.3 → 4.28.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.
@@ -29,13 +29,33 @@ const sanitizeName = (name) => `next_${name.replace(/\W/g, '_')}`;
29
29
  * Initialization added to the top of the edge function bundle
30
30
  */
31
31
  const preamble = /* js */ `
32
-
33
- globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT_PRIVATE_MINIMAL_MODE': '1' } }
34
- let _ENTRIES = {}
32
+ import {
33
+ decode as _base64Decode,
34
+ } from "https://deno.land/std@0.159.0/encoding/base64.ts";
35
35
  // Deno defines "window", but naughty libraries think this means it's a browser
36
36
  delete globalThis.window
37
+ globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT_PRIVATE_MINIMAL_MODE': '1' } }
37
38
  // Next uses "self" as a function-scoped global-like object
38
39
  const self = {}
40
+ let _ENTRIES = {}
41
+
42
+ // Next uses blob: urls to refer to local assets, so we need to intercept these
43
+ const _fetch = globalThis.fetch
44
+ const fetch = async (url, init) => {
45
+ try {
46
+ if (typeof url === 'object' && url.href?.startsWith('blob:')) {
47
+ const key = url.href.slice(5)
48
+ if (key in _ASSETS) {
49
+ return new Response(_base64Decode(_ASSETS[key]))
50
+ }
51
+ }
52
+ return await _fetch(url, init)
53
+ } catch (error) {
54
+ console.error(error)
55
+ throw error
56
+ }
57
+ }
58
+
39
59
  `;
40
60
  // Slightly different spacing in different versions!
41
61
  const IMPORT_UNSUPPORTED = [
@@ -48,6 +68,19 @@ const IMPORT_UNSUPPORTED = [
48
68
  const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) => {
49
69
  const { publish } = netlifyConfig.build;
50
70
  const chunks = [preamble];
71
+ if ('wasm' in edgeFunctionDefinition) {
72
+ for (const { name, filePath } of edgeFunctionDefinition.wasm) {
73
+ const wasm = await fs_1.promises.readFile((0, path_1.join)(publish, filePath));
74
+ chunks.push(`const ${name} = _base64Decode(${JSON.stringify(wasm.toString('base64'))}).buffer`);
75
+ }
76
+ }
77
+ if ('assets' in edgeFunctionDefinition) {
78
+ chunks.push(`const _ASSETS = {}`);
79
+ for (const { name, filePath } of edgeFunctionDefinition.assets) {
80
+ const wasm = await fs_1.promises.readFile((0, path_1.join)(publish, filePath));
81
+ chunks.push(`_ASSETS[${JSON.stringify(name)}] = ${JSON.stringify(wasm.toString('base64'))}`);
82
+ }
83
+ }
51
84
  for (const file of edgeFunctionDefinition.files) {
52
85
  const filePath = (0, path_1.join)(publish, file);
53
86
  let data = await fs_1.promises.readFile(filePath, 'utf8');
package/lib/index.js CHANGED
@@ -82,7 +82,9 @@ const plugin = {
82
82
  await (0, config_1.updateRequiredServerFiles)(publish, config);
83
83
  }
84
84
  else {
85
- const nextAuthUrl = `${process.env.DEPLOY_PRIME_URL}${basePath}`;
85
+ // Using the deploy prime url in production leads to issues because the unique deploy ID is part of the generated URL
86
+ // and will not match the expected URL in the callback URL of an OAuth application.
87
+ const nextAuthUrl = `${process.env.CONTEXT === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL}${basePath}`;
86
88
  console.log(`NextAuth package detected, setting NEXTAUTH_URL environment variable to ${nextAuthUrl}`);
87
89
  config.config.env.NEXTAUTH_URL = nextAuthUrl;
88
90
  await (0, config_1.updateRequiredServerFiles)(publish, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.27.3",
3
+ "version": "4.28.1",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -35,12 +35,12 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@delucis/if-env": "^1.1.2",
38
- "@netlify/build": "^28.1.1",
38
+ "@netlify/build": "^28.1.2",
39
39
  "@types/fs-extra": "^9.0.13",
40
40
  "@types/jest": "^27.4.1",
41
41
  "@types/merge-stream": "^1.1.2",
42
42
  "@types/node": "^17.0.25",
43
- "next": "^12.3.0",
43
+ "next": "^12.3.2-canary.43",
44
44
  "npm-run-all": "^4.1.5",
45
45
  "typescript": "^4.6.3"
46
46
  },
@@ -2,6 +2,6 @@
2
2
  * This placeholder is replaced with the compiled Next.js bundle at build time
3
3
  * @param {Object} props
4
4
  * @param {import("./runtime.ts").RequestData} props.request
5
- * @returns {Promise<import("./utils.ts").FetchEventResult>}
5
+ * @returns {Promise<import("../edge-shared/utils.ts").FetchEventResult>}
6
6
  */
7
7
  export default async ({ request }) => {}
@@ -33,7 +33,7 @@ export interface RequestData {
33
33
  name?: string
34
34
  params?: { [key: string]: string }
35
35
  }
36
- url: URL
36
+ url: string
37
37
  body?: ReadableStream<Uint8Array>
38
38
  }
39
39
 
@@ -82,7 +82,7 @@ const handler = async (req: Request, context: Context) => {
82
82
  const request: RequestData = {
83
83
  headers: Object.fromEntries(req.headers.entries()),
84
84
  geo,
85
- url,
85
+ url: req.url,
86
86
  method: req.method,
87
87
  ip: context.ip,
88
88
  body: req.body ?? undefined,
@@ -83,7 +83,10 @@ export const buildResponse = async ({
83
83
  const transformed = response.dataTransforms.reduce((prev, transform) => {
84
84
  return transform(prev)
85
85
  }, props)
86
- return new Response(JSON.stringify(transformed), response)
86
+ const body = JSON.stringify(transformed)
87
+ const headers = new Headers(response.headers)
88
+ headers.set('content-length', String(body.length))
89
+ return new Response(body, { ...response, headers })
87
90
  }
88
91
  // This var will hold the contents of the script tag
89
92
  let buffer = ''