@zohodesk/client_build_tool 0.0.6-exp.6 → 0.0.6-exp.8

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.
@@ -7,14 +7,20 @@ exports.default = void 0;
7
7
 
8
8
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
9
 
10
- var _nameTemplates = require("../common/nameTemplates");
10
+ var _webpack = require("webpack");
11
11
 
12
- var _modeUtils = require("../common/modeUtils");
12
+ var _nameTemplates = require("../../common/nameTemplates");
13
+
14
+ var _modeUtils = require("../../common/modeUtils");
15
+
16
+ var _webpackCustomJsUrlLoader = _interopRequireDefault(require("./webpackCustomJsUrlLoader"));
13
17
 
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
19
 
16
20
  // import { RuntimeGlobals, RuntimeModule } from 'webpack';
21
+ // eslint-disable-next-line import/extensions
17
22
  // import { Template } from 'webpack';
23
+ // eslint-disable-next-line import/extensions
18
24
  const pluginName = 'CdnChangePlugin'; // const MODULE_TYPE = 'css/mini-extract';
19
25
  // class CdnChangeRuntimePlugin extends RuntimeModule {
20
26
  // constructor(compiler, { variableName }) {
@@ -80,6 +86,12 @@ class CdnChangePlugin {
80
86
  };
81
87
  cb && cb(null, data);
82
88
  });
89
+
90
+ compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.getChunkScriptFilename).tap(pluginName, (chunk, set) => {
91
+ compilation.addRuntimeModule(chunk, // eslint-disable-next-line new-cap
92
+ new _webpackCustomJsUrlLoader.default('javascript', 'javascript', _webpack.RuntimeGlobals.getChunkScriptFilename, chunk => chunk.filenameTemplate || (chunk.canBeInitial() ? compilation.outputOptions.filename : compilation.outputOptions.chunkFilename), false));
93
+ return true;
94
+ });
83
95
  });
84
96
  }
85
97
 
@@ -0,0 +1,265 @@
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
+ const first = set => {
11
+ const entry = set.values().next();
12
+ return entry.done ? undefined : entry.value;
13
+ };
14
+
15
+ class CustomizedGetChunkFilenameRuntimeModule extends _webpack.RuntimeModule {
16
+ /**
17
+ * @param {string} contentType the contentType to use the content hash for
18
+ * @param {string} name kind of filename
19
+ * @param {string} global function name to be assigned
20
+ * @param {function(Chunk): string | FilenameFunction} getFilenameForChunk functor to get the filename or function
21
+ * @param {boolean} allChunks when false, only async chunks are included
22
+ */
23
+ constructor(contentType, name, global, getFilenameForChunk, allChunks) {
24
+ super(`get ${name} chunk filename`);
25
+ this.contentType = contentType;
26
+ this.global = global;
27
+ this.getFilenameForChunk = getFilenameForChunk;
28
+ this.allChunks = allChunks;
29
+ this.dependentHash = true;
30
+ }
31
+
32
+ generate() {
33
+ const {
34
+ global,
35
+ chunk,
36
+ chunkGraph,
37
+ contentType,
38
+ getFilenameForChunk,
39
+ allChunks,
40
+ compilation
41
+ } = this;
42
+ const {
43
+ runtimeTemplate
44
+ } = compilation;
45
+ /** @type {Map<string | FilenameFunction, Set<Chunk>>} */
46
+
47
+ const chunkFilenames = new Map();
48
+ let maxChunks = 0;
49
+ /** @type {string} */
50
+
51
+ let dynamicFilename;
52
+ /**
53
+ * @param {Chunk} c the chunk
54
+ * @returns {void}
55
+ */
56
+
57
+ const addChunk = c => {
58
+ const chunkFilename = getFilenameForChunk(c);
59
+
60
+ if (chunkFilename) {
61
+ let set = chunkFilenames.get(chunkFilename);
62
+
63
+ if (set === undefined) {
64
+ chunkFilenames.set(chunkFilename, set = new Set());
65
+ }
66
+
67
+ set.add(c);
68
+
69
+ if (typeof chunkFilename === 'string') {
70
+ if (set.size < maxChunks) return;
71
+
72
+ if (set.size === maxChunks) {
73
+ if (chunkFilename.length < dynamicFilename.length) return;
74
+
75
+ if (chunkFilename.length === dynamicFilename.length) {
76
+ if (chunkFilename < dynamicFilename) return;
77
+ }
78
+ }
79
+
80
+ maxChunks = set.size;
81
+ dynamicFilename = chunkFilename;
82
+ }
83
+ }
84
+ };
85
+ /** @type {string[]} */
86
+
87
+
88
+ const includedChunksMessages = [];
89
+
90
+ if (allChunks) {
91
+ includedChunksMessages.push('all chunks');
92
+
93
+ for (const c of chunk.getAllReferencedChunks()) {
94
+ addChunk(c);
95
+ }
96
+ } else {
97
+ includedChunksMessages.push('async chunks');
98
+
99
+ for (const c of chunk.getAllAsyncChunks()) {
100
+ addChunk(c);
101
+ }
102
+
103
+ const includeEntries = chunkGraph.getTreeRuntimeRequirements(chunk).has(_webpack.RuntimeGlobals.ensureChunkIncludeEntries);
104
+
105
+ if (includeEntries) {
106
+ includedChunksMessages.push('sibling chunks for the entrypoint');
107
+
108
+ for (const c of chunkGraph.getChunkEntryDependentChunksIterable(chunk)) {
109
+ addChunk(c);
110
+ }
111
+ }
112
+ }
113
+
114
+ for (const entrypoint of chunk.getAllReferencedAsyncEntrypoints()) {
115
+ addChunk(entrypoint.chunks[entrypoint.chunks.length - 1]);
116
+ }
117
+ /** @type {Map<string, Set<string | number>>} */
118
+
119
+
120
+ const staticUrls = new Map();
121
+ /** @type {Set<Chunk>} */
122
+
123
+ const dynamicUrlChunks = new Set();
124
+ /**
125
+ * @param {Chunk} c the chunk
126
+ * @param {string | FilenameFunction} chunkFilename the filename template for the chunk
127
+ * @returns {void}
128
+ */
129
+
130
+ const addStaticUrl = (c, chunkFilename) => {
131
+ /**
132
+ * @param {string | number} value a value
133
+ * @returns {string} string to put in quotes
134
+ */
135
+ const unquotedStringify = value => {
136
+ const str = `${value}`;
137
+
138
+ if (str.length >= 5 && str === `${c.id}`) {
139
+ // This is shorter and generates the same result
140
+ return '" + chunkId + "';
141
+ }
142
+
143
+ const s = JSON.stringify(str);
144
+ return s.slice(1, s.length - 1);
145
+ };
146
+
147
+ const unquotedStringifyWithLength = value => length => unquotedStringify(`${value}`.slice(0, length));
148
+
149
+ const chunkFilenameValue = typeof chunkFilename === 'function' ? JSON.stringify(chunkFilename({
150
+ chunk: c,
151
+ contentHashType: contentType
152
+ })) : JSON.stringify(chunkFilename);
153
+ const staticChunkFilename = compilation.getPath(chunkFilenameValue, {
154
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
155
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
156
+ chunk: {
157
+ id: unquotedStringify(c.id),
158
+ hash: unquotedStringify(c.renderedHash),
159
+ hashWithLength: unquotedStringifyWithLength(c.renderedHash),
160
+ name: unquotedStringify(c.name || c.id),
161
+ contentHash: {
162
+ [contentType]: unquotedStringify(c.contentHash[contentType])
163
+ },
164
+ contentHashWithLength: {
165
+ [contentType]: unquotedStringifyWithLength(c.contentHash[contentType])
166
+ }
167
+ },
168
+ contentHashType: contentType
169
+ });
170
+ let set = staticUrls.get(staticChunkFilename);
171
+
172
+ if (set === undefined) {
173
+ staticUrls.set(staticChunkFilename, set = new Set());
174
+ }
175
+
176
+ set.add(c.id);
177
+ };
178
+
179
+ for (const [filename, chunks] of chunkFilenames) {
180
+ if (filename !== dynamicFilename) {
181
+ for (const c of chunks) addStaticUrl(c, filename);
182
+ } else {
183
+ for (const c of chunks) dynamicUrlChunks.add(c);
184
+ }
185
+ }
186
+ /**
187
+ * @param {function(Chunk): string | number} fn function from chunk to value
188
+ * @returns {string} code with static mapping of results of fn
189
+ */
190
+
191
+
192
+ const createMap = fn => {
193
+ const obj = {};
194
+ let useId = false;
195
+ let lastKey;
196
+ let entries = 0; // eslint-disable-next-line no-restricted-syntax
197
+
198
+ for (const c of dynamicUrlChunks) {
199
+ const value = fn(c);
200
+
201
+ if (value === c.id) {
202
+ useId = true;
203
+ } else {
204
+ obj[c.id] = value;
205
+ lastKey = c.id;
206
+ entries++;
207
+ }
208
+ }
209
+
210
+ if (entries === 0) return 'chunkId';
211
+
212
+ if (entries === 1) {
213
+ return useId ? `(chunkId === ${JSON.stringify(lastKey)} ? ${JSON.stringify(obj[lastKey])} : chunkId)` : JSON.stringify(obj[lastKey]);
214
+ }
215
+
216
+ return useId ? `(${JSON.stringify(obj)}[chunkId] || chunkId)` : `${JSON.stringify(obj)}[chunkId]`;
217
+ };
218
+ /**
219
+ * @param {function(Chunk): string | number} fn function from chunk to value
220
+ * @returns {string} code with static mapping of results of fn for including in quoted string
221
+ */
222
+
223
+
224
+ const mapExpr = fn => {
225
+ return `" + ${createMap(fn)} + "`;
226
+ };
227
+ /**
228
+ * @param {function(Chunk): string | number} fn function from chunk to value
229
+ * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
230
+ */
231
+
232
+
233
+ const mapExprWithLength = fn => length => {
234
+ return `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
235
+ };
236
+
237
+ const url = dynamicFilename && compilation.getPath(JSON.stringify(dynamicFilename), {
238
+ hash: `" + ${_webpack.RuntimeGlobals.getFullHash}() + "`,
239
+ hashWithLength: length => `" + ${_webpack.RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
240
+ chunk: {
241
+ id: `" + chunkId + "`,
242
+ hash: mapExpr(c => c.renderedHash),
243
+ hashWithLength: mapExprWithLength(c => c.renderedHash),
244
+ name: mapExpr(c => c.name || c.id),
245
+ contentHash: {
246
+ [contentType]: mapExpr(c => c.contentHash[contentType])
247
+ },
248
+ contentHashWithLength: {
249
+ [contentType]: mapExprWithLength(c => c.contentHash[contentType])
250
+ }
251
+ },
252
+ contentHashType: contentType
253
+ });
254
+ const cdn = `__CSS_CDN__`;
255
+ return _webpack.Template.asString([`// This function allow to reference ${inclucdndedChunksMessages.join(' and ')}`, `${global} = ${runtimeTemplate.basicFunction('chunkId', staticUrls.size > 0 ? ['// return url for filenames not based on template', // it minimizes to `x===1?"...":x===2?"...":"..."`
256
+ _webpack.Template.asString(Array.from(staticUrls, ([url, ids]) => {
257
+ const condition = ids.size === 1 ? `chunkId === ${JSON.stringify(first(ids))}` : `{${Array.from(ids, id => `${JSON.stringify(id)}:1`).join(',')}}[chunkId]`;
258
+ return `if (${condition}) return window.${cdn}+${url};`;
259
+ })), '// return url for filenames based on template', `return window.${cdn}+${url};`] : ['// return url for filenames based on template', `return window.${cdn}+${url};`])};`]);
260
+ }
261
+
262
+ }
263
+
264
+ var _default = CustomizedGetChunkFilenameRuntimeModule;
265
+ exports.default = _default;
@@ -33,10 +33,16 @@ class SourceMapPlugin {
33
33
  name: pluginName,
34
34
  stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
35
35
  }, assets => {
36
+ console.log('working');
36
37
  Object.keys(assets).forEach(assetName => {
38
+ if (assetName.includes('runtime')) {
39
+ console.log(assetName, true);
40
+ }
41
+
37
42
  const assetCode = assets[assetName].source();
38
43
 
39
- if (checkSmapFilePattern(assetName) && skipRuntimeFiles(assetName)) {
44
+ if (checkSmapFilePattern(assetName) // skipRuntimeFiles(assetName)
45
+ ) {
40
46
  compilation.renameAsset(assetName, `smap/${assetName}`);
41
47
 
42
48
  if (!/\.map$/.test(assetName)) {
@@ -47,12 +47,10 @@ var _configBundleIntegrityReport = require("./pluginConfigs/configBundleIntegrit
47
47
 
48
48
  var _configRuntimeResourceCleanup = require("./pluginConfigs/configRuntimeResourceCleanup");
49
49
 
50
- var _configDummy = require("./pluginConfigs/configDummy");
51
-
52
50
  // import { IgnorePlugin } from 'webpack';
53
51
  function plugins(options) {
54
52
  const {
55
53
  webpackPlugins
56
54
  } = options;
57
- return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), (0, _configDummy.configDummy)(options), ...webpackPlugins].filter(Boolean);
55
+ return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
58
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.6-exp.6",
3
+ "version": "0.0.6-exp.8",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Dummy = void 0;
7
-
8
- var _webpack = require("webpack");
9
-
10
- class Dummy {
11
- constructor() {
12
- this.variableName = '__CSS_CDN__';
13
- } // eslint-disable-next-line class-methods-use-this
14
-
15
-
16
- apply(compiler) {
17
- // Access processAssets hook from v5 API
18
- const {
19
- RawSource
20
- } = compiler.webpack.sources;
21
- compiler.hooks.compilation.tap('MyCutomPlugin', compilation => {
22
- compilation.hooks.processAssets.tap({
23
- name: 'MyCustomPlugin',
24
- stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS // Choose an appropriate stage based on your needs
25
-
26
- }, assets => {
27
- console.log('working'); // Here you can interact with assets
28
-
29
- const asset = 'js/runtime~main'; // Replace with your actual chunk file name pattern
30
-
31
- Object.keys(assets).forEach(assetName => {
32
- // if (assetName.includes('main')) console.log(assetName);
33
- // });
34
- if (assetName.includes(asset)) {
35
- console.log('found');
36
- const originalSource = assets[assetName].source(); // console.log(originalSource);
37
-
38
- const modifiedSource = originalSource.replace('__webpack_require__.p + __webpack_require__.u(chunkId);', `window['${this.variableName}'] + __webpack_require__.u(chunkId);`);
39
- console.log(assetName); // console.log(modifiedSource);
40
- // console.log(a);
41
- // Apply your modifications here
42
- // const modifiedSource = someModificationFunction(originalSource);
43
- // Update the asset's source
44
- // eslint-disable-next-line no-param-reassign
45
-
46
- compilation.updateAsset(assetName, new RawSource(modifiedSource));
47
- }
48
- });
49
- });
50
- });
51
- }
52
-
53
- }
54
-
55
- exports.Dummy = Dummy;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.configDummy = configDummy;
7
-
8
- var _dummy = require("../custom_plugins/dummy");
9
-
10
- function configDummy(options) {
11
- console.log('running');
12
- return new _dummy.Dummy();
13
- }