Skip to content

feat: expose @microsoft/webui/platform subpath#298

Merged
mohamedmansour merged 1 commit into
mainfrom
users/janechu/add-platform-exports-to-main-export
May 16, 2026
Merged

feat: expose @microsoft/webui/platform subpath#298
mohamedmansour merged 1 commit into
mainfrom
users/janechu/add-platform-exports-to-main-export

Conversation

@janechu
Copy link
Copy Markdown
Contributor

@janechu janechu commented May 16, 2026

What

Add a ./platform.js entry to the exports map in packages/webui/package.json so adopters can write:

import { platformKey, packageName, resolve } from '@microsoft/webui/platform.js';

The .js extension on the subpath stays ESM-compliant and matches the rest of the package's resolved paths.

Why

I'm integrating WebUI into a non-WebUI Node host. The integration needs to:

  1. Surface a clear "you don't have the native addon installed for your platform" error to developers running on, say, macOS arm64 without @microsoft/webui-darwin-arm64. platformKey() and packageName() give the exact strings to put in that error.
  2. Spawn the WebUI CLI from a tooling script (build step in another package). resolve('bin') returns the right binary path; without the subpath export the only options are npx webui (slow startup) or reaching into node_modules/@microsoft/webui/dist/platform.js directly (fragile).

packages/webui/src/platform.ts already exports all three functions, and dist/platform.js / dist/platform.d.ts are already shipped via files: ["dist/"]. The only thing missing is the exports map entry, which under Node's strict ESM resolution makes them unreachable.

This PR adds 6 lines to package.json. No code change, no behavior change for existing imports.

How I tested

The new entry mirrors the existing . entry exactly:

  • types points to ./dist/platform.d.ts (already produced by tsc since src/platform.ts is a sibling of src/index.ts).
  • default points to ./dist/platform.js.

Both files exist after npm run build because index.ts already imports from ./platform.js.

Notes

Comment thread packages/webui/package.json Outdated
@janechu janechu force-pushed the users/janechu/add-platform-exports-to-main-export branch from 49c1c7e to f6e2235 Compare May 16, 2026 14:17
@janechu janechu marked this pull request as ready for review May 16, 2026 14:37
Add a `./platform.js` entry to the package's `exports` map so adopters
can import the platform helpers (`platformKey`, `packageName`,
`resolve`) without reaching into `dist/` directly.

The file `packages/webui/src/platform.ts` already exports a small,
useful API:

- `platformKey()` - `${process.platform}-${process.arch}` string
  used for diagnostics and native addon selection.
- `packageName()` - the matching `@microsoft/webui-<platform>` npm
  package name, useful for "is the right native addon installed?"
  preflight checks in adopter environments.
- `resolve(kind: 'bin' | 'addon')` - resolves the platform-specific
  binary path so adopters can spawn the CLI from their own scripts.

These are all real, useful exports already shipped to disk via the
package's `files: ["dist/"]` entry. The `exports` map just doesn't
surface them.

The subpath includes the `.js` extension to stay ESM-compliant and
match the convention used by the rest of the package's resolved
paths.
@janechu janechu force-pushed the users/janechu/add-platform-exports-to-main-export branch from f6e2235 to 0c65356 Compare May 16, 2026 14:42
@mohamedmansour mohamedmansour merged commit 4903aa4 into main May 16, 2026
21 checks passed
@mohamedmansour mohamedmansour deleted the users/janechu/add-platform-exports-to-main-export branch May 16, 2026 16:27
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.

2 participants