jiek 2.2.7 → 2.3.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.
Files changed (100) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +19 -31
  4. package/dist/.internal/.chunks/filterSupport.4rM7f6jB.cjs +114 -0
  5. package/dist/.internal/.chunks/filterSupport.BXWpLBpT.js +104 -0
  6. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -737
  7. package/dist/.internal/.chunks/index.BHuJRlvZ.js +9059 -0
  8. package/dist/.internal/.chunks/index.Daihq2aI.cjs +9071 -0
  9. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -759
  10. package/dist/.internal/.chunks/loadConfig.CFfzkm_p.js +110 -0
  11. package/dist/.internal/.chunks/loadConfig.OOKddvHF.cjs +117 -0
  12. package/dist/{cli-only-build.cjs → .internal/bin/common.cjs} +229 -445
  13. package/dist/.internal/bin/common.d.cts +22 -0
  14. package/dist/.internal/bin/common.d.ts +22 -0
  15. package/dist/{cli-only-build.js → .internal/bin/common.js} +224 -439
  16. package/dist/.internal/bin/parseArgv.cjs +33 -0
  17. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  18. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  19. package/dist/.internal/bin/parseArgv.js +27 -0
  20. package/dist/.internal/bridge.cjs +30 -0
  21. package/dist/.internal/bridge.d.cts +39 -0
  22. package/dist/.internal/bridge.d.ts +39 -0
  23. package/dist/.internal/bridge.js +27 -0
  24. package/dist/.internal/rollup/base.cjs +10 -0
  25. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  26. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  27. package/dist/.internal/rollup/base.js +7 -0
  28. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  29. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  30. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  31. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  32. package/dist/.internal/utils/filterSupport.cjs +18 -0
  33. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  34. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  35. package/dist/.internal/utils/filterSupport.js +8 -0
  36. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  37. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  38. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  39. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  40. package/dist/.internal/utils/intersection.cjs +5 -0
  41. package/dist/.internal/utils/intersection.d.cts +3 -0
  42. package/dist/.internal/utils/intersection.d.ts +3 -0
  43. package/dist/.internal/utils/intersection.js +3 -0
  44. package/dist/.internal/utils/loadConfig.cjs +14 -0
  45. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  46. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  47. package/dist/.internal/utils/loadConfig.js +9 -0
  48. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  49. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  50. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  51. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  52. package/dist/.internal/utils/resolveExports.cjs +124 -0
  53. package/dist/.internal/utils/resolveExports.d.cts +27 -0
  54. package/dist/.internal/utils/resolveExports.d.ts +27 -0
  55. package/dist/.internal/utils/resolveExports.js +117 -0
  56. package/dist/.internal/utils/ts.cjs +68 -0
  57. package/dist/.internal/utils/ts.d.cts +3 -0
  58. package/dist/.internal/utils/ts.d.ts +3 -0
  59. package/dist/.internal/utils/ts.js +62 -0
  60. package/dist/bin/build.cjs +10 -0
  61. package/dist/bin/index.cjs +522 -0
  62. package/dist/index.d.cts +16 -114
  63. package/dist/index.d.ts +16 -114
  64. package/dist/rollup/index.cjs +310 -4573
  65. package/dist/rollup/index.d.cts +7 -1
  66. package/dist/rollup/index.d.ts +7 -1
  67. package/dist/rollup/index.js +298 -4558
  68. package/package.json +16 -24
  69. package/src/bin/build.cts +5 -0
  70. package/src/bin/common.ts +3 -0
  71. package/src/bin/index.cts +7 -0
  72. package/src/bridge.ts +1 -1
  73. package/src/commands/base.ts +3 -3
  74. package/src/commands/build/analyzer.ts +5 -5
  75. package/src/commands/build/client/analyzer.tsx +1 -1
  76. package/src/commands/build/client/index.ts +5 -7
  77. package/src/commands/build.ts +244 -213
  78. package/src/commands/meta.ts +1 -1
  79. package/src/commands/publish.ts +190 -78
  80. package/src/index.ts +6 -1
  81. package/src/rollup/base.ts +2 -2
  82. package/src/rollup/index.ts +361 -124
  83. package/src/rollup/plugins/with-external.ts +23 -0
  84. package/src/rollup/utils/externalResolver.ts +20 -8
  85. package/src/utils/checkDependency.ts +1 -1
  86. package/src/utils/filterSupport.ts +17 -16
  87. package/src/utils/getInternalModuleName.ts +5 -0
  88. package/src/utils/intersection.ts +1 -0
  89. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  90. package/src/utils/{getExports.ts → resolveExports.ts} +28 -19
  91. package/bin/jiek-build.js +0 -16
  92. package/bin/jiek.js +0 -13
  93. package/cli/package.json +0 -1
  94. package/cli-only-build/package.json +0 -1
  95. package/dist/cli.d.cts +0 -14
  96. package/dist/cli.d.ts +0 -14
  97. package/src/cli-only-build.ts +0 -11
  98. package/src/cli.ts +0 -6
  99. /package/{src/bin/build.ts → .jiek-production-tag} +0 -0
  100. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -0,0 +1,23 @@
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,5 +1,6 @@
1
1
  import fs from 'node:fs'
2
2
  import { builtinModules } from 'node:module'
3
+ import process from 'node:process'
3
4
 
4
5
  const EXCLUDE_SUFFIX = [
5
6
  'te?xt',
@@ -7,21 +8,32 @@ const EXCLUDE_SUFFIX = [
7
8
  '(css|s[ac]ss|less|styl)'
8
9
  ]
9
10
 
10
- export default function(json: Record<string, unknown>): (string | RegExp)[]
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)[]
11
23
  export default function(path?: string): (string | RegExp)[]
12
- export default function(jsonOrPath: string | Record<string, unknown> = process.cwd()): (string | RegExp)[] {
13
- const pkg = typeof jsonOrPath === 'string'
24
+ export default function(jsonOrPath: string | PackageJSON = process.cwd()): (string | RegExp)[] {
25
+ const pkg: PackageJSON = typeof jsonOrPath === 'string'
14
26
  ? fs.existsSync(`${jsonOrPath}/package.json`)
15
- ? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8'))
16
- : {}
27
+ ? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8')) as PackageJSON
28
+ : {} as PackageJSON
17
29
  : jsonOrPath
18
30
  const { name, dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg
19
- if (!name) {
31
+ if (name == null) {
20
32
  throw new Error('package.json must have a name field')
21
33
  }
22
34
 
23
- const external = <(string | RegExp)[]> Object
24
- .keys(dependencies)
35
+ const external = (<(string | RegExp)[]> [])
36
+ .concat(Object.keys(dependencies))
25
37
  .concat(Object.keys(peerDependencies))
26
38
  .concat(Object.keys(optionalDependencies))
27
39
  .concat(builtinModules)
@@ -3,7 +3,7 @@ import process from 'node:process'
3
3
 
4
4
  import { confirm } from '@inquirer/prompts'
5
5
 
6
- import { getWD } from '#~/utils/getWD.ts'
6
+ import { getWD } from '#~/utils/getWD'
7
7
 
8
8
  export async function checkDependency(dependency: string) {
9
9
  try {
@@ -1,11 +1,12 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
+ import process from 'node:process'
3
4
 
4
5
  import { program } from 'commander'
5
6
  import { load } from 'js-yaml'
6
7
 
7
- import { getRoot } from '#~/utils/getRoot.ts'
8
- import { getWD } from '#~/utils/getWD.ts'
8
+ import { getRoot } from '#~/utils/getRoot'
9
+ import { getWD } from '#~/utils/getWD'
9
10
 
10
11
  export let type = ''
11
12
 
@@ -14,14 +15,16 @@ try {
14
15
  type = 'pnpm'
15
16
  } catch { /* empty */ }
16
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
+
17
25
  export interface ProjectsGraph {
18
- wd: string
19
26
  root?: string
20
- value?: Record<string, {
21
- name?: string
22
- type?: string
23
- exports?: string | string[] | Record<string, unknown>
24
- }>
27
+ value?: Record<string, Manifest>
25
28
  }
26
29
 
27
30
  export async function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
@@ -29,16 +32,15 @@ export async function filterPackagesGraph(filters: string[]): Promise<ProjectsGr
29
32
  }
30
33
 
31
34
  export async function getSelectedProjectsGraph(
32
- filter = program.getOptionValue('filter')
35
+ filter = program.getOptionValue('filter') as string | undefined
33
36
  ): Promise<ProjectsGraph> {
34
37
  const { wd, notWorkspace } = getWD()
35
38
  let root = getRoot()
36
39
  if (notWorkspace) {
37
40
  return {
38
- wd,
39
41
  root,
40
42
  value: {
41
- [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))
43
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8')) as Manifest
42
44
  }
43
45
  }
44
46
  }
@@ -48,20 +50,20 @@ export async function getSelectedProjectsGraph(
48
50
  const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {
49
51
  packages: string[]
50
52
  }
51
- if (root === wd && !filter) {
53
+ if (root === wd && (filter == null)) {
52
54
  throw new Error('root path is workspace root, please provide a filter')
53
55
  // TODO inquirer prompt support user select packages
54
56
  }
55
57
  if (root === undefined) {
56
58
  root = process.cwd()
57
59
  }
58
- if (root !== wd && !filter) {
60
+ if (root !== wd && (filter == null)) {
59
61
  const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))
60
62
  if (!packageJSONIsExist) {
61
63
  throw new Error('root path is not workspace root, please provide a filter')
62
64
  }
63
- const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))
64
- if (!packageJSON.name) {
65
+ const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8')) as Manifest
66
+ if (packageJSON.name == null) {
65
67
  throw new Error('root path is not workspace root, please provide a filter')
66
68
  }
67
69
  filter = packageJSON.name
@@ -76,7 +78,6 @@ export async function getSelectedProjectsGraph(
76
78
  patterns: pnpmWorkspace.packages
77
79
  })
78
80
  return {
79
- wd,
80
81
  root,
81
82
  value: Object.entries(selectedProjectsGraph)
82
83
  .reduce((acc, [key, value]) => {
@@ -0,0 +1,5 @@
1
+ export const getInternalModuleName = (pkgName: string) => (`${
2
+ (
3
+ pkgName.startsWith('@') ? pkgName : `@${pkgName}`
4
+ ).replace('/', '+')
5
+ }/__internal__`)
@@ -0,0 +1 @@
1
+ export const intersection = <T>(a: Iterable<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))
@@ -1,13 +1,13 @@
1
1
  import fs from 'node:fs'
2
2
  import { resolve } from 'node:path'
3
3
 
4
- export const recusiveListFiles = (dir: string): string[] =>
4
+ export const recursiveListFiles = (dir: string): string[] =>
5
5
  fs.readdirSync(dir).reduce((acc, file) => {
6
6
  const filePath = resolve(dir, file)
7
7
  if (fs.statSync(filePath).isDirectory()) {
8
8
  if (filePath.endsWith('/node_modules')) return acc
9
9
 
10
- return [...acc, ...recusiveListFiles(filePath)]
10
+ return [...acc, ...recursiveListFiles(filePath)]
11
11
  }
12
12
  return [...acc, filePath]
13
13
  }, [] as string[])
@@ -4,15 +4,15 @@ import process from 'node:process'
4
4
  import {
5
5
  type Entrypoints2ExportsOptions,
6
6
  type RecursiveRecord,
7
- DEFAULT_SKIP_VALUES,
8
7
  entrypoints2Exports,
9
8
  filterLeafs,
9
+ getDefaultSkipValues,
10
10
  resolveEntrypoints
11
11
  } from '@jiek/pkger/entrypoints'
12
12
  import type { Config } from 'jiek'
13
13
  import { isMatch } from 'micromatch'
14
14
 
15
- const intersection = <T>(a: Set<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))
15
+ import { intersection } from '#~/utils/intersection'
16
16
 
17
17
  const {
18
18
  JIEK_OUT_DIR,
@@ -58,19 +58,7 @@ export function getOutDirs({
58
58
  }
59
59
  }
60
60
 
61
- export function getExports({
62
- entrypoints,
63
- pkgName,
64
- pkgIsModule,
65
- entries,
66
- config,
67
- dir,
68
- defaultOutdir = OUTDIR,
69
- // FIXME dts support
70
- outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
71
- noFilter,
72
- isPublish
73
- }: {
61
+ export interface ResolveExportsOptions {
74
62
  entrypoints: string | string[] | Record<string, unknown>
75
63
  pkgName: string
76
64
  pkgIsModule: boolean
@@ -81,7 +69,23 @@ export function getExports({
81
69
  defaultOutdir?: string
82
70
  noFilter?: boolean
83
71
  isPublish?: boolean
84
- }) {
72
+ skipJS?: boolean
73
+ }
74
+
75
+ export function resolveExports({
76
+ entrypoints,
77
+ pkgName,
78
+ pkgIsModule,
79
+ entries,
80
+ config,
81
+ dir,
82
+ defaultOutdir = OUTDIR,
83
+ // FIXME dts support
84
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
85
+ noFilter,
86
+ isPublish,
87
+ skipJS
88
+ }: ResolveExportsOptions) {
85
89
  const {
86
90
  build = {},
87
91
  publish: {
@@ -92,7 +96,9 @@ export function getExports({
92
96
  const {
93
97
  crossModuleConvertor = crossModuleConvertorDefault
94
98
  } = build
95
- const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints)
99
+ const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints, {
100
+ allowJS: !skipJS
101
+ })
96
102
  if (entries) {
97
103
  Object
98
104
  .entries(resolvedEntrypoints)
@@ -108,7 +114,9 @@ export function getExports({
108
114
  skipValue: [
109
115
  // ignore values that filename starts with `.jk-noentry`
110
116
  /(^|\/)\.jk-noentry/,
111
- ...DEFAULT_SKIP_VALUES
117
+ ...getDefaultSkipValues({
118
+ allowJS: !skipJS
119
+ })
112
120
  ]
113
121
  }
114
122
  )
@@ -149,7 +157,8 @@ export function getExports({
149
157
  withSource: isPublish ? withSource : undefined,
150
158
  withConditional: {
151
159
  ...crossModuleWithConditional
152
- }
160
+ },
161
+ allowJS: !skipJS
153
162
  }),
154
163
  outdir
155
164
  ] as const
package/bin/jiek-build.js DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync } from 'node:fs'
3
- import { createRequire } from 'node:module'
4
- import { dirname, resolve } from 'node:path'
5
- import process from 'node:process'
6
-
7
- process.env.JIEK_IS_ONLY_BUILD = 'true'
8
-
9
- const __dirname = dirname(import.meta.url.replace('file://', ''))
10
- if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
11
- const require = createRequire(import.meta.url)
12
- require('esbuild-register')
13
- require('../src/cli-only-build.ts')
14
- } else {
15
- import('jiek/cli-only-build')
16
- }
package/bin/jiek.js DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- import { existsSync } from 'node:fs'
3
- import { createRequire } from 'node:module'
4
- import { dirname, resolve } from 'node:path'
5
-
6
- const __dirname = dirname(import.meta.url.replace('file://', ''))
7
- if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
8
- const require = createRequire(import.meta.url)
9
- require('esbuild-register')
10
- require('../src/cli.ts')
11
- } else {
12
- import('jiek/cli')
13
- }
package/cli/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"module","module":"../dist/cli.js","main":"../dist/cli.cjs"}
@@ -1 +0,0 @@
1
- {"type":"module","module":"../dist/cli-only-build.js","main":"../dist/cli-only-build.cjs"}
package/dist/cli.d.cts DELETED
@@ -1,14 +0,0 @@
1
- declare module 'jiek' {
2
- interface Config {
3
- publish?: {
4
- /**
5
- * @default false
6
- */
7
- withSuffix?: boolean;
8
- /**
9
- * @default true
10
- */
11
- withSource?: boolean;
12
- };
13
- }
14
- }
package/dist/cli.d.ts DELETED
@@ -1,14 +0,0 @@
1
- declare module 'jiek' {
2
- interface Config {
3
- publish?: {
4
- /**
5
- * @default false
6
- */
7
- withSuffix?: boolean;
8
- /**
9
- * @default true
10
- */
11
- withSource?: boolean;
12
- };
13
- }
14
- }
@@ -1,11 +0,0 @@
1
- import './utils/filterSupport'
2
- import './commands/base'
3
- import './commands/build'
4
-
5
- import parseArgv from './parseArgv'
6
-
7
- import process from 'node:process'
8
-
9
- if (process.env.JIEK_IS_ONLY_BUILD === 'true') {
10
- parseArgv()
11
- }
package/src/cli.ts DELETED
@@ -1,6 +0,0 @@
1
- import './commands/publish'
2
- import 'jiek/cli-only-build'
3
-
4
- import parseArgv from './parseArgv'
5
-
6
- parseArgv()
File without changes
File without changes