diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 21ad117508bd..2f2895e76eff 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -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 }, } } diff --git a/.gitignore b/.gitignore index 68e8a1376822..59c5d0241526 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ dist .next target packages/next/wasm/@next -packages/*/packed-*.tgz # dependencies node_modules diff --git a/package.json b/package.json index 75bf9e347f81..c2ec00ff4d7d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/create-next-app/package.json b/packages/create-next-app/package.json index 4c3d464eb724..e83f4f1fa3d3 100644 --- a/packages/create-next-app/package.json +++ b/packages/create-next-app/package.json @@ -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": { diff --git a/packages/eslint-config-next/package.json b/packages/eslint-config-next/package.json index fec829f68959..7c90b1095a40 100644 --- a/packages/eslint-config-next/package.json +++ b/packages/eslint-config-next/package.json @@ -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", diff --git a/packages/eslint-plugin-next/package.json b/packages/eslint-plugin-next/package.json index 095c4cddecdb..2fe713cec7d1 100644 --- a/packages/eslint-plugin-next/package.json +++ b/packages/eslint-plugin-next/package.json @@ -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" } } diff --git a/packages/font/package.json b/packages/font/package.json index abffa7cea2f0..3d86bb9cb6bf 100644 --- a/packages/font/package.json +++ b/packages/font/package.json @@ -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", diff --git a/packages/next-bundle-analyzer/package.json b/packages/next-bundle-analyzer/package.json index 24181f2078ac..ab5d31d6309b 100644 --- a/packages/next-bundle-analyzer/package.json +++ b/packages/next-bundle-analyzer/package.json @@ -10,8 +10,5 @@ }, "dependencies": { "webpack-bundle-analyzer": "4.7.0" - }, - "scripts": { - "test-pack": "cd ../../ && pnpm test-pack next-bundle-analyzer" } } diff --git a/packages/next-codemod/package.json b/packages/next-codemod/package.json index affd7df06a2b..050eeb3a375b 100644 --- a/packages/next-codemod/package.json +++ b/packages/next-codemod/package.json @@ -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": { diff --git a/packages/next-env/package.json b/packages/next-env/package.json index eeded75473f2..1f6bd28e5aa3 100644 --- a/packages/next-env/package.json +++ b/packages/next-env/package.json @@ -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", diff --git a/packages/next-mdx/package.json b/packages/next-mdx/package.json index d66a68983e71..5dc4ab354d67 100644 --- a/packages/next-mdx/package.json +++ b/packages/next-mdx/package.json @@ -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" diff --git a/packages/next-plugin-storybook/package.json b/packages/next-plugin-storybook/package.json index d26a1549db32..32bb1784dfc1 100644 --- a/packages/next-plugin-storybook/package.json +++ b/packages/next-plugin-storybook/package.json @@ -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": "*" } diff --git a/packages/next-polyfill-module/package.json b/packages/next-polyfill-module/package.json index 85efee6e214f..6b8a1a31e4a1 100644 --- a/packages/next-polyfill-module/package.json +++ b/packages/next-polyfill-module/package.json @@ -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" diff --git a/packages/next-polyfill-nomodule/package.json b/packages/next-polyfill-nomodule/package.json index 529833e4d743..40895a3599f7 100644 --- a/packages/next-polyfill-nomodule/package.json +++ b/packages/next-polyfill-nomodule/package.json @@ -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", diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index 9ca36c228dc6..fd7cc7ff7eb3 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -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", diff --git a/packages/next/package.json b/packages/next/package.json index 217fad4ef3b1..01214d85470c 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -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": [ diff --git a/packages/react-dev-overlay/package.json b/packages/react-dev-overlay/package.json index 8f3b6acd09f1..c6d4ee4292c4 100644 --- a/packages/react-dev-overlay/package.json +++ b/packages/react-dev-overlay/package.json @@ -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", diff --git a/packages/react-refresh-utils/package.json b/packages/react-refresh-utils/package.json index 044e965bba28..ea6e9620dead 100644 --- a/packages/react-refresh-utils/package.json +++ b/packages/react-refresh-utils/package.json @@ -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", diff --git a/scripts/test-pack-package.mts b/scripts/test-pack-package.mts deleted file mode 100755 index 18863c3d03f6..000000000000 --- a/scripts/test-pack-package.mts +++ /dev/null @@ -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() diff --git a/turbo.json b/turbo.json index 87695181694d..21c50734074e 100644 --- a/turbo.json +++ b/turbo.json @@ -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": {} } }