-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
34 lines (31 loc) · 1.24 KB
/
build.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
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { mkdirSync, cpSync } from 'node:fs'
import { execSync } from 'node:child_process'
const filename = fileURLToPath(import.meta.url)
const directory = dirname(filename)
/**
* NPM workspaces does not appear to use `--install-strategy=nested`
* correctly. There are still hoisted dependencies.
*
* This moves the installed dependencies from the various node_module
* locations into one directory for distribution.
*/
const build = (pkg) => {
const rootDeps = resolve(directory, './node_modules')
const rootDepPkg = resolve(directory, rootDeps, pkg)
const pkgDeps = resolve(directory, `./packages/${pkg}/node_modules`)
const output = resolve(`./dist/${pkg}`)
execSync('npm run clean', { stdio: 'inherit' })
execSync(`npm ci --install-strategy=nested --omit=dev --workspace=${pkg}`, { stdio: 'inherit' })
execSync('rm -rf ./dist', { stdio: 'inherit' })
mkdirSync(output, { recursive: true })
cpSync(rootDeps, output, {recursive: true, filter: (src) => {
// Skip the symlinked pkg directory created by npm workspaces
if (src !== rootDepPkg) {
return true
}
}})
cpSync(pkgDeps, output, { recursive: true })
}
build(process.argv[2])