@atlassian/webresource-webpack-plugin 4.10.2-64a2ef2

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.
Files changed (260) hide show
  1. package/.eslintignore +20 -0
  2. package/.eslintrc +72 -0
  3. package/.nvmrc +1 -0
  4. package/.prettierrc +6 -0
  5. package/CHANGELOG.md +318 -0
  6. package/CONTRIBUTING.md +92 -0
  7. package/LICENSE +13 -0
  8. package/README.md +709 -0
  9. package/RELEASE.md +17 -0
  10. package/package.json +118 -0
  11. package/src/AppResources.js +198 -0
  12. package/src/QUnitTestResources.js +88 -0
  13. package/src/WebpackHelpers.js +176 -0
  14. package/src/WebpackRuntimeHelpers.js +7 -0
  15. package/src/WrmPlugin.js +676 -0
  16. package/src/defaults/builtInProvidedDependencies.js +22 -0
  17. package/src/flattenReduce.js +1 -0
  18. package/src/helpers/options-parser.js +32 -0
  19. package/src/helpers/provided-dependencies.js +21 -0
  20. package/src/helpers/string.js +12 -0
  21. package/src/helpers/web-resource-entrypoints.js +66 -0
  22. package/src/helpers/web-resource-generator.js +138 -0
  23. package/src/helpers/web-resource-parser.js +44 -0
  24. package/src/helpers/xml.js +44 -0
  25. package/src/logger.js +28 -0
  26. package/src/mergeMaps.js +32 -0
  27. package/src/renderCondition.js +29 -0
  28. package/src/renderTransformation.js +44 -0
  29. package/src/settings/base-dependencies.js +42 -0
  30. package/src/shims/qunit-require-shim.js +19 -0
  31. package/src/types/typedefs.js +50 -0
  32. package/src/webpack-modules/EmptyExportsModule.js +26 -0
  33. package/src/webpack-modules/ProvidedExternalDependencyModule.js +30 -0
  34. package/src/webpack-modules/WrmDependencyModule.js +12 -0
  35. package/src/webpack-modules/WrmResourceModule.js +33 -0
  36. package/test/.eslintrc +11 -0
  37. package/test/unit/ProvidedExternalDependencyModule.test.js +63 -0
  38. package/test/unit/WebpackHelpers.test.js +37 -0
  39. package/test/unit/renderCondition.test.js +240 -0
  40. package/test/unit/renderTransformation.test.js +69 -0
  41. package/test/unit/webpack-modules/WrmDependencyModule.test.js +24 -0
  42. package/test/use-cases/.eslintrc +14 -0
  43. package/test/use-cases/asset-content-type/asset-content-type.test.js +50 -0
  44. package/test/use-cases/asset-content-type/src/app.js +8 -0
  45. package/test/use-cases/asset-content-type/src/ice.png +0 -0
  46. package/test/use-cases/asset-content-type/src/rect.svg +4 -0
  47. package/test/use-cases/asset-content-type/webpack.config.js +33 -0
  48. package/test/use-cases/asset-loading-via-js/asset-loading-via-js.test.js +61 -0
  49. package/test/use-cases/asset-loading-via-js/src/app.js +8 -0
  50. package/test/use-cases/asset-loading-via-js/src/ice.png +0 -0
  51. package/test/use-cases/asset-loading-via-js/src/rect.svg +4 -0
  52. package/test/use-cases/asset-loading-via-js/webpack.config.js +31 -0
  53. package/test/use-cases/associations-complex/associations-complex.test.js +82 -0
  54. package/test/use-cases/associations-complex/package-lock.json +73 -0
  55. package/test/use-cases/associations-complex/package.json +9 -0
  56. package/test/use-cases/associations-complex/src/copied-file-should-be-ignored.js +0 -0
  57. package/test/use-cases/associations-complex/src/entry.js +5 -0
  58. package/test/use-cases/associations-complex/src/entry2.js +5 -0
  59. package/test/use-cases/associations-complex/src/qunit.tests.js +2 -0
  60. package/test/use-cases/associations-complex/src/to-be-chunked.js +1 -0
  61. package/test/use-cases/associations-complex/webpack.config.js +48 -0
  62. package/test/use-cases/associations-simple/associations-simple.test.js +65 -0
  63. package/test/use-cases/associations-simple/package-lock.json +69 -0
  64. package/test/use-cases/associations-simple/package.json +5 -0
  65. package/test/use-cases/associations-simple/src/simple.js +3 -0
  66. package/test/use-cases/associations-simple/webpack.config.js +27 -0
  67. package/test/use-cases/async-chunks/async-chunks.test.js +113 -0
  68. package/test/use-cases/async-chunks/src/app.js +9 -0
  69. package/test/use-cases/async-chunks/src/async-bar.js +4 -0
  70. package/test/use-cases/async-chunks/src/async-foo.js +2 -0
  71. package/test/use-cases/async-chunks/webpack.config.js +40 -0
  72. package/test/use-cases/async-chunks-named-context/async-chunks-named-context.test.js +76 -0
  73. package/test/use-cases/async-chunks-named-context/src/app.js +9 -0
  74. package/test/use-cases/async-chunks-named-context/src/app2.js +5 -0
  75. package/test/use-cases/async-chunks-named-context/src/async-async-async-bar.js +4 -0
  76. package/test/use-cases/async-chunks-named-context/src/async-async-bar-two.js +1 -0
  77. package/test/use-cases/async-chunks-named-context/src/async-async-bar.js +6 -0
  78. package/test/use-cases/async-chunks-named-context/src/async-bar.js +7 -0
  79. package/test/use-cases/async-chunks-named-context/src/async-foo.js +2 -0
  80. package/test/use-cases/async-chunks-named-context/webpack.config.js +43 -0
  81. package/test/use-cases/async-chunks-of-async-chunks/async-chunks-of-async-chunks.test.js +117 -0
  82. package/test/use-cases/async-chunks-of-async-chunks/src/app.js +9 -0
  83. package/test/use-cases/async-chunks-of-async-chunks/src/async-async-async-bar.js +4 -0
  84. package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar-two.js +1 -0
  85. package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar.js +6 -0
  86. package/test/use-cases/async-chunks-of-async-chunks/src/async-bar.js +7 -0
  87. package/test/use-cases/async-chunks-of-async-chunks/src/async-foo.js +2 -0
  88. package/test/use-cases/async-chunks-of-async-chunks/webpack.config.js +43 -0
  89. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/async-chunks-of-async-chunks-with-multiple-entrypoints.test.js +156 -0
  90. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app.js +9 -0
  91. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app2.js +5 -0
  92. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-async-bar.js +4 -0
  93. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar-two.js +1 -0
  94. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar.js +6 -0
  95. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-bar.js +7 -0
  96. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-foo.js +2 -0
  97. package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/webpack.config.js +43 -0
  98. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/css-and-assets-distribution-via-mini-css-extract-plugin.test.js +72 -0
  99. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app.js +8 -0
  100. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app2.js +6 -0
  101. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice.png +0 -0
  102. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice2.jpg +0 -0
  103. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect.svg +4 -0
  104. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect2.svg +4 -0
  105. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles.css +8 -0
  106. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles2.css +8 -0
  107. package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/webpack.config.js +51 -0
  108. package/test/use-cases/css-and-assets-via-extract-text-plugin/css-and-assets-via-extract-text-plugin.test.js +87 -0
  109. package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.css +7 -0
  110. package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.js +3 -0
  111. package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.css +3 -0
  112. package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.js +1 -0
  113. package/test/use-cases/css-and-assets-via-extract-text-plugin/src/ice.png +0 -0
  114. package/test/use-cases/css-and-assets-via-extract-text-plugin/webpack.config.js +46 -0
  115. package/test/use-cases/css-and-assets-via-style-loader/css-and-assets-via-style-loader.test.js +46 -0
  116. package/test/use-cases/css-and-assets-via-style-loader/src/app.js +6 -0
  117. package/test/use-cases/css-and-assets-via-style-loader/src/ice.png +0 -0
  118. package/test/use-cases/css-and-assets-via-style-loader/src/styles.css +7 -0
  119. package/test/use-cases/css-and-assets-via-style-loader/webpack.config.js +46 -0
  120. package/test/use-cases/cyclic-dependencies/cyclic.test.js +24 -0
  121. package/test/use-cases/cyclic-dependencies/src/a.js +3 -0
  122. package/test/use-cases/cyclic-dependencies/src/b.js +3 -0
  123. package/test/use-cases/cyclic-dependencies/src/root.js +3 -0
  124. package/test/use-cases/cyclic-dependencies/webpack.config.js +24 -0
  125. package/test/use-cases/data-providers/data-providers.test.js +111 -0
  126. package/test/use-cases/data-providers/src/first.js +2 -0
  127. package/test/use-cases/data-providers/src/second.js +2 -0
  128. package/test/use-cases/data-providers/src/third.js +2 -0
  129. package/test/use-cases/data-providers/webpack.config.js +73 -0
  130. package/test/use-cases/data-providers/webpack.config.with-map.js +33 -0
  131. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/ensure-runtime-overwrite-of-mini-css-extract-plugin.test.js +86 -0
  132. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app.js +5 -0
  133. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app2.js +5 -0
  134. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice.png +0 -0
  135. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice2.jpg +0 -0
  136. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect.svg +4 -0
  137. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect2.svg +4 -0
  138. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles.css +8 -0
  139. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles2.css +8 -0
  140. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.after.config.js +51 -0
  141. package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.before.config.js +51 -0
  142. package/test/use-cases/jsonp-function-name/jsonp-function-name.test.js +37 -0
  143. package/test/use-cases/jsonp-function-name/src/app.js +1 -0
  144. package/test/use-cases/jsonp-function-name/src/foo.js +2 -0
  145. package/test/use-cases/jsonp-function-name/webpack.config.js +35 -0
  146. package/test/use-cases/jsonp-function-name-default/jsonp-function-name-default.test.js +39 -0
  147. package/test/use-cases/jsonp-function-name-default/src/app.js +1 -0
  148. package/test/use-cases/jsonp-function-name-default/src/foo.js +2 -0
  149. package/test/use-cases/jsonp-function-name-default/webpack.config.js +34 -0
  150. package/test/use-cases/location-prefix/location-prefix.test.js +29 -0
  151. package/test/use-cases/location-prefix/src/simple.js +6 -0
  152. package/test/use-cases/location-prefix/webpack.config.js +25 -0
  153. package/test/use-cases/provided-module-replacement/provided-module-replacement.test.js +63 -0
  154. package/test/use-cases/provided-module-replacement/src/app.js +3 -0
  155. package/test/use-cases/provided-module-replacement/webpack.config.with-map.js +33 -0
  156. package/test/use-cases/provided-module-replacement/webpack.config.with-object.js +34 -0
  157. package/test/use-cases/provided-modules-replacement-with-amd-target/provided-modules-replacement-with-amd-target.test.js +62 -0
  158. package/test/use-cases/provided-modules-replacement-with-amd-target/src/app.js +3 -0
  159. package/test/use-cases/provided-modules-replacement-with-amd-target/webpack.config.js +41 -0
  160. package/test/use-cases/qunit-test-wrm-web-resource/qunit-test-wrm-web-resource.test.js +157 -0
  161. package/test/use-cases/qunit-test-wrm-web-resource/src/app.2.js +6 -0
  162. package/test/use-cases/qunit-test-wrm-web-resource/src/app.js +8 -0
  163. package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep.js +8 -0
  164. package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep_test.js +1 -0
  165. package/test/use-cases/qunit-test-wrm-web-resource/src/foo-async.js +3 -0
  166. package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep.js +4 -0
  167. package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep_test.js +1 -0
  168. package/test/use-cases/qunit-test-wrm-web-resource/webpack.config.js +24 -0
  169. package/test/use-cases/resource-parameters/resource-parameters.test.js +77 -0
  170. package/test/use-cases/resource-parameters/src/app.js +12 -0
  171. package/test/use-cases/resource-parameters/src/ice.png +0 -0
  172. package/test/use-cases/resource-parameters/src/ice2.jpg +0 -0
  173. package/test/use-cases/resource-parameters/src/rect.svg +4 -0
  174. package/test/use-cases/resource-parameters/webpack.config.js +62 -0
  175. package/test/use-cases/resource-parameters/webpack.svg.config.js +30 -0
  176. package/test/use-cases/simple/simple.test.js +83 -0
  177. package/test/use-cases/simple/src/simple.js +3 -0
  178. package/test/use-cases/simple/webpack.config.js +24 -0
  179. package/test/use-cases/single-runtime-chunk/single-runtime-chunk.test.js +132 -0
  180. package/test/use-cases/single-runtime-chunk/src/first.js +2 -0
  181. package/test/use-cases/single-runtime-chunk/src/second.js +2 -0
  182. package/test/use-cases/single-runtime-chunk/src/shared.js +3 -0
  183. package/test/use-cases/single-runtime-chunk/src/third.js +2 -0
  184. package/test/use-cases/single-runtime-chunk/webpack.config.js +33 -0
  185. package/test/use-cases/specify-asset-dev-hash/specify-asset-dev-hash.test.js +33 -0
  186. package/test/use-cases/specify-asset-dev-hash/src/feature.js +6 -0
  187. package/test/use-cases/specify-asset-dev-hash/src/library.js +6 -0
  188. package/test/use-cases/specify-asset-dev-hash/webpack.config.js +71 -0
  189. package/test/use-cases/specify-conditions/specify-conditions.test.js +106 -0
  190. package/test/use-cases/specify-conditions/src/app.js +5 -0
  191. package/test/use-cases/specify-conditions/webpack.config.js +65 -0
  192. package/test/use-cases/specify-explicit-context/specify-explicit-context.test.js +89 -0
  193. package/test/use-cases/specify-explicit-context/src/app.js +5 -0
  194. package/test/use-cases/specify-explicit-context/webpack.config.js +34 -0
  195. package/test/use-cases/specify-explicit-context-no-autogenerated/specify-explicit-context-no-autogenerated.test.js +84 -0
  196. package/test/use-cases/specify-explicit-context-no-autogenerated/src/app.js +5 -0
  197. package/test/use-cases/specify-explicit-context-no-autogenerated/webpack.config.js +35 -0
  198. package/test/use-cases/specify-explicit-name/specify-explicit-name.test.js +110 -0
  199. package/test/use-cases/specify-explicit-name/src/app.js +5 -0
  200. package/test/use-cases/specify-explicit-name/webpack.config.js +43 -0
  201. package/test/use-cases/specify-explicit-state/specify-explicit-state.test.js +96 -0
  202. package/test/use-cases/specify-explicit-state/src/app.js +5 -0
  203. package/test/use-cases/specify-explicit-state/webpack.config.js +51 -0
  204. package/test/use-cases/specify-transformation/disable-transformations.test.js +77 -0
  205. package/test/use-cases/specify-transformation/extend-transformations.test.js +69 -0
  206. package/test/use-cases/specify-transformation/specify-transformation.test.js +100 -0
  207. package/test/use-cases/specify-transformation/src/app.js +13 -0
  208. package/test/use-cases/specify-transformation/src/ice.png +0 -0
  209. package/test/use-cases/specify-transformation/src/rect.svg +4 -0
  210. package/test/use-cases/specify-transformation/src/test.html +1 -0
  211. package/test/use-cases/specify-transformation/src/test.less +1 -0
  212. package/test/use-cases/specify-transformation/src/test.txt +1 -0
  213. package/test/use-cases/specify-transformation/webpack.disable-tranformations.config.js +31 -0
  214. package/test/use-cases/specify-transformation/webpack.extend-tranformations.config.js +34 -0
  215. package/test/use-cases/specify-transformation/webpack.specify-transformations.config.js +35 -0
  216. package/test/use-cases/split-chunks/split-chunks.test.js +102 -0
  217. package/test/use-cases/split-chunks/src/app.js +7 -0
  218. package/test/use-cases/split-chunks/src/app2.js +7 -0
  219. package/test/use-cases/split-chunks/src/bar.js +2 -0
  220. package/test/use-cases/split-chunks/src/foo.js +2 -0
  221. package/test/use-cases/split-chunks/src/foo2.js +2 -0
  222. package/test/use-cases/split-chunks/webpack.config.js +42 -0
  223. package/test/use-cases/split-chunks-with-runtime/split-chunks-with-runtime.test.js +114 -0
  224. package/test/use-cases/split-chunks-with-runtime/src/app.js +7 -0
  225. package/test/use-cases/split-chunks-with-runtime/src/app2.js +7 -0
  226. package/test/use-cases/split-chunks-with-runtime/src/bar.js +2 -0
  227. package/test/use-cases/split-chunks-with-runtime/src/foo.js +2 -0
  228. package/test/use-cases/split-chunks-with-runtime/src/foo2.js +2 -0
  229. package/test/use-cases/split-chunks-with-runtime/webpack.config.js +43 -0
  230. package/test/use-cases/split-chunks-with-tests/split-chunks-with-tests.test.js +216 -0
  231. package/test/use-cases/split-chunks-with-tests/src/app.js +7 -0
  232. package/test/use-cases/split-chunks-with-tests/src/app2.js +7 -0
  233. package/test/use-cases/split-chunks-with-tests/src/bar.js +2 -0
  234. package/test/use-cases/split-chunks-with-tests/src/bar_test.js +1 -0
  235. package/test/use-cases/split-chunks-with-tests/src/foo.js +2 -0
  236. package/test/use-cases/split-chunks-with-tests/src/foo2.js +2 -0
  237. package/test/use-cases/split-chunks-with-tests/src/foo_test.js +1 -0
  238. package/test/use-cases/split-chunks-with-tests/webpack.config.js +43 -0
  239. package/test/use-cases/standalone/src/standalone-1.js +1 -0
  240. package/test/use-cases/standalone/src/standalone-2.js +1 -0
  241. package/test/use-cases/standalone/standalone.test.js +53 -0
  242. package/test/use-cases/standalone/webpack.config.js +25 -0
  243. package/test/use-cases/wrm-dependency-loading/src-amd/app.js +7 -0
  244. package/test/use-cases/wrm-dependency-loading/src-es6/app.js +7 -0
  245. package/test/use-cases/wrm-dependency-loading/webpack.config.amd.js +22 -0
  246. package/test/use-cases/wrm-dependency-loading/webpack.config.es6.js +22 -0
  247. package/test/use-cases/wrm-dependency-loading/wrm-dependency-loading.test.js +60 -0
  248. package/test/use-cases/wrm-manifest-path/src/a.js +3 -0
  249. package/test/use-cases/wrm-manifest-path/src/app.js +3 -0
  250. package/test/use-cases/wrm-manifest-path/src/app2.js +3 -0
  251. package/test/use-cases/wrm-manifest-path/src/b.js +3 -0
  252. package/test/use-cases/wrm-manifest-path/webpack.config.js +27 -0
  253. package/test/use-cases/wrm-manifest-path/wrm-manifest-path.test.js +57 -0
  254. package/test/use-cases/wrm-resource-loading/src-amd/app.js +6 -0
  255. package/test/use-cases/wrm-resource-loading/src-es6/app.js +5 -0
  256. package/test/use-cases/wrm-resource-loading/src-relative/app.js +5 -0
  257. package/test/use-cases/wrm-resource-loading/webpack.config.amd.js +23 -0
  258. package/test/use-cases/wrm-resource-loading/webpack.config.es6.js +23 -0
  259. package/test/use-cases/wrm-resource-loading/webpack.config.relative.js +23 -0
  260. package/test/use-cases/wrm-resource-loading/wrm-resource-loading.test.js +89 -0
@@ -0,0 +1,22 @@
1
+ const { buildProvidedDependency } = require('../helpers/provided-dependencies');
2
+
3
+ const webresourcePluginName = 'com.atlassian.plugins.atlassian-plugins-webresource-plugin';
4
+ const webresourceDep = buildProvidedDependency.bind(undefined, webresourcePluginName);
5
+
6
+ const builtInProvidedDependencies = new Map()
7
+ .set(
8
+ 'wrm/require',
9
+ buildProvidedDependency(
10
+ 'com.atlassian.plugins.atlassian-plugins-webresource-rest',
11
+ 'web-resource-manager',
12
+ 'WRM.require',
13
+ 'wrm/require'
14
+ )
15
+ )
16
+ .set('wrm/context-path', webresourceDep('context-path', 'WRM.contextPath', 'wrm/context-path'))
17
+ .set('wrm/data', webresourceDep('data', 'WRM.data', 'wrm/data'))
18
+ .set('wrm/format', webresourceDep('format', 'WRM.format', 'wrm/format'));
19
+
20
+ module.exports = {
21
+ builtInProvidedDependencies,
22
+ };
@@ -0,0 +1 @@
1
+ module.exports = (a, b) => a.concat(b);
@@ -0,0 +1,32 @@
1
+ const path = require('path');
2
+
3
+ const pathSeparatorRegex = new RegExp(`^\\${path.sep}|\\${path.sep}$`, 'g');
4
+
5
+ /**
6
+ * Converts an object in to a Map.
7
+ * @param {Object} original
8
+ * @returns {Map} a map with key-value pairs from the object.
9
+ * returns an empty map if the original value was falsy or not an object.
10
+ */
11
+ function toMap(original) {
12
+ if (original instanceof Map) {
13
+ return original;
14
+ }
15
+ return original && typeof original === 'object' ? new Map(Object.entries(original)) : new Map();
16
+ }
17
+
18
+ function extractPathPrefixForXml(pathPrefix) {
19
+ if (!pathPrefix || pathPrefix === '' || pathPrefix === '/') {
20
+ return '';
21
+ }
22
+
23
+ // remove leading/trailing path separator
24
+ const withoutLeadingTrailingSeparators = pathPrefix.replace(pathSeparatorRegex, '');
25
+ // readd trailing slash - this time OS independent always a "/"
26
+ return withoutLeadingTrailingSeparators + '/';
27
+ }
28
+
29
+ module.exports = {
30
+ toMap,
31
+ extractPathPrefixForXml,
32
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * @param {String} pluginKey
4
+ * @param {String} resourceKey
5
+ * @param {String} importVar
6
+ * @param {String} importAmd
7
+ * @return {{dependency: string, import: {var: *, amd: *}}}
8
+ */
9
+ function buildProvidedDependency(pluginKey, resourceKey, importVar, importAmd) {
10
+ return {
11
+ dependency: `${pluginKey}:${resourceKey}`,
12
+ import: {
13
+ var: importVar,
14
+ amd: importAmd,
15
+ },
16
+ };
17
+ }
18
+
19
+ module.exports = {
20
+ buildProvidedDependency,
21
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param {*} val - the initial value of varying type
3
+ * @returns {string} a trimmed string value
4
+ */
5
+ function parseString(val) {
6
+ let maybeStr = val && val.length ? String(val) : '';
7
+ return maybeStr.trim();
8
+ }
9
+
10
+ module.exports = {
11
+ parseString,
12
+ };
@@ -0,0 +1,66 @@
1
+ const { parseWebResourceAttributes } = require('./web-resource-parser');
2
+
3
+ /**
4
+ * @param {String} entry
5
+ * @param {Map<String, Array<String>>} contextMap
6
+ * @param {Boolean} addEntrypointNameAsContext
7
+ * @returns {Array<String>}
8
+ */
9
+ function getContextForEntry(entry, contextMap, addEntrypointNameAsContext) {
10
+ const contexts = [].concat(contextMap.get(entry));
11
+ if (addEntrypointNameAsContext) {
12
+ contexts.unshift(entry);
13
+ }
14
+ return contexts.filter(context => context && typeof context === 'string');
15
+ }
16
+
17
+ /**
18
+ * @param {String} entry
19
+ * @param {Map<String, String>} webresourceKeyMap
20
+ * @returns {WebResourceAttributes}
21
+ */
22
+ function getWebresourceAttributesForEntry(entry, webresourceKeyMap) {
23
+ const wrKey = webresourceKeyMap.get(entry);
24
+
25
+ // Create the default attribute values
26
+ let attrs = { key: `entrypoint-${entry}`, moduleId: entry };
27
+
28
+ // Extend the attributes with parsed, valid values
29
+ if (typeof wrKey === 'object') {
30
+ attrs = Object.assign(attrs, parseWebResourceAttributes(wrKey));
31
+ }
32
+
33
+ // Override the key if a non-empty string is provided
34
+ if (typeof wrKey === 'string') {
35
+ attrs = Object.assign(attrs, parseWebResourceAttributes({ key: wrKey }));
36
+ }
37
+
38
+ return attrs;
39
+ }
40
+
41
+ /**
42
+ * @param {String} entry
43
+ * @param {Map<String, Object>} conditionMap
44
+ * @returns {*}
45
+ */
46
+ function getConditionForEntry(entry, conditionMap) {
47
+ return conditionMap.get(entry);
48
+ }
49
+
50
+ /**
51
+ * Retrieves the list of data providers for given entrypoint
52
+ *
53
+ * @param {String} entrypoint - webpack entrypoint key
54
+ * @param {Map<String, DataProvider[]>} dataProvidersMap - All data providers from plugin options
55
+ * @return {DataProvider[]} - List of data providers for given entry point
56
+ */
57
+ function getDataProvidersForEntry(entrypoint, dataProvidersMap) {
58
+ return dataProvidersMap.get(entrypoint) || [];
59
+ }
60
+
61
+ module.exports = {
62
+ getContextForEntry,
63
+ getConditionForEntry,
64
+ getWebresourceAttributesForEntry,
65
+ getDataProvidersForEntry,
66
+ };
@@ -0,0 +1,138 @@
1
+ const path = require('path');
2
+ const { renderElement } = require('./xml');
3
+ const { parseWebResourceAttributes } = require('./web-resource-parser');
4
+ const renderCondition = require('../renderCondition');
5
+ const renderTransformation = require('../renderTransformation');
6
+
7
+ /**
8
+ * Renders list of data providers {@see DataProvider} as <data key="provider-key" class="data.provider.Class" /> elements
9
+ *
10
+ * @param {DataProvider[]} dataProviders
11
+ * @return {string[]}
12
+ */
13
+ const renderDataProviders = dataProviders => {
14
+ if (!Array.isArray(dataProviders) || !dataProviders.length < 0) {
15
+ return [];
16
+ }
17
+
18
+ return dataProviders.map(dataProvider =>
19
+ renderElement('data', {
20
+ key: dataProvider.key,
21
+ class: dataProvider.class,
22
+ })
23
+ );
24
+ };
25
+
26
+ function generateContext(contexts) {
27
+ return contexts ? contexts.map(context => `<context>${context}</context>`).join('') : '';
28
+ }
29
+
30
+ function generateDependencies(dependencies) {
31
+ return dependencies ? dependencies.map(dependency => `<dependency>${dependency}</dependency>`).join('\n') : '';
32
+ }
33
+
34
+ /**
35
+ * @param {Resource} resource
36
+ * @param {Map<String, Array<Object>>} parameterMap
37
+ * @returns {string} an XML representation of a {@link Resource}.
38
+ */
39
+ function generateResourceElement(resource, parameterMap) {
40
+ const { name, location } = resource;
41
+ const assetContentType = path.extname(location).substr(1);
42
+ const parameters = parameterMap.get(assetContentType) || [];
43
+ const children = [];
44
+ const renderParameters = attributes => children.push(renderElement('param', attributes));
45
+ parameters.forEach(renderParameters);
46
+
47
+ return renderElement(
48
+ 'resource',
49
+ {
50
+ type: 'download',
51
+ name,
52
+ location,
53
+ },
54
+ children
55
+ );
56
+ }
57
+
58
+ /**
59
+ * Generates a <resource> descriptor that will glue the source code for a file to the qunit test runner.
60
+ * @param {filepath} filepath
61
+ * @returns {string} an XML representation of a {@link Resource}.
62
+ */
63
+ function generateQunitResourceElement(filepath) {
64
+ return renderElement('resource', { type: 'qunit', name: filepath, location: filepath });
65
+ }
66
+
67
+ /**
68
+ * @param {Map<String, Array<Object>>} parameterMap
69
+ * @param {Resource[]} resources
70
+ * @returns {string} an XML string of all {@link Resource} elements
71
+ */
72
+ function generateResources(parameterMap, resources) {
73
+ return resources
74
+ .filter(r => !!r)
75
+ .map(resource => generateResourceElement(resource, parameterMap))
76
+ .join('\n');
77
+ }
78
+
79
+ /**
80
+ * @param {WrmEntrypoint} webresource
81
+ * @param {Map<String, Array<String>>} transformations
82
+ * @param {String} pathPrefix
83
+ * @param {Map<String, Array<Object>>} parameterMap
84
+ * @param standalone
85
+ * @returns {string} an XML representation of the {@link WrmEntrypoint}.
86
+ */
87
+ function createWebResource(webresource, transformations, pathPrefix = '', parameterMap = new Map(), standalone) {
88
+ const { resources = [], externalResources = [], contexts, dependencies, conditions, dataProviders } = webresource;
89
+ const attributes = parseWebResourceAttributes(webresource.attributes);
90
+ const allResources = [];
91
+ const children = [];
92
+
93
+ /** convert filepaths in to {@link Resource}s. */
94
+ const convertFilePaths = location => pathPrefix + location;
95
+
96
+ // add resources for direct dependencies (e.g., JS and CSS files)
97
+ allResources.push(...resources.map(res => ({ name: res, location: convertFilePaths(res) })));
98
+
99
+ if (standalone) {
100
+ children.push(generateResources(parameterMap, allResources));
101
+ } else {
102
+ // add resources for indirect dependencies (e.g., images extracted from CSS)
103
+ allResources.push(...externalResources.map(wr => ({ name: wr.name, location: convertFilePaths(wr.location) })));
104
+
105
+ children.push(
106
+ renderTransformation(transformations, allResources),
107
+ generateContext(contexts),
108
+ generateDependencies(dependencies),
109
+ generateResources(parameterMap, allResources),
110
+ renderCondition(conditions),
111
+ ...renderDataProviders(dataProviders)
112
+ );
113
+ }
114
+
115
+ return renderElement('web-resource', attributes, children);
116
+ }
117
+
118
+ function createResourceDescriptors(jsonDescriptors, transformations, pathPrefix, parameterMap, standalone) {
119
+ const descriptors = jsonDescriptors.map(descriptor =>
120
+ createWebResource(descriptor, transformations, pathPrefix, parameterMap, standalone)
121
+ );
122
+ return descriptors.join('');
123
+ }
124
+
125
+ function createTestResourceDescriptors(jsonTestDescriptors, transformations) {
126
+ const testDescriptors = jsonTestDescriptors.map(descriptor => createWebResource(descriptor, transformations));
127
+ return testDescriptors.join('');
128
+ }
129
+
130
+ function createQUnitResourceDescriptors(qUnitTestFiles) {
131
+ return qUnitTestFiles.map(generateQunitResourceElement).join('');
132
+ }
133
+
134
+ module.exports = {
135
+ createResourceDescriptors,
136
+ createTestResourceDescriptors,
137
+ createQUnitResourceDescriptors,
138
+ };
@@ -0,0 +1,44 @@
1
+ const { parseString } = require('./string');
2
+
3
+ /**
4
+ * @param {Object} data - key value pairs of potentially invalid metadata for a web-resource.
5
+ * @returns {WebResourceAttributes} a valid set of metadata for a web-resource.
6
+ */
7
+ function parseWebResourceAttributes(data = {}) {
8
+ const attributes = {};
9
+ // Only parse objects.
10
+ if (data && data.hasOwnProperty) {
11
+ // define the key if a non-empty string was provided
12
+ if (data.hasOwnProperty('key')) {
13
+ let customKey = parseString(data.key);
14
+ if (customKey) {
15
+ attributes.key = customKey;
16
+ }
17
+ }
18
+
19
+ // define the state as either enabled or disabled
20
+ if (data.hasOwnProperty('state')) {
21
+ let isEnabled = true;
22
+ if (typeof data.state === 'boolean') {
23
+ isEnabled = data.state;
24
+ } else if (typeof data.state === 'string') {
25
+ isEnabled = !(data.state === 'disabled');
26
+ }
27
+ attributes.state = isEnabled ? 'enabled' : 'disabled';
28
+ }
29
+
30
+ // define the name if a non-empty string was provided
31
+ if (data.hasOwnProperty('name')) {
32
+ let customName = parseString(data.name);
33
+ if (customName) {
34
+ attributes.name = customName;
35
+ }
36
+ }
37
+ }
38
+
39
+ return attributes;
40
+ }
41
+
42
+ module.exports = {
43
+ parseWebResourceAttributes,
44
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @param {Object} attributes
3
+ * @returns {string}
4
+ */
5
+ function stringifyAttributes(attributes) {
6
+ if (!attributes) {
7
+ return '';
8
+ }
9
+
10
+ return (
11
+ ' ' +
12
+ Object.keys(attributes)
13
+ .map(key => {
14
+ const val = typeof attributes[key] === 'undefined' ? '' : String(attributes[key]);
15
+ return `${key}="${val}"`;
16
+ })
17
+ .join(' ')
18
+ );
19
+ }
20
+
21
+ function renderElement(name, attributes, children) {
22
+ if (typeof attributes === 'object') {
23
+ attributes = stringifyAttributes(attributes);
24
+ }
25
+ // avoid outputting 'undefined' when attributes aren't present.
26
+ if (!attributes) {
27
+ attributes = '';
28
+ }
29
+ // convert children array in to a string.
30
+ // assume they are string values already. (todo: refactor for nested rendering?)
31
+ if (Array.isArray(children)) {
32
+ children = children.join('\n');
33
+ }
34
+ // render self-closing tags based on whether there is no child input.
35
+ if (!children) {
36
+ return `<${name}${attributes}/>`;
37
+ }
38
+ return `<${name}${attributes}>${children}</${name}>`;
39
+ }
40
+
41
+ module.exports = {
42
+ renderElement,
43
+ stringifyAttributes,
44
+ };
package/src/logger.js ADDED
@@ -0,0 +1,28 @@
1
+ /* eslint-disable no-console */
2
+ let verbose = false;
3
+ const setVerbose = arg => (verbose = arg);
4
+
5
+ function log(...args) {
6
+ if (verbose) {
7
+ console.log(...args);
8
+ }
9
+ }
10
+
11
+ function warn(...args) {
12
+ if (verbose) {
13
+ console.warn(...args);
14
+ }
15
+ }
16
+
17
+ function error(...args) {
18
+ if (verbose) {
19
+ console.error(...args);
20
+ }
21
+ }
22
+
23
+ module.exports = {
24
+ log,
25
+ warn,
26
+ error,
27
+ setVerbose,
28
+ };
@@ -0,0 +1,32 @@
1
+ const defaultMerger = (v, k, map) => map.set(k, v);
2
+
3
+ /**
4
+ * Combines multiple maps in to a single map, allowing control over how
5
+ * the values for keys are stored in the new map.
6
+ *
7
+ * The default behaviour is the value from the last map wins.
8
+ *
9
+ * @example
10
+ * const a = new Map([['first', 1], ['second', 2]]);
11
+ * const b = new Map(['first', 100], ['third', 300]);
12
+ * mergeMaps(a, b) // Map(3) {'first' => 100, 'second' => 2, 'third' => 300}
13
+ *
14
+ * @example
15
+ * const a = new Map([['one', [1,2,3]]]);
16
+ * const b = new Map([['one', [4,5,6]]]);
17
+ * const merger = (map, k, newVal) => {
18
+ * const oldVal = map.get(k);
19
+ * map.set(k, [].concat(oldVal).concat(newVal));
20
+ * }
21
+ * mergeMaps(a, b, merger) // Map(1) {'one' => [1,2,3,4,5,6]}
22
+ */
23
+ const mergeMaps = (...maps) => {
24
+ const source = new Map();
25
+ const merger = typeof maps[maps.length - 1] === 'function' ? maps.pop() : defaultMerger;
26
+ maps.forEach(map => {
27
+ Array.from(map.entries()).reduce((m, [k, v]) => merger(v, k, m), source);
28
+ });
29
+ return source;
30
+ };
31
+
32
+ module.exports = mergeMaps;
@@ -0,0 +1,29 @@
1
+ const { renderElement } = require('./helpers/xml');
2
+
3
+ function renderParams(params) {
4
+ if (!params) {
5
+ return '';
6
+ }
7
+ return params.map(param => renderElement('param', param.attributes, param.value)).join('');
8
+ }
9
+
10
+ module.exports = function renderCondition(condition) {
11
+ if (!condition) {
12
+ return '';
13
+ }
14
+
15
+ // we have actual conditions
16
+ if (Array.isArray(condition)) {
17
+ return condition.map(renderCondition).join('');
18
+ }
19
+ // we have a "conditions"-joiner for multiple sub conditions
20
+ if (condition.type) {
21
+ return renderElement('conditions', { type: condition.type }, renderCondition(condition.conditions));
22
+ }
23
+
24
+ return renderElement(
25
+ 'condition',
26
+ ` class="${condition.class}" ${condition.invert ? `invert="true"` : ''}`,
27
+ renderParams(condition.params)
28
+ );
29
+ };
@@ -0,0 +1,44 @@
1
+ const path = require('path');
2
+ const { renderElement } = require('./helpers/xml');
3
+ const { toMap } = require('./helpers/options-parser');
4
+
5
+ function renderTransformer(transformers) {
6
+ if (transformers && transformers.length) {
7
+ return transformers.map(transformer => renderElement('transformer', { key: transformer })).join('');
8
+ }
9
+ return '';
10
+ }
11
+
12
+ /**
13
+ * Generates the appropriate function to be used when filtering a transform map down to only those required.
14
+ * @param {Resource[]} resources
15
+ * @returns {function}
16
+ */
17
+ function transformFilterFactory(resources) {
18
+ if (resources && resources.length) {
19
+ const resourceFiletypes = resources.map(resource => path.extname(resource.location).substr(1));
20
+ return ext => resourceFiletypes.includes(ext);
21
+ }
22
+ return () => true;
23
+ }
24
+
25
+ /**
26
+ * Converts a map of filetype-to-transformer entries in to the set of XML transform elements
27
+ * required for a given set of resources. Renders every transform if no resources are provided.
28
+ * @param {Map<String, Array<String>>} transformations
29
+ * @param {Resource[]} resources
30
+ * @returns {string} the rendered XML for each necessary transform.
31
+ */
32
+ module.exports = function renderTransformation(transformations, resources = []) {
33
+ const transMap = toMap(transformations);
34
+ return Array.from(transMap.keys())
35
+ .filter(transformFilterFactory(resources))
36
+ .map(fileExtension =>
37
+ renderElement(
38
+ 'transformation',
39
+ { extension: fileExtension },
40
+ renderTransformer(transMap.get(fileExtension))
41
+ )
42
+ )
43
+ .join('');
44
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileOverview
3
+ * Collects a set of web-resource dependencies that should be added
4
+ * to all the web-resources generated during compilation.
5
+ */
6
+ const _ = require('lodash');
7
+ const CROSS_PLATFORM_BASE_DEPS = [];
8
+
9
+ function process(arr) {
10
+ return _.chain([].concat(CROSS_PLATFORM_BASE_DEPS, arr))
11
+ .filter(val => !!val)
12
+ .uniq()
13
+ .value();
14
+ }
15
+
16
+ let configuredContexts = [];
17
+
18
+ function getBaseDependencies() {
19
+ // defensively cloning so consumers can't accidentally add anything
20
+ return [...configuredContexts];
21
+ }
22
+
23
+ function setBaseDependencies(val) {
24
+ const contexts = [];
25
+ if (val instanceof Array) {
26
+ contexts.push(...val);
27
+ } else if (typeof val === 'string') {
28
+ contexts.push(val);
29
+ }
30
+
31
+ configuredContexts = process(contexts);
32
+ }
33
+
34
+ function addBaseDependency(val) {
35
+ configuredContexts = process([...configuredContexts, val]);
36
+ }
37
+
38
+ module.exports = {
39
+ addBaseDependency,
40
+ getBaseDependencies,
41
+ setBaseDependencies,
42
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Used for qunit-tests to prevent them from failing if "resources"/"dependencies" are required.
3
+ * This injects a window.require to capture and ignore require-requests to "wr-dependency!/wr-resource!",
4
+ * while forwarding everything else
5
+ */
6
+ module.exports = `
7
+ !function(){
8
+ var old_require = window.require;
9
+ window.require = function(modRequest){
10
+ if(modRequest.indexOf('wr-dependency!') === 0) {
11
+ return null;
12
+ }
13
+ if(modRequest.indexOf('wr-resource!') === 0) {
14
+ return null;
15
+ }
16
+ return old_require.apply(this, arguments);
17
+ }
18
+ }();
19
+ `;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @typedef {String} filepath - a relative filepath in unix format.
3
+ */
4
+
5
+ /**
6
+ * @typedef {String} filename
7
+ */
8
+
9
+ /**
10
+ * @typedef {String} wrKey
11
+ */
12
+
13
+ /**
14
+ * @typedef {String} wrDep - a composite string in the format "maven.groupId.artifactId:webresource-key"
15
+ */
16
+
17
+ /**
18
+ * @typedef {Object} Resource
19
+ * @property {filepath} location - the relative path for the resource,
20
+ * starting from the root of the plugin's classpath (the JAR file).
21
+ * @property {filename} name - the asset's filename as it appears in the browser at runtime.
22
+ */
23
+
24
+ /**
25
+ * @typedef {Object} WebResourceAttributes
26
+ * @property {wrKey} key - the unique identifier for this web-resource.
27
+ * @property {string} [name] - the human-readable name of the web-resource.
28
+ * @property {true|false} [state] - whether this web-resource should output its resources at runtime or not.
29
+ * If absent, a web-resource is assumed to be enabled.
30
+ */
31
+
32
+ /**
33
+ * @typedef {Object} WrmEntrypoint
34
+ * @description wraps a set of related resources with metadata the WRM can understand and reason about as a discrete unit.
35
+ * @property {WebResourceAttributes} attributes - the metadata for this web-resource.
36
+ * @property {filepath[]} resources - the locations of all resources directly referenced by this entrypoint's graph.
37
+ * @property {Resource[]} externalResources - a filename and filepath pair for resources
38
+ * discovered by the WRM plugin's loaders.
39
+ * @property {wrDep[]} [dependencies] - a list of other web-resources this one should depend upon.
40
+ * @property {string[]} [contexts] - a list of contexts the web-resource should be loaded in to.
41
+ * @property {object[]} [conditions] - a list of conditions to apply to the web-resource to determine whether
42
+ * it should output its resources at runtime or not.
43
+ */
44
+
45
+ /**
46
+ * @typedef {Object} DataProvider
47
+ * @description Data provider shape used by `dataProvidersMap` option.
48
+ * @property {String} key - Data provider key e.g. `my-data-provider`
49
+ * @property {String} class - Data provider Java class e.g. `my.data.provider.JavaClass`
50
+ */
@@ -0,0 +1,26 @@
1
+ const DllModule = require('webpack/lib/DllModule');
2
+ const RawSource = require('webpack-sources').RawSource;
3
+
4
+ /**
5
+ * This module type allows inclusion of special dependencies in the webpack compilation process
6
+ * that ultimately output nothing in the compiled bundles.
7
+ *
8
+ * This is of use when including certain file types with no associated loader in the compilation process,
9
+ * as is the case with things like Atlassian Soy templates.
10
+ */
11
+ class EmptyExportsModule extends DllModule {
12
+ constructor(dependency, type) {
13
+ super(null, [], dependency, type);
14
+ this._dependency = dependency;
15
+ }
16
+
17
+ chunkCondition() {
18
+ return true;
19
+ }
20
+
21
+ source() {
22
+ return new RawSource('module.exports = undefined;');
23
+ }
24
+ }
25
+
26
+ module.exports = EmptyExportsModule;