Skip to content

Commit

Permalink
Merge branch 'canary' into sanjaiyan-nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Jul 11, 2022
2 parents 64c2f7e + 9222ca9 commit ee6139d
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 21 deletions.
29 changes: 26 additions & 3 deletions .github/actions/next-stats-action/src/run/collect-stats.js
Expand Up @@ -35,6 +35,7 @@ module.exports = async function collectStats(
(hasPagesToFetch || hasPagesToBench)
) {
const port = await getPort()
const startTime = Date.now()
const child = spawn(statsConfig.appStartCommand, {
cwd: curDir,
env: {
Expand All @@ -44,14 +45,36 @@ module.exports = async function collectStats(
})
let exitCode = null
let logStderr = true
child.stdout.on('data', (data) => process.stdout.write(data))

let serverReadyResolve
let serverReadyResolved = false
const serverReadyPromise = new Promise((resolve) => {
serverReadyResolve = resolve
})

child.stdout.on('data', (data) => {
if (data.toString().includes('started server') && !serverReadyResolved) {
serverReadyResolved = true
serverReadyResolve()
}
process.stdout.write(data)
})
child.stderr.on('data', (data) => logStderr && process.stderr.write(data))

child.on('exit', (code) => {
if (!serverReadyResolved) {
serverReadyResolve()
serverReadyResolved = true
}
exitCode = code
})
// give app a second to start up
await new Promise((resolve) => setTimeout(() => resolve(), 1500))

await serverReadyPromise
if (!orderedStats['General']) {
orderedStats['General'] = {}
}
orderedStats['General']['nextStartReadyDuration (ms)'] =
Date.now() - startTime

if (exitCode !== null) {
throw new Error(
Expand Down
56 changes: 53 additions & 3 deletions .github/actions/next-stats-action/src/run/index.js
@@ -1,5 +1,6 @@
const path = require('path')
const fs = require('fs-extra')
const getPort = require('get-port')
const glob = require('../util/glob')
const exec = require('../util/exec')
const logger = require('../util/logger')
Expand Down Expand Up @@ -78,9 +79,9 @@ async function runConfigs(
}

const collectedStats = await collectStats(config, statsConfig)
curStats = {
...curStats,
...collectedStats,

for (const key of Object.keys(collectedStats)) {
curStats[key] = Object.assign({}, curStats[key], collectedStats[key])
}

const applyRenames = (renames, stats) => {
Expand Down Expand Up @@ -156,6 +157,55 @@ async function runConfigs(
env: yarnEnvValues,
})
curStats.General.buildDurationCached = Date.now() - secondBuildStart

if (statsConfig.appDevCommand) {
const port = await getPort()
const startTime = Date.now()
const child = exec.spawn(statsConfig.appDevCommand, {
cwd: statsAppDir,
env: {
PORT: port,
},
stdio: 'pipe',
})

let serverReadyResolve
let serverReadyResolved = false
const serverReadyPromise = new Promise((resolve) => {
serverReadyResolve = resolve
})

child.stdout.on('data', (data) => {
if (
data.toString().includes('started server') &&
!serverReadyResolved
) {
serverReadyResolved = true
serverReadyResolve()
}
process.stdout.write(data)
})
child.stderr.on('data', (data) => process.stderr.write(data))

child.on('exit', (code) => {
if (!serverReadyResolved) {
serverReadyResolve()
serverReadyResolved = true
}
exitCode = code
})

setTimeout(() => {
if (!serverReadyResolved) {
child.kill()
}
}, 3 * 1000)

await serverReadyPromise
child.kill()

curStats['General']['nextDevReadyDuration'] = Date.now() - startTime
}
}

logger(`Finished running: ${config.title}`)
Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Expand Up @@ -57,7 +57,10 @@ stages:
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm store path
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
Expand Down Expand Up @@ -92,7 +95,10 @@ stages:
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm store path
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
Expand Down
2 changes: 2 additions & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -364,6 +364,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
serverDistDir: this.serverDistDir,
maxMemoryCacheSize: this.nextConfig.experimental.isrMemoryCacheSize,
flushToDisk: !minimalMode && this.nextConfig.experimental.isrFlushToDisk,
incrementalCacheHandlerPath:
this.nextConfig.experimental?.incrementalCacheHandlerPath,
getPrerenderManifest: () => {
if (dev) {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/next/server/config-shared.ts
Expand Up @@ -534,6 +534,7 @@ export const defaultConfig: NextConfig = {
appDir: false,
// default to 50MB limit
isrMemoryCacheSize: 50 * 1024 * 1024,
incrementalCacheHandlerPath: undefined,
serverComponents: false,
fullySpecified: false,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
Expand Down
8 changes: 4 additions & 4 deletions packages/next/telemetry/events/swc-plugins.ts
Expand Up @@ -5,8 +5,8 @@ const EVENT_SWC_PLUGIN_PRESENT = 'NEXT_SWC_PLUGIN_DETECTED'
type SwcPluginsEvent = {
eventName: string
payload: {
packageName: string
packageVersion?: string
pluginName: string
pluginVersion?: string
}
}

Expand Down Expand Up @@ -34,8 +34,8 @@ export async function eventSwcPlugins(
events.push({
eventName: EVENT_SWC_PLUGIN_PRESENT,
payload: {
packageName: plugin,
packageVersion: version,
pluginName: plugin,
pluginVersion: version,
},
})

Expand Down
1 change: 1 addition & 0 deletions test/.stats-app/stats-config.js
Expand Up @@ -68,6 +68,7 @@ module.exports = {
commentReleaseHeading: 'Stats from current release',
appBuildCommand: 'NEXT_TELEMETRY_DISABLED=1 yarn next build',
appStartCommand: 'NEXT_TELEMETRY_DISABLED=1 yarn next start --port $PORT',
appDevCommand: 'NEXT_TELEMETRY_DISABLED=1 yarn next --port $PORT',
mainRepo: 'vercel/next.js',
mainBranch: 'canary',
autoMergeMain: true,
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -50,12 +50,12 @@ describe('app dir - react server components', () => {
afterAll(() => next.destroy())

const { isNextDeploy, isNextDev } = global as any
if (isNextDeploy) {
it('should skip tests for next-deploy', () => {})
const isReact17 = process.env.NEXT_TEST_REACT_VERSION === '^17'
if (isNextDeploy || isReact17) {
it('should skip tests for next-deploy and react 17', () => {})
return
}

// TODO: support RSC index route
it('should render server components correctly', async () => {
const homeHTML = await renderViaHTTP(next.url, '/', null, {
headers: {
Expand Down
14 changes: 6 additions & 8 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -843,19 +843,17 @@ describe('Telemetry CLI', () => {
const regex = /NEXT_SWC_PLUGIN_DETECTED[\s\S]+?{([\s\S]+?)}/g

const coverage = regex.exec(stderr).pop()
expect(coverage).toContain(
`"packageName": "swc-plugin-coverage-instrument"`
)
expect(coverage).toContain(`"packageVersion": "0.0.6"`)
expect(coverage).toContain(`"pluginName": "swc-plugin-coverage-instrument"`)
expect(coverage).toContain(`"pluginVersion": "0.0.6"`)

const relay = regex.exec(stderr).pop()
expect(relay).toContain(`"packageName": "@swc/plugin-relay"`)
expect(relay).toContain(`"packageVersion": "0.2.0"`)
expect(relay).toContain(`"pluginName": "@swc/plugin-relay"`)
expect(relay).toContain(`"pluginVersion": "0.2.0"`)

const absolute = regex.exec(stderr).pop()
expect(absolute).toContain(
`"packageName": "/test/absolute_path/plugin.wasm"`
`"pluginName": "/test/absolute_path/plugin.wasm"`
)
expect(absolute).not.toContain(`packageVersion`)
expect(absolute).not.toContain(`pluginVersion`)
})
})

0 comments on commit ee6139d

Please sign in to comment.