Skip to content

Commit a8bea25

Browse files
committed
Allow to require module path from whitelisted dependency
Required module path can be one of - `fs` (built-in Node.js module), - `abortcontroller-polyfill` (external main module), - `abortcontroller-polyfill/dist/cjs-ponyfill` (external submodule). FastBoot's build system requires only dependency whitelisting, thus looking only for the first part of module path.
1 parent e5c777d commit a8bea25

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"chalk": "^2.0.1",
3030
"cookie": "^0.3.1",
3131
"debug": "^3.0.0",
32-
"exists-sync": "0.0.4",
3332
"najax": "^1.0.2",
33+
"resolve": "^1.8.1",
3434
"rsvp": "^4.7.0",
3535
"simple-dom": "^1.0.0",
3636
"source-map-support": "^0.5.0"

src/ember-app.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const chalk = require('chalk');
66

77
const najax = require('najax');
88
const SimpleDOM = require('simple-dom');
9-
const existsSync = require('exists-sync');
9+
const resolve = require('resolve');
1010
const debug = require('debug')('fastboot:ember-app');
1111

1212
const FastBootInfo = require('./fastboot-info');
@@ -119,16 +119,12 @@ class EmberApp {
119119
debug("module whitelisted; module=%s", whitelistedModule);
120120
});
121121

122-
return function(moduleName) {
123-
if (whitelist.indexOf(moduleName) > -1) {
124-
let nodeModulesPath = path.join(distPath, 'node_modules', moduleName);
122+
return function(modulePath) {
123+
let moduleName = modulePath.split('/')[0];
125124

126-
if (existsSync(nodeModulesPath)) {
127-
return require(nodeModulesPath);
128-
} else {
129-
// If it's not on disk, assume it's a built-in node package
130-
return require(moduleName);
131-
}
125+
if (whitelist.indexOf(moduleName) > -1) {
126+
let nodeModulesPath = resolve.sync(modulePath, { basedir: distPath });
127+
return require(nodeModulesPath);
132128
} else {
133129
throw new Error("Unable to require module '" + moduleName + "' because it was not in the whitelist.");
134130
}

test/fixtures/custom-sandbox/custom-sandbox.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const vm = require('vm');
44
const fs = require('fs');
5-
const existsSync = require('exists-sync');
65
const Sandbox = require('./../../../src/sandbox');
76

87
/**

0 commit comments

Comments
 (0)