You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Importing a subpath of a scoped runtime package, such as /runtime/v1/@opendatacapture/runtime-core/constants, resolves to a nonexistent .../index.js #1799
The bundler rewrites any import of a subpath of a scoped runtime package to a URL that does not exist. For bare packages, the rule in plugin.ts appends /index.js to /runtime/v1/<pkg> and /runtime/v1/@scope/<pkg>. But its scope group is (@.*\/)?, and .* also matches /, so it swallows any number of path segments. /runtime/v1/@opendatacapture/runtime-core/constants therefore becomes /runtime/v1/@opendatacapture/runtime-core/constants/index.js instead of …/constants.js, and an import that already ends in .js gets /index.js appended after the .js. packages/instrument-bundler/AGENTS.md documents the opposite: only the bare package gets /index.js, and everything deeper gets .js. The import type-checks, because runtime/v1/dist/@opendatacapture/runtime-core/constants.d.ts exists. The bundle then fails to evaluate: on the API the subpath import does not resolve, and in the browser the module 404s. Today this affects FILE_TYPES from /runtime/v1/@opendatacapture/runtime-core/constants, and any future scoped package that ships a subpath.
Bundle an instrument whose index.ts contains import { FILE_TYPES } from '/runtime/v1/@opendatacapture/runtime-core/constants';.
Actual: the bundle contains __import("/runtime/v1/@opendatacapture/runtime-core/constants/index.js") (verified on main), which neither the API nor the browser can load. /runtime/v1/@opendatacapture/runtime-core/constants.js becomes …/constants.js/index.js.
Expected: __import("/runtime/v1/@opendatacapture/runtime-core/constants.js"), which is the file runtime/v1/dist serves.
Tests
packages/instrument-bundler/src/__tests__/plugin.test.ts: it('should append .js to a subpath of a scoped runtime package, so only the bare package resolves to index.js'). Cover @opendatacapture/runtime-core/constants, …/constants.js and the bare @opendatacapture/runtime-core.
e2e: none needed beyond the unit test, since no built-in instrument imports a scoped subpath yet.
Suggested fix
Stop the scope group at one segment and anchor the pattern: /^\/runtime\/v1\/(@[^/]+\/)?[^/]+$/.
Activity