Skip to content

Commit

Permalink
Merge branch 'canary' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
samijaber authored Apr 24, 2024
2 parents 016e62b + 909789a commit 5074d88
Show file tree
Hide file tree
Showing 305 changed files with 3,409 additions and 1,478 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/2.example_bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Bug Report for Examples
description: Create a bug report for one of the Next.js examples
labels: ['example bug']
labels: ['examples']
body:
- type: markdown
attributes:
Expand Down
320 changes: 178 additions & 142 deletions .github/actions/next-stats-action/src/prepare/repo-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const exec = require('../util/exec')
const logger = require('../util/logger')
const execa = require('execa')

const mockSpan = () => ({
traceAsyncFn: (fn) => fn(mockSpan()),
traceFn: (fn) => fn(mockSpan()),
traceChild: () => mockSpan(),
})

module.exports = (actionInfo) => {
return {
async cloneRepo(repoPath = '', dest = '', branch = '', depth = '20') {
Expand Down Expand Up @@ -59,7 +65,11 @@ module.exports = (actionInfo) => {
* @param {{ repoDir: string, nextSwcVersion: null | string }} options Required options
* @returns {Promise<Map<string, string>>} List packages key is the package name, value is the path to the packed tar file.'
*/
async linkPackages({ repoDir, nextSwcVersion }) {
async linkPackages({ repoDir, nextSwcVersion, parentSpan }) {
if (!parentSpan) {
// Not all callers provide a parent span
parentSpan = mockSpan()
}
/** @type {Map<string, string>} */
const pkgPaths = new Map()
/** @type {Map<string, { packageJsonPath: string, packagePath: string, packageJson: any, packedPackageTarPath: string }>} */
Expand All @@ -68,9 +78,11 @@ module.exports = (actionInfo) => {
let packageFolders

try {
packageFolders = await fs.promises.readdir(
path.join(repoDir, 'packages')
)
packageFolders = await parentSpan
.traceChild('read-packages-folder')
.traceAsyncFn(() =>
fs.promises.readdir(path.join(repoDir, 'packages'))
)
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('no packages to link')
Expand All @@ -79,162 +91,186 @@ module.exports = (actionInfo) => {
throw err
}

for (const packageFolder of packageFolders) {
const packagePath = path.join(repoDir, 'packages', packageFolder)
const packedPackageTarPath = path.join(
packagePath,
`${packageFolder}-packed.tgz`
)
const packageJsonPath = path.join(packagePath, 'package.json')

if (!existsSync(packageJsonPath)) {
require('console').log(`Skipping ${packageFolder}, no package.json`)
continue
}
parentSpan.traceChild('get-pkgdatas').traceFn(() => {
for (const packageFolder of packageFolders) {
const packagePath = path.join(repoDir, 'packages', packageFolder)
const packedPackageTarPath = path.join(
packagePath,
`${packageFolder}-packed.tgz`
)
const packageJsonPath = path.join(packagePath, 'package.json')

const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
const { name: packageName } = packageJson
if (!existsSync(packageJsonPath)) {
require('console').log(`Skipping ${packageFolder}, no package.json`)
continue
}

pkgDatas.set(packageName, {
packageJsonPath,
packagePath,
packageJson,
packedPackageTarPath,
})
pkgPaths.set(packageName, packedPackageTarPath)
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
const { name: packageName } = packageJson

for (const [
packageName,
{ packageJsonPath, packagePath, packageJson },
] of pkgDatas.entries()) {
// This loops through all items to get the packagedPkgPath of each item and add it to pkgData.dependencies
for (const [
packageName,
{ packedPackageTarPath },
] of pkgDatas.entries()) {
if (
!packageJson.dependencies ||
!packageJson.dependencies[packageName]
)
continue
// Edit the pkgData of the current item to point to the packed tgz
packageJson.dependencies[packageName] = packedPackageTarPath
pkgDatas.set(packageName, {
packageJsonPath,
packagePath,
packageJson,
packedPackageTarPath,
})
pkgPaths.set(packageName, packedPackageTarPath)
}
})

// make sure native binaries are included in local linking
if (packageName === '@next/swc') {
packageJson.files ||= []
await parentSpan
.traceChild('write-packagejson')
.traceAsyncFn(async () => {
for (const [
packageName,
{ packageJsonPath, packagePath, packageJson },
] of pkgDatas.entries()) {
// This loops through all items to get the packagedPkgPath of each item and add it to pkgData.dependencies
for (const [
packageName,
{ packedPackageTarPath },
] of pkgDatas.entries()) {
if (
!packageJson.dependencies ||
!packageJson.dependencies[packageName]
)
continue
// Edit the pkgData of the current item to point to the packed tgz
packageJson.dependencies[packageName] = packedPackageTarPath
}

packageJson.files.push('native')
// make sure native binaries are included in local linking
if (packageName === '@next/swc') {
packageJson.files ||= []

try {
const swcBinariesDirContents = (
await fs.promises.readdir(path.join(packagePath, 'native'))
).filter((file) => file !== '.gitignore' && file !== 'index.d.ts')
packageJson.files.push('native')

require('console').log(
'using swc binaries: ',
swcBinariesDirContents.join(', ')
)
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('swc binaries dir is missing!')
}
throw err
}
} else if (packageName === 'next') {
const nextSwcPkg = pkgDatas.get('@next/swc')
try {
const swcBinariesDirContents = (
await fs.promises.readdir(path.join(packagePath, 'native'))
).filter(
(file) => file !== '.gitignore' && file !== 'index.d.ts'
)

console.log('using swc dep', {
nextSwcVersion,
nextSwcPkg,
})
if (nextSwcVersion) {
Object.assign(packageJson.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
if (nextSwcPkg) {
packageJson.dependencies['@next/swc'] =
nextSwcPkg.packedPackageTarPath
require('console').log(
'using swc binaries: ',
swcBinariesDirContents.join(', ')
)
} catch (err) {
if (err.code === 'ENOENT') {
require('console').log('swc binaries dir is missing!')
}
throw err
}
} else if (packageName === 'next') {
const nextSwcPkg = pkgDatas.get('@next/swc')

console.log('using swc dep', {
nextSwcVersion,
nextSwcPkg,
})
if (nextSwcVersion) {
Object.assign(packageJson.dependencies, {
'@next/swc-linux-x64-gnu': nextSwcVersion,
})
} else {
}
}

await fs.promises.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
'utf8'
)
}
}
})

await fs.promises.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2),
'utf8'
)
}
await parentSpan
.traceChild('pnpm-packing')
.traceAsyncFn(async (packingSpan) => {
// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.entries()).map(
async ([
packageName,
{ packagePath: pkgPath, packedPackageTarPath: packedPkgPath },
]) => {
return packingSpan
.traceChild('handle-package', { packageName })
.traceAsyncFn(async (handlePackageSpan) => {
/** @type {null | () => Promise<void>} */
let cleanup = null

// wait to pack packages until after dependency paths have been updated
// to the correct versions
await Promise.all(
Array.from(pkgDatas.entries()).map(
async ([
packageName,
{ packagePath: pkgPath, packedPackageTarPath: packedPkgPath },
]) => {
/** @type {null | () => Promise<void>} */
let cleanup = null
if (packageName === '@next/swc') {
// next-swc uses a gitignore to prevent the committing of native builds but it doesn't
// use files in package.json because it publishes to individual packages based on architecture.
// When we used yarn to pack these packages the gitignore was ignored so the native builds were packed
// however npm does respect gitignore when packing so we need to remove it in this specific case
// to ensure the native builds are packed for use in gh actions and related scripts

if (packageName === '@next/swc') {
// next-swc uses a gitignore to prevent the committing of native builds but it doesn't
// use files in package.json because it publishes to individual packages based on architecture.
// When we used yarn to pack these packages the gitignore was ignored so the native builds were packed
// however npm does respect gitignore when packing so we need to remove it in this specific case
// to ensure the native builds are packed for use in gh actions and related scripts

const nativeGitignorePath = path.join(
pkgPath,
'native/.gitignore'
)
const renamedGitignorePath = path.join(
pkgPath,
'disabled-native-gitignore'
)
const nativeGitignorePath = path.join(
pkgPath,
'native/.gitignore'
)
const renamedGitignorePath = path.join(
pkgPath,
'disabled-native-gitignore'
)

await fs.promises.rename(
nativeGitignorePath,
renamedGitignorePath
)
cleanup = async () => {
await fs.promises.rename(
renamedGitignorePath,
nativeGitignorePath
)
}
}
await handlePackageSpan
.traceChild('rename-gitignore')
.traceAsyncFn(() =>
fs.promises.rename(
nativeGitignorePath,
renamedGitignorePath
)
)
cleanup = async () => {
await fs.promises.rename(
renamedGitignorePath,
nativeGitignorePath
)
}
}

const options = {
cwd: pkgPath,
env: {
...process.env,
COREPACK_ENABLE_STRICT: '0',
},
}
let execResult
try {
execResult = await execa('pnpm', ['pack'], options)
} catch {
execResult = await execa('pnpm', ['pack'], options)
}
const { stdout } = execResult
const options = {
cwd: pkgPath,
env: {
...process.env,
COREPACK_ENABLE_STRICT: '0',
},
}
let execResult
try {
execResult = await handlePackageSpan
.traceChild('pnpm-pack-try-1')
.traceAsyncFn(() => execa('pnpm', ['pack'], options))
} catch {
execResult = await handlePackageSpan
.traceChild('pnpm-pack-try-2')
.traceAsyncFn(() => execa('pnpm', ['pack'], options))
}
const { stdout } = execResult

const packedFileName = stdout.trim()
const packedFileName = stdout.trim()

await Promise.all([
fs.promises.rename(
path.join(pkgPath, packedFileName),
packedPkgPath
),
cleanup?.(),
])
}
)
)
await handlePackageSpan
.traceChild('rename-packed-tar-and-cleanup')
.traceAsyncFn(() =>
Promise.all([
fs.promises.rename(
path.join(pkgPath, packedFileName),
packedPkgPath
),
cleanup?.(),
])
)
})
}
)
)
})

return pkgPaths
},
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
NAPI_CLI_VERSION: 2.16.2
TURBO_VERSION: 1.12.5
TURBO_VERSION: 1.13.3-canary.2
NODE_LTS_VERSION: 20
CARGO_PROFILE_RELEASE_LTO: 'true'
TURBO_TEAM: 'vercel'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
NAPI_CLI_VERSION: 2.14.7
TURBO_VERSION: 1.12.5
TURBO_VERSION: 1.13.3-canary.2
NODE_MAINTENANCE_VERSION: 18
NODE_LTS_VERSION: 20
TEST_CONCURRENCY: 8
Expand Down
Loading

0 comments on commit 5074d88

Please sign in to comment.