jiek 2.1.10 → 2.1.12

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,21 +1,15 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "2.1.10",
4
+ "version": "2.1.12",
5
5
  "description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
6
6
  "author": "YiJie <yijie4188@gmail.com>",
7
+ "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
7
8
  "repository": {
8
9
  "url": "nwylzw/jiek",
9
10
  "directory": "packages/jiek"
10
11
  },
11
- "homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
12
12
  "bugs": "https://github.com/NWYLZW/jiek/issues?q=is%3Aissue+is%3Aopen+jiek",
13
- "bin": {
14
- "jiek": "bin/jiek.js",
15
- "jk": "bin/jiek.js",
16
- "jiek-build": "bin/jiek-build.js",
17
- "jb": "bin/jiek-build.js"
18
- },
19
13
  "exports": {
20
14
  "./package.json": "./package.json",
21
15
  ".": {
@@ -23,6 +17,10 @@
23
17
  "require": "./dist/index.cjs",
24
18
  "default": "./dist/index.js"
25
19
  },
20
+ "./bin-helper": {
21
+ "require": "./bin-helper.cjs",
22
+ "default": "./bin-helper.js"
23
+ },
26
24
  "./cli": {
27
25
  "jiek/__source__": "./src/cli.ts",
28
26
  "require": "./dist/cli.cjs",
@@ -42,54 +40,46 @@
42
40
  "imports": {
43
41
  "#~/*": "./src/*"
44
42
  },
43
+ "bin": {
44
+ "jiek": "bin/jiek.js",
45
+ "jk": "bin/jiek.js",
46
+ "jiek-build": "bin/jiek-build.js",
47
+ "jb": "bin/jiek-build.js"
48
+ },
49
+ "peerDependencies": {
50
+ "@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0",
51
+ "@rollup/plugin-terser": "^0.4.4",
52
+ "esbuild-register": "^3.5.0",
53
+ "postcss": "^8.4.47",
54
+ "rollup-plugin-esbuild": "^6.1.0",
55
+ "rollup-plugin-postcss": "^4.0.2",
56
+ "rollup-plugin-swc3": "^0.12.1",
57
+ "typescript": "^4.0.0||^5.0.0",
58
+ "vite-bundle-analyzer": "^0.15.1"
59
+ },
45
60
  "dependencies": {
46
- "@jiek/rollup-plugin-dts": "^6.2.1",
47
61
  "@inquirer/prompts": "^7.1.0",
62
+ "@jiek/rollup-plugin-dts": "^6.2.1",
48
63
  "@rollup/plugin-commonjs": "^28.0.0",
64
+ "@rollup/plugin-inject": "^5.0.5",
49
65
  "@rollup/plugin-json": "^6.0.1",
50
66
  "@rollup/plugin-node-resolve": "^15.3.0",
67
+ "@rollup/plugin-replace": "^6.0.1",
51
68
  "cli-progress": "^3.12.0",
52
69
  "commander": "^12.0.0",
53
70
  "detect-indent": "^6.1.0",
54
- "execa": "9.3.1",
71
+ "execa": "~9.3.1",
55
72
  "js-yaml": "^4.1.0",
56
73
  "jsonc-parser": "^3.2.1",
57
- "rollup": "4.13.2",
74
+ "rollup": "^4.0.0",
58
75
  "@jiek/pkger": "^0.2.1",
59
76
  "@jiek/utils": "^0.2.3"
60
77
  },
61
- "peerDependencies": {
62
- "@rollup/plugin-terser": "^0.4.4",
63
- "@pnpm/filter-workspace-packages": "^7.2.13",
64
- "esbuild-register": "^3.5.0",
65
- "postcss": "^8.4.47",
66
- "rollup-plugin-postcss": "^4.0.2",
67
- "rollup-plugin-esbuild": "^6.1.0",
68
- "rollup-plugin-swc3": "^0.12.1",
69
- "typescript": "^4.0.0||^5.0.0"
70
- },
71
- "devDependencies": {
72
- "@npm/types": "^1.0.2",
73
- "@pnpm/filter-workspace-packages": "^7.2.13",
74
- "@pnpm/workspace.pkgs-graph": "^2.0.15",
75
- "@rollup/plugin-terser": "^0.4.4",
76
- "@types/cli-progress": "^3.11.5",
77
- "@types/inquirer": "^9.0.7",
78
- "@types/js-yaml": "^4.0.9",
79
- "@types/micromatch": "^4.0.6",
80
- "esbuild-register": "^3.5.0",
81
- "micromatch": "^4.0.5",
82
- "node-sass": "^9.0.0",
83
- "postcss": "^8.4.47",
84
- "rollup-plugin-postcss": "^4.0.2",
85
- "rollup-plugin-esbuild": "^6.1.0",
86
- "rollup-plugin-swc3": "^0.12.1"
87
- },
88
78
  "peerDependenciesMeta": {
89
- "@rollup/plugin-terser": {
79
+ "@pnpm/filter-workspace-packages": {
90
80
  "optional": true
91
81
  },
92
- "@pnpm/filter-workspace-packages": {
82
+ "@rollup/plugin-terser": {
93
83
  "optional": true
94
84
  },
95
85
  "esbuild-register": {
@@ -98,10 +88,10 @@
98
88
  "postcss": {
99
89
  "optional": true
100
90
  },
101
- "rollup-plugin-postcss": {
91
+ "rollup-plugin-esbuild": {
102
92
  "optional": true
103
93
  },
104
- "rollup-plugin-esbuild": {
94
+ "rollup-plugin-postcss": {
105
95
  "optional": true
106
96
  },
107
97
  "rollup-plugin-swc3": {
@@ -109,6 +99,9 @@
109
99
  },
110
100
  "typescript": {
111
101
  "optional": true
102
+ },
103
+ "vite-bundle-analyzer": {
104
+ "optional": true
112
105
  }
113
106
  },
114
107
  "scripts": {
File without changes
@@ -2,8 +2,10 @@ import './utils/filterSupport'
2
2
  import './commands/base'
3
3
  import './commands/build'
4
4
 
5
+ import parseArgv from './parseArgv'
6
+
7
+ import process from 'node:process'
8
+
5
9
  if (process.env.JIEK_IS_ONLY_BUILD === 'true') {
6
- import('commander').then(({ program }) => {
7
- program.parse(process.argv)
8
- })
10
+ parseArgv()
9
11
  }
package/src/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import './commands/publish'
2
2
  import 'jiek/cli-only-build'
3
3
 
4
- import { program } from 'commander'
4
+ import parseArgv from './parseArgv'
5
5
 
6
- program.parse(process.argv)
6
+ parseArgv()
@@ -10,6 +10,7 @@ program
10
10
  .version(pkg.version)
11
11
  .description(`${pkg.description} - Version ${pkg.version}`)
12
12
  .option('-c, --config-path <configPath>', 'Custom jiek config path')
13
+ .option('--env.<name>=<value>', 'Set the environment variable.')
13
14
 
14
15
  if (type !== '' && IS_WORKSPACE) {
15
16
  program
@@ -1,6 +1,7 @@
1
- import fs from 'node:fs'
1
+ import fs, { existsSync, statSync } from 'node:fs'
2
2
  import { createRequire } from 'node:module'
3
3
  import path from 'node:path'
4
+ import process from 'node:process'
4
5
 
5
6
  import { confirm } from '@inquirer/prompts'
6
7
  import { MultiBar, Presets } from 'cli-progress'
@@ -16,7 +17,7 @@ import { loadConfig } from '#~/utils/loadConfig.ts'
16
17
  import { tsRegisterName } from '#~/utils/tsRegister.ts'
17
18
 
18
19
  import type { RollupProgressEvent, TemplateOptions } from '../rollup/base'
19
- import { BUILDER_TYPE_PACKAGE_NAME_MAP, BUILDER_TYPES } from '../rollup/base'
20
+ import { BUILDER_TYPES, BUILDER_TYPE_PACKAGE_NAME_MAP } from '../rollup/base'
20
21
 
21
22
  declare module 'jiek' {
22
23
  export interface Config {
@@ -46,6 +47,21 @@ ${isDefault ? 'This command is the default command.' : ''}
46
47
  `.trim()
47
48
 
48
49
  interface BuildOptions {
50
+ ana?: boolean
51
+ /**
52
+ * @default '.jk-analyses'
53
+ */
54
+ 'ana.dir': string
55
+ /**
56
+ * @default 'server'
57
+ */
58
+ 'ana.mode': string
59
+ 'ana.port'?: number
60
+ 'ana.open'?: boolean
61
+ /**
62
+ * @default 'parsed'
63
+ */
64
+ 'ana.size': string
49
65
  /**
50
66
  * Auto-detect the builder from the installed dependencies.
51
67
  * If the builder is not installed, it will prompt the user to install it.
@@ -99,7 +115,7 @@ interface BuildOptions {
99
115
  async function checkDependency(dependency: string) {
100
116
  try {
101
117
  require.resolve(dependency)
102
- } catch (e) {
118
+ } catch {
103
119
  console.error(`The package '${dependency}' is not installed, please install it first.`)
104
120
  const { notWorkspace } = getWD()
105
121
  const command = `pnpm install -${notWorkspace ? '' : 'w'}D ${dependency}`
@@ -138,7 +154,7 @@ ${entriesDescription}
138
154
  If you pass the --entries option, it will merge into the entries of the command.
139
155
  `.trim()
140
156
 
141
- const command = isDefault
157
+ let command = isDefault
142
158
  ? (() => {
143
159
  const c = program
144
160
  .name('jb/jiek-build')
@@ -153,9 +169,10 @@ const command = isDefault
153
169
  : program
154
170
  .command(`build [${IS_WORKSPACE ? 'filters' : 'entries'}]`)
155
171
 
156
- command
172
+ command = command
157
173
  .description(description)
158
174
  .option('-t, --type <TYPE>', `The type of build, support ${BUILDER_TYPES.map(s => `"${s}"`).join(', ')}.`, v => {
175
+ // eslint-disable-next-line ts/no-unsafe-argument
159
176
  if (!BUILDER_TYPES.includes(v as any)) {
160
177
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map(s => `"${s}"`).join(', ')}`)
161
178
  }
@@ -183,13 +200,32 @@ command
183
200
  'Only output minify files, but dts files will still be output, it only replaces the js files.',
184
201
  parseBoolean
185
202
  )
203
+
204
+ command = command
186
205
  .option('--tsconfig <TSCONFIG>', 'The path of the tsconfig file which is used to generate js and dts files.', String)
187
206
  .option('--dtsconfig <DTSCONFIG>', 'The path of the tsconfig file which is used to generate dts files.', String)
207
+
208
+ command = command
188
209
  .option('-w, --watch', 'Watch the file changes.', parseBoolean)
210
+
211
+ command = command
212
+ .option('--ana', 'Enable the bundle analyzer.', parseBoolean)
213
+ .option('--ana.dir <DIR>', 'The directory of the bundle analyzer.', '.jk-analyses')
214
+ .option('--ana.mode <MODE>', 'The mode of the bundle analyzer, support "static", "json" and "server".', 'server')
215
+ .option('--ana.port <PORT>', 'The port of the bundle analyzer.', Number.parseInt)
216
+ .option('--ana.open', 'Open the bundle analyzer in the browser.', parseBoolean)
217
+ .option(
218
+ '--ana.size <SIZE>',
219
+ 'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
220
+ 'parsed'
221
+ )
222
+
223
+ command = command
189
224
  .option('-s, --silent', "Don't display logs.", parseBoolean)
190
225
  .option('-v, --verbose', 'Display debug logs.', parseBoolean)
226
+
227
+ command
191
228
  .action(async (commandFiltersOrEntries: string | undefined, options: BuildOptions) => {
192
- /* eslint-disable prefer-const */
193
229
  let {
194
230
  type,
195
231
  outdir,
@@ -207,10 +243,9 @@ command
207
243
  tsconfig,
208
244
  dtsconfig
209
245
  } = options
210
- /* eslint-enable prefer-const */
211
246
  const resolvedType = type ?? DEFAULT_BUILDER_TYPE
212
247
  if (!withoutJs) {
213
- await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType]!)
248
+ await checkDependency(BUILDER_TYPE_PACKAGE_NAME_MAP[resolvedType])
214
249
  if (minifyType === 'builder') {
215
250
  minifyType = resolvedType
216
251
  }
@@ -220,7 +255,7 @@ command
220
255
  {
221
256
  ...BUILDER_TYPE_PACKAGE_NAME_MAP,
222
257
  terser: '@rollup/plugin-terser'
223
- }[resolvedType]!
258
+ }[resolvedType]
224
259
  )
225
260
  }
226
261
  let shouldPassThrough = false
@@ -238,6 +273,21 @@ command
238
273
  },
239
274
  [] as string[]
240
275
  )
276
+
277
+ const analyzer = options.ana
278
+ ? {
279
+ dir: options['ana.dir'],
280
+ mode: options['ana.mode'],
281
+ port: options['ana.port'],
282
+ open: options['ana.open'],
283
+ size: options['ana.size']
284
+ }
285
+ : undefined
286
+
287
+ if (analyzer) {
288
+ await checkDependency('vite-bundle-analyzer')
289
+ }
290
+
241
291
  const { build } = loadConfig()
242
292
  silent = silent ?? build?.silent ?? false
243
293
 
@@ -256,7 +306,7 @@ command
256
306
  entries = undefined
257
307
  }
258
308
  const env = {
259
- ...process.env,
309
+ JIEK_ANALYZER: analyzer && JSON.stringify(analyzer),
260
310
  JIEK_BUILDER: type,
261
311
  JIEK_OUT_DIR: outdir,
262
312
  JIEK_CLEAN: String(!noClean),
@@ -268,7 +318,8 @@ command
268
318
  JIEK_ONLY_MINIFY: String(onlyMin),
269
319
  JIEK_MINIFY_TYPE: minifyType,
270
320
  JIEK_TSCONFIG: tsconfig,
271
- JIEK_DTSCONFIG: dtsconfig
321
+ JIEK_DTSCONFIG: dtsconfig,
322
+ ...process.env
272
323
  }
273
324
 
274
325
  const multiBars = new MultiBar({
@@ -298,9 +349,26 @@ command
298
349
  let i = 0
299
350
  await Promise.all(
300
351
  Object.entries(value).map(async ([dir, manifest]) => {
301
- if (!manifest.name) {
352
+ if (manifest.name == null) {
302
353
  throw new Error('package.json must have a name field')
303
354
  }
355
+ if (analyzer) {
356
+ const anaDir = path.resolve(dir, analyzer.dir)
357
+ if (!existsSync(anaDir)) {
358
+ fs.mkdirSync(anaDir, { recursive: true })
359
+ }
360
+ const gitIgnorePath = path.resolve(anaDir, '.gitignore')
361
+ if (!existsSync(gitIgnorePath)) {
362
+ fs.writeFileSync(gitIgnorePath, '*\n!.gitignore\n')
363
+ }
364
+ const npmIgnorePath = path.resolve(anaDir, '.npmignore')
365
+ if (!existsSync(npmIgnorePath)) {
366
+ fs.writeFileSync(npmIgnorePath, '*\n')
367
+ }
368
+ if (!statSync(anaDir).isDirectory()) {
369
+ throw new Error(`The directory '${anaDir}' is not a directory.`)
370
+ }
371
+ }
304
372
 
305
373
  // TODO support auto build child packages in workspaces
306
374
  const escapeManifestName = manifest.name.replace(/^@/g, '').replace(/\//g, '+')
@@ -309,7 +377,7 @@ command
309
377
  )
310
378
  fs.writeFileSync(configFile, FILE_TEMPLATE(manifest))
311
379
  const command = [rollupBinaryPath, '--silent', '-c', configFile]
312
- if (tsRegisterName) {
380
+ if (tsRegisterName != null) {
313
381
  command.unshift(`node -r ${tsRegisterName}`)
314
382
  }
315
383
  if (watch) {
@@ -330,6 +398,7 @@ command
330
398
  const locks: Record<string, boolean> = {}
331
399
  let inputMaxLen = 10
332
400
  child.on('message', (e: RollupProgressEvent) => {
401
+ // eslint-disable-next-line no-console,ts/no-unsafe-argument
333
402
  if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
334
403
  })
335
404
  !silent && child.on('message', (e: RollupProgressEvent) => {
@@ -348,12 +417,14 @@ command
348
417
  if (watch) {
349
418
  initMessage += ' and watching...'
350
419
  }
420
+ // eslint-disable-next-line no-console
351
421
  console.log(initMessage)
352
422
  leafs.forEach(({ input }) => {
353
423
  inputMaxLen = Math.max(inputMaxLen, input.length)
354
424
  })
355
425
  leafs.forEach(({ input, path }) => {
356
426
  const key = `${input}:${path}`
427
+ // eslint-disable-next-line ts/strict-boolean-expressions
357
428
  if (bars[key]) return
358
429
  bars[key] = multiBars.create(50, 0, {
359
430
  pkgName: manifest.name,
@@ -374,6 +445,7 @@ command
374
445
  message
375
446
  } = e.data
376
447
  const bar = bars[`${input}:${path}`]
448
+ // eslint-disable-next-line ts/strict-boolean-expressions
377
449
  if (!bar) return
378
450
  const time = times[`${input}:${path}`]
379
451
  bar.update(
@@ -400,6 +472,7 @@ command
400
472
  } = e.data
401
473
  const key = `${input}:${path}`
402
474
  const bar = bars[key]
475
+ // eslint-disable-next-line ts/strict-boolean-expressions
403
476
  if (!bar) return
404
477
  let time = times[key] ?? 1
405
478
  if (!locks[key]) {
@@ -216,6 +216,17 @@ async function prepublish() {
216
216
  }
217
217
  }
218
218
  }
219
+ if (oldJSON['devDependencies']) {
220
+ newJSONString = applyEdits(
221
+ newJSONString,
222
+ modify(
223
+ newJSONString,
224
+ ['devDependencies'],
225
+ undefined,
226
+ { formattingOptions }
227
+ )
228
+ )
229
+ }
219
230
  if (oldJSON['peerDependencies']) {
220
231
  const peerDependenciesMeta = Object.keys(oldJSON['peerDependencies']).reduce(
221
232
  (acc, key) => {
@@ -0,0 +1,26 @@
1
+ import { program } from 'commander'
2
+ import process from 'node:process'
3
+
4
+ const { argv } = process
5
+ const env: Record<string, string> = {}
6
+ let isPassThrough = false
7
+ const newArgv = argv.filter((arg) => {
8
+ if (isPassThrough) {
9
+ return true
10
+ }
11
+ if (arg === '--') {
12
+ isPassThrough = true
13
+ return false
14
+ }
15
+ const m = /^--env\.(\w+)=(.*)$/.exec(arg)
16
+ if (m) {
17
+ env[m[1]] = m[2]
18
+ return false
19
+ }
20
+ return true
21
+ })
22
+ for (const [key, value] of Object.entries(env)) {
23
+ process.env[key] = value
24
+ }
25
+
26
+ export default () => program.parse(newArgv)