-
Notifications
You must be signed in to change notification settings - Fork 0
Stop packing and caching stale dist/source content #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,21 @@ | ||
| --- | ||
| '@gtbuchanan/cli': patch | ||
| --- | ||
|
|
||
| Stop packing and caching stale `dist/source` content | ||
|
|
||
| `compile:ts` now clears its output directory before invoking tsc. tsc doesn't | ||
| record what it emitted and so never removes output whose source was since | ||
| renamed or deleted — the orphan stayed behind and `pack:npm` shipped it. The | ||
| stale `.tsbuildinfo` goes with it, since left in place it reports the removed | ||
| files as up to date and suppresses the re-emit. The `pack:npm` docs and | ||
| manifest are kept, as is the `compile:skills` subtree — but only while the | ||
| package still authors a `skills/` directory, since once it doesn't that | ||
| task no longer runs to clear what it last wrote. | ||
|
|
||
| `compile:ts` also no longer declares the files `pack:npm` writes as its own | ||
| turbo `outputs`. The overlapping glob let a `compile:ts` cache entry capture | ||
| the stamped manifest and replay it on a hit, restoring whatever version was | ||
| current when the entry was written. `pack:npm` now declares the `.npmignore` | ||
| it writes, and excludes it from its own inputs alongside the other | ||
| self-generated files. |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| /* | ||
| * The published output directory is shared: `compile:ts` emits the compiled | ||
| * tree into it, `compile:skills` fills a subtree, and `pack:npm` writes the | ||
| * docs and the stamped manifest. No task may treat it as its own, so the split | ||
| * is declared once here and consumed by both places that depend on it — the | ||
| * turbo `outputs` globs that decide which task caches which file, and the | ||
| * clean `compile:ts` runs before emitting. | ||
| */ | ||
|
|
||
| /** | ||
| * The `outDir` every published package compiles into, and the directory its | ||
| * `publishConfig.directory` points npm at. A generated tsconfig.build.json | ||
| * owns the value (see `buildOwned`) and `gtb verify` fails on drift, so the | ||
| * convention — not a per-package lookup — is the source of truth. | ||
| */ | ||
| export const buildOutDir = 'dist/source'; | ||
|
|
||
| /** | ||
| * Entries `pack:npm` writes into {@link buildOutDir}. | ||
| */ | ||
| export const packNpmOutDirEntries = [ | ||
| '.npmignore', 'LICENSE', 'README.md', 'package.json', | ||
| ] as const; | ||
|
|
||
| /** | ||
| * Subdirectory of {@link buildOutDir} `compile:skills` writes. Named the same | ||
| * as the authored source directory it mirrors. | ||
| */ | ||
| export const skillsOutDirEntry = 'skills'; | ||
|
|
||
| /** | ||
| * Prefixes a {@link buildOutDir} entry to form a turbo glob. | ||
| */ | ||
| export const outDirGlob = (entry: string): string => `${buildOutDir}/${entry}`; |
This file contains hidden or 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 hidden or 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 hidden or 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,128 @@ | ||
| import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { faker } from '@faker-js/faker'; | ||
| import { describe, it } from 'vitest'; | ||
| import { clearCompiledOutput } from '#src/commands/task/compile-ts.js'; | ||
| import { buildOutDir } from '#src/lib/dist-source.js'; | ||
| import { createTempDir } from './helpers.ts'; | ||
|
|
||
| /** | ||
| * Options for {@link createPackage}. | ||
| */ | ||
| interface PackageOptions { | ||
| /** | ||
| * Whether the package still authors `skills/`. `false` scaffolds one that | ||
| * dropped them, leaving only the compiled copy from a prior run. Defaults | ||
| * to `true`. | ||
| */ | ||
| readonly authorsSkills?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * A scaffolded package and the generated facts a test asserts against. | ||
| */ | ||
| interface Package { | ||
| readonly outDir: string; | ||
| readonly pkgDir: string; | ||
| /** | ||
| * Name of the lone compiled skill. Incidental — nothing branches on it. | ||
| */ | ||
| readonly skillName: string; | ||
| } | ||
|
|
||
| /* | ||
| * `skills` stays hardcoded throughout: the production code branches on that | ||
| * exact directory name, so generating it would stop exercising the branch. | ||
| */ | ||
| const skillsDir = 'skills'; | ||
|
|
||
| /** | ||
| * Scaffolds a package whose `dist/source` holds output from a prior run: | ||
| * compiled files, the `compile:skills` subtree, and the `pack:npm` docs. | ||
| */ | ||
| const createPackage = (options: PackageOptions = {}): Package => { | ||
| const pkgDir = createTempDir(); | ||
| const outDir = path.join(pkgDir, buildOutDir); | ||
| const skillName = faker.lorem.slug(); | ||
| if (options.authorsSkills !== false) { | ||
| mkdirSync(path.join(pkgDir, skillsDir), { recursive: true }); | ||
| } | ||
| mkdirSync(path.join(outDir, 'src'), { recursive: true }); | ||
| mkdirSync(path.join(outDir, skillsDir, skillName), { recursive: true }); | ||
| for (const file of [ | ||
| path.join('src', 'renamed.js'), | ||
| path.join('src', 'renamed.d.ts'), | ||
| path.join(skillsDir, skillName, 'SKILL.md'), | ||
| 'tsconfig.tsbuildinfo', | ||
| '.npmignore', | ||
| 'LICENSE', | ||
| 'README.md', | ||
| 'package.json', | ||
| ]) { | ||
| writeFileSync(path.join(outDir, file), ''); | ||
| } | ||
|
|
||
| return { outDir, pkgDir, skillName }; | ||
| }; | ||
|
|
||
| describe.concurrent(clearCompiledOutput, () => { | ||
| it('removes compiled output left by a prior run', ({ expect }) => { | ||
| const { outDir, pkgDir } = createPackage(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(outDir, 'src'))).toBe(false); | ||
| }); | ||
|
|
||
| it('removes the tsbuildinfo so tsc re-emits the cleared output', ({ expect }) => { | ||
| const { outDir, pkgDir } = createPackage(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(outDir, 'tsconfig.tsbuildinfo'))).toBe(false); | ||
| }); | ||
|
|
||
| it('preserves the skills subtree compile:skills owns', ({ expect }) => { | ||
| const { outDir, pkgDir, skillName } = createPackage(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(outDir, skillsDir, skillName, 'SKILL.md'))).toBe(true); | ||
| }); | ||
|
|
||
| it('removes the skills subtree once the package stops authoring skills', ({ expect }) => { | ||
| const { outDir, pkgDir } = createPackage({ authorsSkills: false }); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(outDir, skillsDir))).toBe(false); | ||
| }); | ||
|
|
||
| it('preserves the docs and manifest pack:npm owns', ({ expect }) => { | ||
| const { outDir, pkgDir } = createPackage(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| for (const file of ['.npmignore', 'LICENSE', 'README.md', 'package.json']) { | ||
| expect(existsSync(path.join(outDir, file))).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it('leaves sibling dist directories untouched', ({ expect }) => { | ||
| const { pkgDir } = createPackage(); | ||
| const coverage = path.join(pkgDir, 'dist', 'coverage'); | ||
| mkdirSync(coverage, { recursive: true }); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(coverage)).toBe(true); | ||
| }); | ||
|
|
||
| it('no-ops when the package has never been compiled', ({ expect }) => { | ||
| const pkgDir = createTempDir(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(pkgDir, buildOutDir))).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.