Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkgs/mcpx/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,10 @@ skipped launcher phases).
| `script.cwd` | enum | `caller` | client | no | `--script-cwd` | `MCPX_SCRIPT_CWD` | where a script runs: caller, script, config or workdir |
| `script.env` | list | *(empty)* | client | no | `--script-env`, `--env` | `MCPX_SCRIPT_ENV` | KEY=VALUE pairs added to the script's environment |
| `script.imports` | enum | `report` | client | no | `--script-imports` | `MCPX_SCRIPT_IMPORTS` | resolve the script's import graph before running it |
| `script.importsCrossProject` | enum | `isolate` | client | no | `--script-imports-cross-project` | `MCPX_SCRIPT_IMPORTS_CROSS_PROJECT` | how to handle a file edge into another project's manifest |
| `script.importsNetwork` | enum | `on` | client | no | `--script-imports-network` | `MCPX_SCRIPT_IMPORTS_NETWORK` | allow registry lookups when a package has no declared version |
| `script.importsOnDynamic` | enum | `warn` | client | no | `--script-imports-on-dynamic` | `MCPX_SCRIPT_IMPORTS_ON_DYNAMIC` | what to do about an import() whose specifier is computed |
| `script.importsOnMissing` | enum | `fail` | client | no | `--script-imports-on-missing` | `MCPX_SCRIPT_IMPORTS_ON_MISSING` | how to handle a package absent from the dependency set |
| `script.interpreter` | string | *(empty)* | client | no | `--script-interpreter`, `--interpreter`, `--shell` | `MCPX_SCRIPT_INTERPRETER` | command line that runs scripts instead of a JavaScript runtime |
| `script.launcher` | source | *(empty)* | client | no | `--script-launcher` | `MCPX_SCRIPT_LAUNCHER` | replace the generated launcher entirely |
| `script.onError` | source | *(empty)* | client | no | `--script-on-error` | `MCPX_SCRIPT_ON_ERROR` | runs when the script throws; the error still propagates |
Expand Down
9 changes: 9 additions & 0 deletions pkgs/mcpx/internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,9 @@ func (a *App) runScript(ctx context.Context, args []string, inline bool) error {
opts.TypeCheck = shape.typecheck
opts.Imports = shape.imports
opts.ImportsOnDynamic = shape.importsOnDynamic
opts.ImportsOnMissing = shape.importsOnMissing
opts.ImportsCrossProject = shape.importsCrossProject
opts.ImportsNetwork = shape.importsNetwork
opts.Launcher, opts.LauncherName = shape.launcher, shape.launcherName
opts.PlaceholderFiles = PlaceholderFiles()
opts.AllowRepeat = shape.allowRepeat
Expand Down Expand Up @@ -2311,6 +2314,9 @@ type scriptShape struct {
env map[string]string
typecheck string
imports, importsOnDynamic string
importsOnMissing string
importsCrossProject string
importsNetwork string
launcher, launcherName string
allowRepeat []string
captureConsole bool
Expand Down Expand Up @@ -2425,6 +2431,9 @@ func (a *App) resolveScriptShape(cfg *config.Config, f scriptFlags) (scriptShape
// the generated --script-imports flag, a variable, or the config file.
sh.imports = a.Settings().String("script.imports")
sh.importsOnDynamic = a.Settings().String("script.importsOnDynamic")
sh.importsOnMissing = a.Settings().String("script.importsOnMissing")
sh.importsCrossProject = a.Settings().String("script.importsCrossProject")
sh.importsNetwork = a.Settings().String("script.importsNetwork")

if f.noLauncher && f.launcher != "" {
return sh, errors.New("--launcher and --no-launcher contradict each other; " +
Expand Down
25 changes: 14 additions & 11 deletions pkgs/mcpx/internal/cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,17 +603,20 @@ func (a *App) execOnDaemon(ctx context.Context, c *Client, fs *flag.FlagSet, inl
Args: args,
Artifacts: eo.artifactOptions(cwd),

Export: rf.export,
DryRun: rf.dryRun,
Env: withInputReport(sh.env, a.stdoutOverride == nil),
TypeCheck: sh.typecheck,
Imports: sh.imports,
ImportsOnDynamic: sh.importsOnDynamic,
Launcher: sh.launcher,
LauncherName: sh.launcherName,
AllowRepeat: sh.allowRepeat,
CaptureConsole: &sh.captureConsole,
Deps: depsOpts,
Export: rf.export,
DryRun: rf.dryRun,
Env: withInputReport(sh.env, a.stdoutOverride == nil),
TypeCheck: sh.typecheck,
Imports: sh.imports,
ImportsOnDynamic: sh.importsOnDynamic,
ImportsOnMissing: sh.importsOnMissing,
ImportsCrossProject: sh.importsCrossProject,
ImportsNetwork: sh.importsNetwork,
Launcher: sh.launcher,
LauncherName: sh.launcherName,
AllowRepeat: sh.allowRepeat,
CaptureConsole: &sh.captureConsole,
Deps: depsOpts,
}
if len(phases.Before)+len(phases.Prefix)+len(phases.OnSuccess)+
len(phases.OnError)+len(phases.Suffix) > 0 {
Expand Down
3 changes: 3 additions & 0 deletions pkgs/mcpx/internal/daemon/routes_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func (s *Server) ExecService() *execsvc.Service {
lim.Typecheck = set.String("script.typecheck")
lim.Imports = set.String("script.imports")
lim.ImportsOnDynamic = set.String("script.importsOnDynamic")
lim.ImportsOnMissing = set.String("script.importsOnMissing")
lim.ImportsCrossProject = set.String("script.importsCrossProject")
lim.ImportsNetwork = set.String("script.importsNetwork")
lim.Delivery = set.String("artifacts.delivery")
lim.InlineMaxBytes = set.Bytes("artifacts.inlineMaxBytes")
lim.ChunkBytes = set.Bytes("artifacts.chunkBytes")
Expand Down
79 changes: 44 additions & 35 deletions pkgs/mcpx/internal/execsvc/execsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,13 @@ type Options struct {

// TypeCheck is off, on or strict; empty takes the daemon's default.
TypeCheck string `json:"typecheck,omitempty"`
// Imports is off or report; empty takes the daemon's default.
// Imports is off, report or prepare; empty takes the daemon's default.
Imports string `json:"imports,omitempty"`
// ImportsOnDynamic is warn, fail or ignore; empty takes the daemon's.
ImportsOnDynamic string `json:"importsOnDynamic,omitempty"`
ImportsOnDynamic string `json:"importsOnDynamic,omitempty"`
ImportsOnMissing string `json:"importsOnMissing,omitempty"`
ImportsCrossProject string `json:"importsCrossProject,omitempty"`
ImportsNetwork string `json:"importsNetwork,omitempty"`
// Launcher replaces the generated launcher with this template text;
// "none" runs the script with no launcher at all.
Launcher string `json:"launcher,omitempty"`
Expand Down Expand Up @@ -532,15 +535,18 @@ type Limits struct {
// Setup holds declared runtimes, the auto order and user profiles.
Setup runner.Setup
// SetupErr is why Setup could not be read; every run reports it.
SetupErr error
CaptureConsole bool
Typecheck string
Imports string
ImportsOnDynamic string
Delivery string
InlineMaxBytes int64
ChunkBytes int64
InterceptImages bool
SetupErr error
CaptureConsole bool
Typecheck string
Imports string
ImportsOnDynamic string
ImportsOnMissing string
ImportsCrossProject string
ImportsNetwork string
Delivery string
InlineMaxBytes int64
ChunkBytes int64
InterceptImages bool
// StdoutLimit caps the stdout a Result returns (bytes); <= 0 is no cap.
StdoutLimit int64
}
Expand Down Expand Up @@ -697,30 +703,33 @@ func (s *Service) Run(ctx context.Context, req Request, sink Sink) (*Result, err
capture = *opts.CaptureConsole
}
ropts := runner.Options{
Source: req.Source,
File: req.File,
ClientSource: clientSrc,
GlobalsSource: globals,
Clients: clients,
WorkDir: s.WorkDir,
WorkRoot: s.WorkRoot,
Runtime: firstNonEmpty(opts.Runtime, s.Limits.Runtime),
Interpreter: firstNonEmpty(opts.Interpreter, s.Limits.Interpreter),
CwdPolicy: firstNonEmpty(opts.CwdPolicy, s.Limits.CwdPolicy),
ConfigDir: s.ConfigDir,
Setup: s.Limits.Setup,
Timeout: timeout,
Permissions: firstNonEmpty(opts.Permissions, s.Limits.Permissions),
CaptureConsole: capture,
TypeCheck: firstNonEmpty(opts.TypeCheck, s.Limits.Typecheck),
Imports: firstNonEmpty(opts.Imports, s.Limits.Imports),
ImportsOnDynamic: firstNonEmpty(opts.ImportsOnDynamic, s.Limits.ImportsOnDynamic),
Launcher: opts.Launcher,
LauncherName: opts.LauncherName,
AllowRepeat: opts.AllowRepeat,
Export: opts.Export,
Args: opts.Args,
Dir: opts.Cwd,
Source: req.Source,
File: req.File,
ClientSource: clientSrc,
GlobalsSource: globals,
Clients: clients,
WorkDir: s.WorkDir,
WorkRoot: s.WorkRoot,
Runtime: firstNonEmpty(opts.Runtime, s.Limits.Runtime),
Interpreter: firstNonEmpty(opts.Interpreter, s.Limits.Interpreter),
CwdPolicy: firstNonEmpty(opts.CwdPolicy, s.Limits.CwdPolicy),
ConfigDir: s.ConfigDir,
Setup: s.Limits.Setup,
Timeout: timeout,
Permissions: firstNonEmpty(opts.Permissions, s.Limits.Permissions),
CaptureConsole: capture,
TypeCheck: firstNonEmpty(opts.TypeCheck, s.Limits.Typecheck),
Imports: firstNonEmpty(opts.Imports, s.Limits.Imports),
ImportsOnDynamic: firstNonEmpty(opts.ImportsOnDynamic, s.Limits.ImportsOnDynamic),
ImportsOnMissing: firstNonEmpty(opts.ImportsOnMissing, s.Limits.ImportsOnMissing),
ImportsCrossProject: firstNonEmpty(opts.ImportsCrossProject, s.Limits.ImportsCrossProject),
ImportsNetwork: firstNonEmpty(opts.ImportsNetwork, s.Limits.ImportsNetwork),
Launcher: opts.Launcher,
LauncherName: opts.LauncherName,
AllowRepeat: opts.AllowRepeat,
Export: opts.Export,
Args: opts.Args,
Dir: opts.Cwd,
// Explicitly not the daemon's standard input. A script run on
// somebody else's behalf reading the daemon's stdin would be reading
// whatever started the daemon.
Expand Down
42 changes: 40 additions & 2 deletions pkgs/mcpx/internal/preflight/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type ImportsMode string
const (
ImportsOff ImportsMode = "off"
ImportsReport ImportsMode = "report"
// ImportsPrepare requests resolution for a future materialisation step.
// Resolve can build the dependency set, but this stage never installs it.
ImportsPrepare ImportsMode = "prepare"
)

// DynamicImportMode selects what a computed dynamic import does.
Expand Down Expand Up @@ -138,6 +141,12 @@ type denoPos struct {

// Graph is the parsed result of one `deno info --json` run.
type Graph struct {
// Roots are the entry modules supplied to deno info.
Roots []string
// Edges retains resolved edges as well as Missing. Resolve needs the
// successful file edges to find project boundaries; the graph report
// alone used to discard precisely that information.
Edges []ImportEdge
// Missing is every unresolved edge, in source order by importer.
Missing []MissingSpecifier
// LocalFiles is every module deno read from disk; these are the files
Expand All @@ -156,6 +165,9 @@ func ParseGraph(data []byte) (*Graph, error) {
return nil, fmt.Errorf("parse deno info output: %w", err)
}
g := &Graph{}
for _, root := range info.Roots {
g.Roots = append(g.Roots, fileURLToPath(root))
}
broken := map[string]string{}
for _, m := range info.Modules {
if m.Error != "" {
Expand All @@ -182,7 +194,7 @@ func ParseGraph(data []byte) (*Graph, error) {
continue
}
for _, d := range m.Dependencies {
for _, edge := range []*denoEdge{d.Code, d.Type} {
for edgeIndex, edge := range []*denoEdge{d.Code, d.Type} {
if edge == nil {
continue
}
Expand All @@ -201,6 +213,22 @@ func ParseGraph(data []byte) (*Graph, error) {
})
continue
}
// Preserve resolved module edges for stage 2. Type-only
// edges are distinguished so a later prepare stage can
// decide whether they belong in the runtime environment.
if edge.Specifier != "" {
g.Edges = append(g.Edges, ImportEdge{
From: fileURLToPath(m.Specifier),
Specifier: d.Specifier,
Resolved: fileURLToPath(edge.Specifier),
Span: &SourceSpan{
Path: fileURLToPath(m.Specifier),
Line: edge.Span.Start.Line + 1,
Character: edge.Span.Start.Character + 1,
},
TypeOnly: edgeIndex == 1,
})
}
errText, isBroken := broken[edge.Specifier]
if !isBroken {
continue
Expand Down Expand Up @@ -362,7 +390,7 @@ func CheckImports(ctx context.Context, denoBin, entry string, mode ImportsMode,
// script runs under, and report a valid import as missing (Codex
// review, PR #2575). An empty execDir inherits the caller's working
// directory, which is exactly what the execution does.
func CheckImportsResolved(ctx context.Context, denoBin, entry string, mode ImportsMode, dynamicMode DynamicImportMode, timeout time.Duration, runtimeArgs []string, execDir string) *Report {
func CheckImportsResolved(ctx context.Context, denoBin, entry string, mode ImportsMode, dynamicMode DynamicImportMode, timeout time.Duration, runtimeArgs []string, execDir string, resolve ...ResolveOptions) *Report {
r := &Report{}
if mode == ImportsOff || mode == "" {
return r
Expand Down Expand Up @@ -432,6 +460,16 @@ func CheckImportsResolved(ctx context.Context, denoBin, entry string, mode Impor
}
dynamics = append(dynamics, ScanDynamicImports(f, string(b))...)
}
if len(resolve) > 0 {
_, report := ResolveGraph(cctx, g, resolve[0], dynamics, dynamicMode)
if mode == ImportsPrepare {
report.Add(Problem{
What: "the dependency set was resolved, but materialising it is stage 3 and is not part of this build",
Where: "script.imports",
})
}
return report
}
return ReportGraph(g, dynamics, dynamicMode)
}

Expand Down
3 changes: 3 additions & 0 deletions pkgs/mcpx/internal/preflight/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func TestParseGraphFindsEveryMissingSpecifier(t *testing.T) {
if len(g.LocalFiles) != 2 {
t.Errorf("local files for the dynamic scan: %v", g.LocalFiles)
}
if len(g.Edges) != 3 || g.Edges[1].Resolved != "/work/present.ts" {
t.Errorf("resolved file edges must be retained for Resolve: %+v", g.Edges)
}
}

func TestReportGraphReportsAllMissingInOnePass(t *testing.T) {
Expand Down
Loading