Skip to content

Commit c34dbb0

Browse files
authored
fix: use POSIX paths for Windows require()s (#520)
* fix: use POSIX paths for Windows require()s * fix: test imports
1 parent 23f9379 commit c34dbb0

File tree

12 files changed

+10422
-206
lines changed

12 files changed

+10422
-206
lines changed

Diff for: package-lock.json

+10,368-167
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@
8181
"moize": "^6.0.0",
8282
"node-fetch": "^2.6.1",
8383
"semver": "^7.3.2",
84-
"sharp": "^0.28.1"
84+
"sharp": "^0.28.1",
85+
"slash": "^2.0.0"
8586
},
8687
"devDependencies": {
8788
"@netlify/eslint-config-node": "^3.1.7",

Diff for: src/lib/config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const getNextSrcDirs = require('./helpers/getNextSrcDir')
44

55
// This is where next-on-netlify will place all static files.
66
// The publish key in netlify.toml should point to this folder.
7-
const NETLIFY_PUBLISH_PATH = join('.', 'out_publish/')
7+
const NETLIFY_PUBLISH_PATH = join('.', 'out_publish')
88

99
// This is where next-on-netlify will place all Netlify Functions.
1010
// The functions key in netlify.toml should point to this folder.
11-
const NETLIFY_FUNCTIONS_PATH = join('.', 'out_functions/')
11+
const NETLIFY_FUNCTIONS_PATH = join('.', 'out_functions')
1212

1313
// This is where static assets, such as images, can be placed. They will be
1414
// copied as-is to the Netlify publish folder.
15-
const PUBLIC_PATH = join('.', 'public/')
15+
const PUBLIC_PATH = join('.', 'public')
1616

1717
// This is the file where NextJS can be configured
1818
const NEXT_CONFIG_PATH = join('.', 'next.config.js')

Diff for: src/lib/pages/getStaticProps/redirects.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
46
const asyncForEach = require('../../helpers/asyncForEach')
57
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
@@ -31,7 +33,7 @@ const getRedirects = async () => {
3133

3234
await asyncForEach(pages, async ({ route, dataRoute, srcRoute }) => {
3335
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
34-
const filePath = join('pages', relativePath)
36+
const filePath = slash(join('pages', relativePath))
3537
const functionName = getNetlifyFunctionName(filePath)
3638

3739
// Preview mode conditions

Diff for: src/lib/pages/getStaticProps/setup.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
46
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
57
const { logTitle } = require('../../helpers/logger')
@@ -34,7 +36,7 @@ const setup = async ({ functionsPath, publishPath }) => {
3436

3537
// Set up the Netlify function (this is ONLY for preview mode)
3638
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
37-
const filePath = join('pages', relativePath)
39+
const filePath = slash(join('pages', relativePath))
3840

3941
// Skip if we have already set up a function for this file
4042

Diff for: src/lib/pages/getStaticPropsWithFallback/redirects.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
46
const asyncForEach = require('../../helpers/asyncForEach')
57
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
@@ -13,7 +15,7 @@ const getRedirects = async () => {
1315

1416
await asyncForEach(pages, async ({ route, dataRoute }) => {
1517
const relativePath = getFilePathForRoute(route, 'js')
16-
const filePath = join('pages', relativePath)
18+
const filePath = slash(join('pages', relativePath))
1719
const functionName = getNetlifyFunctionName(filePath)
1820
const target = `/.netlify/functions/${functionName}`
1921

Diff for: src/lib/pages/getStaticPropsWithFallback/setup.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
46
const { logTitle } = require('../../helpers/logger')
57

@@ -14,7 +16,7 @@ const setup = async (functionsPath) => {
1416
// Create Netlify Function for every page
1517
return pages.map(({ route }) => {
1618
const relativePath = getFilePathForRoute(route, 'js')
17-
const filePath = join('pages', relativePath)
19+
const filePath = slash(join('pages', relativePath))
1820
return { type: 'function', filePath, functionsPath, isISR: true }
1921
})
2022
}

Diff for: src/lib/pages/getStaticPropsWithRevalidate/redirects.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
46
const asyncForEach = require('../../helpers/asyncForEach')
57
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
@@ -28,7 +30,7 @@ const getRedirects = async () => {
2830

2931
await asyncForEach(pages, async ({ route, srcRoute, dataRoute }) => {
3032
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
31-
const filePath = join('pages', relativePath)
33+
const filePath = slash(join('pages', relativePath))
3234
const functionName = getNetlifyFunctionName(filePath)
3335
const target = `/.netlify/functions/${functionName}`
3436

Diff for: src/lib/pages/getStaticPropsWithRevalidate/setup.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { join } = require('path')
22

3+
const slash = require('slash')
4+
35
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
46
const { logTitle } = require('../../helpers/logger')
57

@@ -25,7 +27,7 @@ const setup = async (functionsPath) => {
2527

2628
pages.forEach(({ route, srcRoute }) => {
2729
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
28-
const filePath = join('pages', relativePath)
30+
const filePath = slash(join('pages', relativePath))
2931
if (filePathsDone.has(filePath)) {
3032
return
3133
}

Diff for: src/tests/defaults.test.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test default next-on-netlify configuration
22

3-
const { parse, join, sep } = require('path')
3+
const { parse, join } = require('path')
44
const { existsSync, readdirSync, readFileSync, readJsonSync } = require('fs-extra')
55
const buildNextApp = require('./helpers/buildNextApp')
66

@@ -39,19 +39,19 @@ describe('next-on-netlify', () => {
3939
describe('next-on-netlify', () => {
4040
test('builds successfully', () => {
4141
expect(buildOutput).toMatch('Next on Netlify')
42-
expect(buildOutput).toMatch(`Copying public${sep} folder to out_publish${sep}`)
43-
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
44-
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
45-
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
46-
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
47-
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
42+
expect(buildOutput).toMatch(`Copying public folder to out_publish`)
43+
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
44+
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
45+
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
46+
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
47+
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
4848
expect(buildOutput).toMatch(
49-
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
49+
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
5050
)
5151
expect(buildOutput).toMatch(
52-
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
52+
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
5353
)
54-
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
54+
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
5555
expect(buildOutput).toMatch('Setting up redirects')
5656
expect(buildOutput).toMatch('Success! All done!')
5757
})
@@ -68,6 +68,9 @@ describe('SSR Pages', () => {
6868
true,
6969
)
7070
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.js'))).toBe(true)
71+
expect(
72+
readFileSync(join(functionsDir, 'next_getServerSideProps_id', 'nextPage', 'index.js'), 'utf-8'),
73+
).toBe(`module.exports = require("./pages/getServerSideProps/[id].js")`)
7174
})
7275
})
7376

Diff for: src/tests/i18n-ssg-root-index.test.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)
22

3-
const { parse, join, sep } = require('path')
4-
const { existsSync, readdirSync, readFileSync, readJsonSync } = require('fs-extra')
3+
const { parse, join } = require('path')
54
const buildNextApp = require('./helpers/buildNextApp')
65

76
// The name of this test file (without extension)
@@ -40,18 +39,18 @@ describe('next-on-netlify', () => {
4039
describe('next-on-netlify', () => {
4140
test('builds successfully', () => {
4241
expect(buildOutput).toMatch('Next on Netlify')
43-
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
44-
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
45-
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
46-
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
47-
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
42+
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
43+
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
44+
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
45+
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
46+
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
4847
expect(buildOutput).toMatch(
49-
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
48+
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
5049
)
5150
expect(buildOutput).toMatch(
52-
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
51+
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
5352
)
54-
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
53+
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
5554
expect(buildOutput).toMatch('Setting up redirects')
5655
expect(buildOutput).toMatch('Success! All done!')
5756
})

Diff for: src/tests/i18n.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)
22

3-
const { parse, join, sep } = require('path')
3+
const { parse, join } = require('path')
44
const { existsSync, readdirSync, readFileSync, readJsonSync } = require('fs-extra')
55
const buildNextApp = require('./helpers/buildNextApp')
66

@@ -40,18 +40,18 @@ describe('next-on-netlify', () => {
4040
describe('next-on-netlify', () => {
4141
test('builds successfully', () => {
4242
expect(buildOutput).toMatch('Next on Netlify')
43-
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
44-
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
45-
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
46-
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
47-
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
43+
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
44+
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
45+
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
46+
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
47+
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
4848
expect(buildOutput).toMatch(
49-
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
49+
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
5050
)
5151
expect(buildOutput).toMatch(
52-
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
52+
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
5353
)
54-
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
54+
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
5555
expect(buildOutput).toMatch('Setting up redirects')
5656
expect(buildOutput).toMatch('Success! All done!')
5757
})

0 commit comments

Comments
 (0)