jiek 1.1.5 → 1.1.7-alpha.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.5",
4
+ "version": "1.1.7-alpha.1",
5
5
  "description": "YiJie's personal kits.",
6
6
  "bin": {
7
7
  "jiek": "bin/jiek.js",
@@ -58,7 +58,7 @@
58
58
  "inquirer": "^8.2.6",
59
59
  "js-yaml": "^4.1.0",
60
60
  "jsonc-parser": "^3.2.1",
61
- "rollup": "^4.1.5",
61
+ "rollup": "4.13.2",
62
62
  "rollup-plugin-esbuild": "^6.1.0",
63
63
  "typescript": "^5.0.0",
64
64
  "@jiek/pkger": "^0.2.0",
@@ -84,6 +84,9 @@
84
84
  "postcss": "^8.4.47",
85
85
  "rollup-plugin-postcss": "^4.0.2"
86
86
  },
87
+ "scripts": {
88
+ "prepublish": "jk build"
89
+ },
87
90
  "main": "./dist/index.cjs",
88
91
  "module": "./dist/index.js"
89
92
  }
@@ -8,7 +8,8 @@ import { execaCommand } from 'execa'
8
8
 
9
9
  import { actionDone, actionRestore } from '../inner'
10
10
  import type { RollupProgressEvent, TemplateOptions } from '../rollup/base'
11
- import { getSelectedProjectsGraph } from '../utils/filterSupport'
11
+ import { getSelectedProjectsGraph, ProjectsGraph } from '../utils/filterSupport'
12
+ import { filterPackagesGraph } from '../utils/filterSupport'
12
13
  import { loadConfig } from '../utils/loadConfig'
13
14
  import { tsRegisterName } from '../utils/tsRegister'
14
15
 
@@ -59,127 +60,139 @@ program
59
60
  actionRestore()
60
61
  const { build } = loadConfig()
61
62
  silent = silent ?? build?.silent ?? false
62
- const {
63
- wd,
64
- value = {}
65
- } = await getSelectedProjectsGraph() ?? {}
66
-
67
- if (Object.keys(value).length === 0) {
68
- throw new Error('no package found')
69
- }
70
- const wdNodeModules = path.resolve(wd, 'node_modules')
71
- if (!fs.existsSync(wdNodeModules)) {
72
- fs.mkdirSync(wdNodeModules)
73
- }
74
- const jiekTempDir = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
75
- if (!fs.existsSync(jiekTempDir())) {
76
- fs.mkdirSync(jiekTempDir())
77
- }
78
63
 
79
- const rollupBinaryPath = require.resolve('rollup')
80
- .replace(/dist\/rollup.js$/, 'dist/bin/rollup')
81
64
  const multiBars = new MultiBar({
82
65
  clearOnComplete: false,
83
66
  hideCursor: true,
84
- format: '- {bar} | {status} | {input} | {message}'
67
+ format: '- {bar} | {status} | {pkgName} | {input} | {message}'
85
68
  }, Presets.shades_classic)
86
- let i = 0
87
- await Promise.all(
88
- Object.entries(value).map(async ([dir, manifest]) => {
89
- // TODO support auto build child packages in workspaces
90
- const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\//g, '+')
91
- const configFile = jiekTempDir(
92
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
93
- )
94
- fs.writeFileSync(configFile, FILE_TEMPLATE(manifest))
95
- let prefix = ''
96
- if (tsRegisterName) {
97
- prefix = `node -r ${tsRegisterName} `
98
- }
99
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`
100
- const child = execaCommand(command, {
101
- ipc: true,
102
- cwd: dir,
103
- env: {
104
- ...process.env,
105
- JIEK_ROOT: wd,
106
- JIEK_ENTRIES: entries,
107
- JIEK_WITHOUT_JS: String(withoutJs),
108
- JIEK_WITHOUT_DTS: String(withoutDts)
69
+
70
+ const buildPackage = async ({
71
+ wd,
72
+ value = {}
73
+ }: ProjectsGraph) => {
74
+ if (Object.keys(value).length === 0) {
75
+ throw new Error('no package found')
76
+ }
77
+ const wdNodeModules = path.resolve(wd, 'node_modules')
78
+ if (!fs.existsSync(wdNodeModules)) {
79
+ fs.mkdirSync(wdNodeModules)
80
+ }
81
+ const jiekTempDir = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
82
+ if (!fs.existsSync(jiekTempDir())) {
83
+ fs.mkdirSync(jiekTempDir())
84
+ }
85
+
86
+ const rollupBinaryPath = require.resolve('rollup')
87
+ .replace(/dist\/rollup.js$/, 'dist/bin/rollup')
88
+ let i = 0
89
+ await Promise.all(
90
+ Object.entries(value).map(async ([dir, manifest]) => {
91
+ // TODO support auto build child packages in workspaces
92
+ const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\//g, '+')
93
+ const configFile = jiekTempDir(
94
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
95
+ )
96
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest))
97
+ let prefix = ''
98
+ if (tsRegisterName) {
99
+ prefix = `node -r ${tsRegisterName} `
109
100
  }
110
- })
111
- const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
112
- let inputMaxLen = 10
113
- child.on('message', (e: RollupProgressEvent) => {
114
- if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
115
- })
116
- !silent && child.on('message', (e: RollupProgressEvent) => {
117
- if (e.type === 'init') {
118
- const { leafMap, targetsLength } = e.data
119
- const leafs = Array
120
- .from(leafMap.entries())
121
- .flatMap(([input, pathAndCondiions]) =>
122
- pathAndCondiions.map(([path, ...conditions]) => ({
123
- input,
124
- path,
125
- conditions
126
- }))
127
- )
128
- console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`)
129
- leafs.forEach(({ input }) => {
130
- inputMaxLen = Math.max(inputMaxLen, input.length)
131
- })
132
- leafs.forEach(({ input, path }) => {
133
- const key = `${input}:${path}`
134
- if (bars[key]) return
135
- bars[key] = multiBars.create(50, 0, {
136
- input: input.padEnd(inputMaxLen),
137
- status: 'waiting'.padEnd(10)
138
- }, {
139
- barsize: 20,
140
- linewrap: true
101
+ const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`
102
+ const child = execaCommand(command, {
103
+ ipc: true,
104
+ cwd: dir,
105
+ env: {
106
+ ...process.env,
107
+ JIEK_ROOT: wd,
108
+ JIEK_ENTRIES: entries,
109
+ JIEK_WITHOUT_JS: String(withoutJs),
110
+ JIEK_WITHOUT_DTS: String(withoutDts)
111
+ }
112
+ })
113
+ const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
114
+ let inputMaxLen = 10
115
+ child.on('message', (e: RollupProgressEvent) => {
116
+ if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
117
+ })
118
+ !silent && child.on('message', (e: RollupProgressEvent) => {
119
+ if (e.type === 'init') {
120
+ const { leafMap, targetsLength } = e.data
121
+ const leafs = Array
122
+ .from(leafMap.entries())
123
+ .flatMap(([input, pathAndCondiions]) =>
124
+ pathAndCondiions.map(([path, ...conditions]) => ({
125
+ input,
126
+ path,
127
+ conditions
128
+ }))
129
+ )
130
+ console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`)
131
+ leafs.forEach(({ input }) => {
132
+ inputMaxLen = Math.max(inputMaxLen, input.length)
133
+ })
134
+ leafs.forEach(({ input, path }) => {
135
+ const key = `${input}:${path}`
136
+ if (bars[key]) return
137
+ bars[key] = multiBars.create(50, 0, {
138
+ pkgName: manifest.name,
139
+ input: input.padEnd(inputMaxLen),
140
+ status: 'waiting'.padEnd(10)
141
+ }, {
142
+ barsize: 20,
143
+ linewrap: true
144
+ })
141
145
  })
146
+ }
147
+ if (e.type === 'progress') {
148
+ const {
149
+ path,
150
+ tags,
151
+ input,
152
+ event,
153
+ message
154
+ } = e.data
155
+ const bar = bars[`${input}:${path}`]
156
+ if (!bar) return
157
+ bar.update(
158
+ {
159
+ start: 0,
160
+ resolve: 20,
161
+ end: 50
162
+ }[event ?? 'start'] ?? 0,
163
+ {
164
+ input: input.padEnd(inputMaxLen),
165
+ status: event?.padEnd(10),
166
+ message: `${tags?.join(', ')}: ${message}`
167
+ }
168
+ )
169
+ }
170
+ })
171
+ await new Promise<void>((resolve, reject) => {
172
+ let errorStr = ''
173
+ child.stderr?.on('data', (data) => {
174
+ errorStr += data
142
175
  })
143
- }
144
- if (e.type === 'progress') {
145
- const {
146
- path,
147
- tags,
148
- input,
149
- event,
150
- message
151
- } = e.data
152
- const bar = bars[`${input}:${path}`]
153
- if (!bar) return
154
- bar.update(
155
- {
156
- start: 0,
157
- resolve: 20,
158
- end: 50
159
- }[event ?? 'start'] ?? 0,
160
- {
161
- input: input.padEnd(inputMaxLen),
162
- status: event?.padEnd(10),
163
- message: `${tags?.join(', ')}: ${message}`
164
- }
165
- )
166
- }
167
- })
168
- await new Promise<void>((resolve, reject) => {
169
- let errorStr = ''
170
- child.stderr?.on('data', (data) => {
171
- errorStr += data
176
+ child.once('exit', (code) =>
177
+ code === 0
178
+ ? resolve()
179
+ : reject(new Error(`rollup build failed:\n${errorStr}`)))
180
+ verbose && child.stdout?.pipe(process.stdout)
172
181
  })
173
- child.once('exit', (code) =>
174
- code === 0
175
- ? resolve()
176
- : reject(new Error(`rollup build failed:\n${errorStr}`)))
177
- verbose && child.stdout?.pipe(process.stdout)
178
182
  })
179
- })
180
- ).finally(() => {
183
+ )
184
+ }
185
+ const filters = (program.getOptionValue('filter') as string | undefined)?.split(',')
186
+ try {
187
+ if (filters) {
188
+ const packages = await filterPackagesGraph(filters)
189
+ await Promise.all(packages.map(buildPackage))
190
+ } else {
191
+ await buildPackage(await getSelectedProjectsGraph())
192
+ }
193
+ } finally {
181
194
  multiBars.stop()
182
- })
195
+ }
183
196
 
184
197
  actionDone()
185
198
  })
@@ -2,7 +2,7 @@ import * as childProcess from 'node:child_process'
2
2
  import fs from 'node:fs'
3
3
  import path from 'node:path'
4
4
 
5
- import { bump, type BumperType } from '@jiek/utils/bumper'
5
+ import { bump, type BumperType, TAGS } from '@jiek/utils/bumper'
6
6
  import { program } from 'commander'
7
7
  import detectIndent from 'detect-indent'
8
8
  import { applyEdits, modify } from 'jsonc-parser'
@@ -156,7 +156,11 @@ program
156
156
  console.warn('preview mode')
157
157
  continue
158
158
  }
159
- childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {
159
+ const args = ['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs]
160
+ if (bumper && TAGS.includes(bumper)) {
161
+ args.push('--tag', bumper)
162
+ }
163
+ childProcess.execSync(args.join(' '), {
160
164
  cwd: dir,
161
165
  stdio: 'inherit'
162
166
  })
@@ -18,10 +18,10 @@ try {
18
18
  } catch { /* empty */ }
19
19
  if (type !== '') {
20
20
  program
21
- .option('-f, --filter <filter>', 'filter packages')
21
+ .option('-f, --filter <filter>', 'filter packages, support fuzzy match and array. e.g. -f core,utils')
22
22
  }
23
23
 
24
- interface ProjectsGraph {
24
+ export interface ProjectsGraph {
25
25
  wd: string
26
26
  root: string
27
27
  value?: Record<string, {
@@ -31,11 +31,25 @@ interface ProjectsGraph {
31
31
  }>
32
32
  }
33
33
 
34
- export async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {
35
- let filter = program.getOptionValue('filter')
36
- const root = getRoot()
34
+ export function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
35
+ return Promise.all(filters.map(async filter => getSelectedProjectsGraph(filter)))
36
+ }
37
+
38
+ export async function getSelectedProjectsGraph(
39
+ filter = program.getOptionValue('filter')
40
+ ): Promise<ProjectsGraph> {
41
+ let root = getRoot()
37
42
  const { wd, notWorkspace } = getWD()
38
- if (!notWorkspace && type === 'pnpm') {
43
+ if (notWorkspace) {
44
+ return {
45
+ wd,
46
+ root,
47
+ value: {
48
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))
49
+ }
50
+ }
51
+ }
52
+ if (type === 'pnpm') {
39
53
  const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')
40
54
  const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')
41
55
  const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {
@@ -45,6 +59,9 @@ export async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {
45
59
  throw new Error('root path is workspace root, please provide a filter')
46
60
  // TODO inquirer prompt support user select packages
47
61
  }
62
+ if (root === undefined) {
63
+ root = process.cwd()
64
+ }
48
65
  if (root !== wd && !filter) {
49
66
  const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))
50
67
  if (!packageJSONIsExist) {
@@ -74,11 +91,5 @@ export async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {
74
91
  }, {} as NonNullable<ProjectsGraph['value']>)
75
92
  }
76
93
  }
77
- return {
78
- wd,
79
- root,
80
- value: {
81
- [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))
82
- }
83
- }
94
+ throw new Error(`not supported package manager ${type}`)
84
95
  }