Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
fix: quantum relative package requires (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebboyd authored and nchanged committed Sep 16, 2017
1 parent b8b9c69 commit aa11433
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function ensureAbsolutePath(userPath: string) {
return userPath;
}
export function joinFuseBoxPath(...any): string {
return ensureFuseBoxPath(path.join.apply(path, arguments));
return ensureFuseBoxPath(path.join(...any));
}
export function ensureDir(userPath: string) {
if (!path.isAbsolute(userPath)) {
Expand Down Expand Up @@ -220,7 +220,7 @@ export function extractExtension(str: string) {
return result[1];
}
export function ensureFuseBoxPath(input: string) {
return input.replace(/\\/g, "/");
return input.replace(/\\/g, "/").replace(/\/$/, "");
}

export function transpileToEs5(contents: string) {
Expand Down
49 changes: 21 additions & 28 deletions src/quantum/core/ProducerAbstraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BundleAbstraction } from "./BundleAbstraction";
import { generateFileCombinations } from "./utils";
import { ProducerWarning } from "./ProducerWarning";
import { QuantumCore } from "../plugin/QuantumCore";
import { FileAbstraction } from "./FileAbstraction";

export interface ProducerAbtractionOptions {
customComputedStatementPaths?: Set<RegExp>;
Expand Down Expand Up @@ -32,38 +33,30 @@ export class ProducerAbstraction {
}


public findFileAbstraction(packageName: string, resolvedPathRaw: string) {
public findFileAbstraction(packageName: string, resolvedPathRaw: string): FileAbstraction | undefined {
let combinations: string[] = generateFileCombinations(resolvedPathRaw);

let requiredFileAbstraction;
this.bundleAbstractions.forEach(bundle => {
if (requiredFileAbstraction) { return; };
for (const [, bundle] of this.bundleAbstractions) {
if (!bundle.packageAbstractions.has(packageName)) { continue; }
const pkg = bundle.packageAbstractions.get(packageName)
const entryFile = pkg.entryFile;
// if no combinations
// means we are dealing with external package require
// or requiring a package.json dir relatively
// like require("foo") or require('../../') from "foo/a/b"
if (!combinations) {
combinations = generateFileCombinations(entryFile);
}

const pkg = bundle.packageAbstractions.get(packageName);
if (pkg) {
const entryFile = pkg.entryFile;
// if no combinations
// which means we are dealing with external package require
// like require("foo")
if (!combinations) {
combinations = generateFileCombinations(entryFile);
for(const combination of combinations) {
for (const [, file] of pkg.fileAbstractions) {
const found = file.fuseBoxPath === combination
//console.log(found, combination);
if (found) {
return file
}
}

combinations.some(combination => {
let found;
pkg.fileAbstractions.forEach(file => {
if (requiredFileAbstraction) { return; };
found = file.fuseBoxPath === combination;
//console.log(found, combination);
if (found) {
requiredFileAbstraction = file;
}
});
return found;
});

}
});
return requiredFileAbstraction;
}
}
}
2 changes: 1 addition & 1 deletion src/quantum/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path";
import { joinFuseBoxPath } from "../../Utils";

export function generateFileCombinations(input: string): string[] {
if (!input) {
if (!input || input === ".") {
return undefined;
}
let ext = path.extname(input);
Expand Down

0 comments on commit aa11433

Please sign in to comment.