jiek 2.3.2 → 2.3.4

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 (81) hide show
  1. package/dist/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
  2. package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
  3. package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
  4. package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
  5. package/dist/.internal/bin/common.cjs +92 -97
  6. package/dist/.internal/bin/common.d.cts +2 -0
  7. package/dist/.internal/bin/common.d.ts +2 -0
  8. package/dist/.internal/bin/common.js +93 -98
  9. package/dist/.internal/bin/parseArgv.cjs +2 -2
  10. package/dist/.internal/bin/parseArgv.js +2 -2
  11. package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
  12. package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
  13. package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
  14. package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
  15. package/dist/.internal/polyfill.cjs +13 -0
  16. package/dist/.internal/polyfill.d.cts +1 -0
  17. package/dist/.internal/polyfill.d.ts +1 -0
  18. package/dist/.internal/polyfill.js +11 -0
  19. package/dist/.internal/rollup/base.d.cts +27 -4
  20. package/dist/.internal/rollup/base.d.ts +27 -4
  21. package/dist/.internal/utils/filterSupport.cjs +1 -1
  22. package/dist/.internal/utils/filterSupport.js +2 -2
  23. package/dist/.internal/utils/loadConfig.cjs +3 -3
  24. package/dist/.internal/utils/loadConfig.d.cts +1 -0
  25. package/dist/.internal/utils/loadConfig.d.ts +1 -0
  26. package/dist/.internal/utils/loadConfig.js +4 -4
  27. package/dist/.internal/utils/pascalCase.cjs +5 -0
  28. package/dist/.internal/utils/pascalCase.d.cts +3 -0
  29. package/dist/.internal/utils/pascalCase.d.ts +3 -0
  30. package/dist/.internal/utils/pascalCase.js +3 -0
  31. package/dist/.internal/utils/reveal.cjs +9 -0
  32. package/dist/.internal/utils/reveal.d.cts +3 -0
  33. package/dist/.internal/utils/reveal.d.ts +3 -0
  34. package/dist/.internal/utils/reveal.js +7 -0
  35. package/dist/bin/index.cjs +101 -43
  36. package/dist/index.d.cts +7 -0
  37. package/dist/index.d.ts +7 -0
  38. package/dist/rollup/index.cjs +91 -31
  39. package/dist/rollup/index.js +90 -30
  40. package/package.json +6 -2
  41. package/src/bin/build.cts +0 -5
  42. package/src/bin/common.ts +0 -3
  43. package/src/bin/index.cts +0 -7
  44. package/src/bin/parseArgv.ts +0 -26
  45. package/src/bridge.ts +0 -46
  46. package/src/commands/base.ts +0 -18
  47. package/src/commands/build/analyzer.ts +0 -122
  48. package/src/commands/build/client/analyzer.tsx +0 -121
  49. package/src/commands/build/client/index.ts +0 -26
  50. package/src/commands/build.ts +0 -544
  51. package/src/commands/descriptions.ts +0 -17
  52. package/src/commands/meta.ts +0 -5
  53. package/src/commands/publish.ts +0 -628
  54. package/src/commands/utils/optionParser.ts +0 -4
  55. package/src/index.ts +0 -12
  56. package/src/inner.ts +0 -11
  57. package/src/rollup/base.ts +0 -151
  58. package/src/rollup/bundle-analyzer.ts +0 -62
  59. package/src/rollup/index.ts +0 -892
  60. package/src/rollup/plugins/create-require.ts +0 -23
  61. package/src/rollup/plugins/progress.ts +0 -26
  62. package/src/rollup/plugins/replace.ts +0 -96
  63. package/src/rollup/plugins/skip.ts +0 -21
  64. package/src/rollup/plugins/with-external.ts +0 -23
  65. package/src/rollup/utils/commonOptions.ts +0 -9
  66. package/src/rollup/utils/externalResolver.ts +0 -47
  67. package/src/rollup/utils/globalResolver.ts +0 -13
  68. package/src/rollup/utils/withMinify.ts +0 -18
  69. package/src/rollup-plugin-utils.ts +0 -32
  70. package/src/server.ts +0 -30
  71. package/src/utils/checkDependency.ts +0 -26
  72. package/src/utils/filterSupport.ts +0 -90
  73. package/src/utils/getInternalModuleName.ts +0 -5
  74. package/src/utils/getRoot.ts +0 -14
  75. package/src/utils/getWD.ts +0 -31
  76. package/src/utils/intersection.ts +0 -1
  77. package/src/utils/loadConfig.ts +0 -108
  78. package/src/utils/recursiveListFiles.ts +0 -13
  79. package/src/utils/resolveExports.ts +0 -165
  80. package/src/utils/ts.ts +0 -94
  81. package/src/utils/tsRegister.ts +0 -22
@@ -1,23 +0,0 @@
1
- import type { Plugin } from 'rollup'
2
-
3
- export const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = 'jiek:create-require'
4
-
5
- const INSERT_STR = (isESM: boolean) =>
6
- `
7
- ${isESM ? `import { createRequire } from 'node:module'` : ''}
8
- export default ${isESM ? '/* @__PURE__ */ createRequire(import.meta.url)' : 'require'}
9
- `.trim()
10
-
11
- export default (isEsm: boolean): Plugin => ({
12
- name: 'create-require',
13
- resolveId: id => (
14
- id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
15
- ? id
16
- : null
17
- ),
18
- load: id => (
19
- id === CREATE_REQUIRE_VIRTUAL_MODULE_NAME
20
- ? INSERT_STR(isEsm)
21
- : null
22
- )
23
- })
@@ -1,26 +0,0 @@
1
- import type { PluginImpl } from 'rollup'
2
-
3
- interface Options {
4
- onEvent?: (event: string, message?: string) => void
5
- }
6
-
7
- export default ((options = {}) => {
8
- const { onEvent } = options
9
- return {
10
- name: 'progress',
11
- buildStart: () => onEvent?.('start', 'Start building...'),
12
- buildEnd: () => onEvent?.('end', 'Build completed!'),
13
- resolveId: {
14
- order: 'post',
15
- handler: source => onEvent?.('resolve', `Resolving ${source}...`)
16
- },
17
- load: {
18
- order: 'post',
19
- handler: id => onEvent?.('load', `Loading ${id}...`)
20
- },
21
- transform: {
22
- order: 'post',
23
- handler: (_, id) => onEvent?.('transform', `Transforming ${id}...`)
24
- }
25
- }
26
- }) as PluginImpl<Options>
@@ -1,96 +0,0 @@
1
- import type { FilterOptions } from 'jiek/rollup-plugin-utils'
2
- import { createFilter, definePlugin } from 'jiek/rollup-plugin-utils'
3
- import MagicString from 'magic-string'
4
-
5
- export interface ReplacementFuncCtx {
6
- type: 'transform' | 'renderChunk'
7
- id: string
8
- code: string
9
- start: number
10
- end: number
11
- }
12
-
13
- export type ReplacementFunc = (ctx: ReplacementFuncCtx) => string
14
-
15
- export type Replacements = Record<
16
- string,
17
- string | ReplacementFunc
18
- >
19
-
20
- export type Options =
21
- & FilterOptions
22
- & {
23
- sourcemap?: boolean
24
- values?: Replacements
25
- }
26
-
27
- export default definePlugin((options: Options = {}) => {
28
- const {
29
- include = [/\.[cm]?[tj]sx?$/],
30
- exclude = [/node_modules/],
31
- values = {},
32
- sourcemap
33
- } = options
34
- const allValues = { ...values }
35
- const allKeys = Object.keys(allValues)
36
- const filter = createFilter({ include, exclude })
37
-
38
- const replaceAll = (ctx: Pick<ReplacementFuncCtx, 'type' | 'id'>, code: string) => {
39
- const ms = new MagicString(code)
40
- allKeys.forEach(key => {
41
- const reg = new RegExp(key, 'g')
42
- let match
43
- // eslint-disable-next-line no-cond-assign
44
- while ((match = reg.exec(code))) {
45
- const start = match.index
46
- const end = start + key.length
47
- ms.overwrite(
48
- match.index,
49
- match.index + key.length,
50
- typeof allValues[key] === 'function'
51
- ? allValues[key]({
52
- ...ctx,
53
- code,
54
- start,
55
- end
56
- })
57
- : allValues[key]
58
- )
59
- }
60
- })
61
- return ms
62
- }
63
-
64
- return {
65
- name: 'jiek:replace',
66
- transform: {
67
- order: 'pre',
68
- handler(code, id) {
69
- if (allKeys.length === 0) return
70
- if (filter(id)) return
71
- const ms = replaceAll({ type: 'transform', id }, code)
72
- if (ms == null) return
73
-
74
- return {
75
- code: ms.toString(),
76
- map: sourcemap ? ms.generateMap({ hires: true }) : null
77
- }
78
- }
79
- },
80
- renderChunk: {
81
- order: 'post',
82
- handler(code, { fileName: id }) {
83
- if (allKeys.length === 0) return
84
- if (filter(id)) return
85
-
86
- const ms = replaceAll({ type: 'renderChunk', id }, code)
87
- if (ms == null) return
88
-
89
- return {
90
- code: ms.toString(),
91
- map: sourcemap ? ms.generateMap({ hires: true }) : null
92
- }
93
- }
94
- }
95
- }
96
- })
@@ -1,21 +0,0 @@
1
- import type { PluginImpl } from 'rollup'
2
-
3
- interface Options {
4
- patterns?: (string | RegExp)[]
5
- }
6
-
7
- export default ((options = {}) => ({
8
- name: 'skip',
9
- // skip the specified files by `options.patterns`
10
- load(id) {
11
- if (
12
- options.patterns?.some((pattern) =>
13
- typeof pattern === 'string'
14
- ? id.includes(pattern)
15
- : pattern.test(id)
16
- )
17
- ) {
18
- return ''
19
- }
20
- }
21
- })) as PluginImpl<Options>
@@ -1,23 +0,0 @@
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,9 +0,0 @@
1
- import type { OutputOptions } from 'rollup'
2
-
3
- const defineOutput = <O extends OutputOptions>(output: O) => output
4
-
5
- export const commonOutputOptions = defineOutput({
6
- exports: 'named',
7
- interop: 'auto',
8
- sourcemap: true
9
- })
@@ -1,47 +0,0 @@
1
- import fs from 'node:fs'
2
- import { builtinModules } from 'node:module'
3
- import process from 'node:process'
4
-
5
- const EXCLUDE_SUFFIX = [
6
- 'te?xt',
7
- 'json',
8
- '(css|s[ac]ss|less|styl)'
9
- ]
10
-
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)[]
23
- export default function(path?: string): (string | RegExp)[]
24
- export default function(jsonOrPath: string | PackageJSON = process.cwd()): (string | RegExp)[] {
25
- const pkg: PackageJSON = typeof jsonOrPath === 'string'
26
- ? fs.existsSync(`${jsonOrPath}/package.json`)
27
- ? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8')) as PackageJSON
28
- : {} as PackageJSON
29
- : jsonOrPath
30
- const { name, dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg
31
- if (name == null) {
32
- throw new Error('package.json must have a name field')
33
- }
34
-
35
- const external = (<(string | RegExp)[]> [])
36
- .concat(Object.keys(dependencies))
37
- .concat(Object.keys(peerDependencies))
38
- .concat(Object.keys(optionalDependencies))
39
- .concat(builtinModules)
40
-
41
- return [...new Set(external)]
42
- .map(dep => new RegExp(`^${dep}(/.*)?$`))
43
- .concat([
44
- new RegExp(`^${name}(/.*)?(?<!${EXCLUDE_SUFFIX.map(suffix => `\\.${suffix}`).join('|')})$`),
45
- /^node:/
46
- ])
47
- }
@@ -1,13 +0,0 @@
1
- export default function (external: string) {
2
- // a/b => AB
3
- // a-b => AB
4
- // a@b => AB
5
- // a@b/c => ABC
6
- // node:a => a
7
- // node:a_b => a_b
8
- if (external.startsWith('node:')) {
9
- return external.slice(5)
10
- }
11
- return external
12
- .replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase())
13
- }
@@ -1,18 +0,0 @@
1
- import terser from '@rollup/plugin-terser'
2
- import type { OutputOptions, OutputPlugin } from 'rollup'
3
-
4
- export default function(
5
- output: OutputOptions & {
6
- entryFileNames?: string
7
- plugins?: OutputPlugin[]
8
- }
9
- ): OutputOptions[] {
10
- return [
11
- output,
12
- {
13
- ...output,
14
- entryFileNames: output.entryFileNames?.replace(/(\.[cm]?js)$/, '.min$1'),
15
- plugins: [...(output.plugins ?? []), terser()]
16
- }
17
- ]
18
- }
@@ -1,32 +0,0 @@
1
- import { isMatch } from 'micromatch'
2
- import type { PluginImpl } from 'rollup'
3
-
4
- export const definePlugin = <O extends object>(plugin: PluginImpl<O>) => plugin
5
-
6
- export interface FilterOptions {
7
- include?: string | RegExp | (string | RegExp)[]
8
- exclude?: string | RegExp | (string | RegExp)[]
9
- }
10
-
11
- export function createFilter(options: FilterOptions) {
12
- const { include = [], exclude = [] } = options
13
-
14
- const resolvedInclude = Array.isArray(include) ? include : [include]
15
- const resolvedExclude = Array.isArray(exclude) ? exclude : [exclude]
16
-
17
- return (id: string) => {
18
- if (typeof id !== 'string') return false
19
- const isInclude = resolvedInclude.length === 0 || resolvedInclude.some(filter => {
20
- return filter instanceof RegExp
21
- ? filter.test(id)
22
- : isMatch(id, filter)
23
- })
24
- const isExclude = resolvedExclude.length > 0 && resolvedExclude.some(filter => {
25
- return filter instanceof RegExp
26
- ? filter.test(id)
27
- : isMatch(id, filter)
28
- })
29
-
30
- return !isInclude || isExclude
31
- }
32
- }
package/src/server.ts DELETED
@@ -1,30 +0,0 @@
1
- import Koa from 'koa'
2
-
3
- export const createServer = (port: number, host: string) => {
4
- const app = new Koa()
5
- app.listen(port, host)
6
- const streams = new Map<string, string>()
7
- app.use(async (ctx) => {
8
- let stream = streams.get(ctx.path)
9
- if (stream == null) {
10
- const maybeKey = streams
11
- .keys()
12
- .find(p => ctx.path.startsWith(p))
13
- stream = maybeKey != null
14
- ? streams.get(maybeKey)
15
- : undefined
16
- }
17
- if (stream != null) {
18
- ctx.body = stream
19
- }
20
- })
21
- // noinspection HttpUrlsUsage
22
- return {
23
- port,
24
- host,
25
- rootUrl: `http://${host}:${port}`,
26
- renderTo: async (path: string, stream: string) => {
27
- streams.set(path, stream)
28
- }
29
- }
30
- }
@@ -1,26 +0,0 @@
1
- import { execSync } from 'node:child_process'
2
- import process from 'node:process'
3
-
4
- import { confirm } from '@inquirer/prompts'
5
-
6
- import { getWD } from '#~/utils/getWD'
7
-
8
- export async function checkDependency(dependency: string) {
9
- try {
10
- require.resolve(dependency)
11
- } catch {
12
- console.error(`The package '${dependency}' is not installed, please install it first.`)
13
- const { notWorkspace } = getWD()
14
- const command = `pnpm add -${notWorkspace ? '' : 'w'}D ${dependency}`
15
- if (await confirm({ message: `Do you want to add it now? (${command})` })) {
16
- execSync(command, {
17
- stdio: 'inherit',
18
- cwd: process.cwd(),
19
- env: process.env
20
- })
21
- } else {
22
- console.warn(`You can run the command '${command}' to install it manually.`)
23
- process.exit(1)
24
- }
25
- }
26
- }
@@ -1,90 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import process from 'node:process'
4
-
5
- import { program } from 'commander'
6
- import { load } from 'js-yaml'
7
-
8
- import { getRoot } from '#~/utils/getRoot'
9
- import { getWD } from '#~/utils/getWD'
10
-
11
- export let type = ''
12
-
13
- try {
14
- require.resolve('@pnpm/filter-workspace-packages')
15
- type = 'pnpm'
16
- } catch { /* empty */ }
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
-
25
- export interface ProjectsGraph {
26
- root?: string
27
- value?: Record<string, Manifest>
28
- }
29
-
30
- export async function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
31
- return Promise.all(filters.map(async filter => getSelectedProjectsGraph(filter)))
32
- }
33
-
34
- export async function getSelectedProjectsGraph(
35
- filter = program.getOptionValue('filter') as string | undefined
36
- ): Promise<ProjectsGraph> {
37
- const { wd, notWorkspace } = getWD()
38
- let root = getRoot()
39
- if (notWorkspace) {
40
- return {
41
- root,
42
- value: {
43
- [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8')) as Manifest
44
- }
45
- }
46
- }
47
- if (type === 'pnpm') {
48
- const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')
49
- const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')
50
- const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {
51
- packages: string[]
52
- }
53
- if (root === wd && (filter == null)) {
54
- throw new Error('root path is workspace root, please provide a filter')
55
- // TODO inquirer prompt support user select packages
56
- }
57
- if (root === undefined) {
58
- root = process.cwd()
59
- }
60
- if (root !== wd && (filter == null)) {
61
- const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))
62
- if (!packageJSONIsExist) {
63
- throw new Error('root path is not workspace root, please provide a filter')
64
- }
65
- const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8')) as Manifest
66
- if (packageJSON.name == null) {
67
- throw new Error('root path is not workspace root, please provide a filter')
68
- }
69
- filter = packageJSON.name
70
- }
71
- const { filterPackagesFromDir } = await import('@pnpm/filter-workspace-packages')
72
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
73
- filter: filter ?? '',
74
- followProdDepsOnly: true
75
- }], {
76
- prefix: root,
77
- workspaceDir: wd,
78
- patterns: pnpmWorkspace.packages
79
- })
80
- return {
81
- root,
82
- value: Object.entries(selectedProjectsGraph)
83
- .reduce((acc, [key, value]) => {
84
- acc[key] = value.package.manifest
85
- return acc
86
- }, {} as NonNullable<ProjectsGraph['value']>)
87
- }
88
- }
89
- throw new Error(`not supported package manager ${type}`)
90
- }
@@ -1,5 +0,0 @@
1
- export const getInternalModuleName = (pkgName: string) => (`${
2
- (
3
- pkgName.startsWith('@') ? pkgName : `@${pkgName}`
4
- ).replace('/', '+')
5
- }/__internal__`)
@@ -1,14 +0,0 @@
1
- import path from 'node:path'
2
-
3
- let root: string | undefined
4
- export function getRoot() {
5
- if (root) return root
6
-
7
- const rootOption = process.env.JIEK_ROOT
8
- root = rootOption
9
- ? path.isAbsolute(rootOption)
10
- ? rootOption
11
- : path.resolve(process.cwd(), rootOption)
12
- : undefined
13
- return root
14
- }
@@ -1,31 +0,0 @@
1
- import { getWorkspaceDir, isWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
2
-
3
- import { type } from './filterSupport'
4
- import { getRoot } from './getRoot'
5
-
6
- let wd: string
7
- let notWorkspace = false
8
-
9
- export function getWD() {
10
- if (wd) return { wd, notWorkspace }
11
-
12
- const root = getRoot()
13
- if (root !== undefined) {
14
- const isWorkspace = isWorkspaceDir(root, type)
15
- notWorkspace = !isWorkspace
16
- wd = root
17
- return { wd, notWorkspace }
18
- }
19
- try {
20
- wd = getWorkspaceDir(type)
21
- } catch (e) {
22
- // @ts-ignore
23
- if ('message' in e && e.message === 'workspace root not found') {
24
- wd = root ?? process.cwd()
25
- notWorkspace = true
26
- } else {
27
- throw e
28
- }
29
- }
30
- return { wd, notWorkspace }
31
- }
@@ -1 +0,0 @@
1
- export const intersection = <T>(a: Iterable<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))
@@ -1,108 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
-
4
- import { program } from 'commander'
5
- import type { Config } from 'jiek'
6
- import { load } from 'js-yaml'
7
-
8
- import { getWD } from './getWD'
9
- import { tsRegisterName } from './tsRegister'
10
-
11
- let configName = 'jiek.config'
12
-
13
- function getConfigPath(root: string, dir?: string) {
14
- const isSupportTsLoader = !!tsRegisterName
15
- function configWithExtIsExist(ext: string) {
16
- const filenames = [
17
- path.resolve(process.cwd(), `${configName}.${ext}`),
18
- path.resolve(process.cwd(), `.${configName}.${ext}`),
19
- path.resolve(root, `${configName}.${ext}`),
20
- path.resolve(root, `.${configName}.${ext}`)
21
- ]
22
- if (dir) {
23
- filenames.unshift(...[
24
- path.resolve(dir, `${configName}.${ext}`),
25
- path.resolve(dir, `.${configName}.${ext}`)
26
- ])
27
- }
28
- for (const filename of filenames) {
29
- if (
30
- fs.existsSync(filename)
31
- && fs.lstatSync(filename)
32
- .isFile()
33
- ) {
34
- return filename
35
- }
36
- }
37
- return
38
- }
39
- configName = configWithExtIsExist('js') ?? configName
40
- configName = configWithExtIsExist('json') ?? configName
41
- configName = configWithExtIsExist('yaml') ?? configName
42
- if (isSupportTsLoader) {
43
- configName = configWithExtIsExist('ts') ?? configName
44
- }
45
- return path.resolve(root, configName)
46
- }
47
-
48
- interface LoadConfigOptions {
49
- dir?: string
50
- root?: string
51
- }
52
-
53
- export function loadConfig(options?: LoadConfigOptions): Config
54
- export function loadConfig(dir?: string): Config
55
- export function loadConfig(dirOrOptions?: string | LoadConfigOptions): Config {
56
- let dir: string | undefined
57
- let root: string
58
- if (typeof dirOrOptions === 'object') {
59
- dir = dirOrOptions.dir
60
- root = dirOrOptions.root ?? getWD().wd
61
- } else {
62
- dir = dirOrOptions
63
- root = getWD().wd
64
- }
65
-
66
- let configPath = program.getOptionValue('configPath')
67
-
68
- if (!configPath) {
69
- configPath = getConfigPath(root, dir)
70
- } else {
71
- if (!fs.existsSync(configPath)) {
72
- throw new Error(`config file not found: ${configPath}`)
73
- }
74
- if (!path.isAbsolute(configPath)) {
75
- configPath = path.resolve(root, configPath)
76
- }
77
- }
78
- const ext = path.extname(configPath)
79
-
80
- let module: any
81
- switch (ext) {
82
- case '.js':
83
- module = require(configPath)
84
- break
85
- case '.json':
86
- return require(configPath)
87
- case '.yaml':
88
- return load(fs.readFileSync(configPath, 'utf-8')) as Config
89
- case '.ts':
90
- if (tsRegisterName) {
91
- require(tsRegisterName)
92
- module = require(configPath)
93
- break
94
- }
95
- throw new Error(
96
- 'ts config file is not supported without ts register, '
97
- + 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'
98
- )
99
- case '.config':
100
- module = {}
101
- break
102
- default:
103
- throw new Error(`unsupported config file type: ${ext}`)
104
- }
105
- if (!module) throw new Error('config file is empty')
106
-
107
- return module.default ?? module
108
- }
@@ -1,13 +0,0 @@
1
- import fs from 'node:fs'
2
- import { resolve } from 'node:path'
3
-
4
- export const recursiveListFiles = (dir: string): string[] =>
5
- fs.readdirSync(dir).reduce((acc, file) => {
6
- const filePath = resolve(dir, file)
7
- if (fs.statSync(filePath).isDirectory()) {
8
- if (filePath.endsWith('/node_modules')) return acc
9
-
10
- return [...acc, ...recursiveListFiles(filePath)]
11
- }
12
- return [...acc, filePath]
13
- }, [] as string[])