Declare the module's JS dependencies in a package.json - #4
Merged
Conversation
The package shipped only a composer.json, so its frontend dependencies were invisible and unversioned at the package level: every library the module's own code imports was declared solely in the host app's package.json. Nothing recorded that this module needs them, and dropping one from the host would break this module silently. package.json lists what the module's frontend actually imports, pinned to the versions the host already resolves. They are peerDependencies rather than dependencies because the host compiles the module's JS and resolves it from the host's node_modules; the module does not install its own copy, and a second copy of React or the Inertia client would break the app rather than duplicate it. Deliberately no build script yet. A module cannot compile standalone: its frontend imports the host app's UI kit, layouts, hooks and contexts through the @/ alias, which resolves into the host's resources/js. Shipping a build script that cannot produce a usable bundle would be worse than shipping none. See zerp-pk/zerp#56 for the analysis and the options.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of zerp-pk/zerp#56, which asks that each module own its frontend build.
This lands the part that is achievable today: declaring the module's JS dependencies, the issue's third complaint ("Module JS deps are invisible and unversioned at the package level").
The problem it fixes
The package shipped only a
composer.json. Every JS library this module's own code imports was declared solely in the host app'spackage.json. Nothing recorded that this module needs them, so dropping one from the host would break this module silently, and there was no way to see a module's frontend surface without grepping its source.package.jsonnow lists what the frontend actually imports, pinned to the versions the host already resolves.They are
peerDependencies, notdependencies: the host compiles this module's JS and resolves it from the host'snode_modules. The module must not install its own copy. A second copy of React or the Inertia client would not merely duplicate bytes, it would break the app, since a second React instance means a second context tree.No build script, deliberately
The issue also asks for a build script and compiled assets shipped with the package. That is not possible as the code stands, and shipping a build script that cannot produce a usable bundle would be worse than shipping none.
A module cannot compile standalone. Its frontend imports the host app's UI kit, layouts, hooks and contexts through the
@/alias, whichtsconfig.jsonresolves to the host's./resources/js/*. Across all 32 modules that is 5,528 imports into 64 distinct host paths, led by:Compiling that into a self-contained
dist/would mean bundling a private copy of the host's 59-component UI kit, its layouts and its contexts. That breaks rather than duplicates:authenticated-layout,brand-context, i18n and Inertia all assume a single shared React instance and provider tree.Getting to a real per-module build needs one of two architectural changes, neither of which belongs in this PR:
components/ui,layouts,hooksandutilsinto a versioned package both host and modules depend on.@/*as externals, resolved at runtime through a host-side registry (Module Federation or an import map).Full analysis is on zerp-pk/zerp#56. This PR is a prerequisite for either path: you cannot version a module's frontend without first knowing what it depends on.