jiek 2.2.6 → 2.2.7-alpha.3

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 (136) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +31 -0
  4. package/bin-helper/index.d.cts +1 -0
  5. package/bin-helper/index.d.ts +1 -0
  6. package/bin-helper/package.json +5 -1
  7. package/dist/.internal/.chunks/getWD.D6wq8Qc2.js +95 -0
  8. package/dist/.internal/.chunks/getWD.ZF0avqDB.cjs +105 -0
  9. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -735
  10. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -757
  11. package/dist/.internal/.chunks/jiek_create-require.CWFWNQHj.cjs +5 -0
  12. package/dist/.internal/.chunks/jiek_create-require.CxSGbkTB.js +5 -0
  13. package/dist/.internal/bin/parseArgv.cjs +33 -0
  14. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  15. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  16. package/dist/.internal/bin/parseArgv.js +27 -0
  17. package/dist/.internal/bridge.cjs +12 -0
  18. package/dist/.internal/bridge.d.cts +39 -0
  19. package/dist/.internal/bridge.d.ts +39 -0
  20. package/dist/.internal/bridge.js +9 -0
  21. package/dist/.internal/commands/build/analyzer.cjs +201 -0
  22. package/dist/.internal/commands/build/analyzer.d.cts +30 -0
  23. package/dist/.internal/commands/build/analyzer.d.ts +30 -0
  24. package/dist/.internal/commands/build/analyzer.js +195 -0
  25. package/dist/.internal/commands/descriptions.cjs +21 -0
  26. package/dist/.internal/commands/descriptions.d.cts +5 -0
  27. package/dist/.internal/commands/descriptions.d.ts +5 -0
  28. package/dist/.internal/commands/descriptions.js +17 -0
  29. package/dist/.internal/commands/meta.cjs +16 -0
  30. package/dist/.internal/commands/meta.d.cts +3 -0
  31. package/dist/.internal/commands/meta.d.ts +3 -0
  32. package/dist/.internal/commands/meta.js +15 -0
  33. package/dist/.internal/commands/utils/optionParser.cjs +8 -0
  34. package/dist/.internal/commands/utils/optionParser.d.cts +3 -0
  35. package/dist/.internal/commands/utils/optionParser.d.ts +3 -0
  36. package/dist/.internal/commands/utils/optionParser.js +6 -0
  37. package/dist/.internal/rollup/base.cjs +10 -0
  38. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  39. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  40. package/dist/.internal/rollup/base.js +7 -0
  41. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  42. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  43. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  44. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  45. package/dist/.internal/server.cjs +33 -0
  46. package/dist/.internal/server.d.cts +8 -0
  47. package/dist/.internal/server.d.ts +8 -0
  48. package/dist/.internal/server.js +27 -0
  49. package/dist/.internal/utils/checkDependency.cjs +39 -0
  50. package/dist/.internal/utils/checkDependency.d.cts +3 -0
  51. package/dist/.internal/utils/checkDependency.d.ts +3 -0
  52. package/dist/.internal/utils/checkDependency.js +34 -0
  53. package/dist/.internal/utils/filterSupport.cjs +20 -0
  54. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  55. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  56. package/dist/.internal/utils/filterSupport.js +10 -0
  57. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  58. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  59. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  60. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  61. package/dist/.internal/utils/getRoot.cjs +17 -0
  62. package/dist/.internal/utils/getRoot.d.cts +3 -0
  63. package/dist/.internal/utils/getRoot.d.ts +3 -0
  64. package/dist/.internal/utils/getRoot.js +11 -0
  65. package/dist/.internal/utils/getWD.cjs +15 -0
  66. package/dist/.internal/utils/getWD.d.cts +6 -0
  67. package/dist/.internal/utils/getWD.d.ts +6 -0
  68. package/dist/.internal/utils/getWD.js +10 -0
  69. package/dist/.internal/utils/intersection.cjs +5 -0
  70. package/dist/.internal/utils/intersection.d.cts +3 -0
  71. package/dist/.internal/utils/intersection.d.ts +3 -0
  72. package/dist/.internal/utils/intersection.js +3 -0
  73. package/dist/.internal/utils/loadConfig.cjs +100 -0
  74. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  75. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  76. package/dist/.internal/utils/loadConfig.js +94 -0
  77. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  78. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  79. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  80. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  81. package/dist/.internal/utils/resolveExports.cjs +118 -0
  82. package/dist/.internal/utils/resolveExports.d.cts +26 -0
  83. package/dist/.internal/utils/resolveExports.d.ts +26 -0
  84. package/dist/.internal/utils/resolveExports.js +111 -0
  85. package/dist/.internal/utils/ts.cjs +68 -0
  86. package/dist/.internal/utils/ts.d.cts +3 -0
  87. package/dist/.internal/utils/ts.d.ts +3 -0
  88. package/dist/.internal/utils/ts.js +62 -0
  89. package/dist/.internal/utils/tsRegister.cjs +25 -0
  90. package/dist/.internal/utils/tsRegister.d.cts +3 -0
  91. package/dist/.internal/utils/tsRegister.d.ts +3 -0
  92. package/dist/.internal/utils/tsRegister.js +26 -0
  93. package/dist/bin/build.cjs +515 -0
  94. package/dist/bin/index.cjs +497 -0
  95. package/dist/index.d.cts +12 -114
  96. package/dist/index.d.ts +12 -114
  97. package/dist/rollup/index.cjs +280 -4573
  98. package/dist/rollup/index.d.cts +7 -1
  99. package/dist/rollup/index.d.ts +7 -1
  100. package/dist/rollup/index.js +268 -4558
  101. package/package.json +20 -26
  102. package/src/bin/build.cts +11 -0
  103. package/src/bin/index.cts +6 -0
  104. package/src/bridge.ts +1 -1
  105. package/src/commands/base.ts +3 -3
  106. package/src/commands/build/analyzer.ts +5 -5
  107. package/src/commands/build/client/analyzer.tsx +1 -1
  108. package/src/commands/build/client/index.ts +5 -7
  109. package/src/commands/build.ts +226 -211
  110. package/src/commands/meta.ts +1 -1
  111. package/src/commands/publish.ts +112 -32
  112. package/src/index.ts +6 -1
  113. package/src/rollup/base.ts +2 -2
  114. package/src/rollup/index.ts +321 -124
  115. package/src/rollup/plugins/with-external.ts +23 -0
  116. package/src/rollup/utils/externalResolver.ts +20 -8
  117. package/src/utils/checkDependency.ts +1 -1
  118. package/src/utils/filterSupport.ts +17 -16
  119. package/src/utils/getInternalModuleName.ts +5 -0
  120. package/src/utils/intersection.ts +1 -0
  121. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  122. package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
  123. package/bin/jiek-build.js +0 -16
  124. package/bin/jiek.js +0 -13
  125. package/bin-helper.cjs +0 -43
  126. package/cli/package.json +0 -1
  127. package/cli-only-build/package.json +0 -1
  128. package/dist/cli-only-build.cjs +0 -977
  129. package/dist/cli-only-build.js +0 -969
  130. package/dist/cli.d.cts +0 -14
  131. package/dist/cli.d.ts +0 -14
  132. package/src/bin/build.ts +0 -0
  133. package/src/cli-only-build.ts +0 -11
  134. package/src/cli.ts +0 -6
  135. /package/{bin-helper.js → bin-helper/index.js} +0 -0
  136. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -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[])
@@ -12,7 +12,7 @@ import {
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,7 +58,20 @@ export function getOutDirs({
58
58
  }
59
59
  }
60
60
 
61
- export function getExports({
61
+ export interface ResolveExportsOptions {
62
+ entrypoints: string | string[] | Record<string, unknown>
63
+ pkgName: string
64
+ pkgIsModule: boolean
65
+ entries?: string[]
66
+ config?: Config
67
+ dir?: string
68
+ outdir?: string
69
+ defaultOutdir?: string
70
+ noFilter?: boolean
71
+ isPublish?: boolean
72
+ }
73
+
74
+ export function resolveExports({
62
75
  entrypoints,
63
76
  pkgName,
64
77
  pkgIsModule,
@@ -70,18 +83,7 @@ export function getExports({
70
83
  outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
71
84
  noFilter,
72
85
  isPublish
73
- }: {
74
- entrypoints: string | string[] | Record<string, unknown>
75
- pkgName: string
76
- pkgIsModule: boolean
77
- entries?: string[]
78
- config?: Config
79
- dir?: string
80
- outdir?: string
81
- defaultOutdir?: string
82
- noFilter?: boolean
83
- isPublish?: boolean
84
- }) {
86
+ }: ResolveExportsOptions) {
85
87
  const {
86
88
  build = {},
87
89
  publish: {
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/bin-helper.cjs DELETED
@@ -1,43 +0,0 @@
1
- const process = require('node:process')
2
-
3
- /**
4
- * @type {string | undefined}
5
- */
6
- let binFilePath
7
-
8
- try {
9
- // eslint-disable-next-line unicorn/error-message
10
- throw new Error()
11
- } catch (e) {
12
- const { stack } = e
13
- const lines = stack.split('\n')
14
- for (const line of lines) {
15
- if (
16
- line === 'Error' || line.includes(' (node:') || line.includes(` (${__filename}`)
17
- ) {
18
- continue
19
- }
20
- const match = line.match(/\(([^)]+)\)$/)
21
- if (match) {
22
- binFilePath = match[1].replace(/:\d+:\d+$/, '')
23
- }
24
- break
25
- }
26
- }
27
-
28
- binFilePath = binFilePath ?? process.env.JIEK_BIN__FILEPATH
29
-
30
- const {
31
- basename,
32
- dirname
33
- } = require('node:path')
34
-
35
- const packageDir = dirname(dirname(binFilePath))
36
- const binFilename = basename(binFilePath).replace(/(\.[cm]?)js$/, '$1ts')
37
-
38
- process.env.JIEK_PACKAGE_DIR = packageDir
39
- process.env.JIEK_BIN__FILENAME = binFilename
40
- process.env.JIEK_BIN__FILEPATH = binFilePath
41
-
42
- require('esbuild-register')
43
- require(`${packageDir}/src/bin/${binFilename}`)
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"}