forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-native.mjs
59 lines (57 loc) · 1.81 KB
/
install-native.mjs
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
import os from 'os'
import path from 'path'
import execa from 'execa'
import fs from 'fs-extra'
;(async function () {
if (process.env.NEXT_SKIP_NATIVE_POSTINSTALL) {
console.log(
`Skipping next-swc postinstall due to NEXT_SKIP_NATIVE_POSTINSTALL env`
)
return
}
try {
let tmpdir = path.join(os.tmpdir(), `next-swc-${Date.now()}`)
await fs.ensureDir(tmpdir)
let cwd = process.cwd()
let pkgJson = {
name: 'dummy-package',
version: '1.0.0',
optionalDependencies: {
'@next/swc-android-arm64': 'canary',
'@next/swc-android-arm-eabi': 'canary',
'@next/swc-darwin-arm64': 'canary',
'@next/swc-darwin-x64': 'canary',
'@next/swc-linux-arm-gnueabihf': 'canary',
'@next/swc-linux-arm64-gnu': 'canary',
'@next/swc-linux-arm64-musl': 'canary',
'@next/swc-linux-x64-gnu': 'canary',
'@next/swc-linux-x64-musl': 'canary',
'@next/swc-win32-arm64-msvc': 'canary',
'@next/swc-win32-ia32-msvc': 'canary',
'@next/swc-win32-x64-msvc': 'canary',
},
}
await fs.writeFile(
path.join(tmpdir, 'package.json'),
JSON.stringify(pkgJson)
)
let { stdout } = await execa('yarn', ['--force'], { cwd: tmpdir })
console.log(stdout)
let pkgs = await fs.readdir(path.join(tmpdir, 'node_modules/@next'))
await fs.ensureDir(path.join(cwd, 'node_modules/@next'))
await Promise.all(
pkgs.map((pkg) =>
fs.move(
path.join(tmpdir, 'node_modules/@next', pkg),
path.join(cwd, 'node_modules/@next', pkg),
{ overwrite: true }
)
)
)
await fs.remove(tmpdir)
console.log('Installed the following binary packages:', pkgs)
} catch (e) {
console.error(e)
console.error('Failed to load @next/swc binary packages')
}
})()