Skip to content

Commit

Permalink
always expect opt pkg to exist in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Jan 29, 2020
1 parent 75421bc commit 7fe6ffa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/electrode-archetype-react-app/arch-clap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ module.exports = function(xclap) {
setupPath();
createElectrodeTmpDir();
xclap = xclap || requireAt(process.cwd())("xclap") || devRequire("xclap");
process.env._ELECTRODE_DEV_ = "1";
if (!process.env.hasOwnProperty("FORCE_COLOR")) {
process.env.FORCE_COLOR = "1"; // force color for chalk
}
Expand Down
38 changes: 30 additions & 8 deletions packages/electrode-archetype-react-app/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,38 @@ const constants = require("./constants");
const utils = require("../lib/utils");
const appPkg = require(Path.resolve("package.json"));

function checkOptArchetypeInAppDep(dependencies) {
function checkOptArchetypeInAppDep(dependencies, isDev) {
const options = Object.keys(dependencies)
.filter(x => x.startsWith("electrode-archetype-opt-"))
.reduce((acc, name) => {
try {
const optPkg = require(name)();
if (optPkg.pass) {
acc[optPkg.optionalTagName] = optPkg.expectTag;
//
// In dev mode, when all dev deps are installed, we can safely load
// opt packages and find the feature flag name to enable.
//
// In production mode, dep could've been pruned for prod, and dev only
// opt packages would not even exist.
// note 1: we don't expect dev only opt packages to have any effect
// in production runs.
//
const optPkg = optionalRequire(name, {
notFound(err) {
//
// if in dev mode, or if in production but looking for
// opt pkg within devDependencies:
// then always expect opt pkg to be installed.
//
if (process.env._ELECTRODE_DEV_ || (process.env.NODE_ENV === "production" && !isDev)) {
throw err;
}
}
} catch (err) {}
});

if (optPkg) {
const optPkgFlag = optPkg();
if (optPkgFlag.pass) {
acc[optPkgFlag.optionalTagName] = optPkgFlag.expectTag;
}
}
return acc;
}, {});

Expand All @@ -29,8 +51,8 @@ const userConfigOptions = Object.assign(
//
// Check for any optional archetype in application's devDependencies or dependencies
//
process.env.NODE_ENV !== "production" &&
checkOptArchetypeInAppDep(appPkg.devDependencies).options,

checkOptArchetypeInAppDep(appPkg.devDependencies, true).options,
checkOptArchetypeInAppDep(appPkg.dependencies).options
);

Expand Down

0 comments on commit 7fe6ffa

Please sign in to comment.