-
Notifications
You must be signed in to change notification settings - Fork 67
Fix Windows support #101
Fix Windows support #101
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"name": "next-on-netlify-test", | ||
"scripts": { | ||
"build": "../../../node_modules/.bin/next build", | ||
"build": "next build", | ||
"postbuild": "node ../../../next-on-netlify", | ||
"preview": "../../../node_modules/.bin/netlify dev", | ||
"preview": "netlify dev", | ||
"predeploy": "mkdir -p .git", | ||
"deploy": "../../../node_modules/.bin/netlify deploy --json > deployment.json" | ||
"deploy": "netlify deploy --json > deployment.json" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
const { join } = require("path"); | ||
const { spawnSync } = require("child_process"); | ||
const execa = require("execa"); | ||
|
||
// Build the given NextJS project | ||
const buildProject = ({ project }, config) => { | ||
process.stdout.write(`Building project: ${project}...`); | ||
|
||
// Build project | ||
spawnSync("npm", ["run", "build"], { | ||
execa.sync("npm", ["run", "build"], { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
cwd: join(config.buildsFolder, project), | ||
preferLocal: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://github.com/sindresorhus/execa#preferlocal |
||
}); | ||
|
||
console.log(" Done! ✅"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const waitOn = require("wait-on"); | ||
const { spawn, spawnSync } = require("child_process"); | ||
const execa = require("execa"); | ||
const { join } = require("path"); | ||
const getBaseUrl = require("./getBaseUrl"); | ||
|
||
|
@@ -10,9 +10,10 @@ const deployLocally = ({ project }, config) => { | |
// Start server. Must start in detached mode, so that we can kill it later. | ||
// Otherwise, we seem unable to kill it. | ||
// See: https://medium.com/@almenon214/killing-processes-with-node-772ffdd19aad | ||
const server = spawn("npm", ["run", "preview"], { | ||
const server = execa("npm", ["run", "preview"], { | ||
cwd: join(config.buildsFolder, project), | ||
detached: true, | ||
localDir: true, | ||
}); | ||
|
||
// Set deployment | ||
|
@@ -36,9 +37,9 @@ const deployOnNetlify = ({ project }, config) => { | |
process.stdout.write(`Deploying project: ${project}...`); | ||
|
||
// Trigger deploy | ||
const deploy = spawnSync("npm", ["run", "deploy"], { | ||
const deploy = execa.sync("npm", ["run", "deploy"], { | ||
cwd: join(config.buildsFolder, project), | ||
encoding: "utf-8", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
localDir: true, | ||
}); | ||
|
||
// Verify success | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ const buildId = fileContents.toString(); | |
// Return the data route for the given route | ||
const getDataRouteForRoute = (route) => { | ||
const filePath = getFilePathForRoute(route, "json"); | ||
|
||
return join("/_next", "data", buildId, filePath); | ||
return `/_next/data/${buildId}${filePath}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Paths in the |
||
}; | ||
|
||
module.exports = getDataRouteForRoute; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Test next-on-netlify when a custom distDir is set in next.config.js | ||
|
||
const { EOL } = require("os"); | ||
const { parse, join } = require("path"); | ||
const { readFileSync } = require("fs-extra"); | ||
const buildNextApp = require("./helpers/buildNextApp"); | ||
|
@@ -40,10 +41,11 @@ describe("Routing", () => { | |
test("includes custom redirect rules", async () => { | ||
// Read _redirects file | ||
const contents = readFileSync( | ||
join(PROJECT_PATH, "out_publish", "_redirects") | ||
join(PROJECT_PATH, "out_publish", "_redirects"), | ||
"utf8" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes the need for |
||
); | ||
|
||
const redirects = contents.toString().trim().split(/\n/); | ||
const redirects = contents.trim().split(EOL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Windows, this is |
||
expect(redirects[0]).toEqual("# Custom Redirect Rules"); | ||
expect(redirects[1]).toEqual( | ||
"https://old.example.com/* https://new.example.com/:splat 301!" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Test default next-on-netlify configuration | ||
|
||
const { parse, join } = require("path"); | ||
const { parse, join, sep } = require("path"); | ||
const { | ||
existsSync, | ||
readdirSync, | ||
|
@@ -44,28 +44,32 @@ describe("next-on-netlify", () => { | |
describe("next-on-netlify", () => { | ||
test("builds successfully", () => { | ||
expect(buildOutput).toMatch("Next on Netlify"); | ||
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/" | ||
`Copying public${sep} folder to out_publish${sep}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File paths are normalized with |
||
); | ||
expect(buildOutput).toMatch( | ||
"Setting up pages with getInitialProps as Netlify Functions in out_functions/" | ||
`Copying static NextJS assets to out_publish${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
"Setting up pages with getServerSideProps as Netlify Functions in out_functions/" | ||
`Setting up API endpoints as Netlify Functions in out_functions${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
"Copying pre-rendered pages with getStaticProps and JSON data to out_publish/" | ||
`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
"Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions/" | ||
`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
"Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions/" | ||
`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
"Copying pre-rendered pages without props to out_publish/" | ||
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}` | ||
); | ||
expect(buildOutput).toMatch( | ||
`Copying pre-rendered pages without props to out_publish${sep}` | ||
); | ||
expect(buildOutput).toMatch("Setting up redirects"); | ||
expect(buildOutput).toMatch("Success! All done!"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "next-on-netlify-test", | ||
"scripts": { | ||
"next-build": "../../../../node_modules/.bin/next build", | ||
"next-build": "next build", | ||
"next-on-netlify": "node ../../../next-on-netlify" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relies on shebangs, which do not work on Windows.
This PR instead relies on
execa
, which adds shebangs support for Windows.Note: I co-maintain
execa
.