-
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
Open
gtbuchanan
wants to merge
1
commit into
main
Choose a base branch
from
issue-353-stale-dist-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,19 @@ | ||
| --- | ||
| '@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. Entries another task owns | ||
| (the `compile:skills` subtree, the `pack:npm` docs and manifest) are kept. | ||
|
|
||
| `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,42 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| export const skillsOutDirEntry = 'skills'; | ||
|
|
||
| /** | ||
| * Entries inside {@link buildOutDir} that belong to a task other than | ||
| * `compile:ts`. | ||
| */ | ||
| export const foreignOutDirEntries: readonly string[] = [ | ||
| ...packNpmOutDirEntries, | ||
| skillsOutDirEntry, | ||
| ]; | ||
|
|
||
| /** | ||
| * 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,85 @@ | ||
| import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| 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'; | ||
|
|
||
| /** | ||
| * 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 = (): { readonly outDir: string; readonly pkgDir: string } => { | ||
| const pkgDir = createTempDir(); | ||
| const outDir = path.join(pkgDir, buildOutDir); | ||
| mkdirSync(path.join(outDir, 'src'), { recursive: true }); | ||
| mkdirSync(path.join(outDir, 'skills', 'my-skill'), { recursive: true }); | ||
| for (const file of [ | ||
| path.join('src', 'renamed.js'), | ||
| path.join('src', 'renamed.d.ts'), | ||
| path.join('skills', 'my-skill', 'SKILL.md'), | ||
| 'tsconfig.tsbuildinfo', | ||
| '.npmignore', | ||
| 'LICENSE', | ||
| 'README.md', | ||
| 'package.json', | ||
| ]) { | ||
| writeFileSync(path.join(outDir, file), ''); | ||
| } | ||
|
|
||
| return { outDir, pkgDir }; | ||
| }; | ||
|
|
||
| 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 } = createPackage(); | ||
|
|
||
| clearCompiledOutput(pkgDir); | ||
|
|
||
| expect(existsSync(path.join(outDir, 'skills', 'my-skill', 'SKILL.md'))).toBe(true); | ||
| }); | ||
|
|
||
| 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); | ||
| }); | ||
| }); |
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,71 @@ | ||
| import { describe, it } from 'vitest'; | ||
| import { generateTurboJson } from '#src/lib/turbo-config.js'; | ||
| import { makeCapabilities, makeDiscovery } from './turbo-config.helpers.ts'; | ||
|
|
||
| /* | ||
| * Every task writing the published output directory must declare only what it | ||
| * writes: an overlapping glob lets one task cache a file another produced and | ||
| * replay a stale copy of it on a hit. | ||
| */ | ||
| describe.concurrent('generateTurboJson (dist/source ownership)', () => { | ||
| it('excludes the generated manifest from pack:npm inputs', ({ expect }) => { | ||
| const discovery = makeDiscovery([ | ||
| makeCapabilities({ isPublished: true }), | ||
| ]); | ||
|
|
||
| const result = generateTurboJson(discovery); | ||
|
|
||
| expect(result.tasks['pack:npm']?.inputs).toContain('!dist/source/package.json'); | ||
| }); | ||
|
|
||
| it('excludes the generated .npmignore from pack:npm inputs', ({ expect }) => { | ||
| const discovery = makeDiscovery([ | ||
| makeCapabilities({ isPublished: true }), | ||
| ]); | ||
|
|
||
| const result = generateTurboJson(discovery); | ||
|
|
||
| expect(result.tasks['pack:npm']?.inputs).toContain('!dist/source/.npmignore'); | ||
| }); | ||
|
|
||
| it('claims every file it writes as a pack:npm output', ({ expect }) => { | ||
| const discovery = makeDiscovery([ | ||
| makeCapabilities({ isPublished: true }), | ||
| ]); | ||
|
|
||
| const result = generateTurboJson(discovery); | ||
|
|
||
| expect(result.tasks['pack:npm']?.outputs).toStrictEqual(expect.arrayContaining([ | ||
| 'dist/source/.npmignore', | ||
| 'dist/source/LICENSE', | ||
| 'dist/source/README.md', | ||
| 'dist/source/package.json', | ||
| ])); | ||
| }); | ||
|
|
||
| it('excludes the pack:npm-owned files from compile:ts outputs', ({ expect }) => { | ||
| const discovery = makeDiscovery([ | ||
| makeCapabilities({ isPublished: true }), | ||
| ]); | ||
|
|
||
| const result = generateTurboJson(discovery); | ||
|
|
||
| expect(result.tasks['compile:ts']?.outputs).toStrictEqual([ | ||
| 'dist/source/**', | ||
| '!dist/source/.npmignore', | ||
| '!dist/source/LICENSE', | ||
| '!dist/source/README.md', | ||
| '!dist/source/package.json', | ||
| ]); | ||
| }); | ||
|
|
||
| it('excludes the compile:skills subtree from compile:ts outputs', ({ expect }) => { | ||
| const discovery = makeDiscovery([ | ||
| makeCapabilities({ hasSkills: true, isPublished: true }), | ||
| ]); | ||
|
|
||
| const result = generateTurboJson(discovery); | ||
|
|
||
| expect(result.tasks['compile:ts']?.outputs).toContain('!dist/source/skills/**'); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Make
skillspreservation conditional on the current skills capability.Line 27 always preserves
skills.packages/cli/src/lib/turbo-config.tstreats that subtree as foreign only whenflags.hasSkillsis true.If a package removes its skills capability, this cleanup leaves its old
dist/source/skillsfiles in place.compile:tsthen owns and caches that subtree, andpack:npmcan publish the stale files. Derive the preserved entries from the same capability state that createscompile:skills, and add a no-skills stale-subtree test.🤖 Prompt for AI Agents