Compare commits

..

5 Commits

Author SHA1 Message Date
Joe Haddad
4e58951808 Publish
- @now/next@1.0.4
2019-10-20 14:56:29 -04:00
Joe Haddad
fbd805aad7 [now-next] Update console.time labels for clarity (#3157) 2019-10-20 14:37:35 -04:00
JJ Kasper
2a2705c6e3 Add test for now dev and Next.js src dir (#3149)
Follow up on #3140 we needed to publish the change before we could test it in `now dev`
2019-10-20 14:37:27 -04:00
JJ Kasper
986c957183 [now-next] Add support for src dir in now-dev (#3140)
Fixes: #3133
Fixes: https://github.com/zeit/next.js/issues/9007
2019-10-20 14:37:13 -04:00
Nathan Rajlich
c5d063e876 [now-next] Exit dev server child processes upon SIGINT/SIGTERM (#3137)
Explicitly send the SIGINT / SIGTERM signal to `now dev` server child processes, so that they are not left running when running the now-dev unit tests.

Related to #3113 which has hanging unit tests that never "complete".
2019-10-20 14:37:07 -04:00
9 changed files with 5645 additions and 6 deletions

View File

@@ -0,0 +1,2 @@
node_modules
.next

View File

@@ -0,0 +1,2 @@
README.md
yarn.lock

View File

@@ -0,0 +1,13 @@
{
"name": "nextjs",
"license": "MIT",
"scripts": {
"dev": "next",
"build": "next build"
},
"dependencies": {
"next": "^9.1.1",
"react": "^16.7.0",
"react-dom": "^16.7.0"
}
}

View File

@@ -0,0 +1,102 @@
import { useEffect, useState } from 'react';
import Head from 'next/head';
function Index() {
const [date, setDate] = useState(null);
useEffect(() => {
async function getDate() {
const res = await fetch('/api/date');
const newDate = await res.text();
setDate(newDate);
}
getDate();
}, []);
return (
<main>
<Head>
<title>Next.js + Node API</title>
</Head>
<h1>Next.js + Node.js API</h1>
<h2>
Deployed with{' '}
<a
href="https://zeit.co/docs"
target="_blank"
rel="noreferrer noopener"
>
ZEIT Now
</a>
!
</h2>
<p>
<a
href="https://github.com/zeit/now-examples/blob/master/nextjs-node"
target="_blank"
rel="noreferrer noopener"
>
This project
</a>{' '}
is a <a href="https://nextjs.org/">Next.js</a> app with two directories,{' '}
<code>/pages</code> for static content and <code>/api</code> which
contains a serverless <a href="https://nodejs.org/en/">Node.js</a>{' '}
function. See{' '}
<a href="/api/date">
<code>api/date</code> for the Date API with Node.js
</a>
.
</p>
<br />
<h2>The date according to Node.js is:</h2>
<p>{date ? date : 'Loading date...'}</p>
<style jsx>{`
main {
align-content: center;
box-sizing: border-box;
display: grid;
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue',
'Helvetica', 'Arial', sans-serif;
hyphens: auto;
line-height: 1.65;
margin: 0 auto;
max-width: 680px;
min-height: 100vh;
padding: 72px 0;
text-align: center;
}
h1 {
font-size: 45px;
}
h2 {
margin-top: 1.5em;
}
p {
font-size: 16px;
}
a {
border-bottom: 1px solid white;
color: #0076ff;
cursor: pointer;
text-decoration: none;
transition: all 0.2s ease;
}
a:hover {
border-bottom: 1px solid #0076ff;
}
code,
pre {
color: #d400ff;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono,
DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace,
serif;
font-size: 0.92em;
}
code:before,
code:after {
content: '\`';
}
`}</style>
</main>
);
}
export default Index;

File diff suppressed because it is too large Load Diff

View File

@@ -869,3 +869,23 @@ test('[now dev] do not rebuild for changes in the output directory', async t =>
dev.kill('SIGTERM');
}
});
test('[now dev] 25-nextjs-src-dir', async t => {
const directory = fixture('25-nextjs-src-dir');
const { dev, port } = await testFixture(directory);
try {
// start `now dev` detached in child_process
dev.unref();
const result = await fetchWithRetry(`http://localhost:${port}`, 80);
const response = await result;
validateResponseHeaders(t, response);
const body = await response.text();
t.regex(body, /Next.js \+ Node.js API/gm);
} finally {
dev.kill('SIGTERM');
}
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/next-js-now-next",

View File

@@ -67,6 +67,20 @@ interface BuildParamsType extends BuildOptions {
export const version = 2;
const nowDevChildProcesses = new Set<ChildProcess>();
['SIGINT', 'SIGTERM'].forEach(signal => {
process.once(signal as NodeJS.Signals, () => {
for (const child of nowDevChildProcesses) {
debug(
`Got ${signal}, killing dev server child process (pid=${child.pid})`
);
process.kill(child.pid, signal);
}
process.exit(0);
});
});
/**
* Read package.json from files
*/
@@ -212,6 +226,7 @@ export const build = async ({
const { forked, getUrl } = startDevServer(entryPath, runtimeEnv);
urls[entrypoint] = await getUrl();
childProcess = forked;
nowDevChildProcesses.add(forked);
debug(
`${name} Development server for ${entrypoint} running at ${urls[entrypoint]}`
);
@@ -571,7 +586,7 @@ export const build = async ({
const launcherPath = path.join(__dirname, 'templated-launcher.js');
const launcherData = await readFile(launcherPath, 'utf8');
const allLambdasLabel = `All serverless functions created`;
const allLambdasLabel = `All serverless functions created (in parallel)`;
console.time(allLambdasLabel);
await Promise.all(
@@ -587,7 +602,7 @@ export const build = async ({
dynamicPages.push(normalizePage(pathname));
}
const label = `Creating serverless function for page: "${page}"...`;
const label = `Created serverless function for "${page}" in`;
console.time(label);
const pageFileName = path.normalize(

View File

@@ -176,17 +176,35 @@ function getRoutes(
files: Files,
url: string
): Route[] {
let pagesDir = '';
const filesInside: Files = {};
const prefix = entryDirectory === `.` ? `/` : `/${entryDirectory}/`;
const fileKeys = Object.keys(files);
for (const file of Object.keys(files)) {
for (const file of fileKeys) {
if (!pathsInside.includes(file)) {
continue;
}
if (!pagesDir) {
if (file.startsWith(path.join(entryDirectory, 'pages'))) {
pagesDir = 'pages';
}
}
filesInside[file] = files[file];
}
// If default pages dir isn't found check for `src/pages`
if (
!pagesDir &&
fileKeys.some(file =>
file.startsWith(path.join(entryDirectory, 'src/pages'))
)
) {
pagesDir = 'src/pages';
}
const routes: Route[] = [
{
src: `${prefix}_next/(.*)`,
@@ -202,13 +220,13 @@ function getRoutes(
for (const file of filePaths) {
const relativePath = path.relative(entryDirectory, file);
const isPage = pathIsInside('pages', relativePath);
const isPage = pathIsInside(pagesDir, relativePath);
if (!isPage) {
continue;
}
const relativeToPages = path.relative('pages', relativePath);
const relativeToPages = path.relative(pagesDir, relativePath);
const extension = path.extname(relativeToPages);
const pageName = relativeToPages.replace(extension, '').replace(/\\/g, '/');