Skip to content

Commit

Permalink
types by tsup in compile and tsc in build - 4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Aug 23, 2024
1 parent 686a804 commit 9c4716b
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/config",
"version": "4.0.1",
"version": "4.0.2",
"description": "TypeScript project scripts",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-flat/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/eslint-config-flat",
"version": "4.0.1",
"version": "4.0.2",
"description": "ESLint Config used throughout XY Labs TypeScript/JavaScript libraries and react projects",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-react-flat/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/eslint-config-react-flat",
"version": "4.0.1",
"version": "4.0.2",
"description": "ESLint Config used throughout XY Labs TypeScript/JavaScript libraries and react projects",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-scripts-react-yarn3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/ts-scripts-react-yarn3",
"version": "4.0.1",
"version": "4.0.2",
"description": "TypeScript project scripts",
"keywords": [
"xylabs",
Expand Down
3 changes: 2 additions & 1 deletion packages/ts-scripts-yarn3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xylabs/ts-scripts-yarn3",
"version": "4.0.1",
"version": "4.0.2",
"description": "TypeScript project scripts",
"keywords": [
"xylabs",
Expand Down Expand Up @@ -59,6 +59,7 @@
"lint-clean": "dist/bin/lint-clean.mjs",
"lint-fast": "dist/bin/lint-fast.mjs",
"lint-profile": "dist/bin/lint-profile.mjs",
"package-build": "dist/bin/package/build.mjs",
"package-clean": "dist/bin/package/clean.mjs",
"package-compile": "dist/bin/package/compile.mjs",
"package-compile-only": "dist/bin/package/compile-only.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-scripts-yarn3/src/actions/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const build = async ({
}

const result = await runStepsAsync(`Build${incremental ? '-Incremental' : ''} [${pkg ?? 'All'}]`, [
['yarn', ['xy', 'compile', ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
['yarn', ['xy', 'compile', ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions, '--types', 'tsc']],
['yarn', ['xy', 'lint', ...pkgOptions, ...verboseOptions, ...incrementalOptions]],
['yarn', ['xy', 'deps', ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
])
Expand Down
29 changes: 22 additions & 7 deletions packages/ts-scripts-yarn3/src/actions/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,43 @@ export interface CompileParams {
pkg?: string
publint?: boolean
target?: 'esm' | 'cjs'
types?: 'tsc' | 'tsup'
verbose?: boolean
}

interface CompilePackageParams {
pkg: string
publint?: boolean
target?: 'esm' | 'cjs'
types?: 'tsc' | 'tsup'
verbose?: boolean
}

export const compile = ({
verbose, target, pkg, incremental, publint, jobs,
verbose, target, pkg, incremental, publint, jobs, types,
}: CompileParams) => {
return pkg
? compilePackage({
pkg, publint, target, verbose,
pkg, publint, target, verbose, types,
})
: compileAll({
incremental, publint, target, verbose, jobs,
incremental, publint, target, verbose, jobs, types,
})
}

export const compilePackage = ({ target, pkg }: CompilePackageParams) => {
export const compilePackage = ({
target, pkg, types,
}: CompilePackageParams) => {
const targetOptions = target ? ['-t', target] : []

return runSteps(`Compile [${pkg}]`, [['yarn', ['workspace', pkg, 'run', 'package-compile', ...targetOptions]]])
return runSteps(
`Compile [${pkg}]`,
[['yarn', ['workspace', pkg, 'run', types === 'tsup' ? 'package-compile' : 'package-build', ...targetOptions]]],
)
}

export const compileAll = ({
jobs, verbose, target, incremental,
jobs, verbose, target, incremental, types,
}: CompileParams) => {
const start = Date.now()
const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']
Expand All @@ -49,7 +56,15 @@ export const compileAll = ({
}

const result = runSteps(`Compile${incremental ? '-Incremental' : ''} [All]`, [
['yarn', ['workspaces', 'foreach', ...incrementalOptions, ...jobsOptions, ...verboseOptions, 'run', 'package-compile', ...targetOptions]],
['yarn', ['workspaces',
'foreach',
...incrementalOptions,
...jobsOptions,
...verboseOptions,
'run',
types === 'tsup' ? 'package-compile' : 'package-build',
...targetOptions,
]],
])
console.log(`${chalk.gray('Compiled in')} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
XyConfig, XyTscConfig, XyTsupConfig,
} from './XyConfig.ts'

export const packageCompile = async (inConfig: XyConfig = {}): Promise<number> => {
export const packageCompile = async (inConfig: XyConfig = {}, types?: 'tsc' | 'tsup'): Promise<number> => {
const pkg = process.env.INIT_CWD
console.log(chalk.green(`Compiling ${pkg}`))
const config = await loadConfig(inConfig)
Expand All @@ -22,7 +22,7 @@ export const packageCompile = async (inConfig: XyConfig = {}): Promise<number> =
break
}
case 'tsup': {
result += await packageCompileTsup(config as XyTsupConfig)
result += await packageCompileTsup(config as XyTsupConfig, types)
break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { buildEntries } from './buildEntries.ts'
import { packageCompileTscTypes } from './packageCompileTscTypes.ts'
import type { EntryMode, XyTsupConfig } from './XyConfig.ts'

const compileFolder = async (folder: string, entryMode: EntryMode = 'single', options?: Options, verbose?: boolean) => {
const compileFolder = async (
folder: string,
entryMode: EntryMode = 'single',
options?: Options,
types: 'tsc' | 'tsup' = 'tsup',
verbose?: boolean,
): Promise<number> => {
const outDir = options?.outDir ?? 'dist'
const entry = buildEntries(folder, entryMode)
const optionsResult = defineConfig({
Expand All @@ -19,7 +25,7 @@ const compileFolder = async (folder: string, entryMode: EntryMode = 'single', op
format: ['esm'],
outDir,
silent: true,
sourcemap: false,
sourcemap: types === 'tsup',
splitting: false,
tsconfig: 'tsconfig.json',
...options,
Expand All @@ -34,10 +40,15 @@ const compileFolder = async (folder: string, entryMode: EntryMode = 'single', op
).flat()

await Promise.all(optionsList.map(options => build(options)))
return packageCompileTscTypes(folder, { verbose }, { outDir })
if (types === 'tsc') {
return packageCompileTscTypes(folder, { verbose }, { outDir })
}
return 0
}

export const packageCompileTsup = async (config?: XyTsupConfig) => {
// eslint-disable-next-line complexity
export const packageCompileTsup = async (config?: XyTsupConfig, types: 'tsc' | 'tsup' = 'tsup') => {
console.warn('packageCompileTsup-types', types)
const compile = config?.compile
const publint = config?.publint ?? true
const verbose = config?.verbose ?? false
Expand Down Expand Up @@ -82,6 +93,7 @@ export const packageCompileTsup = async (config?: XyTsupConfig) => {
...compile?.tsup?.options,
...(typeof options === 'object' ? options : {}),
},
types,
verbose,
)
: 0
Expand All @@ -107,6 +119,7 @@ export const packageCompileTsup = async (config?: XyTsupConfig) => {
...compile?.tsup?.options,
...(typeof options === 'object' ? options : {}),
},
types,
verbose,
)
: 0
Expand All @@ -132,6 +145,7 @@ export const packageCompileTsup = async (config?: XyTsupConfig) => {
...compile?.tsup?.options,
...(typeof options === 'object' ? options : {}),
},
types,
verbose,
)
: 0
Expand Down
16 changes: 16 additions & 0 deletions packages/ts-scripts-yarn3/src/bin/package/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

import chalk from 'chalk'

import { packageCompile } from '../../actions/index.ts'

packageCompile({ verbose: false, publint: false }, 'tsc')
.then((value) => {
if (value) {
process.exit(value)
}
})
.catch((reason) => {
console.error(chalk.red(reason))
process.exit(-1)
})
9 changes: 5 additions & 4 deletions packages/ts-scripts-yarn3/src/xy/xyBuildCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ export const xyBuildCommands = (args: Argv) => {
(yargs) => {
return yargs.positional('package', { describe: 'Specific package to compile' })
},
async (argv) => {
(argv) => {
if (argv.verbose) {
console.log(`Compiling: ${argv.package ?? 'all'}`)
}
process.exitCode = await compile({
process.exitCode = compile({
incremental: !!argv.incremental,
jobs: argv.jobs as number,
pkg: argv.package as string,
target: argv.target as 'esm' | 'cjs',
types: argv.types as 'tsc' | 'tsup',
verbose: !!argv.verbose,
})
},
Expand All @@ -51,11 +52,11 @@ export const xyBuildCommands = (args: Argv) => {
(yargs) => {
return yargs.positional('package', { describe: 'Specific package to compile' })
},
async (argv) => {
(argv) => {
if (argv.verbose) {
console.log(`Compiling: ${argv.package ?? 'all'}`)
}
process.exitCode = await compile({
process.exitCode = compile({
incremental: !!argv.incremental,
jobs: argv.jobs as number,
pkg: argv.package as string,
Expand Down
7 changes: 7 additions & 0 deletions packages/ts-scripts-yarn3/src/xy/xyParseOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const xyParseOptions = (): Argv => {
})
.option('target', {
alias: 't',
default: 'esm',
choices: ['esm', 'cjs'],
description: 'Limit output to specific target',
type: 'string',
Expand Down Expand Up @@ -48,4 +49,10 @@ export const xyParseOptions = (): Argv => {
description: 'Profile action',
type: 'boolean',
})
.option('types', {
default: 'tsup',
choices: ['tsc', 'tsup'],
description: 'Tool to generate Typescript types',
type: 'string',
})
}
2 changes: 1 addition & 1 deletion packages/tsconfig-dom-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/tsconfig-dom-jest",
"version": "4.0.1",
"version": "4.0.2",
"description": "Typescript Base Config used throughout XY Labs TypeScript/JavaScript jest tests [DOM]",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig-dom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/tsconfig-dom",
"version": "4.0.1",
"version": "4.0.2",
"description": "Typescript Base Config used throughout XY Labs TypeScript/JavaScript libraries and react projects",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/tsconfig-jest",
"version": "4.0.1",
"version": "4.0.2",
"description": "Typescript Base Config used throughout XY Labs TypeScript/JavaScript jest tests",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig-react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/tsconfig-react",
"version": "4.0.1",
"version": "4.0.2",
"description": "Typescript Base Config used throughout XY Labs TypeScript/JavaScript libraries and react projects",
"keywords": [
"xylabs",
Expand Down
2 changes: 1 addition & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package.json",
"name": "@xylabs/tsconfig",
"version": "4.0.1",
"version": "4.0.2",
"description": "Typescript Base Config used throughout XY Labs TypeScript/JavaScript libraries and react projects",
"keywords": [
"xylabs",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,7 @@ __metadata:
lint-clean: dist/bin/lint-clean.mjs
lint-fast: dist/bin/lint-fast.mjs
lint-profile: dist/bin/lint-profile.mjs
package-build: dist/bin/package/build.mjs
package-clean: dist/bin/package/clean.mjs
package-compile: dist/bin/package/compile.mjs
package-compile-only: dist/bin/package/compile-only.mjs
Expand Down

0 comments on commit 9c4716b

Please sign in to comment.