Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use POSIX paths for Windows require()s #520

Merged
merged 4 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,535 changes: 10,368 additions & 167 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"moize": "^6.0.0",
"node-fetch": "^2.6.1",
"semver": "^7.3.2",
"sharp": "^0.28.1"
"sharp": "^0.28.1",
"slash": "^2.0.0"
},
"devDependencies": {
"@netlify/eslint-config-node": "^3.1.7",
Expand Down
6 changes: 3 additions & 3 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const getNextSrcDirs = require('./helpers/getNextSrcDir')

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

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

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

// This is the file where NextJS can be configured
const NEXT_CONFIG_PATH = join('.', 'next.config.js')
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticProps/redirects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
const asyncForEach = require('../../helpers/asyncForEach')
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
Expand Down Expand Up @@ -31,7 +33,7 @@ const getRedirects = async () => {

await asyncForEach(pages, async ({ route, dataRoute, srcRoute }) => {
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
const filePath = join('pages', relativePath)
const filePath = slash(join('pages', relativePath))
const functionName = getNetlifyFunctionName(filePath)

// Preview mode conditions
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticProps/setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
const isRouteWithFallback = require('../../helpers/isRouteWithFallback')
const { logTitle } = require('../../helpers/logger')
Expand Down Expand Up @@ -34,7 +36,7 @@ const setup = async ({ functionsPath, publishPath }) => {

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

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

Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticPropsWithFallback/redirects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const addLocaleRedirects = require('../../helpers/addLocaleRedirects')
const asyncForEach = require('../../helpers/asyncForEach')
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
Expand All @@ -13,7 +15,7 @@ const getRedirects = async () => {

await asyncForEach(pages, async ({ route, dataRoute }) => {
const relativePath = getFilePathForRoute(route, 'js')
const filePath = join('pages', relativePath)
const filePath = slash(join('pages', relativePath))
const functionName = getNetlifyFunctionName(filePath)
const target = `/.netlify/functions/${functionName}`

Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticPropsWithFallback/setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
const { logTitle } = require('../../helpers/logger')

Expand All @@ -14,7 +16,7 @@ const setup = async (functionsPath) => {
// Create Netlify Function for every page
return pages.map(({ route }) => {
const relativePath = getFilePathForRoute(route, 'js')
const filePath = join('pages', relativePath)
const filePath = slash(join('pages', relativePath))
return { type: 'function', filePath, functionsPath, isISR: true }
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticPropsWithRevalidate/redirects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const addDefaultLocaleRedirect = require('../../helpers/addDefaultLocaleRedirect')
const asyncForEach = require('../../helpers/asyncForEach')
const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
Expand Down Expand Up @@ -28,7 +30,7 @@ const getRedirects = async () => {

await asyncForEach(pages, async ({ route, srcRoute, dataRoute }) => {
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
const filePath = join('pages', relativePath)
const filePath = slash(join('pages', relativePath))
const functionName = getNetlifyFunctionName(filePath)
const target = `/.netlify/functions/${functionName}`

Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/getStaticPropsWithRevalidate/setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { join } = require('path')

const slash = require('slash')

const getFilePathForRoute = require('../../helpers/getFilePathForRoute')
const { logTitle } = require('../../helpers/logger')

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

pages.forEach(({ route, srcRoute }) => {
const relativePath = getFilePathForRoute(srcRoute || route, 'js')
const filePath = join('pages', relativePath)
const filePath = slash(join('pages', relativePath))
if (filePathsDone.has(filePath)) {
return
}
Expand Down
23 changes: 13 additions & 10 deletions src/tests/defaults.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test default next-on-netlify configuration

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

Expand Down Expand Up @@ -39,19 +39,19 @@ describe('next-on-netlify', () => {
describe('next-on-netlify', () => {
test('builds successfully', () => {
expect(buildOutput).toMatch('Next on Netlify')
expect(buildOutput).toMatch(`Copying public${sep} folder to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying public folder to out_publish`)
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
expect(buildOutput).toMatch('Setting up redirects')
expect(buildOutput).toMatch('Success! All done!')
})
Expand All @@ -68,6 +68,9 @@ describe('SSR Pages', () => {
true,
)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.js'))).toBe(true)
expect(
readFileSync(join(functionsDir, 'next_getServerSideProps_id', 'nextPage', 'index.js'), 'utf-8'),
).toBe(`module.exports = require("./pages/getServerSideProps/[id].js")`)
})
})

Expand Down
19 changes: 9 additions & 10 deletions src/tests/i18n-ssg-root-index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)

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

// The name of this test file (without extension)
Expand Down Expand Up @@ -40,18 +39,18 @@ describe('next-on-netlify', () => {
describe('next-on-netlify', () => {
test('builds successfully', () => {
expect(buildOutput).toMatch('Next on Netlify')
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
expect(buildOutput).toMatch('Setting up redirects')
expect(buildOutput).toMatch('Success! All done!')
})
Expand Down
18 changes: 9 additions & 9 deletions src/tests/i18n.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)

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

Expand Down Expand Up @@ -40,18 +40,18 @@ describe('next-on-netlify', () => {
describe('next-on-netlify', () => {
test('builds successfully', () => {
expect(buildOutput).toMatch('Next on Netlify')
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish${sep}`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying static NextJS assets to out_publish`)
expect(buildOutput).toMatch(`Setting up API endpoints as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getInitialProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Setting up pages with getServerSideProps as Netlify Functions in out_functions`)
expect(buildOutput).toMatch(`Copying pre-rendered pages with getStaticProps and JSON data to out_publish`)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`,
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions`,
)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish${sep}`)
expect(buildOutput).toMatch(`Copying pre-rendered pages without props to out_publish`)
expect(buildOutput).toMatch('Setting up redirects')
expect(buildOutput).toMatch('Success! All done!')
})
Expand Down