Skip to content

Commit

Permalink
Preserve import load order
Browse files Browse the repository at this point in the history
  • Loading branch information
znewsham committed Apr 18, 2024
1 parent fd3cd87 commit 05c1a93
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,24 @@ export default class Runtime {
}

if (module.status === 'unlinked') {
// ensure that every import fully evaluates before any siblings are allowed to import.
let linkPromiseChain = Promise.resolve();
// since we might attempt to link the same module in parallel, stick the promise in a weak map so every call to
// this method can await it
this._esmModuleLinkingMap.set(
module,
module.link((specifier: string, referencingModule: VMModule) =>
this.resolveModule(
specifier,
referencingModule.identifier,
referencingModule.context,
),
),
module.link((specifier: string, referencingModule: VMModule) => {
linkPromiseChain = linkPromiseChain.then(async () => {

Check failure on line 768 in packages/jest-runtime/src/index.ts

View workflow job for this annotation

GitHub Actions / Typecheck Examples and Tests

Type 'Promise<unknown>' is not assignable to type 'Promise<void>'.

Check failure on line 768 in packages/jest-runtime/src/index.ts

View workflow job for this annotation

GitHub Actions / TypeScript Compatibility

Type 'Promise<unknown>' is not assignable to type 'Promise<void>'.
const mod = await this.resolveModule(
specifier,
referencingModule.identifier,
referencingModule.context

Check failure on line 772 in packages/jest-runtime/src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert `,`
);
await this.linkAndEvaluateModule(mod);
return mod;
});
return linkPromiseChain;
}),
);
}

Expand Down

0 comments on commit 05c1a93

Please sign in to comment.