@netlify/plugin-nextjs 4.17.1-runtime.1 → 4.17.1-runtime.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.
@@ -11,15 +11,16 @@ const edge_1 = require("./edge");
11
11
  const files_1 = require("./files");
12
12
  // The types haven't been updated yet
13
13
  const onPreDev = async ({ constants, netlifyConfig }) => {
14
+ var _a;
15
+ const base = (_a = netlifyConfig.build.base) !== null && _a !== void 0 ? _a : process.cwd();
14
16
  // Need to patch the files, because build might not have been run
15
- await (0, files_1.patchNextFiles)((0, path_1.resolve)(netlifyConfig.build.publish, '..'));
17
+ await (0, files_1.patchNextFiles)(base);
16
18
  // Clean up old functions
17
19
  await (0, fs_extra_1.unlink)((0, path_1.resolve)('.netlify', 'middleware.js')).catch(() => {
18
20
  // Ignore if it doesn't exist
19
21
  });
20
22
  await (0, edge_1.writeDevEdgeFunction)(constants);
21
- if (!(0, fs_extra_1.existsSync)((0, path_1.resolve)(netlifyConfig.build.base, 'middleware.ts')) &&
22
- !(0, fs_extra_1.existsSync)((0, path_1.resolve)(netlifyConfig.build.base, 'middleware.js'))) {
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'))) {
23
24
  console.log("No middleware found. Create a 'middleware.ts' or 'middleware.js' file in your project root to add custom middleware.");
24
25
  }
25
26
  else {
@@ -32,8 +33,8 @@ const onPreDev = async ({ constants, netlifyConfig }) => {
32
33
  `--format=esm`,
33
34
  '--watch',
34
35
  // Watch for both, because it can have either ts or js
35
- (0, path_1.resolve)(netlifyConfig.build.base, 'middleware.ts'),
36
- (0, path_1.resolve)(netlifyConfig.build.base, 'middleware.js'),
36
+ (0, path_1.resolve)(base, 'middleware.ts'),
37
+ (0, path_1.resolve)(base, 'middleware.js'),
37
38
  ]);
38
39
  childProcess.stdout.pipe(process.stdout);
39
40
  childProcess.stderr.pipe(process.stderr);
@@ -82,7 +82,7 @@ const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/ed
82
82
  await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
83
83
  const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'next-dev');
84
84
  await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
85
- await copyEdgeSourceFile({ edgeFunctionDir, file: 'next-dev.ts', target: 'index.ts' });
85
+ await copyEdgeSourceFile({ edgeFunctionDir, file: 'next-dev.js', target: 'index.js' });
86
86
  await copyEdgeSourceFile({ edgeFunctionDir, file: 'utils.ts' });
87
87
  };
88
88
  exports.writeDevEdgeFunction = writeDevEdgeFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.17.1-runtime.1",
3
+ "version": "4.17.1-runtime.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -1,81 +1,12 @@
1
- import type { Context } from 'https://edge.netlify.com'
2
1
  import { NextRequest, NextResponse } from 'https://esm.sh/next/server'
3
2
  import { fromFileUrl } from 'https://deno.land/std/path/mod.ts'
4
3
  import { buildResponse } from './utils.ts'
5
4
 
6
- export interface FetchEventResult {
7
- response: Response
8
- waitUntil: Promise<unknown>
9
- }
10
-
11
- interface I18NConfig {
12
- defaultLocale: string
13
- domains?: DomainLocale[]
14
- localeDetection?: false
15
- locales: string[]
16
- }
17
-
18
- interface DomainLocale {
19
- defaultLocale: string
20
- domain: string
21
- http?: true
22
- locales?: string[]
23
- }
24
- export interface NextRequestInit extends RequestInit {
25
- geo?: {
26
- city?: string
27
- country?: string
28
- region?: string
29
- }
30
- ip?: string
31
- nextConfig?: {
32
- basePath?: string
33
- i18n?: I18NConfig | null
34
- trailingSlash?: boolean
35
- }
36
- }
37
-
38
- export interface RequestData {
39
- geo?: {
40
- city?: string
41
- country?: string
42
- region?: string
43
- latitude?: string
44
- longitude?: string
45
- }
46
- headers: Record<string, string>
47
- ip?: string
48
- method: string
49
- nextConfig?: {
50
- basePath?: string
51
- i18n?: Record<string, unknown>
52
- trailingSlash?: boolean
53
- }
54
- page?: {
55
- name?: string
56
- params?: { [key: string]: string }
57
- }
58
- url: string
59
- body?: ReadableStream<Uint8Array>
60
- }
61
-
62
- export interface RequestContext {
63
- request: Request
64
- context: Context
65
- }
66
-
67
- declare global {
68
- // deno-lint-ignore no-var
69
- var NFRequestContextMap: Map<string, RequestContext>
70
- // deno-lint-ignore no-var
71
- var __dirname: string
72
- }
73
-
74
5
  globalThis.NFRequestContextMap ||= new Map()
75
6
  globalThis.__dirname = fromFileUrl(new URL('./', import.meta.url)).slice(0, -1)
76
7
 
77
8
  // Check if a file exists, given a relative path
78
- const exists = async (relativePath: string) => {
9
+ const exists = async (relativePath) => {
79
10
  const path = fromFileUrl(new URL(relativePath, import.meta.url))
80
11
  try {
81
12
  await Deno.stat(path)
@@ -88,7 +19,7 @@ const exists = async (relativePath: string) => {
88
19
  }
89
20
  }
90
21
 
91
- const handler = async (req: Request, context: Context) => {
22
+ const handler = async (req, context) => {
92
23
  // Uncomment when CLI update lands
93
24
  // if (!Deno.env.get('NETLIFY_DEV')) {
94
25
  // // Only run in dev
@@ -111,7 +42,7 @@ const handler = async (req: Request, context: Context) => {
111
42
  }
112
43
 
113
44
  // This is the format expected by Next.js
114
- const geo: NextRequestInit['geo'] = {
45
+ const geo = {
115
46
  country: context.geo.country?.code,
116
47
  region: context.geo.subdivision?.code,
117
48
  city: context.geo.city,
@@ -125,7 +56,7 @@ const handler = async (req: Request, context: Context) => {
125
56
  context,
126
57
  })
127
58
 
128
- const request: NextRequestInit = {
59
+ const request = {
129
60
  headers: Object.fromEntries(req.headers.entries()),
130
61
  geo,
131
62
  method: req.method,
@@ -133,7 +64,7 @@ const handler = async (req: Request, context: Context) => {
133
64
  body: req.body || undefined,
134
65
  }
135
66
 
136
- const nextRequest: NextRequest = new NextRequest(req, request)
67
+ const nextRequest = new NextRequest(req, request)
137
68
 
138
69
  try {
139
70
  const response = await middleware(nextRequest)