@xylabs/ts-scripts-yarn3 6.0.9 → 6.1.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 (161) hide show
  1. package/dist/actions/build.mjs +2 -2
  2. package/dist/actions/build.mjs.map +1 -1
  3. package/dist/actions/index.mjs +17 -2
  4. package/dist/actions/index.mjs.map +1 -1
  5. package/dist/actions/knip.mjs +113 -0
  6. package/dist/actions/knip.mjs.map +1 -0
  7. package/dist/actions/relint.mjs.map +1 -1
  8. package/dist/bin/xy.mjs +23 -2
  9. package/dist/bin/xy.mjs.map +1 -1
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.mjs +24 -2
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/types/actions/index.d.ts +1 -0
  14. package/dist/types/actions/index.d.ts.map +1 -1
  15. package/dist/types/actions/knip.d.ts +2 -0
  16. package/dist/types/actions/knip.d.ts.map +1 -0
  17. package/dist/types/actions/relint.d.ts.map +1 -1
  18. package/dist/types/xy/xyLintCommands.d.ts.map +1 -1
  19. package/dist/xy/index.mjs +23 -2
  20. package/dist/xy/index.mjs.map +1 -1
  21. package/dist/xy/xy.mjs +23 -2
  22. package/dist/xy/xy.mjs.map +1 -1
  23. package/dist/xy/xyBuildCommands.mjs +2 -2
  24. package/dist/xy/xyBuildCommands.mjs.map +1 -1
  25. package/dist/xy/xyLintCommands.mjs +21 -0
  26. package/dist/xy/xyLintCommands.mjs.map +1 -1
  27. package/package.json +10 -4
  28. package/spec/yarn/workspace/tsconfig.json +0 -3
  29. package/src/actions/build.ts +0 -34
  30. package/src/actions/clean-docs.ts +0 -12
  31. package/src/actions/clean-eslint.ts +0 -15
  32. package/src/actions/clean-jest.ts +0 -7
  33. package/src/actions/clean.ts +0 -26
  34. package/src/actions/compile-types.ts +0 -67
  35. package/src/actions/compile.ts +0 -67
  36. package/src/actions/copy-assets.ts +0 -70
  37. package/src/actions/cycle.ts +0 -15
  38. package/src/actions/dead.ts +0 -5
  39. package/src/actions/deploy-major.ts +0 -11
  40. package/src/actions/deploy-minor.ts +0 -11
  41. package/src/actions/deploy-next.ts +0 -11
  42. package/src/actions/deploy.ts +0 -11
  43. package/src/actions/deps.ts +0 -43
  44. package/src/actions/dupdeps.ts +0 -12
  45. package/src/actions/fix.ts +0 -6
  46. package/src/actions/gen-docs.ts +0 -26
  47. package/src/actions/gitignore-gen.ts +0 -5
  48. package/src/actions/gitlint-fix.ts +0 -27
  49. package/src/actions/gitlint.ts +0 -46
  50. package/src/actions/index.ts +0 -37
  51. package/src/actions/license.ts +0 -81
  52. package/src/actions/lint.ts +0 -61
  53. package/src/actions/npmignore-gen.ts +0 -5
  54. package/src/actions/package/clean-outputs.ts +0 -18
  55. package/src/actions/package/clean-typescript.ts +0 -18
  56. package/src/actions/package/clean.ts +0 -6
  57. package/src/actions/package/compile/XyConfig.ts +0 -60
  58. package/src/actions/package/compile/buildEntries.ts +0 -22
  59. package/src/actions/package/compile/compile.ts +0 -21
  60. package/src/actions/package/compile/compileTypes.ts +0 -13
  61. package/src/actions/package/compile/copyTypeFiles.ts +0 -38
  62. package/src/actions/package/compile/deepMerge.ts +0 -33
  63. package/src/actions/package/compile/getCompilerOptions.ts +0 -30
  64. package/src/actions/package/compile/index.ts +0 -6
  65. package/src/actions/package/compile/inputs.ts +0 -6
  66. package/src/actions/package/compile/packageCompileTsc.ts +0 -67
  67. package/src/actions/package/compile/packageCompileTscTypes.ts +0 -68
  68. package/src/actions/package/compile/packageCompileTsup.ts +0 -154
  69. package/src/actions/package/copy-assets.ts +0 -46
  70. package/src/actions/package/deps.ts +0 -144
  71. package/src/actions/package/gen-docs.ts +0 -126
  72. package/src/actions/package/index.ts +0 -10
  73. package/src/actions/package/lint.ts +0 -86
  74. package/src/actions/package/publint.ts +0 -75
  75. package/src/actions/package/recompile.ts +0 -6
  76. package/src/actions/publint.ts +0 -26
  77. package/src/actions/rebuild.ts +0 -13
  78. package/src/actions/recompile.ts +0 -81
  79. package/src/actions/reinstall.ts +0 -29
  80. package/src/actions/relint.ts +0 -76
  81. package/src/actions/retest.ts +0 -8
  82. package/src/actions/sonar.ts +0 -5
  83. package/src/actions/statics.ts +0 -13
  84. package/src/actions/test.ts +0 -5
  85. package/src/actions/up.ts +0 -5
  86. package/src/actions/updo.ts +0 -9
  87. package/src/actions/upplug.ts +0 -10
  88. package/src/actions/upyarn.ts +0 -5
  89. package/src/actions/yarn3only.ts +0 -9
  90. package/src/bin/package/build-only.ts +0 -16
  91. package/src/bin/package/build.ts +0 -16
  92. package/src/bin/package/clean-outputs.ts +0 -5
  93. package/src/bin/package/clean-typescript.ts +0 -5
  94. package/src/bin/package/clean.ts +0 -12
  95. package/src/bin/package/compile-only.ts +0 -12
  96. package/src/bin/package/compile-tsup.ts +0 -12
  97. package/src/bin/package/compile-types.ts +0 -16
  98. package/src/bin/package/compile.ts +0 -16
  99. package/src/bin/package/copy-assets-cjs.ts +0 -12
  100. package/src/bin/package/copy-assets-esm.ts +0 -12
  101. package/src/bin/package/deps.ts +0 -12
  102. package/src/bin/package/fix.ts +0 -16
  103. package/src/bin/package/gen-docs.ts +0 -12
  104. package/src/bin/package/lint.ts +0 -16
  105. package/src/bin/package/publint.ts +0 -13
  106. package/src/bin/package/recompile.ts +0 -12
  107. package/src/bin/package/relint.ts +0 -16
  108. package/src/bin/xy.ts +0 -12
  109. package/src/index.ts +0 -4
  110. package/src/lib/checkResult.ts +0 -12
  111. package/src/lib/createBuildConfig.ts +0 -37
  112. package/src/lib/defaultBuildConfig.ts +0 -18
  113. package/src/lib/deleteGlob.ts +0 -13
  114. package/src/lib/dependencies/DuplicateDetector.ts +0 -97
  115. package/src/lib/dependencies/detectDuplicateDependencies.ts +0 -41
  116. package/src/lib/dependencies/index.ts +0 -2
  117. package/src/lib/file/ReadFileSyncOptions.ts +0 -6
  118. package/src/lib/file/constants.ts +0 -2
  119. package/src/lib/file/fileLines.ts +0 -25
  120. package/src/lib/file/index.ts +0 -4
  121. package/src/lib/file/tryReadFileSync.ts +0 -9
  122. package/src/lib/generateIgnoreFiles.ts +0 -31
  123. package/src/lib/index.ts +0 -20
  124. package/src/lib/jsonFormatters.ts +0 -6
  125. package/src/lib/loadConfig.ts +0 -19
  126. package/src/lib/parsedPackageJSON.ts +0 -7
  127. package/src/lib/processEx.ts +0 -27
  128. package/src/lib/runSteps.ts +0 -40
  129. package/src/lib/runStepsAsync.ts +0 -53
  130. package/src/lib/runXy.ts +0 -8
  131. package/src/lib/runXyWithWarning.ts +0 -9
  132. package/src/lib/safeExit.ts +0 -29
  133. package/src/lib/string/empty.ts +0 -2
  134. package/src/lib/string/index.ts +0 -2
  135. package/src/lib/string/union.ts +0 -1
  136. package/src/lib/withErrnoException.ts +0 -7
  137. package/src/lib/withError.ts +0 -8
  138. package/src/lib/yarn/index.ts +0 -3
  139. package/src/lib/yarn/isYarnVersionOrGreater.ts +0 -16
  140. package/src/lib/yarn/workspace/Workspace.ts +0 -4
  141. package/src/lib/yarn/workspace/index.ts +0 -3
  142. package/src/lib/yarn/workspace/yarnWorkspace.ts +0 -8
  143. package/src/lib/yarn/workspace/yarnWorkspaces.ts +0 -21
  144. package/src/lib/yarn/yarnInitCwd.ts +0 -4
  145. package/src/loadPackageConfig.ts +0 -13
  146. package/src/types.d.ts +0 -26
  147. package/src/xy/index.ts +0 -7
  148. package/src/xy/param.ts +0 -5
  149. package/src/xy/xy.ts +0 -20
  150. package/src/xy/xyBuildCommands.ts +0 -127
  151. package/src/xy/xyCommonCommands.ts +0 -167
  152. package/src/xy/xyDeployCommands.ts +0 -53
  153. package/src/xy/xyInstallCommands.ts +0 -80
  154. package/src/xy/xyLintCommands.ts +0 -92
  155. package/src/xy/xyParseOptions.ts +0 -58
  156. package/tsconfig.build.json +0 -29
  157. package/tsconfig.json +0 -4
  158. package/tsconfig.test.json +0 -4
  159. package/tsup.config.ts +0 -16
  160. package/types/node-cmd.d.ts +0 -1
  161. package/xy.config.ts +0 -3
@@ -1,60 +0,0 @@
1
- import type { Options } from 'tsup'
2
-
3
- export type EntryMode = 'all' | 'single' | 'auto' | 'platform'
4
-
5
- /**
6
- * Configuration for specifying which paths are targeted.
7
- */
8
- export interface PathConfig {
9
- /**
10
- * Glob patterns to exclude (takes precedence over include).
11
- */
12
- exclude?: string[]
13
- /**
14
- * Glob patterns to include.
15
- */
16
- include?: string[]
17
- }
18
-
19
- /**
20
- * Configuration for Dynamic Share.
21
- */
22
-
23
- export interface DynamicShareConfig extends PathConfig {}
24
-
25
- /**
26
- * Configuration for Live Share.
27
- */
28
-
29
- export interface LiveShareConfig extends PathConfig {}
30
-
31
- export interface CompileConfig {
32
- depth?: number
33
- /** @param entryMode all, single, platform, or auto */
34
- entryMode?: EntryMode
35
- /** @param files Manually specify the files to be compiled */
36
- files?: string[]
37
- }
38
-
39
- export type PackageCompileTsupConfig = CompileConfig & {
40
- browser?: Record<string, Options | boolean>
41
- neutral?: Record<string, Options | boolean>
42
- node?: Record<string, Options | boolean>
43
- tsup?: { options?: Options }
44
- }
45
-
46
- export type PackageCompileTscConfig = CompileConfig & { mode: 'tsc' }
47
-
48
- export interface XyConfigBase {
49
- compile?: CompileConfig
50
- dynamicShare?: DynamicShareConfig
51
- liveShare?: LiveShareConfig
52
- publint?: boolean
53
- verbose?: boolean
54
- }
55
-
56
- export interface XyTsupConfig extends XyConfigBase { compile?: PackageCompileTsupConfig }
57
-
58
- export interface XyTscConfig extends XyConfigBase { compile?: PackageCompileTscConfig }
59
-
60
- export type XyConfig = XyTsupConfig | XyTscConfig
@@ -1,22 +0,0 @@
1
- import { getAllInputs } from './inputs.ts'
2
- import type { EntryMode } from './XyConfig.ts'
3
-
4
- export const buildEntries = (folder: string, entryMode: EntryMode = 'single', verbose = false) => {
5
- let entries: string[] = []
6
- switch (entryMode) {
7
- case 'platform': {
8
- entries = [`${folder}/index-node.ts`, `${folder}/index-browser.ts`]
9
- break
10
- }
11
- case 'all': {
12
- entries = getAllInputs(folder).filter(entry => !entry.includes('.spec.') && !entry.includes('.story.'))
13
- break
14
- }
15
- default: {
16
- entries = [`${folder}/index.ts`]
17
- break
18
- }
19
- }
20
- if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`)
21
- return entries
22
- }
@@ -1,21 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- import { loadConfig } from '../../../lib/index.ts'
4
- import { packagePublint } from '../publint.ts'
5
- import { packageCompileTsup } from './packageCompileTsup.ts'
6
- import type { XyConfig } from './XyConfig.ts'
7
-
8
- export const packageCompile = async (inConfig: XyConfig = {}): Promise<number> => {
9
- const pkg = process.env.INIT_CWD
10
- console.log(chalk.green(`Compiling ${pkg}`))
11
- const config = await loadConfig(inConfig)
12
- const publint = config.publint
13
-
14
- const tsupResults = await packageCompileTsup(config)
15
-
16
- if (tsupResults > 0) {
17
- return tsupResults
18
- }
19
-
20
- return (publint ? await packagePublint(config) : 0)
21
- }
@@ -1,13 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- import { loadConfig } from '../../../lib/index.ts'
4
- import { packageCompileTscTypes } from './packageCompileTscTypes.ts'
5
- import type { XyConfig, XyTscConfig } from './XyConfig.ts'
6
-
7
- export const packageCompileTypes = async (inConfig: XyConfig = {}): Promise<number> => {
8
- const pkg = process.env.INIT_CWD
9
- console.log(chalk.green(`Compiling Types ${pkg}`))
10
- const config = await loadConfig(inConfig)
11
-
12
- return packageCompileTscTypes(undefined, config as XyTscConfig)
13
- }
@@ -1,38 +0,0 @@
1
- import { copyFile, readdir } from 'node:fs/promises'
2
-
3
- import { Mutex } from 'async-mutex'
4
- import type { TsConfigCompilerOptions } from 'tsc-prog'
5
-
6
- const copyFileMutex = new Mutex()
7
-
8
- const getDistTypeFiles = async (compilerOptions: TsConfigCompilerOptions) => {
9
- const outDir = compilerOptions.outDir ?? 'dist'
10
- return (await readdir(outDir, { recursive: true })).filter(file => file.endsWith('d.ts')).map(file => `${outDir}/${file}`)
11
- }
12
-
13
- const getDistTypeMapFiles = async (compilerOptions: TsConfigCompilerOptions) => {
14
- const outDir = compilerOptions.outDir ?? 'dist'
15
- return (await readdir(outDir, { recursive: true })).filter(file => file.endsWith('d.ts.map')).map(file => `${outDir}/${file}`)
16
- }
17
-
18
- export const copyTypeFiles = async (compilerOptions: TsConfigCompilerOptions) => {
19
- // using a mutex since sometimes two compiles are running at once and cause a lock on windows
20
- await copyFileMutex.runExclusive(async () => {
21
- // hybrid packages want two copies of the types
22
- const distTypeFiles = await getDistTypeFiles(compilerOptions)
23
- await Promise.all(
24
- distTypeFiles.map(async (file) => {
25
- await copyFile(file, file.replace('d.ts', 'd.mts'))
26
- await copyFile(file, file.replace('d.ts', 'd.cts'))
27
- }),
28
- )
29
-
30
- const distTypeMapFiles = await getDistTypeMapFiles(compilerOptions)
31
- await Promise.all(
32
- distTypeMapFiles.map(async (file) => {
33
- await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))
34
- await copyFile(file, file.replace('d.ts.map', 'd.cts.map'))
35
- }),
36
- )
37
- })
38
- }
@@ -1,33 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
- type AnyObject = Record<any, any>
3
-
4
- function deepMerge<T extends AnyObject>(target: AnyObject, source: AnyObject): T {
5
- if (!source || typeof source !== 'object') return target
6
-
7
- for (const key of Object.keys(source)) {
8
- if (
9
- typeof source[key] === 'object'
10
- && source[key] !== null
11
- && !Array.isArray(source[key])
12
- ) {
13
- // Recursively merge nested objects
14
- if (!target[key] || typeof target[key] !== 'object') {
15
- target[key] = {} as T[typeof key]
16
- }
17
- deepMerge(target[key], source[key])
18
- } else {
19
- // Overwrite with non-object values
20
- target[key] = source[key]
21
- }
22
- }
23
-
24
- return target
25
- }
26
-
27
- export function deepMergeObjects<T extends AnyObject>(objects: T[]): T {
28
- const result = {} as T
29
- for (const obj of objects) {
30
- deepMerge(result, obj)
31
- }
32
- return result
33
- }
@@ -1,30 +0,0 @@
1
- import { createRequire } from 'node:module'
2
-
3
- import deepmerge from 'deepmerge'
4
- import type { TsConfig } from 'tsc-prog'
5
- import type { CompilerOptions } from 'typescript'
6
- import {
7
- findConfigFile, readConfigFile, sys,
8
- } from 'typescript'
9
-
10
- const getNested = (config: TsConfig): CompilerOptions => {
11
- if (config.extends) {
12
- const require = createRequire(import.meta.url)
13
- const opts = require(config.extends)
14
- return deepmerge(getNested(opts), config.compilerOptions ?? {}) as CompilerOptions
15
- }
16
-
17
- return config.compilerOptions as CompilerOptions
18
- }
19
-
20
- const getCompilerOptionsJSONFollowExtends = (filename: string): CompilerOptions => {
21
- const config = readConfigFile(filename, sys.readFile).config
22
- return getNested(config)
23
- }
24
-
25
- export const getCompilerOptions = (options: CompilerOptions = {}, tsconfig: string = 'tsconfig.json'): CompilerOptions => {
26
- const configFileName = findConfigFile('./', sys.fileExists, tsconfig)
27
- const configFileCompilerOptions = (configFileName ? getCompilerOptionsJSONFollowExtends(configFileName) : undefined) ?? {}
28
-
29
- return deepmerge(configFileCompilerOptions, options)
30
- }
@@ -1,6 +0,0 @@
1
- export * from './compile.ts'
2
- export * from './compileTypes.ts'
3
- export * from './packageCompileTsc.ts'
4
- export * from './packageCompileTscTypes.ts'
5
- export * from './packageCompileTsup.ts'
6
- export * from './XyConfig.ts'
@@ -1,6 +0,0 @@
1
- import { glob } from 'glob'
2
-
3
- export const getAllInputs = (folder: string) => {
4
- /* tsup wants posix paths */
5
- return glob.sync(`${folder}/**/*.*`, { ignore: ['**/*.spec.*', '**/*.stories.*', '**/spec/**/*'], posix: true })
6
- }
@@ -1,67 +0,0 @@
1
- import { cwd } from 'node:process'
2
-
3
- import chalk from 'chalk'
4
- import type { TsConfigCompilerOptions } from 'tsc-prog'
5
- import { createProgramFromConfig } from 'tsc-prog'
6
- import type {
7
- CompilerOptions,
8
- FormatDiagnosticsHost,
9
- LineAndCharacter,
10
- } from 'typescript'
11
- import {
12
- DiagnosticCategory,
13
- formatDiagnosticsWithColorAndContext,
14
- getLineAndCharacterOfPosition,
15
- getPreEmitDiagnostics,
16
- } from 'typescript'
17
-
18
- import { packagePublint } from '../publint.ts'
19
- import { getCompilerOptions } from './getCompilerOptions.ts'
20
- import type { XyTscConfig } from './XyConfig.ts'
21
-
22
- export const packageCompileTsc = async (noEmit?: boolean, config?: XyTscConfig, compilerOptionsParam?: CompilerOptions): Promise<number> => {
23
- const pkg = process.env.INIT_CWD ?? cwd()
24
-
25
- const publint = config?.publint ?? true
26
- const verbose = config?.verbose ?? false
27
-
28
- const formatHost: FormatDiagnosticsHost = {
29
- getCanonicalFileName: fileName => fileName,
30
- getCurrentDirectory: () => pkg,
31
- getNewLine: () => '\n',
32
- }
33
-
34
- if (verbose) {
35
- console.log(`Compiling with NoEmit TSC [${pkg}]`)
36
- }
37
-
38
- const compilerOptions = {
39
- ...(getCompilerOptions({
40
- outDir: 'dist',
41
- removeComments: true,
42
- rootDir: 'src',
43
- })),
44
- ...compilerOptionsParam,
45
- ...(noEmit === undefined ? {} : { noEmit }),
46
- } as TsConfigCompilerOptions
47
-
48
- const program = createProgramFromConfig({
49
- basePath: pkg ?? cwd(),
50
- compilerOptions,
51
- exclude: ['dist', 'docs', '**/*.spec.*', '**/*.stories.*', 'src/**/spec/**/*'],
52
- include: ['src'],
53
- })
54
-
55
- const results = getPreEmitDiagnostics(program)
56
-
57
- for (const diag of results) {
58
- const lineAndChar: LineAndCharacter = diag.file
59
- ? getLineAndCharacterOfPosition(diag.file, diag.start ?? 0)
60
- : { character: 0, line: 0 }
61
- console.log(chalk.cyan(`${diag.file?.fileName}:${lineAndChar.line + 1}:${lineAndChar.character + 1}`))
62
- console.log(formatDiagnosticsWithColorAndContext([diag], formatHost))
63
- }
64
-
65
- // eslint-disable-next-line unicorn/no-array-reduce
66
- return results.reduce((prev, diag) => (prev + diag.category === DiagnosticCategory.Error ? 1 : 0), 0) || (publint ? await packagePublint() : 0)
67
- }
@@ -1,68 +0,0 @@
1
- import { cwd } from 'node:process'
2
-
3
- import type { TsConfigCompilerOptions } from 'tsc-prog'
4
- import { createProgramFromConfig } from 'tsc-prog'
5
- import type { CompilerOptions } from 'typescript'
6
- import {
7
- DiagnosticCategory, formatDiagnosticsWithColorAndContext, getPreEmitDiagnostics, sys,
8
- } from 'typescript'
9
-
10
- import { buildEntries } from './buildEntries.ts'
11
- import { getCompilerOptions } from './getCompilerOptions.ts'
12
- import type { XyConfig } from './XyConfig.ts'
13
-
14
- export const packageCompileTscTypes = (
15
- folder: string = 'src',
16
- config: XyConfig = {},
17
- compilerOptionsParam?: CompilerOptions,
18
- ): number => {
19
- const pkg = process.env.INIT_CWD ?? cwd()
20
- const verbose = config?.verbose ?? false
21
-
22
- if (verbose) {
23
- console.log(`Compiling types [${pkg}]`)
24
- }
25
-
26
- const compilerOptions = {
27
- ...(getCompilerOptions({
28
- emitDeclarationOnly: true,
29
- outDir: 'dist/types',
30
- removeComments: false,
31
- skipDefaultLibCheck: true,
32
- skipLibCheck: true,
33
- sourceMap: false,
34
- })),
35
- ...compilerOptionsParam,
36
- emitDeclarationOnly: true,
37
- noEmit: false,
38
- } as TsConfigCompilerOptions
39
-
40
- const validTsExt = ['.ts', '.tsx', '.d.ts', '.cts', '.d.cts', '.mts', '.d.mts']
41
-
42
- // calling all here since the types do not get rolled up
43
- const files = buildEntries(folder, 'all', verbose).filter(file => validTsExt.find(ext => file.endsWith(ext)))
44
-
45
- const program = createProgramFromConfig({
46
- basePath: pkg ?? cwd(),
47
- compilerOptions,
48
- exclude: ['dist', 'docs', '**/*.spec.*', '**/*.stories.*', 'src/**/spec/**/*'],
49
- files,
50
- })
51
-
52
- const diagnostics = getPreEmitDiagnostics(program)
53
-
54
- if (diagnostics.length > 0) {
55
- const formattedDiagnostics = formatDiagnosticsWithColorAndContext(
56
- diagnostics,
57
- {
58
- getCanonicalFileName: fileName => fileName,
59
- getCurrentDirectory: () => folder,
60
- getNewLine: () => sys.newLine,
61
- },
62
- )
63
- console.error(formattedDiagnostics)
64
- }
65
-
66
- program.emit()
67
- return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0)
68
- }
@@ -1,154 +0,0 @@
1
- import type { Loader } from 'esbuild'
2
- import type { Options } from 'tsup'
3
- import { build, defineConfig } from 'tsup'
4
-
5
- import { buildEntries } from './buildEntries.ts'
6
- import { packageCompileTypes } from './compileTypes.ts'
7
- import { deepMergeObjects } from './deepMerge.ts'
8
- import type { EntryMode, XyTsupConfig } from './XyConfig.ts'
9
-
10
- const compileFolder = async (
11
- folder: string,
12
- entryMode: EntryMode = 'single',
13
- options?: Options,
14
- verbose?: boolean,
15
- ): Promise<number> => {
16
- const outDir = options?.outDir ?? 'dist'
17
-
18
- if (verbose) {
19
- console.log(`compileFolder [${folder}]`)
20
- }
21
-
22
- const entry = buildEntries(folder, entryMode)
23
- const optionsResult = defineConfig({
24
- bundle: true,
25
- cjsInterop: true,
26
- clean: true,
27
- dts: false,
28
- entry,
29
- format: ['esm'],
30
- outDir,
31
- silent: true,
32
- sourcemap: true,
33
- splitting: false,
34
- tsconfig: 'tsconfig.json',
35
- ...options,
36
- })
37
- const optionsList = (
38
- await Promise.all(
39
- (Array.isArray(optionsResult) ? optionsResult : [optionsResult]).flatMap<Promise<Options[]>>(async (options) => {
40
- const result = typeof options === 'function' ? await options({}) : [options]
41
- return Array.isArray(result) ? result : [result]
42
- }),
43
- )
44
- ).flat()
45
-
46
- if (verbose) {
47
- console.log(`TSUP:build:start [${folder}]`)
48
- }
49
-
50
- await Promise.all(optionsList.map(options => build(options)))
51
-
52
- if (verbose) {
53
- console.log(`TSUP:build:stop [${folder}]`)
54
- }
55
-
56
- return 0
57
- }
58
-
59
- export const tsupOptions = (options: Options[] = []): Options => {
60
- const standardLoaders: Record<string, Loader> = {
61
- '.gif': 'copy', '.html': 'copy', '.jpg': 'copy', '.json': 'json', '.png': 'copy', '.svg': 'copy', '.webp': 'copy',
62
- }
63
-
64
- const standardOptions: Options = {
65
- bundle: true,
66
- format: ['esm'],
67
- loader: standardLoaders,
68
- outExtension: ({ format }) => (format === 'esm' ? { js: '.mjs' } : { js: '.cjs' }),
69
- skipNodeModulesBundle: true,
70
- sourcemap: true,
71
- target: 'esnext',
72
- }
73
-
74
- return deepMergeObjects([standardOptions, ...options])
75
- }
76
-
77
- export const packageCompileTsup = async (config?: XyTsupConfig) => {
78
- console.log('packageCompileTsup-types')
79
- const compile = config?.compile
80
- const verbose = config?.verbose ?? false
81
- if (verbose) {
82
- console.log(`Compiling with TSUP [Depth: ${compile?.depth}]`)
83
- }
84
-
85
- const compileForNode = compile?.node ?? { src: {} }
86
- const compileForBrowser = compile?.browser ?? { src: {} }
87
- const compileForNeutral = compile?.neutral ?? { src: {} }
88
-
89
- if (verbose) {
90
- console.log('Calling packageCompileTscTypes')
91
- }
92
- const errors = await packageCompileTypes(config)
93
- if (errors > 0) {
94
- return errors
95
- }
96
-
97
- return (
98
- (
99
- await Promise.all(
100
- Object.entries(compileForNode).map(async ([folder, options]) => {
101
- const inEsBuildOptions = typeof compile?.node?.esbuildOptions === 'object' ? compile?.node?.esbuildOptions : {}
102
- return folder
103
- ? await compileFolder(
104
- folder,
105
- compile?.entryMode,
106
- tsupOptions([inEsBuildOptions,
107
- compile?.tsup?.options ?? {},
108
- (typeof options === 'object' ? options : {}),
109
- { platform: 'node', outDir: 'dist/node' }]),
110
- verbose,
111
- )
112
- : 0
113
- }),
114
- )
115
- ).reduce((prev, value) => prev + value, 0)
116
- || (
117
- await Promise.all(
118
- Object.entries(compileForBrowser).map(async ([folder, options]) => {
119
- const inEsBuildOptions = typeof compile?.browser?.esbuildOptions === 'object' ? compile?.browser?.esbuildOptions : {}
120
- return folder
121
- ? await compileFolder(
122
- folder,
123
- compile?.entryMode,
124
- tsupOptions([inEsBuildOptions,
125
- compile?.tsup?.options ?? {},
126
- (typeof options === 'object' ? options : {}),
127
- { platform: 'browser', outDir: 'dist/browser' }]),
128
- verbose,
129
- )
130
- : 0
131
- }),
132
- )
133
- ).reduce((prev, value) => prev + value, 0)
134
- || (
135
- await Promise.all(
136
- Object.entries(compileForNeutral).map(async ([folder, options]) => {
137
- const inEsBuildOptions = typeof compile?.neutral?.esbuildOptions === 'object' ? compile?.neutral?.esbuildOptions : {}
138
- return folder
139
- ? await compileFolder(
140
- folder,
141
- compile?.entryMode,
142
- tsupOptions([inEsBuildOptions,
143
- compile?.tsup?.options ?? {},
144
- (typeof options === 'object' ? options : {}),
145
- { platform: 'neutral', outDir: 'dist/neutral' }]),
146
- verbose,
147
- )
148
- : 0
149
- }),
150
- )
151
- ).reduce((prev, value) => prev + value, 0)
152
- || 0
153
- )
154
- }
@@ -1,46 +0,0 @@
1
- import path from 'node:path/posix'
2
-
3
- import chalk from 'chalk'
4
- import cpy from 'cpy'
5
-
6
- export interface PackageCopyAssetsParams { target?: 'esm' | 'cjs' }
7
-
8
- const copyTargetAssets = async (target: 'esm' | 'cjs', name: string, location: string) => {
9
- try {
10
- const values = await cpy(
11
- ['**/*.jpg', '**/*.png', '**/*.gif', '**/*.svg', '**/*.webp', '**/*.sass', '**/*.scss', '**/*.gif', '**/*.css'],
12
- `../dist/${target}`,
13
- {
14
- cwd: path.join(location, 'src'),
15
- flat: false,
16
- },
17
- )
18
- if (values.length > 0) {
19
- console.log(chalk.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`))
20
- }
21
- for (const value of values) {
22
- console.log(`${value.split('/').pop()} => ./dist/${target}`)
23
- }
24
- return 0
25
- } catch (ex) {
26
- const error = ex as Error
27
- console.log(`Copy Assets Failed: ${name}: ${error.message}`)
28
- return 1
29
- }
30
- }
31
-
32
- export const packageCopyAssets = async ({ target }: PackageCopyAssetsParams) => {
33
- const pkg = process.env.INIT_CWD ?? './'
34
- const pkgName = process.env.npm_package_name ?? 'Unknown'
35
- switch (target) {
36
- case 'esm': {
37
- return await copyTargetAssets('esm', pkgName, pkg)
38
- }
39
- case 'cjs': {
40
- return await copyTargetAssets('cjs', pkgName, pkg)
41
- }
42
- default: {
43
- return (await copyTargetAssets('esm', pkgName, pkg)) || (await copyTargetAssets('cjs', pkgName, pkg))
44
- }
45
- }
46
- }