Remove unused code from test-pack turbo task (#48487)

We decided in https://github.com/vercel/next.js/pull/48308 that we won't
use `turbo` when packing packages for tests.

This PR removes all code associated with that effort. The whole thing
fas behind a flag, so it shouldn't affect anything.
fix NEXT-1025
This commit is contained in:
Jan Kaifer 2023-04-18 14:12:00 +02:00 committed by GitHub
parent 12472b4c60
commit 902bb40454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 101 additions and 278 deletions

View file

@ -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)
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 = []
}
// 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,
})
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
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'
pkgData.files.push('native/*')
require('console').log(
'using swc binaries: ',
await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`)
)
}
// 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,
if (pkg === 'next') {
if (nextSwcVersion) {
Object.assign(pkgData.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
await fs.copyFile(tmpTarball, packedPkgPath)
})
)
} else {
if (pkgDatas.get('@next/swc')) {
pkgData.dependencies['@next/swc'] =
pkgDatas.get('@next/swc').packedPkgPath
} else {
pkgData.files.push('native/*')
}
}
}
return pkgPaths
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'
)
}
// 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
.gitignore vendored
View file

@ -3,7 +3,6 @@ dist
.next
target
packages/next/wasm/@next
packages/*/packed-*.tgz
# dependencies
node_modules

View file

@ -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",

View file

@ -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": {

View file

@ -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.12",
"@rushstack/eslint-patch": "^1.1.3",

View file

@ -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"
}
}

View file

@ -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",

View file

@ -10,8 +10,5 @@
},
"dependencies": {
"webpack-bundle-analyzer": "4.7.0"
},
"scripts": {
"test-pack": "cd ../../ && pnpm test-pack next-bundle-analyzer"
}
}

View file

@ -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": {

View file

@ -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",

View file

@ -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"

View file

@ -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": "*"
}

View file

@ -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"

View file

@ -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",

View file

@ -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",

View file

@ -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": [

View file

@ -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",

View file

@ -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",

View file

@ -1,108 +0,0 @@
import path from 'path'
import fs from 'fs-extra'
import os from 'os'
import execa from 'execa'
import { randomBytes } from 'crypto'
import { fileURLToPath } from 'url'
const main = async () => {
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const repoRoot = path.dirname(__dirname)
const pkgsDir = path.join(repoRoot, 'packages')
const currentPkgDirname = process.argv[2]
const getPackedPkgPath = (pkgDirname: string) =>
path.join(pkgsDir, pkgDirname, `packed-${pkgDirname}.tgz`)
const getPackageJsonPath = (pkgDirname: string) =>
path.join(pkgsDir, pkgDirname, `package.json`)
const allPkgDirnames = (await fs.readdir(pkgsDir)).filter(
(item) => !item.startsWith('.')
)
if (!allPkgDirnames.includes(currentPkgDirname)) {
throw new Error(`Unknown package '${currentPkgDirname}'`)
}
const currentPkgDir = path.join(pkgsDir, currentPkgDirname)
const tmpPkgPath = path.join(
os.tmpdir(),
`${currentPkgDirname}-${randomBytes(32).toString('hex')}`
)
console.log(`Packing '${currentPkgDirname}' in '${tmpPkgPath}'.`)
const packageJsonPath = getPackageJsonPath(currentPkgDirname)
const packageJson = await fs.readJson(packageJsonPath)
const dependencies = packageJson.dependencies
if (packageJson?.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 packageJson.scripts.prepublishOnly
}
// @next/swc is devDependency in next, but we want to include it anyway
if (currentPkgDirname === 'next') {
dependencies['@next/swc'] = '*'
}
// Modify dependencies to point to packed packages
if (dependencies) {
await Promise.all(
allPkgDirnames.map(async (depPkgDirname) => {
const { name: depPkgName } = await fs.readJson(
getPackageJsonPath(depPkgDirname)
)
if (depPkgName in dependencies) {
dependencies[depPkgName] = getPackedPkgPath(depPkgDirname)
}
})
)
}
// Ensure that we bundle binaries with swc
if (currentPkgDirname === 'next-swc') {
packageJson.files = packageJson.files ?? []
packageJson.files.push('native/*')
console.log('using swc binaries:')
await execa('ls', [
path.join(path.dirname(packageJsonPath), 'native'),
]).stdout?.pipe(process.stdout)
}
// Allow overriding nateve swc version in next
if (currentPkgDirname === 'next' && process.env.NEXT_SWC_VERSION) {
dependencies['@next/swc-linux-x64-gnu'] = process.env.NEXT_SWC_VERSION
}
try {
await fs.copy(currentPkgDir, tmpPkgPath, {
filter: (item) =>
!item.includes('node_modules') &&
!item.includes('.DS_Store') &&
// Exclude Rust compilation files
(currentPkgDirname !== 'next' ||
!/build[\\/]swc[\\/]target/.test(item)) &&
(currentPkgDirname !== 'next-swc' || !/target/.test(item)),
})
await fs.writeJson(path.join(tmpPkgPath, 'package.json'), packageJson)
// Copied from pnpm source: https://github.com/pnpm/pnpm/blob/5a5512f14c47f4778b8d2b6d957fb12c7ef40127/releasing/plugin-commands-publishing/src/pack.ts#L96
const tmpTarball = path.join(
tmpPkgPath,
`${packageJson.name.replace('@', '').replace('/', '-')}-${
packageJson.version
}.tgz`
)
await execa('pnpm', ['pack'], {
cwd: tmpPkgPath,
})
await fs.copyFile(tmpTarball, getPackedPkgPath(currentPkgDirname))
} finally {
await fs.remove(tmpPkgPath).catch()
}
}
main()

View file

@ -29,15 +29,6 @@
"dependsOn": ["^dev"],
"outputs": ["dist/**"]
},
"typescript": {},
"test-pack": {
"dependsOn": ["^test-pack", "test-pack-global-deps"],
"outputs": ["packed-*.tgz"],
"env": ["NEXT_SWC_VERSION"]
},
"test-pack-global-deps": {
"inputs": ["../../scripts/test-pack-package.mts", "../../package.json"],
"cache": false
}
"typescript": {}
}
}