@zohodesk/react-cli 0.0.1-beta.17 → 0.0.1-beta.171
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 +49 -10
- package/.prettierrc +6 -0
- package/CHANGELOG.md +5 -0
- package/README.md +859 -0
- package/bin/cli.js +215 -46
- package/cert/Tsicsezwild-22-23.crt +37 -0
- package/cert/Tsicsezwild-22-23.key +27 -0
- package/docs/CustomChunks.md +26 -0
- package/docs/DevStart.md +18 -0
- package/docs/HoverActive.md +12 -0
- package/docs/InstallNode.md +28 -0
- package/docs/TODOS.md +10 -0
- package/docs/ValueReplacer.md +60 -0
- package/docs/warnings_while_install.txt +35 -0
- package/files/eslintrc.js +62 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +24 -0
- package/lib/babel/es-plugins-presets.js +34 -0
- package/lib/common/getEntries.js +33 -46
- package/lib/common/getPublicPathConfig.js +40 -0
- package/lib/common/index.js +24 -19
- package/lib/common/splitChunks.js +110 -25
- package/lib/common/sslcertUpdater.js +59 -0
- package/lib/common/templateParameters.js +25 -0
- package/lib/common/testPattern.js +69 -0
- package/lib/common/valueReplacer.js +55 -0
- package/lib/configs/jest.config.js +31 -27
- package/lib/configs/libAlias.js +31 -0
- package/lib/configs/webpack.component.umd.config.js +46 -53
- package/lib/configs/webpack.css.umd.config.js +47 -46
- package/lib/configs/webpack.dev.config.js +99 -84
- package/lib/configs/webpack.docs.config.js +65 -57
- package/lib/configs/webpack.impact.config.js +109 -0
- package/lib/configs/webpack.prod.config.js +147 -104
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +144 -71
- package/lib/jest/coverageCollector.js +68 -35
- 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 +92 -42
- package/lib/jest/run.js +75 -28
- package/lib/jest/setup.js +103 -102
- package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
- package/lib/loaderUtils/getCSSLoaders.js +113 -0
- package/lib/loaderUtils/getDevJsLoaders.js +35 -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 +23 -20
- package/lib/loaders/selectorMappingLoader.js +75 -0
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +90 -72
- package/lib/middlewares/SSTMiddleware.js +21 -0
- package/lib/pluginUtils/getDevPlugins.js +177 -30
- package/lib/pluginUtils/getDocsPlugins.js +36 -15
- package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +244 -37
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +14 -18
- package/lib/pluginUtils/getUMDComponentPlugins.js +14 -9
- 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 +95 -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 +86 -0
- package/lib/plugins/ModuleStatsPlugin.js +98 -97
- package/lib/plugins/OptimizeJSPlugin.js +41 -0
- package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
- package/lib/plugins/PublicPathChangePlugin.js +226 -0
- package/lib/plugins/ReportGeneratePlugin.js +181 -0
- package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
- package/lib/plugins/ResourceHintsPlugin.js +67 -0
- 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 -59
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +39 -0
- package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
- package/lib/plugins/index.js +127 -37
- package/lib/plugins/libraryImpactPlugin.js +190 -0
- package/lib/plugins/webpackwatchrunplugin.js +26 -0
- package/lib/postcss-plugins/ExcludePlugin.js +23 -0
- package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
- package/lib/postcss-plugins/ValueReplacer.js +46 -0
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
- package/lib/postcss-plugins/__test__/test1Input.css +39 -0
- package/lib/postcss-plugins/__test__/test1Output.css +39 -0
- package/lib/postcss-plugins/hoverActivePlugin.js +368 -0
- package/lib/postcss-plugins/variableModifier.js +243 -0
- package/lib/schemas/index.js +541 -65
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/devBuild.js +102 -0
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +94 -79
- package/lib/servers/getCliPath.js +28 -0
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/httpsOptions.js +18 -0
- package/lib/servers/impactServer.js +123 -115
- package/lib/servers/mockserver.js +44 -0
- package/lib/servers/nowatchserver.js +200 -0
- package/lib/servers/scrServer.js +147 -0
- package/lib/servers/server.js +134 -132
- package/lib/servers/ssServer.js +106 -70
- 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 -4
- package/lib/utils/buildstats.html +148 -0
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +16 -109
- 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 +136 -0
- 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 +113 -28
- package/lib/utils/getServerURL.js +25 -8
- package/lib/utils/index.js +283 -68
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +47 -27
- package/lib/utils/jsonHelper.js +106 -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 +59 -63
- package/lib/utils/request.js +64 -77
- package/lib/utils/resultSchema.json +73 -0
- package/lib/utils/rtl.js +59 -0
- package/lib/utils/setEnvVariables.js +13 -0
- package/lib/utils/ssTestHack.js +48 -0
- package/lib/utils/switchBranch.js +28 -0
- package/lib/utils/urlConcat.js +22 -0
- package/lib/utils/useExitCleanup.js +55 -0
- package/npm8.md +9 -0
- package/package.json +96 -64
- package/postpublish.js +6 -0
- 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
- package/.npmignore +0 -3
- package/cert/cert.pem +0 -129
- package/cert/key.pem +0 -27
- package/lib/common/getInsertAt.js +0 -36
- package/lib/common/getInsertIntoFunction.js +0 -13
- package/lib/configs/webpack.server.config.js +0 -93
- package/lib/plugins/ChunkManifestReplacePlugin.js +0 -94
- package/lib/plugins/RuntimePublicPathPlugin.js +0 -46
- package/lib/rmcntrlm.sh +0 -14
- package/lib/servers/nodeServer.js +0 -238
- package/lib/templates/HMRTemplate.js +0 -256
- package/lib/templates/publicPathTemplate.js +0 -16
- package/lib/utils/setConfig.js +0 -14
- package/node_modules/history/CHANGES.md +0 -395
- package/node_modules/history/DOMUtils.js +0 -3
- package/node_modules/history/ExecutionEnvironment.js +0 -3
- package/node_modules/history/LICENSE +0 -21
- package/node_modules/history/LocationUtils.js +0 -3
- package/node_modules/history/PathUtils.js +0 -3
- package/node_modules/history/README.md +0 -282
- package/node_modules/history/cjs/history.js +0 -933
- package/node_modules/history/cjs/history.min.js +0 -1
- package/node_modules/history/createBrowserHistory.js +0 -3
- package/node_modules/history/createHashHistory.js +0 -3
- package/node_modules/history/createMemoryHistory.js +0 -3
- package/node_modules/history/createTransitionManager.js +0 -3
- package/node_modules/history/es/DOMUtils.js +0 -7
- package/node_modules/history/es/ExecutionEnvironment.js +0 -7
- package/node_modules/history/es/LocationUtils.js +0 -7
- package/node_modules/history/es/PathUtils.js +0 -7
- package/node_modules/history/es/createBrowserHistory.js +0 -7
- package/node_modules/history/es/createHashHistory.js +0 -7
- package/node_modules/history/es/createMemoryHistory.js +0 -7
- package/node_modules/history/es/createTransitionManager.js +0 -7
- package/node_modules/history/es/warnAboutDeprecatedESMImport.js +0 -35
- package/node_modules/history/esm/history.js +0 -904
- package/node_modules/history/index.js +0 -7
- package/node_modules/history/package.json +0 -134
- package/node_modules/history/umd/history.js +0 -1059
- package/node_modules/history/umd/history.min.js +0 -1
- package/node_modules/history/warnAboutDeprecatedCJSRequire.js +0 -35
- package/templates/app/.npmignore +0 -9
- package/templates/library/.npmignore +0 -9
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
4
|
+
|
5
|
+
var _fs = _interopRequireDefault(require("fs"));
|
6
|
+
|
7
|
+
var _utils = require("../utils");
|
8
|
+
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
|
11
|
+
let options = (0, _utils.getOptions)();
|
12
|
+
const {
|
13
|
+
cssSelectorZipPath
|
14
|
+
} = options.impactService;
|
15
|
+
|
16
|
+
const zipname = _path.default.parse(cssSelectorZipPath).name; // console.log({ cssSelectorZipPath, zipname });
|
17
|
+
// TODO:NOTE: need to check about .. path related files creation
|
18
|
+
// for now no css files have given form react-cli need to make sure about it.
|
19
|
+
|
20
|
+
|
21
|
+
let zippath = _path.default.join(process.cwd(), cssSelectorZipPath);
|
22
|
+
|
23
|
+
if (_fs.default.existsSync(_path.default.join(process.cwd(), cssSelectorZipPath))) {
|
24
|
+
_fs.default.rmSync(zippath);
|
25
|
+
|
26
|
+
console.log('zip file deleted', zippath); // fs.rmSync(zippath, {force:true})
|
27
|
+
// console.log('created folder ==> ', dpath);
|
28
|
+
} // const minicssComment =
|
29
|
+
// '// extracted by mini-css-extract-plugin\n';
|
30
|
+
|
31
|
+
|
32
|
+
const startStr = '// extracted by mini-css-extract-plugin\n' + 'module.exports = ';
|
33
|
+
|
34
|
+
module.exports = function (source) {
|
35
|
+
const {
|
36
|
+
rootContext,
|
37
|
+
resourcePath
|
38
|
+
} = this;
|
39
|
+
|
40
|
+
const relativePath = _path.default.relative(rootContext, resourcePath);
|
41
|
+
|
42
|
+
let fpath = _path.default.join(rootContext, zipname, relativePath);
|
43
|
+
|
44
|
+
let originalpath = _path.default.join(rootContext, relativePath);
|
45
|
+
|
46
|
+
if (relativePath.startsWith('..')) {
|
47
|
+
throw `unexpected path ${relativePath}`;
|
48
|
+
}
|
49
|
+
|
50
|
+
let dpath = fpath.slice(0, fpath.lastIndexOf(_path.default.sep));
|
51
|
+
|
52
|
+
if (!_fs.default.existsSync(originalpath)) {
|
53
|
+
throw `originalpath not exixt ${originalpath}`;
|
54
|
+
}
|
55
|
+
|
56
|
+
if (!_fs.default.existsSync(dpath)) {
|
57
|
+
_fs.default.mkdirSync(dpath, {
|
58
|
+
recursive: true
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
let jsonStr = '{}';
|
63
|
+
|
64
|
+
if (source.startsWith(startStr)) {
|
65
|
+
// source will be like
|
66
|
+
// `// extracted by mini-css-extract-plugin\nmodule.exports = {"app":"zd-app"};`
|
67
|
+
jsonStr = source.slice(startStr.length, -1);
|
68
|
+
}
|
69
|
+
|
70
|
+
_fs.default.writeFileSync(`${fpath}_map`, jsonStr);
|
71
|
+
|
72
|
+
_fs.default.writeFileSync(fpath, _fs.default.readFileSync(originalpath));
|
73
|
+
|
74
|
+
return source;
|
75
|
+
};
|
@@ -0,0 +1,136 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = loader;
|
7
|
+
exports.pitch = pitch;
|
8
|
+
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
10
|
+
|
11
|
+
var _loaderUtils = require("loader-utils");
|
12
|
+
|
13
|
+
var _schemaUtils = _interopRequireDefault(require("schema-utils"));
|
14
|
+
|
15
|
+
var _SingleEntryPlugin = _interopRequireDefault(require("webpack/lib/SingleEntryPlugin"));
|
16
|
+
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
+
|
19
|
+
/* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
|
20
|
+
import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
|
21
|
+
const schema = {
|
22
|
+
'type': 'object',
|
23
|
+
'properties': {
|
24
|
+
'publicPath': {
|
25
|
+
'anyOf': [{
|
26
|
+
'type': 'string'
|
27
|
+
}, {
|
28
|
+
'instanceof': 'Function'
|
29
|
+
}]
|
30
|
+
},
|
31
|
+
'filename': {
|
32
|
+
'anyOf': [{
|
33
|
+
'type': 'string',
|
34
|
+
'minLength': 1
|
35
|
+
}, {
|
36
|
+
'instanceof': 'Function'
|
37
|
+
}]
|
38
|
+
},
|
39
|
+
'chunkFilename': {
|
40
|
+
'type': 'string',
|
41
|
+
'minLength': 1
|
42
|
+
},
|
43
|
+
'esModule': {
|
44
|
+
'type': 'boolean'
|
45
|
+
}
|
46
|
+
},
|
47
|
+
'additionalProperties': false
|
48
|
+
}; // eslint-disable-next-line
|
49
|
+
|
50
|
+
function loader() {}
|
51
|
+
|
52
|
+
function getDefaultFilename(filename) {
|
53
|
+
if (typeof filename === 'function') {
|
54
|
+
return filename;
|
55
|
+
}
|
56
|
+
|
57
|
+
return filename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
|
58
|
+
}
|
59
|
+
|
60
|
+
function getDefaultChunkFilename(chunkFilename) {
|
61
|
+
return chunkFilename.replace(/\.([a-z]+)(\?.+)?$/i, '.worker.$1$2');
|
62
|
+
}
|
63
|
+
|
64
|
+
function pitch(request) {
|
65
|
+
this.cacheable(false);
|
66
|
+
const options = (0, _loaderUtils.getOptions)(this);
|
67
|
+
(0, _schemaUtils.default)(schema, options, {
|
68
|
+
name: 'Worker Loader',
|
69
|
+
baseDataPath: 'options'
|
70
|
+
});
|
71
|
+
const workerContext = {};
|
72
|
+
const compilerOptions = this._compiler.options || {};
|
73
|
+
const filename = options.filename ? options.filename : getDefaultFilename(compilerOptions.output.filename);
|
74
|
+
const chunkFilename = options.chunkFilename ? options.chunkFilename : getDefaultChunkFilename(compilerOptions.output.chunkFilename);
|
75
|
+
const publicPath = options.publicPath ? options.publicPath : compilerOptions.output.publicPath;
|
76
|
+
workerContext.options = {
|
77
|
+
filename,
|
78
|
+
chunkFilename,
|
79
|
+
publicPath,
|
80
|
+
globalObject: 'self'
|
81
|
+
};
|
82
|
+
workerContext.compiler = this._compilation.createChildCompiler(`worker-loader ${request}`, workerContext.options);
|
83
|
+
/*
|
84
|
+
new WebWorkerTemplatePlugin().apply(workerContext.compiler);
|
85
|
+
|
86
|
+
if (compilerOptions.externals) {
|
87
|
+
new ExternalsPlugin(
|
88
|
+
getExternalsType(compilerOptions),
|
89
|
+
compilerOptions.externals
|
90
|
+
).apply(workerContext.compiler);
|
91
|
+
} */
|
92
|
+
|
93
|
+
new _SingleEntryPlugin.default(this.context, `!!${request}`, _path.default.parse(this.resourcePath).name).apply(workerContext.compiler);
|
94
|
+
workerContext.request = request;
|
95
|
+
const cb = this.async();
|
96
|
+
workerContext.compiler.runAsChild((errorArg, entries, compilation) => {
|
97
|
+
let error = errorArg;
|
98
|
+
|
99
|
+
if (!error && compilation.errors && compilation.errors.length) {
|
100
|
+
// eslint-disable-next-line
|
101
|
+
error = compilation.errors[0];
|
102
|
+
}
|
103
|
+
|
104
|
+
const entry = entries && entries[0] && entries[0].files.values().next().value;
|
105
|
+
|
106
|
+
if (!error && !entry) {
|
107
|
+
error = Error(`WorkerPlugin: no entry for ${request}`);
|
108
|
+
}
|
109
|
+
|
110
|
+
if (error) {
|
111
|
+
return cb(error);
|
112
|
+
}
|
113
|
+
|
114
|
+
function workerCode() {
|
115
|
+
let blob;
|
116
|
+
|
117
|
+
try {
|
118
|
+
blob = new Blob([`importScripts('${this.workerUrl}');`], {
|
119
|
+
'type': 'application/javascript'
|
120
|
+
});
|
121
|
+
} catch (e1) {
|
122
|
+
throw new Error(e1);
|
123
|
+
}
|
124
|
+
|
125
|
+
let url = window.URL || window.webkitURL;
|
126
|
+
let blobUrl = url.createObjectURL(blob);
|
127
|
+
let worker = new Worker(blobUrl);
|
128
|
+
return worker;
|
129
|
+
}
|
130
|
+
|
131
|
+
return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} {\n
|
132
|
+
workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
|
133
|
+
getInstance: ${workerCode} \n
|
134
|
+
}`);
|
135
|
+
});
|
136
|
+
}
|
@@ -1,75 +1,43 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = HMRMiddleware;
|
7
|
+
|
7
8
|
function pathMatch(url, path) {
|
8
9
|
if (url === path) {
|
9
10
|
return true;
|
10
11
|
}
|
11
|
-
|
12
|
+
|
13
|
+
let q = url.indexOf('?');
|
14
|
+
|
12
15
|
if (q === -1) {
|
13
16
|
return false;
|
14
17
|
}
|
15
|
-
return url.substring(0, q) === path;
|
16
|
-
}
|
17
|
-
|
18
|
-
function HMRMiddleware(compiler) {
|
19
|
-
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
20
18
|
|
21
|
-
|
22
|
-
// eslint-disable-next-line no-console
|
23
|
-
typeof opts.log === 'undefined' ? console.log.bind(console) : opts.log;
|
24
|
-
opts.path = opts.path || '/__webpack_hmr';
|
25
|
-
opts.heartbeat = opts.heartbeat || 10 * 1000;
|
26
|
-
|
27
|
-
var eventStream = createEventStream(opts.heartbeat);
|
28
|
-
var latestStats = null;
|
29
|
-
|
30
|
-
compiler.plugin('compile', function () {
|
31
|
-
latestStats = null;
|
32
|
-
if (opts.log) {
|
33
|
-
opts.log('webpack building...');
|
34
|
-
}
|
35
|
-
eventStream.publish({ type: 'building' });
|
36
|
-
});
|
37
|
-
compiler.plugin('done', function (statsResult) {
|
38
|
-
// Keep hold of latest stats so they can be propagated to new clients
|
39
|
-
latestStats = statsResult;
|
40
|
-
|
41
|
-
publishStats('built', latestStats, eventStream, opts.log);
|
42
|
-
});
|
43
|
-
var middleware = function middleware(req, res, next) {
|
44
|
-
if (!pathMatch(req.url, opts.path)) {
|
45
|
-
return next();
|
46
|
-
}
|
47
|
-
eventStream.handler(req, res);
|
48
|
-
// if (latestStats) {
|
49
|
-
// // Explicitly not passing in `log` fn as we don't want to log again on
|
50
|
-
// // the server
|
51
|
-
// // publishStats('sync', latestStats, eventStream);
|
52
|
-
// }
|
53
|
-
};
|
54
|
-
middleware.publish = eventStream.publish;
|
55
|
-
return middleware;
|
19
|
+
return url.substring(0, q) === path;
|
56
20
|
}
|
57
21
|
|
58
22
|
function createEventStream(heartbeat) {
|
59
|
-
|
60
|
-
|
23
|
+
let clientId = 0;
|
24
|
+
let clients = {};
|
25
|
+
|
61
26
|
function everyClient(fn) {
|
62
|
-
Object.keys(clients).forEach(
|
27
|
+
Object.keys(clients).forEach(id => {
|
63
28
|
fn(clients[id]);
|
64
29
|
});
|
65
30
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
31
|
+
|
32
|
+
setInterval(() => {
|
33
|
+
everyClient(client => {
|
34
|
+
client.write(`data: ${JSON.stringify({
|
35
|
+
type: 'heartbeat'
|
36
|
+
})}\n\n`);
|
69
37
|
});
|
70
38
|
}, heartbeat).unref();
|
71
39
|
return {
|
72
|
-
handler: function
|
40
|
+
handler: function (req, res) {
|
73
41
|
req.socket.setKeepAlive(true);
|
74
42
|
res.writeHead(200, {
|
75
43
|
'Access-Control-Allow-Origin': '*',
|
@@ -78,28 +46,44 @@ function createEventStream(heartbeat) {
|
|
78
46
|
Connection: 'keep-alive'
|
79
47
|
});
|
80
48
|
res.write('\n');
|
81
|
-
|
49
|
+
let id = clientId++;
|
82
50
|
clients[id] = res;
|
83
|
-
req.on('close',
|
51
|
+
req.on('close', () => {
|
84
52
|
delete clients[id];
|
85
53
|
});
|
86
54
|
},
|
87
|
-
publish: function
|
88
|
-
everyClient(
|
89
|
-
client.write(
|
55
|
+
publish: function (payload) {
|
56
|
+
everyClient(client => {
|
57
|
+
client.write(`data: ${JSON.stringify(payload)}\n\n`);
|
90
58
|
});
|
91
59
|
}
|
92
60
|
};
|
93
61
|
}
|
94
62
|
|
63
|
+
function extractBundles(stats) {
|
64
|
+
// Stats has modules, single bundle
|
65
|
+
if (stats.modules) {
|
66
|
+
return [stats];
|
67
|
+
} // Stats has children, multiple bundles
|
68
|
+
|
69
|
+
|
70
|
+
if (stats.children && stats.children.length) {
|
71
|
+
return stats.children;
|
72
|
+
} // Not sure, assume single
|
73
|
+
|
74
|
+
|
75
|
+
return [stats];
|
76
|
+
}
|
77
|
+
|
95
78
|
function publishStats(action, statsResult, eventStream, log) {
|
96
79
|
// For multi-compiler, stats will be an object with a 'children' array of stats
|
97
|
-
|
98
|
-
|
80
|
+
let bundles = extractBundles(statsResult.toJson({
|
81
|
+
errorDetails: false
|
82
|
+
}));
|
83
|
+
bundles.forEach(stats => {
|
99
84
|
if (log) {
|
100
|
-
log(
|
101
|
-
}
|
102
|
-
// if (
|
85
|
+
log(`webpack built ${stats.name ? `${stats.name} ` : ''}${stats.hash} in ${stats.time}ms`);
|
86
|
+
} // if (
|
103
87
|
// // !force &&
|
104
88
|
// action !== 'sync' &&
|
105
89
|
// stats &&
|
@@ -111,6 +95,8 @@ function publishStats(action, statsResult, eventStream, log) {
|
|
111
95
|
// type: 'still-ok'
|
112
96
|
// });
|
113
97
|
// }
|
98
|
+
|
99
|
+
|
114
100
|
eventStream.publish({
|
115
101
|
type: 'hash',
|
116
102
|
data: stats.hash
|
@@ -134,22 +120,54 @@ function publishStats(action, statsResult, eventStream, log) {
|
|
134
120
|
});
|
135
121
|
}
|
136
122
|
|
137
|
-
function
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
123
|
+
function HMRMiddleware(compiler, opts = {}) {
|
124
|
+
opts.log = // eslint-disable-next-line no-console
|
125
|
+
typeof opts.log === 'undefined' ? console.log.bind(console) : opts.log;
|
126
|
+
opts.path = opts.path || '/__webpack_hmr';
|
127
|
+
opts.heartbeat = opts.heartbeat || 10 * 1000;
|
128
|
+
let eventStream = createEventStream(opts.heartbeat);
|
129
|
+
let latestStats = null;
|
130
|
+
let loggedInfo = false;
|
131
|
+
compiler.hooks.beforeCompile.tap('HMRMiddleware', (c, callback) => {
|
132
|
+
if (opts.log && !loggedInfo) {
|
133
|
+
opts.log('webpack compilation starts...');
|
134
|
+
loggedInfo = true;
|
135
|
+
}
|
142
136
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
137
|
+
callback && callback();
|
138
|
+
});
|
139
|
+
compiler.hooks.compile.tap('HMRMiddleware', () => {
|
140
|
+
latestStats = null;
|
147
141
|
|
148
|
-
|
149
|
-
|
150
|
-
}
|
142
|
+
if (opts.log) {
|
143
|
+
opts.log('webpack building...');
|
144
|
+
}
|
145
|
+
|
146
|
+
eventStream.publish({
|
147
|
+
type: 'building'
|
148
|
+
});
|
149
|
+
});
|
150
|
+
compiler.hooks.done.tap('HMRMiddleware', statsResult => {
|
151
|
+
// Keep hold of latest stats so they can be propagated to new clients
|
152
|
+
latestStats = statsResult;
|
153
|
+
publishStats('built', latestStats, eventStream, opts.log);
|
154
|
+
});
|
155
|
+
|
156
|
+
let middleware = function (req, res, next) {
|
157
|
+
if (!pathMatch(req.url, opts.path)) {
|
158
|
+
return next();
|
159
|
+
}
|
151
160
|
|
152
|
-
//
|
161
|
+
eventStream.handler(req, res); // if (latestStats) {
|
162
|
+
// // Explicitly not passing in `log` fn as we don't want to log again on
|
163
|
+
// // the server
|
164
|
+
// // publishStats('sync', latestStats, eventStream);
|
165
|
+
// }
|
166
|
+
};
|
167
|
+
|
168
|
+
middleware.publish = eventStream.publish;
|
169
|
+
return middleware;
|
170
|
+
} // function buildModuleMap(modules) {
|
153
171
|
// let map = {};
|
154
172
|
// modules.forEach(function(module) {
|
155
173
|
// map[module.id] = module.name;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _utils = require("../utils");
|
9
|
+
|
10
|
+
function SSTMiddleware(compiler, callback) {
|
11
|
+
compiler.hooks.done.tap('SSTMiddleware', stats => {
|
12
|
+
(0, _utils.log)('Compilation finished!');
|
13
|
+
callback(stats.compilation.assets['js/moduleStats.js'].source());
|
14
|
+
});
|
15
|
+
return (res, req, next) => {
|
16
|
+
next();
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
var _default = SSTMiddleware;
|
21
|
+
exports.default = _default;
|