use a customized require/.resolve instead of relying on NODE_PATH
# Conflicts: # cmd/cmd.js
This commit is contained in:
parent
64fdc691c4
commit
6eae7a9a31
10
cmd/cmd.js
10
cmd/cmd.js
|
@ -25,16 +25,6 @@ if (!process.env.PKG_PATH) {
|
||||||
process.env.PKG_PATH = process.env.PWD;
|
process.env.PKG_PATH = process.env.PWD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: setting NODE_PATH at runtime won't effect lookup behavior in the
|
|
||||||
// current process, but will take effect in child processes; this enables
|
|
||||||
// lookup of *global* embark's own node_modules from within dapp scripts (such
|
|
||||||
// as an ejected webpack.config.js), making embark's dependencies trasitive
|
|
||||||
// dependencies of a dapp without the dapp explicitly specifying embark as a
|
|
||||||
// dependency in the dapp's package.json
|
|
||||||
process.env.NODE_PATH = utils.joinPath(process.env.EMBARK_PATH, 'node_modules') +
|
|
||||||
(process.env.NODE_PATH ? require('path').delimiter : '') +
|
|
||||||
(process.env.NODE_PATH || '');
|
|
||||||
|
|
||||||
process.env.DEFAULT_DIAGRAM_PATH = utils.joinPath(process.env.DAPP_PATH, 'diagram.svg');
|
process.env.DEFAULT_DIAGRAM_PATH = utils.joinPath(process.env.DAPP_PATH, 'diagram.svg');
|
||||||
process.env.DEFAULT_CMD_HISTORY_PATH = utils.joinPath(process.env.DAPP_PATH, '.embark', 'cmd_history');
|
process.env.DEFAULT_CMD_HISTORY_PATH = utils.joinPath(process.env.DAPP_PATH, '.embark', 'cmd_history');
|
||||||
process.env.DEFAULT_CMD_HISTORY_SIZE = 20;
|
process.env.DEFAULT_CMD_HISTORY_SIZE = 20;
|
||||||
|
|
|
@ -1,27 +1,36 @@
|
||||||
// some packages, plugins, and presets referenced/required in this webpack
|
/* global __dirname module process require */
|
||||||
// config are deps of embark and will be transitive dapp deps unless specified
|
|
||||||
// in the dapp's own package.json
|
|
||||||
|
|
||||||
// embark modifies process.env.NODE_PATH so that when running dapp scripts in
|
|
||||||
// embark's child processes, embark's own node_modules directory will be
|
|
||||||
// searched by node's require(); however, webpack and babel do not directly
|
|
||||||
// support NODE_PATH, so modules such as babel plugins and presets must be
|
|
||||||
// resolved with require.resolve(); that is only necessary if a plugin/preset
|
|
||||||
// is in embark's node_modules vs. the dapp's node_modules
|
|
||||||
|
|
||||||
const cloneDeep = require('lodash.clonedeep');
|
|
||||||
// const CompressionPlugin = require('compression-webpack-plugin');
|
|
||||||
const glob = require('glob');
|
|
||||||
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const dappPath = process.env.DAPP_PATH;
|
const dappPath = process.env.DAPP_PATH;
|
||||||
const embarkPath = process.env.EMBARK_PATH;
|
const embarkPath = process.env.EMBARK_PATH;
|
||||||
|
|
||||||
|
const dappNodeModules = path.join(dappPath, 'node_modules');
|
||||||
|
const embarkNodeModules = path.join(embarkPath, 'node_modules');
|
||||||
|
|
||||||
|
function customRequire(mod) {
|
||||||
|
return require(customRequire.resolve(mod));
|
||||||
|
}
|
||||||
|
|
||||||
|
customRequire.resolve = function (mod) {
|
||||||
|
return require.resolve(
|
||||||
|
mod,
|
||||||
|
{paths: [dappNodeModules, embarkNodeModules]}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// some packages, plugins, and presets referenced/required in this webpack
|
||||||
|
// config are deps of embark and will effectively be transitive dapp deps
|
||||||
|
// unless specified in the dapp's own package.json
|
||||||
|
|
||||||
|
const cloneDeep = customRequire('lodash.clonedeep');
|
||||||
|
// const CompressionPlugin = customRequire('compression-webpack-plugin');
|
||||||
|
const glob = customRequire('glob');
|
||||||
|
const HardSourceWebpackPlugin = customRequire('hard-source-webpack-plugin');
|
||||||
|
|
||||||
const embarkAliases = require(path.join(dappPath, '.embark/embark-aliases.json'));
|
const embarkAliases = require(path.join(dappPath, '.embark/embark-aliases.json'));
|
||||||
const embarkAssets = require(path.join(dappPath, '.embark/embark-assets.json'));
|
const embarkAssets = require(path.join(dappPath, '.embark/embark-assets.json'));
|
||||||
const embarkJson = require(path.join(dappPath, 'embark.json'));
|
const embarkJson = require(path.join(dappPath, 'embark.json'));
|
||||||
const embarkNodeModules = path.join(embarkPath, 'node_modules');
|
|
||||||
const embarkPipeline = require(path.join(dappPath, '.embark/embark-pipeline.json'));
|
const embarkPipeline = require(path.join(dappPath, '.embark/embark-pipeline.json'));
|
||||||
|
|
||||||
const buildDir = path.join(dappPath, embarkJson.buildDir);
|
const buildDir = path.join(dappPath, embarkJson.buildDir);
|
||||||
|
@ -57,10 +66,10 @@ const entry = Object.keys(embarkAssets)
|
||||||
function resolve(pkgName) {
|
function resolve(pkgName) {
|
||||||
if (Array.isArray(pkgName)) {
|
if (Array.isArray(pkgName)) {
|
||||||
const _pkgName = pkgName[0];
|
const _pkgName = pkgName[0];
|
||||||
pkgName[0] = require.resolve(_pkgName);
|
pkgName[0] = customRequire.resolve(_pkgName);
|
||||||
return pkgName;
|
return pkgName;
|
||||||
}
|
}
|
||||||
return require.resolve(pkgName);
|
return customRequire.resolve(pkgName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// base config
|
// base config
|
||||||
|
@ -200,7 +209,7 @@ const isFlowEnabled = !embarkPipeline.typescript;
|
||||||
if (isFlowEnabled) {
|
if (isFlowEnabled) {
|
||||||
// position @babel/plugin-transform-flow-strip-types per babel-preset-react-app
|
// position @babel/plugin-transform-flow-strip-types per babel-preset-react-app
|
||||||
baseBabelLoader.options.plugins.unshift(
|
baseBabelLoader.options.plugins.unshift(
|
||||||
require.resolve('@babel/plugin-transform-flow-strip-types')
|
customRequire.resolve('@babel/plugin-transform-flow-strip-types')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +222,7 @@ if (isTypeScriptEnabled) {
|
||||||
// position @babel/preset-typescript as the last preset (runs first)
|
// position @babel/preset-typescript as the last preset (runs first)
|
||||||
// see: https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/
|
// see: https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/
|
||||||
baseBabelLoader.options.presets.push(
|
baseBabelLoader.options.presets.push(
|
||||||
require.resolve('@babel/preset-typescript')
|
customRequire.resolve('@babel/preset-typescript')
|
||||||
);
|
);
|
||||||
// additional extensions
|
// additional extensions
|
||||||
baseBabelLoader.test = /\.(js|ts)x?$/;
|
baseBabelLoader.test = /\.(js|ts)x?$/;
|
||||||
|
@ -250,7 +259,7 @@ production.name = 'production';
|
||||||
const prodBabelLoader = production.module.rules[3];
|
const prodBabelLoader = production.module.rules[3];
|
||||||
// position babel-plugin-transform-react-remove-prop-types per babel-preset-react-app
|
// position babel-plugin-transform-react-remove-prop-types per babel-preset-react-app
|
||||||
prodBabelLoader.options.plugins.splice(prodBabelLoader.length - 1, 0, [
|
prodBabelLoader.options.plugins.splice(prodBabelLoader.length - 1, 0, [
|
||||||
require.resolve('babel-plugin-transform-react-remove-prop-types'),
|
customRequire.resolve('babel-plugin-transform-react-remove-prop-types'),
|
||||||
{
|
{
|
||||||
removeImport: true
|
removeImport: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue