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

Commit

Permalink
fix: check pkg main (#797)
Browse files Browse the repository at this point in the history
* fix: check pkg main

* fix: load entry if present

* refactor: assert base filepath before loading entry

* fix: don't append js to fully relative path
  • Loading branch information
calebboyd authored and nchanged committed Sep 16, 2017
1 parent 7810aba commit 3c219de
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
12 changes: 4 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,8 @@ gulp.task("installDevDeps", function(done) {
"buble",
];

if (os.platform().match(/^win/)) {
let windowsCommands = ["start", "cmd.exe", "/K", "npm", "install", "--no-save", ...deps];
exec(windowsCommands.join(" "), () => {})
} else {
var installDeps = spawn("npm", ["install", "--no-save"].concat(deps), {
stdio: "inherit",
});
}
const ext = /^win/.test(os.platform()) ? ".cmd" : ""
spawn("npm" + ext, ["install", "--no-save"].concat(deps), {
stdio: "inherit",
});
});
3 changes: 3 additions & 0 deletions modules/fuse-box-loader-api/fusebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ function $getRef(name, o) {
if (!file && !wildcard) {
validPath = $pathJoin(filePath, "/", "index.js");
file = pkg.f[validPath];
if (!file && filePath === ".") {
file = pkg.f[pkg.s && pkg.s.entry];
}
if (!file) {
validPath = filePath + ".js";
file = pkg.f[validPath];
Expand Down
2 changes: 1 addition & 1 deletion modules/fuse-box-loader-api/fusebox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/BundleSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class BundleSource {
* @memberOf BundleSource
*/
public includeSourceMaps: boolean = false;

public bundleInfoObject: any;

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ export class BundleSource {
*/
public endCollection(collection: ModuleCollection) {
let entry = collection.entryFile ? collection.entryFile.info.fuseBoxPath : "";

entry = entry || collection.bundle && collection.bundle.entry
if (entry) {
this.collectionSource.add(null, `return ___scope___.entry = "${entry}";`);
}
Expand Down
28 changes: 15 additions & 13 deletions src/core/PathMaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { BundleData } from "../arithmetic/Arithmetic";
* and only has ascii + @ in the name it is considered a node module
*/
const NODE_MODULE = /^([a-z@](?!:).*)$/;
const isRelative = /^[\.\/\\]+$/
const jsExtensions = ['js', 'jsx'];
const tsExtensions = jsExtensions.concat(['ts', 'tsx']);

export interface INodeModuleRequire {
name: string;
Expand Down Expand Up @@ -225,21 +228,20 @@ export class PathMaster {
}

private testFolder(folder: string, name: string) {
const extensions = ["js", "jsx"];
let extensions = jsExtensions;
if (this.tsMode) {
extensions.push("ts", "tsx");
extensions = tsExtensions
}

if (fs.existsSync(folder)) {
for (let i = 0; i < extensions.length; i++) {
let ext = extensions[i];
const index = `index.${ext}`;
const target = path.join(folder, index);
if (fs.existsSync(target)) {
let result = path.join(name, index);
let startsWithDot = result[0] === "."; // After transformation we need to bring the dot back
if (startsWithDot) {
result = `./${result}`;
const index = "index." + extensions[i]
if (fs.existsSync(path.join(folder, index))) {
const result = path.join(name, index);
const [a, b] = name
if (a === "." && b !== ".") {
//add relative './' from `name`, back onto joined path
return "./" + result;
}
return result;
}
Expand All @@ -248,9 +250,9 @@ export class PathMaster {
}

private checkFileName(root: string, name: string) {
const extensions = ["js", "jsx"];
let extensions = jsExtensions;
if (this.tsMode) {
extensions.push("ts", "tsx");
extensions = tsExtensions;
}
for (let i = 0; i < extensions.length; i++) {
let ext = extensions[i];
Expand All @@ -267,7 +269,7 @@ export class PathMaster {

private ensureNodeModuleExtension(input: string) {
let ext = path.extname(input);
if (!ext) {
if (!ext && !isRelative.test(input)) {
return input + ".js";
}
return input;
Expand Down
6 changes: 5 additions & 1 deletion src/loader/LoaderAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,13 @@ function $getRef(name: string, o: RefOpts): IReference {
wildcard = validPath;
}
if (!file && !wildcard) {
// try folder index.js
// try index.js
validPath = $pathJoin(filePath, "/", "index.js");
file = pkg.f[validPath];

if (!file && filePath === ".") {
file = pkg.f[pkg.s && pkg.s.entry];
}
// last resort try adding .js extension
// Some libraries have a weired convention of naming file lile "foo.bar""
if (!file) {
Expand Down

0 comments on commit 3c219de

Please sign in to comment.