-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: fix cjs+esm build outputs (#834)
- Loading branch information
1 parent
a27f222
commit 132f479
Showing
8 changed files
with
101 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,6 +261,6 @@ Otherwise, consider sending me an email ([email protected]) or [message me on Dis | |
### Current Sponsors 🥰 | ||
| [tmm](https://github.com/tmm) | [xrexy](https://github.com/xrexy) | [thomasballinger](https://github.com/thomasballinger) | [codeandcats](https://github.com/codeandcats) | | ||
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- | | ||
| <img height="64px" src="https://avatars.githubusercontent.com/u/6759464"> | <img height="64px" src="https://avatars.githubusercontent.com/u/71969236"> | <img height="64px" src="https://avatars.githubusercontent.com/u/458879"> | <img height="64px" src="https://avatars.githubusercontent.com/u/6035934"> | | ||
| [tmm](https://github.com/tmm) | [xrexy](https://github.com/xrexy) | [thomasballinger](https://github.com/thomasballinger) | [codeandcats](https://github.com/codeandcats) | [jacksteamdev](https://github.com/jacksteamdev) | | ||
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | ||
| <img height="64px" src="https://avatars.githubusercontent.com/u/6759464"> | <img height="64px" src="https://avatars.githubusercontent.com/u/71969236"> | <img height="64px" src="https://avatars.githubusercontent.com/u/458879"> | <img height="64px" src="https://avatars.githubusercontent.com/u/6035934"> | <img height="64px" src="https://avatars.githubusercontent.com/u/23390212"> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"arktype": patch | ||
--- | ||
|
||
ci: revert to dual cjs+esm build output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,71 @@ | ||
import { cpSync, rmSync } from "node:fs" | ||
import { renameSync, rmSync } from "node:fs" | ||
import { join } from "node:path" | ||
import { readJson, shell, writeJson } from "../attest/src/main.js" | ||
import * as process from "node:process" | ||
import { | ||
getSourceFilePaths, | ||
readJson, | ||
shell, | ||
writeJson | ||
} from "../attest/src/main.js" | ||
import { repoDirs } from "./common.js" | ||
|
||
const packageRoot = process.cwd() | ||
const outRoot = join(packageRoot, "dist") | ||
const packageJson = readJson(join(packageRoot, "package.json")) | ||
|
||
console.log(`🔨 Building ${packageJson.name}...`) | ||
rmSync(outRoot, { recursive: true, force: true }) | ||
const tsConfigData = readJson(join(repoDirs.configs, "tsconfig.json")) | ||
const tempTsConfig = join(packageRoot, "tsconfig.temp.json") | ||
writeJson(tempTsConfig, { | ||
...tsConfigData, | ||
include: ["src"], | ||
compilerOptions: { | ||
...tsConfigData.compilerOptions, | ||
noEmit: false, | ||
module: "commonjs", | ||
outDir: "dist" | ||
const isTestBuild = process.argv.includes("--test") | ||
|
||
const isProd = () => process.argv.includes("--prod") || !!process.env.CI | ||
|
||
const inFiles = getSourceFilePaths( | ||
isTestBuild ? repoDirs.root : repoDirs.srcRoot | ||
) | ||
|
||
const successMessage = `📦 Successfully built arktype!` | ||
|
||
const arktypeTsc = () => { | ||
console.log(`🔨 Building arktype...`) | ||
rmSync(repoDirs.outRoot, { recursive: true, force: true }) | ||
if (!isTestBuild) { | ||
buildTypes() | ||
} | ||
transpile() | ||
console.log(successMessage) | ||
} | ||
|
||
const buildTypes = () => { | ||
process.stdout.write("⏳ Building types...".padEnd(successMessage.length)) | ||
const tsConfigData = readJson(join(repoDirs.root, "tsconfig.json")) | ||
const tempTsConfig = join(repoDirs.root, "tsconfig.temp.json") | ||
try { | ||
writeJson(tempTsConfig, { ...tsConfigData, include: ["src"] }) | ||
shell( | ||
`pnpm tsc --project ${tempTsConfig} --outDir ${repoDirs.outRoot} --noEmit false --emitDeclarationOnly` | ||
) | ||
renameSync(join(repoDirs.outRoot, "src"), repoDirs.typesOut) | ||
} finally { | ||
rmSync(tempTsConfig, { force: true }) | ||
} | ||
}) | ||
try { | ||
shell(`pnpm tsc --project ${tempTsConfig}`) | ||
const outSrc = join(outRoot, "src") | ||
// not sure which setting to change to get it to compile here in the first place | ||
cpSync(outSrc, outRoot, { | ||
recursive: true, | ||
force: true | ||
process.stdout.write(`✅\n`) | ||
} | ||
|
||
const transpile = () => { | ||
process.stdout.write(`⌛ Transpiling...`.padEnd(successMessage.length)) | ||
swc("mjs") | ||
swc("cjs") | ||
process.stdout.write("✅\n") | ||
} | ||
|
||
const swc = (kind: "mjs" | "cjs") => { | ||
const kindOutDir = join(repoDirs.outRoot, kind) | ||
let cmd = `pnpm swc -d ${kindOutDir} -C jsc.target=es2020 -q ` | ||
if (kind === "cjs") { | ||
cmd += `-C module.type=commonjs ` | ||
} | ||
if (!isProd()) { | ||
cmd += `--source-maps inline ` | ||
} | ||
cmd += inFiles.join(" ") | ||
shell(cmd) | ||
writeJson(join(kindOutDir, "package.json"), { | ||
type: kind === "cjs" ? "commonjs" : "module" | ||
}) | ||
rmSync(outSrc, { recursive: true, force: true }) | ||
writeJson(join(outRoot, "package.json"), { type: "commonjs" }) | ||
} finally { | ||
rmSync(tempTsConfig, { force: true }) | ||
} | ||
console.log(`📦 Successfully built ${packageJson.name}!`) | ||
|
||
arktypeTsc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters