mesh-build-node: emit a package that builds before its tests, so tests importing its own output find it (issue 1869, part of issue 1309's run step)
A package with a build or prepare script and a tsconfig.json is built with tsc -p . in the shut-off run step, at both levels, instead of the --noEmit type-check; the fetch's --ignore-scripts never runs those scripts. mesh-sdk's tests import ../dist and failed ERR_MODULE_NOT_FOUND. The result names the step build.
This commit is contained in:
@@ -138,13 +138,20 @@ func (m *Module) test(ctx context.Context, args map[string]any) (any, error) {
|
||||
return nil
|
||||
}
|
||||
if len(sources) > 0 {
|
||||
// A package that builds (a build or prepare script, which the fetch's --ignore-scripts never runs) is emitted
|
||||
// by tsc into the workspace, shut off like every run step, so its tests find what they import of its own output
|
||||
// (issue 1869: mesh-sdk's tests import ../dist); any other is type-checked without emitting.
|
||||
name, line := "type-check", m.typeCheck(dir, sources)
|
||||
if emit := m.emitBuild(dir, scripts); emit != nil {
|
||||
name, line = "build", emit
|
||||
}
|
||||
start := m.now()
|
||||
r := m.runIn(ctx, root, false, dir, nil, "node", m.typeCheck(dir, sources)...)
|
||||
r := m.runIn(ctx, root, false, dir, nil, "node", line...)
|
||||
check = m.now().Sub(start)
|
||||
if err := ran("type-check", r); err != nil {
|
||||
if err := ran(name, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.Ran = append(res.Ran, "type-check")
|
||||
res.Ran = append(res.Ran, name)
|
||||
}
|
||||
if hasScript && len(failed) == 0 {
|
||||
start := m.now()
|
||||
@@ -220,6 +227,18 @@ func (m *Module) typeCheck(dir string, sources []string) []string {
|
||||
"--target", "ES2022", "--rootDir", "."}, sources...)
|
||||
}
|
||||
|
||||
// emitBuild is tsc's line that builds a package as its tsconfig.json says (`tsc -p .`, emitting where it says), when the
|
||||
// package builds (a build or prepare script) and has a tsconfig.json; nil otherwise.
|
||||
func (m *Module) emitBuild(dir string, scripts map[string]string) []string {
|
||||
if scripts["build"] == "" && scripts["prepare"] == "" {
|
||||
return nil
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "tsconfig.json")); err != nil {
|
||||
return nil
|
||||
}
|
||||
return []string{m.tsc(), "-p", "."}
|
||||
}
|
||||
|
||||
// packageScripts are the scripts of the package.json in dir (none without one).
|
||||
func packageScripts(dir string) (map[string]string, error) {
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "package.json"))
|
||||
|
||||
Reference in New Issue
Block a user