@zohodesk/client_build_tool 0.0.11-exp.33.0 → 0.0.11-exp.35.0

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.
@@ -199,8 +199,7 @@ var _default = {
199
199
  emitFiles: true,
200
200
  injectI18nUrlInIndex: true,
201
201
  customGroups: null,
202
- chunkToGroupMapping: {},
203
- groupPublicPathRuntimeExpression: 'window.__SMAP_PATH__'
202
+ chunkToGroupMapping: {}
204
203
  },
205
204
  publicFolders: {
206
205
  dev: ['...'],
@@ -116,8 +116,7 @@ var _default = {
116
116
  emitFiles: true,
117
117
  injectI18nUrlInIndex: true,
118
118
  customGroups: null,
119
- chunkToGroupMapping: {},
120
- groupPublicPathRuntimeExpression: 'window.__SMAP_PATH__'
119
+ chunkToGroupMapping: {}
121
120
  },
122
121
  publicFolders: {
123
122
  dev: ['...'],
@@ -19,101 +19,38 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
19
19
  customGroups,
20
20
  chunkIdToGroupMapping,
21
21
  localeVarName,
22
- groupAssetUrls,
23
- publicPathRuntimeExpression
22
+ groupAssetUrls
24
23
  } = this.options;
25
24
  const chunkIdToGroup = chunkIdToGroupMapping || {};
26
- const runtimePublicPathResolver = publicPathRuntimeExpression ? `function(){ try { return ${publicPathRuntimeExpression}; } catch (err) { return undefined; } }` : 'function(){ return undefined; }';
25
+ console.log("kiren");
27
26
  return `
28
- // I18n Group Loading Runtime
29
27
  (function() {
30
- var loadedGroups = {};
28
+ var loadedGroups = Object.create(null);
29
+ var loadingGroups = Object.create(null);
31
30
  var chunkIdToGroup = ${JSON.stringify(chunkIdToGroup)};
32
31
  var groupAssetUrls = ${JSON.stringify(groupAssetUrls || {})};
33
- var runtimePublicPathResolver = ${runtimePublicPathResolver};
34
- var cachedDocumentBase;
35
-
36
- function ensureTrailingSlash(path) {
37
- if (!path) return '';
38
- return path.charAt(path.length - 1) === '/' ? path : path + '/';
39
- }
32
+ var groupConfig = ${JSON.stringify(customGroups || {})};
40
33
 
41
34
  function normalizeRelativePath(path) {
42
- if (!path) return '';
43
- return path.charAt(0) === '/' ? path.slice(1) : path;
35
+ return path && path.charAt(0) === '/' ? path.slice(1) : path;
44
36
  }
45
37
 
46
38
  function isFullUrl(value) {
47
- if (typeof value !== 'string') {
48
- return false;
49
- }
50
- return value.indexOf('://') !== -1 || value.startsWith('//');
51
- }
52
-
53
- function getDocumentBase() {
54
- if (cachedDocumentBase !== undefined) {
55
- return cachedDocumentBase;
56
- }
57
-
58
- if (typeof document === 'undefined') {
59
- cachedDocumentBase = '';
60
- return cachedDocumentBase;
61
- }
62
-
63
- var script = document.currentScript;
64
- if (!script) {
65
- var scripts = document.getElementsByTagName('script');
66
- if (scripts.length) {
67
- script = scripts[scripts.length - 1];
68
- }
69
- }
70
-
71
- if (script && script.src) {
72
- var scriptUrl = script.src.replace(/[?#].*$/, '');
73
- var lastSlash = scriptUrl.lastIndexOf('/');
74
- var withoutFile = lastSlash >= 0 ? scriptUrl.slice(0, lastSlash + 1) : '';
75
- var normalized = withoutFile.endsWith('js/')
76
- ? withoutFile.slice(0, withoutFile.length - 3)
77
- : withoutFile;
78
- cachedDocumentBase = ensureTrailingSlash(normalized);
79
- } else {
80
- cachedDocumentBase = '';
81
- }
82
-
83
- return cachedDocumentBase;
84
- }
85
-
86
- function resolveRuntimePublicPath() {
87
- var dynamicBase = runtimePublicPathResolver();
88
- if (dynamicBase != null && dynamicBase !== '') {
89
- return ensureTrailingSlash(String(dynamicBase));
90
- }
91
-
92
- var webpackPublicPath = ${_webpack.RuntimeGlobals.publicPath};
93
- if (typeof webpackPublicPath === 'string' && webpackPublicPath) {
94
- return ensureTrailingSlash(webpackPublicPath);
95
- }
96
-
97
- var documentBase = getDocumentBase();
98
- if (documentBase) {
99
- return documentBase;
100
- }
101
-
102
- return '';
39
+ return typeof value === 'string' && (value.indexOf('://') !== -1 || value.indexOf('//') === 0);
103
40
  }
104
41
 
105
42
  function buildI18nUrl(relativePath) {
106
- if (!relativePath) {
107
- return resolveRuntimePublicPath();
108
- }
109
-
110
43
  if (isFullUrl(relativePath)) {
111
44
  return relativePath;
112
45
  }
113
-
114
46
  var normalizedPath = normalizeRelativePath(relativePath);
115
- var base = resolveRuntimePublicPath();
116
- return base + normalizedPath;
47
+ var publicPath = ${_webpack.RuntimeGlobals.publicPath};
48
+
49
+ if (typeof publicPath === 'undefined' || publicPath === 'undefined') {
50
+ publicPath = '';
51
+ }
52
+
53
+ return publicPath + normalizedPath;
117
54
  }
118
55
 
119
56
  function loadI18nGroup(groupName) {
@@ -121,15 +58,22 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
121
58
  return Promise.resolve();
122
59
  }
123
60
 
124
- var locale = ${localeVarName} || 'en_US';
125
- var groupConfig = ${JSON.stringify(customGroups)};
126
- var config = groupConfig[groupName];
61
+ if (loadingGroups[groupName]) {
62
+ return loadingGroups[groupName];
63
+ }
127
64
 
65
+ var config = groupConfig[groupName];
128
66
  if (!config) {
129
67
  return Promise.resolve();
130
68
  }
131
69
 
132
- return new Promise(function(resolve, reject) {
70
+ if (typeof document === 'undefined' || !document.head || !document.createElement) {
71
+ return Promise.resolve();
72
+ }
73
+
74
+ var locale = ${localeVarName} || 'en_US';
75
+
76
+ var loadPromise = new Promise(function(resolve, reject) {
133
77
  var relativePath;
134
78
 
135
79
  if (groupAssetUrls[groupName] && groupAssetUrls[groupName][locale]) {
@@ -139,14 +83,24 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
139
83
  }
140
84
 
141
85
  var i18nUrl = buildI18nUrl(relativePath);
142
-
143
86
  var script = document.createElement('script');
87
+
144
88
  script.src = i18nUrl;
145
89
  script.async = true;
90
+
146
91
  if (typeof __webpack_require__ !== 'undefined' && __webpack_require__.nc) {
147
92
  script.setAttribute('nonce', __webpack_require__.nc);
148
93
  }
149
94
 
95
+ var target = document.head || document.getElementsByTagName('head')[0] || document.documentElement;
96
+
97
+ if (!target) {
98
+ loadedGroups[groupName] = true;
99
+ delete loadingGroups[groupName];
100
+ resolve();
101
+ return;
102
+ }
103
+
150
104
  var cleanup = function() {
151
105
  if (script.parentNode) {
152
106
  script.parentNode.removeChild(script);
@@ -155,20 +109,27 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
155
109
 
156
110
  script.onload = function() {
157
111
  loadedGroups[groupName] = true;
112
+ delete loadingGroups[groupName];
158
113
  cleanup();
159
114
  resolve();
160
115
  };
161
116
 
162
117
  script.onerror = function(err) {
118
+ delete loadingGroups[groupName];
163
119
  cleanup();
164
- if (typeof console !== 'undefined' && console.warn) {
165
- console.warn('Failed to load i18n group', groupName, 'from', i18nUrl, err);
120
+ var errorMessage = 'Failed to load i18n group: ' + groupName + ' from ' + i18nUrl;
121
+ if (err && err.message) {
122
+ errorMessage += ' (' + err.message + ')';
166
123
  }
167
- reject(new Error('Failed to load i18n group: ' + groupName));
124
+ reject(new Error(errorMessage));
168
125
  };
169
126
 
170
- document.head.appendChild(script);
127
+ target.appendChild(script);
171
128
  });
129
+
130
+ loadingGroups[groupName] = loadPromise;
131
+
132
+ return loadPromise;
172
133
  }
173
134
 
174
135
  function findGroupByChunkId(chunkId) {
@@ -187,12 +148,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
187
148
  };
188
149
 
189
150
  function detectGroupFromUrl() {
190
- if (typeof window === 'undefined') {
191
- return null;
192
- }
193
-
194
151
  var url = window.location.href;
195
- var groupConfig = ${JSON.stringify(customGroups)};
196
152
 
197
153
  for (var groupName in groupConfig) {
198
154
  if (!Object.prototype.hasOwnProperty.call(groupConfig, groupName)) {
@@ -200,12 +156,12 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
200
156
  }
201
157
 
202
158
  var config = groupConfig[groupName];
203
- if (config && Array.isArray(config.urlPatterns)) {
204
- for (var i = 0; i < config.urlPatterns.length; i++) {
205
- var pattern = config.urlPatterns[i];
206
- if (pattern && url.indexOf(pattern) !== -1) {
207
- return groupName;
208
- }
159
+ if (!config.urlPatterns || !Array.isArray(config.urlPatterns)) {
160
+ continue;
161
+ }
162
+ for (var i = 0; i < config.urlPatterns.length; i++) {
163
+ if (url.indexOf(config.urlPatterns[i]) !== -1) {
164
+ return groupName;
209
165
  }
210
166
  }
211
167
  }
@@ -217,20 +173,49 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
217
173
  try {
218
174
  var detectedGroup = detectGroupFromUrl();
219
175
  if (detectedGroup && !loadedGroups[detectedGroup]) {
220
- loadI18nGroup(detectedGroup).catch(function(err) {
221
- if (typeof console !== 'undefined' && console.warn) {
222
- console.warn('Failed to preload i18n group', detectedGroup, err);
223
- }
224
- });
176
+ loadI18nGroup(detectedGroup).catch(function() {});
225
177
  }
226
- } catch (err) {
227
- if (typeof console !== 'undefined' && console.warn) {
228
- console.warn('Error during i18n group detection', err);
178
+ } catch (err) {}
179
+ }
180
+
181
+ function safeCheckAndLoadGroupFromUrl() {
182
+ var publicPath = ${_webpack.RuntimeGlobals.publicPath};
183
+ if (typeof publicPath === 'undefined' || publicPath === 'undefined') {
184
+ if (typeof document !== 'undefined' && document.readyState === 'loading') {
185
+ document.addEventListener('DOMContentLoaded', checkAndLoadGroupFromUrl);
186
+ } else {
187
+ setTimeout(checkAndLoadGroupFromUrl, 0);
229
188
  }
189
+ } else {
190
+ checkAndLoadGroupFromUrl();
230
191
  }
231
192
  }
232
193
 
233
- checkAndLoadGroupFromUrl();
194
+ safeCheckAndLoadGroupFromUrl();
195
+
196
+ if (typeof window !== 'undefined' && window.history) {
197
+ var originalPushState = window.history.pushState;
198
+ var originalReplaceState = window.history.replaceState;
199
+
200
+ if (originalPushState) {
201
+ window.history.pushState = function() {
202
+ var result = originalPushState.apply(this, arguments);
203
+ checkAndLoadGroupFromUrl();
204
+ return result;
205
+ };
206
+ }
207
+
208
+ if (originalReplaceState) {
209
+ window.history.replaceState = function() {
210
+ var result = originalReplaceState.apply(this, arguments);
211
+ checkAndLoadGroupFromUrl();
212
+ return result;
213
+ };
214
+ }
215
+
216
+ window.addEventListener('popstate', checkAndLoadGroupFromUrl);
217
+ window.addEventListener('hashchange', checkAndLoadGroupFromUrl);
218
+ }
234
219
  })();
235
220
  `;
236
221
  }
@@ -23,16 +23,12 @@ class I18nNumericIndexHtmlInjectorPlugin {
23
23
  }
24
24
 
25
25
  apply(compiler) {
26
- console.log(`[I18nNumericIndexHtmlInjectorPlugin] Plugin loaded - v1.0.0`);
27
26
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
28
- _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (hookData, cb) => {
27
+ _htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, cb) => {
29
28
  if (!this.options.injectI18nUrlInIndex) {
30
- return cb(null, hookData);
29
+ return cb(null, data);
31
30
  }
32
31
 
33
- const {
34
- assets
35
- } = hookData;
36
32
  const {
37
33
  outputFolder = 'i18n-chunk',
38
34
  numericFilenameTemplate,
@@ -42,7 +38,7 @@ class I18nNumericIndexHtmlInjectorPlugin {
42
38
  singleFile,
43
39
  i18nAssetsPublicPathPrefix = ''
44
40
  } = this.options;
45
- const newI18nAssetUrlsToAdd = [];
41
+ const i18nScriptTags = [];
46
42
  const emittedAssetNames = compilation.getAssets().map(asset => asset.name);
47
43
  const recordedAssets = compilation[assetStoreKey] || [];
48
44
 
@@ -83,27 +79,48 @@ class I18nNumericIndexHtmlInjectorPlugin {
83
79
  const combinedFilename = resolveAssetPath(singleFileTemplate, 'single');
84
80
 
85
81
  if (combinedFilename) {
86
- newI18nAssetUrlsToAdd.push(combinedFilename);
82
+ i18nScriptTags.push({
83
+ tagName: 'script',
84
+ voidTag: false,
85
+ attributes: {
86
+ src: combinedFilename,
87
+ nonce: '{{--CSP-nonce}}'
88
+ }
89
+ });
87
90
  }
88
91
  } else {
89
92
  const numericFilename = resolveAssetPath(numericFilenameTemplate, 'numeric');
90
93
 
91
94
  if (numericFilename) {
92
- newI18nAssetUrlsToAdd.push(numericFilename);
95
+ i18nScriptTags.push({
96
+ tagName: 'script',
97
+ voidTag: false,
98
+ attributes: {
99
+ src: numericFilename,
100
+ nonce: '{{--CSP-nonce}}'
101
+ }
102
+ });
93
103
  }
94
104
 
95
105
  const dynamicFilename = resolveAssetPath(dynamicFilenameTemplate, 'dynamic');
96
106
 
97
107
  if (dynamicFilename) {
98
- newI18nAssetUrlsToAdd.push(dynamicFilename);
108
+ i18nScriptTags.push({
109
+ tagName: 'script',
110
+ voidTag: false,
111
+ attributes: {
112
+ src: dynamicFilename,
113
+ nonce: '{{--CSP-nonce}}'
114
+ }
115
+ });
99
116
  }
100
117
  }
101
118
 
102
- if (newI18nAssetUrlsToAdd.length > 0) {
103
- assets.js = [...newI18nAssetUrlsToAdd, ...assets.js];
119
+ if (i18nScriptTags.length > 0) {
120
+ data.headTags = [...i18nScriptTags, ...data.headTags];
104
121
  }
105
122
 
106
- return cb(null, hookData);
123
+ cb(null, data);
107
124
  });
108
125
  });
109
126
  }
@@ -53,8 +53,7 @@ class I18nNumericIndexPlugin {
53
53
  outputFolder: options.outputFolder || 'i18n-chunk',
54
54
  manifestPath: options.manifestPath || null,
55
55
  emitFiles: options.emitFiles !== undefined ? options.emitFiles : true,
56
- chunkToGroupMapping: options.chunkToGroupMapping || {},
57
- groupPublicPathRuntimeExpression: options.groupPublicPathRuntimeExpression || ''
56
+ chunkToGroupMapping: options.chunkToGroupMapping || {}
58
57
  };
59
58
  this.numericMap = {};
60
59
  this.customGroups = {};
@@ -67,7 +66,6 @@ class I18nNumericIndexPlugin {
67
66
  }
68
67
 
69
68
  apply(compiler) {
70
- console.log(`[I18nNumericIndexPlugin] Plugin loaded - v1.0.0`);
71
69
  this.detectI18nGroupComments(compiler);
72
70
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
73
71
  this.groupAssetUrls = {};
@@ -86,10 +84,7 @@ class I18nNumericIndexPlugin {
86
84
  customGroups: this.options.customGroups,
87
85
  chunkIdToGroupMapping: chunkMapping,
88
86
  localeVarName: this.options.localeVarName,
89
- jsonpFunc: this.options.jsonpFunc,
90
- groupAssetUrls: this.groupAssetUrls,
91
- includeContentHash: this.options.includeContentHash,
92
- publicPathRuntimeExpression: this.options.groupPublicPathRuntimeExpression
87
+ groupAssetUrls: this.groupAssetUrls
93
88
  }));
94
89
  }
95
90
  });
@@ -177,9 +172,7 @@ class I18nNumericIndexPlugin {
177
172
  }
178
173
  }
179
174
  });
180
- } catch (err) {
181
- console.warn(`[I18nNumericIndexPlugin] Failed to read properties folder: ${err.message}`);
182
- }
175
+ } catch (err) {}
183
176
 
184
177
  return locales;
185
178
  }
@@ -208,7 +201,6 @@ class I18nNumericIndexPlugin {
208
201
  ...this.normalizeObjectValues(localeProperties)
209
202
  };
210
203
  } catch (err) {
211
- console.warn(`[I18nNumericIndexPlugin] Failed to load locale ${locale}: ${err.message}`);
212
204
  return;
213
205
  }
214
206
  }
@@ -291,12 +283,20 @@ class I18nNumericIndexPlugin {
291
283
  }
292
284
 
293
285
  compilation.fileDependencies.add(_path.default.resolve(jsResourcePath));
294
- compilation.fileDependencies.add(_path.default.resolve(propertiesFolderPath));
295
286
 
296
287
  if (numericMapPath) {
297
288
  compilation.fileDependencies.add(_path.default.resolve(numericMapPath));
298
- } // Reset caches for incremental builds
289
+ }
299
290
 
291
+ try {
292
+ const propertiesFiles = _fs.default.readdirSync(propertiesFolderPath);
293
+
294
+ propertiesFiles.forEach(file => {
295
+ if (file.endsWith('.properties')) {
296
+ compilation.fileDependencies.add(_path.default.resolve(propertiesFolderPath, file));
297
+ }
298
+ });
299
+ } catch (err) {}
300
300
 
301
301
  this.numericMap = {};
302
302
  this.manifest = {};
@@ -322,10 +322,9 @@ class I18nNumericIndexPlugin {
322
322
  }
323
323
 
324
324
  const availableLocales = this.getAvailableLocales(propertiesFolderPath);
325
- console.log(`[I18nNumericIndexPlugin] Processing ${availableLocales.length} locales:`, availableLocales.join(', '));
326
325
  availableLocales.forEach(locale => {
327
326
  this.processLocale(locale, jsResourceKeys, propertiesFolderPath, compilation);
328
- }); // Generate manifest file if enabled
327
+ });
329
328
 
330
329
  if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
331
330
  const manifestPath = this.options.manifestPath || _path.default.join(this.options.outputFolder, 'manifest.json');
@@ -431,7 +430,7 @@ class I18nNumericIndexPlugin {
431
430
  }
432
431
 
433
432
  const content = this.generateChunkContent(data, jsonpFunc, groupName);
434
- let outputPath = this.constructFilePath(filenameTemplate, locale); // Handle [contenthash] placeholder in template
433
+ let outputPath = this.constructFilePath(filenameTemplate, locale);
435
434
 
436
435
  if (outputPath.includes('[contenthash]')) {
437
436
  const contentHash = this.generateContentHash(content, compilation);
@@ -439,8 +438,7 @@ class I18nNumericIndexPlugin {
439
438
  } else if (this.options.includeContentHash) {
440
439
  const contentHash = this.generateContentHash(content, compilation);
441
440
  outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
442
- } // Track in manifest if enabled
443
-
441
+ }
444
442
 
445
443
  if (this.options.generateManifest) {
446
444
  const manifestKey = this.options.singleFile ? `${locale}.js` : outputPath;
@@ -107,6 +107,7 @@ function loadI18nData(options, compilation) {
107
107
  allI18n,
108
108
  locales
109
109
  } = loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase);
110
+ console.log("kiren");
110
111
  return {
111
112
  jsResourceBase,
112
113
  allI18n,
@@ -21,12 +21,6 @@ function configI18nNumericIndexPlugin(options) {
21
21
  }
22
22
 
23
23
  const i18nOpts = options.i18nIndexing;
24
- const cdnMapping = options.cdnMapping || {};
25
- const cdnVariableName = cdnMapping.variableName || 'window.__SMAP_PATH__';
26
- const {
27
- groupPublicPathRuntimeExpression: configuredRuntimeExpression
28
- } = i18nOpts;
29
- const groupPublicPathRuntimeExpression = configuredRuntimeExpression !== undefined ? configuredRuntimeExpression : cdnVariableName;
30
24
 
31
25
  try {
32
26
  const result = (0, _i18nOptionsValidator.validateI18nIndexingOptions)(i18nOpts);
@@ -86,8 +80,7 @@ function configI18nNumericIndexPlugin(options) {
86
80
  manifestPath: i18nOpts.manifestPath || null,
87
81
  customGroups: i18nOpts.customGroups || null,
88
82
  chunkToGroupMapping: i18nOpts.chunkToGroupMapping || {},
89
- emitFiles,
90
- groupPublicPathRuntimeExpression
83
+ emitFiles
91
84
  };
92
85
  const htmlInjectorOptions = { ...sharedOptions,
93
86
  htmlTemplateLabel: i18nOpts.htmlTemplateLabel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.11-exp.33.0",
3
+ "version": "0.0.11-exp.35.0",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {