Skip to content

fix: limit admin source aliasing to repo dev#183

Merged
ascorbic merged 2 commits intoemdash-cms:mainfrom
masonjames:codex/admin-dev-alias-default-dist
Apr 27, 2026
Merged

fix: limit admin source aliasing to repo dev#183
ascorbic merged 2 commits intoemdash-cms:mainfrom
masonjames:codex/admin-dev-alias-default-dist

Conversation

@masonjames
Copy link
Copy Markdown
Contributor

@masonjames masonjames commented Apr 3, 2026

What does this PR do?

Fixes Astro dev so the raw @emdash-cms/admin source alias only applies when running an EmDash app inside this repo. External app installs now use the built admin package surface, while local monorepo/admin development keeps source aliasing for HMR.

The tests cover:

  • local monorepo dev uses packages/admin/src
  • external app dev uses packages/admin/dist
  • sibling paths with matching prefixes do not count as inside this repo
  • non-dev commands use dist

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm --silent lint:json | jq '.diagnostics | length' returns 0
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code

Screenshots / test output

  • pnpm --silent lint:quick
  • pnpm --filter emdash exec vitest run tests/unit/astro/vite-config.test.ts
  • pnpm typecheck

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 3, 2026

🦋 Changeset detected

Latest commit: 53cce68

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@masonjames masonjames marked this pull request as ready for review April 3, 2026 18:00
Copilot AI review requested due to automatic review settings April 4, 2026 17:03
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 4, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@183

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@183

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@183

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@183

emdash

npm i https://pkg.pr.new/emdash@183

create-emdash

npm i https://pkg.pr.new/create-emdash@183

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@183

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@183

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@183

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@183

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@183

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@183

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@183

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@183

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@183

commit: 53cce68

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Astro integration’s Vite configuration so that, during astro dev, EmDash uses the built @emdash-cms/admin package by default (instead of forcing raw source), with an opt-in escape hatch via EMDASH_USE_ADMIN_SOURCE=1.

Changes:

  • Gate admin source aliasing in dev behind EMDASH_USE_ADMIN_SOURCE=1, otherwise use admin dist/.
  • Keep additional SSR dependencies (sanitize-html parsing stack) external for Node SSR to avoid runtime ESM interop issues.
  • Add unit tests for SSR externals composition and admin alias selection.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/astro/integration/vite-config.ts Switch dev default to admin dist/, add NODE_SSR_EXTERNALS, and apply it to SSR externals + optimizeDeps exclusions.
packages/core/src/astro/routes/admin.astro Change AdminWrapper import to a local sibling module.
packages/core/tests/unit/astro/vite-config.test.ts New tests covering SSR externals behavior and admin aliasing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/tests/unit/astro/vite-config.test.ts Outdated
Comment thread packages/core/tests/unit/astro/vite-config.test.ts Outdated
@ascorbic
Copy link
Copy Markdown
Collaborator

Can you explain a bit about why you're suggesting this change? I would rather just do a fix to ensure it doesn't apply when installed for end users.

@masonjames masonjames changed the title fix: use the built admin package by default in Astro dev fix: limit admin source aliasing to repo dev Apr 12, 2026
@masonjames
Copy link
Copy Markdown
Contributor Author

masonjames commented Apr 12, 2026

Thanks — agreed. I was trying to keep the dev-only admin source alias from leaking into installed apps, but the first pass was too broad. The main use case is external Astro apps consuming EmDash — including linked/local installs — where the host app should see the same built admin package surface it would get from npm, not raw admin source.

I pushed a narrower version that keeps source aliasing for local repo development and uses the built admin package for external app installs. I also dropped the unrelated SSR externalization and admin.astro import change from this PR.

@ascorbic
Copy link
Copy Markdown
Collaborator

We should probably just not be shipping the src folder to production

@masonjames
Copy link
Copy Markdown
Contributor Author

Thanks @ascorbic Agreed — that sounds like the cleanest fix.

One nuance from checking the manifests: @emdash-cms/admin already packs only dist, so this PR’s specific alias leak is mainly about linked/workspace installs where src still exists on disk.

The source-shipping issue is in emdash itself: exports like emdash/ui, emdash/ui/search, and emdash/routes/* currently point at src, and those entries aren’t built into dist today.

I can keep this PR scoped as a small guard for consumer apps, then do a follow-up to move those exports to built outputs and remove src from the published package if that makes the most sense.

Happy to tackle that next if that’s the direction you want.

@ascorbic
Copy link
Copy Markdown
Collaborator

Most of those UI exports are Astro components though, which are not compiled

@masonjames masonjames force-pushed the codex/admin-dev-alias-default-dist branch from 1e1598b to 9fa6698 Compare April 14, 2026 15:16
@masonjames
Copy link
Copy Markdown
Contributor Author

Narrowed this to the admin package aliasing behavior only; no emdash/ui* or route source-export changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 282 to 287
const isDev = command === "dev";
const projectRoot = fileURLToPath(options.astroConfig.root);

// In dev mode within the monorepo, alias JS imports to source for instant HMR.
// CSS always comes from dist/ (pre-compiled by @tailwindcss/cli) since Tailwind's
// Vite plugin has native deps that don't bundle well. Run `pnpm dev` in packages/admin
// alongside the demo server to get CSS watch-rebuilds too.
const adminSourcePath = isDev ? resolveAdminSource() : undefined;
const adminSourcePath = isDev ? resolveAdminSource(projectRoot) : undefined;
const useSource = adminSourcePath !== undefined;

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useSource doesn't narrow adminSourcePath for TypeScript, so adminSourcePath remains string | undefined even when useSource is true. Consider structuring this as a direct check on adminSourcePath (or typeof adminSourcePath === "string") so later uses can be type-safe without relying on non-local reasoning.

Copilot uses AI. Check for mistakes.
// and redirect locale .mjs imports to dist/.
// In production, macros are pre-compiled by tsdown in the admin package.
...(useSource ? [linguiMacroPlugin(adminSourcePath!, adminDistPath)] : []),
...(useSource ? [linguiMacroPlugin(adminSourcePath, adminDistPath)] : []),
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call passes adminSourcePath (typed string | undefined) into linguiMacroPlugin (expects string). Even though useSource is derived from adminSourcePath !== undefined, TypeScript won't correlate them; please either (a) branch on adminSourcePath directly here, or (b) reintroduce a local non-null assertion after narrowing so the plugin always receives a string.

Suggested change
...(useSource ? [linguiMacroPlugin(adminSourcePath, adminDistPath)] : []),
...(useSource ? [linguiMacroPlugin(adminSourcePath!, adminDistPath)] : []),

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +11
const externalProjectRoot = new URL("file:///workspace/emdash-site/");
const siblingProjectRoot = new URL("../../../../../../emdash-site/", import.meta.url);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test hard-codes file:///workspace/emdash-site/ as the external project root. This path is environment-specific and can also be an invalid file URL on Windows (no drive/UNC), making the test less portable. Prefer constructing an external root via pathToFileURL(resolve(os.tmpdir(), ...)) or another deterministic path derived from the current runtime.

Copilot uses AI. Check for mistakes.
@ascorbic
Copy link
Copy Markdown
Collaborator

/ultrareview

@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented Apr 27, 2026

All concentrated in one file.

The PR is clean. Per the instructions: "If the PR looks good, respond with only 'LGTM!' and skip posting a review."

LGTM!

github run

Copy link
Copy Markdown
Collaborator

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ascorbic ascorbic merged commit da3d065 into emdash-cms:main Apr 27, 2026
35 checks passed
@emdashbot emdashbot Bot mentioned this pull request Apr 27, 2026
0aveRyan pushed a commit to 0aveRyan/emdash that referenced this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants