Skip to content

fix(ado-script): inline azure-devops-node-api to avoid missing ncc chunk#935

Merged
jamesadevine merged 1 commit into
mainfrom
fix/ado-script-static-azdev-import
Jun 9, 2026
Merged

fix(ado-script): inline azure-devops-node-api to avoid missing ncc chunk#935
jamesadevine merged 1 commit into
mainfrom
fix/ado-script-static-azdev-import

Conversation

@jamesadevine

Copy link
Copy Markdown
Collaborator

Summary

exec-context-pr-synth (and latently gate.js) crashed at runtime with:

[synth-pr] listActivePullRequestsBySourceRef failed: Cannot find module
'/tmp/ado-aw-scripts/ado-script/485.index.js' imported from
/tmp/ado-aw-scripts/ado-script/exec-context-pr-synth.js

Root cause

src/shared/auth.ts lazy-loaded azure-devops-node-api via
await import("azure-devops-node-api") to defer ~50–100 ms of module
evaluation on bypass paths. ncc 0.38 compiles dynamic import() into a
separate webpack chunk file (<id>.index.js) that lives alongside
the main bundle in .ado-build/<name>/. Each build:* script in
scripts/ado-script/package.json only copies index.js out to the flat
<name>.js layout that the release workflow ships as individual assets
(see src/compile/extensions/ado_script.rs's per-file download list),
so the chunk silently vanished. At runtime getWebApi() tried
n.e(485).then(n.t.bind(n, 3485, 23)) and Node could not resolve the
missing file.

gate.js had the same chunk-split, but most gate evaluations short-
circuit before touching getWebApi(), so the bug stayed dormant there
until exec-context-pr-synth exercised the ADO REST path on every run.

Fix

Replace the dynamic import with a static import * as azdev in
src/shared/auth.ts. ncc now inlines the SDK directly into every
bundle, so each script ships as a single self-contained file that
matches the flat release layout:

bundle dynamic chunks size
gate.js 0 1 127 kB
import.js 0 2 kB
exec-context-pr.js 0 8 kB
exec-context-pr-synth.js 0 1 145 kB

Updated the doc comment on auth.ts to record why the import is static
(linking the failure mode to the flat release layout) and dropped the
now-stale 30 s vitest timeout in auth.test.ts that compensated for
the first-call dynamic-import cost.

Note

No compiler/Rust changes — the broken artefacts only ship via a new
ado-aw release that bundles scripts/ado-script/*.js as release
assets. A release of ado-aw is required before pipelines pick up
the fix end-to-end.

Test plan

From scripts/ado-script/:

  • npm run typecheck — clean
  • npm test — 281/281 passing (34 test files)
  • npm run test:smoke — 6/6 passing
  • npm run build — all four bundles rebuilt; verified each contains
    zero n.e(<id>) dynamic chunk loads via a regex sweep over the
    emitted *.js files.

auth.ts lazy-loaded the SDK via `await import()`. ncc 0.38 splits dynamic imports into separate webpack chunk files (e.g. `485.index.js`) that the flat release layout in `scripts/ado-script/` does not ship, so at runtime `getWebApi()` failed with `Cannot find module .../485.index.js`. Use a static `import * as azdev` so ncc inlines the SDK into every bundle, making each script self-contained. Also fixes the same latent bug in gate.js.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamesadevine jamesadevine merged commit 7a568fa into main Jun 9, 2026
14 checks passed
@jamesadevine jamesadevine deleted the fix/ado-script-static-azdev-import branch June 9, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant