@xylabs/ts-scripts-yarn3 3.0.10 → 3.0.12
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.
- package/dist/actions/package/compile/CompileParams.js +17 -0
- package/dist/actions/package/compile/CompileParams.js.map +1 -0
- package/dist/actions/package/compile/CompileParams.mjs +1 -0
- package/dist/actions/package/compile/CompileParams.mjs.map +1 -0
- package/dist/actions/package/compile/compile.js +86 -0
- package/dist/actions/package/compile/compile.js.map +1 -0
- package/dist/actions/package/compile/compile.mjs +52 -0
- package/dist/actions/package/compile/compile.mjs.map +1 -0
- package/dist/actions/package/compile/copyTypeFiles.js +49 -0
- package/dist/actions/package/compile/copyTypeFiles.js.map +1 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs +25 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -0
- package/dist/actions/package/compile/index.js +29 -0
- package/dist/actions/package/compile/index.js.map +1 -0
- package/dist/actions/package/compile/index.mjs +5 -0
- package/dist/actions/package/compile/index.mjs.map +1 -0
- package/dist/actions/package/compile/inputs.js +58 -0
- package/dist/actions/package/compile/inputs.js.map +1 -0
- package/dist/actions/package/compile/inputs.mjs +32 -0
- package/dist/actions/package/compile/inputs.mjs.map +1 -0
- package/dist/actions/package/{compile.js → compile/rollup.js} +26 -76
- package/dist/actions/package/compile/rollup.js.map +1 -0
- package/dist/actions/package/compile/rollup.mjs +98 -0
- package/dist/actions/package/compile/rollup.mjs.map +1 -0
- package/dist/actions/package/compile/tsc.js +114 -0
- package/dist/actions/package/compile/tsc.js.map +1 -0
- package/dist/actions/package/compile/tsc.mjs +80 -0
- package/dist/actions/package/compile/tsc.mjs.map +1 -0
- package/dist/actions/package/compile/tscTypes.js +55 -0
- package/dist/actions/package/compile/tscTypes.js.map +1 -0
- package/dist/actions/package/compile/tscTypes.mjs +31 -0
- package/dist/actions/package/compile/tscTypes.mjs.map +1 -0
- package/dist/actions/package/compile/tsup.js +75 -0
- package/dist/actions/package/compile/tsup.js.map +1 -0
- package/dist/actions/package/compile/tsup.mjs +51 -0
- package/dist/actions/package/compile/tsup.mjs.map +1 -0
- package/dist/actions/package/publint.js +1 -1
- package/dist/actions/package/publint.js.map +1 -1
- package/dist/actions/package/publint.mjs +1 -1
- package/dist/actions/package/publint.mjs.map +1 -1
- package/dist/bin/package/compile-tsup.js +31 -0
- package/dist/bin/package/compile-tsup.js.map +1 -0
- package/dist/bin/package/compile-tsup.mjs +8 -0
- package/dist/bin/package/compile-tsup.mjs.map +1 -0
- package/dist/index.d.mts +53 -10
- package/dist/index.d.ts +53 -10
- package/dist/lib/index.js +3 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/loadConfig.js +54 -0
- package/dist/lib/loadConfig.js.map +1 -0
- package/dist/lib/loadConfig.mjs +20 -0
- package/dist/lib/loadConfig.mjs.map +1 -0
- package/package.json +6 -6
- package/src/actions/package/compile/CompileParams.ts +10 -0
- package/src/actions/package/compile/compile.ts +59 -0
- package/src/actions/package/compile/copyTypeFiles.ts +27 -0
- package/src/actions/package/compile/index.ts +4 -0
- package/src/actions/package/compile/inputs.ts +33 -0
- package/src/actions/package/compile/rollup.ts +108 -0
- package/src/actions/package/compile/tsc.ts +100 -0
- package/src/actions/package/compile/tscTypes.ts +32 -0
- package/src/actions/package/compile/tsup.ts +64 -0
- package/src/actions/package/publint.ts +5 -1
- package/src/bin/package/compile-tsup.ts +9 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/loadConfig.ts +19 -0
- package/tsconfig.json +1 -7
- package/dist/actions/package/compile.js.map +0 -1
- package/dist/actions/package/compile.mjs +0 -149
- package/dist/actions/package/compile.mjs.map +0 -1
- package/src/actions/package/compile.ts +0 -176
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
2
|
-
import typescript from '@rollup/plugin-typescript'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import { cosmiconfig } from 'cosmiconfig'
|
|
5
|
-
import { copyFile, readdir } from 'fs/promises'
|
|
6
|
-
import { OutputOptions, rollup, RollupLog, RollupOptions, watch } from 'rollup'
|
|
7
|
-
import externalDeps from 'rollup-plugin-exclude-dependencies-from-bundle'
|
|
8
|
-
import nodeExternals from 'rollup-plugin-node-externals'
|
|
9
|
-
|
|
10
|
-
import { loadPackageConfig, PackageJsonEx } from '../../loadPackageConfig'
|
|
11
|
-
import { packagePublint } from './publint'
|
|
12
|
-
|
|
13
|
-
export interface CompilePackageParams {
|
|
14
|
-
publint?: boolean
|
|
15
|
-
verbose?: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const rollItUp = async (format: 'cjs' | 'esm', ext: string, subDir?: string) => {
|
|
19
|
-
const dir = subDir === '.' ? undefined : subDir
|
|
20
|
-
const input = await getInputs(dir)
|
|
21
|
-
const tsPlugIn = typescript({
|
|
22
|
-
baseUrl: 'src',
|
|
23
|
-
declaration: !dir || !subDir,
|
|
24
|
-
declarationMap: !dir || !subDir,
|
|
25
|
-
emitDeclarationOnly: false,
|
|
26
|
-
esModuleInterop: true,
|
|
27
|
-
exclude: ['**/*.spec.*', 'dist', 'docs', 'node_modules', 'packages'],
|
|
28
|
-
outDir: dir ? `dist/${dir}` : 'dist',
|
|
29
|
-
rootDir: 'src',
|
|
30
|
-
tsconfig: 'tsconfig.json',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const errors: RollupLog[] = []
|
|
34
|
-
const warnings: RollupLog[] = []
|
|
35
|
-
const infos: RollupLog[] = []
|
|
36
|
-
const debugs: RollupLog[] = []
|
|
37
|
-
|
|
38
|
-
const options: RollupOptions = {
|
|
39
|
-
input: subDir ? input.map((file) => `./src/${file}`) : ['./src/index.ts'],
|
|
40
|
-
logLevel: 'warn',
|
|
41
|
-
onLog: (level, log, defaultHandler) => {
|
|
42
|
-
const pushLog = !(log.code === 'EMPTY_BUNDLE' || log.code === 'MIXED_EXPORTS' || log.code === 'UNUSED_EXTERNAL_IMPORT')
|
|
43
|
-
if (pushLog) {
|
|
44
|
-
switch (level) {
|
|
45
|
-
case 'warn': {
|
|
46
|
-
warnings.push(log)
|
|
47
|
-
break
|
|
48
|
-
}
|
|
49
|
-
case 'info': {
|
|
50
|
-
infos.push(log)
|
|
51
|
-
break
|
|
52
|
-
}
|
|
53
|
-
case 'debug': {
|
|
54
|
-
debugs.push(log)
|
|
55
|
-
break
|
|
56
|
-
}
|
|
57
|
-
default: {
|
|
58
|
-
errors.push(log)
|
|
59
|
-
break
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
console.log(chalk.yellow(`${level}: ${log.message} [${log.code}]`))
|
|
64
|
-
if (log.id) {
|
|
65
|
-
console.log(chalk.gray(log.id))
|
|
66
|
-
}
|
|
67
|
-
log.ids?.map((id) => {
|
|
68
|
-
console.log(chalk.gray(id))
|
|
69
|
-
})
|
|
70
|
-
return defaultHandler(level, log)
|
|
71
|
-
},
|
|
72
|
-
plugins: [commonjs(), externalDeps(), nodeExternals(), tsPlugIn],
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const outputOptions: OutputOptions = {
|
|
76
|
-
dir: subDir ? `dist/${subDir}` : 'dist',
|
|
77
|
-
dynamicImportInCjs: true,
|
|
78
|
-
entryFileNames: (chunkInfo) => `${chunkInfo.name}.${ext}`,
|
|
79
|
-
format,
|
|
80
|
-
sourcemap: true,
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (input.length) {
|
|
84
|
-
await (await rollup(options)).write(outputOptions)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return errors.length + warnings.length
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const getInputs = async (subDir?: string) => {
|
|
91
|
-
return (await readdir(subDir ? `src/${subDir}` : 'src', { recursive: false }))
|
|
92
|
-
.filter((file) => (file.endsWith('.ts') || file.endsWith('.tsx')) && !file.endsWith('d.ts') && !file.endsWith('spec.ts'))
|
|
93
|
-
.map((file) => (subDir ? `${subDir}/${file}` : file))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const getInputDirs = async (depth: number) => {
|
|
97
|
-
if (depth === 0) {
|
|
98
|
-
return []
|
|
99
|
-
}
|
|
100
|
-
return [
|
|
101
|
-
'.',
|
|
102
|
-
...(await readdir('src', { recursive: depth > 1, withFileTypes: true }))
|
|
103
|
-
.filter((file) => file.isDirectory())
|
|
104
|
-
.map((file) => {
|
|
105
|
-
const pathParts = file.path.split('/')
|
|
106
|
-
pathParts.shift()
|
|
107
|
-
if (pathParts.length) {
|
|
108
|
-
const root = pathParts.join('/')
|
|
109
|
-
return `${root}/${file.name}`
|
|
110
|
-
} else {
|
|
111
|
-
return file.name
|
|
112
|
-
}
|
|
113
|
-
}),
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const getDistTypeFiles = async () => {
|
|
118
|
-
return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts')).map((file) => `dist/${file}`)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const getDistTypeMapFiles = async () => {
|
|
122
|
-
return (await readdir('dist', { recursive: true })).filter((file) => file.endsWith('d.ts.map')).map((file) => `dist/${file}`)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const buildIt = async (pkg: PackageJsonEx, compileDepth: number) => {
|
|
126
|
-
console.log(`Compile Depth: ${compileDepth}`)
|
|
127
|
-
const inputDirs = await getInputDirs(compileDepth)
|
|
128
|
-
|
|
129
|
-
const pkgType = pkg.type ?? 'commonjs'
|
|
130
|
-
|
|
131
|
-
const esmExt = pkgType === 'module' ? 'js' : 'mjs'
|
|
132
|
-
const cjsExt = pkgType === 'commonjs' ? 'js' : 'cjs'
|
|
133
|
-
|
|
134
|
-
const rollupResult = inputDirs.length
|
|
135
|
-
? await Promise.all(
|
|
136
|
-
inputDirs.map(async (inputDir) => {
|
|
137
|
-
return (await rollItUp('esm', esmExt, inputDir)) + (await rollItUp('cjs', cjsExt, inputDir))
|
|
138
|
-
}),
|
|
139
|
-
)
|
|
140
|
-
: [(await rollItUp('esm', esmExt)) + (await rollItUp('cjs', cjsExt))]
|
|
141
|
-
|
|
142
|
-
//hybrid packages want two copies of the types
|
|
143
|
-
const distTypeFiles = await getDistTypeFiles()
|
|
144
|
-
await Promise.all(
|
|
145
|
-
distTypeFiles.map(async (file) => {
|
|
146
|
-
await copyFile(file, file.replace('d.ts', 'd.mts'))
|
|
147
|
-
}),
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
const distTypeMapFiles = await getDistTypeMapFiles()
|
|
151
|
-
await Promise.all(
|
|
152
|
-
distTypeMapFiles.map(async (file) => {
|
|
153
|
-
await copyFile(file, file.replace('d.ts.map', 'd.mts.map'))
|
|
154
|
-
}),
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
return rollupResult.reduce((prev, item) => prev + item, 0)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export const packageCompile = async ({ publint = true, verbose }: CompilePackageParams = { verbose: false }) => {
|
|
161
|
-
const xyConfig = await cosmiconfig('xy').search()
|
|
162
|
-
const compileDepth: number = xyConfig?.config.compile?.depth ?? 0
|
|
163
|
-
const pkgName = process.env.npm_package_name
|
|
164
|
-
if (verbose) {
|
|
165
|
-
console.log(chalk.green(`Compiling ${pkgName} Start`))
|
|
166
|
-
}
|
|
167
|
-
const result = (await buildIt(await loadPackageConfig(), compileDepth)) + (publint ? await packagePublint() : 0)
|
|
168
|
-
if (result) {
|
|
169
|
-
const input = await getInputs()
|
|
170
|
-
console.log(`Inputs: ${JSON.stringify(input, null, 2)}`)
|
|
171
|
-
console.error(chalk.red(`Compiling ${pkgName} Failed [${result}]`))
|
|
172
|
-
} else if (verbose) {
|
|
173
|
-
console.log(chalk.green(`Compiling ${pkgName} Done`))
|
|
174
|
-
}
|
|
175
|
-
return result
|
|
176
|
-
}
|