@zohodesk/react-cli 1.1.20-exp.7 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/docs/ReactLive.md +5 -1
- package/lib/jest/preProcessors/jsPreprocessor.js +0 -2
- package/lib/loaders/docsLoader.js +2 -2
- package/lib/loaders/enhancedReactLiveConverter.js +151 -0
- package/lib/pluginUtils/getDevPlugins.js +5 -2
- package/lib/pluginUtils/getProdPlugins.js +4 -1
- package/lib/plugins/EventsHandlingPlugin.js +34 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
- package/lib/schemas/index.js +2 -2
- package/npm-shrinkwrap.json +19652 -15
- package/package.json +1 -1
package/README.md
CHANGED
@@ -44,9 +44,28 @@ Now to run app
|
|
44
44
|
|
45
45
|
# Change Logs
|
46
46
|
|
47
|
-
#
|
47
|
+
# 1.1.21 (4-6-2024)
|
48
48
|
|
49
|
-
|
49
|
+
- TypeScript support has been added for the application, library, and Jest.
|
50
|
+
|
51
|
+
- The `enable_typescript` option has been added in the react-cli.config.js. Set it to true to enable TypeScript
|
52
|
+
|
53
|
+
- Support for adding plugins is now available. To use this, configure your react-cli.config.js file as follows:
|
54
|
+
|
55
|
+
```
|
56
|
+
babelCustomizationForLibrary: {
|
57
|
+
babelPlugins: [<`your plugins`>]
|
58
|
+
},
|
59
|
+
```
|
60
|
+
- The Memory leak issue while downloading i18n and CSS files has been fixed
|
61
|
+
|
62
|
+
# 1.1.20 (27-5-2024)
|
63
|
+
|
64
|
+
**Feature**
|
65
|
+
|
66
|
+
- enhancedReactLiveConverter.js added and imported in docLoader file
|
67
|
+
|
68
|
+
- stats.json file creation deleted, if `enable_stats` option is false.
|
50
69
|
|
51
70
|
# 1.1.19 (5-2-2024)
|
52
71
|
|
package/docs/ReactLive.md
CHANGED
@@ -11,4 +11,8 @@
|
|
11
11
|
|
12
12
|
# v1.1.2 update:
|
13
13
|
|
14
|
-
* ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
|
14
|
+
* ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
|
15
|
+
|
16
|
+
# v1.1.20 update:
|
17
|
+
|
18
|
+
* enhancedReactLiveConverter.js added and imported in docLoader file
|
@@ -6,7 +6,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
6
6
|
|
7
7
|
const getOptions = require('../../../lib/utils/getOptions').default;
|
8
8
|
|
9
|
-
console.log('water');
|
10
9
|
const {
|
11
10
|
enableTypeScript,
|
12
11
|
babelCustomizationForLibrary
|
@@ -26,7 +25,6 @@ if (enableTypeScript) {
|
|
26
25
|
|
27
26
|
const defaultPlugins = [require.resolve('babel-plugin-transform-dynamic-import')];
|
28
27
|
const plugins = [...defaultPlugins, ...resolvedPlugins];
|
29
|
-
console.log(presets, plugins, 'wtru');
|
30
28
|
module.exports = _babelJest.default.createTransformer({
|
31
29
|
presets: presets,
|
32
30
|
plugins: plugins
|
@@ -6,7 +6,7 @@ var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));
|
|
6
6
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
8
8
|
|
9
|
-
var
|
9
|
+
var _enhancedReactLiveConverter = require("./enhancedReactLiveConverter.js");
|
10
10
|
|
11
11
|
var _markdownLoader = require("./markdownLoader.js");
|
12
12
|
|
@@ -27,7 +27,7 @@ module.exports = function (source) {
|
|
27
27
|
const src = _fs.default.readFileSync(originalFilePath).toString();
|
28
28
|
|
29
29
|
options.docs.enableMDParser && (source = (0, _markdownLoader.markdownParser)(source));
|
30
|
-
options.docs.enableReactLive && (source = (0,
|
30
|
+
options.docs.enableReactLive && (source = (0, _enhancedReactLiveConverter.enhancedReactLiveConverter)(source, originalFilePath)); //to Enable the ReactLive Converter
|
31
31
|
|
32
32
|
return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
|
33
33
|
};
|
@@ -0,0 +1,151 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.enhancedReactLiveConverter = enhancedReactLiveConverter;
|
7
|
+
|
8
|
+
const parser = require('@babel/parser');
|
9
|
+
|
10
|
+
const traverse = require('@babel/traverse').default;
|
11
|
+
|
12
|
+
const t = require("@babel/types");
|
13
|
+
|
14
|
+
const path = require('path');
|
15
|
+
|
16
|
+
function getFilename(originalFilePath) {
|
17
|
+
const [fileName] = path.basename(originalFilePath).split('.');
|
18
|
+
return fileName;
|
19
|
+
}
|
20
|
+
|
21
|
+
function convertKeyToValue(object = {}) {
|
22
|
+
let keys = Object.keys(object);
|
23
|
+
let values = Object.values(object);
|
24
|
+
return keys.reduce((value, item, i) => {
|
25
|
+
if (item.includes(',')) {
|
26
|
+
item = item.replace(/{|}/g, "");
|
27
|
+
item = '{ ' + item + ' }';
|
28
|
+
}
|
29
|
+
|
30
|
+
value = value + "'" + values[i] + "'" + ": " + item + ",";
|
31
|
+
return value;
|
32
|
+
}, '');
|
33
|
+
}
|
34
|
+
|
35
|
+
function mergeDuplicateValues(obj) {
|
36
|
+
let mergedObj = {};
|
37
|
+
|
38
|
+
for (let key in obj) {
|
39
|
+
if (obj.hasOwnProperty(key)) {
|
40
|
+
let value = obj[key];
|
41
|
+
let existingKey = Object.keys(mergedObj).find(k => mergedObj[k] === value);
|
42
|
+
|
43
|
+
if (existingKey) {
|
44
|
+
mergedObj[existingKey + ' , ' + key] = value;
|
45
|
+
delete mergedObj[existingKey];
|
46
|
+
} else {
|
47
|
+
mergedObj[key] = value;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
return mergedObj;
|
53
|
+
}
|
54
|
+
|
55
|
+
function enhancedReactLiveConverter(source, originalFilePath) {
|
56
|
+
const fileName = getFilename(originalFilePath);
|
57
|
+
|
58
|
+
if (!source) {
|
59
|
+
return '';
|
60
|
+
}
|
61
|
+
|
62
|
+
let docCode = '';
|
63
|
+
const fileContent = source.replace(/[\s\r\n]*$/, '');
|
64
|
+
const ast = parser.parse(fileContent, {
|
65
|
+
sourceType: 'module',
|
66
|
+
plugins: ['jsx', 'classProperties']
|
67
|
+
});
|
68
|
+
|
69
|
+
function createImportStatements(input) {
|
70
|
+
let output = '';
|
71
|
+
|
72
|
+
for (const key in input) {
|
73
|
+
if (input.hasOwnProperty(key) && key !== 'React') {
|
74
|
+
output += `import ${key} from '${input[key]}';\n`;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
return output;
|
79
|
+
}
|
80
|
+
|
81
|
+
const importBlock = {};
|
82
|
+
const printableCode = {};
|
83
|
+
let remainingBlock = ''; // Traverse the AST and find the import and export blocks
|
84
|
+
|
85
|
+
let remainingCode = ast.program.body.filter(node => node.type !== 'ImportDeclaration').filter(node => node.type !== 'ExpressionStatement').map(node => fileContent.substring(node.start, node.end)).join('').trim();
|
86
|
+
traverse(ast, {
|
87
|
+
ImportDeclaration(path) {
|
88
|
+
path.node.specifiers.map(specifier => {
|
89
|
+
if (t.isImportSpecifier(specifier)) {
|
90
|
+
importBlock[`{ ${specifier.local.name} }`] = path.node.source.value;
|
91
|
+
printableCode[`{ ${specifier.local.name} }`] = path.node.source.value;
|
92
|
+
return `{'${specifier.imported.name}': ${specifier.local.name}}`;
|
93
|
+
} else if (t.isImportDefaultSpecifier(specifier)) {
|
94
|
+
importBlock[`${specifier.local.name}`] = `${path.node.source.value}`;
|
95
|
+
printableCode[`${specifier.local.name}`] = `${path.node.source.value} `;
|
96
|
+
return specifier.local.name;
|
97
|
+
}
|
98
|
+
}).join(", ");
|
99
|
+
},
|
100
|
+
|
101
|
+
ExpressionStatement(path) {
|
102
|
+
const expression = path.get('expression');
|
103
|
+
const expressionLeft = expression.get('left');
|
104
|
+
|
105
|
+
if (path.isExpressionStatement() && expression.isAssignmentExpression() && expressionLeft.isMemberExpression()) {
|
106
|
+
const docCheck = expressionLeft.toString();
|
107
|
+
|
108
|
+
if (docCheck === `${fileName}.docs`) {
|
109
|
+
docCode = expression.toString();
|
110
|
+
} else if (docCheck.includes(fileName)) {
|
111
|
+
const startIndex = path.node.start;
|
112
|
+
const endIndex = path.node.end;
|
113
|
+
remainingBlock += fileContent.slice(startIndex, endIndex);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
});
|
119
|
+
remainingCode = remainingCode.replace(/__DOCS__/, true);
|
120
|
+
remainingCode = remainingCode.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
|
121
|
+
remainingBlock = remainingBlock.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
|
122
|
+
const addBractick = `\`
|
123
|
+
${createImportStatements(printableCode)}
|
124
|
+
${remainingCode}
|
125
|
+
|
126
|
+
${remainingBlock}\`
|
127
|
+
`;
|
128
|
+
const template = `
|
129
|
+
|
130
|
+
${createImportStatements(importBlock)}
|
131
|
+
|
132
|
+
import { LiveProviderv3, LiveEditorv3, LiveErrorv3, LivePreviewv3, Wrapper, EditorWrapper , ErrorWrapper, PreviewWrapper } from '@zohodesk-private/react-live/es/index'
|
133
|
+
|
134
|
+
export default class ${fileName} extends React.Component{
|
135
|
+
render(){
|
136
|
+
return(
|
137
|
+
<LiveProviderv3 needToolBox scope={{import: {${convertKeyToValue(mergeDuplicateValues(printableCode))}}}} code={${addBractick}}>
|
138
|
+
<Wrapper>
|
139
|
+
<EditorWrapper><LiveEditorv3 /></EditorWrapper>
|
140
|
+
<PreviewWrapper><LivePreviewv3 /></PreviewWrapper>
|
141
|
+
<LiveErrorv3 needStyle />
|
142
|
+
</Wrapper>
|
143
|
+
</LiveProviderv3>
|
144
|
+
)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
${docCode}
|
149
|
+
`;
|
150
|
+
return template;
|
151
|
+
}
|
@@ -37,6 +37,8 @@ var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
|
|
37
37
|
|
38
38
|
var _EfcResourceCleanupPlugin = _interopRequireDefault(require("../plugins/EfcResourceCleanupPlugin"));
|
39
39
|
|
40
|
+
var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
|
41
|
+
|
40
42
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
41
43
|
|
42
44
|
// import { windowsModification } from '../loaderUtils/windowsModification';
|
@@ -217,12 +219,13 @@ const getDevPlugins = (options, publicPath) => {
|
|
217
219
|
exclude: exclude.selectorWeight,
|
218
220
|
patterns
|
219
221
|
}));
|
220
|
-
}
|
222
|
+
}
|
223
|
+
|
224
|
+
pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin()); // if (pluginObject.minifier) {
|
221
225
|
// // console.log('minifier active');
|
222
226
|
// pluginsArr.push(new MinifierPlugin());
|
223
227
|
// }
|
224
228
|
|
225
|
-
|
226
229
|
return pluginsArr.filter(Boolean);
|
227
230
|
};
|
228
231
|
|
@@ -27,6 +27,8 @@ var _VariableConversionCollector = _interopRequireDefault(require("../plugins/Va
|
|
27
27
|
|
28
28
|
var _SelectorPlugin = _interopRequireDefault(require("../plugins/SelectorPlugin"));
|
29
29
|
|
30
|
+
var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
|
31
|
+
|
30
32
|
var _plugins = require("../plugins");
|
31
33
|
|
32
34
|
var _CustomAttributePlugin = require("../plugins/CustomAttributePlugin");
|
@@ -237,7 +239,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
237
239
|
if (bundleAnalyze) {
|
238
240
|
pluginsArr.push(new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
|
239
241
|
analyzerMode: 'static',
|
240
|
-
generateStatsFile:
|
242
|
+
generateStatsFile: false,
|
241
243
|
openAnalyzer: false,
|
242
244
|
statsOptions: enableStats ? null : {
|
243
245
|
source: false,
|
@@ -306,6 +308,7 @@ const getProdPlugins = (options, publicPath = '') => {
|
|
306
308
|
statsOutputExcludeKeys,
|
307
309
|
statsFileName
|
308
310
|
}));
|
311
|
+
pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin());
|
309
312
|
return pluginsArr;
|
310
313
|
};
|
311
314
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.EventsHandlingPlugin = void 0;
|
7
|
+
|
8
|
+
/* eslint-disable no-use-before-define */
|
9
|
+
class EventsHandlingPlugin {
|
10
|
+
constructor(options) {}
|
11
|
+
|
12
|
+
apply(compiler) {
|
13
|
+
// NOTE: we not using this, Reason currently this option is only need for EFC,
|
14
|
+
// So it do not needed.
|
15
|
+
compiler.hooks.thisCompilation.tap({
|
16
|
+
name: 'CustomAttributePlugin',
|
17
|
+
stage: 1,
|
18
|
+
fn: compilation => {
|
19
|
+
compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
20
|
+
// const str = attributeSetTemplate(cssAttributes, 'linkTag');
|
21
|
+
const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null');
|
22
|
+
const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
|
23
|
+
resolve();
|
24
|
+
linkTag.onerror = linkTag.onload = null
|
25
|
+
};`);
|
26
|
+
return replacedSourceStr;
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
exports.EventsHandlingPlugin = EventsHandlingPlugin;
|
@@ -228,8 +228,12 @@ class I18nDownlodLogic {
|
|
228
228
|
if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
|
229
229
|
}
|
230
230
|
var scriptTag = document.createElement("script");
|
231
|
-
scriptTag.onload =
|
231
|
+
scriptTag.onload = () => {
|
232
|
+
resolve();
|
233
|
+
scriptTag.onerror = scriptTag.onload = null;
|
234
|
+
};
|
232
235
|
scriptTag.onerror = function(event) {
|
236
|
+
scriptTag.onerror = scriptTag.onload = null;
|
233
237
|
var request = event && event.target && event.target.src || fullsrcPath;
|
234
238
|
var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
|
235
239
|
err.code = "I18N_CHUNK_LOAD_FAILED";
|
package/lib/schemas/index.js
CHANGED
@@ -740,10 +740,10 @@ var _default = {
|
|
740
740
|
excludeKeys: null
|
741
741
|
},
|
742
742
|
babelCustomizationForLibrary: {
|
743
|
-
babelPlugins: [
|
743
|
+
babelPlugins: []
|
744
744
|
},
|
745
745
|
enableTypeScript: {
|
746
|
-
value:
|
746
|
+
value: false,
|
747
747
|
cli: 'enable_typescript'
|
748
748
|
}
|
749
749
|
};
|