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

Remove unused code from test-pack turbo task #48487

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
209 changes: 87 additions & 122 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Expand Up @@ -55,146 +55,111 @@ module.exports = (actionInfo) => {
}
},
async linkPackages({ repoDir, nextSwcVersion }) {
let useTestPack = process.env.NEXT_TEST_PACK
const pkgPaths = new Map()
const pkgDatas = new Map()
let pkgs

if (useTestPack) {
execa.sync('pnpm', ['turbo', 'run', 'test-pack'], {
cwd: repoDir,
env: { NEXT_SWC_VERSION: nextSwcVersion },
})

const pkgPaths = new Map()
const pkgs = (await fs.readdir(path.join(repoDir, 'packages'))).filter(
(item) => !item.startsWith('.')
)

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
} else {
// TODO: remove after next stable release (current v13.1.2)
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
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
}

for (const pkg of pkgs) {
const pkgPath = path.join(repoDir, 'packages', pkg)
const packedPkgPath = path.join(pkgPath, `${pkg}-packed.tgz`)
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)
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 { 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
}
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')}`)
)
// 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 (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
if (pkg === 'next') {
if (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native/*')
}
pkgData.files.push('native/*')
}
}
}

if (pkgData?.scripts?.prepublishOnly) {
// There's a bug in `pnpm pack` where it will run
// the prepublishOnly script and that will fail.
// See https://github.com/pnpm/pnpm/issues/2941
delete pkgData.scripts.prepublishOnly
}

await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)
if (pkgData?.scripts?.prepublishOnly) {
// There's a bug in `pnpm pack` where it will run
// the prepublishOnly script and that will fail.
// See https://github.com/pnpm/pnpm/issues/2941
delete pkgData.scripts.prepublishOnly
}

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath, pkgData, packedPkgPath } =
pkgDatas.get(pkgName)
// Copied from pnpm source: https://github.com/pnpm/pnpm/blob/5a5512f14c47f4778b8d2b6d957fb12c7ef40127/releasing/plugin-commands-publishing/src/pack.ts#L96
const tmpTarball = path.join(
pkgPath,
`${pkgData.name.replace('@', '').replace('/', '-')}-${
pkgData.version
}.tgz`
)
await execa('pnpm', ['pack'], {
cwd: pkgPath,
})
await fs.copyFile(tmpTarball, packedPkgPath)
})
await fs.writeFile(
pkgDataPath,
JSON.stringify(pkgData, null, 2),
'utf8'
)

return pkgPaths
}

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.keys()).map(async (pkgName) => {
const { pkg, pkgPath, pkgData, packedPkgPath } = pkgDatas.get(pkgName)
// Copied from pnpm source: https://github.com/pnpm/pnpm/blob/5a5512f14c47f4778b8d2b6d957fb12c7ef40127/releasing/plugin-commands-publishing/src/pack.ts#L96
const tmpTarball = path.join(
pkgPath,
`${pkgData.name.replace('@', '').replace('/', '-')}-${
pkgData.version
}.tgz`
)
await execa('pnpm', ['pack'], {
cwd: pkgPath,
})
await fs.copyFile(tmpTarball, packedPkgPath)
})
)

return pkgPaths
},
}
}
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -3,7 +3,6 @@ dist
.next
target
packages/next/wasm/@next
packages/*/packed-*.tgz

# dependencies
node_modules
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,6 @@
"test": "pnpm testheadless",
"testonly": "jest --runInBand",
"testheadless": "cross-env HEADLESS=true pnpm testonly",
"test-pack": "cross-env 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
1 change: 0 additions & 1 deletion packages/create-next-app/package.json
Expand Up @@ -26,7 +26,6 @@
"release": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"prepublishOnly": "cd ../../ && turbo run build",
"build": "pnpm release",
"test-pack": "cd ../../ && pnpm test-pack create-next-app",
"lint-fix": "pnpm prettier -w --plugin prettier-plugin-tailwindcss 'templates/*-tw/{ts,js}/{app,pages}/**/*.{js,ts,tsx}'"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions packages/eslint-config-next/package.json
Expand Up @@ -8,9 +8,6 @@
"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.3.1-canary.9",
"@rushstack/eslint-patch": "^1.1.3",
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-next/package.json
Expand Up @@ -20,7 +20,6 @@
},
"scripts": {
"build": "swc -d dist src",
"prepublishOnly": "cd ../../ && turbo run build",
"test-pack": "cd ../../ && pnpm test-pack eslint-plugin-next"
"prepublishOnly": "cd ../../ && turbo run build"
}
}
3 changes: 1 addition & 2 deletions packages/font/package.json
Expand Up @@ -17,8 +17,7 @@
"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",
"test-pack": "cd ../../ && pnpm test-pack font"
"ncc-fontkit": "ncc build ./fontkit.js -o dist/fontkit"
},
"devDependencies": {
"@types/fontkit": "2.0.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/next-bundle-analyzer/package.json
Expand Up @@ -10,8 +10,5 @@
},
"dependencies": {
"webpack-bundle-analyzer": "4.7.0"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack next-bundle-analyzer"
}
}
3 changes: 1 addition & 2 deletions packages/next-codemod/package.json
Expand Up @@ -27,8 +27,7 @@
"build": "pnpm tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "pnpm tsc -d -w -p tsconfig.json",
"test": "jest",
"test-pack": "cd ../../ && pnpm test-pack next-codemod"
"test": "jest"
},
"bin": "./bin/next-codemod.js",
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/next-env/package.json
Expand Up @@ -26,8 +26,7 @@
"types": "tsc index.ts --declaration --emitDeclarationOnly --declarationDir dist --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",
"test-pack": "cd ../../ && pnpm test-pack next-env"
"prepublishOnly": "cd ../../ && turbo run build"
},
"devDependencies": {
"@vercel/ncc": "0.34.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/next-mdx/package.json
Expand Up @@ -7,9 +7,6 @@
"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": ">=0.15.0"
Expand Down
3 changes: 0 additions & 3 deletions packages/next-plugin-storybook/package.json
Expand Up @@ -5,9 +5,6 @@
"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: 1 addition & 2 deletions packages/next-polyfill-module/package.json
Expand Up @@ -11,8 +11,7 @@
"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",
"test-pack": "cd ../../ && pnpm test-pack next-polyfill-module"
"prepublishOnly": "cd ../../ && turbo run build"
},
"devDependencies": {
"microbundle": "0.15.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/next-polyfill-nomodule/package.json
Expand Up @@ -11,8 +11,7 @@
"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",
"test-pack": "cd ../../ && pnpm test-pack next-polyfill-nomodule"
"prepublishOnly": "cd ../../ && turbo run build"
},
"devDependencies": {
"core-js": "3.6.5",
Expand Down
3 changes: 1 addition & 2 deletions packages/next-swc/package.json
Expand Up @@ -9,8 +9,7 @@
"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)",
"test-pack": "cd ../../ && pnpm test-pack next-swc"
"cache-build-native": "echo $(ls native)"
},
"napi": {
"name": "next-swc",
Expand Down
3 changes: 1 addition & 2 deletions packages/next/package.json
Expand Up @@ -71,8 +71,7 @@
"prepublishOnly": "cd ../../ && turbo run build",
"types": "tsc --declaration --emitDeclarationOnly --stripInternal --declarationDir dist",
"typescript": "tsec --noEmit",
"ncc-compiled": "ncc cache clean && taskr ncc",
"test-pack": "cd ../../ && pnpm test-pack next"
"ncc-compiled": "ncc cache clean && taskr ncc"
},
"taskr": {
"requires": [
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dev-overlay/package.json
Expand Up @@ -15,8 +15,7 @@
"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",
"test-pack": "cd ../../ && pnpm test-pack react-dev-overlay"
"typescript": "tsec --noEmit -p tsconfig.json"
},
"dependencies": {
"@babel/code-frame": "7.12.11",
Expand Down
3 changes: 1 addition & 2 deletions packages/react-refresh-utils/package.json
Expand Up @@ -14,8 +14,7 @@
"scripts": {
"build": "rimraf dist && tsc -d -p tsconfig.json",
"prepublishOnly": "cd ../../ && turbo run build",
"dev": "tsc -d -w -p tsconfig.json",
"test-pack": "cd ../../ && pnpm test-pack react-refresh-utils"
"dev": "tsc -d -w -p tsconfig.json"
},
"peerDependencies": {
"react-refresh": "0.12.0",
Expand Down