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

Commit

Permalink
feat: added support for arrays in modulesFolder (#1293)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz authored and nchanged committed Jun 18, 2018
1 parent 1f34eb0 commit 73e2f73
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 2 additions & 0 deletions docs/development/configuration.md
Expand Up @@ -142,6 +142,8 @@ FuseBox.init({
})
```

Optionally, modulesFolder can be an array of paths. In that case the module will be searched for in priority order, this is, from the first array item to last.


You local `npm` will have the highest priority. In essence, you can override fusebox's [path](https://github.com/fuse-box/fuse-box/blob/master/modules/path/index.js) of [fs](https://github.com/fuse-box/fuse-box/blob/master/modules/fs/index.js) module if you like. Customize you packages in your own manner!

Expand Down
15 changes: 11 additions & 4 deletions src/core/FuseBox.ts
Expand Up @@ -22,7 +22,7 @@ const appRoot = require("app-root-path");

export interface FuseBoxOptions {
homeDir?: string;
modulesFolder?: string;
modulesFolder?: string | string[];
tsConfig?: string;
package?: string | { name: string, main: string };
dynamicImportsEnabled?: boolean;
Expand Down Expand Up @@ -184,9 +184,16 @@ export class FuseBox {

this.context.debugMode = opts.debug !== undefined ? opts.debug : contains(process.argv, "--debug");

if (opts.modulesFolder) {
this.context.customModulesFolder =
ensureUserPath(opts.modulesFolder);
let modulesFolders = opts.modulesFolder;
if (modulesFolders) {
if (!Array.isArray(modulesFolders)) {
modulesFolders = [modulesFolders];
}
modulesFolders = modulesFolders.map((folder) => ensureUserPath(folder));
this.context.customModulesFolder = modulesFolders;
}
else {
this.context.customModulesFolder = [];
}

if (opts.sourceMaps) {
Expand Down
17 changes: 9 additions & 8 deletions src/core/PathMaster.ts
Expand Up @@ -140,7 +140,7 @@ export class PathMaster {
// nodeModuleInfo.browserOverrides[name] = info.name + "/" + absPath.alias;
if (parent) {
parent.analysis.
replaceAliases(new Set([{from : name, to : info.name + "/" + absPath.alias }]))
replaceAliases(new Set([{ from: name, to: info.name + "/" + absPath.alias }]))
}
data.fuseBoxAlias = absPath.alias;
}
Expand All @@ -166,7 +166,7 @@ export class PathMaster {
data.fuseBoxAlias = absPath.alias;
if (parent) {
parent.analysis.
replaceAliases(new Set([{from : name, to : `~/` + absPath.alias }]))
replaceAliases(new Set([{ from: name, to: `~/` + absPath.alias }]))
}
}
data.absPath = absPath.resolved;
Expand Down Expand Up @@ -495,12 +495,13 @@ export class PathMaster {
}
}


if (this.context.customModulesFolder) {

let customFolder = path.join(this.context.customModulesFolder, name);
if (fs.existsSync(customFolder)) {
return readMainFile(customFolder, false);
const customModulesFolder = this.context.customModulesFolder;
if (customModulesFolder) {
for (const customModulesFolderItem of customModulesFolder) {
const customFolder = path.join(customModulesFolderItem, name);
if (fs.existsSync(customFolder)) {
return readMainFile(customFolder, false);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/WorkflowContext.ts
Expand Up @@ -130,7 +130,7 @@ export class WorkFlowContext {

public target: string = "universal";

public inlineCSSPath : string = "css-sourcemaps";
public inlineCSSPath: string = "css-sourcemaps";
/**
* Explicitly target bundle to server
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ export class WorkFlowContext {

public tsConfig: TypescriptConfig;

public customModulesFolder: string;
public customModulesFolder: string[];

public tsMode = false;

Expand Down Expand Up @@ -335,7 +335,7 @@ export class WorkFlowContext {
this.sourceMapsProject = params;
} else {
if (utils.isPlainObject(params)) {
if( params.inlineCSSPath){
if (params.inlineCSSPath) {
this.inlineCSSPath = params.inlineCSSPath;
}
this.sourceMapsProject = params.project !== undefined ? params.project : true;
Expand Down

0 comments on commit 73e2f73

Please sign in to comment.