8000 feat: added support for arrays in modulesFolder (#1293) · fuse-box/fuse-box@73e2f73 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 73e2f73

Browse files
xaviergonznchanged
authored andcommitted
feat: added support for arrays in modulesFolder (#1293)
1 parent 1f34eb0 commit 73e2f73

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

docs/development/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ FuseBox.init({
142142
})
143143
```
144144

145+
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.
146+
145147

146148
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!
147149

src/core/FuseBox.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const appRoot = require("app-root-path");
2222

2323
export interface FuseBoxOptions {
2424
homeDir?: string;
25-
modulesFolder?: string;
25+
modulesFolder?: string | string[];
2626
tsConfig?: string;
2727
package?: string | { name: string, main: string };
2828
dynamicImportsEnabled?: boolean;
@@ -184,9 +184,16 @@ export class FuseBox {
184184

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

187-
if (opts.modulesFolder) {
188-
this.context.customModulesFolder =
189-
ensureUserPath(opts.modulesFolder);
187+
let modulesFolders = opts.modulesFolder;
188+
if (modulesFolders) {
189+
if (!Array.isArray(modulesFolders)) {
190+
modulesFolders = [modulesFolders];
191+
}
192+
modulesFolders = modulesFolders.map((folder) => ensureUserPath(folder));
193+
this.context.customModulesFolder = modulesFolders;
194+
}
195+
else {
196+
this.context.customModulesFolder = [];
190197
}
191198

192199
if (opts.sourceMaps) {

src/core/PathMaster.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class PathMaster {
140140
// nodeModuleInfo.browserOverrides[name] = info.name + "/" + absPath.alias;
141141
if (parent) {
142142
parent.analysis.
143-
replaceAliases(new Set([{from : name, to : info.name + "/" + absPath.alias }]))
143+
replaceAliases(new Set([{ from: name, to: info.name + "/" + absPath.alias }]))
144144
}
145145
data.fuseBoxAlias = absPath.alias;
146146
}
@@ -166,7 +166,7 @@ export class PathMaster {
166166
data.fuseBoxAlias = absPath.alias;
167167
if (parent) {
168168
parent.analysis.
169-
replaceAliases(new Set([{from : name, to : `~/` + absPath.alias }]))
169+
replaceAliases(new Set([{ from: name, to: `~/` + absPath.alias }]))
170170
}
171171
}
172172
data.absPath = absPath.resolved;
@@ -495,12 +495,13 @@ export class PathMaster {
495495
}
496496
}
497497

498-
499-
if (this.context.customModulesFolder) {
500-
501-
let customFolder = path.join(this.context.customModulesFolder, name);
502-
if (fs.existsSync(customFolder)) {
503-
return readMainFile(customFolder, false);
498+
const customModulesFolder = this.context.customModulesFolder;
499+
if (customModulesFolder) {
500+
for (const customModulesFolderItem of customModulesFolder) {
501+
const customFolder = path.join(customModulesFolderItem, name);
502+
if (fs.existsSync(customFolder)) {
503+
return readMainFile(customFolder, false);
504+
}
504505
}
505506
}
506507

src/core/WorkflowContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class WorkFlowContext {
130130

131131
public target: string = "universal";
132132

133-
public inlineCSSPath : string = "css-sourcemaps";
133+
public inlineCSSPath: string = "css-sourcemaps";
134134
/**
135135
* Explicitly target bundle to server
136136
*/
@@ -158,7 +158,7 @@ export class WorkFlowContext {
158158

159159
public tsConfig: TypescriptConfig;
160160

161-
public customModulesFolder: string;
161+
public customModulesFolder: string[];
162162

163163
public tsMode = false;
164164

@@ -335,7 +335,7 @@ export class WorkFlowContext {
335335
this.sourceMapsProject = params;
336336
} else {
337337
if (utils.isPlainObject(params)) {
338-
if( params.inlineCSSPath){
338+
if (params.inlineCSSPath) {
339339
this.inlineCSSPath = params.inlineCSSPath;
340340
}
341341
this.sourceMapsProject = params.project !== undefined ? params.project : true;

0 commit comments

Comments
 (0)
0