Skip to content

refactor: split the shared building blocks into packages/core - #564

Merged
awatson1978 merged 4 commits into
release/1.0-beta-corefrom
split/core-package
Oct 2, 2026
Merged

awatson1978 merged 4 commits into
release/1.0-beta-corefrom
split/core-package

Conversation

@awatson1978

Copy link
Copy Markdown
Collaborator

This PR starts the @dcmjs/core package. It's the first half of the package-folder split that section 3 of RELEASE_PLAN.md promised: the four engines migrated together on this staging branch, and now the shared building blocks split out into their package folder. A second PR for packages/legacy follows right behind it.

The commits are separable the same way the fixtures move (#521) was:

  1. The first commit is the scaffold: packages/core/package.json and a README, following the fixtures/schemas precedent (private, version 0.0.0, until the publish switch flips for everything at once).
  2. The second and third commits are pure git mv, zero edits — git records them all as R100 renames. The second moves the buffer machinery and shared leaf utilities (SplitDataView, BufferStream, log, the constants, the charset decoders, normalizeSyntax, toFloat, toInt, addAccessors, dicomJson, deepEqual, DicomMetadataListener); the third moves the value types and runtime dictionary (ValueRepresentation, Tag, DicomMetaDictionary, dictionary.fast, dicom.lookup, dicom.packed, dictionary.ranges.data, dictionary.private.data). Everything lands under packages/core/src/ with its relative structure preserved, which is why not one import inside the moved closure needed editing.
  3. The fourth commit is the hand-written rewiring: a two-line shim at every old path under src/ re-exporting from the new location (matched one by one to each module's default-vs-named export shape), a packages/core/src/index.js with the public surface, and two small config consequences — the relative .babelrc became a root babel.config.js with the identical preset (relative Babel configs stop applying at package.json boundaries, so Jest couldn't transform files under packages/core), and the lint/format globs now cover packages/*/src. Tests stay rooted and unmoved, as with the schemas package.

Where DicomMetaDictionary lives. The plan's package table left this open and asked reviewers to confirm — objections welcome before GA. It goes in core, and here's the dependency-graph argument: ValueRepresentation and DicomMetaDictionary point at each other (VR resolves naturalized names through DicomMetaDictionary.nameMap, wired by late-binding injection), its consumers span the legacy engines, the streaming reader, and the wrapper surface alike, and its own imports — the dictionary modules, log, addAccessors, VR — are all core. Putting it anywhere else would force an edge into that package from everything. @dcmjs/legacy will re-export it unchanged, so nothing on today's surface moves.

One deviation from the plan's table, on purpose: BufferStream (and SplitDataView) go to core, not legacy. The table lists BufferStream under legacy, but the event stream uses this machinery too — fromPart10Stream's backpressure relay reads through ReadBufferStream, and the streaming writers write through WriteBufferStream. The rule we're protecting is that neither core nor the new engines ever depend on legacy, so the sync reader can one day be deprecated and removed without touching anything else. Listing BufferStream under legacy would force exactly that forbidden edge. Legacy re-exports both names, so its surface is unaffected.

Two smaller placement calls worth flagging: normalizeSyntax rides in core (it's a pure function over the constants, and the streaming reader imports it), while decodeCore stays in src/ for now — it still imports DicomMessage for tag lookup, so it can't enter core without dragging the legacy reader in; breaking that edge belongs to the parser-wave split, not a move PR. And deepEqual plus DicomMetadataListener moved as shared leaves (each used from both sides of the future package boundary; both import nothing outside core).

The hand-written total is about 145 changed lines (scaffold 38, shims 46, index 45, config 16), well under the 500 budget; the pure moves are exempt and declared above. After each commit group: the full suite is 844 passed / 12 skipped / 856, pnpm run build produces the same bundle surface (checked the UMD export names against the previous build), and lint and format pass over the new globs.

🤖 Generated with Claude Code

awatson1978 and others added 4 commits October 1, 2026 21:25
Adds packages/core/package.json and README.md, following the
packages/fixtures and packages/schemas scaffold precedent (private and
version 0.0.0 until the publish switch flips). The pnpm workspace globs
already cover packages/*, so only the lockfile picks up the new project.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ckages/core (pure git mv)

Pure file moves, zero edits: SplitDataView, BufferStream, log, the DICOM
constants, the charset decoders, normalizeSyntax, and the leaf utilities
(toFloat, toInt, addAccessors, dicomJson, deepEqual,
DicomMetadataListener). Relative structure under src/ is preserved, so
every intra-group import still resolves. The rewiring commit in this PR
adds shims at the old paths.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ore (pure git mv)

Pure file moves, zero edits: ValueRepresentation, Tag,
DicomMetaDictionary, and the runtime dictionary modules
(dictionary.fast, dicom.lookup, dicom.packed, dictionary.ranges.data,
dictionary.private.data). Together with the previous commit this is the
complete @dcmjs/core closure; every import between the moved files is
relative and structure-preserving, so none of them needed editing.

Co-Authored-By: Claude Fable 5 <[email protected]>
Hand-written rewiring for the two pure-move commits before it:

- a shim at every old path under src/ re-exporting from the new
  packages/core location, matching each module's export shape (default
  vs named), so every existing import in src/, test/, and the root
  index keeps working unchanged
- packages/core/src/index.js exporting the package's public surface
- the relative .babelrc becomes a root babel.config.js with the same
  preset: relative Babel configs stop applying at package.json
  boundaries, so Jest could not transform files under packages/core
- the lint and format globs in package.json now cover packages/*/src

No import inside packages/core needed editing: the moves preserve the
relative structure, so the whole closure resolves as before. The
package's only external imports are pako and loglevel.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

1 participant