Skip to content

Commit

Permalink
Allow to require module path from whitelisted dependency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bobisjan committed Oct 28, 2018
1 parent e5c777d commit a8bea25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"chalk": "^2.0.1",
"cookie": "^0.3.1",
"debug": "^3.0.0",
"exists-sync": "0.0.4",
"najax": "^1.0.2",
"resolve": "^1.8.1",
"rsvp": "^4.7.0",
"simple-dom": "^1.0.0",
"source-map-support": "^0.5.0"
Expand Down
16 changes: 6 additions & 10 deletions src/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chalk = require('chalk');

const najax = require('najax');
const SimpleDOM = require('simple-dom');
const existsSync = require('exists-sync');
const resolve = require('resolve');
const debug = require('debug')('fastboot:ember-app');

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

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

if (existsSync(nodeModulesPath)) {
return require(nodeModulesPath);
} else {
// If it's not on disk, assume it's a built-in node package
return require(moduleName);
}
if (whitelist.indexOf(moduleName) > -1) {
let nodeModulesPath = resolve.sync(modulePath, { basedir: distPath });
return require(nodeModulesPath);
} else {
throw new Error("Unable to require module '" + moduleName + "' because it was not in the whitelist.");
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/custom-sandbox/custom-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const vm = require('vm');
const fs = require('fs');
const existsSync = require('exists-sync');
const Sandbox = require('./../../../src/sandbox');

/**
Expand Down

0 comments on commit a8bea25

Please sign in to comment.