@netlify/plugin-nextjs 4.21.1 → 4.21.2

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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ![Next.js Runtime](https://github.com/netlify/next-runtime/raw/main/next-on-netlify.png)
2
+
3
+ # `@netlify/plugin-nextjs`
4
+
5
+ <p align="center">
6
+ <a aria-label="npm version" href="https://www.npmjs.com/package/@netlify/plugin-nextjs">
7
+ <img alt="" src="https://img.shields.io/npm/v/@netlify/plugin-nextjs">
8
+ </a>
9
+ <a aria-label="MIT License" href="https://img.shields.io/npm/l/@netlify/plugin-nextjs">
10
+ <img alt="" src="https://img.shields.io/npm/l/@netlify/plugin-nextjs">
11
+ </a>
12
+ </p>
13
+
14
+ This package handles the build process for Next.js sites on Netlify. You should not normally need to install it
15
+ yourself, as it is used automatically during builds of Next.js sites. See
16
+ [the docs for using Next.js on Netlify](https://docs.netlify.com/integrations/frameworks/next-js/overview/) for more
17
+ details.
@@ -5,8 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.onPreDev = void 0;
7
7
  const path_1 = require("path");
8
+ const stream_1 = require("stream");
8
9
  const execa_1 = __importDefault(require("execa"));
9
10
  const fs_extra_1 = require("fs-extra");
11
+ const merge_stream_1 = __importDefault(require("merge-stream"));
10
12
  const edge_1 = require("./edge");
11
13
  const files_1 = require("./files");
12
14
  // The types haven't been updated yet
@@ -20,18 +22,27 @@ const onPreDev = async ({ constants, netlifyConfig }) => {
20
22
  // Ignore if it doesn't exist
21
23
  });
22
24
  await (0, edge_1.writeDevEdgeFunction)(constants);
23
- if (!(0, fs_extra_1.existsSync)((0, path_1.resolve)(base, 'middleware.ts')) && !(0, fs_extra_1.existsSync)((0, path_1.resolve)(base, 'middleware.js'))) {
24
- console.log("No middleware found. If you did intend to use middleware, create a 'middleware.ts' or 'middleware.js' file in your project root to add custom middleware.");
25
- }
26
- else {
27
- console.log('Watching for changes in Next.js middleware...');
28
- // Eventually we might want to do this via esbuild's API, but for now the CLI works fine
29
- const common = [`--bundle`, `--outdir=${(0, path_1.resolve)('.netlify')}`, `--format=esm`, `--target=esnext`, '--watch'];
30
- // TypeScript
31
- (0, execa_1.default)(`esbuild`, [...common, (0, path_1.resolve)(base, 'middleware.ts')], { all: true }).all.pipe(process.stdout);
32
- // JavaScript
33
- (0, execa_1.default)(`esbuild`, [...common, (0, path_1.resolve)(base, 'middleware.js')], { all: true }).all.pipe(process.stdout);
34
- // Don't return the promise because we don't want to wait for the child process to finish
35
- }
25
+ // Eventually we might want to do this via esbuild's API, but for now the CLI works fine
26
+ const common = [`--bundle`, `--outdir=${(0, path_1.resolve)('.netlify')}`, `--format=esm`, `--target=esnext`, '--watch'];
27
+ const opts = {
28
+ all: true,
29
+ env: { ...process.env, FORCE_COLOR: '1' },
30
+ };
31
+ // TypeScript
32
+ const tsout = (0, execa_1.default)(`esbuild`, [...common, (0, path_1.resolve)(base, 'middleware.ts')], opts).all;
33
+ // JavaScript
34
+ const jsout = (0, execa_1.default)(`esbuild`, [...common, (0, path_1.resolve)(base, 'middleware.js')], opts).all;
35
+ const filter = new stream_1.Transform({
36
+ transform(chunk, encoding, callback) {
37
+ const str = chunk.toString(encoding);
38
+ // Skip if message includes this, because we run even when the files are missing
39
+ if (!str.includes('[ERROR] Could not resolve')) {
40
+ this.push(chunk);
41
+ }
42
+ callback();
43
+ },
44
+ });
45
+ (0, merge_stream_1.default)(tsout, jsout).pipe(filter).pipe(process.stdout);
46
+ // Don't return the promise because we don't want to wait for the child process to finish
36
47
  };
37
48
  exports.onPreDev = onPreDev;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enableEdgeInNextConfig = exports.writeEdgeFunctions = exports.writeDevEdgeFunction = exports.loadMiddlewareManifest = void 0;
3
+ exports.enableEdgeInNextConfig = exports.writeEdgeFunctions = exports.writeDevEdgeFunction = exports.cleanupEdgeFunctions = exports.loadMiddlewareManifest = void 0;
4
4
  /* eslint-disable max-lines */
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
@@ -67,6 +67,10 @@ const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, net
67
67
  pattern: stripLookahead(edgeFunctionDefinition.regexp),
68
68
  };
69
69
  };
70
+ const cleanupEdgeFunctions = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions', }) => {
71
+ await (0, fs_extra_1.emptyDir)(INTERNAL_EDGE_FUNCTIONS_SRC);
72
+ };
73
+ exports.cleanupEdgeFunctions = cleanupEdgeFunctions;
70
74
  const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions', }) => {
71
75
  const manifest = {
72
76
  functions: [
package/lib/index.js CHANGED
@@ -45,6 +45,7 @@ const plugin = {
45
45
  publish,
46
46
  failBuild,
47
47
  });
48
+ await (0, edge_1.cleanupEdgeFunctions)(constants);
48
49
  const middlewareManifest = await (0, edge_1.loadMiddlewareManifest)(netlifyConfig);
49
50
  let usingEdge = false;
50
51
  if ((middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.functions) && Object.keys(middlewareManifest.functions).length !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.21.1",
3
+ "version": "4.21.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -11,12 +11,13 @@
11
11
  "dependencies": {
12
12
  "@netlify/esbuild": "0.14.25",
13
13
  "@netlify/functions": "^1.2.0",
14
- "@netlify/ipx": "^1.2.3",
14
+ "@netlify/ipx": "^1.2.4",
15
15
  "@vercel/node-bridge": "^2.1.0",
16
16
  "chalk": "^4.1.2",
17
17
  "execa": "^5.1.1",
18
18
  "fs-extra": "^10.0.0",
19
19
  "globby": "^11.0.4",
20
+ "merge-stream": "^2.0.0",
20
21
  "moize": "^6.1.0",
21
22
  "node-fetch": "^2.6.6",
22
23
  "node-stream-zip": "^1.15.0",
@@ -33,6 +34,7 @@
33
34
  "@netlify/build": "^27.16.1",
34
35
  "@types/fs-extra": "^9.0.13",
35
36
  "@types/jest": "^27.4.1",
37
+ "@types/merge-stream": "^1.1.2",
36
38
  "@types/node": "^17.0.25",
37
39
  "next": "^12.2.0",
38
40
  "npm-run-all": "^4.1.5",