diff --git a/modules/mesh-build-node/cmd/mesh-build-node/steps.go b/modules/mesh-build-node/cmd/mesh-build-node/steps.go index 0e0d236cb..4593073f7 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/steps.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/steps.go @@ -1,7 +1,9 @@ package main // **The verb `steps`** (design 47 G §22, §307, §326, §328): which pipeline steps a TypeScript artifact can run, by the -// convention check.go tests by. The type-check is the lint step (§328) and is always one; the unit step is the packages +// convention check.go tests by. The type-check is the lint step (§328), answered only when one of the artifact's packages +// holds a TypeScript file, by the test the lint step itself uses (lint.go; design 47 H2 H-A-515 second addendum), so the +// pipeline runner ends a lint with nothing to type-check at placement, never asking it (H-A-515 addendum); the unit step is the packages // holding a package.json script `test`, the integration step those holding `test:integration`. A level with none is not // answered. The answer is kept in the state detected-steps by the artifact's fingerprint, replaced by a newer one and by // again, as the Go build module keeps it. @@ -51,7 +53,15 @@ func detectSteps(dir string, narrowedTree bool) ([]DetectedStep, error) { return nil, err } unit, integration := []string{}, []string{} + lint := false for _, tg := range targets { + if !lint { + sources, err := typeScriptFiles(tg.dir) + if err != nil { + return nil, err + } + lint = len(sources) > 0 + } scripts, err := packageScripts(tg.dir) if err != nil { return nil, err @@ -63,7 +73,10 @@ func detectSteps(dir string, narrowedTree bool) ([]DetectedStep, error) { integration = append(integration, tg.where) } } - steps := []DetectedStep{{Step: StepLint}} + steps := []DetectedStep{} + if lint { + steps = append(steps, DetectedStep{Step: StepLint}) + } for _, l := range []struct { step string pkgs []string @@ -79,7 +92,7 @@ func detectSteps(dir string, narrowedTree bool) ([]DetectedStep, error) { // stepsTool is the seat's verb `steps`. func (m *Module) stepsTool() stdio.Tool { return stdio.Tool{Name: Seat + "." + seat.VerbSteps, - Description: "Which pipeline steps a TypeScript artifact can run: the type-check as lint, always; unit tests where a package has a test script; " + + Description: "Which pipeline steps a TypeScript artifact can run: the type-check as lint, where one of its packages holds a TypeScript file; unit tests where a package has a test script; " + "integration tests where one has a test:integration script. A level with no test is not answered.", Input: map[string]any{"type": "object", "required": []string{"module", "artifact"}, "properties": map[string]any{ "module": map[string]any{"type": "string"}, diff --git a/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go b/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go index e9f687ef6..272e2ad12 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/steps_test.go @@ -10,8 +10,9 @@ import ( "testing" ) -// Design 47 G §22, §307, §328 (BLD7): steps answers the type-check as lint always, the packages with a test script as -// unit, those with test:integration as integration, and leaves out a level with none. +// Design 47 G §22, §307, §328 (BLD7): steps answers the type-check as lint where a package holds a TypeScript file (design 47 +// H2 H-A-515 second addendum: none for a tree with none, whose lint would end nothing to run), the packages with a test +// script as unit, those with test:integration as integration, and leaves out a level with none. func TestTheStepsOfATypeScriptArtifactAreFoundByItsScripts(t *testing.T) { put := func(dir, name, body string) { if err := os.MkdirAll(filepath.Join(dir), 0o755); err != nil { @@ -23,15 +24,18 @@ func TestTheStepsOfATypeScriptArtifactAreFoundByItsScripts(t *testing.T) { } for name, c := range map[string]struct { pkg string + noTS bool narrowed bool want []DetectedStep }{ - "both levels": {`{"scripts":{"test":"node t.js","test:integration":"node i.js"}}`, false, + "both levels": {`{"scripts":{"test":"node t.js","test:integration":"node i.js"}}`, false, false, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"."}}, {Step: "integration", Packages: []string{"."}}}}, - "unit only": {`{"scripts":{"test":"node t.js"}}`, false, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"."}}}}, - "no script": {`{"scripts":{}}`, false, []DetectedStep{{Step: "lint"}}}, + "unit only": {`{"scripts":{"test":"node t.js"}}`, false, false, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"."}}}}, + "no script": {`{"scripts":{}}`, false, false, []DetectedStep{{Step: "lint"}}}, + // No TypeScript file (only a declaration, as a generated package of JavaScript has): nothing to type-check, no lint. + "no TypeScript file": {`{"scripts":{}}`, true, false, []DetectedStep{}}, // A folder module's tree narrowed to ts/seats/a (H-A-136): the steps are those the narrowed levels run there. - "narrowed folder": {"", true, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"ts/seats/a"}}}}, + "narrowed folder": {"", false, true, []DetectedStep{{Step: "lint"}, {Step: "unit", Packages: []string{"ts/seats/a"}}}}, } { dir := t.TempDir() if c.narrowed { @@ -42,6 +46,12 @@ func TestTheStepsOfATypeScriptArtifactAreFoundByItsScripts(t *testing.T) { } } else { put(dir, "package.json", c.pkg) + if c.noTS { + put(dir, "index.d.ts", "export declare const v: number;\n") + put(dir, "index.js", "export const v = 1;\n") + } else { + put(dir, "index.ts", "export const v = 1;\n") + } } got, err := detectSteps(dir, c.narrowed) if err != nil || !reflect.DeepEqual(got, c.want) {