@zohodesk/react-cli 1.1.0 → 1.1.2-9.exp.3
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/.vscode/settings.json +25 -0
- package/README.md +453 -34
- package/bin/cli.js +25 -52
- package/docs/CustomChunks.md +12 -9
- package/docs/MarkdownParser.md +18 -0
- package/docs/ReactLive.md +8 -0
- package/docs/ValueReplacer.md +27 -0
- package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
- package/lib/babel/cmjs-plugins-presets.js +36 -7
- package/lib/babel/es-plugins-presets.js +45 -16
- package/lib/common/runPreProcess.js +71 -0
- package/lib/common/splitChunks.js +65 -45
- package/lib/common/testPattern.js +9 -9
- package/lib/configs/jest.config.js +4 -4
- package/lib/configs/libAlias.js +36 -2
- package/lib/configs/resolvers.js +7 -4
- package/lib/configs/webpack.css.umd.config.js +3 -2
- package/lib/configs/webpack.dev.config.js +28 -8
- package/lib/configs/webpack.docs.config.js +11 -5
- package/lib/configs/webpack.impact.config.js +9 -4
- package/lib/configs/webpack.prod.config.js +32 -10
- package/lib/constants.js +3 -3
- package/lib/deprecationLogger.js +40 -0
- package/lib/jest/preProcessors/jsPreprocessor.js +27 -2
- package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
- package/lib/loaderUtils/getCSSLoaders.js +32 -8
- package/lib/loaderUtils/getDevJsLoaders.js +8 -2
- package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
- package/lib/loaders/composeLoader.js +140 -14
- package/lib/loaders/docsLoader.js +5 -2
- package/lib/loaders/enhancedReactLiveConverter.js +151 -0
- package/lib/loaders/markdownLoader.js +71 -0
- package/lib/loaders/reactLiveConvertor.js +64 -66
- package/lib/loaders/workerLoader.js +37 -22
- package/lib/logger.js +7 -0
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
- package/lib/pluginUtils/getDevPlugins.js +24 -8
- package/lib/pluginUtils/getProdPlugins.js +34 -6
- package/lib/plugins/CssOrderControlPlugin.js +36 -0
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
- package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
- package/lib/plugins/EventsHandlingPlugin.js +34 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
- package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
- package/lib/plugins/ReportGeneratePlugin.js +8 -6
- package/lib/plugins/ResourceHintsPlugin.js +13 -3
- package/lib/plugins/StatsPlugin.js +82 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
- package/lib/plugins/utils/fileHandling.js +36 -51
- package/lib/plugins/variableConvertorUtils.js +4 -2
- package/lib/postcss-plugins/ValueReplacer.js +7 -17
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
- package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
- package/lib/schemas/index.js +96 -27
- package/lib/servers/getCliPath.js +3 -5
- package/lib/servers/requireLocalOrGlobal.js +1 -1
- package/lib/utils/cssClassNameGenerate.js +43 -5
- package/lib/utils/deprecationSupport.js +134 -0
- package/lib/utils/getFileType.js +1 -1
- package/lib/utils/getOptions.js +34 -43
- package/lib/utils/getServerURL.js +7 -2
- package/lib/utils/index.js +27 -11
- package/lib/utils/initPreCommitHook.js +5 -5
- package/lib/utils/log.js +11 -0
- package/lib/utils/object-manipulation.js +88 -0
- package/lib/utils/pullOrigin.js +3 -3
- package/lib/utils/reinstallDependencies.js +3 -3
- package/lib/utils/selectorReplacer.js +47 -0
- package/lib/utils/switchBranch.js +4 -2
- package/lib/utils/typeCheck.js +10 -0
- package/lib/utils/variableConverter.js +26 -11
- package/npm-shrinkwrap.json +1001 -106
- package/package.json +12 -4
- package/templates/docs/all.html +1 -0
- package/templates/docs/component.html +1 -0
- package/templates/docs/components.html +1 -0
- package/templates/docs/css/markdown.css +202 -0
- package/templates/docs/css/style.css +136 -169
- package/templates/docs/index.html +796 -632
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
4
|
+
|
5
|
+
var _ValueReplacer = _interopRequireDefault(require("../ValueReplacer"));
|
6
|
+
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8
|
+
|
9
|
+
/* eslint-disable no-use-before-define */
|
10
|
+
describe('postcss value replacer tests', () => {
|
11
|
+
it('is creating value replaced code', () => {
|
12
|
+
const cssInputStr = `.abc{ cursor : text }`;
|
13
|
+
const cssOutputStr = `.abc{ cursor : --textCursor }`;
|
14
|
+
const cssOptions = [{
|
15
|
+
props: ['font', 'font-family', 'cursor'],
|
16
|
+
values: {
|
17
|
+
'zdf-': 'zd-react-app-',
|
18
|
+
'^text$': '--textCursor'
|
19
|
+
}
|
20
|
+
}];
|
21
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
22
|
+
expect(result.css).toEqual(cssOutputStr);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
describe('postcss value replacer tests', () => {
|
26
|
+
it('is creating value replaced code', () => {
|
27
|
+
const cssInputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
28
|
+
const cssOutputStr = `.def{ cursor : var(--textBoxCursor) }`;
|
29
|
+
const cssOptions = [{
|
30
|
+
props: ['font', 'font-family', 'cursor'],
|
31
|
+
values: {
|
32
|
+
'zdf-': 'zd-react-app-',
|
33
|
+
'^text$': '--textCursor'
|
34
|
+
}
|
35
|
+
}];
|
36
|
+
const result = runValueReplacerForCssString(cssInputStr, cssOptions);
|
37
|
+
expect(result.css).toEqual(cssOutputStr);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
function runValueReplacerForCssString(cssInputStr, cssOptions) {
|
42
|
+
return (0, _postcss.default)([(0, _ValueReplacer.default)(cssOptions)]).process(cssInputStr);
|
43
|
+
}
|
@@ -89,11 +89,16 @@ function pxToCalc(value) {
|
|
89
89
|
}
|
90
90
|
});
|
91
91
|
});
|
92
|
-
console.log(arr.join(' '));
|
93
92
|
return arr.join(' ');
|
94
93
|
}
|
95
94
|
|
96
|
-
const singleConvertor = (
|
95
|
+
const singleConvertor = ({
|
96
|
+
value,
|
97
|
+
changeVal,
|
98
|
+
details,
|
99
|
+
range,
|
100
|
+
allowed
|
101
|
+
}) => {
|
97
102
|
const {
|
98
103
|
path,
|
99
104
|
filename,
|
@@ -107,7 +112,15 @@ const singleConvertor = (value, changeVal, details, range) => {
|
|
107
112
|
}
|
108
113
|
}
|
109
114
|
|
115
|
+
if (allowed && allowed.includes(decl.value) && decl.value.toString() !== '0') {
|
116
|
+
return decl.value;
|
117
|
+
}
|
118
|
+
|
110
119
|
if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
|
120
|
+
if (value.trim() === '0px') {
|
121
|
+
return '0';
|
122
|
+
}
|
123
|
+
|
111
124
|
let retVal = value.replace(/(\d+)px/gi, changeVal.replace('$$', '$1'));
|
112
125
|
|
113
126
|
if (/^-var/.test(retVal)) {
|
@@ -162,6 +175,7 @@ module.exports = {
|
|
162
175
|
});
|
163
176
|
const valRegex = new RegExp(regValStr, 'gi');
|
164
177
|
return rootOriginal => {
|
178
|
+
// console.log(rootOriginal.source.input.from, 'passed through variable Plugin');
|
165
179
|
rootOriginal.walkRules(rule => {
|
166
180
|
// rule.nodes[-1] = {}
|
167
181
|
// need map, forEach fine less memory
|
@@ -200,6 +214,9 @@ module.exports = {
|
|
200
214
|
.replace(/\d+/gi, '').replace('var(--zd_size)', 'px').replace('var(--zd_font_size)', 'px').replace('rect(', '').replace(')', '').replace('px,', 'px').replace(',', '').split(' ').filter(x => x !== ''); // unit = unit.replace(unit, unit.replace('-',''))
|
201
215
|
// console.log('unit : ');
|
202
216
|
// console.log(unit);
|
217
|
+
// if (decl.prop === 'height') {
|
218
|
+
// console.log(decl.prop, unit, 'case 1');
|
219
|
+
// }
|
203
220
|
|
204
221
|
unit.forEach((val, index) => {
|
205
222
|
allowed.forEach(alwdVal => {
|
@@ -219,21 +236,49 @@ module.exports = {
|
|
219
236
|
unitErrorVal = val;
|
220
237
|
}
|
221
238
|
}
|
222
|
-
}); //
|
239
|
+
}); // if (decl.prop === 'height') {
|
240
|
+
// console.log(decl.prop, unitErrorVal, unitError, unit, 'case 2');
|
241
|
+
// }
|
242
|
+
// console.log(allowed, replacements, range)
|
223
243
|
|
224
244
|
if (!unitError) {
|
225
|
-
|
226
|
-
|
245
|
+
let calcValue = false;
|
246
|
+
|
247
|
+
if (decl.value.includes('calc')) {
|
248
|
+
decl.value = pxToCalc(decl.value);
|
249
|
+
calcValue = true;
|
250
|
+
} // use variable decl.value.split(' ')
|
251
|
+
|
252
|
+
|
253
|
+
if (range && !calcValue) {
|
227
254
|
// console.log('multiple :', decl.value)
|
255
|
+
const tempVal = decl.value; // if (decl.prop === 'height') {
|
256
|
+
// console.log(decl.prop, tempVal, decl.value, allowed, 'case 3');
|
257
|
+
// }
|
258
|
+
// if (decl.prop === 'height') {
|
259
|
+
// console.log('allowed!', decl.prop, decl.value, allowed);
|
260
|
+
// }
|
261
|
+
|
228
262
|
let newVal = '';
|
229
|
-
decl.value.split(' ')
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
263
|
+
let splitValues = decl.value.split(' ');
|
264
|
+
splitValues = splitValues.filter(val => val.trim() !== '');
|
265
|
+
splitValues = splitValues.map(val => val.replace(/\r|\t|\n/gi, ''));
|
266
|
+
splitValues.forEach(singleVal => {
|
267
|
+
newVal += `${singleConvertor({
|
268
|
+
value: singleVal,
|
269
|
+
changeVal: settings.replacements.px,
|
270
|
+
details: {
|
271
|
+
decl,
|
272
|
+
filename,
|
273
|
+
path: fromPath
|
274
|
+
},
|
275
|
+
range,
|
276
|
+
allowed
|
277
|
+
})} `;
|
235
278
|
});
|
236
|
-
decl.value = newVal;
|
279
|
+
decl.value = newVal; // if (decl.prop === 'height') {
|
280
|
+
// console.log(decl.prop, tempVal, newVal, 'case 4');
|
281
|
+
// }
|
237
282
|
}
|
238
283
|
} else {
|
239
284
|
if (!decl.value.includes('calc')) {
|
@@ -272,15 +317,22 @@ module.exports = {
|
|
272
317
|
const valArr = decl.value.split(' ');
|
273
318
|
const settings = settingsObject[decl.prop];
|
274
319
|
const {
|
275
|
-
range
|
320
|
+
range,
|
321
|
+
allowed
|
276
322
|
} = settings;
|
277
323
|
const convertedVals = valArr.map(val => {
|
278
324
|
if (val.includes('px')) {
|
279
|
-
const convertedVal = singleConvertor(
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
325
|
+
const convertedVal = singleConvertor({
|
326
|
+
value: val,
|
327
|
+
changeVal: settings.replacements.px,
|
328
|
+
details: {
|
329
|
+
decl,
|
330
|
+
filename,
|
331
|
+
path: fromPath
|
332
|
+
},
|
333
|
+
range,
|
334
|
+
allowed
|
335
|
+
});
|
284
336
|
return convertedVal ? convertedVal : val;
|
285
337
|
}
|
286
338
|
|
package/lib/schemas/index.js
CHANGED
@@ -15,7 +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
|
-
|
18
|
+
alias: null,
|
19
19
|
unstableDepsInverse: {
|
20
20
|
value: false,
|
21
21
|
cli: 'unstable_deps_inverse'
|
@@ -36,6 +36,9 @@ var _default = {
|
|
36
36
|
cli: 'stop_nodemon'
|
37
37
|
}
|
38
38
|
},
|
39
|
+
resourceHints: {
|
40
|
+
allowPrefetchingMultipleChunks: false
|
41
|
+
},
|
39
42
|
i18n: {
|
40
43
|
chunkSplitEnable: {
|
41
44
|
value: false,
|
@@ -49,6 +52,10 @@ var _default = {
|
|
49
52
|
propertiesFolder: null
|
50
53
|
},
|
51
54
|
css: {
|
55
|
+
cssOrderControler: {
|
56
|
+
enable: false,
|
57
|
+
className: 'customCss'
|
58
|
+
},
|
52
59
|
enableRTLSplit: false,
|
53
60
|
valueReplacer: null,
|
54
61
|
//valueReplacer: [
|
@@ -63,7 +70,39 @@ var _default = {
|
|
63
70
|
// ],
|
64
71
|
templateLabel: '{{--dir}}',
|
65
72
|
disableMiniFiySelector: false,
|
66
|
-
dirVarName: 'document.dir'
|
73
|
+
dirVarName: 'document.dir',
|
74
|
+
selectorReplace: {
|
75
|
+
before: [],
|
76
|
+
after: []
|
77
|
+
},
|
78
|
+
plugins: null,
|
79
|
+
// @type {Boolean | Array}
|
80
|
+
postCssPluginOrder: null,
|
81
|
+
patterns: {
|
82
|
+
valueReplacer: [],
|
83
|
+
selectorReplace: [],
|
84
|
+
hoverActive: [],
|
85
|
+
combinerMediaQuery: [],
|
86
|
+
hasRTL: [],
|
87
|
+
cssVariableReplacement: [],
|
88
|
+
selectorWeight: [],
|
89
|
+
cssUniqueness: [],
|
90
|
+
composeMinification: []
|
91
|
+
},
|
92
|
+
exclude: {
|
93
|
+
rtl: [],
|
94
|
+
hoverActive: [],
|
95
|
+
combinerMediaQuery: [],
|
96
|
+
cssVariableReplacement: [],
|
97
|
+
selectorWeight: [],
|
98
|
+
hasRTL: []
|
99
|
+
},
|
100
|
+
cssVariableReplacementConfig: '',
|
101
|
+
selectorWeightConfig: {
|
102
|
+
defaultSelector: '',
|
103
|
+
customFileDetails: '',
|
104
|
+
excludeStrings: []
|
105
|
+
}
|
67
106
|
},
|
68
107
|
efc: {
|
69
108
|
hasEFC: {
|
@@ -91,10 +130,23 @@ var _default = {
|
|
91
130
|
cssDirStatement: null
|
92
131
|
},
|
93
132
|
app: {
|
133
|
+
generateHtml: {
|
134
|
+
value: true,
|
135
|
+
cli: 'generate_html'
|
136
|
+
},
|
137
|
+
displayClassName: {
|
138
|
+
value: false,
|
139
|
+
cli: 'display_class_name'
|
140
|
+
},
|
94
141
|
moduleResolvePath: {
|
95
142
|
value: '@zohodesk/client_packages_group',
|
96
143
|
cli: 'module_resolve_path'
|
97
144
|
},
|
145
|
+
enableMjsLoader: {
|
146
|
+
value: false,
|
147
|
+
cli: 'enableMjsLoader'
|
148
|
+
},
|
149
|
+
customClassNamePrefix: [],
|
98
150
|
// this option only for impact testing
|
99
151
|
devCssFileBountry: {
|
100
152
|
value: '',
|
@@ -180,6 +232,7 @@ var _default = {
|
|
180
232
|
none: '(hover: none)'
|
181
233
|
},
|
182
234
|
disableES5Transpile: false,
|
235
|
+
disableES5Import: false,
|
183
236
|
isReactMig: false,
|
184
237
|
hasWidget: false,
|
185
238
|
hasEFC: {
|
@@ -228,17 +281,8 @@ var _default = {
|
|
228
281
|
value: true,
|
229
282
|
cli: 'enable_smaphook'
|
230
283
|
},
|
231
|
-
plugins:
|
232
|
-
|
233
|
-
selectorReplace: false,
|
234
|
-
hasRTL: false,
|
235
|
-
hoverActive: false,
|
236
|
-
combinerMediaQuery: false,
|
237
|
-
cssVariableReplacement: false,
|
238
|
-
selectorWeight: false,
|
239
|
-
minifier: false,
|
240
|
-
composeMinification: false
|
241
|
-
},
|
284
|
+
plugins: null,
|
285
|
+
postCssPluginOrder: null,
|
242
286
|
patterns: {
|
243
287
|
valueReplacer: [],
|
244
288
|
selectorReplace: [],
|
@@ -255,7 +299,8 @@ var _default = {
|
|
255
299
|
hoverActive: [],
|
256
300
|
combinerMediaQuery: [],
|
257
301
|
cssVariableReplacement: [],
|
258
|
-
selectorWeight: []
|
302
|
+
selectorWeight: [],
|
303
|
+
hasRTL: []
|
259
304
|
},
|
260
305
|
cssVariableReplacementConfig: '',
|
261
306
|
selectorWeightConfig: {
|
@@ -291,9 +336,14 @@ var _default = {
|
|
291
336
|
},
|
292
337
|
htmlTemplate: {
|
293
338
|
minify: null,
|
294
|
-
inject: true
|
339
|
+
inject: true,
|
340
|
+
customScriptLoadingStrategey: {
|
341
|
+
enable: false,
|
342
|
+
options: null
|
343
|
+
}
|
295
344
|
},
|
296
345
|
removePropTypes: false,
|
346
|
+
customChunksBaseConfig: null,
|
297
347
|
customChunks: [{
|
298
348
|
name: 'styles',
|
299
349
|
pattern: '\\.css$'
|
@@ -309,9 +359,11 @@ var _default = {
|
|
309
359
|
sourcemap: {
|
310
360
|
cli: 'source_map',
|
311
361
|
value: 'cheap-eval-source-map'
|
312
|
-
}
|
362
|
+
},
|
363
|
+
externals: null
|
313
364
|
},
|
314
365
|
docs: {
|
366
|
+
externals: null,
|
315
367
|
server: {
|
316
368
|
iphost: (0, _getIp.default)(),
|
317
369
|
host: (0, _os.hostname)(),
|
@@ -329,6 +381,7 @@ var _default = {
|
|
329
381
|
hover: 'all and (min--moz-device-pixel-ratio:0) and (hover: hover), (hover: hover)',
|
330
382
|
none: '(hover: none)'
|
331
383
|
},
|
384
|
+
customClassNamePrefix: [],
|
332
385
|
componentFolder: 'src',
|
333
386
|
cssUniqueness: {
|
334
387
|
value: true,
|
@@ -343,16 +396,14 @@ var _default = {
|
|
343
396
|
value: true,
|
344
397
|
cli: 'react_live'
|
345
398
|
},
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
hoverActive: false,
|
350
|
-
combinerMediaQuery: false,
|
351
|
-
cssVariableReplacement: false,
|
352
|
-
selectorWeight: false,
|
353
|
-
minifier: false,
|
354
|
-
composeMinification: false
|
399
|
+
enableMDParser: {
|
400
|
+
value: true,
|
401
|
+
cli: 'markdown_parser'
|
355
402
|
},
|
403
|
+
rtlExclude: [],
|
404
|
+
selectorReplace: null,
|
405
|
+
plugins: null,
|
406
|
+
postCssPluginOrder: null,
|
356
407
|
patterns: {
|
357
408
|
valueReplacer: [],
|
358
409
|
selectorReplace: [],
|
@@ -360,14 +411,16 @@ var _default = {
|
|
360
411
|
combinerMediaQuery: [],
|
361
412
|
hasRTL: [],
|
362
413
|
cssVariableReplacement: [],
|
363
|
-
selectorWeight: []
|
414
|
+
selectorWeight: [],
|
415
|
+
cssUniqueness: []
|
364
416
|
},
|
365
417
|
exclude: {
|
366
418
|
rtl: [],
|
367
419
|
hoverActive: [],
|
368
420
|
combinerMediaQuery: [],
|
369
421
|
cssVariableReplacement: [],
|
370
|
-
selectorWeight: []
|
422
|
+
selectorWeight: [],
|
423
|
+
hasRTL: []
|
371
424
|
},
|
372
425
|
cssVariableReplacementConfig: '',
|
373
426
|
selectorWeightConfig: {
|
@@ -694,6 +747,22 @@ var _default = {
|
|
694
747
|
cli: 'module_mode'
|
695
748
|
},
|
696
749
|
disableES5Transpile: true
|
750
|
+
},
|
751
|
+
stats: {
|
752
|
+
enable: {
|
753
|
+
value: false,
|
754
|
+
cli: 'enable_stats'
|
755
|
+
},
|
756
|
+
fileName: null,
|
757
|
+
options: null,
|
758
|
+
excludeKeys: null
|
759
|
+
},
|
760
|
+
babelCustomizationForLibrary: {
|
761
|
+
babelPlugins: []
|
762
|
+
},
|
763
|
+
enableTypeScript: {
|
764
|
+
value: false,
|
765
|
+
cli: 'enable_typescript'
|
697
766
|
}
|
698
767
|
};
|
699
768
|
exports.default = _default;
|
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.getCliPath = getCliPath;
|
7
7
|
|
8
|
-
var _path =
|
8
|
+
var _path = require("path");
|
9
9
|
|
10
10
|
var _os = require("os");
|
11
11
|
|
12
12
|
var _fs = require("fs");
|
13
13
|
|
14
|
-
|
14
|
+
var _constants = require("../constants");
|
15
15
|
|
16
|
-
const appPath = process.cwd();
|
17
|
-
const isNodeModuleUnderAppFolder = __dirname.indexOf(appPath) !== -1;
|
18
16
|
const isWindows = (0, _os.platform)().toLowerCase() === 'win32';
|
19
17
|
|
20
|
-
const _getCliPath =
|
18
|
+
const _getCliPath = libName => (0, _path.join)(_constants.cliNodeModulesPath, '.bin', libName);
|
21
19
|
|
22
20
|
const suffixExt = isWindows ? '.cmd' : '';
|
23
21
|
|
@@ -25,7 +25,7 @@ function requireLocalOrGlobal(moduleName, opts = {}) {
|
|
25
25
|
const {
|
26
26
|
local = true
|
27
27
|
} = opts;
|
28
|
-
const isRelativePath = moduleName === '.'; // NOTE: if starts with . then it only mean local
|
28
|
+
const isRelativePath = moduleName[0] === '.'; // NOTE: if starts with . then it only mean local
|
29
29
|
|
30
30
|
if (isRelativePath) {
|
31
31
|
global = false;
|
@@ -38,14 +38,35 @@ const isSelectorPackage = (resourcePath, packages) => {
|
|
38
38
|
return isValid;
|
39
39
|
};
|
40
40
|
|
41
|
+
function patternBasedClass({
|
42
|
+
customClassNamePrefix,
|
43
|
+
context,
|
44
|
+
relativePath,
|
45
|
+
localName
|
46
|
+
}) {
|
47
|
+
let newName = null;
|
48
|
+
customClassNamePrefix.forEach(obj => {
|
49
|
+
if (obj.enable) {
|
50
|
+
if (obj.patterns && obj.prefix && (0, _fileHandling.isFileNameMatchingPluginPattern)({
|
51
|
+
filename: context.resourcePath,
|
52
|
+
filterArr: obj.patterns
|
53
|
+
})) {
|
54
|
+
const h = (0, _getHash.default)(`${relativePath}-${localName}`, 10);
|
55
|
+
newName = `${obj.prefix}${h}`;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
});
|
59
|
+
return newName;
|
60
|
+
}
|
61
|
+
|
41
62
|
var _default = (unique = true, {
|
42
63
|
filenames,
|
43
64
|
packages
|
44
|
-
}, classNamePrefix, patterns) => (context, localIdentName, localName) => {
|
65
|
+
}, classNamePrefix, customClassNamePrefix, patterns, displayClassName) => (context, localIdentName, localName) => {
|
45
66
|
// console.log(patterns, context.resourcePath);
|
46
|
-
// NOTE: in build
|
67
|
+
// NOTE: in build machine we use date as folder path.
|
47
68
|
// So every time we create new build there is path will alway different
|
48
|
-
// in order to
|
69
|
+
// in order to minimize that problem we try in relative path;
|
49
70
|
// console.log('context.resourcePath', context.resourcePath, context);
|
50
71
|
// let contextResourcePath = context.resourcePath;
|
51
72
|
const filePaths = context.resourcePath.split(_path.default.sep);
|
@@ -53,7 +74,8 @@ var _default = (unique = true, {
|
|
53
74
|
const [fileNameWithoutExt] = fileName.split('.');
|
54
75
|
const cleanFileName = fileNameWithoutExt.replace(/-/g, '_').toLowerCase();
|
55
76
|
|
56
|
-
const relativePath = _path.default.relative(context.rootContext, context.resourcePath);
|
77
|
+
const relativePath = _path.default.relative(context.rootContext, context.resourcePath); // console.log('customClassNamePrefix', customClassNamePrefix);
|
78
|
+
|
57
79
|
/*
|
58
80
|
input :
|
59
81
|
context.resourcePath : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
|
@@ -70,6 +92,11 @@ var _default = (unique = true, {
|
|
70
92
|
*/
|
71
93
|
|
72
94
|
|
95
|
+
if (displayClassName) {
|
96
|
+
return `${fileNameWithoutExt}__${localName}`;
|
97
|
+
} // return cleanFileName
|
98
|
+
|
99
|
+
|
73
100
|
if (context.resourcePath.endsWith('.plain.css')) {
|
74
101
|
return localName;
|
75
102
|
}
|
@@ -86,7 +113,18 @@ var _default = (unique = true, {
|
|
86
113
|
if (unique) {
|
87
114
|
const h = (0, _getHash.default)(`${relativePath}-${localName}`, 10);
|
88
115
|
return `${classNamePrefix}${h}`;
|
89
|
-
}
|
116
|
+
}
|
117
|
+
|
118
|
+
const patternClass = patternBasedClass({
|
119
|
+
customClassNamePrefix,
|
120
|
+
context,
|
121
|
+
relativePath,
|
122
|
+
localName
|
123
|
+
});
|
124
|
+
|
125
|
+
if (patternClass) {
|
126
|
+
return patternClass;
|
127
|
+
} //css file has case sensitive selector issue so can't toLowerCase
|
90
128
|
//let local = localName.toLowerCase()
|
91
129
|
|
92
130
|
|
@@ -0,0 +1,134 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.deprecationSupport = deprecationSupport;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var deprecationHandlers = _interopRequireWildcard(require("../deprecationLogger"));
|
11
|
+
|
12
|
+
var _windowsModification = require("../loaderUtils/windowsModification");
|
13
|
+
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15
|
+
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
let {
|
21
|
+
deprecateMessage,
|
22
|
+
deprecateOption,
|
23
|
+
deprecationLoggerEnd
|
24
|
+
} = deprecationHandlers;
|
25
|
+
|
26
|
+
function modifyCssArr(arr) {
|
27
|
+
return arr.map(x => {
|
28
|
+
const includeCss = !x.startsWith('!');
|
29
|
+
const modifier = includeCss ? '/*.css' : '';
|
30
|
+
const filePath = x.replace(/^!/, ''); // Remove the "!" symbol if present
|
31
|
+
|
32
|
+
return (0, _windowsModification.windowsModificationFile)(_path.default.join(includeCss ? '**' : '!**', filePath, '**', modifier));
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
const defaultPostCssPluginOptions = {
|
37
|
+
valueReplacer: null,
|
38
|
+
hasRTL: false,
|
39
|
+
selectorReplace: null,
|
40
|
+
hoverActive: false,
|
41
|
+
combinerMediaQuery: false,
|
42
|
+
cssVariableReplacement: false,
|
43
|
+
selectorWeight: false,
|
44
|
+
minifier: false,
|
45
|
+
composeMinification: false
|
46
|
+
};
|
47
|
+
|
48
|
+
function deprecationSupport(options, disableDeprecationWarning) {
|
49
|
+
if (disableDeprecationWarning) {
|
50
|
+
/* eslint-disable no-empty-function */
|
51
|
+
deprecateMessage = () => {};
|
52
|
+
|
53
|
+
deprecateOption = () => {};
|
54
|
+
|
55
|
+
deprecationLoggerEnd = () => {};
|
56
|
+
/* eslint-enable no-empty-function */
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
options.app.plugins = options.app.plugins || defaultPostCssPluginOptions;
|
61
|
+
options.docs.plugins = options.docs.plugins || defaultPostCssPluginOptions;
|
62
|
+
options.css.plugins = options.css.plugins || defaultPostCssPluginOptions; // if (selectn(options, ".app.hasRTL") === true) {
|
63
|
+
|
64
|
+
if (options.app.hasRTL === true) {
|
65
|
+
deprecateOption('app.hasRTL', 'app.plugins.hasRTL');
|
66
|
+
options.app.plugins.hasRTL = true;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (options.docs.hasRTL === true) {
|
70
|
+
deprecateOption('docs.hasRTL', 'docs.plugins.hasRTL');
|
71
|
+
options.docs.plugins.hasRTL = true;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (options.app.selectorReplace !== null && options.app.plugins && (options.app.plugins.selectorReplace === null || options.app.plugins.selectorReplace === undefined)) {
|
75
|
+
deprecateMessage('when you use app.selectorReplace mention enable or disable app.plugins.selectorReplace by setting value to true or false');
|
76
|
+
options.app.plugins.selectorReplace = true;
|
77
|
+
}
|
78
|
+
|
79
|
+
if (options.docs.selectorReplace !== null && options.docs.plugins && (options.docs.plugins.selectorReplace === null || options.docs.plugins.selectorReplace === undefined)) {
|
80
|
+
deprecateMessage('when you use docs.selectorReplace mention enable or disable docs.plugins.selectorReplace by setting value to true or false');
|
81
|
+
options.docs.plugins.selectorReplace = true;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (options.css.valueReplacer !== null && options.css.plugins && (options.app.plugins.valueReplacer === null || options.app.plugins.valueReplacer === undefined)) {
|
85
|
+
deprecateMessage('when you use app.valueReplacer mention enable or disable app.plugins.valueReplacer by setting value to true or false');
|
86
|
+
options.app.plugins.valueReplacer = true;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (!options.app.patterns) {
|
90
|
+
options.app.patterns = {};
|
91
|
+
}
|
92
|
+
|
93
|
+
function handleRTL(rtlExclude, rtl, hasRTL, type) {
|
94
|
+
if (rtlExclude && rtlExclude.length > 0) {
|
95
|
+
options[type].patterns.hasRTL = modifyCssArr(rtlExclude);
|
96
|
+
deprecateOption(`${type}.rtlExclude`, `${type}.patterns.hasRTL`);
|
97
|
+
}
|
98
|
+
|
99
|
+
if (rtl && rtl.length > 0) {
|
100
|
+
options[type].patterns.hasRTL = modifyCssArr(rtl);
|
101
|
+
deprecateOption(`${type}.exclude.rtl`, `${type}.patterns.hasRTL`);
|
102
|
+
}
|
103
|
+
|
104
|
+
if (hasRTL && hasRTL.length > 0) {
|
105
|
+
options[type].patterns.hasRTL = modifyCssArr(hasRTL);
|
106
|
+
deprecateOption(`${type}.exclude.hasRTL`, `${type}.patterns.hasRTL`);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function addExcludesToPattern(patterns, exclude, type) {
|
111
|
+
Object.keys(defaultPostCssPluginOptions).forEach(key => {
|
112
|
+
if (!exclude[key] || exclude[key].length === 0) {
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
|
116
|
+
if (patterns[key].length === 0) {
|
117
|
+
deprecateOption(`${type}.exclude.${key}`, `${type}.patterns.${key}`);
|
118
|
+
let tempArr = exclude[key];
|
119
|
+
tempArr = tempArr.map(x => _path.default.join('!**', x, '**')); // Since patterns[key] is empty we need to wildcard for allow all others.
|
120
|
+
|
121
|
+
tempArr.unshift('*');
|
122
|
+
patterns[key] = tempArr;
|
123
|
+
} else if (exclude[key].length > 0 && patterns[key].length > 0) {
|
124
|
+
deprecateOption(`${type}.exclude.${key}`, `${type}.patterns.${key}`, ` And Since you have used ${type}.patterns.${key} we won't use ${type}.exclude.${key}. So please make appropriate changes`);
|
125
|
+
}
|
126
|
+
});
|
127
|
+
}
|
128
|
+
|
129
|
+
handleRTL(options.app.rtlExclude, options.app.exclude.rtl, options.app.exclude.hasRTL, 'app');
|
130
|
+
handleRTL(options.docs.rtlExclude, options.docs.exclude.rtl, options.docs.exclude.hasRTL, 'docs');
|
131
|
+
addExcludesToPattern(options.app.patterns, options.app.exclude, 'app');
|
132
|
+
addExcludesToPattern(options.docs.patterns, options.docs.exclude, 'docs');
|
133
|
+
deprecationLoggerEnd();
|
134
|
+
}
|
package/lib/utils/getFileType.js
CHANGED