Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: support npm workspaces #74

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 25 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,28 @@ function makeOutputOptions(options: Options): OutputOptions {
return { sourceMaps, compression };
}

function nodeModulesDir(initialRoot: string, system: ts.System) {
function parentDir(path: string) {
const parentDir = crosspath.join(path, "..");
if (crosspath.normalize(parentDir) !== crosspath.normalize(path)) {
return parentDir;
} else {
return undefined;
}
}

for (let root: string | undefined = initialRoot; root !== undefined; root = parentDir(root)) {
const path = crosspath.join(root, "node_modules");
if (system.directoryExists(path)) {
return path;
}
}

throw new Error(`Unable to locate node_modules for ${initialRoot}`);
}

export function queryDefaultAssets(projectRoot: string, sys: ts.System): Assets {
const projectNodeModulesDir = crosspath.join(crosspath.ensurePosix(projectRoot), "node_modules");
const projectNodeModulesDir = nodeModulesDir(projectRoot, sys);
const compilerNodeModulesDir = crosspath.join(compilerRoot, "node_modules");
let shimDir: string;
if (sys.directoryExists(crosspath.join(compilerNodeModulesDir, "@frida"))) {
Expand Down Expand Up @@ -422,6 +442,10 @@ function createBundler(entrypoint: EntrypointName, projectRoot: string, assets:
return path.substring(projectRoot.length);
}

if (path.includes("/node_modules/")) {
return path.substring(path.indexOf("/node_modules/"));
}

throw new Error(`unexpected file path: ${path}`);
}

Expand Down