Repository navigation
Backlog
Labels
Description
Context
Part of #2459, whose Copied components section has the full rules. After #2460, #2461 and #2463, nsgo add only requires modules, and #2466 holds declared components to the copy rules. An app that wants to change a component copies it by hand, and then:
- its imports still name the source: three files of
ui/chatimportui/chat/locales, andui/terminal's external test importsuiterminal "github.com/nsgo-dev/nsgo/ui/terminal"(ui/terminal/terminal_test.go:15); - its
catalog_gen.go, generated by another NSGo, failsnsgo checkas out of date, since main-module catalogs are checked with this nsgo's generator (cmd/nsgo/i18n_build.go:233-263,:281-311), and the app's catalogs keep supplying the original package (cmd/nsgo/i18n.go:30-34,ui/chat/locales/locales.go:1-3); - its license stays behind unless someone copies it. The build applies
licensesonly to other modules (cmd/nsgo/licenses.go:194,:282-305), and lists license documents in the app's directories under the app's own module path (:168-217,:250), as nsgo build: treat a Go workspace's modules as the app's own in license notices #1814 found for workspace modules; - nothing records where it came from, so its edits and the author's later fixes cannot be told apart.
A hand copy can also carry what nobody reviewed: a .syso file, an nsgo-natives.yaml (cmd/nsgo/package_natives.go:192-207), an AGENTS.md, a //go:generate line, bidi characters.
Why it matters
Copying is how an app takes a component and makes it its own. With a plan and a record, the copy is reviewed before it is written, and can be compared and updated later.
Proposal
- Names. An index item with
componentis copied.module[@version]#namenames a component that the module'snsgo-module.yamldeclares, parsed asparseModuleTemplateparses templates (cmd/nsgo/init_module.go:19-37). - Version.
- The typed version; else the version of the module that the app requires, which is final, so a version that does not declare the component is refused with the
nsgo add <name>@<version>that takes one that does; else the item'sversion; else@upgrade. - A version that moves the app's requirement says so in the plan's first line. A typed version below the app's requirement leaves it alone, and the plan says the copy is older.
- A module whose
goline is newer than the app's after the plan, or below 1.22, is refused.
- The typed version; else the version of the module that the app requires, which is final, so a version that does not declare the component is refused with the
- Source.
go mod download -jsonruns in an isolated directory, as indownloadInitModule(init_module.go:174-215), withadd's environment. x/mod'szip.CheckZipchecks the archive, anddirhash.HashZipmust equal the app's go.sum entry, when there is one, and the download'sSum. Files are read from that zip. - Rules. cmd/nsgo: nsgo check holds the components a module declares to the rules nsgo add copies by #2466's package, and:
- imports: rewritten as RFC: libraries and components by name: nsgo add, registries, copied components, and native needs declared by packages #2459 lists, keeping their names; a rewritten path that appears whole in a comment is rewritten too, and one in a string literal is listed; then
go/format; - components it imports: copied into the default directory, or found where an earlier copy is; a taken default place stops the plan, naming
nsgo add -dir <dir> <name>; - requirements: the component's module at least at the copy's version, and other modules at least at the versions the component module's go.mod requires (x/mod's
modfile), withgo get -modfilein the same plan under cmd/nsgo: nsgo add, a go get that shows its plan first and never moves an app onto an unreleased NSGo #2460's environment and refusals, marked direct. cmd/nsgo: nsgo add shows each target's native libraries and licenses, and refuses what the app's license policy would fail #2463' listing shows what they bring to each target; - tests: listed apart, with their build constraints.
-tests=falseleaves out_test.gofiles andtestdata/, and the record keeps the choice.
- imports: rewritten as RFC: libraries and components by name: nsgo add, registries, copied components, and native needs declared by packages #2459 lists, keeping their names; a rewritten path that appears whole in a comment is rewritten too, and one in a string literal is listed; then
- Catalogs.
- The copied catalogs are loaded under the copy's final import path, not
importPathOfof the staging directory (i18n_build.go:324), andcatalog_gen.gois generated in memory withnsgo i18n's code (generateCatalog,:313-345). - Supplies to other packages resolve with the planned go.mod through the overlay, not plain
go list(:157-167). - The plan names the keys of the app's catalogs that supply the original
locales. Once the app imports the copy,nsgo check's coverage warning names the copy's key (:215-216). - A plan that moves NSGo says that
nsgo dev,buildori18nthen rewrites the generated file.
- The copied catalogs are loaded under the copy's final import path, not
- Licenses.
- Every license document the copy brings, beside it and inside it, is classified with the build's classifier and checked against the app's policy; a refusal names the
licenses.allowline. - The documents of the module root, and of the directories between it and the component, are copied beside the copy, and two with one name are refused.
- The build gives a main-module package directory that holds
nsgo-copy.yamlits own section ofTHIRD_PARTY_NOTICES.txt, headed<import path>, copied from <module> <version>, and leaves those documents out of the app's own section (addLicensePackage,licenses.go:168-199).
- Every license document the copy brings, beside it and inside it, is classified with the build's classifier and checked against the app's policy; a refusal names the
- Destination.
components.dirin nsgo.yaml, defaultcomponents, relative to nsgo.yaml; the module root'scomponentswithout nsgo.yaml;-dirfor the one component named, ending in the package's name. Refused:- outside the module, or in
vendor,testdata, a directory starting with.or_, or a nested module; - an existing path, or one that differs only in case, that is not this component's copy;
- a second copy of a component;
- a module that go.mod replaces.
- outside the module, or in
- Record.
nsgo-copy.yaml, as RFC: libraries and components by name: nsgo add, registries, copied components, and native needs declared by packages #2459 defines it: strict, deterministic, without a hash. Its paths are checked on every read, every read and write it drives goes through anos.Rootat the copy's directory, and symlinks are refused. - Plan. It shows the files, the rewritten imports and comments, the go.mod changes, the licenses, and the targets vetted and not vetted:
- vetting runs
go vetfor each target inbuild.targets, or the host's without nsgo.yaml, invetEnv's environment (check.go:347-381), with go.mod, go.sum and the copy given through-overlayand-mod=readonly, as cmd/nsgo: nsgo add shows each target's native libraries and licenses, and refuses what the app's license policy would fail #2463 lists, so a workspace and a vendor directory work; - a target whose toolchain the host lacks is listed as not vetted, with the reason, as
nsgo check -target allskips one (check.go:151-170), and does not stop-y; -diffprints every file;- cmd/nsgo: nsgo check holds the components a module declares to the rules nsgo add copies by #2466's flags, and a copy that does not vet, are shown with their positions and refused under
-y.
- vetting runs
- Applying works as in cmd/nsgo: nsgo add, a go get that shows its plan first and never moves an app onto an unreleased NSGo #2460, holding the module's check lock (
lockCheck,check.go:270-318).- The copy goes into a hidden staging directory beside its destination, which
./...skips as it skipsnsgo dev -preview's host (preview.go:29-30), and is then renamed into place. - An error or interrupt removes it and restores go.mod and go.sum; the next
addremoves one an interrupted run left.
- The copy goes into a hidden staging directory beside its destination, which
- An existing copy. The same version is a no-op that prints the copy's version and directory. Another version is refused until cmd/nsgo: nsgo add <component>@<version> updates a copy file by file, keeping the app's edits #2469, naming
nsgo diff <name>@<version>.nsgo remove's refusal of a component (cmd/nsgo: nsgo remove drops a library the module no longer imports, through a go mod tidy it shows first #2465) names the copy's directory. - Usage and docs:
nsgo add [-dry-run] [-y] [-diff] [-dir D] [-tests=false] ..., and thecomponents:key in nsgo.yaml;- a new page,
docs/public/en/copying-components.md(group Components), and its zh page; - the Adding libraries section of
building.md; skills/nsgo/SKILL.md;- a
changelog.dfragment.
Acceptance
- Offline tests use a
file://proxy and a module cache of their own (addTemplateVersion,cmd/nsgo/init_module_test.go:91-134;goEnv,cmd/nsgo/delegate_test.go:23-31). The app requires NSGo through areplaceof this checkout, and a fixture module serves two components:field: catalogs in en and zh-Hans, an_android.gofile, a preview fixture, an embedded SVG inicons/with anOFL.txt, a README.md, and an external test of its own package;form: importsfieldand a package ofexample.com/flags.
- Golden plans; the written files and the record equal golden files; loading and saving the record changes nothing
-
formbringsfield, and requiresexample.com/flagsat the version form's go.mod requires, never below the app's - The generated catalog equals what
nsgo i18nwrites in place, andnsgo checkpasses; with the app supplying the originallocales, the plan names that key - The copy vets for
android_arm64with its_android.gofile; a target whose toolchain is missing, simulated, is listed as not vetted, and-ystill applies - An app under a go.work, and one with a vendor directory without
goEnv's-mod=mod, are planned and vetted; the second's next step isgo mod vendor - Each refusal holds with
-yand without it: a path with..or a leading dot; a.syso; anAGENTS.md; a second package; an internal import;import "C"; a foreign//go:generate; a 2 MiB file; a destination invendor, under a symlinked parent, already there, orcomponents/Chatbesidecomponents/chat; copyleft underlicenses.copyleft: error; a go.sum entry that does not match; a zip in the module cache changed after download - A U+202E in a comment, a Cyrillic letter in an identifier and an
unsafeimport are each shown with their position and refused under-y - An app that requires a version without the component is refused with the command; a typed version that raises the module says so in the first line
-
-tests=falsecopies no test, and the record says so - Without a terminal and without
-y, nothing is written; an injected failure leaves the module as it was; a leftover staging directory is removed by the next add - A build's
THIRD_PARTY_NOTICES.txtholds the copy's LICENSE, NOTICE and OFL.txt under<import path>, copied from <module> <version>, not under the app's own heading -
nsgo remove fieldis refused, namingcomponents/field - The docs (en and zh), the skill and the usage describe the command
Activity