@zohodesk/client_build_tool 0.0.13-exp.4 → 0.0.13-exp.5

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.
@@ -355,6 +355,10 @@ var _default = {
355
355
  enable: false,
356
356
  chunkName: '',
357
357
  filePath: ''
358
+ },
359
+ enableSubResourceIntegrity: {
360
+ value: false,
361
+ cli: 'enable_sub_resource_integrity'
358
362
  }
359
363
  };
360
364
  exports.default = _default;
@@ -16,13 +16,28 @@ class InitialHtmlPlugin {
16
16
  this.options = options;
17
17
  }
18
18
 
19
+ getBaseName(str) {
20
+ const fileName = str.split("/").pop();
21
+ const parts = fileName.split("."); // Find index of the hash-like segment
22
+
23
+ const hashIndex = parts.findIndex(p => /^[0-9a-f_]{20,}$/i.test(p)); // If a hash is found, return everything before it
24
+
25
+ if (hashIndex < 0) {
26
+ console.error('this initial file dont have a hash');
27
+ return parts.slice(0, -1).join(".");
28
+ }
29
+
30
+ return parts.slice(0, hashIndex).join("."); // Otherwise fallback: remove only ".js"
31
+ }
32
+
19
33
  apply(compiler) {
20
34
  const {
21
35
  filename,
22
36
  template,
23
37
  minify,
24
38
  inject,
25
- mainChunkName
39
+ mainChunkName,
40
+ enableSubResourceIntegrity
26
41
  } = this.options;
27
42
  new _htmlWebpackPlugin.default({
28
43
  filename,
@@ -37,13 +52,36 @@ class InitialHtmlPlugin {
37
52
  const headTags = [];
38
53
  const bodyTags = [];
39
54
  data.headTags.forEach(tag => {
55
+ const url = tag.attributes?.src || tag.attributes?.href;
56
+ let chunkName;
57
+
58
+ const addIntegrity = (tag, suffix) => {
59
+ if (enableSubResourceIntegrity && chunkName) {
60
+ Object.assign(tag.attributes, {
61
+ integrity: `{{--${chunkName}-${suffix}-integrity}}`
62
+ });
63
+ }
64
+ };
65
+
66
+ if (enableSubResourceIntegrity) {
67
+ chunkName = this.getBaseName(url);
68
+ }
69
+
40
70
  Object.assign(tag.attributes, {
41
- nonce: '{{--CSP-nonce}}'
71
+ nonce: '{{--CSP-nonce}}',
72
+ crossorigin: "anonymous"
42
73
  });
43
74
 
44
75
  if (tag.tagName === 'link') {
76
+ addIntegrity(tag, 'css');
45
77
  headTags.push(tag);
46
78
  } else {
79
+ if (url.endsWith('.i18n.js')) {
80
+ addIntegrity(tag, 'i18n');
81
+ } else {
82
+ addIntegrity(tag, 'js');
83
+ }
84
+
47
85
  bodyTags.push(tag);
48
86
  }
49
87
  });
@@ -16,7 +16,8 @@ var _InitialHtmlPlugin = require("../custom_plugins/InitialHtmlPlugin");
16
16
  function configHtmlWebpackPlugin(options) {
17
17
  const {
18
18
  htmlTemplate,
19
- mode
19
+ mode,
20
+ enableSubResourceIntegrity
20
21
  } = options;
21
22
  const {
22
23
  inject,
@@ -31,7 +32,8 @@ function configHtmlWebpackPlugin(options) {
31
32
  template: appInitialHTMLTemplatePath,
32
33
  minify: minifyHtmlOptions,
33
34
  inject,
34
- scriptLoading: 'defer'
35
+ scriptLoading: 'defer',
36
+ enableSubResourceIntegrity
35
37
  });
36
38
  }
37
39
 
@@ -8,11 +8,10 @@ exports.tsLoaders = tsLoaders;
8
8
  var _babelLoaderConfig = require("./loaderConfigs/babelLoaderConfig");
9
9
 
10
10
  function tsLoaders(options) {
11
- console.log('testing');
12
11
  return [{
13
- test: /\.tsx?$/,
12
+ test: /\.tsx$/,
14
13
  exclude: /node_modules/,
15
- use: "ts-loader" // include: path.join(appPath, folder)
14
+ use: [(0, _babelLoaderConfig.babelLoaderConfig)(options)] // include: path.join(appPath, folder)
16
15
 
17
16
  }];
18
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.13-exp.4",
3
+ "version": "0.0.13-exp.5",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {