Skip to content

Commit

Permalink
[fix] need to always regen xarc options if called by user (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip authored Nov 25, 2020
1 parent 7be23da commit 6e0a5f1
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 140 deletions.
54 changes: 31 additions & 23 deletions packages/xarc-app-dev/src/config/archetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,62 @@ let cachedArchetype = null;
* @param user - user options
* @returns options - final options with defaults and env applied
*/
module.exports = function getDevOptions(user: XarcOptions = {}) {
//checking for cwd from xclap or from env
const cwd = user.cwd || process.env.XARC_CWD || process.cwd();
process.env.XARC_CWD = cwd;

if (cachedArchetype) {
// if cached is already runnig
module.exports = function getDevOptions(userOptions: XarcOptions = null) {
if (!userOptions && cachedArchetype) {
// if cached is already running
cachedArchetype._fromCache = true;
// maintained for backwards compatibility
return cachedArchetype;
}

// first get legacy configs
const legacy = getDevArchetypeLegacy();

// try to read xarc-options.json if it exist and merge it into legacy
const xarcOptions = {
...loadXarcOptions(cwd, false),
// don't want these from saved options because the calculated ones in
// legacy is most up to date. otherwise an outdated saved options
// will break everything if dependencies were updated
dir: undefined,
devDir: undefined,
config: undefined,
cwd: undefined // we know what this is already
};
const xarcOptions = userOptions
? {}
: {
...loadXarcOptions(process.env.XARC_CWD || process.cwd(), false),
// don't want these from saved options because the calculated ones in
// legacy is most up to date. otherwise an outdated saved options
// will break everything if dependencies were updated
dir: undefined,
devDir: undefined,
config: undefined,
cwd: undefined // we know what this is already
};

userOptions = _.merge({}, xarcOptions, userOptions);

//checking for cwd from xclap or from env
const cwd = userOptions.cwd || process.env.XARC_CWD || process.cwd();
process.env.XARC_CWD = cwd;

user = _.merge({}, xarcOptions, user);
const proxy = getEnvProxy();

// proxy config was not set in legacy, so add to top level here
_.merge(legacy, proxy);

// merge user.webpackOptions into legacy.webpack
_.merge(legacy.webpack, user.webpackOptions);
_.merge(legacy.webpack, userOptions.webpackOptions);
// merge user.babelOptions into legacy.babel
_.merge(legacy.babel, user.babelOptions);
_.merge(legacy.babel, userOptions.babelOptions);
// merge user.addOnFeatures into legacy.options
_.merge(legacy.options, user.addOnFeatures);
_.merge(legacy.options, userOptions.addOnFeatures);
// merge the rest into top level
_.merge(legacy, {
...user,
...userOptions,
cwd,
webpackOptions: undefined,
babelOptions: undefined,
addOnFeatures: undefined
});

saveXarcOptions(legacy);
// if user's options exist, it means this is invoked by user passing in options
// the first time, so save it.
if (userOptions) {
saveXarcOptions(legacy);
}

cachedArchetype = legacy;

Expand Down
6 changes: 2 additions & 4 deletions packages/xarc-app-dev/src/config/env-app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
export {};

let cachedEnvApp = null;

module.exports = function getAppEnv() {
const xenvConfig = require("xenv-config");
const { merge } = require("lodash");
Expand All @@ -17,6 +15,6 @@ module.exports = function getAppEnv() {
post: x => x || 0
}
};
cachedEnvApp = cachedEnvApp || xenvConfig(appConfigSpec, {}, { merge });
return cachedEnvApp;

return xenvConfig(appConfigSpec, {}, { merge });
};
6 changes: 2 additions & 4 deletions packages/xarc-app-dev/src/config/env-babel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
export {};

let cachedEnvBabel = null;

module.exports = function getEnvBabel() {
const xenvConfig = require("xenv-config");
const { merge } = require("lodash");
Expand Down Expand Up @@ -42,6 +40,6 @@ module.exports = function getEnvBabel() {
default: {}
}
};
cachedEnvBabel = cachedEnvBabel || xenvConfig(babelConfigSpec, userConfig.babel, { merge });
return cachedEnvBabel;

return xenvConfig(babelConfigSpec, userConfig.babel, { merge });
};
5 changes: 1 addition & 4 deletions packages/xarc-app-dev/src/config/env-karma.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
export {};

let cachedEnvKarma = null;

module.exports = function getEnvKarma() {
const xenvConfig = require("xenv-config");
const { merge } = require("lodash");
Expand All @@ -11,6 +9,5 @@ module.exports = function getEnvKarma() {
const karmaConfigSpec = {
browser: { env: "KARMA_BROWSER", default: "chrome" }
};
cachedEnvKarma = cachedEnvKarma || xenvConfig(karmaConfigSpec, userConfig.karma, { merge });
return cachedEnvKarma;
return xenvConfig(karmaConfigSpec, userConfig.karma, { merge });
};
5 changes: 1 addition & 4 deletions packages/xarc-app-dev/src/config/env-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ export {};

const { merge } = require("lodash");

let cachedEnvProxy = null;

module.exports = function getEnvProxy() {
const xenvConfig = require("xenv-config");

Expand All @@ -21,6 +19,5 @@ module.exports = function getEnvProxy() {
},
elevated: { env: ["ELECTRODE_DEV_ELEVATED"], default: false }
};
cachedEnvProxy = cachedEnvProxy || xenvConfig(proxyConfigSpec, {}, { merge });
return cachedEnvProxy;
return xenvConfig(proxyConfigSpec, {}, { merge });
};
7 changes: 2 additions & 5 deletions packages/xarc-app-dev/src/config/env-webpack.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
export {};

let cachedWebpackConfig = null;

module.exports = function getEnvWebpack() {
const xenvConfig = require("xenv-config");
const userConfig = require("./user-config")();
Expand Down Expand Up @@ -50,7 +48,6 @@ module.exports = function getEnvWebpack() {
loadDlls: { env: "ELECTRODE_LOAD_DLLS", type: "json", default: {} },
minify: { env: "WEBPACK_MINIFY", default: true }
};
cachedWebpackConfig =
cachedWebpackConfig || xenvConfig(webpackConfigSpec, userConfig.webpack, { merge });
return cachedWebpackConfig;

return xenvConfig(webpackConfigSpec, userConfig.webpack, { merge });
};
13 changes: 2 additions & 11 deletions packages/xarc-app-dev/src/config/get-dev-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ export {};
const Path = require("path");
const Fs = require("fs");

let cachedProxy = null;
import { loadXarcOptions } from "../lib/utils";

module.exports = function createDevProxy() {
const xarcOptions = loadXarcOptions();
const xarcCwd = xarcOptions.cwd;
if (cachedProxy) {
return cachedProxy;
}
const xarcCwd = process.env.XARC_CWD || process.cwd();

const envWebpack = require("./env-webpack")();
const envApp = require("./env-app")();
Expand Down Expand Up @@ -131,7 +124,7 @@ module.exports = function createDevProxy() {
reporter: `${devPath}/reporter`
};

cachedProxy = cachedProxy || {
return {
settings,
devServer: useDevProxy
? // when using dev proxy, all routes and assets are unified at the same protocol/host/port
Expand All @@ -147,6 +140,4 @@ module.exports = function createDevProxy() {
controlPaths,
searchSSLCerts
};

return cachedProxy;
};
39 changes: 0 additions & 39 deletions packages/xarc-app-dev/src/config/load-dev.ts

This file was deleted.

Loading

0 comments on commit 6e0a5f1

Please sign in to comment.