Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
84 lines
2.4 KiB
JavaScript
84 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { promises as fs } from 'node:fs'
|
|
import path from 'node:path'
|
|
import url from 'node:url'
|
|
import execa from 'execa'
|
|
import { NEXT_DIR, logCommand } from './pack-util'
|
|
|
|
const nextSwcDir = path.join(NEXT_DIR, 'packages/next-swc')
|
|
|
|
export default async function buildNative(
|
|
buildNativeArgs: string[]
|
|
): Promise<void> {
|
|
const buildCommand = ['pnpm', 'run', 'build-native', ...buildNativeArgs]
|
|
logCommand('Build native bindings', buildCommand)
|
|
await execa(buildCommand[0], buildCommand.slice(1), {
|
|
cwd: nextSwcDir,
|
|
// Without a shell, `pnpm run build-native` returns a 0 exit code on SIGINT?
|
|
shell: true,
|
|
env: {
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
CARGO_TERM_COLOR: 'always',
|
|
TTY: '1',
|
|
},
|
|
stdio: 'inherit',
|
|
})
|
|
|
|
await writeTypes()
|
|
}
|
|
|
|
// Check if this file is being run directly
|
|
if (import.meta.url === url.pathToFileURL(process.argv[1]).toString()) {
|
|
buildNative(process.argv.slice(2)).catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|
|
}
|
|
|
|
async function writeTypes() {
|
|
const generatedTypesPath = path.join(
|
|
NEXT_DIR,
|
|
'packages/next-swc/native/index.d.ts'
|
|
)
|
|
const vendoredTypesPath = path.join(
|
|
NEXT_DIR,
|
|
'packages/next/src/build/swc/generated-native.d.ts'
|
|
)
|
|
const generatedTypesMarker = '// GENERATED-TYPES-BELOW\n'
|
|
const generatedNotice =
|
|
'// DO NOT MANUALLY EDIT THESE TYPES\n' +
|
|
'// You can regenerate this file by running `pnpm swc-build-native` in the root of the repo.\n\n'
|
|
|
|
const generatedTypes = await fs.readFile(generatedTypesPath, 'utf8')
|
|
let vendoredTypes = await fs.readFile(vendoredTypesPath, 'utf8')
|
|
|
|
const existingContent = vendoredTypes
|
|
vendoredTypes = vendoredTypes.split(generatedTypesMarker)[0]
|
|
vendoredTypes =
|
|
vendoredTypes + generatedTypesMarker + generatedNotice + generatedTypes
|
|
|
|
const prettifyCommand = ['prettier', '--stdin-filepath', vendoredTypesPath]
|
|
logCommand('Prettify generated types', prettifyCommand)
|
|
const prettierResult = await execa(
|
|
prettifyCommand[0],
|
|
prettifyCommand.slice(1),
|
|
{
|
|
cwd: NEXT_DIR,
|
|
input: vendoredTypes,
|
|
preferLocal: true,
|
|
}
|
|
)
|
|
vendoredTypes = prettierResult.stdout
|
|
if (!vendoredTypes.endsWith('\n')) {
|
|
vendoredTypes += '\n'
|
|
}
|
|
|
|
if (vendoredTypes === existingContent) {
|
|
return
|
|
}
|
|
|
|
logCommand('Write generated types', `write file`)
|
|
await fs.writeFile(vendoredTypesPath, vendoredTypes)
|
|
}
|