1
- import execa from 'execa'
2
1
import { relative } from 'pathe'
3
2
import { getAllPageDependencies } from '../packages/runtime/src/templates/getPageResolver'
4
3
@@ -9,8 +8,8 @@ jest.mock('../packages/runtime/src/helpers/utils', () => {
9
8
}
10
9
} )
11
10
12
- const Chance = require ( ' chance' )
13
- const {
11
+ import Chance from " chance"
12
+ import {
14
13
writeJSON ,
15
14
unlink ,
16
15
existsSync ,
@@ -21,34 +20,36 @@ const {
21
20
pathExists ,
22
21
writeFile ,
23
22
move ,
24
- } = require ( 'fs-extra' )
25
- const path = require ( 'path' )
26
- const process = require ( 'process' )
27
- const os = require ( 'os' )
28
- const cpy = require ( 'cpy' )
29
- const { dir : getTmpDir } = require ( 'tmp-promise' )
30
- const { downloadFile } = require ( '../packages/runtime/src/templates/handlerUtils' )
31
- const { getExtendedApiRouteConfigs } = require ( '../packages/runtime/src/helpers/functions' )
32
- const nextRuntimeFactory = require ( '../packages/runtime/src' )
23
+ } from "fs-extra"
24
+ import path from "path"
25
+ import process from "process"
26
+ import os from "os"
27
+ import cpy from "cpy"
28
+ import { dir as getTmpDir } from "tmp-promise"
29
+ import { downloadFile } from "../packages/runtime/src/templates/handlerUtils"
30
+ import { getExtendedApiRouteConfigs } from "../packages/runtime/src/helpers/functions"
31
+ // @ts -expect-error - TODO: Convert runtime export to ES6
32
+ import nextRuntimeFactory from "../packages/runtime/src"
33
33
const nextRuntime = nextRuntimeFactory ( { } )
34
- const { watchForMiddlewareChanges } = require ( ' ../packages/runtime/src/helpers/compiler' )
35
- const { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME } = require ( ' ../packages/runtime/src/constants' )
36
- const { join } = require ( ' pathe' )
37
- const {
34
+ import { watchForMiddlewareChanges } from " ../packages/runtime/src/helpers/compiler"
35
+ import { HANDLER_FUNCTION_NAME , ODB_FUNCTION_NAME , IMAGE_FUNCTION_NAME } from " ../packages/runtime/src/constants"
36
+ import { join } from " pathe"
37
+ import {
38
38
matchMiddleware ,
39
39
stripLocale ,
40
40
matchesRedirect ,
41
41
matchesRewrite ,
42
42
patchNextFiles ,
43
43
unpatchNextFiles ,
44
- } = require ( ' ../packages/runtime/src/helpers/files' )
45
- const {
44
+ } from " ../packages/runtime/src/helpers/files"
45
+ import {
46
46
getRequiredServerFiles ,
47
47
updateRequiredServerFiles ,
48
48
generateCustomHeaders ,
49
- } = require ( '../packages/runtime/src/helpers/config' )
50
- const { dirname, resolve } = require ( 'path' )
51
- const { getProblematicUserRewrites } = require ( '../packages/runtime/src/helpers/verification' )
49
+ } from "../packages/runtime/src/helpers/config"
50
+ import { dirname , resolve } from "path"
51
+ import { getProblematicUserRewrites } from "../packages/runtime/src/helpers/verification"
52
+ import type { NetlifyPluginOptions } from '@netlify/build'
52
53
53
54
const chance = new Chance ( )
54
55
const FIXTURES_DIR = `${ __dirname } /fixtures`
@@ -57,7 +58,7 @@ const constants = {
57
58
INTERNAL_FUNCTIONS_SRC : '.netlify/functions-internal' ,
58
59
PUBLISH_DIR : '.next' ,
59
60
FUNCTIONS_DIST : '.netlify/functions' ,
60
- }
61
+ } as unknown as NetlifyPluginOptions [ "constants" ]
61
62
const utils = {
62
63
build : {
63
64
failBuild ( message ) {
@@ -69,7 +70,7 @@ const utils = {
69
70
save : jest . fn ( ) ,
70
71
restore : jest . fn ( ) ,
71
72
} ,
72
- }
73
+ } as unknown as NetlifyPluginOptions [ "utils" ]
73
74
74
75
const normalizeChunkNames = ( source ) => source . replaceAll ( / \/ c h u n k s \/ \d + \. j s / g, '/chunks/CHUNK_ID.js' )
75
76
@@ -174,12 +175,12 @@ const useFixture = async function (fixtureName) {
174
175
await cpy ( '**' , process . cwd ( ) , { cwd : fixtureDir , parents : true , overwrite : true , dot : true } )
175
176
}
176
177
177
- const netlifyConfig = { build : { command : 'npm run build' } , functions : { } , redirects : [ ] , headers : [ ] }
178
+ const netlifyConfig = { build : { command : 'npm run build' } , functions : { } , redirects : [ ] , headers : [ ] } as NetlifyPluginOptions [ "netlifyConfig" ]
178
179
const defaultArgs = {
179
180
netlifyConfig,
180
181
utils,
181
182
constants,
182
- }
183
+ } as NetlifyPluginOptions
183
184
184
185
let restoreCwd
185
186
let cleanup
0 commit comments