Skip to content

Commit

Permalink
compiler: Support usage separate from project root
Browse files Browse the repository at this point in the history
E.g. where the project root is “/prj” while the compiler resides in
“/prj/test/node_modules”.

This is useful in projects where the test-suite has its own package.json
only used for building a bundled version for the test-suite itself.

Co-authored-by: Håvard Sørbø <havard@hsorbo.no>
  • Loading branch information
oleavr and hsorbo committed Feb 13, 2023
1 parent 20d1f22 commit 97a2e88
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,20 @@ function makeOutputOptions(options: Options): OutputOptions {
export function queryDefaultAssets(projectRoot: string, sys: ts.System): Assets {
const projectNodeModulesDir = crosspath.join(crosspath.ensurePosix(projectRoot), "node_modules");
const compilerNodeModulesDir = crosspath.join(compilerRoot, "node_modules");
const shimDir = sys.directoryExists(crosspath.join(compilerNodeModulesDir, "@frida"))
? compilerNodeModulesDir
: projectNodeModulesDir;
let shimDir: string;
if (sys.directoryExists(crosspath.join(compilerNodeModulesDir, "@frida"))) {
shimDir = compilerNodeModulesDir;
} else if (sys.directoryExists(crosspath.join(projectNodeModulesDir, "@frida"))) {
shimDir = projectNodeModulesDir;
} else {
const compilerParent = crosspath.dirname(compilerRoot);
if (crosspath.basename(compilerParent) === "node_modules" &&
sys.directoryExists(crosspath.join(compilerParent, "@frida"))) {
shimDir = compilerParent;
} else {
throw new Error("Unable to detect shim directory; please file a bug");
}
}

const shims = new Map([
["assert", crosspath.join(shimDir, "@frida", "assert")],
Expand Down Expand Up @@ -687,8 +698,11 @@ function resolveModuleReference(ref: ModuleReference, assets: Assets, system: ts
needsAlias = true;
} else {
const linkedCompilerRoot = crosspath.join(assets.projectNodeModulesDir, "frida-compile");
if (requesterPath.startsWith(compilerRoot) || requesterPath.startsWith(linkedCompilerRoot)) {
modPath = crosspath.join(assets.shimDir, ...tokens);
const {shimDir} = assets;
if (requesterPath.startsWith(compilerRoot) ||
requesterPath.startsWith(linkedCompilerRoot) ||
requesterPath.startsWith(shimDir)) {
modPath = crosspath.join(shimDir, ...tokens);
} else {
modPath = crosspath.join(assets.projectNodeModulesDir, ...tokens);
}
Expand Down

0 comments on commit 97a2e88

Please sign in to comment.