bundler: remove mutable Rootname global; derive and return the entry name (#95) - #118
Merged
Conversation
UnbundleAll stored the detected entry-module name in a mutable package global (Rootname) while findNextBundledScript hardcoded "__root" in its terminating regex. The two disagreed, causing (a) silent loss of a bundle's alphabetically-last module whenever its entry was not named "__root", and (b) persistent cross-call contamination that corrupted the entry line emitted by later Bundle calls. Rootname is now an immutable const (the canonical entry name and default). UnbundleAll detects the actual entry name locally, threads it into the scan regex, and returns it; UnbundleAllXML returns the canonical name so Lua and XML unbundling stay uniform. Callers (Unbundle, the shared handler, and tests) use the returned name instead of the global. Adds bundler tests reproducing both failure modes with a foreign entry name. Fixes #95 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
argonui
force-pushed
the
refactor/bundler-rootname
branch
from
August 4, 2026 02:24
4a9b1f2 to
d490839
Compare
argonui
added a commit
that referenced
this pull request
Aug 4, 2026
#116 (handler tests) and #118 (bundler Rootname refactor) each merged clean against a main that lacked the other, but together they don't compile: the test called h.unbundle with two return values while #118 changed it to three. Discard the new root-name return in the test. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Summary
bundler.Rootnamewas a mutable package global thatUnbundleAllrewrote at runtime, whilefindNextBundledScripthardcoded"__root"in its terminating regex. The two disagreed, producing the two failures described in #95:__rootlost its alphabetically-last module, with no error, because that module's__bundle_registerblock is only matched when followed by the literalreturn __bundle_require("__root").Bundle()registered the root under the stale name whilemetasuffixstill emittedreturn __bundle_require("__root"), producing Lua that references an unregistered module.Fix
Follows the issue's suggested approach:
Rootnameis now an immutableconst— the canonical entry name and the default when a bundle declares none.UnbundleAlldetects the actual entry name locally from thereturn __bundle_require("...")line, threads it into the scan regex (viaregexp.QuoteMeta, no longer hardcoded), and returns it:(map[string]string, string, error).UnbundleAllXMLreturns the canonicalRootnameso Lua and XML unbundling stay uniform behind the sharedhandlerfunc pointer.Unbundle,AnalyzeBundle,handler.WhileWritingToFile(no longer referencesbundler.Rootname), and the affected tests.Tests
Adds two
bundlertests over a bundle with a foreign entry name (custom_entry):TestUnbundleForeignEntryName— asserts the alphabetically-last module (zzz) survives and the returned root name is correct (failure mode a).TestNoCrossCallContamination— unbundles the foreign bundle, then asserts a subsequentBundlestill emits__rootand round-trips (failure mode b).Verified the first test fails against the pre-fix hardcoded regex.
go build ./...,go vet ./..., andgo test ./...all pass.Fixes #95