@netlify/plugin-nextjs 4.29.1 → 4.29.2-alpha-isr-404.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.
@@ -293,7 +293,7 @@ const getDependenciesOfFile = async (file) => {
293
293
  return [];
294
294
  }
295
295
  const dependencies = await (0, fs_extra_1.readJson)(nft, 'utf8');
296
- return dependencies.files.map((dep) => (0, pathe_1.resolve)(file, dep));
296
+ return dependencies.files.map((dep) => (0, pathe_1.resolve)((0, pathe_1.dirname)(file), dep));
297
297
  };
298
298
  exports.getDependenciesOfFile = getDependenciesOfFile;
299
299
  const baseServerReplacements = [
@@ -303,7 +303,7 @@ const baseServerReplacements = [
303
303
  `checkIsManualRevalidate(process.env._REVALIDATE_SSG ? { headers: { 'x-prerender-revalidate': this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)`,
304
304
  ],
305
305
  // ensure ISR 404 pages send the correct SWR cache headers
306
- [`private: isPreviewMode || is404Page && cachedData`, `private: isPreviewMode && cachedData`],
306
+ [`private: isPreviewMode || is404Page`, `private: isPreviewMode || false`],
307
307
  ];
308
308
  const nextServerReplacements = [
309
309
  [
@@ -36,7 +36,7 @@ const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS
36
36
  await (0, fs_extra_1.copyFile)(node_bridge_1.default, (0, pathe_1.join)(functionsDir, functionName, 'bridge.js'));
37
37
  await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'handlerUtils.js'), (0, pathe_1.join)(functionsDir, functionName, 'handlerUtils.js'));
38
38
  const resolveSourceFile = (file) => (0, pathe_1.join)(publish, 'server', file);
39
- const resolverSource = await (0, getPageResolver_1.getSinglePageResolver)({
39
+ const resolverSource = await (0, getPageResolver_1.getResolverForSourceFiles)({
40
40
  functionsDir,
41
41
  // These extra pages are always included by Next.js
42
42
  sourceFiles: [compiled, 'pages/_app.js', 'pages/_document.js', 'pages/_error.js'].map(resolveSourceFile),
@@ -58,12 +58,9 @@ exports.generateFunctions = generateFunctions;
58
58
  * Writes a file in each function directory that contains references to every page entrypoint.
59
59
  * This is just so that the nft bundler knows about them. We'll eventually do this better.
60
60
  */
61
- const generatePagesResolver = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, PUBLISH_DIR }, target, }) => {
61
+ const generatePagesResolver = async ({ INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, PUBLISH_DIR, }) => {
62
62
  const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
63
- const jsSource = await (0, getPageResolver_1.getPageResolver)({
64
- publish: PUBLISH_DIR,
65
- target,
66
- });
63
+ const jsSource = await (0, getPageResolver_1.getResolverForPages)(PUBLISH_DIR);
67
64
  await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.ODB_FUNCTION_NAME, 'pages.js'), jsSource);
68
65
  await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.HANDLER_FUNCTION_NAME, 'pages.js'), jsSource);
69
66
  };
package/lib/index.js CHANGED
@@ -94,7 +94,7 @@ const plugin = {
94
94
  await (0, config_1.configureHandlerFunctions)({ netlifyConfig, ignore, publish: (0, path_1.relative)(process.cwd(), publish) });
95
95
  const apiRoutes = await (0, functions_1.getExtendedApiRouteConfigs)(publish, appDir);
96
96
  await (0, functions_1.generateFunctions)(constants, appDir, apiRoutes);
97
- await (0, functions_1.generatePagesResolver)({ target, constants });
97
+ await (0, functions_1.generatePagesResolver)(constants);
98
98
  await (0, files_1.movePublicFiles)({ appDir, outdir, publish });
99
99
  await (0, files_1.patchNextFiles)(appDir);
100
100
  if (!(0, destr_1.default)(process.env.SERVE_STATIC_FILES_FROM_ORIGIN)) {
@@ -3,28 +3,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSinglePageResolver = exports.getPageResolver = void 0;
7
- const path_1 = require("path");
6
+ exports.getResolverForSourceFiles = exports.getResolverForPages = exports.getResolverForDependencies = exports.getAllPageDependencies = exports.getUniqueDependencies = void 0;
7
+ const globby_1 = __importDefault(require("globby"));
8
8
  const outdent_1 = require("outdent");
9
9
  const pathe_1 = require("pathe");
10
- const slash_1 = __importDefault(require("slash"));
11
- const tiny_glob_1 = __importDefault(require("tiny-glob"));
12
10
  const constants_1 = require("../constants");
13
11
  const files_1 = require("../helpers/files");
14
12
  // Generate a file full of require.resolve() calls for all the pages in the
15
13
  // build. This is used by the nft bundler to find all the pages.
16
- const getPageResolver = async ({ publish, target }) => {
17
- const functionDir = path_1.posix.resolve(path_1.posix.join('.netlify', 'functions', constants_1.HANDLER_FUNCTION_NAME));
18
- const root = path_1.posix.resolve((0, slash_1.default)(publish), target === 'server' ? 'server' : 'serverless', 'pages');
19
- const pages = await (0, tiny_glob_1.default)('**/*.js', {
14
+ const getUniqueDependencies = async (sourceFiles) => {
15
+ const dependencies = await Promise.all(sourceFiles.map((sourceFile) => (0, files_1.getDependenciesOfFile)(sourceFile)));
16
+ return [...new Set([...sourceFiles, ...dependencies.flat()])].sort();
17
+ };
18
+ exports.getUniqueDependencies = getUniqueDependencies;
19
+ const getAllPageDependencies = async (publish) => {
20
+ const root = (0, pathe_1.resolve)(publish, 'server');
21
+ const pageFiles = await (0, globby_1.default)('{pages,app}/**/*.js', {
20
22
  cwd: root,
21
23
  dot: true,
22
24
  });
23
- const pageFiles = pages
24
- .map((page) => `require.resolve('${path_1.posix.relative(functionDir, path_1.posix.join(root, (0, slash_1.default)(page)))}')`)
25
- .sort();
26
- return (0, outdent_1.outdent) `
27
- // This file is purely to allow nft to know about these pages. It should be temporary.
25
+ // We don't use `absolute: true` because that returns Windows paths on Windows.
26
+ // Instead we use pathe to normalize the paths.
27
+ return (0, exports.getUniqueDependencies)(pageFiles.map((pageFile) => (0, pathe_1.join)(root, pageFile)));
28
+ };
29
+ exports.getAllPageDependencies = getAllPageDependencies;
30
+ const getResolverForDependencies = ({ dependencies, functionDir, }) => {
31
+ const pageFiles = dependencies.map((file) => `require.resolve('${(0, pathe_1.relative)(functionDir, file)}')`);
32
+ return (0, outdent_1.outdent /* javascript */) `
33
+ // This file is purely to allow nft to know about these pages.
28
34
  exports.resolvePages = () => {
29
35
  try {
30
36
  ${pageFiles.join('\n ')}
@@ -32,24 +38,17 @@ const getPageResolver = async ({ publish, target }) => {
32
38
  }
33
39
  `;
34
40
  };
35
- exports.getPageResolver = getPageResolver;
36
- /**
37
- * API routes only need the dependencies for a single entrypoint, so we use the
38
- * NFT trace file to get the dependencies.
39
- */
40
- const getSinglePageResolver = async ({ functionsDir, sourceFiles, }) => {
41
- const dependencies = await Promise.all(sourceFiles.map((sourceFile) => (0, files_1.getDependenciesOfFile)(sourceFile)));
41
+ exports.getResolverForDependencies = getResolverForDependencies;
42
+ const getResolverForPages = async (publish) => {
43
+ const functionDir = (0, pathe_1.resolve)('.netlify', 'functions', constants_1.HANDLER_FUNCTION_NAME);
44
+ const dependencies = await (0, exports.getAllPageDependencies)(publish);
45
+ return (0, exports.getResolverForDependencies)({ dependencies, functionDir });
46
+ };
47
+ exports.getResolverForPages = getResolverForPages;
48
+ const getResolverForSourceFiles = async ({ functionsDir, sourceFiles, }) => {
42
49
  // We don't need the actual name, just the relative path.
43
50
  const functionDir = (0, pathe_1.resolve)(functionsDir, 'functionName');
44
- const deduped = [...new Set(dependencies.flat())];
45
- const pageFiles = [...sourceFiles, ...deduped]
46
- .map((file) => `require.resolve('${(0, pathe_1.relative)(functionDir, file)}')`)
47
- .sort();
48
- return (0, outdent_1.outdent /* javascript */) `
49
- // This file is purely to allow nft to know about these pages.
50
- try {
51
- ${pageFiles.join('\n ')}
52
- } catch {}
53
- `;
51
+ const dependencies = await (0, exports.getUniqueDependencies)(sourceFiles);
52
+ return (0, exports.getResolverForDependencies)({ dependencies, functionDir });
54
53
  };
55
- exports.getSinglePageResolver = getSinglePageResolver;
54
+ exports.getResolverForSourceFiles = getResolverForSourceFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.29.1",
3
+ "version": "4.29.2-alpha-isr-404.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -36,12 +36,12 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@delucis/if-env": "^1.1.2",
39
- "@netlify/build": "^28.1.13",
39
+ "@netlify/build": "^28.1.15",
40
40
  "@types/fs-extra": "^9.0.13",
41
41
  "@types/jest": "^27.4.1",
42
42
  "@types/merge-stream": "^1.1.2",
43
43
  "@types/node": "^17.0.25",
44
- "next": "^13.0.0",
44
+ "next": "^13.0.3",
45
45
  "npm-run-all": "^4.1.5",
46
46
  "typescript": "^4.6.3"
47
47
  },