Skip to content

Commit 98af549

Browse files
committed
fix(workflow-code): a check removes workspace.d.ts once the directory declares nothing
1 parent 3a3cded commit 98af549

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎packages/sim-cli/src/commands/protocol/source-tree.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ export async function loadWorkspaceTypes(
377377
* Regenerates `workspace.d.ts` from the stored manifest the last get kept beside it and what the
378378
* directory declares now (`local`), so a check types a key added since without a request. Without
379379
* a kept manifest (the get could not list the workspace's resources), it types what the directory
380-
* declares, as that get did. A manifest that does not parse leaves the file as it is.
380+
* declares, as that get did, and removes the file when it declares nothing. A manifest that does
381+
* not parse leaves the file as it is.
381382
*/
382383
export async function refreshWorkspaceTypes(dir: string, local: LocalDeclarations): Promise<void> {
383384
const [manifest, current] = await Promise.all([
@@ -396,7 +397,9 @@ export async function refreshWorkspaceTypes(dir: string, local: LocalDeclaration
396397
stored = parsed
397398
}
398399
const types = workspaceTypesFrom(stored, local)
399-
if (types && types.text !== current) {
400+
if (types === null) {
401+
if (current !== null) await updateSourceDir(dir, { write: [], remove: [WORKSPACE_TYPES_FILE] })
402+
} else if (types.text !== current) {
400403
await updateSourceDir(dir, { write: [[WORKSPACE_TYPES_FILE, types.text]] })
401404
}
402405
}

‎packages/sim-cli/src/commands/protocol/workspace-source-get.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,18 @@ describe('the type check of workspaces source check', () => {
12051205
}
12061206
)
12071207

1208+
it('removes workspace.d.ts when a directory with no resource listing stops declaring anything', async () => {
1209+
serve({ 'tables/leads.ts': LEADS })
1210+
await get()
1211+
expect(existsSync(join(dir, '.sim/sdk/workspace.d.ts'))).toBe(true)
1212+
rmSync(join(dir, 'tables/leads.ts'))
1213+
1214+
await runWorkspaceSource('check', dir)
1215+
1216+
expect(existsSync(join(dir, '.sim/sdk/workspace.d.ts'))).toBe(false)
1217+
expect(result()).toMatchObject({ checked: ['compile', 'types'], errors: 0 })
1218+
})
1219+
12081220
it('fails on a type error the compile only warns about, at its file and line, annotated in CI', async () => {
12091221
serve({ 'tables/leads.ts': LEADS })
12101222
await get()

0 commit comments

Comments
 (0)