Commit 778e7bf1 authored by JJ Kasper's avatar JJ Kasper

lock swc binaries

parent 5a97b408
This diff is collapsed.
...@@ -21,7 +21,8 @@ import { getDefineEnv } from '../webpack/plugins/define-env-plugin' ...@@ -21,7 +21,8 @@ import { getDefineEnv } from '../webpack/plugins/define-env-plugin'
import type { PageExtensions } from '../page-extensions-type' import type { PageExtensions } from '../page-extensions-type'
import type { __ApiPreviewProps } from '../../server/api-utils' import type { __ApiPreviewProps } from '../../server/api-utils'
const nextVersion = process.env.__NEXT_VERSION as string // locked version as binaries are locked
const nextVersion = '14.2.33'
const ArchName = arch() const ArchName = arch()
const PlatformName = platform() const PlatformName = platform()
......
#!/usr/bin/env node #!/usr/bin/env node
const path = require('path') const path = require('path')
const execa = require('execa') // const execa = require('execa')
const { Sema } = require('async-sema') // const { Sema } = require('async-sema')
const { readFile, readdir, writeFile, cp } = require('fs/promises') const { readFile, readdir, writeFile } = require('fs/promises')
const cwd = process.cwd() const cwd = process.cwd()
;(async function () { ;(async function () {
try { try {
const publishSema = new Sema(2) // const publishSema = new Sema(2)
let version = JSON.parse( let version = '14.2.33'
await readFile(path.join(cwd, 'lerna.json'))
).version
// Copy binaries to package folders, update version, and publish // Copy binaries to package folders, update version, and publish
let nativePackagesDir = path.join(cwd, 'packages/next-swc/crates/napi/npm') let nativePackagesDir = path.join(cwd, 'packages/next-swc/crates/napi/npm')
...@@ -21,118 +19,118 @@ const cwd = process.cwd() ...@@ -21,118 +19,118 @@ const cwd = process.cwd()
(name) => !name.startsWith('.') (name) => !name.startsWith('.')
) )
await Promise.all( // await Promise.all(
platforms.map(async (platform) => { // platforms.map(async (platform) => {
await publishSema.acquire() // await publishSema.acquire()
let output = '' // let output = ''
try { // try {
let binaryName = `next-swc.${platform}.node` // let binaryName = `next-swc.${platform}.node`
await cp( // await cp(
path.join(cwd, 'packages/next-swc/native', binaryName), // path.join(cwd, 'packages/next-swc/native', binaryName),
path.join(nativePackagesDir, platform, binaryName) // path.join(nativePackagesDir, platform, binaryName)
) // )
let pkg = JSON.parse( // let pkg = JSON.parse(
await readFile( // await readFile(
path.join(nativePackagesDir, platform, 'package.json') // path.join(nativePackagesDir, platform, 'package.json')
) // )
) // )
pkg.version = version // pkg.version = version
await writeFile( // await writeFile(
path.join(nativePackagesDir, platform, 'package.json'), // path.join(nativePackagesDir, platform, 'package.json'),
JSON.stringify(pkg, null, 2) // JSON.stringify(pkg, null, 2)
) // )
const child = execa( // const child = execa(
`npm`, // `npm`,
[ // [
`publish`, // `publish`,
`${path.join(nativePackagesDir, platform)}`, // `${path.join(nativePackagesDir, platform)}`,
`--access`, // `--access`,
`public`, // `public`,
...(version.includes('canary') // ...(version.includes('canary')
? ['--tag', 'canary'] // ? ['--tag', 'canary']
: ['--tag', 'next-14']), // : ['--tag', 'next-14']),
], // ],
{ stdio: 'inherit' } // { stdio: 'inherit' }
) // )
const handleData = (type) => (chunk) => { // const handleData = (type) => (chunk) => {
process[type].write(chunk) // process[type].write(chunk)
output += chunk.toString() // output += chunk.toString()
} // }
child.stdout?.on('data', handleData('stdout')) // child.stdout?.on('data', handleData('stdout'))
child.stderr?.on('data', handleData('stderr')) // child.stderr?.on('data', handleData('stderr'))
await child // await child
} catch (err) { // } catch (err) {
// don't block publishing other versions on single platform error // // don't block publishing other versions on single platform error
console.error(`Failed to publish`, platform, err) // console.error(`Failed to publish`, platform, err)
if ( // if (
output.includes( // output.includes(
'cannot publish over the previously published versions' // 'cannot publish over the previously published versions'
) // )
) { // ) {
console.error('Ignoring already published error', platform, err) // console.error('Ignoring already published error', platform, err)
} else { // } else {
// throw err // // throw err
} // }
} finally { // } finally {
publishSema.release() // publishSema.release()
} // }
}) // })
) // )
// Update name/version of wasm packages and publish // Update name/version of wasm packages and publish
const pkgDirectory = 'packages/next-swc/crates/wasm' // const pkgDirectory = 'packages/next-swc/crates/wasm'
let wasmDir = path.join(cwd, pkgDirectory) // let wasmDir = path.join(cwd, pkgDirectory)
await Promise.all( // await Promise.all(
['web', 'nodejs'].map(async (wasmTarget) => { // ['web', 'nodejs'].map(async (wasmTarget) => {
await publishSema.acquire() // await publishSema.acquire()
let wasmPkg = JSON.parse( // let wasmPkg = JSON.parse(
await readFile(path.join(wasmDir, `pkg-${wasmTarget}/package.json`)) // await readFile(path.join(wasmDir, `pkg-${wasmTarget}/package.json`))
) // )
wasmPkg.name = `@next/swc-wasm-${wasmTarget}` // wasmPkg.name = `@next/swc-wasm-${wasmTarget}`
wasmPkg.version = version // wasmPkg.version = version
wasmPkg.repository = { // wasmPkg.repository = {
type: 'git', // type: 'git',
url: 'https://github.com/vercel/next.js', // url: 'https://github.com/vercel/next.js',
directory: pkgDirectory, // directory: pkgDirectory,
} // }
await writeFile( // await writeFile(
path.join(wasmDir, `pkg-${wasmTarget}/package.json`), // path.join(wasmDir, `pkg-${wasmTarget}/package.json`),
JSON.stringify(wasmPkg, null, 2) // JSON.stringify(wasmPkg, null, 2)
) // )
try { // try {
await execa( // await execa(
`npm`, // `npm`,
[ // [
'publish', // 'publish',
`${path.join(wasmDir, `pkg-${wasmTarget}`)}`, // `${path.join(wasmDir, `pkg-${wasmTarget}`)}`,
'--access', // '--access',
'public', // 'public',
...(version.includes('canary') // ...(version.includes('canary')
? ['--tag', 'canary'] // ? ['--tag', 'canary']
: ['--tag', 'next-14']), // : ['--tag', 'next-14']),
], // ],
{ stdio: 'inherit' } // { stdio: 'inherit' }
) // )
} catch (err) { // } catch (err) {
// don't block publishing other versions on single platform error // // don't block publishing other versions on single platform error
console.error(`Failed to publish`, wasmTarget, err) // console.error(`Failed to publish`, wasmTarget, err)
if ( // if (
err.message && // err.message &&
err.message.includes( // err.message.includes(
'You cannot publish over the previously published versions' // 'You cannot publish over the previously published versions'
) // )
) { // ) {
console.error('Ignoring already published error', wasmTarget) // console.error('Ignoring already published error', wasmTarget)
} else { // } else {
// throw err // // throw err
} // }
} finally { // } finally {
publishSema.release() // publishSema.release()
} // }
}) // })
) // )
// Update optional dependencies versions // Update optional dependencies versions
let nextPkg = JSON.parse( let nextPkg = JSON.parse(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment