-
Notifications
You must be signed in to change notification settings - Fork 27.8k
/
Copy pathpublish-native.js
executable file
·69 lines (64 loc) · 2.24 KB
/
publish-native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
const path = require('path')
const { readFile, readdir, writeFile } = require('fs/promises')
const { copy } = require('fs-extra')
const { execSync } = require('child_process')
const cwd = process.cwd()
;(async function () {
try {
let version = JSON.parse(await readFile(path.join(cwd, 'lerna.json')))
.version
let gitref = process.argv.slice(2)[0]
// Copy binaries to package folders, update version, and publish
let nativePackagesDir = path.join(cwd, 'packages/next/build/swc/npm')
let platforms = await (await readdir(nativePackagesDir)).filter(
(name) => name !== '.gitignore'
)
for (let platform of platforms) {
let binaryName = `next-swc.${platform}.node`
await copy(
path.join(cwd, 'packages/next/build/swc/dist', binaryName),
path.join(nativePackagesDir, platform, binaryName)
)
let pkg = JSON.parse(
await readFile(path.join(nativePackagesDir, platform, 'package.json'))
)
pkg.version = version
await writeFile(
path.join(nativePackagesDir, platform, 'package.json'),
JSON.stringify(pkg, null, 2)
)
execSync(
`npm publish ${path.join(nativePackagesDir, platform)}${
gitref.includes('canary') ? ' --tag canary' : ''
}`
)
// lerna publish in next step will fail if git status is not clean
execSync(
`git update-index --skip-worktree ${path.join(
nativePackagesDir,
platform,
'package.json'
)}`
)
}
// Update optional dependencies versions
let nextPkg = JSON.parse(
await readFile(path.join(cwd, 'packages/next/package.json'))
)
for (let platform of platforms) {
let optionalDependencies = nextPkg.optionalDependencies || {}
optionalDependencies['@next/swc-' + platform] = version
nextPkg.optionalDependencies = optionalDependencies
}
await writeFile(
path.join(path.join(cwd, 'packages/next/package.json')),
JSON.stringify(nextPkg, null, 2)
)
// lerna publish in next step will fail if git status is not clean
execSync('git update-index --skip-worktree packages/next/package.json')
} catch (err) {
console.error(err)
process.exit(1)
}
})()