Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix turbo usage in tests #44715

Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
fede73f
install ts-node
jankaifer Jan 6, 2023
64e5103
start packing things with turbo properly
jankaifer Jan 6, 2023
447de92
fixed repo setup to use new turbo packing
jankaifer Jan 6, 2023
cbd9bc3
refactored repo-setup to use new turbo packing
jankaifer Jan 9, 2023
ac6c164
migrated to mts for scripts
jankaifer Jan 9, 2023
5ae1a2f
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 9, 2023
61a2b18
install execa in next-stats-action
jankaifer Jan 9, 2023
319b629
remove unused temporary directory
jankaifer Jan 9, 2023
7727e95
debug stats action
jankaifer Jan 9, 2023
0ced4e4
wip
jankaifer Jan 9, 2023
a5d6e36
stats move cloned repos out of main project
jankaifer Jan 9, 2023
eb4d7a1
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 9, 2023
1915eae
Merge canary
jankaifer Jan 9, 2023
f05571e
wip
jankaifer Jan 9, 2023
1d5d128
wip
jankaifer Jan 9, 2023
8f3017d
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 9, 2023
53eca02
remove debug file
jankaifer Jan 9, 2023
2552680
fix TYPO in package.json
jankaifer Jan 9, 2023
82116a3
fix __dirname missing
jankaifer Jan 9, 2023
6c5e7d5
wip
jankaifer Jan 9, 2023
72fbabf
fix missing files in package json
jankaifer Jan 9, 2023
ec76c4d
remove logs
jankaifer Jan 9, 2023
838f052
wip
jankaifer Jan 9, 2023
d87c1e3
re-allow using custom swc version in stats action
jankaifer Jan 9, 2023
f95ced4
turbo cache
jankaifer Jan 10, 2023
3f79a9c
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 10, 2023
643112c
wip
jankaifer Jan 10, 2023
f83647e
remove package lock caching
jankaifer Jan 10, 2023
0170a6a
remove unused function
jankaifer Jan 10, 2023
67b310e
remove unused variable
jankaifer Jan 10, 2023
f6c5c0a
wip
jankaifer Jan 10, 2023
3d4b182
wip
jankaifer Jan 10, 2023
5548741
use pnpm for packing
jankaifer Jan 10, 2023
d895e01
fix pnpm tarball result name detection
jankaifer Jan 10, 2023
60353ec
add log to test-pack
jankaifer Jan 10, 2023
8bea837
add some root files as dependencies to test-pack turbo
jankaifer Jan 11, 2023
f27211c
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 11, 2023
104cffd
remove orce from turbo running because we added our scripts aas depen…
jankaifer Jan 11, 2023
0d40bda
migrate back to yarn for now with packing
jankaifer Jan 11, 2023
4b19002
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 11, 2023
bbc3352
improve loging of used swc binaries
jankaifer Jan 11, 2023
944e357
Ignore test/traces which are generated by run-tests.js
jankaifer Jan 11, 2023
f570e31
cleanup linkPackages
jankaifer Jan 11, 2023
b4e7e71
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 12, 2023
6f27a6e
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 17, 2023
21e3b2e
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 17, 2023
d0168cf
lint
jankaifer Jan 17, 2023
2c6fbdf
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 18, 2023
068161a
Merge branch 'canary' into jankaifer/next-344-try-rethinking-turbo-us…
jankaifer Jan 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant that the package has to pass the name. Can we update the script to derive the current package by reading process.cwd() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I dig into it. And I would need to repeat that ts-node magical initialization.
Not worth it. But good point.

},
"dependencies": {
"@next/eslint-plugin-next": "13.1.3-canary.1",
"@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