mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
c11ff2b8e3
## Convert unpack-next.cjs to TypeScript ### What? Converted `scripts/unpack-next.cjs` to TypeScript, renaming it to `scripts/unpack-next.ts` and updating the imports and type definitions. ### Why? This change continues the ongoing TypeScript migration efforts in the codebase, providing better type safety and developer experience. ### How? - Renamed file from `.cjs` to `.ts` - Converted CommonJS `require()` statements to ES module `import` statements - Added type annotation for the `path` parameter in the `realPathIfAny` function Fixes #
31 lines
811 B
TypeScript
Executable File
31 lines
811 B
TypeScript
Executable File
// This script must be run with tsx
|
|
|
|
import { NEXT_DIR, exec } from './pack-util'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
const TARBALLS = `${NEXT_DIR}/tarballs`
|
|
|
|
const PROJECT_DIR = path.resolve(process.argv[2])
|
|
|
|
function realPathIfAny(path: fs.PathLike) {
|
|
try {
|
|
return fs.realpathSync(path)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
const packages = {
|
|
next: realPathIfAny(`${PROJECT_DIR}/node_modules/next`),
|
|
'next-swc': realPathIfAny(`${PROJECT_DIR}/node_modules/@next/swc`),
|
|
'next-mdx': realPathIfAny(`${PROJECT_DIR}/node_modules/@next/mdx`),
|
|
'next-bundle-analyzer': realPathIfAny(
|
|
`${PROJECT_DIR}/node_modules/@next/bundle-anlyzer`
|
|
),
|
|
}
|
|
|
|
for (const [key, path] of Object.entries(packages)) {
|
|
if (!path) continue
|
|
exec(`Unpack ${key}`, `tar -xf '${TARBALLS}/${key}.tar' -C '${path}'`)
|
|
}
|