Skip to content

Commit

Permalink
Fix turbo usage in tests (#44715)
Browse files Browse the repository at this point in the history
  • Loading branch information
jankaifer authored Jan 18, 2023
1 parent ad48202 commit d7307cf
Show file tree
Hide file tree
Showing 27 changed files with 301 additions and 259 deletions.
1 change: 1 addition & 0 deletions .github/actions/next-stats-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"main": "src/index.js",
"dependencies": {
"async-sema": "^3.1.0",
"execa": "2.0.3",
"fs-extra": "^8.1.0",
"get-port": "^5.0.0",
"glob": "^7.1.4",
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/next-stats-action/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const benchTitle = 'Page Load Tests'
const workDir = path.join(os.tmpdir(), 'next-stats')
const mainRepoName = 'main-repo'
const diffRepoName = 'diff-repo'
const mainRepoDir = path.join(workDir, mainRepoName)
const diffRepoDir = path.join(workDir, diffRepoName)
const mainRepoDir = path.join(os.tmpdir(), mainRepoName)
const diffRepoDir = path.join(os.tmpdir(), diffRepoName)
const statsAppDir = path.join(workDir, 'stats-app')
const diffingDir = path.join(workDir, 'diff')
const yarnEnvValues = {
Expand Down
6 changes: 2 additions & 4 deletions .github/actions/next-stats-action/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
if (actionInfo.isRelease) {
logger('Release detected, resetting mainRepo to last stable tag')
const lastStableTag = await getLastStable(mainRepoDir, actionInfo.prRef)
mainNextSwcVersion = {
'@next/swc-linux-x64-gnu': lastStableTag,
}
mainNextSwcVersion = lastStableTag
if (!lastStableTag) throw new Error('failed to get last stable tag')
console.log('using latestStable', lastStableTag)
await checkoutRef(lastStableTag, mainRepoDir)
Expand Down Expand Up @@ -140,7 +138,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
const isMainRepo = dir === mainRepoDir
const pkgPaths = await linkPackages({
repoDir: dir,
nextSwcPkg: isMainRepo ? mainNextSwcVersion : undefined,
nextSwcVersion: isMainRepo ? mainNextSwcVersion : undefined,
})

if (isMainRepo) mainRepoPkgPaths = pkgPaths
Expand Down
135 changes: 21 additions & 114 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ const exec = require('../util/exec')
const { remove } = require('fs-extra')
const logger = require('../util/logger')
const semver = require('semver')

const mockTrace = () => ({
traceAsyncFn: (fn) => fn(mockTrace()),
traceChild: () => mockTrace(),
})
const execa = require('execa')

module.exports = (actionInfo) => {
return {
Expand Down Expand Up @@ -58,117 +54,28 @@ module.exports = (actionInfo) => {
}
}
},
async linkPackages({ repoDir = '', nextSwcPkg, parentSpan }) {
const rootSpan = parentSpan
? parentSpan.traceChild('linkPackages')
: mockTrace()

return await rootSpan.traceAsyncFn(async () => {
const pkgPaths = new Map()
const pkgDatas = new Map()
let pkgs

try {
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
return pkgPaths
}
throw err
}

await rootSpan
.traceChild('prepare packages for packing')
.traceAsyncFn(async () => {
for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)

const pkgDataPath = path.join(pkgPath, 'package.json')
if (!fs.existsSync(pkgDataPath)) {
require('console').log(`Skipping ${pkgDataPath}`)
continue
}
const pkgData = require(pkgDataPath)
const { name } = pkgData
pkgDatas.set(name, {
pkgDataPath,
pkg,
pkgPath,
pkgData,
packedPkgPath,
})
pkgPaths.set(name, packedPkgPath)
}

for (const pkg of pkgDatas.keys()) {
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)

for (const pkg of pkgDatas.keys()) {
const { packedPkgPath } = pkgDatas.get(pkg)
if (!pkgData.dependencies || !pkgData.dependencies[pkg])
continue
pkgData.dependencies[pkg] = packedPkgPath
}

// make sure native binaries are included in local linking
if (pkg === '@next/swc') {
if (!pkgData.files) {
pkgData.files = []
}
pkgData.files.push('native')
require('console').log(
'using swc binaries: ',
await exec(
`ls ${path.join(path.dirname(pkgDataPath), 'native')}`
)
)
}

if (pkg === 'next') {
if (nextSwcPkg) {
Object.assign(pkgData.dependencies, nextSwcPkg)
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native')
}
}
}

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)
}
})

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await rootSpan
.traceChild('packing packages')
.traceAsyncFn(async (packingSpan) => {
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
await packingSpan
.traceChild(`pack ${pkgName}`)
.traceAsyncFn(async () => {
const { pkg, pkgPath } = pkgDatas.get(pkgName)
await exec(
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
true
)
})
})
)
})
async linkPackages({ repoDir, nextSwcVersion }) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

return pkgPaths
const pkgPaths = new Map()
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))

pkgs.forEach((pkgDirname) => {
const { name } = require(path.join(
repoDir,
'packages',
pkgDirname,
'package.json'
))
pkgPaths.set(
name,
path.join(repoDir, 'packages', pkgDirname, `packed-${pkgDirname}.tgz`)
)
})
return pkgPaths
},
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
.next
target
packages/next/wasm/@next
packages/*/packed-*.tgz

# dependencies
node_modules
Expand All @@ -29,6 +30,7 @@ test/**/tsconfig.json
/e2e-tests
test/tmp/**
test/.trace
test/traces

# Editors
**/.idea
Expand All @@ -49,3 +51,4 @@ test-timings.json
# Cache
*.tsbuildinfo
.swc/
.turbo
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"test": "pnpm testheadless",
"testonly": "pnpm jest --runInBand",
"testheadless": "cross-env HEADLESS=true pnpm testonly",
"test-pack": "TS_NODE_TRANSPILE_ONLY=1 node --loader ts-node/esm scripts/test-pack-package.mts",
"genstats": "cross-env LOCAL_STATS=true node .github/actions/next-stats-action/src/index.js",
"git-reset": "git reset --hard HEAD",
"git-clean": "git clean -d -x -e node_modules -e packages -f",
Expand Down Expand Up @@ -216,6 +217,7 @@
"tailwindcss": "1.1.3",
"taskr": "1.1.0",
"tree-kill": "1.2.2",
"ts-node": "10.9.1",
"tsec": "0.2.1",
"turbo": "1.6.3",
"typescript": "4.8.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"prerelease": "rimraf ./dist/",
"release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"prepublishOnly": "cd ../../ && turbo run build",
"build": "pnpm release"
"build": "pnpm release",
"test-pack": "cd ../../ && pnpm test-pack create-next-app"
},
"devDependencies": {
"@types/async-retry": "1.4.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"url": "vercel/next.js",
"directory": "packages/eslint-config-next"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "13.1.3-canary.4",
"@rushstack/eslint-patch": "^1.1.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"scripts": {
"build": "swc -d dist src",
"prepublishOnly": "cd ../../ && turbo run build"
"prepublishOnly": "cd ../../ && turbo run build",
"test-pack": "cd ../../ && pnpm test-pack eslint-plugin-next"
}
}
3 changes: 2 additions & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "pnpm ncc-fontkit && tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json",
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit"
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit",
"test-pack": "cd ../../ && pnpm test-pack font"
},
"devDependencies": {
"@types/fontkit": "2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
},
"dependencies": {
"webpack-bundle-analyzer": "4.7.0"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack next-bundle-analyzer"
}
}
3 changes: 2 additions & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"build": "pnpm tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "pnpm tsc -d -w -p tsconfig.json",
"test": "jest"
"test": "jest",
"test-pack": "cd ../../ && pnpm test-pack next-codemod"
},
"bin": "./bin/next-codemod.js",
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"types": "tsc index.ts --declaration --emitDeclarationOnly --declarationDir types --esModuleInterop",
"release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"build": "pnpm release && pnpm types",
"prepublishOnly": "cd ../../ && turbo run build"
"prepublishOnly": "cd ../../ && turbo run build",
"test-pack": "cd ../../ && pnpm test-pack next-env"
},
"devDependencies": {
"@vercel/ncc": "0.34.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/next-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"url": "vercel/next.js",
"directory": "packages/next-mdx"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack next-mdx"
},
"peerDependencies": {
"@mdx-js/loader": ">=0.15.0",
"@mdx-js/react": "*"
Expand Down
3 changes: 3 additions & 0 deletions packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack next-plugin-storybook"
},
"peerDependencies": {
"next": "*"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"build": "microbundle -i src/index.js -o dist/polyfill-module.js -f iife --no-sourcemap --external none --no-pkg-main",
"dev": "pnpm build",
"prepublishOnly": "cd ../../ && turbo run build"
"prepublishOnly": "cd ../../ && turbo run build",
"test-pack": "cd ../../ && pnpm test-pack next-polyfill-module"
},
"devDependencies": {
"microbundle": "0.15.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"build": "microbundle -i src/index.js -o dist/polyfill-nomodule.js -f iife --no-sourcemap --external none --no-pkg-main",
"dev": "pnpm build",
"prepublishOnly": "cd ../../ && turbo run build"
"prepublishOnly": "cd ../../ && turbo run build",
"test-pack": "cd ../../ && pnpm test-pack next-polyfill-nomodule"
},
"devDependencies": {
"core-js": "3.6.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build-native-no-plugin": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --js false native",
"build-native-no-plugin-woa": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi --cargo-flags=--no-default-features --features native-tls --js false native",
"build-wasm": "wasm-pack build crates/wasm --scope=next",
"cache-build-native": "echo $(ls native)"
"cache-build-native": "echo $(ls native)",
"test-pack": "cd ../../ && pnpm test-pack next-swc"
},
"napi": {
"name": "next-swc",
Expand Down
3 changes: 2 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"prepublishOnly": "cd ../../ && turbo run build",
"types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"typescript": "tsec --noEmit",
"ncc-compiled": "ncc cache clean && taskr ncc"
"ncc-compiled": "ncc cache clean && taskr ncc",
"test-pack": "cd ../../ && pnpm test-pack next"
},
"taskr": {
"requires": [
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dev-overlay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"build": "rimraf dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"typescript": "tsec --noEmit -p tsconfig.json"
"typescript": "tsec --noEmit -p tsconfig.json",
"test-pack": "cd ../../ && pnpm test-pack react-dev-overlay"
},
"dependencies": {
"@babel/code-frame": "7.12.11",
Expand Down
3 changes: 2 additions & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"scripts": {
"build": "rimraf dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json"
"dev": "tsc -d -w -p tsconfig.json",
"test-pack": "cd ../../ && pnpm test-pack react-refresh-utils"
},
"peerDependencies": {
"react-refresh": "0.12.0",
Expand Down
Loading

0 comments on commit d7307cf

Please sign in to comment.