jiek 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
- package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
- package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
- package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
- package/dist/.internal/bin/common.cjs +90 -97
- package/dist/.internal/bin/common.js +91 -98
- package/dist/.internal/bin/parseArgv.cjs +2 -2
- package/dist/.internal/bin/parseArgv.js +2 -2
- package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
- package/dist/.internal/polyfill.cjs +13 -0
- package/dist/.internal/polyfill.d.cts +1 -0
- package/dist/.internal/polyfill.d.ts +1 -0
- package/dist/.internal/polyfill.js +11 -0
- package/dist/.internal/utils/filterSupport.cjs +1 -1
- package/dist/.internal/utils/filterSupport.js +2 -2
- package/dist/.internal/utils/loadConfig.cjs +3 -3
- package/dist/.internal/utils/loadConfig.d.cts +1 -0
- package/dist/.internal/utils/loadConfig.d.ts +1 -0
- package/dist/.internal/utils/loadConfig.js +4 -4
- package/dist/.internal/utils/pascalCase.cjs +5 -0
- package/dist/.internal/utils/pascalCase.d.cts +3 -0
- package/dist/.internal/utils/pascalCase.d.ts +3 -0
- package/dist/.internal/utils/pascalCase.js +3 -0
- package/dist/.internal/utils/reveal.cjs +9 -0
- package/dist/.internal/utils/reveal.d.cts +3 -0
- package/dist/.internal/utils/reveal.d.ts +3 -0
- package/dist/.internal/utils/reveal.js +7 -0
- package/dist/bin/index.cjs +101 -43
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/rollup/index.cjs +16 -18
- package/dist/rollup/index.js +13 -15
- package/package.json +2 -2
- package/src/bin/build.cts +0 -5
- package/src/bin/common.ts +0 -3
- package/src/bin/index.cts +0 -7
- package/src/bin/parseArgv.ts +0 -26
- package/src/bridge.ts +0 -46
- package/src/commands/base.ts +0 -18
- package/src/commands/build/analyzer.ts +0 -122
- package/src/commands/build/client/analyzer.tsx +0 -121
- package/src/commands/build/client/index.ts +0 -26
- package/src/commands/build.ts +0 -544
- package/src/commands/descriptions.ts +0 -17
- package/src/commands/meta.ts +0 -5
- package/src/commands/publish.ts +0 -628
- package/src/commands/utils/optionParser.ts +0 -4
- package/src/index.ts +0 -12
- package/src/inner.ts +0 -11
- package/src/rollup/base.ts +0 -152
- package/src/rollup/bundle-analyzer.ts +0 -62
- package/src/rollup/index.ts +0 -893
- package/src/rollup/plugins/create-require.ts +0 -23
- package/src/rollup/plugins/progress.ts +0 -26
- package/src/rollup/plugins/replace.ts +0 -185
- package/src/rollup/plugins/skip.ts +0 -21
- package/src/rollup/plugins/with-external.ts +0 -23
- package/src/rollup/utils/commonOptions.ts +0 -9
- package/src/rollup/utils/externalResolver.ts +0 -47
- package/src/rollup/utils/globalResolver.ts +0 -13
- package/src/rollup/utils/withMinify.ts +0 -18
- package/src/rollup-plugin-utils.ts +0 -32
- package/src/server.ts +0 -30
- package/src/utils/checkDependency.ts +0 -26
- package/src/utils/filterSupport.ts +0 -90
- package/src/utils/getInternalModuleName.ts +0 -5
- package/src/utils/getRoot.ts +0 -14
- package/src/utils/getWD.ts +0 -31
- package/src/utils/intersection.ts +0 -1
- package/src/utils/loadConfig.ts +0 -108
- package/src/utils/recursiveListFiles.ts +0 -13
- package/src/utils/resolveExports.ts +0 -165
- package/src/utils/ts.ts +0 -94
- package/src/utils/tsRegister.ts +0 -22
@@ -1,23 +0,0 @@
|
|
1
|
-
import type { Plugin } from 'rollup'
|
2
|
-
|
3
|
-
export const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = 'jiek:create-require'
|
4
|
-
|
5
|
-
const INSERT_STR = (isESM: boolean) =>
|
6
|
-
`
|
7
|
-
${isESM ? `import { createRequire } from 'node:module'` : ''}
|
8
|
-
export default ${isESM ? '/* @__PURE__ */ createRequire(import.meta.url)' : 'require'}
|
9
|
-
`.trim()
|
10
|
-
|
11
|
-
export default (isEsm: boolean): Plugin => ({
|
12
|
-
name: 'create-require',
|
13
|
-
resolveId: id => (
|
14
|
-
id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
|
15
|
-
? id
|
16
|
-
: null
|
17
|
-
),
|
18
|
-
load: id => (
|
19
|
-
id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
|
20
|
-
? INSERT_STR(isEsm)
|
21
|
-
: null
|
22
|
-
)
|
23
|
-
})
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import type { PluginImpl } from 'rollup'
|
2
|
-
|
3
|
-
interface Options {
|
4
|
-
onEvent?: (event: string, message?: string) => void
|
5
|
-
}
|
6
|
-
|
7
|
-
export default ((options = {}) => {
|
8
|
-
const { onEvent } = options
|
9
|
-
return {
|
10
|
-
name: 'progress',
|
11
|
-
buildStart: () => onEvent?.('start', 'Start building...'),
|
12
|
-
buildEnd: () => onEvent?.('end', 'Build completed!'),
|
13
|
-
resolveId: {
|
14
|
-
order: 'post',
|
15
|
-
handler: source => onEvent?.('resolve', `Resolving ${source}...`)
|
16
|
-
},
|
17
|
-
load: {
|
18
|
-
order: 'post',
|
19
|
-
handler: id => onEvent?.('load', `Loading ${id}...`)
|
20
|
-
},
|
21
|
-
transform: {
|
22
|
-
order: 'post',
|
23
|
-
handler: (_, id) => onEvent?.('transform', `Transforming ${id}...`)
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}) as PluginImpl<Options>
|
@@ -1,185 +0,0 @@
|
|
1
|
-
import { extname } from 'node:path'
|
2
|
-
|
3
|
-
import type { Lang, SgNode } from '@ast-grep/napi'
|
4
|
-
import type { FilterOptions } from 'jiek/rollup-plugin-utils'
|
5
|
-
import { createFilter, definePlugin } from 'jiek/rollup-plugin-utils'
|
6
|
-
import MagicString from 'magic-string'
|
7
|
-
|
8
|
-
export type Mode = 'string' | 'ast-grep'
|
9
|
-
|
10
|
-
export type ReplacementFuncCtx =
|
11
|
-
& {
|
12
|
-
type: 'transform' | 'renderChunk'
|
13
|
-
id: string
|
14
|
-
code: string
|
15
|
-
mode: Mode
|
16
|
-
}
|
17
|
-
& (
|
18
|
-
| {
|
19
|
-
mode?: 'string'
|
20
|
-
start: number
|
21
|
-
end: number
|
22
|
-
}
|
23
|
-
| {
|
24
|
-
mode?: 'ast-grep'
|
25
|
-
$:
|
26
|
-
& ((name: string) => string | undefined)
|
27
|
-
& ((template: { raw: readonly string[] }) => string | undefined)
|
28
|
-
node: SgNode
|
29
|
-
lang: Lang
|
30
|
-
}
|
31
|
-
)
|
32
|
-
|
33
|
-
type Falsy = false | null | undefined
|
34
|
-
|
35
|
-
export type ReplacementFunc = (ctx: ReplacementFuncCtx) => string | Falsy
|
36
|
-
|
37
|
-
export type Replacements = Record<
|
38
|
-
string,
|
39
|
-
string | Falsy | ReplacementFunc
|
40
|
-
>
|
41
|
-
|
42
|
-
export type ReplaceOptions =
|
43
|
-
& FilterOptions
|
44
|
-
& {
|
45
|
-
/**
|
46
|
-
* @default 'string'
|
47
|
-
*/
|
48
|
-
mode?: Mode
|
49
|
-
sourcemap?: boolean
|
50
|
-
values?: Replacements
|
51
|
-
}
|
52
|
-
|
53
|
-
export default definePlugin((options: ReplaceOptions = {}) => {
|
54
|
-
const {
|
55
|
-
include = [/\.[cm]?[tj]sx?$/],
|
56
|
-
exclude = [/node_modules/],
|
57
|
-
values = {},
|
58
|
-
sourcemap
|
59
|
-
} = options
|
60
|
-
let { mode = 'string' } = options
|
61
|
-
const allValues = { ...values }
|
62
|
-
const allKeys = Object.keys(allValues)
|
63
|
-
const filter = createFilter({ include, exclude })
|
64
|
-
|
65
|
-
const replaceAll = async (ctx: Pick<ReplacementFuncCtx, 'type' | 'id'>, code: string) => {
|
66
|
-
const ms = new MagicString(code)
|
67
|
-
if (mode === 'string') {
|
68
|
-
allKeys.forEach(key => {
|
69
|
-
const reg = new RegExp(key, 'g')
|
70
|
-
let match
|
71
|
-
// eslint-disable-next-line no-cond-assign
|
72
|
-
while ((match = reg.exec(code))) {
|
73
|
-
const start = match.index
|
74
|
-
const end = start + key.length
|
75
|
-
const value = typeof allValues[key] === 'function'
|
76
|
-
? allValues[key]({
|
77
|
-
...ctx,
|
78
|
-
code,
|
79
|
-
start,
|
80
|
-
end,
|
81
|
-
mode: 'string'
|
82
|
-
})
|
83
|
-
: allValues[key]
|
84
|
-
if (([null, undefined, false] as unknown[]).includes(value)) continue
|
85
|
-
ms.overwrite(
|
86
|
-
match.index,
|
87
|
-
match.index + key.length,
|
88
|
-
value as string
|
89
|
-
)
|
90
|
-
}
|
91
|
-
})
|
92
|
-
} else if (mode === 'ast-grep') {
|
93
|
-
const ext = extname(ctx.id)
|
94
|
-
const { parse, Lang } = await import('@ast-grep/napi')
|
95
|
-
let lang: Lang | undefined
|
96
|
-
if (/[cm]?tsx?/.test(ext)) {
|
97
|
-
lang = Lang.TypeScript
|
98
|
-
}
|
99
|
-
if (/[cm]?jsx?/.test(ext)) {
|
100
|
-
lang = Lang.JavaScript
|
101
|
-
}
|
102
|
-
if (/json?/.test(ext)) {
|
103
|
-
lang = Lang.Json
|
104
|
-
}
|
105
|
-
if (lang == null) return
|
106
|
-
const root = parse(lang, code).root()
|
107
|
-
allKeys.forEach(key => {
|
108
|
-
root
|
109
|
-
.findAll(key)
|
110
|
-
.forEach(node => {
|
111
|
-
const { start, end } = node.range()
|
112
|
-
const newValue = typeof allValues[key] === 'function'
|
113
|
-
? allValues[key]({
|
114
|
-
...ctx,
|
115
|
-
code,
|
116
|
-
mode: 'ast-grep',
|
117
|
-
node,
|
118
|
-
lang,
|
119
|
-
$: (input) => {
|
120
|
-
if (typeof input === 'string') {
|
121
|
-
return node.getMatch(input)?.text()
|
122
|
-
}
|
123
|
-
if ('raw' in input) {
|
124
|
-
return node.getMatch(input.raw[0])?.text()
|
125
|
-
}
|
126
|
-
}
|
127
|
-
})
|
128
|
-
: allValues[key]
|
129
|
-
if (([null, undefined, false] as unknown[]).includes(newValue)) return
|
130
|
-
ms.overwrite(
|
131
|
-
start.index,
|
132
|
-
end.index,
|
133
|
-
newValue as string
|
134
|
-
)
|
135
|
-
})
|
136
|
-
})
|
137
|
-
}
|
138
|
-
return ms
|
139
|
-
}
|
140
|
-
|
141
|
-
return {
|
142
|
-
name: 'jiek:replace',
|
143
|
-
buildStart() {
|
144
|
-
if (mode === 'ast-grep') {
|
145
|
-
try {
|
146
|
-
require.resolve('@ast-grep/napi')
|
147
|
-
this.warn(
|
148
|
-
'You are using `ast-grep` mode, please make sure you have installed `@ast-grep/napi`'
|
149
|
-
)
|
150
|
-
} catch {
|
151
|
-
mode = 'string'
|
152
|
-
}
|
153
|
-
}
|
154
|
-
},
|
155
|
-
transform: {
|
156
|
-
order: 'pre',
|
157
|
-
async handler(code, id) {
|
158
|
-
if (allKeys.length === 0) return
|
159
|
-
if (filter(id)) return
|
160
|
-
const ms = await replaceAll({ type: 'transform', id }, code)
|
161
|
-
if (ms == null) return
|
162
|
-
|
163
|
-
return {
|
164
|
-
code: ms.toString(),
|
165
|
-
map: sourcemap ? ms.generateMap({ hires: true }) : null
|
166
|
-
}
|
167
|
-
}
|
168
|
-
},
|
169
|
-
renderChunk: {
|
170
|
-
order: 'post',
|
171
|
-
async handler(code, { fileName: id }) {
|
172
|
-
if (allKeys.length === 0) return
|
173
|
-
if (filter(id)) return
|
174
|
-
|
175
|
-
const ms = await replaceAll({ type: 'renderChunk', id }, code)
|
176
|
-
if (ms == null) return
|
177
|
-
|
178
|
-
return {
|
179
|
-
code: ms.toString(),
|
180
|
-
map: sourcemap ? ms.generateMap({ hires: true }) : null
|
181
|
-
}
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
})
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import type { PluginImpl } from 'rollup'
|
2
|
-
|
3
|
-
interface Options {
|
4
|
-
patterns?: (string | RegExp)[]
|
5
|
-
}
|
6
|
-
|
7
|
-
export default ((options = {}) => ({
|
8
|
-
name: 'skip',
|
9
|
-
// skip the specified files by `options.patterns`
|
10
|
-
load(id) {
|
11
|
-
if (
|
12
|
-
options.patterns?.some((pattern) =>
|
13
|
-
typeof pattern === 'string'
|
14
|
-
? id.includes(pattern)
|
15
|
-
: pattern.test(id)
|
16
|
-
)
|
17
|
-
) {
|
18
|
-
return ''
|
19
|
-
}
|
20
|
-
}
|
21
|
-
})) as PluginImpl<Options>
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import type { PluginImpl } from 'rollup'
|
2
|
-
|
3
|
-
export default (() => ({
|
4
|
-
name: 'jiek:with-external',
|
5
|
-
resolveId: {
|
6
|
-
order: 'pre',
|
7
|
-
handler: (source, _, { attributes }) => {
|
8
|
-
if (
|
9
|
-
'external' in attributes || 'bundle' in attributes
|
10
|
-
) {
|
11
|
-
delete attributes.external
|
12
|
-
delete attributes.bundle
|
13
|
-
return {
|
14
|
-
id: source,
|
15
|
-
external: attributes.external === 'true'
|
16
|
-
? true
|
17
|
-
: attributes.bundle !== 'true',
|
18
|
-
attributes
|
19
|
-
}
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
})) as PluginImpl<{}>
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import fs from 'node:fs'
|
2
|
-
import { builtinModules } from 'node:module'
|
3
|
-
import process from 'node:process'
|
4
|
-
|
5
|
-
const EXCLUDE_SUFFIX = [
|
6
|
-
'te?xt',
|
7
|
-
'json',
|
8
|
-
'(css|s[ac]ss|less|styl)'
|
9
|
-
]
|
10
|
-
|
11
|
-
export interface PackageJSON {
|
12
|
-
name: string
|
13
|
-
type?: string
|
14
|
-
bin?: string | Record<string, string>
|
15
|
-
exports?: Record<string, unknown> | string | string[]
|
16
|
-
imports?: Record<string, unknown>
|
17
|
-
dependencies?: Record<string, unknown>
|
18
|
-
peerDependencies?: Record<string, unknown>
|
19
|
-
optionalDependencies?: Record<string, unknown>
|
20
|
-
}
|
21
|
-
|
22
|
-
export default function(json: PackageJSON): (string | RegExp)[]
|
23
|
-
export default function(path?: string): (string | RegExp)[]
|
24
|
-
export default function(jsonOrPath: string | PackageJSON = process.cwd()): (string | RegExp)[] {
|
25
|
-
const pkg: PackageJSON = typeof jsonOrPath === 'string'
|
26
|
-
? fs.existsSync(`${jsonOrPath}/package.json`)
|
27
|
-
? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8')) as PackageJSON
|
28
|
-
: {} as PackageJSON
|
29
|
-
: jsonOrPath
|
30
|
-
const { name, dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg
|
31
|
-
if (name == null) {
|
32
|
-
throw new Error('package.json must have a name field')
|
33
|
-
}
|
34
|
-
|
35
|
-
const external = (<(string | RegExp)[]> [])
|
36
|
-
.concat(Object.keys(dependencies))
|
37
|
-
.concat(Object.keys(peerDependencies))
|
38
|
-
.concat(Object.keys(optionalDependencies))
|
39
|
-
.concat(builtinModules)
|
40
|
-
|
41
|
-
return [...new Set(external)]
|
42
|
-
.map(dep => new RegExp(`^${dep}(/.*)?$`))
|
43
|
-
.concat([
|
44
|
-
new RegExp(`^${name}(/.*)?(?<!${EXCLUDE_SUFFIX.map(suffix => `\\.${suffix}`).join('|')})$`),
|
45
|
-
/^node:/
|
46
|
-
])
|
47
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
export default function (external: string) {
|
2
|
-
// a/b => AB
|
3
|
-
// a-b => AB
|
4
|
-
// a@b => AB
|
5
|
-
// a@b/c => ABC
|
6
|
-
// node:a => a
|
7
|
-
// node:a_b => a_b
|
8
|
-
if (external.startsWith('node:')) {
|
9
|
-
return external.slice(5)
|
10
|
-
}
|
11
|
-
return external
|
12
|
-
.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase())
|
13
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import terser from '@rollup/plugin-terser'
|
2
|
-
import type { OutputOptions, OutputPlugin } from 'rollup'
|
3
|
-
|
4
|
-
export default function(
|
5
|
-
output: OutputOptions & {
|
6
|
-
entryFileNames?: string
|
7
|
-
plugins?: OutputPlugin[]
|
8
|
-
}
|
9
|
-
): OutputOptions[] {
|
10
|
-
return [
|
11
|
-
output,
|
12
|
-
{
|
13
|
-
...output,
|
14
|
-
entryFileNames: output.entryFileNames?.replace(/(\.[cm]?js)$/, '.min$1'),
|
15
|
-
plugins: [...(output.plugins ?? []), terser()]
|
16
|
-
}
|
17
|
-
]
|
18
|
-
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import { isMatch } from 'micromatch'
|
2
|
-
import type { PluginImpl } from 'rollup'
|
3
|
-
|
4
|
-
export const definePlugin = <O extends object>(plugin: PluginImpl<O>) => plugin
|
5
|
-
|
6
|
-
export interface FilterOptions {
|
7
|
-
include?: string | RegExp | (string | RegExp)[]
|
8
|
-
exclude?: string | RegExp | (string | RegExp)[]
|
9
|
-
}
|
10
|
-
|
11
|
-
export function createFilter(options: FilterOptions) {
|
12
|
-
const { include = [], exclude = [] } = options
|
13
|
-
|
14
|
-
const resolvedInclude = Array.isArray(include) ? include : [include]
|
15
|
-
const resolvedExclude = Array.isArray(exclude) ? exclude : [exclude]
|
16
|
-
|
17
|
-
return (id: string) => {
|
18
|
-
if (typeof id !== 'string') return false
|
19
|
-
const isInclude = resolvedInclude.length === 0 || resolvedInclude.some(filter => {
|
20
|
-
return filter instanceof RegExp
|
21
|
-
? filter.test(id)
|
22
|
-
: isMatch(id, filter)
|
23
|
-
})
|
24
|
-
const isExclude = resolvedExclude.length > 0 && resolvedExclude.some(filter => {
|
25
|
-
return filter instanceof RegExp
|
26
|
-
? filter.test(id)
|
27
|
-
: isMatch(id, filter)
|
28
|
-
})
|
29
|
-
|
30
|
-
return !isInclude || isExclude
|
31
|
-
}
|
32
|
-
}
|
package/src/server.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import Koa from 'koa'
|
2
|
-
|
3
|
-
export const createServer = (port: number, host: string) => {
|
4
|
-
const app = new Koa()
|
5
|
-
app.listen(port, host)
|
6
|
-
const streams = new Map<string, string>()
|
7
|
-
app.use(async (ctx) => {
|
8
|
-
let stream = streams.get(ctx.path)
|
9
|
-
if (stream == null) {
|
10
|
-
const maybeKey = streams
|
11
|
-
.keys()
|
12
|
-
.find(p => ctx.path.startsWith(p))
|
13
|
-
stream = maybeKey != null
|
14
|
-
? streams.get(maybeKey)
|
15
|
-
: undefined
|
16
|
-
}
|
17
|
-
if (stream != null) {
|
18
|
-
ctx.body = stream
|
19
|
-
}
|
20
|
-
})
|
21
|
-
// noinspection HttpUrlsUsage
|
22
|
-
return {
|
23
|
-
port,
|
24
|
-
host,
|
25
|
-
rootUrl: `http://${host}:${port}`,
|
26
|
-
renderTo: async (path: string, stream: string) => {
|
27
|
-
streams.set(path, stream)
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { execSync } from 'node:child_process'
|
2
|
-
import process from 'node:process'
|
3
|
-
|
4
|
-
import { confirm } from '@inquirer/prompts'
|
5
|
-
|
6
|
-
import { getWD } from '#~/utils/getWD'
|
7
|
-
|
8
|
-
export async function checkDependency(dependency: string) {
|
9
|
-
try {
|
10
|
-
require.resolve(dependency)
|
11
|
-
} catch {
|
12
|
-
console.error(`The package '${dependency}' is not installed, please install it first.`)
|
13
|
-
const { notWorkspace } = getWD()
|
14
|
-
const command = `pnpm add -${notWorkspace ? '' : 'w'}D ${dependency}`
|
15
|
-
if (await confirm({ message: `Do you want to add it now? (${command})` })) {
|
16
|
-
execSync(command, {
|
17
|
-
stdio: 'inherit',
|
18
|
-
cwd: process.cwd(),
|
19
|
-
env: process.env
|
20
|
-
})
|
21
|
-
} else {
|
22
|
-
console.warn(`You can run the command '${command}' to install it manually.`)
|
23
|
-
process.exit(1)
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
@@ -1,90 +0,0 @@
|
|
1
|
-
import fs from 'node:fs'
|
2
|
-
import path from 'node:path'
|
3
|
-
import process from 'node:process'
|
4
|
-
|
5
|
-
import { program } from 'commander'
|
6
|
-
import { load } from 'js-yaml'
|
7
|
-
|
8
|
-
import { getRoot } from '#~/utils/getRoot'
|
9
|
-
import { getWD } from '#~/utils/getWD'
|
10
|
-
|
11
|
-
export let type = ''
|
12
|
-
|
13
|
-
try {
|
14
|
-
require.resolve('@pnpm/filter-workspace-packages')
|
15
|
-
type = 'pnpm'
|
16
|
-
} catch { /* empty */ }
|
17
|
-
|
18
|
-
export interface Manifest {
|
19
|
-
name?: string
|
20
|
-
type?: string
|
21
|
-
exports?: string | string[] | Record<string, unknown>
|
22
|
-
imports?: Record<string, unknown>
|
23
|
-
}
|
24
|
-
|
25
|
-
export interface ProjectsGraph {
|
26
|
-
root?: string
|
27
|
-
value?: Record<string, Manifest>
|
28
|
-
}
|
29
|
-
|
30
|
-
export async function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
|
31
|
-
return Promise.all(filters.map(async filter => getSelectedProjectsGraph(filter)))
|
32
|
-
}
|
33
|
-
|
34
|
-
export async function getSelectedProjectsGraph(
|
35
|
-
filter = program.getOptionValue('filter') as string | undefined
|
36
|
-
): Promise<ProjectsGraph> {
|
37
|
-
const { wd, notWorkspace } = getWD()
|
38
|
-
let root = getRoot()
|
39
|
-
if (notWorkspace) {
|
40
|
-
return {
|
41
|
-
root,
|
42
|
-
value: {
|
43
|
-
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8')) as Manifest
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
if (type === 'pnpm') {
|
48
|
-
const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')
|
49
|
-
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')
|
50
|
-
const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {
|
51
|
-
packages: string[]
|
52
|
-
}
|
53
|
-
if (root === wd && (filter == null)) {
|
54
|
-
throw new Error('root path is workspace root, please provide a filter')
|
55
|
-
// TODO inquirer prompt support user select packages
|
56
|
-
}
|
57
|
-
if (root === undefined) {
|
58
|
-
root = process.cwd()
|
59
|
-
}
|
60
|
-
if (root !== wd && (filter == null)) {
|
61
|
-
const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))
|
62
|
-
if (!packageJSONIsExist) {
|
63
|
-
throw new Error('root path is not workspace root, please provide a filter')
|
64
|
-
}
|
65
|
-
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8')) as Manifest
|
66
|
-
if (packageJSON.name == null) {
|
67
|
-
throw new Error('root path is not workspace root, please provide a filter')
|
68
|
-
}
|
69
|
-
filter = packageJSON.name
|
70
|
-
}
|
71
|
-
const { filterPackagesFromDir } = await import('@pnpm/filter-workspace-packages')
|
72
|
-
const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
|
73
|
-
filter: filter ?? '',
|
74
|
-
followProdDepsOnly: true
|
75
|
-
}], {
|
76
|
-
prefix: root,
|
77
|
-
workspaceDir: wd,
|
78
|
-
patterns: pnpmWorkspace.packages
|
79
|
-
})
|
80
|
-
return {
|
81
|
-
root,
|
82
|
-
value: Object.entries(selectedProjectsGraph)
|
83
|
-
.reduce((acc, [key, value]) => {
|
84
|
-
acc[key] = value.package.manifest
|
85
|
-
return acc
|
86
|
-
}, {} as NonNullable<ProjectsGraph['value']>)
|
87
|
-
}
|
88
|
-
}
|
89
|
-
throw new Error(`not supported package manager ${type}`)
|
90
|
-
}
|
package/src/utils/getRoot.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import path from 'node:path'
|
2
|
-
|
3
|
-
let root: string | undefined
|
4
|
-
export function getRoot() {
|
5
|
-
if (root) return root
|
6
|
-
|
7
|
-
const rootOption = process.env.JIEK_ROOT
|
8
|
-
root = rootOption
|
9
|
-
? path.isAbsolute(rootOption)
|
10
|
-
? rootOption
|
11
|
-
: path.resolve(process.cwd(), rootOption)
|
12
|
-
: undefined
|
13
|
-
return root
|
14
|
-
}
|
package/src/utils/getWD.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import { getWorkspaceDir, isWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
|
2
|
-
|
3
|
-
import { type } from './filterSupport'
|
4
|
-
import { getRoot } from './getRoot'
|
5
|
-
|
6
|
-
let wd: string
|
7
|
-
let notWorkspace = false
|
8
|
-
|
9
|
-
export function getWD() {
|
10
|
-
if (wd) return { wd, notWorkspace }
|
11
|
-
|
12
|
-
const root = getRoot()
|
13
|
-
if (root !== undefined) {
|
14
|
-
const isWorkspace = isWorkspaceDir(root, type)
|
15
|
-
notWorkspace = !isWorkspace
|
16
|
-
wd = root
|
17
|
-
return { wd, notWorkspace }
|
18
|
-
}
|
19
|
-
try {
|
20
|
-
wd = getWorkspaceDir(type)
|
21
|
-
} catch (e) {
|
22
|
-
// @ts-ignore
|
23
|
-
if ('message' in e && e.message === 'workspace root not found') {
|
24
|
-
wd = root ?? process.cwd()
|
25
|
-
notWorkspace = true
|
26
|
-
} else {
|
27
|
-
throw e
|
28
|
-
}
|
29
|
-
}
|
30
|
-
return { wd, notWorkspace }
|
31
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export const intersection = <T>(a: Iterable<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))
|