Skip to content

fix: generate root barrel file in multi-target codegen#875

Merged
pyramation merged 1 commit intomainfrom
devin/1774066120-fix-multi-target-barrel
Mar 21, 2026
Merged

fix: generate root barrel file in multi-target codegen#875
pyramation merged 1 commit intomainfrom
devin/1774066120-fix-multi-target-barrel

Conversation

@pyramation
Copy link
Contributor

Summary

generateMulti() creates per-target barrel files (admin/index.ts, auth/index.ts, …) but never generated the root src/index.ts that re-exports all targets as namespaces. The SDK's pregenerate script deletes src/index.ts via rimraf, and codegen never recreated it — so after any schema propagation run, @constructive-io/node fails to build:

src/index.ts(31,15): error TS2307: Cannot find module '@constructive-io/sdk'

Fix: Add generateMultiTargetBarrel() to the codegen barrel module, and call it from generateMulti() after all targets complete. It writes:

export * as admin from './admin';
export * as auth from './auth';
export * as objects from './objects';
export * as public_ from './public';   // reserved-word alias

The output root is derived from the first successful target's output path (path.dirname(firstOutput)).

Review & Testing Checklist for Human

  • Verify path.dirname(firstOutput) is correct for your codegen configs — this assumes all targets share the same parent directory (e.g. ./src/admin, ./src/auth./src). If any consumer configures targets with divergent roots, the barrel would land in the wrong place.
  • Confirm the generated barrel matches the old hand-written src/index.ts — specifically that export * as public_ from './public' is produced (the _ suffix for JS reserved words). Run pnpm generate in sdk/constructive-sdk and diff the output against what was on main before.
  • Re-run the schema-propagation workflow (or simulate it) end-to-end to confirm @constructive-io/node builds after codegen. Local pnpm build passed on this branch, but CI codegen uses a different path (the hub workflow).

Notes

  • The JS_RESERVED set is comprehensive but static — covers ES2015+ reserved words plus future reserved words in strict mode.
  • No unit test added for generateMultiTargetBarrel(). Consider adding one if the codegen test suite is easy to extend.
  • This does not address the separate Cannot find module 'grafast' error seen when running generate-sdk.ts locally — that's a pnpm peer-dependency hoisting issue with @graphile-contrib/pg-many-to-many and is unrelated.

Link to Devin session: https://app.devin.ai/sessions/5d550def7a314c97854ec12fa09dd4ca
Requested by: @pyramation

generateMulti() was generating per-target barrel files (admin/index.ts,
auth/index.ts, etc.) but never creating the root src/index.ts that
re-exports all targets as namespaces. The pregenerate script deletes
src/index.ts via rimraf, and the codegen never recreated it, causing
downstream packages like @constructive-io/node to fail with
TS2307: Cannot find module '@constructive-io/sdk'.

Adds generateMultiTargetBarrel() which creates:
  export * as admin from './admin';
  export * as auth from './auth';
  export * as public_ from './public';  // reserved word alias

Called from generateMulti() after all targets complete.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 4e56598 into main Mar 21, 2026
44 checks passed
@pyramation pyramation deleted the devin/1774066120-fix-multi-target-barrel branch March 21, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant