Skip to content

Commit 077cc18

Browse files
authored
fix: copy-next-code on windows (#297)
1 parent 8a60324 commit 077cc18

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/build/content/server.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { existsSync } from 'node:fs'
22
import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from 'node:fs/promises'
33
import { createRequire } from 'node:module'
44
// eslint-disable-next-line no-restricted-imports
5-
import { dirname, join, resolve } from 'node:path'
5+
import { dirname, join, resolve, sep } from 'node:path'
6+
import { sep as posixSep } from 'node:path/posix'
67

78
import glob from 'fast-glob'
89

910
import { RUN_CONFIG } from '../../run/constants.js'
1011
import { PluginContext } from '../plugin-context.js'
1112

13+
const toPosixPath = (path: string) => path.split(sep).join(posixSep)
14+
1215
/**
1316
* Copy App/Pages Router Javascript needed by the server handler
1417
*/
@@ -26,7 +29,7 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
2629
// this means the path got altered by a plugin like nx and contained ../../ parts so we have to reset it
2730
// to point to the correct lambda destination
2831
if (
29-
ctx.distDir.replace(new RegExp(`^${ctx.packagePath}/?`), '') !== reqServerFiles.config.distDir
32+
toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.packagePath}/?`), '') !== reqServerFiles.config.distDir
3033
) {
3134
// set the distDir to the latest path portion of the publish dir
3235
reqServerFiles.config.distDir = ctx.nextDistDir
@@ -45,7 +48,7 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
4548

4649
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir)
4750
// if the distDir got resolved and altered use the nextDistDir instead
48-
const nextFolder = ctx.distDir === ctx.buildConfig.distDir ? ctx.distDir : ctx.nextDistDir
51+
const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir
4952
const destDir = join(ctx.serverHandlerDir, nextFolder)
5053

5154
const paths = await glob(

tests/integration/build/copy-next-code.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test<FixtureTestContext>('should copy the next standalone folder correctly for a
3030
).toEqual(['required-server-files.json'])
3131
})
3232

33-
test.skipIf(platform === "win32")<FixtureTestContext>('should copy the next standalone folder correctly based on a custom dist dir', async (ctx) => {
33+
test<FixtureTestContext>('should copy the next standalone folder correctly based on a custom dist dir', async (ctx) => {
3434
const reqServerFiles = JSON.stringify({ config: { distDir: 'out/dir' } })
3535
const reqServerPath = 'out/dir/required-server-files.json'
3636
const reqServerPathStandalone = join('out/dir/standalone', reqServerPath)
@@ -77,7 +77,7 @@ test<FixtureTestContext>('should copy the next standalone folder correctly for m
7777
).toEqual(['required-server-files.json'])
7878
})
7979

80-
test.skipIf(platform === "win32")<FixtureTestContext>('should copy the next standalone folder correctly for monorepo with custom dir', async (ctx) => {
80+
test<FixtureTestContext>('should copy the next standalone folder correctly for monorepo with custom dir', async (ctx) => {
8181
const reqServerFiles = JSON.stringify({ config: { distDir: 'deep/out/dir' } })
8282
const reqServerPath = 'apps/my-app/deep/out/dir/required-server-files.json'
8383
const reqServerPathStandalone = join('apps/my-app/deep/out/dir/standalone', reqServerPath)

0 commit comments

Comments
 (0)