@zohodesk/react-cli 1.1.22-exp.3 → 1.1.22-exp.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -13,17 +13,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
13
13
|
|
14
14
|
const {
|
15
15
|
module: {
|
16
|
-
mode
|
17
|
-
alias
|
16
|
+
mode
|
18
17
|
},
|
19
18
|
babelCustomizationForLibrary: {
|
20
19
|
babelPlugins
|
21
20
|
},
|
22
|
-
enableTypeScript
|
21
|
+
enableTypeScript,
|
22
|
+
alias
|
23
23
|
} = (0, _utils.getOptions)();
|
24
24
|
const isProd = mode.toLowerCase() === 'prod';
|
25
25
|
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
26
|
-
|
26
|
+
__DOCS__: false
|
27
27
|
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
|
28
28
|
"root": ["./"],
|
29
29
|
alias
|
@@ -19,12 +19,16 @@ const {
|
|
19
19
|
babelCustomizationForLibrary: {
|
20
20
|
babelPlugins
|
21
21
|
},
|
22
|
-
enableTypeScript
|
22
|
+
enableTypeScript,
|
23
|
+
alias
|
23
24
|
} = (0, _utils.getOptions)();
|
24
25
|
const isProd = mode.toLowerCase() === 'prod';
|
25
26
|
const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
|
26
27
|
__DOCS__: false
|
27
|
-
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('
|
28
|
+
} : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
|
29
|
+
"root": ["./"],
|
30
|
+
alias
|
31
|
+
}]];
|
28
32
|
const resolvedPlugins = [];
|
29
33
|
babelPlugins.forEach(plugin => {
|
30
34
|
resolvedPlugins.push(require.resolve(plugin));
|
package/lib/configs/libAlias.js
CHANGED
@@ -3,12 +3,45 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.aliasPathCreation = aliasPathCreation;
|
6
7
|
exports.libAlias = exports.jestModuleNameMapper = void 0;
|
8
|
+
|
9
|
+
var _utils = require("../utils");
|
10
|
+
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
12
|
+
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
|
+
|
7
15
|
// the reason for alias at the time was code tree shaking
|
8
16
|
// tree shaking was most compactable with ES module system
|
9
17
|
// FIXME: But there is a posiblity when these package does not have lib,
|
10
18
|
// app will work because of alias, But may be jest won't work because of not alais
|
11
19
|
// So need to think about use alais in jest
|
20
|
+
const appPath = process.cwd();
|
21
|
+
const {
|
22
|
+
alias,
|
23
|
+
app
|
24
|
+
} = (0, _utils.getOptions)();
|
25
|
+
const {
|
26
|
+
disableES5Transpile
|
27
|
+
} = app;
|
28
|
+
|
29
|
+
function aliasPathCreation(customAlias) {
|
30
|
+
if (customAlias == null) {
|
31
|
+
return {};
|
32
|
+
}
|
33
|
+
|
34
|
+
const newAlias = {};
|
35
|
+
Object.keys(customAlias).forEach(key => {
|
36
|
+
if (customAlias[key].startsWith('.')) {
|
37
|
+
newAlias[key] = _path.default.resolve(appPath, customAlias[key]);
|
38
|
+
} else {
|
39
|
+
newAlias[key] = customAlias[key];
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return newAlias;
|
43
|
+
}
|
44
|
+
|
12
45
|
const libAlias = {
|
13
46
|
'@zohodesk/components/lib': '@zohodesk/components/es',
|
14
47
|
// '@zohodesk/zc-custom/lib': '@zohodesk/zc-custom/es',
|
@@ -31,8 +64,9 @@ const libAlias = {
|
|
31
64
|
// '^@components(.*)$': '<rootDir>/src/components$1',
|
32
65
|
|
33
66
|
exports.libAlias = libAlias;
|
34
|
-
const
|
35
|
-
|
67
|
+
const totalAlias = disableES5Transpile ? Object.assign({}, libAlias, aliasPathCreation(alias)) : aliasPathCreation(alias);
|
68
|
+
const jestModuleNameMapper = Object.keys(totalAlias).reduce((previousValue, key) => {
|
69
|
+
previousValue[`^${key}(.*)$`] = `${totalAlias[key]}$1`;
|
36
70
|
return previousValue;
|
37
71
|
}, {});
|
38
72
|
exports.jestModuleNameMapper = jestModuleNameMapper;
|
package/lib/configs/resolvers.js
CHANGED
@@ -21,7 +21,7 @@ function moduleResolver(options) {
|
|
21
21
|
moduleResolvePath,
|
22
22
|
disableES5Transpile
|
23
23
|
} = options.app;
|
24
|
-
const customAlias = options.
|
24
|
+
const customAlias = options.alias;
|
25
25
|
let required = moduleResolvePath && (0, _requireLocalOrGlobal.requireLocal)(moduleResolvePath);
|
26
26
|
|
27
27
|
if (!required) {
|
@@ -33,11 +33,11 @@ function moduleResolver(options) {
|
|
33
33
|
}
|
34
34
|
|
35
35
|
const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
|
36
|
-
const totalAlias = Object.assign({}, _libAlias.libAlias, customAlias);
|
36
|
+
const totalAlias = disableES5Transpile ? Object.assign({}, _libAlias.libAlias, (0, _libAlias.aliasPathCreation)(customAlias)) : (0, _libAlias.aliasPathCreation)(customAlias);
|
37
37
|
return {
|
38
38
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
39
39
|
modules: [nodeModulesPath, _constants.cliNodeModulesPath, 'node_modules'].filter(Boolean),
|
40
|
-
alias:
|
40
|
+
alias: totalAlias // alias: { ...libAlias, ...clientDependenies }
|
41
41
|
|
42
42
|
};
|
43
43
|
}
|
package/lib/schemas/index.js
CHANGED
@@ -15,6 +15,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
15
15
|
|
16
16
|
// TODO move deprecated options to separate file and manage seperately
|
17
17
|
var _default = {
|
18
|
+
alias: null,
|
18
19
|
unstableDepsInverse: {
|
19
20
|
value: false,
|
20
21
|
cli: 'unstable_deps_inverse'
|
@@ -125,7 +126,6 @@ var _default = {
|
|
125
126
|
cssDirStatement: null
|
126
127
|
},
|
127
128
|
app: {
|
128
|
-
alias: null,
|
129
129
|
moduleResolvePath: {
|
130
130
|
value: '@zohodesk/client_packages_group',
|
131
131
|
cli: 'module_resolve_path'
|
@@ -729,8 +729,7 @@ var _default = {
|
|
729
729
|
value: 'prod',
|
730
730
|
cli: 'module_mode'
|
731
731
|
},
|
732
|
-
disableES5Transpile: true
|
733
|
-
alias: null
|
732
|
+
disableES5Transpile: true
|
734
733
|
},
|
735
734
|
stats: {
|
736
735
|
enable: {
|
package/package.json
CHANGED
@@ -1,23 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
4
|
-
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
-
|
7
|
-
const options = (0, _getOptions.default)();
|
8
|
-
const alias = options.app.alias;
|
9
|
-
|
10
|
-
module.exports = () => ({
|
11
|
-
visitor: {
|
12
|
-
ImportDeclaration(path) {
|
13
|
-
const source = path.node.source.value;
|
14
|
-
const aliasName = Object.keys(alias);
|
15
|
-
aliasName.forEach(name => {
|
16
|
-
if (source.includes(name)) {
|
17
|
-
path.node.source.value = source.replace(name, alias[name]);
|
18
|
-
}
|
19
|
-
});
|
20
|
-
}
|
21
|
-
|
22
|
-
}
|
23
|
-
});
|