jiek 1.1.3 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.3",
4
+ "version": "1.1.5",
5
5
  "description": "YiJie's personal kits.",
6
6
  "bin": {
7
7
  "jiek": "bin/jiek.js",
@@ -40,15 +40,21 @@ program
40
40
  .description(description)
41
41
  .option('-s, --silent', "Don't display logs.")
42
42
  .option('-e, --entries <ENTRIES>', "Specify the entries of the package.json's 'exports' field.(support glob)")
43
+ .option('--without-js', 'Do not output js files.')
44
+ .option('--without-dts', 'Do not output dts files.')
43
45
  .option('-v, --verbose', 'Display debug logs.')
44
46
  .action(async ({
45
47
  silent,
46
48
  entries,
47
- verbose
49
+ verbose,
50
+ withoutJs,
51
+ withoutDts
48
52
  }: {
49
53
  silent: boolean
50
54
  entries: string
51
55
  verbose: boolean
56
+ withoutJs: boolean
57
+ withoutDts: boolean
52
58
  }) => {
53
59
  actionRestore()
54
60
  const { build } = loadConfig()
@@ -97,7 +103,9 @@ program
97
103
  env: {
98
104
  ...process.env,
99
105
  JIEK_ROOT: wd,
100
- JIEK_ENTRIES: entries
106
+ JIEK_ENTRIES: entries,
107
+ JIEK_WITHOUT_JS: String(withoutJs),
108
+ JIEK_WITHOUT_DTS: String(withoutDts)
101
109
  }
102
110
  })
103
111
  const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
@@ -15,6 +15,8 @@ export interface ConfigGenerateContext {
15
15
  conditionals: string[]
16
16
  }
17
17
 
18
+ export type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean)
19
+
18
20
  export interface TemplateOptions {
19
21
  /**
20
22
  * When the user configures type: module, the generated output from entry points that don't
@@ -39,6 +41,8 @@ export interface TemplateOptions {
39
41
  dir?: Mapping2ROO<'dir'>
40
42
  sourcemap?: Mapping2ROO<'sourcemap'>
41
43
  strict?: Mapping2ROO<'strict'>
44
+ js?: OutputControl
45
+ dts?: OutputControl
42
46
  }
43
47
  plugins?:
44
48
  | InputPluginOption
@@ -33,13 +33,17 @@ interface PackageJSON {
33
33
 
34
34
  const {
35
35
  JIEK_ROOT,
36
- JIEK_ENTRIES
36
+ JIEK_ENTRIES,
37
+ JIEK_WITHOUT_JS,
38
+ JIEK_WITHOUT_DTS
37
39
  } = process.env
38
40
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir()
39
41
  const COMMON_OPTIONS = {} satisfies RollupOptions
40
42
  const COMMON_PLUGINS = [
41
43
  json()
42
44
  ]
45
+ const WITHOUT_JS = JIEK_WITHOUT_JS === 'true'
46
+ const WITHOUT_DTS = JIEK_WITHOUT_DTS === 'true'
43
47
 
44
48
  const config = loadConfig({
45
49
  root: WORKSPACE_ROOT
@@ -88,6 +92,22 @@ const resolveBuildPlugins = (context: ConfigGenerateContext, plugins: TemplateOp
88
92
  return { js, dts }
89
93
  }
90
94
 
95
+ const resolveOutputControls = (
96
+ context: ConfigGenerateContext,
97
+ output: TemplateOptions['output']
98
+ ): { js: boolean; dts: boolean } => ({
99
+ js: typeof output?.js === 'boolean'
100
+ ? output.js
101
+ : typeof output?.js === 'function'
102
+ ? output.js(context)
103
+ : true,
104
+ dts: typeof output?.dts === 'boolean'
105
+ ? output.dts
106
+ : typeof output?.dts === 'function'
107
+ ? output.dts(context)
108
+ : true
109
+ })
110
+
91
111
  const resolveWorkspacePath = (p: string) => resolve(WORKSPACE_ROOT, p)
92
112
 
93
113
  const pascalCase = (str: string) =>
@@ -212,8 +232,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
212
232
  }
213
233
  const jsOutputSuffix = extname(output)
214
234
  const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, '.d$1ts')
215
- return [
216
- {
235
+ const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output)
236
+ const rollupOptions: RollupOptions[] = []
237
+ if (jsOutput && !WITHOUT_JS) {
238
+ rollupOptions.push({
217
239
  input: inputObj,
218
240
  external,
219
241
  output: [
@@ -268,8 +290,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
268
290
  }),
269
291
  jsPlugins
270
292
  ]
271
- },
272
- {
293
+ })
294
+ }
295
+ if (dtsOutput && !WITHOUT_DTS) {
296
+ rollupOptions.push({
273
297
  input: inputObj,
274
298
  external,
275
299
  output: [
@@ -304,7 +328,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
304
328
  outDir: 'dist',
305
329
  declaration: true,
306
330
  // https://github.com/Swatinem/rollup-plugin-dts/issues/143
307
- preserveSymlinks: false
331
+ preserveSymlinks: false,
332
+ // Expected '{', got 'type' (Note that you need plugins to import files that are not JavaScript)
333
+ // https://github.com/Swatinem/rollup-plugin-dts/issues/96
334
+ noEmit: false
308
335
  }
309
336
  }),
310
337
  progress({
@@ -318,8 +345,9 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
318
345
  }),
319
346
  dtsPlugins
320
347
  ]
321
- }
322
- ]
348
+ })
349
+ }
350
+ return rollupOptions
323
351
  }
324
352
 
325
353
  export function template(packageJSON: PackageJSON): RollupOptions[] {
@@ -1,4 +1,5 @@
1
1
  import fs from 'node:fs'
2
+ import { builtinModules } from 'node:module'
2
3
 
3
4
  const EXCLUDE_SUFFIX = [
4
5
  'te?xt',
@@ -18,11 +19,14 @@ export default function(jsonOrPath: string | Record<string, unknown> = process.c
18
19
  if (!name) {
19
20
  throw new Error('package.json must have a name field')
20
21
  }
22
+
21
23
  const external = <(string | RegExp)[]> Object
22
24
  .keys(dependencies)
23
25
  .concat(Object.keys(peerDependencies))
24
26
  .concat(Object.keys(optionalDependencies))
25
- return external
27
+ .concat(builtinModules)
28
+
29
+ return [...new Set(external)]
26
30
  .map(dep => new RegExp(`^${dep}(/.*)?$`))
27
31
  .concat([
28
32
  new RegExp(`^${name}(/.*)?(?<!${EXCLUDE_SUFFIX.map(suffix => `\\.${suffix}`).join('|')})$`),