Skip to content

Commit

Permalink
fix: ensure virtual file paths are resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 9, 2023
1 parent f3d7933 commit 417708e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/transform/create-transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import path from "path";
import mergeMaps from "merge-source-map";
import ConcatMap from "concat-with-sourcemaps";
import type { Transformer } from "@jest/transform";
Expand Down Expand Up @@ -95,7 +96,11 @@ export default ({ browser }: { browser: boolean }) => {
for (let dep of deps) {
if (typeof dep !== "string") {
if (dep.virtualPath) {
const acceptedMatch = acceptPathReg.exec(dep.virtualPath);
const resolvedVirtualPath = path.resolve(
filename,
dep.virtualPath
);
const acceptedMatch = acceptPathReg.exec(resolvedVirtualPath);
let depCode = dep.code;
let depMap = dep.map;

Expand All @@ -116,7 +121,7 @@ export default ({ browser }: { browser: boolean }) => {
)
: nestedTransformerModule;
const transformResult = nestedTransformer.process
? nestedTransformer.process(depCode, dep.virtualPath, {
? nestedTransformer.process(depCode, resolvedVirtualPath, {
...transformOptions,
...nestedTransformerOpts,
})
Expand All @@ -135,7 +140,7 @@ export default ({ browser }: { browser: boolean }) => {
}

concatMap.add(null, `\n;((module, exports) => {`);
concatMap.add(dep.virtualPath, depCode, depMap);
concatMap.add(resolvedVirtualPath, depCode, depMap);
concatMap.add(null, `\n})({ exports: {} })`);
continue;
} else {
Expand Down

0 comments on commit 417708e

Please sign in to comment.