|
1 |
| -const { writeJSON, unlink, existsSync, readFileSync, copy, ensureDir } = require('fs-extra') |
| 1 | +const { writeJSON, unlink, existsSync, readFileSync, copy, ensureDir, readJson } = require('fs-extra') |
2 | 2 | const path = require('path')
|
3 | 3 | const process = require('process')
|
4 | 4 | const os = require('os')
|
@@ -41,10 +41,19 @@ const changeCwd = function (cwd) {
|
41 | 41 | const onBuildHasRun = (netlifyConfig) =>
|
42 | 42 | Boolean(netlifyConfig.functions[HANDLER_FUNCTION_NAME]?.included_files?.some((file) => file.includes('BUILD_ID')))
|
43 | 43 |
|
| 44 | +const rewriteAppDir = async function () { |
| 45 | + const manifest = path.join('.next', 'required-server-files.json') |
| 46 | + const manifestContent = await readJson(manifest) |
| 47 | + manifestContent.appDir = process.cwd() |
| 48 | + |
| 49 | + await writeJSON(manifest, manifestContent) |
| 50 | +} |
| 51 | + |
44 | 52 | // Move .next from sample project to current directory
|
45 | 53 | const moveNextDist = async function () {
|
46 | 54 | await stubModules(['next', 'sharp'])
|
47 | 55 | await copy(path.join(SAMPLE_PROJECT_DIR, '.next'), path.join(process.cwd(), '.next'))
|
| 56 | + await rewriteAppDir() |
48 | 57 | }
|
49 | 58 |
|
50 | 59 | const stubModules = async function (modules) {
|
@@ -231,6 +240,25 @@ describe('onBuild()', () => {
|
231 | 240 | expect(readFileSync(handlerPagesFile, 'utf8')).toMatchSnapshot()
|
232 | 241 | expect(readFileSync(odbHandlerPagesFile, 'utf8')).toMatchSnapshot()
|
233 | 242 | })
|
| 243 | + |
| 244 | + test('generates entrypoints with correct references', async () => { |
| 245 | + await moveNextDist() |
| 246 | + await plugin.onBuild(defaultArgs) |
| 247 | + |
| 248 | + const handlerFile = path.join( |
| 249 | + constants.INTERNAL_FUNCTIONS_SRC, |
| 250 | + HANDLER_FUNCTION_NAME, |
| 251 | + `${HANDLER_FUNCTION_NAME}.js`, |
| 252 | + ) |
| 253 | + const odbHandlerFile = path.join(constants.INTERNAL_FUNCTIONS_SRC, ODB_FUNCTION_NAME, `${ODB_FUNCTION_NAME}.js`) |
| 254 | + expect(existsSync(handlerFile)).toBeTruthy() |
| 255 | + expect(existsSync(odbHandlerFile)).toBeTruthy() |
| 256 | + |
| 257 | + expect(readFileSync(handlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest)`) |
| 258 | + expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`(config, "../../..", pageRoot, staticManifest)`) |
| 259 | + expect(readFileSync(handlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`) |
| 260 | + expect(readFileSync(odbHandlerFile, 'utf8')).toMatch(`require("../../../.next/required-server-files.json")`) |
| 261 | + }) |
234 | 262 | })
|
235 | 263 |
|
236 | 264 | describe('onPostBuild', () => {
|
|
0 commit comments