Review round 1 for the Node build module: build depth (1490), bin scripts for the test script (1491), toolchain.reported and its stream (1483, 1488); delta part 3 of 4
This commit is contained in:
@@ -76,7 +76,7 @@ func TestTscAndEsbuildRunWithTheBuildAgentsFlags(t *testing.T) {
|
||||
if _, err := m.build(context.Background(), buildArgs()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dir := filepath.Join(work, "w1", "tree", "modules", "m")
|
||||
dir := filepath.Join(work, "w1", "stage-tools", "modules", "module")
|
||||
nm := filepath.Join(m.toolchainDir(), "node_modules")
|
||||
banner := "--banner:js=import { createRequire as __meshRequire } from 'node:module'; const require = __meshRequire(import.meta.url);"
|
||||
common := []string{"--bundle", "--platform=node", "--format=esm", "--target=node22",
|
||||
@@ -143,7 +143,7 @@ func TestTheBundleIsPackedWithItsLauncherAndPackageJson(t *testing.T) {
|
||||
if err != nil || again.(BuildResult).Digest != r.Digest {
|
||||
t.Errorf("a second build: %v, digest %v, want %s", err, again, r.Digest)
|
||||
}
|
||||
launcher, _ := os.ReadFile(filepath.Join(filepath.Dir(r.Archive), "tree", "modules", "m", ".mesh-build", "tools", "tools", "index.serve.mjs"))
|
||||
launcher, _ := os.ReadFile(filepath.Join(filepath.Dir(r.Archive), "stage-tools", "modules", "module", ".mesh-build", "tools", "tools", "index.serve.mjs"))
|
||||
if !strings.Contains(string(launcher), `import { serveRegisteredOverStdio } from "@novox/mesh-sdk/stdio";`) || !strings.Contains(string(launcher), `await import("./index.js");`) {
|
||||
t.Errorf("launcher = %q", launcher)
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func TestNoSymlinkIsMadeInTheWorkspace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 1490: the bundle's SDK comes from the workspace's node_modules, copied beside the tree, and the packed bundle holds
|
||||
// 1490: the bundle's SDK comes from the staging directory's node_modules, two levels above the module, and the packed bundle holds
|
||||
// the toolchain's packages only when the artifact keeps one external, never typescript or esbuild.
|
||||
func TestThePackagesAreCopiedBesideTheTreeAndIntoTheBundleOnlyForExternals(t *testing.T) {
|
||||
m, _, work := builtMachine(t, ``)
|
||||
@@ -170,7 +170,7 @@ func TestThePackagesAreCopiedBesideTheTreeAndIntoTheBundleOnlyForExternals(t *te
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nm := filepath.Join(work, "w1", "node_modules")
|
||||
nm := filepath.Join(work, "w1", "stage-tools", "node_modules")
|
||||
for _, p := range []string{"@novox/mesh-sdk/dist/stdio.js", "@types/node/index.d.ts", "nats/lib/nats.js"} {
|
||||
if _, err := os.Stat(filepath.Join(nm, p)); err != nil {
|
||||
t.Errorf("the workspace's node_modules lacks %s", p)
|
||||
@@ -217,3 +217,40 @@ func TestOnlyATypeScriptBundleOfTheModuleIsBuilt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1490 (review 7): the build agent runs a module mounted at /app/modules/module with the toolchain's packages at
|
||||
// /app/node_modules (mesh-controller builder.go `within`), so esbuild writes the path comments of what it inlines
|
||||
// relative to the module's directory as `../../node_modules/...`. The step builds at that depth: in a staging
|
||||
// directory whose module directory has the packages two levels above it, whatever the module's place in the
|
||||
// repository, so the bundle's bytes (and its digest) equal the build agent's.
|
||||
func TestTheBuildRunsWithThePackagesTwoLevelsAboveTheModule(t *testing.T) {
|
||||
for _, module := range []string{"modules/m", "."} {
|
||||
m, f, work := newMachine(t)
|
||||
files := map[string]string{"module.json": strings.Replace(bundleManifest, "%s", "", 1), "tools/index.ts": "export {}"}
|
||||
if module != "." {
|
||||
files = map[string]string{"modules/m/module.json": strings.Replace(bundleManifest, "%s", "", 1), "modules/m/tools/index.ts": "export {}"}
|
||||
}
|
||||
workspaceWith(t, work, files)
|
||||
f.effect = esbuildEffect(t)
|
||||
args := buildArgs()
|
||||
args["module"] = module
|
||||
if _, err := m.build(context.Background(), args); err != nil {
|
||||
t.Fatalf("%s: %v", module, err)
|
||||
}
|
||||
for _, c := range f.calls {
|
||||
rel, err := filepath.Rel(c.dir, filepath.Join(c.dir, "..", "..", "node_modules"))
|
||||
if err != nil || rel != "../../node_modules" {
|
||||
t.Fatalf("%s: relative path %q (%v)", module, rel, err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(c.dir, "..", "..", "node_modules", "@novox", "mesh-sdk", "dist", "stdio.js")); err != nil {
|
||||
t.Errorf("%s: %s ran in %s, which has no packages at ../../node_modules: %v", module, filepath.Base(c.name), c.dir, err)
|
||||
}
|
||||
if filepath.Base(c.dir) != "module" || filepath.Base(filepath.Dir(c.dir)) != "modules" {
|
||||
t.Errorf("%s: ran in %s, want .../modules/module", module, c.dir)
|
||||
}
|
||||
}
|
||||
if !strings.HasPrefix(f.calls[0].dir, filepath.Join(work, "w1")) {
|
||||
t.Errorf("%s: staged outside the workspace: %s", module, f.calls[0].dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user