Skip to content

Commit

Permalink
rename .tshy-build-tmp to .tshy-build
Browse files Browse the repository at this point in the history
It's not temporary if you use incremental:true in tsconfig
  • Loading branch information
isaacs committed Nov 4, 2023
1 parent 0d4b528 commit 77ec08a
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.tshy-build-tmp
/.tshy-build
/node_modules
/dist
/docs
Expand Down
2 changes: 1 addition & 1 deletion .tshy/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/esm"
"outDir": "../.tshy-build/esm"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ depending on the dialect type that it is.
## Atomic Builds
Code is built in `./.tshy-build-tmp` and then copied over only if
Code is built in `./.tshy-build` and then copied over only if
the build succeeds. This makes it work in monorepo cases where
you may have packages that depend on one another and are all
being built in parallel (as long as they've been built one time,
Expand Down
6 changes: 3 additions & 3 deletions scripts/fixup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

chmod 0755 .tshy-build-tmp/esm/index.js
sync-content .tshy-build-tmp dist
rm -rf .tshy-build-tmp
chmod 0755 .tshy-build/esm/index.js
sync-content .tshy-build dist
rm -rf .tshy-build
6 changes: 3 additions & 3 deletions src/build-commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const buildCommonJS = () => {
setFolderDialect('src')
return buildFail(res)
}
setFolderDialect('.tshy-build-tmp/' + d, 'commonjs')
setFolderDialect('.tshy-build/' + d, 'commonjs')
for (const [override, orig] of pf?.map.entries() ?? []) {
const stemFrom = resolve(
`.tshy-build-tmp/${d}`,
`.tshy-build/${d}`,
relative(resolve('src'), resolve(override))
).replace(/\.cts$/, '')
const stemTo = resolve(
`.tshy-build-tmp/${d}`,
`.tshy-build/${d}`,
relative(resolve('src'), resolve(orig))
).replace(/\.tsx?$/, '')
unlinkSync(`${stemTo}.js.map`)
Expand Down
6 changes: 3 additions & 3 deletions src/build-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const buildESM = () => {
setFolderDialect('src')
return buildFail(res)
}
setFolderDialect('.tshy-build-tmp/' + d, 'esm')
setFolderDialect('.tshy-build/' + d, 'esm')
for (const [override, orig] of pf?.map.entries() ?? []) {
const stemFrom = resolve(
`.tshy-build-tmp/${d}`,
`.tshy-build/${d}`,
relative(resolve('src'), resolve(override))
).replace(/\.mts$/, '')
const stemTo = resolve(
`.tshy-build-tmp/${d}`,
`.tshy-build/${d}`,
relative(resolve('src'), resolve(orig))
).replace(/\.tsx?$/, '')
unlinkSync(`${stemTo}.js.map`)
Expand Down
15 changes: 7 additions & 8 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import chalk from 'chalk'
import { rimrafSync } from 'rimraf'
import { syncContentSync } from 'sync-content'
import bins from './bins.js'
import { buildCommonJS } from './build-commonjs.js'
import { buildESM } from './build-esm.js'
import cleanBuildTmp from './clean-build-tmp.js'
import * as console from './console.js'
import dialects from './dialects.js'
import {
link as linkImports,
save as saveImports,
unlink as unlinkImports,
} from './unbuilt-imports.js'
import pkg from './package.js'
import {
link as linkSelfDep,
unlink as unlinkSelfDep,
} from './self-dep.js'
import './tsconfig.js'
import {
link as linkImports,
save as saveImports,
unlink as unlinkImports,
} from './unbuilt-imports.js'
import writePackage from './write-package.js'
import cleanBuildTmp from './clean-build-tmp.js'

export default async () => {
cleanBuildTmp()
Expand All @@ -31,7 +30,7 @@ export default async () => {
unlinkSelfDep(pkg, 'src')

console.debug(chalk.cyan.dim('moving to ./dist'))
syncContentSync('.tshy-build-tmp', 'dist')
syncContentSync('.tshy-build', 'dist')
console.debug(chalk.cyan.dim('cleaning build temp dir'))

cleanBuildTmp()
Expand Down
12 changes: 6 additions & 6 deletions src/clean-build-tmp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Remove the .tshy-build-tmp folder, but ONLY if
// Remove the .tshy-build folder, but ONLY if
// the "incremental" config value is not set, or if
// it does not contain any tsbuildinfo files.
// If we are in incremental mode, and have tsbuildinfo files,
Expand Down Expand Up @@ -67,20 +67,20 @@ const cleanRemovedOutputs = (path: string, root: string) => {
export default () => {
const config = readTypescriptConfig()
if (config.options.incremental !== true) {
return rimrafSync('.tshy-build-tmp')
return rimrafSync('.tshy-build')
}

let buildInfos: string[] | undefined = undefined
try {
buildInfos = readdirSync('.tshy-build-tmp/.tshy')
buildInfos = readdirSync('.tshy-build/.tshy')
} catch {}
if (!buildInfos?.length) {
return rimrafSync('.tshy-build-tmp')
return rimrafSync('.tshy-build')
}

// delete anything that has been removed from src.
for (const dialect of readdirSync('.tshy-build-tmp')) {
for (const dialect of readdirSync('.tshy-build')) {
if (dialect === '.tshy') continue
cleanRemovedOutputs('.', `.tshy-build-tmp/${dialect}`)
cleanRemovedOutputs('.', `.tshy-build/${dialect}`)
}
}
4 changes: 2 additions & 2 deletions src/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const commonjs = (dialect: string): Record<string, any> => {
exclude,
compilerOptions: {
outDir:
'../.tshy-build-tmp/' +
'../.tshy-build/' +
(dialect === 'cjs' ? 'commonjs' : dialect),
},
}
Expand All @@ -83,7 +83,7 @@ const esm = (dialect: string): Record<string, any> => {
include: ['../src/**/*.ts', '../src/**/*.mts', '../src/**/*.tsx'],
exclude,
compilerOptions: {
outDir: '../.tshy-build-tmp/' + dialect,
outDir: '../.tshy-build/' + dialect,
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/tsconfig.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/commonjs.json 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/commonjs",
"outDir": "../.tshy-build/commonjs",
},
"exclude": Array [
"../src/**/*.mts",
Expand All @@ -50,7 +50,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/commonjs.json generate everything 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/commonjs",
"outDir": "../.tshy-build/commonjs",
},
"exclude": Array [
"../src/**/*.mts",
Expand All @@ -68,7 +68,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/deno.json 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/deno",
"outDir": "../.tshy-build/deno",
},
"exclude": Array [
".././src/index-cjs.cts",
Expand All @@ -85,7 +85,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/esm.json 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/esm",
"outDir": "../.tshy-build/esm",
},
"exclude": Array [
".././src/index-cjs.cts",
Expand All @@ -103,7 +103,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/esm.json generate everything 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/esm",
"outDir": "../.tshy-build/esm",
},
"exclude": Array [
".././src/index-cjs.cts",
Expand All @@ -121,7 +121,7 @@ Object {
exports[`test/tsconfig.ts > TAP > .tshy/webpack.json 1`] = `
Object {
"compilerOptions": Object {
"outDir": "../.tshy-build-tmp/webpack",
"outDir": "../.tshy-build/webpack",
},
"exclude": Array [
"../src/**/*.mts",
Expand Down
2 changes: 1 addition & 1 deletion test/build-commonjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const spawnSync = t.captureFn((...a: any[]) => {
})

const output = () =>
readdirSync('.tshy-build-tmp/commonjs').sort((a, b) =>
readdirSync('.tshy-build/commonjs').sort((a, b) =>
a.localeCompare(b, 'en')
)

Expand Down
2 changes: 1 addition & 1 deletion test/build-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const spawnSync = t.captureFn((...a: any[]) => {
})

const output = () =>
readdirSync('.tshy-build-tmp/esm').sort((a, b) =>
readdirSync('.tshy-build/esm').sort((a, b) =>
a.localeCompare(b, 'en')
)

Expand Down
14 changes: 7 additions & 7 deletions test/clean-build-tmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ t.test('no incremental build, just delete it', t => {
readTypescriptConfig().options.incremental = false
process.chdir(
t.testdir({
'.tshy-build-tmp': {},
'.tshy-build': {},
})
)
cleanBuildTmp()
t.throws(() => statSync('.tshy-build-tmp'))
t.throws(() => statSync('.tshy-build'))
t.end()
})

t.test('no tsbuildinfo, just delete it', t => {
readTypescriptConfig().options.incremental = true
process.chdir(
t.testdir({
'.tshy-build-tmp': {},
'.tshy-build': {},
})
)
cleanBuildTmp()
t.throws(() => statSync('.tshy-build-tmp'))
t.throws(() => statSync('.tshy-build'))
t.end()
})

t.test('remove files not found in src', t => {
readTypescriptConfig().options.incremental = true
process.chdir(
t.testdir({
'.tshy-build-tmp': {
'.tshy-build': {
'.tshy': { 'esm.tsbuildinfo': '{}' },
esm: {
'a.d.ts': '',
Expand Down Expand Up @@ -73,7 +73,7 @@ t.test('remove files not found in src', t => {
})
)
cleanBuildTmp()
t.throws(() => statSync('.tshy-build-tmp/dist/esm/x.js.map'))
t.throws(() => statSync('.tshy-build-tmp/dist/esm/x.d.ts'))
t.throws(() => statSync('.tshy-build/dist/esm/x.js.map'))
t.throws(() => statSync('.tshy-build/dist/esm/x.d.ts'))
t.end()
})
2 changes: 1 addition & 1 deletion test/fixtures/basic-imports-only-deps/.tshy/commonjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"../src/**/*.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/commonjs"
"outDir": "../.tshy-build/commonjs"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/basic-imports-only-deps/.tshy/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/esm"
"outDir": "../.tshy-build/esm"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/basic/.tshy/commonjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"../src/**/*.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/commonjs"
"outDir": "../.tshy-build/commonjs"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/basic/.tshy/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/esm"
"outDir": "../.tshy-build/esm"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/imports-with-star/.tshy/commonjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"../src/**/*.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/commonjs"
"outDir": "../.tshy-build/commonjs"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/imports-with-star/.tshy/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/esm"
"outDir": "../.tshy-build/esm"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/imports/.tshy/commonjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"../src/**/*.mts"
],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/commonjs"
"outDir": "../.tshy-build/commonjs"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/imports/.tshy/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
],
"exclude": [],
"compilerOptions": {
"outDir": "../.tshy-build-tmp/esm"
"outDir": "../.tshy-build/esm"
}
}

0 comments on commit 77ec08a

Please sign in to comment.