Skip to content

Commit

Permalink
Merge branch 'canary' into add/rewrite-proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Feb 4, 2020
2 parents e78f752 + 44e234e commit 123356c
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 78 deletions.
2 changes: 0 additions & 2 deletions examples/blog-starter/now.json
@@ -1,8 +1,6 @@
{
"version": 2,
"name": "nextjs-blog-starter",
"alias": ["nextjs-blog-starter.now.sh"],
"builds": [{ "src": "package.json", "use": "@now/next" }],
"routes": [
{ "src": "/feed.json", "dest": "/_next/static/feed.json" },
{ "src": "/blog/(?<page>[^/]+)$", "dest": "/blog?page=$page" }
Expand Down
7 changes: 0 additions & 7 deletions examples/with-now-env/now.json
@@ -1,11 +1,4 @@
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@now/next"
}
],
"build": {
"env": {
"SECRET": "@my-secret-key",
Expand Down
2 changes: 2 additions & 0 deletions examples/with-stencil/README.md
Expand Up @@ -47,6 +47,8 @@ Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.
now
```

> Choose `packages/web-app` as root directory when deploying.
## The idea behind the example

Stencil is a compiler that generates Web Components (more specifically, Custom Elements). Stencil combines the best concepts of the most popular frameworks into a simple build-time tool.
Expand Down
5 changes: 0 additions & 5 deletions examples/with-stencil/now.json

This file was deleted.

2 changes: 2 additions & 0 deletions examples/with-yarn-workspaces/README.md
Expand Up @@ -48,6 +48,8 @@ Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.
now
```

> Choose `packages/web-app` as root directory when deploying.
## Useful Links

- [Documentation](https://yarnpkg.com/en/docs/workspaces)
Expand Down
5 changes: 0 additions & 5 deletions examples/with-yarn-workspaces/now.json

This file was deleted.

2 changes: 2 additions & 0 deletions examples/with-zones/blog/.gitignore
@@ -1,2 +1,4 @@
.next
node_modules

.now
13 changes: 13 additions & 0 deletions examples/with-zones/blog/now.json
@@ -0,0 +1,13 @@
{
"build": {
"env": {
"BUILDING_FOR_NOW": "true"
}
},
"rewrites": [
{
"source": "/blog/_next$1",
"destination": "/_next$1"
}
]
}
2 changes: 2 additions & 0 deletions examples/with-zones/home/.gitignore
@@ -1,2 +1,4 @@
.next
node_modules

.now
8 changes: 8 additions & 0 deletions examples/with-zones/home/now.json
@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/blog(.*)",
"destination": "https://with-zones-blog.now.sh$1"
}
]
}
18 changes: 0 additions & 18 deletions examples/with-zones/now.json

This file was deleted.

3 changes: 0 additions & 3 deletions examples/z-experimental-next-news/now.json

This file was deleted.

2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.2-canary.9"
"version": "9.2.2-canary.10"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
3 changes: 1 addition & 2 deletions packages/next/build/index.ts
Expand Up @@ -770,9 +770,8 @@ export default async function build(dir: string, conf = null): Promise<void> {

const analysisEnd = process.hrtime(analysisBegin)
telemetry.record(
eventBuildOptimize({
eventBuildOptimize(pagePaths, {
durationInSeconds: analysisEnd[0],
totalPageCount: pagePaths.length,
staticPageCount: staticPages.size,
ssrPageCount: pagePaths.length - staticPages.size,
})
Expand Down
10 changes: 4 additions & 6 deletions packages/next/next-server/server/next-server.ts
Expand Up @@ -164,12 +164,10 @@ export default class Server {
}

// Initialize next/config with the environment configuration
if (this.nextConfig.target === 'server') {
envConfig.setConfig({
serverRuntimeConfig,
publicRuntimeConfig,
})
}
envConfig.setConfig({
serverRuntimeConfig,
publicRuntimeConfig,
})

this.serverBuildDir = join(
this.distDir,
Expand Down
4 changes: 2 additions & 2 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.2.2-canary.9",
"version": "9.2.2-canary.10",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -73,7 +73,7 @@
"@babel/preset-typescript": "7.7.2",
"@babel/runtime": "7.7.2",
"@babel/runtime-corejs2": "7.7.2",
"@next/polyfill-nomodule": "9.2.2-canary.9",
"@next/polyfill-nomodule": "9.2.2-canary.10",
"amphtml-validator": "1.0.23",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
Expand Down
23 changes: 21 additions & 2 deletions packages/next/telemetry/events/build.ts
Expand Up @@ -19,13 +19,32 @@ type EventBuildOptimized = {
totalPageCount: number
staticPageCount: number
ssrPageCount: number
hasDunderPages: boolean
hasTestPages: boolean
}

const REGEXP_DIRECTORY_DUNDER = /[\\/]__[^\\/]+(?<![\\/]__(?:tests|mocks))__[\\/]/i
const REGEXP_DIRECTORY_TESTS = /[\\/]__(tests|mocks)__[\\/]/i
const REGEXP_FILE_TEST = /\.(?:spec|test)\.[^.]+$/i

export function eventBuildOptimize(
event: EventBuildOptimized
pagePaths: string[],
event: Omit<
EventBuildOptimized,
'totalPageCount' | 'hasDunderPages' | 'hasTestPages'
>
): { eventName: string; payload: EventBuildOptimized } {
return {
eventName: EVENT_BUILD_OPTIMIZE,
payload: event,
payload: {
...event,
totalPageCount: pagePaths.length,
hasDunderPages: pagePaths.some(path =>
REGEXP_DIRECTORY_DUNDER.test(path)
),
hasTestPages: pagePaths.some(
path => REGEXP_DIRECTORY_TESTS.test(path) || REGEXP_FILE_TEST.test(path)
),
},
}
}
59 changes: 41 additions & 18 deletions test/integration/serverless-runtime-configs/test/index.test.js
Expand Up @@ -6,6 +6,7 @@ import {
nextBuild,
findPort,
killApp,
launchApp,
renderViaHTTP,
initNextServerScript,
} from 'next-test-utils'
Expand Down Expand Up @@ -74,24 +75,7 @@ describe('Serverless runtime configs', () => {
)
})

it('should support runtime configs in serverless mode', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)

await nextBuild(appDir, [], { stderr: true, stdout: true })
const appPort = await findPort()
const app = await nextStart(appDir, appPort)

const testRuntimeConfig = async (app, appPort) => {
const browser = await webdriver(appPort, '/config')

const clientHTML = await browser.eval(`document.documentElement.innerHTML`)
Expand Down Expand Up @@ -140,5 +124,44 @@ describe('Serverless runtime configs', () => {
expect(JSON.parse(docClientConfig)).toEqual(expectedSsrConfig)

expect(JSON.parse(apiJson)).toEqual(expectedSsrConfig)
}

it('should support runtime configs in serverless mode (production)', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)

await nextBuild(appDir, [], { stderr: true, stdout: true })
const appPort = await findPort()
const app = await nextStart(appDir, appPort)
await testRuntimeConfig(app, appPort)
})

it('should support runtime configs in serverless mode (dev)', async () => {
await fs.writeFile(
nextConfigPath,
`module.exports = {
target: 'serverless',
serverRuntimeConfig: {
hello: 'world'
},
publicRuntimeConfig: {
another: 'thing'
}
}`
)

const appPort = await findPort()
const app = await launchApp(appDir, appPort)
await testRuntimeConfig(app, appPort)
})
})
3 changes: 3 additions & 0 deletions test/integration/telemetry/pages/__ytho__/lel.js
@@ -0,0 +1,3 @@
export default () => {
return 'oops, I happen to look like a React component'
}
1 change: 1 addition & 0 deletions test/integration/telemetry/pages/hello.test.skip
@@ -0,0 +1 @@
export default () => 'Hello Test'
20 changes: 20 additions & 0 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -92,6 +92,26 @@ describe('Telemetry CLI', () => {
expect(stderr2).toMatch(/isSrcDir.*?true/)
})

it('detects tests correctly for `next build`', async () => {
await fs.rename(
path.join(appDir, 'pages', 'hello.test.skip'),
path.join(appDir, 'pages', 'hello.test.js')
)
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await fs.rename(
path.join(appDir, 'pages', 'hello.test.js'),
path.join(appDir, 'pages', 'hello.test.skip')
)

expect(stderr).toMatch(/hasDunderPages.*?true/)
expect(stderr).toMatch(/hasTestPages.*?true/)
})

it('detects isSrcDir dir correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''
Expand Down

0 comments on commit 123356c

Please sign in to comment.