@zohodesk/react-cli 0.0.1-beta.16 → 0.0.1-beta.162
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/.eslintignore +1 -0
- package/.eslintrc.js +46 -3
- package/CHANGELOG.md +5 -0
- package/README.md +708 -0
- package/bin/cli.js +134 -27
- package/cert/cert.pem +37 -129
- package/cert/key.pem +27 -27
- package/cert/passphrase.pem +1 -0
- package/files/eslintrc.js +62 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +33 -24
- package/lib/common/getPublicPathConfig.js +40 -0
- package/lib/common/index.js +27 -13
- package/lib/common/splitChunks.js +64 -26
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/templateParameters.js +25 -0
- package/lib/configs/jest.config.js +26 -27
- package/lib/configs/libAlias.js +31 -0
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -44
- package/lib/configs/webpack.dev.config.js +96 -56
- package/lib/configs/webpack.docs.config.js +104 -98
- package/lib/configs/webpack.impact.config.js +116 -0
- package/lib/configs/webpack.prod.config.js +137 -85
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +144 -71
- package/lib/jest/coverageCollector.js +62 -29
- package/lib/jest/jsonMaker.js +54 -0
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +91 -41
- package/lib/jest/run.js +74 -27
- package/lib/jest/setup.js +103 -102
- package/lib/loaderUtils/getCSSLoaders.js +77 -0
- package/lib/loaderUtils/getDevJsLoaders.js +30 -23
- package/lib/loaderUtils/index.js +14 -7
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileBountryLoader.js +17 -0
- package/lib/loaders/fileLoader.js +47 -38
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +59 -41
- package/lib/middlewares/SSTMiddleware.js +21 -0
- package/lib/pluginUtils/getDevPlugins.js +175 -26
- package/lib/pluginUtils/getDocsPlugins.js +32 -17
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +240 -37
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +77 -0
- package/lib/plugins/CleanupStatsPlugin.js +28 -0
- package/lib/plugins/EFCPlugin.js +241 -0
- package/lib/plugins/EFCPlugin.md +6 -0
- package/lib/plugins/EFCTemplatePlugin.js +151 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +59 -62
- package/lib/plugins/ModuleStatsPlugin.js +98 -97
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
- package/lib/plugins/PublicPathChangePlugin.js +187 -174
- package/lib/plugins/ReportGeneratePlugin.js +181 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
- package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +107 -0
- package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
- package/lib/plugins/SourceMapHookPlugin.js +25 -31
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
- package/lib/plugins/index.js +118 -55
- package/lib/plugins/libraryImpactPlugin.js +190 -0
- package/lib/plugins/webpackwatchrunplugin.js +26 -0
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
- package/lib/schemas/index.js +466 -52
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +93 -85
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/httpsOptions.js +19 -0
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +44 -0
- package/lib/servers/nowatchserver.js +275 -0
- package/lib/servers/scrServer.js +147 -0
- package/lib/servers/server.js +118 -124
- package/lib/servers/ssServer.js +107 -65
- package/lib/sh/reportPublish.sh +16 -10
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +10 -0
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/buildstats.html +148 -0
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +13 -127
- package/lib/utils/copyTimezones.js +21 -0
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +77 -0
- package/lib/utils/cssURLReplacer.js +67 -54
- package/lib/utils/dependencyPostPublish.js +42 -0
- package/lib/utils/fileUtils.js +125 -0
- package/lib/utils/folderIterator.js +47 -0
- package/lib/utils/getComponents.js +126 -0
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +151 -0
- package/lib/utils/getHash.js +26 -0
- package/lib/utils/getIp.js +20 -0
- package/lib/utils/getOptions.js +55 -30
- package/lib/utils/getServerURL.js +25 -8
- package/lib/utils/index.js +259 -82
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -31
- package/lib/utils/jsonHelper.js +97 -0
- package/lib/utils/libraryImpactConfig.js +63 -0
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +142 -0
- package/lib/utils/mailSender.js +16 -25
- package/lib/utils/pullOrigin.js +28 -0
- package/lib/utils/reinstallDependencies.js +133 -0
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +56 -63
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -0
- package/lib/utils/rtl.js +42 -0
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +48 -0
- package/lib/utils/switchBranch.js +28 -0
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +92 -64
- package/templates/app/.eslintrc.js +140 -0
- package/templates/app/README.md +12 -12
- package/templates/app/app/index.html +24 -8
- package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
- package/templates/app/app/properties/i18nkeys.json +3 -3
- package/templates/app/docs/all.html +69 -69
- package/templates/app/mockapi/index.js +18 -13
- package/templates/app/package.json +37 -17
- package/templates/app/src/actions/SampleActions/index.js +37 -0
- package/templates/app/src/actions/index.js +65 -0
- package/templates/app/src/appUrls.js +19 -0
- package/templates/app/src/components/Alert/Alert.js +134 -0
- package/templates/app/src/components/Alert/Alert.module.css +79 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
- package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
- package/templates/app/src/components/Sample/Sample.module.css +11 -0
- package/templates/app/src/components/Sample/SampleList.js +61 -0
- package/templates/app/src/components/Slider/Slider.css +41 -0
- package/templates/app/src/components/Slider/Slider.js +55 -0
- package/templates/app/src/containers/AlertContainer/index.js +15 -0
- package/templates/app/src/containers/AppContainer/index.js +96 -0
- package/templates/app/src/containers/AppContainer/index.module.css +27 -0
- package/templates/app/src/containers/CustomMatch/index.js +65 -0
- package/templates/app/src/containers/DevTools/index.js +10 -0
- package/templates/app/src/containers/Header/index.js +67 -0
- package/templates/app/src/containers/Header/index.module.css +43 -0
- package/templates/app/src/containers/Redirect/index.js +63 -0
- package/templates/app/src/containers/Redirector/index.js +47 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
- package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
- package/templates/app/src/historyChange.js +5 -0
- package/templates/app/src/index.html +10 -0
- package/templates/app/src/index.js +24 -0
- package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
- package/templates/app/src/reducers/alertData.js +11 -0
- package/templates/app/src/reducers/index.js +6 -0
- package/templates/app/src/reducers/samples.js +19 -0
- package/templates/app/src/store/configureStore.dev.js +51 -0
- package/templates/app/src/store/configureStore.js +5 -0
- package/templates/app/src/store/configureStore.prod.js +26 -0
- package/templates/app/src/util/Common.js +5 -0
- package/templates/app/src/util/RequestAPI.js +132 -0
- package/templates/appold/README.md +12 -0
- package/templates/appold/app/index.html +8 -0
- package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
- package/templates/appold/app/properties/i18nkeys.json +3 -0
- package/templates/appold/docs/all.html +69 -0
- package/templates/appold/mockapi/index.js +13 -0
- package/templates/{app → appold}/mockapi/tickets.json +0 -0
- package/templates/appold/package.json +17 -0
- package/templates/appold/src/components/Text/Text.css +0 -0
- package/templates/appold/src/components/Text/Text.js +23 -0
- package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
- package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
- package/templates/appold/src/components/docs.js +1 -0
- package/templates/appold/src/components/index.js +5 -0
- package/templates/appold/src/index.js +13 -0
- package/templates/docs/all.html +1 -1
- package/templates/docs/component.html +110 -69
- package/templates/docs/components.html +221 -0
- package/templates/docs/css/component.css +12 -14
- package/templates/docs/css/componentTest.css +7 -0
- package/templates/docs/css/style.css +150 -206
- package/templates/docs/impactReportTemplate.html +154 -0
- package/templates/docs/index.html +1482 -1336
- package/templates/library/src/index.js +0 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = ShadowDOMSupportPlugin;
|
7
|
+
|
8
|
+
var _Template = _interopRequireDefault(require("webpack/lib/Template"));
|
9
|
+
|
10
|
+
var _JsonpMainTemplatePlugin = _interopRequireDefault(require("webpack/lib/web/JsonpMainTemplatePlugin"));
|
11
|
+
|
12
|
+
var _tapable = require("tapable");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
/* eslint-disable no-unused-vars */
|
17
|
+
//eslint-disable-next-line
|
18
|
+
function ShadowDOMSupportPlugin() {}
|
19
|
+
|
20
|
+
ShadowDOMSupportPlugin.prototype.apply = function () {
|
21
|
+
this.patchJsonpMainTemplatePlugin();
|
22
|
+
};
|
23
|
+
|
24
|
+
ShadowDOMSupportPlugin.prototype.patchJsonpMainTemplatePlugin = function () {
|
25
|
+
_JsonpMainTemplatePlugin.default.prototype.apply = this._apply;
|
26
|
+
};
|
27
|
+
|
28
|
+
ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
|
29
|
+
const needChunkOnDemandLoadingCode = chunk => {
|
30
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
31
|
+
if (chunkGroup.getNumberOfChildren() > 0) {
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
return false;
|
37
|
+
};
|
38
|
+
|
39
|
+
const needChunkLoadingCode = chunk => {
|
40
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
41
|
+
if (chunkGroup.chunks.length > 1) {
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
|
45
|
+
if (chunkGroup.getNumberOfChildren() > 0) {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
return false;
|
51
|
+
};
|
52
|
+
|
53
|
+
const needEntryDeferringCode = chunk => {
|
54
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
55
|
+
if (chunkGroup.chunks.length > 1) {
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return false;
|
61
|
+
};
|
62
|
+
|
63
|
+
const needPrefetchingCode = chunk => {
|
64
|
+
const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch;
|
65
|
+
return allPrefetchChunks && Object.keys(allPrefetchChunks).length;
|
66
|
+
}; // TODO webpack 5, no adding to .hooks, use WeakMap and static methods
|
67
|
+
|
68
|
+
|
69
|
+
['jsonpScript', 'linkPreload', 'linkPrefetch'].forEach(hook => {
|
70
|
+
if (!mainTemplate.hooks[hook]) {
|
71
|
+
mainTemplate.hooks[hook] = new _tapable.SyncWaterfallHook(['source', 'chunk', 'hash']);
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
const getScriptSrcPath = (hash, chunk, chunkIdExpression) => {
|
76
|
+
const {
|
77
|
+
chunkFilename
|
78
|
+
} = mainTemplate.outputOptions;
|
79
|
+
const chunkMaps = chunk.getChunkMaps();
|
80
|
+
return mainTemplate.getAssetPath(JSON.stringify(chunkFilename), {
|
81
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
82
|
+
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
83
|
+
chunk: {
|
84
|
+
id: `" + ${chunkIdExpression} + "`,
|
85
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[${chunkIdExpression}] + "`,
|
86
|
+
|
87
|
+
hashWithLength(length) {
|
88
|
+
const shortChunkHashMap = Object.create(null);
|
89
|
+
|
90
|
+
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
91
|
+
if (typeof chunkMaps.hash[chunkId] === 'string') {
|
92
|
+
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
return `" + ${JSON.stringify(shortChunkHashMap)}[${chunkIdExpression}] + "`;
|
97
|
+
},
|
98
|
+
|
99
|
+
name: `" + (${JSON.stringify(chunkMaps.name)}[${chunkIdExpression}]||${chunkIdExpression}) + "`,
|
100
|
+
contentHash: {
|
101
|
+
javascript: `" + ${JSON.stringify(chunkMaps.contentHash.javascript)}[${chunkIdExpression}] + "`
|
102
|
+
},
|
103
|
+
contentHashWithLength: {
|
104
|
+
javascript: length => {
|
105
|
+
const shortContentHashMap = {};
|
106
|
+
const contentHash = chunkMaps.contentHash.javascript;
|
107
|
+
|
108
|
+
for (const chunkId of Object.keys(contentHash)) {
|
109
|
+
if (typeof contentHash[chunkId] === 'string') {
|
110
|
+
shortContentHashMap[chunkId] = contentHash[chunkId].substr(0, length);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return `" + ${JSON.stringify(shortContentHashMap)}[${chunkIdExpression}] + "`;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
},
|
118
|
+
contentHashType: 'javascript'
|
119
|
+
});
|
120
|
+
};
|
121
|
+
|
122
|
+
mainTemplate.hooks.localVars.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
123
|
+
const extraCode = [];
|
124
|
+
|
125
|
+
if (needChunkLoadingCode(chunk)) {
|
126
|
+
extraCode.push('', '// object to store loaded and loading chunks', '// undefined = chunk not loaded, null = chunk preloaded/prefetched', '// Promise = chunk loading, 0 = chunk loaded', 'var installedChunks = {', _Template.default.indent(chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};', '', needEntryDeferringCode(chunk) ? 'var deferredModules = [];' : '');
|
127
|
+
}
|
128
|
+
|
129
|
+
if (needChunkOnDemandLoadingCode(chunk)) {
|
130
|
+
extraCode.push('', '// script path function', 'function jsonpScriptSrc(chunkId) {', _Template.default.indent([`return ${mainTemplate.requireFn}.p + ${getScriptSrcPath(hash, chunk, 'chunkId')}`]), '}');
|
131
|
+
}
|
132
|
+
|
133
|
+
if (extraCode.length === 0) {
|
134
|
+
return source;
|
135
|
+
}
|
136
|
+
|
137
|
+
return _Template.default.asString([source, ...extraCode]);
|
138
|
+
});
|
139
|
+
mainTemplate.hooks.jsonpScript.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
|
140
|
+
const {
|
141
|
+
crossOriginLoading
|
142
|
+
} = mainTemplate.outputOptions;
|
143
|
+
const {
|
144
|
+
chunkLoadTimeout
|
145
|
+
} = mainTemplate.outputOptions;
|
146
|
+
const {
|
147
|
+
jsonpScriptType
|
148
|
+
} = mainTemplate.outputOptions;
|
149
|
+
return _Template.default.asString(['var script = document.createElement(\'script\');', 'var onScriptComplete;', jsonpScriptType ? `script.type = ${JSON.stringify(jsonpScriptType)};` : '', 'script.charset = \'utf-8\';', `script.timeout = ${chunkLoadTimeout / 1000};`, `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'script.src = jsonpScriptSrc(chunkId);', crossOriginLoading ? _Template.default.asString(['if (script.src.indexOf(window.location.origin + \'/\') !== 0) {', _Template.default.indent(`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', 'onScriptComplete = function (event) {', _Template.default.indent(['// avoid mem leaks in IE.', 'script.onerror = script.onload = null;', 'clearTimeout(timeout);', 'var chunk = installedChunks[chunkId];', 'if(chunk !== 0) {', _Template.default.indent(['if(chunk) {', _Template.default.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src;', 'var error = new Error(\'Loading chunk \' + chunkId + \' failed.\\n(\' + errorType + \': \' + realSrc + \')\');', 'error.type = errorType;', 'error.request = realSrc;', 'chunk[1](error);']), '}', 'installedChunks[chunkId] = undefined;']), '}']), '};', 'var timeout = setTimeout(function(){', _Template.default.indent(['onScriptComplete({ type: \'timeout\', target: script });']), `}, ${chunkLoadTimeout});`, 'script.onerror = script.onload = onScriptComplete;']);
|
150
|
+
});
|
151
|
+
mainTemplate.hooks.linkPreload.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
|
152
|
+
const {
|
153
|
+
crossOriginLoading
|
154
|
+
} = mainTemplate.outputOptions;
|
155
|
+
const {
|
156
|
+
jsonpScriptType
|
157
|
+
} = mainTemplate.outputOptions;
|
158
|
+
return _Template.default.asString(['var link = document.createElement(\'link\');', jsonpScriptType ? `link.type = ${JSON.stringify(jsonpScriptType)};` : '', 'link.charset = \'utf-8\';', `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'link.rel = "preload";', 'link.as = "script";', 'link.href = jsonpScriptSrc(chunkId);', crossOriginLoading ? _Template.default.asString(['if (link.href.indexOf(window.location.origin + \'/\') !== 0) {', _Template.default.indent(`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '']);
|
159
|
+
});
|
160
|
+
mainTemplate.hooks.linkPrefetch.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
|
161
|
+
const {
|
162
|
+
crossOriginLoading
|
163
|
+
} = mainTemplate.outputOptions;
|
164
|
+
return _Template.default.asString(['var link = document.createElement(\'link\');', crossOriginLoading ? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : '', `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'link.rel = "prefetch";', 'link.as = "script";', 'link.href = jsonpScriptSrc(chunkId);']);
|
165
|
+
});
|
166
|
+
mainTemplate.hooks.requireEnsure.tap('JsonpMainTemplatePlugin load', (source, chunk, hash) => _Template.default.asString([source, '', '// JSONP chunk loading for javascript', '', 'var installedChunkData = installedChunks[chunkId];', 'if(installedChunkData !== 0) { // 0 means "already installed".', _Template.default.indent(['', '// a Promise means "currently loading".', 'if(installedChunkData) {', _Template.default.indent(['promises.push(installedChunkData[2]);']), '} else {', _Template.default.indent(['// setup Promise in chunk cache', 'var promise = new Promise(function(resolve, reject) {', _Template.default.indent(['installedChunkData = installedChunks[chunkId] = [resolve, reject];']), '});', 'promises.push(installedChunkData[2] = promise);', '', '// start chunk loading', mainTemplate.hooks.jsonpScript.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(script);']), '}']), '}']));
|
167
|
+
mainTemplate.hooks.requireEnsure.tap({
|
168
|
+
name: 'JsonpMainTemplatePlugin preload',
|
169
|
+
stage: 10
|
170
|
+
}, (source, chunk, hash) => {
|
171
|
+
const chunkMap = chunk.getChildIdsByOrdersMap().preload;
|
172
|
+
|
173
|
+
if (!chunkMap || Object.keys(chunkMap).length === 0) {
|
174
|
+
return source;
|
175
|
+
}
|
176
|
+
|
177
|
+
return _Template.default.asString([source, '', '// chunk preloadng for javascript', '', `var chunkPreloadMap = ${JSON.stringify(chunkMap, null, '\t')};`, '', 'var chunkPreloadData = chunkPreloadMap[chunkId];', 'if(chunkPreloadData) {', _Template.default.indent(['chunkPreloadData.forEach(function(chunkId) {', _Template.default.indent(['if(installedChunks[chunkId] === undefined) {', _Template.default.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(link);']), '}']), '});']), '}']);
|
178
|
+
});
|
179
|
+
mainTemplate.hooks.requireExtensions.tap('JsonpMainTemplatePlugin', (source, chunk) => {
|
180
|
+
if (!needChunkOnDemandLoadingCode(chunk)) {
|
181
|
+
return source;
|
182
|
+
}
|
183
|
+
|
184
|
+
return _Template.default.asString([source, '', '// on error function for async loading', `${mainTemplate.requireFn}.oe = function(err) { console.error(err); throw err; };`]);
|
185
|
+
});
|
186
|
+
mainTemplate.hooks.bootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
187
|
+
if (needChunkLoadingCode(chunk)) {
|
188
|
+
const withDefer = needEntryDeferringCode(chunk);
|
189
|
+
const withPrefetch = needPrefetchingCode(chunk);
|
190
|
+
return _Template.default.asString([source, '', '// install a JSONP callback for chunk loading', 'function webpackJsonpCallback(data) {', _Template.default.indent(['var chunkIds = data[0];', 'var moreModules = data[1];', withDefer ? 'var executeModules = data[2];' : '', withPrefetch ? 'var prefetchChunks = data[3] || [];' : '', '// add "moreModules" to the modules object,', '// then flag all "chunkIds" as loaded and fire callback', 'var moduleId, chunkId, i = 0, resolves = [];', 'for(;i < chunkIds.length; i++) {', _Template.default.indent(['chunkId = chunkIds[i];', 'if(installedChunks[chunkId]) {', _Template.default.indent('resolves.push(installedChunks[chunkId][0]);'), '}', 'installedChunks[chunkId] = 0;']), '}', 'for(moduleId in moreModules) {', _Template.default.indent(['if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {', _Template.default.indent(mainTemplate.renderAddModule(hash, chunk, 'moduleId', 'moreModules[moduleId]')), '}']), '}', 'if(parentJsonpFunction) parentJsonpFunction(data);', withPrefetch ? _Template.default.asString(['// chunk prefetching for javascript', 'prefetchChunks.forEach(function(chunkId) {', _Template.default.indent(['if(installedChunks[chunkId] === undefined) {', _Template.default.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPrefetch.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(link);']), '}']), '});']) : '', 'while(resolves.length) {', _Template.default.indent('resolves.shift()();'), '}', withDefer ? _Template.default.asString(['', '// add entry modules from loaded chunk to deferred list', 'deferredModules.push.apply(deferredModules, executeModules || []);', '', '// run deferred modules when all chunks ready', 'return checkDeferredModules();']) : '']), '};', withDefer ? _Template.default.asString(['function checkDeferredModules() {', _Template.default.indent(['var result;', 'for(var i = 0; i < deferredModules.length; i++) {', _Template.default.indent(['var deferredModule = deferredModules[i];', 'var fulfilled = true;', 'for(var j = 1; j < deferredModule.length; j++) {', _Template.default.indent(['var depId = deferredModule[j];', 'if(installedChunks[depId] !== 0) fulfilled = false;']), '}', 'if(fulfilled) {', _Template.default.indent(['deferredModules.splice(i--, 1);', `result = ${mainTemplate.requireFn}(${mainTemplate.requireFn}.s = deferredModule[0]);`]), '}']), '}', 'return result;']), '}']) : '']);
|
191
|
+
}
|
192
|
+
|
193
|
+
return source;
|
194
|
+
});
|
195
|
+
mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
196
|
+
if (needChunkLoadingCode(chunk)) {
|
197
|
+
let {
|
198
|
+
jsonpFunction
|
199
|
+
} = mainTemplate.outputOptions;
|
200
|
+
let {
|
201
|
+
globalObject
|
202
|
+
} = mainTemplate.outputOptions;
|
203
|
+
return _Template.default.asString([`var jsonpArray = ${globalObject}[${JSON.stringify(jsonpFunction)}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`, 'var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);', 'jsonpArray.push = webpackJsonpCallback;', 'jsonpArray = jsonpArray.slice();', 'for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);', 'var parentJsonpFunction = oldJsonpFunction;', '', source]);
|
204
|
+
}
|
205
|
+
|
206
|
+
return source;
|
207
|
+
});
|
208
|
+
mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
209
|
+
const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
|
210
|
+
|
211
|
+
if (needChunkLoadingCode(chunk) && prefetchChunks && prefetchChunks.length) {
|
212
|
+
return _Template.default.asString([source, `webpackJsonpCallback([[], {}, 0, ${JSON.stringify(prefetchChunks)}]);`]);
|
213
|
+
}
|
214
|
+
|
215
|
+
return source;
|
216
|
+
});
|
217
|
+
mainTemplate.hooks.startup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
218
|
+
if (needEntryDeferringCode(chunk)) {
|
219
|
+
if (chunk.hasEntryModule()) {
|
220
|
+
const entries = [chunk.entryModule].filter(Boolean).map(m => [m.id].concat(Array.from(chunk.groupsIterable)[0].chunks.filter(c => c !== chunk).map(c => c.id)));
|
221
|
+
return _Template.default.asString(['// add entry module to deferred list', `deferredModules.push(${entries.map(e => JSON.stringify(e)).join(', ')});`, '// run deferred modules when ready', 'return checkDeferredModules();']);
|
222
|
+
}
|
223
|
+
|
224
|
+
return _Template.default.asString(['// run deferred modules from other chunks', 'checkDeferredModules();']);
|
225
|
+
}
|
226
|
+
|
227
|
+
return source;
|
228
|
+
});
|
229
|
+
mainTemplate.hooks.hotBootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
|
230
|
+
const {
|
231
|
+
globalObject
|
232
|
+
} = mainTemplate.outputOptions;
|
233
|
+
const {
|
234
|
+
hotUpdateChunkFilename
|
235
|
+
} = mainTemplate.outputOptions;
|
236
|
+
const {
|
237
|
+
hotUpdateMainFilename
|
238
|
+
} = mainTemplate.outputOptions;
|
239
|
+
const {
|
240
|
+
crossOriginLoading
|
241
|
+
} = mainTemplate.outputOptions;
|
242
|
+
const {
|
243
|
+
hotUpdateFunction
|
244
|
+
} = mainTemplate.outputOptions;
|
245
|
+
const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateChunkFilename), {
|
246
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
247
|
+
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
248
|
+
chunk: {
|
249
|
+
id: '" + chunkId + "'
|
250
|
+
}
|
251
|
+
});
|
252
|
+
const currentHotUpdateMainFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateMainFilename), {
|
253
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
254
|
+
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
|
255
|
+
});
|
256
|
+
|
257
|
+
const runtimeSource = _Template.default.getFunctionContent(require('./JsonpMainTemplate.runtime')).replace(/\/\/\$semicolon/g, ';').replace(/\$require\$/g, mainTemplate.requireFn).replace(/\$crossOriginLoading\$/g, crossOriginLoading ? JSON.stringify(crossOriginLoading) : 'null').replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename).replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename).replace(/\$hash\$/g, JSON.stringify(hash));
|
258
|
+
|
259
|
+
return `${source}
|
260
|
+
function hotDisposeChunk(chunkId) {
|
261
|
+
delete installedChunks[chunkId];
|
262
|
+
}
|
263
|
+
var parentHotUpdateCallback = ${globalObject}[${JSON.stringify(hotUpdateFunction)}];
|
264
|
+
${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
265
|
+
});
|
266
|
+
mainTemplate.hooks.hash.tap('JsonpMainTemplatePlugin', hash => {
|
267
|
+
hash.update('jsonp');
|
268
|
+
hash.update('6');
|
269
|
+
});
|
270
|
+
};
|
@@ -1,47 +1,41 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
var
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
8
9
|
|
9
|
-
var
|
10
|
-
|
11
|
-
var _path2 = _interopRequireDefault(_path);
|
12
|
-
|
13
|
-
var _webpackSources = require('webpack-sources');
|
10
|
+
var _webpackSources = require("webpack-sources");
|
14
11
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
_createClass(SourceMapHookPlugin, [{
|
25
|
-
key: 'apply',
|
26
|
-
value: function apply(compiler) {
|
27
|
-
compiler.hooks.emit.tap('SourceMapHookPlugin', function (compilation) {
|
28
|
-
Object.keys(compilation.assets).forEach(function (filename) {
|
29
|
-
if (/\.js$/g.test(filename)) {
|
30
|
-
var source = compilation.assets[filename].source();
|
14
|
+
class SourceMapHookPlugin {
|
15
|
+
apply(compiler) {
|
16
|
+
compiler.hooks.emit.tap('SourceMapHookPlugin', compilation => {
|
17
|
+
Object.keys(compilation.assets).forEach(filename => {
|
18
|
+
if (/\.js$/g.test(filename) && !/(\.map.|tp\/)/g.test(filename)) {
|
19
|
+
let source = compilation.assets[filename].source();
|
31
20
|
|
32
|
-
|
33
|
-
|
21
|
+
let {
|
22
|
+
name
|
23
|
+
} = _path.default.parse(filename);
|
34
24
|
|
35
|
-
|
25
|
+
let src = source;
|
36
26
|
|
37
|
-
|
27
|
+
if (!/(i18n-chunk\/)/g.test(filename)) {
|
28
|
+
src = `${source}\n//# sourceMappingURL=../../js/${name}.js.map`;
|
29
|
+
compilation.assets[filename.replace(/js\//g, 'smap/js/')] = new _webpackSources.RawSource(src);
|
30
|
+
} else {
|
31
|
+
compilation.assets[filename.replace(/i18n-chunk\//g, 'smap/i18n-chunk/')] = new _webpackSources.RawSource(src);
|
38
32
|
}
|
39
|
-
}
|
33
|
+
}
|
40
34
|
});
|
41
|
-
}
|
42
|
-
}
|
35
|
+
});
|
36
|
+
}
|
43
37
|
|
44
|
-
|
45
|
-
}();
|
38
|
+
}
|
46
39
|
|
47
|
-
|
40
|
+
var _default = SourceMapHookPlugin;
|
41
|
+
exports.default = _default;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _webpack = require("webpack");
|
9
|
+
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
11
|
+
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
13
|
+
|
14
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Plugin that generates hash for the provided list of third party files
|
20
|
+
* Map the provided key with the file hash and add it to the list of exisiting global constants.
|
21
|
+
* Plugin in turn uses the defineplugin to generate global constants.
|
22
|
+
*/
|
23
|
+
class TPHashMappingPlugin {
|
24
|
+
constructor(options) {
|
25
|
+
this.fileMappings = options.fileMappings;
|
26
|
+
this.tpFolder = options.tpFolder;
|
27
|
+
return new _webpack.DefinePlugin(this.getFiles());
|
28
|
+
}
|
29
|
+
|
30
|
+
getHash(content) {
|
31
|
+
let hash = _crypto.default.createHash('md5');
|
32
|
+
|
33
|
+
let data = hash.update(content, 'utf-8');
|
34
|
+
let gen_hash = data.digest('hex');
|
35
|
+
return gen_hash;
|
36
|
+
}
|
37
|
+
|
38
|
+
getFiles() {
|
39
|
+
let hashMapping = {};
|
40
|
+
this.fileMappings.forEach(fileInfo => {
|
41
|
+
let filePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, fileInfo.fileName)}`;
|
42
|
+
|
43
|
+
if (_fs.default.existsSync(filePath)) {
|
44
|
+
let fileContent = _fs.default.readFileSync(filePath, {
|
45
|
+
encoding: 'utf-8'
|
46
|
+
});
|
47
|
+
|
48
|
+
let generatedHash = this.getHash(fileContent);
|
49
|
+
let outputFileSplit = fileInfo.fileName.split('.');
|
50
|
+
outputFileSplit.splice(outputFileSplit.length - 1, 0, generatedHash);
|
51
|
+
let outputFileName = outputFileSplit.join('.');
|
52
|
+
let outputFilePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, outputFileName)}`;
|
53
|
+
|
54
|
+
_fs.default.writeFileSync(outputFilePath, fileContent);
|
55
|
+
|
56
|
+
hashMapping[fileInfo.key] = JSON.stringify(generatedHash);
|
57
|
+
} else {
|
58
|
+
throw new Error(`Third party file ${fileInfo.fileName} does not exist`);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
return hashMapping;
|
62
|
+
}
|
63
|
+
|
64
|
+
}
|
65
|
+
|
66
|
+
var _default = TPHashMappingPlugin;
|
67
|
+
exports.default = _default;
|
@@ -1,46 +1,39 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.default = void 0;
|
6
7
|
|
7
|
-
var
|
8
|
+
var _webpackSources = require("webpack-sources");
|
8
9
|
|
9
|
-
var
|
10
|
-
|
11
|
-
var _uglifycss = require('uglifycss');
|
12
|
-
|
13
|
-
var _uglifycss2 = _interopRequireDefault(_uglifycss);
|
10
|
+
var _uglifycss = _interopRequireDefault(require("uglifycss"));
|
14
11
|
|
15
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
class UglifyCSSPlugin {
|
15
|
+
apply(compiler) {
|
16
|
+
compiler.hooks.emit.tap('UglifyCSSPlugin', compilation => {
|
17
|
+
Object.keys(compilation.assets).forEach(filename => {
|
18
|
+
if (/\.css$/.test(filename)) {
|
19
|
+
try {
|
20
|
+
let asset = compilation.assets[filename].source();
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
value: function apply(compiler) {
|
27
|
-
compiler.hooks.emit.tap('UglifyCSSPlugin', function (compilation) {
|
28
|
-
Object.keys(compilation.assets).forEach(function (filename) {
|
29
|
-
if (/\.css$/.test(filename)) {
|
30
|
-
try {
|
31
|
-
var asset = compilation.assets[filename].source();
|
32
|
-
var result = _uglifycss2.default.processString(asset);
|
33
|
-
compilation.assets[filename] = new _webpackSources.RawSource(result);
|
34
|
-
} catch (e) {
|
35
|
-
compilation.errors.push(e);
|
22
|
+
if (typeof asset !== 'string') {
|
23
|
+
asset = asset.toString();
|
36
24
|
}
|
25
|
+
|
26
|
+
const result = _uglifycss.default.processString(asset);
|
27
|
+
|
28
|
+
compilation.assets[filename] = new _webpackSources.RawSource(result);
|
29
|
+
} catch (e) {
|
30
|
+
compilation.errors.push(e);
|
37
31
|
}
|
38
|
-
}
|
32
|
+
}
|
39
33
|
});
|
40
|
-
}
|
41
|
-
}
|
34
|
+
});
|
35
|
+
}
|
42
36
|
|
43
|
-
|
44
|
-
}();
|
37
|
+
}
|
45
38
|
|
46
39
|
exports.default = UglifyCSSPlugin;
|