@xylabs/ts-scripts-yarn3 3.0.12 → 3.0.13

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 (57) hide show
  1. package/dist/actions/package/compile/CompileParams.js.map +1 -1
  2. package/dist/actions/package/compile/compile.js +27 -15
  3. package/dist/actions/package/compile/compile.js.map +1 -1
  4. package/dist/actions/package/compile/compile.mjs +27 -15
  5. package/dist/actions/package/compile/compile.mjs.map +1 -1
  6. package/dist/actions/package/compile/copyTypeFiles.js.map +1 -1
  7. package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -1
  8. package/dist/actions/package/compile/index.js +3 -3
  9. package/dist/actions/package/compile/index.js.map +1 -1
  10. package/dist/actions/package/compile/index.mjs +1 -1
  11. package/dist/actions/package/compile/index.mjs.map +1 -1
  12. package/dist/actions/package/compile/inputs.js.map +1 -1
  13. package/dist/actions/package/compile/inputs.mjs.map +1 -1
  14. package/dist/actions/package/compile/rollup.js +4 -4
  15. package/dist/actions/package/compile/rollup.js.map +1 -1
  16. package/dist/actions/package/compile/rollup.mjs +4 -4
  17. package/dist/actions/package/compile/rollup.mjs.map +1 -1
  18. package/dist/actions/package/compile/tsc.js +16 -25
  19. package/dist/actions/package/compile/tsc.js.map +1 -1
  20. package/dist/actions/package/compile/tsc.mjs +24 -25
  21. package/dist/actions/package/compile/tsc.mjs.map +1 -1
  22. package/dist/actions/package/compile/tscTypes.js +5 -7
  23. package/dist/actions/package/compile/tscTypes.js.map +1 -1
  24. package/dist/actions/package/compile/tscTypes.mjs +5 -7
  25. package/dist/actions/package/compile/tscTypes.mjs.map +1 -1
  26. package/dist/actions/package/compile/tsup.js +5 -5
  27. package/dist/actions/package/compile/tsup.js.map +1 -1
  28. package/dist/actions/package/compile/tsup.mjs +5 -5
  29. package/dist/actions/package/compile/tsup.mjs.map +1 -1
  30. package/dist/actions/package/publint.js +1 -1
  31. package/dist/actions/package/publint.js.map +1 -1
  32. package/dist/actions/package/publint.mjs +1 -1
  33. package/dist/actions/package/publint.mjs.map +1 -1
  34. package/dist/index.d.mts +9 -9
  35. package/dist/index.d.ts +9 -9
  36. package/dist/lib/index.js +3 -3
  37. package/dist/lib/index.js.map +1 -1
  38. package/dist/lib/index.mjs +1 -1
  39. package/dist/lib/index.mjs.map +1 -1
  40. package/dist/lib/loadConfig.js +1 -1
  41. package/dist/lib/loadConfig.js.map +1 -1
  42. package/dist/lib/loadConfig.mjs +1 -1
  43. package/dist/lib/loadConfig.mjs.map +1 -1
  44. package/package.json +4 -4
  45. package/src/actions/package/compile/CompileParams.ts +1 -1
  46. package/src/actions/package/compile/compile.ts +30 -16
  47. package/src/actions/package/compile/copyTypeFiles.ts +15 -16
  48. package/src/actions/package/compile/index.ts +1 -1
  49. package/src/actions/package/compile/inputs.ts +1 -1
  50. package/src/actions/package/compile/rollup.ts +14 -13
  51. package/src/actions/package/compile/tsc.ts +51 -46
  52. package/src/actions/package/compile/tscTypes.ts +7 -9
  53. package/src/actions/package/compile/tsup.ts +22 -17
  54. package/src/actions/package/publint.ts +1 -1
  55. package/src/lib/index.ts +1 -1
  56. package/src/lib/loadConfig.ts +4 -2
  57. package/tsconfig.build.json +2 -2
@@ -1,6 +1,5 @@
1
1
  import { copyFile, readdir } from 'fs/promises'
2
2
 
3
-
4
3
  const getDistTypeFiles = async () => {
5
4
  return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts')).map((file) => `dist/${file}`)
6
5
  }
@@ -10,18 +9,18 @@ const getDistTypeMapFiles = async () => {
10
9
  }
11
10
 
12
11
  export const copyTypeFiles = async () => {
13
- //hybrid packages want two copies of the types
14
- const distTypeFiles = await getDistTypeFiles()
15
- await Promise.all(
16
- distTypeFiles.map(async (file) => {
17
- await copyFile(file, file.replace('d.ts', 'd.mts'))
18
- }),
19
- )
20
-
21
- const distTypeMapFiles = await getDistTypeMapFiles()
22
- await Promise.all(
23
- distTypeMapFiles.map(async (file) => {
24
- await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))
25
- }),
26
- )
27
- }
12
+ //hybrid packages want two copies of the types
13
+ const distTypeFiles = await getDistTypeFiles()
14
+ await Promise.all(
15
+ distTypeFiles.map(async (file) => {
16
+ await copyFile(file, file.replace('d.ts', 'd.mts'))
17
+ }),
18
+ )
19
+
20
+ const distTypeMapFiles = await getDistTypeMapFiles()
21
+ await Promise.all(
22
+ distTypeMapFiles.map(async (file) => {
23
+ await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))
24
+ }),
25
+ )
26
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './compile'
2
+ export * from './rollup'
2
3
  export * from './tsc'
3
4
  export * from './tsup'
4
- export * from './rollup'
@@ -30,4 +30,4 @@ export const getInputDirs = async (depth: number = 0) => {
30
30
  export const getAllInputs = async (depth: number = 100) => {
31
31
  const dirs = await getInputDirs(depth)
32
32
  return (await Promise.all(dirs.map(async (dir) => await getInputs(dir)))).flat()
33
- }
33
+ }
@@ -5,17 +5,16 @@ import chalk from 'chalk'
5
5
  import { OutputOptions, rollup, RollupLog, RollupOptions } from 'rollup'
6
6
  import externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'
7
7
  import nodeExternals from 'rollup-plugin-node-externals'
8
- import { getInputDirs, getInputs } from './inputs'
9
- import { packagePublint } from '../publint'
8
+
9
+ import { loadConfig } from '../../../lib'
10
10
  import { loadPackageConfig } from '../../../loadPackageConfig'
11
+ import { packagePublint } from '../publint'
11
12
  import { CompileParams } from './CompileParams'
12
- import { loadConfig } from '../../../lib'
13
+ import { getInputDirs, getInputs } from './inputs'
13
14
 
14
- export interface PackageCompileRollupParams extends CompileParams {
15
+ export interface PackageCompileRollupParams extends CompileParams {}
15
16
 
16
- }
17
-
18
- export const compileSubDir = async (format: 'cjs' | 'esm', ext: string, subDir?: string, verbose = false) => {
17
+ export const compileSubDir = async (format: 'cjs' | 'esm', ext: string, subDir?: string, _verbose = false) => {
19
18
  const dir = subDir === '.' ? undefined : subDir
20
19
  const input = await getInputs(dir)
21
20
  const tsPlugIn = typescript({
@@ -99,10 +98,12 @@ export const packageCompileRollup = async (params?: PackageCompileRollupParams)
99
98
  const esmExt = pkgType === 'module' ? 'js' : 'mjs'
100
99
  const cjsExt = pkgType === 'commonjs' ? 'js' : 'cjs'
101
100
 
102
- const result = (await Promise.all(
103
- inputDirs.map(async (inputDir) => {
104
- return await compileSubDir('cjs', cjsExt, inputDir, verbose) + await compileSubDir('esm', esmExt, inputDir, verbose)
105
- }),
106
- )).reduce(((prev, result) => prev + result), 0)
101
+ const result = (
102
+ await Promise.all(
103
+ inputDirs.map(async (inputDir) => {
104
+ return (await compileSubDir('cjs', cjsExt, inputDir, verbose)) + (await compileSubDir('esm', esmExt, inputDir, verbose))
105
+ }),
106
+ )
107
+ ).reduce((prev, result) => prev + result, 0)
107
108
  return result + (publint ? await packagePublint() : 0)
108
- }
109
+ }
@@ -1,74 +1,79 @@
1
- import ts, { CompilerOptions, readConfigFile, sys, getPreEmitDiagnostics, parseJsonConfigFileContent, getLineAndCharacterOfPosition, flattenDiagnosticMessageText, createProgram, convertCompilerOptionsFromJson, Diagnostic, findConfigFile } from "typescript"
2
- import { CompileParams } from "./CompileParams"
3
- import { loadConfig } from "../../../lib"
4
- import { getAllInputs } from "./inputs"
1
+ import chalk from 'chalk'
2
+ // eslint-disable-next-line import/no-internal-modules
5
3
  import merge from 'lodash/merge'
6
- import chalk from "chalk"
4
+ import {
5
+ CompilerOptions,
6
+ createProgram,
7
+ Diagnostic,
8
+ findConfigFile,
9
+ flattenDiagnosticMessageText,
10
+ getLineAndCharacterOfPosition,
11
+ getPreEmitDiagnostics,
12
+ readConfigFile,
13
+ sys,
14
+ } from 'typescript'
7
15
 
8
- export type PackageCompileTscParams = Partial<CompileParams & {
9
- compile?: {
10
- tsc?: {
11
- tsconfig?: string
12
- compilerOptions?: CompilerOptions
16
+ import { loadConfig } from '../../../lib'
17
+ import { CompileParams } from './CompileParams'
18
+ import { getAllInputs } from './inputs'
19
+
20
+ export type PackageCompileTscParams = Partial<
21
+ CompileParams & {
22
+ compile?: {
23
+ tsc?: {
24
+ compilerOptions?: CompilerOptions
25
+ tsconfig?: string
26
+ }
13
27
  }
14
28
  }
15
- }>
29
+ >
16
30
 
17
- const getCompilerOptionsJSONFollowExtends = (filename: string): Record<string, any> => {
18
- let opts = {};
19
- const config = readConfigFile(filename, ts.sys.readFile).config;
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ const getCompilerOptionsJSONFollowExtends = (filename: string): CompilerOptions => {
33
+ let opts = {}
34
+ const config = readConfigFile(filename, sys.readFile).config
20
35
  if (config.extends) {
21
- const requirePath = require.resolve(config.extends);
22
- opts = getCompilerOptionsJSONFollowExtends(requirePath);
36
+ const requirePath = require.resolve(config.extends)
37
+ opts = getCompilerOptionsJSONFollowExtends(requirePath)
23
38
  }
24
39
  if (config?.error) {
25
40
  throw Error(`getCompilerOptionsJSONFollowExtends failed ${JSON.stringify(config?.error?.messageText, null, 2)}`)
26
41
  }
27
-
28
- return config.compilerOptions
42
+
43
+ return { ...opts, ...config.compilerOptions }
29
44
  }
30
45
 
31
- const getCompilerOptions = (options?: CompilerOptions, tsconfig: string = "tsconfig.json"): CompilerOptions => {
32
- const configFileName = findConfigFile(
33
- "./",
34
- ts.sys.fileExists,
35
- tsconfig
36
- )
46
+ const getCompilerOptions = (options?: CompilerOptions, tsconfig: string = 'tsconfig.json'): CompilerOptions => {
47
+ const configFileName = findConfigFile('./', sys.fileExists, tsconfig)
37
48
  const configFileCompilerOptions = configFileName ? getCompilerOptionsJSONFollowExtends(configFileName) : undefined
38
49
 
39
50
  return merge({}, configFileCompilerOptions, options)
40
51
  }
41
52
 
42
- const getConfigFile = (options?: CompilerOptions, tsconfig: string = "tsconfig.json") => {
43
- const configFileName = findConfigFile(
44
- "./",
45
- ts.sys.fileExists,
46
- tsconfig
47
- )
48
- return {...(configFileName ? readConfigFile(configFileName, sys.readFile).config : {}), compilerOptions: getCompilerOptions(options)}
53
+ const getConfigFile = (options?: CompilerOptions, tsconfig: string = 'tsconfig.json') => {
54
+ const configFileName = findConfigFile('./', sys.fileExists, tsconfig)
55
+ return { ...(configFileName ? readConfigFile(configFileName, sys.readFile).config : {}), compilerOptions: getCompilerOptions(options) }
49
56
  }
50
57
 
51
- const compile = (fileNames: string[], optionsParam: CompilerOptions) => {
52
- console.log(chalk.blue(`compile`))
53
- const {moduleResolution, ...options} = optionsParam
58
+ const compile = (fileNames: string[], options: CompilerOptions) => {
59
+ console.log(chalk.blue('compile'))
54
60
  console.log(chalk.magenta(`options: ${JSON.stringify(options, null, 2)}`))
55
61
  const program = createProgram(fileNames, options)
56
- console.log(chalk.blue(`createProgram`))
62
+ console.log(chalk.blue('createProgram'))
57
63
  const emitResult = program.emit()
58
- console.log(chalk.blue(`emit`))
64
+ console.log(chalk.blue('emit'))
59
65
 
60
- const allDiagnostics: Diagnostic[] = getPreEmitDiagnostics(program)
61
- .concat(emitResult.diagnostics)
66
+ const allDiagnostics: Diagnostic[] = getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
62
67
 
63
68
  const errorDiagnostics = allDiagnostics.filter((diagnostic) => diagnostic.category === 1)
64
69
 
65
- allDiagnostics.forEach(diagnostic => {
70
+ allDiagnostics.forEach((diagnostic) => {
66
71
  if (diagnostic.file) {
67
- let { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!)
68
- let message = flattenDiagnosticMessageText(diagnostic.messageText, "\n")
72
+ const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start!)
73
+ const message = flattenDiagnosticMessageText(diagnostic.messageText, '\n')
69
74
  console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`)
70
75
  } else {
71
- console.log(flattenDiagnosticMessageText(diagnostic.messageText, "\n"))
76
+ console.log(flattenDiagnosticMessageText(diagnostic.messageText, '\n'))
72
77
  }
73
78
  })
74
79
 
@@ -82,19 +87,19 @@ const compile = (fileNames: string[], optionsParam: CompilerOptions) => {
82
87
 
83
88
  export const packageCompileTsc = async (params?: PackageCompileTscParams): Promise<number> => {
84
89
  const defaultCompilerOptions: CompilerOptions = {
85
- sourceMap: true,
86
90
  declaration: true,
87
91
  declarationMap: true,
88
- rootDir: 'src',
89
92
  outDir: 'dist',
93
+ rootDir: 'src',
94
+ sourceMap: true,
90
95
  }
91
96
  const compilerOptions = merge({}, defaultCompilerOptions, params?.compile?.tsc?.compilerOptions)
92
97
  const config = await loadConfig(params)
93
98
  if (config.verbose) {
94
- console.log(`Compiling with TSC`)
99
+ console.log('Compiling with TSC')
95
100
  }
96
101
 
97
102
  const fileNames = (await getAllInputs(config.compile?.depth)).map((fileName) => `src/${fileName}`)
98
103
  const configFile = getConfigFile(compilerOptions)
99
104
  return compile(fileNames, configFile.compilerOptions)
100
- }
105
+ }
@@ -1,24 +1,23 @@
1
- import { build, BuildOptions } from 'tsc-prog'
2
- import { CompileParams } from "./CompileParams"
3
- import { loadConfig } from "../../../lib"
4
- import { getAllInputs } from "./inputs"
5
1
  import { cwd } from 'process'
2
+ import { build, BuildOptions } from 'tsc-prog'
6
3
 
4
+ import { loadConfig } from '../../../lib'
5
+ import { CompileParams } from './CompileParams'
7
6
 
8
7
  export const packageCompileTscTypes = async (params?: CompileParams): Promise<number> => {
9
8
  const pkg = process.env.INIT_CWD
10
9
  const buildOptions: BuildOptions = {
11
10
  basePath: pkg ?? cwd(),
12
11
  compilerOptions: {
13
- sourceMap: true,
14
12
  declaration: true,
15
13
  declarationMap: true,
16
14
  emitDeclarationOnly: true,
17
15
  esModuleInterop: true,
18
- outDir: 'dist'
16
+ outDir: 'dist',
17
+ sourceMap: true,
19
18
  },
19
+ exclude: ['dist', 'docs'],
20
20
  include: ['src'],
21
- exclude: ['dist', 'docs']
22
21
  }
23
22
 
24
23
  const config = await loadConfig(params)
@@ -26,7 +25,6 @@ export const packageCompileTscTypes = async (params?: CompileParams): Promise<nu
26
25
  console.log(`Compiling types with TSC [${pkg}]`)
27
26
  }
28
27
 
29
- const fileNames = (await getAllInputs(config.compile?.depth)).map((fileName) => `src/${fileName}`)
30
28
  build(buildOptions)
31
29
  return 0
32
- }
30
+ }
@@ -1,17 +1,20 @@
1
1
  import { build, defineConfig, Options } from 'tsup'
2
- import {getInputDirs, getInputs} from './inputs'
2
+
3
+ import { loadConfig } from '../../../lib'
3
4
  import { packagePublint } from '../publint'
4
5
  import { CompileParams } from './CompileParams'
5
- import { loadConfig } from '../../../lib'
6
+ import { getInputDirs, getInputs } from './inputs'
6
7
  import { packageCompileTscTypes } from './tscTypes'
7
8
 
8
- export type PackageCompileTsupParams = Partial<CompileParams & {
9
- compile?: {
10
- tsup?: {
11
- options?: Options
9
+ export type PackageCompileTsupParams = Partial<
10
+ CompileParams & {
11
+ compile?: {
12
+ tsup?: {
13
+ options?: Options
14
+ }
12
15
  }
13
16
  }
14
- }>
17
+ >
15
18
 
16
19
  const compileSubDir = async (subDir?: string, options?: Options, verbose?: boolean) => {
17
20
  const dir = subDir === '.' ? undefined : subDir
@@ -22,8 +25,8 @@ const compileSubDir = async (subDir?: string, options?: Options, verbose?: boole
22
25
  clean: true,
23
26
  dts: {
24
27
  entry: ['src/index.ts'],
28
+ only: false,
25
29
  resolve: false,
26
- only: false
27
30
  },
28
31
  entry: subDir ? input.map((file) => `./src/${file}`) : ['./src/index.ts'],
29
32
  format: ['cjs', 'esm'],
@@ -31,7 +34,7 @@ const compileSubDir = async (subDir?: string, options?: Options, verbose?: boole
31
34
  sourcemap: true,
32
35
  splitting: false,
33
36
  tsconfig: 'tsconfig.json',
34
- ...options
37
+ ...options,
35
38
  })
36
39
  const optionsList = (
37
40
  await Promise.all(
@@ -45,20 +48,22 @@ const compileSubDir = async (subDir?: string, options?: Options, verbose?: boole
45
48
  ).flat()
46
49
  await Promise.all(optionsList.map((options) => build(options)))
47
50
 
48
- return await packageCompileTscTypes({verbose})
51
+ return await packageCompileTscTypes({ verbose })
49
52
  }
50
53
 
51
54
  export const packageCompileTsup = async (params?: PackageCompileTsupParams) => {
52
55
  const config = await loadConfig(params)
53
56
  if (config.verbose) {
54
- console.log(`Compiling with TSUP`)
57
+ console.log('Compiling with TSUP')
55
58
  }
56
59
  const inputDirs = await getInputDirs(config.compile?.depth)
57
60
 
58
- const result = (await Promise.all(
59
- inputDirs.map(async (inputDir) => {
60
- return await compileSubDir(inputDir, config.compile?.tsup?.options, config.verbose )
61
- }),
62
- )).reduce(((prev, result) => prev + result), 0)
61
+ const result = (
62
+ await Promise.all(
63
+ inputDirs.map(async (inputDir) => {
64
+ return await compileSubDir(inputDir, config.compile?.tsup?.options, config.verbose)
65
+ }),
66
+ )
67
+ ).reduce((prev, result) => prev + result, 0)
63
68
  return result + (config.compile?.publint ? await packagePublint() : 0)
64
- }
69
+ }
@@ -6,7 +6,7 @@ export interface PackagePublintParams {
6
6
  verbose?: boolean
7
7
  }
8
8
 
9
- export const packagePublint = async (params?: PackagePublintParams) => {
9
+ export const packagePublint = async (_params?: PackagePublintParams) => {
10
10
  const pkgDir = process.env.INIT_CWD
11
11
 
12
12
  const pkg = JSON.parse(await fs.readFile(`${pkgDir}/package.json`, 'utf8'))
package/src/lib/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from './dependencies'
5
5
  export * from './file'
6
6
  export * from './generateIgnoreFiles'
7
7
  export * from './jsonFormatters'
8
+ export * from './loadConfig'
8
9
  export * from './parsedPackageJSON'
9
10
  export * from './processEx'
10
11
  export * from './runSteps'
@@ -16,4 +17,3 @@ export * from './string'
16
17
  export * from './withErrnoException'
17
18
  export * from './withError'
18
19
  export * from './yarn'
19
- export * from './loadConfig'
@@ -1,7 +1,9 @@
1
1
  import chalk from 'chalk'
2
- import merge from 'lodash/merge'
3
2
  import { cosmiconfig } from 'cosmiconfig'
3
+ // eslint-disable-next-line import/no-internal-modules
4
+ import merge from 'lodash/merge'
4
5
 
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
7
  let config: Record<string, any>
6
8
 
7
9
  export const loadConfig = async <T extends object>(params?: T): Promise<T> => {
@@ -16,4 +18,4 @@ export const loadConfig = async <T extends object>(params?: T): Promise<T> => {
16
18
  console.log(chalk.gray(`Loading config from ${configFilePath}`))
17
19
  }
18
20
  return merge({}, config, params)
19
- }
21
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "include": ["src"],
3
2
  "exclude": ["src/**/*.spec.*", "dist", "docs"],
4
- "extends": "./tsconfig.json"
3
+ "extends": "./tsconfig.json",
4
+ "include": ["src"]
5
5
  }