Skip to content

Commit d7307cf

Browse files
authored
Fix turbo usage in tests (#44715)
1 parent ad48202 commit d7307cf

File tree

27 files changed

+301
-259
lines changed

27 files changed

+301
-259
lines changed

.github/actions/next-stats-action/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"main": "src/index.js",
44
"dependencies": {
55
"async-sema": "^3.1.0",
6+
"execa": "2.0.3",
67
"fs-extra": "^8.1.0",
78
"get-port": "^5.0.0",
89
"glob": "^7.1.4",

.github/actions/next-stats-action/src/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const benchTitle = 'Page Load Tests'
55
const workDir = path.join(os.tmpdir(), 'next-stats')
66
const mainRepoName = 'main-repo'
77
const diffRepoName = 'diff-repo'
8-
const mainRepoDir = path.join(workDir, mainRepoName)
9-
const diffRepoDir = path.join(workDir, diffRepoName)
8+
const mainRepoDir = path.join(os.tmpdir(), mainRepoName)
9+
const diffRepoDir = path.join(os.tmpdir(), diffRepoName)
1010
const statsAppDir = path.join(workDir, 'stats-app')
1111
const diffingDir = path.join(workDir, 'diff')
1212
const yarnEnvValues = {

.github/actions/next-stats-action/src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
7878
if (actionInfo.isRelease) {
7979
logger('Release detected, resetting mainRepo to last stable tag')
8080
const lastStableTag = await getLastStable(mainRepoDir, actionInfo.prRef)
81-
mainNextSwcVersion = {
82-
'@next/swc-linux-x64-gnu': lastStableTag,
83-
}
81+
mainNextSwcVersion = lastStableTag
8482
if (!lastStableTag) throw new Error('failed to get last stable tag')
8583
console.log('using latestStable', lastStableTag)
8684
await checkoutRef(lastStableTag, mainRepoDir)
@@ -140,7 +138,7 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
140138
const isMainRepo = dir === mainRepoDir
141139
const pkgPaths = await linkPackages({
142140
repoDir: dir,
143-
nextSwcPkg: isMainRepo ? mainNextSwcVersion : undefined,
141+
nextSwcVersion: isMainRepo ? mainNextSwcVersion : undefined,
144142
})
145143

146144
if (isMainRepo) mainRepoPkgPaths = pkgPaths

.github/actions/next-stats-action/src/prepare/repo-setup.js

Lines changed: 21 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const exec = require('../util/exec')
44
const { remove } = require('fs-extra')
55
const logger = require('../util/logger')
66
const semver = require('semver')
7-
8-
const mockTrace = () => ({
9-
traceAsyncFn: (fn) => fn(mockTrace()),
10-
traceChild: () => mockTrace(),
11-
})
7+
const execa = require('execa')
128

139
module.exports = (actionInfo) => {
1410
return {
@@ -58,117 +54,28 @@ module.exports = (actionInfo) => {
5854
}
5955
}
6056
},
61-
async linkPackages({ repoDir = '', nextSwcPkg, parentSpan }) {
62-
const rootSpan = parentSpan
63-
? parentSpan.traceChild('linkPackages')
64-
: mockTrace()
65-
66-
return await rootSpan.traceAsyncFn(async () => {
67-
const pkgPaths = new Map()
68-
const pkgDatas = new Map()
69-
let pkgs
70-
71-
try {
72-
pkgs = await fs.readdir(path.join(repoDir, 'packages'))
73-
} catch (err) {
74-
if (err.code === 'ENOENT') {
75-
require('console').log('no packages to link')
76-
return pkgPaths
77-
}
78-
throw err
79-
}
80-
81-
await rootSpan
82-
.traceChild('prepare packages for packing')
83-
.traceAsyncFn(async () => {
84-
for (const pkg of pkgs) {
85-
const pkgPath = path.join(repoDir, 'packages', pkg)
86-
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
87-
88-
const pkgDataPath = path.join(pkgPath, 'package.json')
89-
if (!fs.existsSync(pkgDataPath)) {
90-
require('console').log(`Skipping ${pkgDataPath}`)
91-
continue
92-
}
93-
const pkgData = require(pkgDataPath)
94-
const { name } = pkgData
95-
pkgDatas.set(name, {
96-
pkgDataPath,
97-
pkg,
98-
pkgPath,
99-
pkgData,
100-
packedPkgPath,
101-
})
102-
pkgPaths.set(name, packedPkgPath)
103-
}
104-
105-
for (const pkg of pkgDatas.keys()) {
106-
const { pkgDataPath, pkgData } = pkgDatas.get(pkg)
107-
108-
for (const pkg of pkgDatas.keys()) {
109-
const { packedPkgPath } = pkgDatas.get(pkg)
110-
if (!pkgData.dependencies || !pkgData.dependencies[pkg])
111-
continue
112-
pkgData.dependencies[pkg] = packedPkgPath
113-
}
114-
115-
// make sure native binaries are included in local linking
116-
if (pkg === '@next/swc') {
117-
if (!pkgData.files) {
118-
pkgData.files = []
119-
}
120-
pkgData.files.push('native')
121-
require('console').log(
122-
'using swc binaries: ',
123-
await exec(
124-
`ls ${path.join(path.dirname(pkgDataPath), 'native')}`
125-
)
126-
)
127-
}
128-
129-
if (pkg === 'next') {
130-
if (nextSwcPkg) {
131-
Object.assign(pkgData.dependencies, nextSwcPkg)
132-
} else {
133-
if (pkgDatas.get('@next/swc')) {
134-
pkgData.dependencies['@next/swc'] =
135-
pkgDatas.get('@next/swc').packedPkgPath
136-
} else {
137-
pkgData.files.push('native')
138-
}
139-
}
140-
}
141-
142-
await fs.writeFile(
143-
pkgDataPath,
144-
JSON.stringify(pkgData, null, 2),
145-
'utf8'
146-
)
147-
}
148-
})
149-
150-
// wait to pack packages until after dependency paths have been updated
151-
// to the correct versions
152-
await rootSpan
153-
.traceChild('packing packages')
154-
.traceAsyncFn(async (packingSpan) => {
155-
await Promise.all(
156-
Array.from(pkgDatas.keys()).map(async (pkgName) => {
157-
await packingSpan
158-
.traceChild(`pack ${pkgName}`)
159-
.traceAsyncFn(async () => {
160-
const { pkg, pkgPath } = pkgDatas.get(pkgName)
161-
await exec(
162-
`cd ${pkgPath} && yarn pack -f '${pkg}-packed.tgz'`,
163-
true
164-
)
165-
})
166-
})
167-
)
168-
})
57+
async linkPackages({ repoDir, nextSwcVersion }) {
58+
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
59+
cwd: repoDir,
60+
env: { NEXT_SWC_VERSION: nextSwcVersion },
61+
})
16962

170-
return pkgPaths
63+
const pkgPaths = new Map()
64+
const pkgs = await fs.readdir(path.join(repoDir, 'packages'))
65+
66+
pkgs.forEach((pkgDirname) => {
67+
const { name } = require(path.join(
68+
repoDir,
69+
'packages',
70+
pkgDirname,
71+
'package.json'
72+
))
73+
pkgPaths.set(
74+
name,
75+
path.join(repoDir, 'packages', pkgDirname, `packed-${pkgDirname}.tgz`)
76+
)
17177
})
78+
return pkgPaths
17279
},
17380
}
17481
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ dist
33
.next
44
target
55
packages/next/wasm/@next
6+
packages/*/packed-*.tgz
67

78
# dependencies
89
node_modules
@@ -29,6 +30,7 @@ test/**/tsconfig.json
2930
/e2e-tests
3031
test/tmp/**
3132
test/.trace
33+
test/traces
3234

3335
# Editors
3436
**/.idea
@@ -49,3 +51,4 @@ test-timings.json
4951
# Cache
5052
*.tsbuildinfo
5153
.swc/
54+
.turbo

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test": "pnpm testheadless",
2424
"testonly": "pnpm jest --runInBand",
2525
"testheadless": "cross-env HEADLESS=true pnpm testonly",
26+
"test-pack": "TS_NODE_TRANSPILE_ONLY=1 node --loader ts-node/esm scripts/test-pack-package.mts",
2627
"genstats": "cross-env LOCAL_STATS=true node .github/actions/next-stats-action/src/index.js",
2728
"git-reset": "git reset --hard HEAD",
2829
"git-clean": "git clean -d -x -e node_modules -e packages -f",
@@ -216,6 +217,7 @@
216217
"tailwindcss": "1.1.3",
217218
"taskr": "1.1.0",
218219
"tree-kill": "1.2.2",
220+
"ts-node": "10.9.1",
219221
"tsec": "0.2.1",
220222
"turbo": "1.6.3",
221223
"typescript": "4.8.2",

packages/create-next-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"prerelease": "rimraf ./dist/",
2626
"release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
2727
"prepublishOnly": "cd ../../ && turbo run build",
28-
"build": "pnpm release"
28+
"build": "pnpm release",
29+
"test-pack": "cd ../../ && pnpm test-pack create-next-app"
2930
},
3031
"devDependencies": {
3132
"@types/async-retry": "1.4.2",

packages/eslint-config-next/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"url": "vercel/next.js",
99
"directory": "packages/eslint-config-next"
1010
},
11+
"scripts": {
12+
"test-pack": "cd ../../ && pnpm test-pack eslint-config-next"
13+
},
1114
"dependencies": {
1215
"@next/eslint-plugin-next": "13.1.3-canary.4",
1316
"@rushstack/eslint-patch": "^1.1.3",

packages/eslint-plugin-next/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"scripts": {
2222
"build": "swc -d dist src",
23-
"prepublishOnly": "cd ../../ && turbo run build"
23+
"prepublishOnly": "cd ../../ && turbo run build",
24+
"test-pack": "cd ../../ && pnpm test-pack eslint-plugin-next"
2425
}
2526
}

packages/font/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"prepublishOnly": "cd ../../ && turbo run build",
1818
"dev": "pnpm ncc-fontkit && tsc -d -w -p tsconfig.json",
1919
"typescript": "tsec --noEmit -p tsconfig.json",
20-
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit"
20+
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit",
21+
"test-pack": "cd ../../ && pnpm test-pack font"
2122
},
2223
"devDependencies": {
2324
"@types/fontkit": "2.0.0",

0 commit comments

Comments
 (0)