diff --git a/.yarn/versions/5bd80959.yml b/.yarn/versions/5bd80959.yml new file mode 100644 index 00000000..868e1fa5 --- /dev/null +++ b/.yarn/versions/5bd80959.yml @@ -0,0 +1,12 @@ +releases: + "@xylabs/config": minor + "@xylabs/eslint-config": minor + "@xylabs/eslint-config-react": minor + "@xylabs/ts-scripts": minor + "@xylabs/ts-scripts-react-yarn3": minor + "@xylabs/ts-scripts-yarn3": minor + "@xylabs/tsconfig": minor + "@xylabs/tsconfig-dom": minor + "@xylabs/tsconfig-dom-jest": minor + "@xylabs/tsconfig-jest": minor + "@xylabs/tsconfig-react": minor diff --git a/.yarn/versions/95cac132.yml b/.yarn/versions/95cac132.yml new file mode 100644 index 00000000..868e1fa5 --- /dev/null +++ b/.yarn/versions/95cac132.yml @@ -0,0 +1,12 @@ +releases: + "@xylabs/config": minor + "@xylabs/eslint-config": minor + "@xylabs/eslint-config-react": minor + "@xylabs/ts-scripts": minor + "@xylabs/ts-scripts-react-yarn3": minor + "@xylabs/ts-scripts-yarn3": minor + "@xylabs/tsconfig": minor + "@xylabs/tsconfig-dom": minor + "@xylabs/tsconfig-dom-jest": minor + "@xylabs/tsconfig-jest": minor + "@xylabs/tsconfig-react": minor diff --git a/package.json b/package.json index 262dabdc..48a6af7a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@typescript-eslint/parser": "^5.53.0", "@xylabs/eslint-config": "workspace:^", "@xylabs/ts-scripts-yarn3": "workspace:^", - "@xylabs/tsconfig": "^2.15.0", + "@xylabs/tsconfig": "^2.16.0-rc.2", "cpy-cli": "^4.2.0", "eslint": "^8.34.0", "eslint-config-prettier": "^8.6.0", @@ -66,7 +66,7 @@ "node": ">=14.16" }, "sideEffects": false, - "version": "2.15.0", + "version": "2.16.0-rc.2", "packageManager": "yarn@3.4.1", "scripts": { "build": "echo Building... && yarn compile", @@ -79,5 +79,6 @@ "deploy-patch": "yarn workspaces foreach --all version patch --deferred && yarn deploy-common", "deploy-common": "yarn build && yarn version apply --all && yarn workspaces foreach -ptv npm publish", "deploy-next": "yarn workspaces foreach --all version minor --deferred && yarn build && yarn version apply --all --prerelease && yarn workspaces foreach -ptv npm publish --tag next" - } + }, + "stableVersion": "2.15.0" } diff --git a/packages/eslint-config-react/package.json b/packages/eslint-config-react/package.json index 00c78167..a0476eb5 100644 --- a/packages/eslint-config-react/package.json +++ b/packages/eslint-config-react/package.json @@ -72,5 +72,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 7810c45d..15f9da53 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -67,5 +67,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/ts-scripts-react-yarn3/package.json b/packages/ts-scripts-react-yarn3/package.json index 83dbc2ec..e94fb171 100644 --- a/packages/ts-scripts-react-yarn3/package.json +++ b/packages/ts-scripts-react-yarn3/package.json @@ -106,5 +106,6 @@ "node": ">=14.16" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/ts-scripts-yarn3/package.json b/packages/ts-scripts-yarn3/package.json index 4d955ee0..b8e0c8f3 100644 --- a/packages/ts-scripts-yarn3/package.json +++ b/packages/ts-scripts-yarn3/package.json @@ -35,10 +35,12 @@ "package-copy-assets-esm": "dist/cjs/bin/package/copy-assets-esm.js", "package-deps": "dist/cjs/bin/package/deps.js", "package-gen-docs": "dist/cjs/bin/package/gen-docs.js", + "package-recompile": "dist/cjs/bin/package/recompile.js", "package-tsconfig-gen": "dist/cjs/bin/package/tsconfig-gen.js", "package-tsconfig-gen-cjs": "dist/cjs/bin/package/tsconfig-gen-cjs.js", "package-tsconfig-gen-esm": "dist/cjs/bin/package/tsconfig-gen-esm.js", "rebuild": "dist/cjs/bin/rebuild.js", + "recompile": "dist/cjs/bin/recompile.js", "reinstall": "dist/cjs/bin/reinstall.js", "relint": "dist/cjs/bin/relint.js", "sonar": "dist/cjs/bin/sonar.js", @@ -144,5 +146,6 @@ "compile": "tsc --build tsconfig.build.cjs.json && tsc --build tsconfig.build.esm.json" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/ts-scripts-yarn3/src/actions/build.ts b/packages/ts-scripts-yarn3/src/actions/build.ts index 5b96f57a..4833a00d 100644 --- a/packages/ts-scripts-yarn3/src/actions/build.ts +++ b/packages/ts-scripts-yarn3/src/actions/build.ts @@ -22,8 +22,8 @@ export const build = async ({ incremental, jobs, target, verbose, pkg }: BuildPa } const result = await runStepsAsync(`Build${incremental ? '-Incremental' : ''} [${pkg ?? 'All'}]`, [ - ['yarn', ['xy', 'compile', ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]], - ['yarn', ['xy', 'lint', ...pkgOptions, ...verboseOptions, ...incrementalOptions]], + ['yarn', ['xy', 'recompile', ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]], + ['yarn', ['xy', 'relint', ...pkgOptions, ...verboseOptions, ...incrementalOptions]], ['yarn', ['xy', 'deps', ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]], ]) console.log(`${chalk.gray('Built in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`) diff --git a/packages/ts-scripts-yarn3/src/actions/clean-eslint.ts b/packages/ts-scripts-yarn3/src/actions/clean-eslint.ts new file mode 100644 index 00000000..704333a8 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/clean-eslint.ts @@ -0,0 +1,12 @@ +import chalk from 'chalk' +import { rimrafSync } from 'rimraf' + +export const cleanESLint = () => { + const pkg = process.env.INIT_CWD + const pkgName = process.env.npm_package_name + console.log(chalk.green(`Cleaning ESLint [${pkgName}]`)) + + rimrafSync(`${pkg}/.eslintcache`) + + return 0 +} diff --git a/packages/ts-scripts-yarn3/src/actions/clean-jest.ts b/packages/ts-scripts-yarn3/src/actions/clean-jest.ts new file mode 100644 index 00000000..e5f1dda9 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/clean-jest.ts @@ -0,0 +1,7 @@ +import { runSteps } from '../lib' + +export const cleanJest = (): number => { + const pkgName = process.env.npm_package_name + + return runSteps(`Cleaning Jest [${pkgName}]`, [['jest', ['--clearCache']]]) +} diff --git a/packages/ts-scripts-yarn3/src/actions/clean.ts b/packages/ts-scripts-yarn3/src/actions/clean.ts index 2f4aadef..9e83288b 100644 --- a/packages/ts-scripts-yarn3/src/actions/clean.ts +++ b/packages/ts-scripts-yarn3/src/actions/clean.ts @@ -1,9 +1,11 @@ import { runSteps } from '../lib' +import { cleanESLint } from './clean-eslint' +import { cleanJest } from './clean-jest' export interface CleanParams { pkg?: string } export const clean = () => { - return runSteps('Clean', [['yarn', 'workspaces foreach -pA run package-clean']]) + return cleanJest() + cleanESLint() + runSteps('Clean', [['yarn', 'workspaces foreach -pA run package-clean']]) } diff --git a/packages/ts-scripts-yarn3/src/actions/index.ts b/packages/ts-scripts-yarn3/src/actions/index.ts index 246e5956..b0db70c7 100644 --- a/packages/ts-scripts-yarn3/src/actions/index.ts +++ b/packages/ts-scripts-yarn3/src/actions/index.ts @@ -20,8 +20,10 @@ export * from './lint-clean' export * from './lint-profile' export * from './package' export * from './rebuild' +export * from './recompile' export * from './reinstall' export * from './relint' +export * from './retest' export * from './sonar' export * from './statics' export * from './test' diff --git a/packages/ts-scripts-yarn3/src/actions/package/clean-outputs.ts b/packages/ts-scripts-yarn3/src/actions/package/clean-outputs.ts new file mode 100644 index 00000000..d3cc6805 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/package/clean-outputs.ts @@ -0,0 +1,15 @@ +import chalk from 'chalk' +import { rmSync } from 'fs' + +export const packageCleanOutputs = () => { + const pkg = process.env.INIT_CWD + const pkgName = process.env.npm_package_name + console.log(chalk.green(`Cleaning Outputs [${pkgName}]`)) + + const dist = `${pkg}/dist` + rmSync(dist, { force: true, recursive: true }) + + const build = `${pkg}/build` + rmSync(build, { force: true, recursive: true }) + return 0 +} diff --git a/packages/ts-scripts-yarn3/src/actions/package/clean-typescript.ts b/packages/ts-scripts-yarn3/src/actions/package/clean-typescript.ts new file mode 100644 index 00000000..c0168e35 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/package/clean-typescript.ts @@ -0,0 +1,13 @@ +import chalk from 'chalk' +import { rimrafSync } from 'rimraf' + +export const packageCleanTypescript = () => { + const pkg = process.env.INIT_CWD + const pkgName = process.env.npm_package_name + console.log(chalk.green(`Cleaning Typescript [${pkgName}]`)) + + rimrafSync(`${pkg}/*.tsbuildinfo`) + rimrafSync(`${pkg}/.tsconfig.*`) + + return 0 +} diff --git a/packages/ts-scripts-yarn3/src/actions/package/clean.ts b/packages/ts-scripts-yarn3/src/actions/package/clean.ts index e957ebba..281d4a56 100644 --- a/packages/ts-scripts-yarn3/src/actions/package/clean.ts +++ b/packages/ts-scripts-yarn3/src/actions/package/clean.ts @@ -1,18 +1,6 @@ -import chalk from 'chalk' -import { rmSync } from 'fs' -import { rimrafSync } from 'rimraf' +import { packageCleanOutputs } from './clean-outputs' +import { packageCleanTypescript } from './clean-typescript' export const packageClean = () => { - const pkg = process.env.INIT_CWD - const pkgName = process.env.npm_package_name - console.log(chalk.green(`Cleaning [${pkgName}]`)) - - const dist = `${pkg}/dist` - rmSync(dist, { force: true, recursive: true }) - - const build = `${pkg}/build` - rmSync(build, { force: true, recursive: true }) - - rimrafSync(`${pkg}/**/*.tsbuildinfo`) - rimrafSync(`${pkg}/**/.tsconfig.*`) + return packageCleanOutputs() + packageCleanTypescript() } diff --git a/packages/ts-scripts-yarn3/src/actions/package/deps.ts b/packages/ts-scripts-yarn3/src/actions/package/deps.ts index 6133db55..2aaf8d20 100644 --- a/packages/ts-scripts-yarn3/src/actions/package/deps.ts +++ b/packages/ts-scripts-yarn3/src/actions/package/deps.ts @@ -3,6 +3,8 @@ import chalk from 'chalk' import depcheck, { special } from 'depcheck' import { existsSync, readFileSync } from 'fs' +import { checkResult } from '../../lib' + export const packageDeps = async () => { const pkg = process.env.INIT_CWD const pkgName = process.env.npm_package_name @@ -93,6 +95,9 @@ export const packageDeps = async () => { }) console.log(chalk.yellow(message.join('\n'))) } + + checkResult(`Deps [${pkgName}]`, errorCount, 'warn', false) + //returning 0 here since we never want deps to be fatal return 0 } diff --git a/packages/ts-scripts-yarn3/src/actions/package/index.ts b/packages/ts-scripts-yarn3/src/actions/package/index.ts index 92577ab1..c9634425 100644 --- a/packages/ts-scripts-yarn3/src/actions/package/index.ts +++ b/packages/ts-scripts-yarn3/src/actions/package/index.ts @@ -1,9 +1,12 @@ export * from './clean' +export * from './clean-outputs' +export * from './clean-typescript' export * from './compile' export * from './compile-cjs' export * from './compile-esm' export * from './copy-assets' export * from './deps' export * from './gen-docs' +export * from './recompile' export * from './tsconfig-gen-cjs' export * from './tsconfig-gen-esm' diff --git a/packages/ts-scripts-yarn3/src/actions/package/recompile.ts b/packages/ts-scripts-yarn3/src/actions/package/recompile.ts new file mode 100644 index 00000000..5aad8cc1 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/package/recompile.ts @@ -0,0 +1,7 @@ +import { packageClean } from './clean' +import { packageCompileCjs } from './compile-cjs' +import { packageCompileEsm } from './compile-esm' + +export const packageRecompile = async () => { + return (await Promise.all([packageClean(), packageCompileEsm(), packageCompileCjs()])).reduce((prev, value) => prev + value, 0) +} diff --git a/packages/ts-scripts-yarn3/src/actions/package/tsconfig-gen-esm.ts b/packages/ts-scripts-yarn3/src/actions/package/tsconfig-gen-esm.ts index b43d5a3f..cc99a098 100644 --- a/packages/ts-scripts-yarn3/src/actions/package/tsconfig-gen-esm.ts +++ b/packages/ts-scripts-yarn3/src/actions/package/tsconfig-gen-esm.ts @@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from 'fs' import { createBuildConfig } from '../../lib' -export const packageTsconfigGenEsm = () => { +export const packageTsconfigGenEsm = (quiet = false) => { const pkg = process.env.INIT_CWD ?? './' const pkgName = process.env.npm_package_name @@ -19,7 +19,9 @@ export const packageTsconfigGenEsm = () => { currentConfig = undefined } if (currentConfig !== config) { - console.log(chalk.gray(`Updating ESM tsconfig [${pkgName}]`)) + if (!quiet) { + console.log(chalk.gray(`Updating ESM tsconfig [${pkgName}]`)) + } writeFileSync(`${pkg}/.tsconfig.build.esm.json`, config, { encoding: 'utf8' }) } } diff --git a/packages/ts-scripts-yarn3/src/actions/recompile.ts b/packages/ts-scripts-yarn3/src/actions/recompile.ts new file mode 100644 index 00000000..fb0e6f0d --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/recompile.ts @@ -0,0 +1,45 @@ +import chalk from 'chalk' + +import { runStepsAsync } from '../lib' + +export interface RecompileParams { + incremental?: boolean + jobs?: number + pkg?: string + target?: 'esm' | 'cjs' + verbose?: boolean +} + +export interface RecompilePackageParams { + pkg: string + target?: 'esm' | 'cjs' + verbose?: boolean +} + +export const recompile = async ({ verbose, target, pkg, incremental }: RecompileParams) => { + return pkg ? await recompilePackage({ pkg, target, verbose }) : await recompileAll({ incremental, target, verbose }) +} + +export const recompilePackage = ({ verbose, target, pkg }: RecompilePackageParams) => { + const verboseOptions = verbose ? ['-v'] : [] + const targetOptions = target ? ['-t', target] : [] + + return runStepsAsync(`Recompile [${pkg}]`, [['yarn', ['workspace', pkg, 'run', 'package-recompile', ...verboseOptions, ...targetOptions]]]) +} + +export const recompileAll = async ({ jobs, verbose, target, incremental }: RecompileParams) => { + const start = Date.now() + const verboseOptions = verbose ? ['-v'] : [] + const targetOptions = target ? ['-t', target] : [] + const incrementalOptions = incremental ? ['--since', '-ptA'] : ['-ptA'] + const jobsOptions = jobs ? ['-j', `${jobs}`] : [] + if (jobs) { + console.log(chalk.blue(`Jobs set to [${jobs}]`)) + } + + const result = await runStepsAsync(`Recompile${incremental ? '-Incremental' : ''} [All]`, [ + ['yarn', ['workspaces', 'foreach', ...incrementalOptions, ...jobsOptions, 'run', 'package-recompile', ...verboseOptions, ...targetOptions]], + ]) + console.log(`${chalk.gray('Recompiled in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`) + return result +} diff --git a/packages/ts-scripts-yarn3/src/actions/retest.ts b/packages/ts-scripts-yarn3/src/actions/retest.ts new file mode 100644 index 00000000..c8fe260b --- /dev/null +++ b/packages/ts-scripts-yarn3/src/actions/retest.ts @@ -0,0 +1,8 @@ +import { runSteps } from '../lib' + +export const retest = () => { + return runSteps('Test', [ + ['yarn', ['jest', '--clearCache']], + ['yarn', ['jest', '.']], + ]) +} diff --git a/packages/ts-scripts-yarn3/src/bin/package/clean-outputs.ts b/packages/ts-scripts-yarn3/src/bin/package/clean-outputs.ts new file mode 100644 index 00000000..32c2c854 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/bin/package/clean-outputs.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { packageCleanOutputs } from '../../actions' + +packageCleanOutputs() diff --git a/packages/ts-scripts-yarn3/src/bin/package/clean-typescript.ts b/packages/ts-scripts-yarn3/src/bin/package/clean-typescript.ts new file mode 100644 index 00000000..813d8477 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/bin/package/clean-typescript.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { packageCleanTypescript } from '../../actions' + +packageCleanTypescript() diff --git a/packages/ts-scripts-yarn3/src/bin/package/recompile.ts b/packages/ts-scripts-yarn3/src/bin/package/recompile.ts new file mode 100644 index 00000000..9e1a8e1a --- /dev/null +++ b/packages/ts-scripts-yarn3/src/bin/package/recompile.ts @@ -0,0 +1,9 @@ +#!/usr/bin/env node + +import chalk from 'chalk' +import { packageRecompile } from '../../actions' + +packageRecompile().then((value) => process.exitCode = value).catch((reason) => { + console.error(chalk.red(reason)) + process.exitCode = 1 +}) \ No newline at end of file diff --git a/packages/ts-scripts-yarn3/src/bin/recompile.ts b/packages/ts-scripts-yarn3/src/bin/recompile.ts new file mode 100644 index 00000000..f7b45c90 --- /dev/null +++ b/packages/ts-scripts-yarn3/src/bin/recompile.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +import { runXyWithWarning } from "../lib" + +runXyWithWarning('recompile') diff --git a/packages/ts-scripts-yarn3/src/lib/checkResult.ts b/packages/ts-scripts-yarn3/src/lib/checkResult.ts new file mode 100644 index 00000000..ac9804fb --- /dev/null +++ b/packages/ts-scripts-yarn3/src/lib/checkResult.ts @@ -0,0 +1,12 @@ +import chalk from 'chalk' + +export const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => { + if (result) { + const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]' + const chalkFunc = level === 'error' ? chalk.red : chalk.yellow + console[level](chalkFunc(`${name} had ${result} failures ${exiting}`)) + if (exitOnFail) { + process.exit(result) + } + } +} diff --git a/packages/ts-scripts-yarn3/src/lib/dependencies/detectDuplicateDependencies.ts b/packages/ts-scripts-yarn3/src/lib/dependencies/detectDuplicateDependencies.ts index fd2b7e9d..aefee468 100644 --- a/packages/ts-scripts-yarn3/src/lib/dependencies/detectDuplicateDependencies.ts +++ b/packages/ts-scripts-yarn3/src/lib/dependencies/detectDuplicateDependencies.ts @@ -19,24 +19,25 @@ export const detectDuplicateDependencies = (depsFromPackageJSON?: string[], Defa } catch (e) { console.error(`Error running yarn why: ${e}`) exitCode = 1 - return + return exitCode } if (output) { exitCode = new DuplicateDetector(output, dependency).detect() - return + return exitCode } else { console.log(`${dependency} - N/A`) if (depsFromPackageJSON) { console.log(`🚨 Library ${dependency} was requested in package.json but not found`) } exitCode = 1 - return + return exitCode } }) return exitCode } else { console.log('🚨 No dependencies where passed') + return exitCode } }) } diff --git a/packages/ts-scripts-yarn3/src/lib/index.ts b/packages/ts-scripts-yarn3/src/lib/index.ts index a3cd29b9..2a64a427 100644 --- a/packages/ts-scripts-yarn3/src/lib/index.ts +++ b/packages/ts-scripts-yarn3/src/lib/index.ts @@ -1,3 +1,4 @@ +export * from './checkResult' export * from './createBuildConfig' export * from './defaultBuildConfig' export * from './dependencies' diff --git a/packages/ts-scripts-yarn3/src/lib/runSteps.ts b/packages/ts-scripts-yarn3/src/lib/runSteps.ts index e294dac9..4aad4577 100644 --- a/packages/ts-scripts-yarn3/src/lib/runSteps.ts +++ b/packages/ts-scripts-yarn3/src/lib/runSteps.ts @@ -2,16 +2,18 @@ import chalk from 'chalk' import { spawnSync, SpawnSyncOptionsWithBufferEncoding } from 'child_process' import { existsSync } from 'fs' +import { checkResult } from './checkResult' import { safeExit } from './safeExit' export type ScriptStep = - | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc', /*arg*/ string | string[]] + | [/*command*/ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /*arg*/ string | string[]] | [/*command*/ string, /*arg*/ string | string[], /*config*/ SpawnSyncOptionsWithBufferEncoding] -export const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]) => { +export const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => { return safeExit(() => { const pkgName = process.env.npm_package_name console.log(chalk.green(`${name} [${pkgName}]`)) + let totalStatus = 0 for (let i = 0; i < steps.length; i++) { const [command, args, config] = steps[i] if (messages?.[i]) { @@ -21,17 +23,17 @@ export const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, m if (command === 'node' && !existsSync(argList[0])) { throw Error(`File not found [${argList[0]}]`) } - const status = spawnSync(command, Array.isArray(args) ? args : args.split(' '), { - ...config, - encoding: 'utf8', - env: { FORCE_COLOR: '3', ...process.env }, - shell: true, - stdio: 'inherit', - }).status - if (status && exitOnFail) { - return status - } + const status = + spawnSync(command, Array.isArray(args) ? args : args.split(' '), { + ...config, + encoding: 'utf8', + env: { FORCE_COLOR: '3', ...process.env }, + shell: true, + stdio: 'inherit', + }).status ?? 0 + checkResult(name, status, 'error', exitOnFail) + totalStatus += status ?? 0 } - return 0 - }) + return totalStatus + }, !!exitOnFail) } diff --git a/packages/ts-scripts-yarn3/src/lib/runStepsAsync.ts b/packages/ts-scripts-yarn3/src/lib/runStepsAsync.ts index 720e4c48..228cc3af 100644 --- a/packages/ts-scripts-yarn3/src/lib/runStepsAsync.ts +++ b/packages/ts-scripts-yarn3/src/lib/runStepsAsync.ts @@ -2,9 +2,11 @@ import chalk from 'chalk' import { spawn } from 'child_process' import { existsSync } from 'fs' +import { checkResult } from './checkResult' import { ScriptStep } from './runSteps' +import { safeExitAsync } from './safeExit' -export const runStepAsync = (step: ScriptStep, exitOnFail = true, message?: string) => { +export const runStepAsync = (name: string, step: ScriptStep, exitOnFail = true, message?: string) => { return new Promise((resolve) => { const [command, args, config] = step if (message) { @@ -28,9 +30,7 @@ export const runStepAsync = (step: ScriptStep, exitOnFail = true, message?: stri )}`, ), ) - if (exitOnFail) { - process.exit(code) - } + checkResult(name, code, 'error', exitOnFail) resolve(code) } else { resolve(0) @@ -40,16 +40,13 @@ export const runStepAsync = (step: ScriptStep, exitOnFail = true, message?: stri } export const runStepsAsync = async (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]) => { - try { + return await safeExitAsync(async () => { const pkgName = process.env.npm_package_name console.log(chalk.green(`${name} [${pkgName}]`)) let result = 0 for (let i = 0; i < steps.length; i++) { - result += await runStepAsync(steps[i], exitOnFail, messages?.[i]) + result += await runStepAsync(name, steps[i], exitOnFail, messages?.[i]) } return result - } catch (ex) { - console.error(chalk.red(ex)) - process.exit(-1) - } + }) } diff --git a/packages/ts-scripts-yarn3/src/lib/safeExit.ts b/packages/ts-scripts-yarn3/src/lib/safeExit.ts index 450cd2da..3a0be21b 100644 --- a/packages/ts-scripts-yarn3/src/lib/safeExit.ts +++ b/packages/ts-scripts-yarn3/src/lib/safeExit.ts @@ -2,16 +2,28 @@ import { processEx } from './processEx' -const safeExit = (func: () => number | undefined) => { +const safeExit = (func: () => number, exitOnFail = true): number => { try { const result = func() - if (result) { + if (result && exitOnFail) { process.exit(result) } return result } catch (ex) { - processEx(ex) + return processEx(ex) } } -export { safeExit } +const safeExitAsync = async (func: () => Promise, exitOnFail = true): Promise => { + try { + const result = await func() + if (result && exitOnFail) { + process.exit(result) + } + return result + } catch (ex) { + return processEx(ex) + } +} + +export { safeExit, safeExitAsync } diff --git a/packages/ts-scripts-yarn3/src/lib/xy/xyBuildCommands.ts b/packages/ts-scripts-yarn3/src/lib/xy/xyBuildCommands.ts index 9f4addc0..467817b7 100644 --- a/packages/ts-scripts-yarn3/src/lib/xy/xyBuildCommands.ts +++ b/packages/ts-scripts-yarn3/src/lib/xy/xyBuildCommands.ts @@ -1,6 +1,6 @@ import yargs from 'yargs' -import { build, compile, copyAssets, rebuild } from '../../actions' +import { build, compile, copyAssets, rebuild, recompile } from '../../actions' export const xyBuildCommands = (args: yargs.Argv) => { return args @@ -47,6 +47,27 @@ export const xyBuildCommands = (args: yargs.Argv) => { }) }, ) + .command( + 'recompile [package]', + 'Re-compile with Typescript & Copy Images', + (yargs) => { + return yargs.positional('package', { + describe: 'Specific package to re-compile', + }) + }, + async (argv) => { + if (argv.verbose) { + console.log(`Re-compiling: ${argv.package ?? 'all'}`) + } + process.exitCode = await recompile({ + incremental: !!argv.incremental, + jobs: argv.jobs as number, + pkg: argv.package as string, + target: argv.target as 'esm' | 'cjs', + verbose: !!argv.verbose, + }) + }, + ) .command( 'rebuild [package]', 'Rebuild - Clean, Compile & Lint', diff --git a/packages/ts-scripts-yarn3/src/lib/xy/xyCommonCommands.ts b/packages/ts-scripts-yarn3/src/lib/xy/xyCommonCommands.ts index 1b21166b..7c044aca 100644 --- a/packages/ts-scripts-yarn3/src/lib/xy/xyCommonCommands.ts +++ b/packages/ts-scripts-yarn3/src/lib/xy/xyCommonCommands.ts @@ -7,6 +7,7 @@ import { gitlint, gitlintFix, license, + retest, test, tsconfigGen, tsconfigGenClean, @@ -81,6 +82,17 @@ export const xyCommonCommands = (args: yargs.Argv) => { process.exitCode = argv.fix ? gitlintFix() : gitlint() }, ) + .command( + 'retest', + 'Re-Test - Run Jest Tests with cleaned cache', + (yargs) => { + return yargs + }, + (argv) => { + if (argv.verbose) console.log('Re-Testing') + process.exitCode = retest() + }, + ) .command( 'test', 'Test - Run Jest Tests', diff --git a/packages/ts-scripts/package.json b/packages/ts-scripts/package.json index 17e55152..c5f9524a 100644 --- a/packages/ts-scripts/package.json +++ b/packages/ts-scripts/package.json @@ -104,5 +104,6 @@ "node": ">=14.16" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/tsconfig-dom-jest/package.json b/packages/tsconfig-dom-jest/package.json index 47307596..82d35bc0 100644 --- a/packages/tsconfig-dom-jest/package.json +++ b/packages/tsconfig-dom-jest/package.json @@ -35,5 +35,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/tsconfig-dom/package.json b/packages/tsconfig-dom/package.json index 867874fc..6323f52c 100644 --- a/packages/tsconfig-dom/package.json +++ b/packages/tsconfig-dom/package.json @@ -35,5 +35,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/tsconfig-jest/package.json b/packages/tsconfig-jest/package.json index 9830184a..a7da9d4d 100644 --- a/packages/tsconfig-jest/package.json +++ b/packages/tsconfig-jest/package.json @@ -39,5 +39,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/tsconfig-react/package.json b/packages/tsconfig-react/package.json index b097f164..69312837 100644 --- a/packages/tsconfig-react/package.json +++ b/packages/tsconfig-react/package.json @@ -39,5 +39,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/packages/tsconfig/package.json b/packages/tsconfig/package.json index 9cb89ebe..94043aa4 100644 --- a/packages/tsconfig/package.json +++ b/packages/tsconfig/package.json @@ -32,5 +32,6 @@ "url": "https://github.com/xylabs/config.git" }, "sideEffects": false, - "version": "2.15.0" + "version": "2.16.0-rc.2", + "stableVersion": "2.15.0" } diff --git a/yarn.lock b/yarn.lock index 84864dcb..c28580a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2708,7 +2708,7 @@ __metadata: "@typescript-eslint/parser": ^5.53.0 "@xylabs/eslint-config": "workspace:^" "@xylabs/ts-scripts-yarn3": "workspace:^" - "@xylabs/tsconfig": ^2.15.0 + "@xylabs/tsconfig": ^2.16.0-rc.2 cpy-cli: ^4.2.0 depcheck: ^1.4.3 eslint: ^8.34.0 @@ -2959,10 +2959,12 @@ __metadata: package-copy-assets-esm: dist/cjs/bin/package/copy-assets-esm.js package-deps: dist/cjs/bin/package/deps.js package-gen-docs: dist/cjs/bin/package/gen-docs.js + package-recompile: dist/cjs/bin/package/recompile.js package-tsconfig-gen: dist/cjs/bin/package/tsconfig-gen.js package-tsconfig-gen-cjs: dist/cjs/bin/package/tsconfig-gen-cjs.js package-tsconfig-gen-esm: dist/cjs/bin/package/tsconfig-gen-esm.js rebuild: dist/cjs/bin/rebuild.js + recompile: dist/cjs/bin/recompile.js reinstall: dist/cjs/bin/reinstall.js relint: dist/cjs/bin/relint.js sonar: dist/cjs/bin/sonar.js @@ -3101,7 +3103,7 @@ __metadata: languageName: unknown linkType: soft -"@xylabs/tsconfig@^2.15.0, @xylabs/tsconfig@workspace:^, @xylabs/tsconfig@workspace:packages/tsconfig": +"@xylabs/tsconfig@^2.16.0-rc.2, @xylabs/tsconfig@workspace:^, @xylabs/tsconfig@workspace:packages/tsconfig": version: 0.0.0-use.local resolution: "@xylabs/tsconfig@workspace:packages/tsconfig" dependencies: