forked from moodle/moodlenet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
align_pkg_mn-peer-deps_to_mn-dev-deps.mjs
45 lines (37 loc) · 1.58 KB
/
align_pkg_mn-peer-deps_to_mn-dev-deps.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
import { readdirSync, readFileSync, statSync, writeFileSync } from 'fs'
import * as path from 'path'
// https://github.com/lerna/lerna/issues/1892
// https://github.com/lerna/lerna/issues/3014
// https://github.com/lerna/lerna/issues/1575
const __dirname = path.dirname(new URL(import.meta.url).pathname)
const packagesDirs = readdirSync(path.resolve(__dirname, 'packages')).map(pkg_name =>
path.resolve(__dirname, 'packages', pkg_name),
)
packagesDirs.forEach(pkgDir => {
console.log('pkgDir', pkgDir)
const pkgJsonFile = path.resolve(pkgDir, 'package.json')
const pkgJsonFileExists = !!statSync(pkgJsonFile, { throwIfNoEntry: false })
if (!pkgJsonFileExists) return
const pkgJson = JSON.parse(readFileSync(pkgJsonFile, 'utf8'))
if (pkgJson.name === 'storybook-vite') {
return
}
// const hasMNDevDeps = !!Object.keys(pkgJson.devDependencies ?? {}).find(depName =>
// depName.startsWith('@moodlenet/'),
// )
// if (!hasMNDevDeps) return
Object.keys(pkgJson.peerDependencies ?? {}).forEach(depName => {
if (depName.startsWith('@moodlenet/')) {
delete pkgJson.peerDependencies[depName]
return
}
pkgJson.devDependencies = pkgJson.devDependencies ?? {}
pkgJson.devDependencies[depName] = pkgJson.peerDependencies[depName]
})
Object.keys(pkgJson.devDependencies ?? {}).forEach(depName => {
if (!depName.startsWith('@moodlenet/')) return
pkgJson.peerDependencies = pkgJson.peerDependencies ?? {}
pkgJson.peerDependencies[depName] = pkgJson.devDependencies[depName]
})
writeFileSync(pkgJsonFile, JSON.stringify(pkgJson, null, 2) + '\n')
})