buddy ts build
buddy ts build <type> runs tsc -p tsconfig.<type>.json in the current directory. For cjs and tslib it then
copies package.cjs.json to <type>/package.json.
buddy ts build <type>Requires the plugin to be enabled.
Arguments
Section titled “Arguments”| Argument | Type | Default | Effect |
|---|---|---|---|
type |
cjs, esm, or tslib |
required | Picks the tsconfig file tsconfig.<type>.json and, for cjs and tslib, the output folder <type>/ that receives package.json. |
The command has no flags.
Output
Section titled “Output”On success it prints:
building cjs...copying package.json...build cjs doneFor esm, the copying package.json... line is absent.
Exit codes
Section titled “Exit codes”| Code | When |
|---|---|
0 |
tsc succeeded and, for cjs and tslib, the copy succeeded. |
1 |
tsc failed (the error, with tsc’s output, is printed as an uncaught ExecaError), or the output folder does not exist for the copy. |
2 |
type is missing (missing required argument <type>) or is not one of the three values (invalid value for argument <type>). |
Behavior
Section titled “Behavior”- It runs
tscfromPATH, not from a resolved TypeScript install. Package scripts,pnpm exec, andnpxput the project’snode_modules/.binonPATH. tscoutput is captured. On success none of it is printed.- It copies to
./<type>/package.jsonrelative to the current directory. Set the tsconfig’soutDirtocjsortslibso the copy lands next to the emitted files. With anotheroutDir,tscemits there and the copy then fails withENOENT(exit code1) because<type>/does not exist. - It overwrites an existing
<type>/package.json. esmonly runstsc. It writes nopackage.json.tslibis a name only. The command does not addimportHelpers. Set it intsconfig.tslib.json.
Examples
Section titled “Examples”testcases/build-ts in this repository builds both CommonJS variants with these scripts:
{ "scripts": { "test:cjs": "buddy ts build cjs", "test:tslib": "buddy ts build tslib" }}{ "extends": ["./tsconfig.json", "@repobuddy/typescript/tsconfig/modules/buddy-commonjs.json"], "compilerOptions": { "outDir": "cjs" }}{ "extends": "./tsconfig.cjs.json", "compilerOptions": { "importHelpers": true, "outDir": "tslib" }}After buddy ts build cjs, cjs/ holds index.js, index.js.map, index.d.ts, index.d.ts.map, and a
package.json with { "type": "commonjs" }.
Building esm without a tsconfig.esm.json exits with code 1:
building esm...ExecaError: Command failed with exit code 1: tsc -p tsconfig.esm.json
error TS5058: The specified path does not exist: '<cwd>/tsconfig.esm.json'.