N2: a build reports every module or package it resolved, with no prefix or scope (issue 721)
Mesh Go modules come from the seat go-package-registry, not the forge, so no prefix or scope tells a mesh package apart. ModuleImports reports the module path of every package the build resolved but the standard library's and the module's own, and build_node_imports every npm package the bundles reach but Node's own modules. The settings import-prefix and import-scope leave both manifests and the ask. Builds: design 47 H2 H-A-539 (withdraws H-A-534's form check and H-A-535)
This commit is contained in:
@@ -33,9 +33,9 @@ func (m *Module) askSteps(steps []StepTool) steprun.AskSteps {
|
||||
}
|
||||
return steprun.AskSteps{
|
||||
Fetch: byName["build_node_fetch"], Build: byName["build_node_build"], Test: byName["build_node_test"],
|
||||
// The mesh npm packages its bundles import, read after the build and said as imports-reported, judged in the
|
||||
// mesh's npm scope (design 47 H2 H-A-523, H-A-532 DQ-6, H-A-534, H-A-535).
|
||||
Imports: byName[ImportsTool], ImportScope: importScope(),
|
||||
// The npm packages its bundles import, read after the build and said as imports-reported (design 47 H2 H-A-523,
|
||||
// H-A-532 DQ-6, H-A-539).
|
||||
Imports: byName[ImportsTool],
|
||||
Compare: steprun.CompareStep(steprun.GeneratedRootTS, func(ws string) string { return filepath.Join(m.Work, ws, "tree") }),
|
||||
Toolchain: func(ctx context.Context) (sdkstep.ToolchainUsed, error) {
|
||||
installed, err := m.Probe(ctx)
|
||||
|
||||
@@ -4,13 +4,11 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// Design 47 G §496, §602 (BG4, BN4, BI4): the module's puller says the seat's events on this node's subjects.
|
||||
@@ -61,13 +59,6 @@ func TestADoneNodeBuildSaysItsImportSetAndAFailedOneNone(t *testing.T) {
|
||||
said[0].Commit != askCommit || !slices.Equal(said[0].Imports, []string{"@novox/mesh-sdk"}) {
|
||||
t.Fatalf("said %v on %v, want one imports-reported of gitea naming @novox/mesh-sdk on %s", said, subjects, want)
|
||||
}
|
||||
// H-A-534, H-A-535: the import set is judged by the setting import-scope, so a scope it lies outside refuses it.
|
||||
said = nil
|
||||
t.Setenv(stdio.SettingWord(ImportScopeSetting), "@other")
|
||||
if _, err := steprun.RunAsk(context.Background(), m.askSteps(steps), a); err == nil || !strings.Contains(err.Error(), "@other") {
|
||||
t.Errorf("an import set outside import-scope: %v, want it refused", err)
|
||||
}
|
||||
t.Setenv(stdio.SettingWord(ImportScopeSetting), "")
|
||||
said = nil
|
||||
for i := range steps {
|
||||
if steps[i].Name == "build_node_build" {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
trunk "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
@@ -116,9 +115,9 @@ func TestManifestTakesTheBuildCapacity(t *testing.T) {
|
||||
if strings.Contains(doc.Config[steprun.BuildHoursSetting].Description, "=") {
|
||||
t.Errorf("the build-hours description names a node pair")
|
||||
}
|
||||
// Design 47 H2 H-A-535: the Node build module declares import-scope, the mesh's npm scope by default.
|
||||
if scope := string(doc.Config[ImportScopeSetting].Default); scope != `"`+trunk.DefaultNpmScope+`"` {
|
||||
t.Errorf("the import-scope default = %s, want %q", scope, trunk.DefaultNpmScope)
|
||||
// Design 47 H2 H-A-539: no scope tells a mesh package apart, so the module declares no setting import-scope.
|
||||
if _, ok := doc.Config["import-scope"]; ok {
|
||||
t.Errorf("the manifest declares import-scope, which H-A-539 withdrew")
|
||||
}
|
||||
var capacity float64
|
||||
_ = json.Unmarshal(doc.Config[sdkstep.CapacitySetting].Default, &capacity)
|
||||
|
||||
@@ -362,23 +362,23 @@ func TestTheBundleCarriesTheAsksVersionInItsPackageJSON(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// N1/AC1, N1/AC2 (design 47 H2 H-A-523, H-A-532 DQ-6): after a bundle's build, the imports step runs esbuild over the
|
||||
// staged entrypoint and launcher with a metafile and answers the npm packages in the mesh's scope among its inputs and
|
||||
// external imports, each by its package name once (the SDK's stdio sub-path is the SDK); a bundle reaching none answers
|
||||
// none.
|
||||
func TestTheImportsStepNamesTheMeshNpmPackagesABundleReaches(t *testing.T) {
|
||||
// N1/AC1, N1/AC2 (design 47 H2 H-A-523, H-A-532 DQ-6, H-A-539): after a bundle's build, the imports step runs esbuild
|
||||
// over the staged entrypoint and launcher with a metafile and answers every npm package among its inputs and external
|
||||
// imports, each by its package name once (the SDK's stdio sub-path is the SDK), with no scope filter: a mesh package is
|
||||
// told apart by the indexer, never by its scope. Node's own modules (node:module, fs) are no package; a bundle reaching
|
||||
// only those answers none.
|
||||
func TestTheImportsStepNamesTheNpmPackagesABundleReaches(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
metafile string
|
||||
want []string
|
||||
}{
|
||||
{"mesh packages", `{"inputs":{
|
||||
".mesh-build/tools/tools/index.js":{"imports":[{"path":"../../node_modules/@novox/mesh-sdk/dist/stdio.js"},{"path":"@novox/mesh-other/x","external":true},{"path":"pg","external":true}]},
|
||||
{"packages", `{"inputs":{
|
||||
".mesh-build/tools/tools/index.js":{"imports":[{"path":"../../node_modules/@novox/mesh-sdk/dist/stdio.js"},{"path":"@novox/mesh-other/x","external":true},{"path":"pg","external":true},{"path":"node:module","external":true},{"path":"fs","external":true}]},
|
||||
"../../node_modules/@novox/mesh-sdk/dist/stdio.js":{"imports":[]},
|
||||
"../../node_modules/@novox/mesh-sdk/dist/index.js":{"imports":[]},
|
||||
"../../node_modules/nats/lib/index.js":{"imports":[]}}}`, []string{"@novox/mesh-other", "@novox/mesh-sdk"}},
|
||||
{"none", `{"inputs":{".mesh-build/tools/tools/index.js":{"imports":[{"path":"../../node_modules/nats/lib/index.js"}]},
|
||||
"../../node_modules/nats/lib/index.js":{"imports":[]}}}`, []string{}},
|
||||
"../../node_modules/nats/lib/index.js":{"imports":[]}}}`, []string{"@novox/mesh-other", "@novox/mesh-sdk", "nats", "pg"}},
|
||||
{"none", `{"inputs":{".mesh-build/tools/tools/index.js":{"imports":[{"path":"node:module","external":true},{"path":"path","external":true}]}}}`, []string{}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
m, f, work := builtMachine(t, `,"external":["pg"]`)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package main
|
||||
|
||||
// The imports step (design 47 H2 H-A-523, H-A-532 DQ-6, H-A-534): at a build's end the module says which mesh npm
|
||||
// packages its TypeScript bundles import, so the indexer can take the fingerprint over those packages' content and no
|
||||
// other. It is what esbuild's metafile names as each bundle's inputs, read from the bundle's compiled entrypoints and
|
||||
// launchers as the build step staged them, and of those the packages in the mesh's npm scope (the setting
|
||||
// import-scope), each by its package name once (@novox/mesh-sdk, never a sub-path of it). A bundle's inputs are what
|
||||
// its entrypoints reach, so no test file is among them.
|
||||
// The imports step (design 47 H2 H-A-523, H-A-532 DQ-6, H-A-539): at a build's end the module says which npm packages
|
||||
// its TypeScript bundles import, so the indexer can take the fingerprint over the ones a module of the module graph
|
||||
// publishes and no other. It is what esbuild's metafile names as each bundle's inputs, read from the bundle's compiled
|
||||
// entrypoints and launchers as the build step staged them: every npm package among them, each by its package name once
|
||||
// (@novox/mesh-sdk, never a sub-path of it), with no scope telling a mesh package apart, and none of Node's own modules.
|
||||
// A bundle's inputs are what its entrypoints reach, so no test file is among them.
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -17,35 +17,22 @@ import (
|
||||
"strings"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
trunk "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
)
|
||||
|
||||
// ImportsTool reads the mesh npm packages a module's bundles import (design 47 H2 H-A-532 DQ-6).
|
||||
// ImportsTool reads the npm packages a module's bundles import (design 47 H2 H-A-532 DQ-6).
|
||||
const ImportsTool = "build_node_imports"
|
||||
|
||||
// ImportScopeSetting is the module's setting naming the npm scope of the mesh's packages (design 47 H2 H-A-535).
|
||||
const ImportScopeSetting = "import-scope"
|
||||
|
||||
// ImportsResult is what the imports step answers; a BuildAnswer carries Imports as it is.
|
||||
type ImportsResult struct {
|
||||
Imports []string `json:"imports"`
|
||||
}
|
||||
|
||||
// importScope is the setting import-scope, trunk.DefaultNpmScope when it names none.
|
||||
func importScope() string {
|
||||
if v, ok := stdio.Setting(ImportScopeSetting); ok && strings.TrimSpace(v) != "" {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
return trunk.DefaultNpmScope
|
||||
}
|
||||
|
||||
func (m *Module) importsTool() StepTool {
|
||||
return StepTool{
|
||||
Name: ImportsTool,
|
||||
Description: "Read the mesh npm packages the TypeScript bundles of a module of a workspace import, after its build: " +
|
||||
"esbuild's inputs of each bundle's compiled entrypoints and launchers, kept to the packages in the mesh's npm scope " +
|
||||
"(the setting import-scope), each by its package name, sorted and each once. It is what a build says at its end " +
|
||||
Description: "Read the npm packages the TypeScript bundles of a module of a workspace import, after its build: " +
|
||||
"esbuild's inputs of each bundle's compiled entrypoints and launchers, every npm package among them but Node's own " +
|
||||
"modules, each by its package name, sorted and each once. It is what a build says at its end " +
|
||||
"for the fingerprint (design 47 H2 H-A-523). Writes only esbuild's scratch output in the workspace.",
|
||||
Input: map[string]any{
|
||||
"type": "object",
|
||||
@@ -78,13 +65,12 @@ func (m *Module) imports(ctx context.Context, args map[string]any) (any, error)
|
||||
if err := json.Unmarshal(raw, &manifest); err != nil {
|
||||
return nil, fmt.Errorf("module.json is not JSON: %w", err)
|
||||
}
|
||||
scope := importScope()
|
||||
seen := map[string]bool{}
|
||||
for _, a := range manifest.Build.Artifacts {
|
||||
if a.Kind != "bundle" || a.Language != "typescript" {
|
||||
continue
|
||||
}
|
||||
names, err := m.bundleImports(ctx, root, a, scope)
|
||||
names, err := m.bundleImports(ctx, root, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -100,9 +86,9 @@ func (m *Module) imports(ctx context.Context, args map[string]any) (any, error)
|
||||
return ImportsResult{Imports: out}, nil
|
||||
}
|
||||
|
||||
// bundleImports are the packages in scope that esbuild names as inputs of bundle a, read in the stage its build left
|
||||
// bundleImports are the npm packages esbuild names as inputs of bundle a, read in the stage its build left
|
||||
// (build.go: <root>/stage-<artifact>/modules/module), from the same entries and externals the build bundled.
|
||||
func (m *Module) bundleImports(ctx context.Context, root string, a artifact, scope string) ([]string, error) {
|
||||
func (m *Module) bundleImports(ctx context.Context, root string, a artifact) ([]string, error) {
|
||||
dir := filepath.Join(root, "stage-"+a.Name, "modules", "module")
|
||||
out := Out(a.Name)
|
||||
if _, err := os.Stat(filepath.Join(dir, out)); err != nil {
|
||||
@@ -133,12 +119,12 @@ func (m *Module) bundleImports(ctx context.Context, root string, a artifact, sco
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("esbuild wrote no metafile for %s: %w", a.Name, err)
|
||||
}
|
||||
return inScope(raw, scope)
|
||||
return packagesOf(raw)
|
||||
}
|
||||
|
||||
// inScope are the npm packages in scope an esbuild metafile names: each input under a node_modules directory and each
|
||||
// external import, by its package name.
|
||||
func inScope(metafile []byte, scope string) ([]string, error) {
|
||||
// packagesOf are the npm packages an esbuild metafile names: each input under a node_modules directory and each external
|
||||
// import, by its package name, but Node's own modules.
|
||||
func packagesOf(metafile []byte) ([]string, error) {
|
||||
var meta struct {
|
||||
Inputs map[string]struct {
|
||||
Imports []struct {
|
||||
@@ -152,7 +138,7 @@ func inScope(metafile []byte, scope string) ([]string, error) {
|
||||
}
|
||||
var out []string
|
||||
keep := func(name string) {
|
||||
if strings.HasPrefix(name, scope+"/") && !slices.Contains(out, name) {
|
||||
if name != "" && !nodeBuiltin(name) && !slices.Contains(out, name) {
|
||||
out = append(out, name)
|
||||
}
|
||||
}
|
||||
@@ -183,3 +169,19 @@ func packageName(spec string) string {
|
||||
}
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
// nodeBuiltin says whether name is one of Node's own modules (node:<name>, or a name of module.builtinModules), which
|
||||
// is the runtime's standard library and no npm package.
|
||||
func nodeBuiltin(name string) bool {
|
||||
if strings.HasPrefix(name, "node:") {
|
||||
return true
|
||||
}
|
||||
return slices.Contains(nodeBuiltins, name)
|
||||
}
|
||||
|
||||
// nodeBuiltins are the names of Node 22's module.builtinModules without a sub-path.
|
||||
var nodeBuiltins = []string{"assert", "async_hooks", "buffer", "child_process", "cluster", "console", "constants",
|
||||
"crypto", "dgram", "diagnostics_channel", "dns", "domain", "events", "fs", "http", "http2", "https", "inspector",
|
||||
"module", "net", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "stream",
|
||||
"string_decoder", "sys", "timers", "tls", "trace_events", "tty", "url", "util", "v8", "vm", "wasi",
|
||||
"worker_threads", "zlib"}
|
||||
|
||||
@@ -72,13 +72,6 @@
|
||||
"minimum": 1,
|
||||
"maximum": 100,
|
||||
"default": 50
|
||||
},
|
||||
"import-scope": {
|
||||
"type": "string",
|
||||
"description": "The npm scope of the mesh's packages (design 47 H2 H-A-534, H-A-535): a TypeScript build's import set names each package of it its bundles import, by its package name, and the step runner refuses an import set naming a package outside it.",
|
||||
"trusted": false,
|
||||
"runtime": true,
|
||||
"default": "@novox"
|
||||
}
|
||||
},
|
||||
"tools": [
|
||||
|
||||
Reference in New Issue
Block a user