@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,61 @@
1
+ const assert = require('chai').assert;
2
+ const parse = require('xml-parser');
3
+ const webpack = require('webpack');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const targetDir = path.join(__dirname, 'target');
8
+ const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
9
+
10
+ describe('asset-loading-via-js', function() {
11
+ const config = require('./webpack.config.js');
12
+
13
+ let stats;
14
+ let assets;
15
+ let resources;
16
+
17
+ beforeEach(done => {
18
+ webpack(config, (err, st) => {
19
+ stats = st;
20
+
21
+ const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
22
+ const results = parse(xmlFile);
23
+ assets = results.root.children.find(n => n.attributes.key.startsWith('assets'));
24
+ resources = assets.children.filter(n => n.name === 'resource');
25
+ done();
26
+ });
27
+ });
28
+
29
+ it('should create an "asset"-webresource containing the asset', () => {
30
+ assert.ok(assets);
31
+ assert.equal(stats.hasErrors(), false);
32
+ assert.equal(stats.hasWarnings(), false);
33
+ assert.equal(resources[0].attributes.type, 'download');
34
+ assert.equal(path.extname(resources[0].attributes.name), '.png');
35
+ });
36
+
37
+ it('should add all assets to the "asset"-webresource', () => {
38
+ assert.ok(assets);
39
+ assert.equal(stats.hasErrors(), false);
40
+ assert.equal(stats.hasWarnings(), false);
41
+ assert.equal(resources.length, 2);
42
+ assert.equal(resources[0].attributes.type, 'download');
43
+ assert.equal(path.extname(resources[0].attributes.name), '.png');
44
+ assert.equal(resources[1].attributes.type, 'download');
45
+ assert.equal(path.extname(resources[1].attributes.name), '.svg');
46
+ });
47
+
48
+ it('should overwrite webpack output path to point to a wrm-resource', () => {
49
+ // setup
50
+ const bundleFile = fs.readFileSync(path.join(targetDir, 'app.js'), 'utf-8');
51
+ const publicPathLines = bundleFile.match(/__webpack_require__\.p\s*?=.+?;/g);
52
+ const injectedLine = publicPathLines.find(line => line.includes('download'));
53
+
54
+ assert.isNotEmpty(
55
+ injectedLine,
56
+ 'an override to the public path helper that uses a WRM-friendly URL should be injected, but was not'
57
+ );
58
+ assert.startsWith(injectedLine, '__webpack_require__.p = AJS.contextPath()');
59
+ assert.endsWith(injectedLine, `/download/resources/com.atlassian.plugin.test:${assets.attributes.key}/";`);
60
+ });
61
+ });
@@ -0,0 +1,8 @@
1
+ import ice from './ice.png';
2
+ import rect from './rect.svg';
3
+
4
+ const image = new Image();
5
+ image.src = ice;
6
+
7
+ const image2 = new Image();
8
+ image2.src = rect;
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg width="48px" height="64px" viewBox="0 0 48 64" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <rect width="48" height="64" style="fill:rgb(0,0,255)" />
4
+ </svg>
@@ -0,0 +1,31 @@
1
+ const path = require('path');
2
+ const WrmPlugin = require('../../../src/WrmPlugin');
3
+ const FRONTEND_SRC_DIR = path.join(__dirname, 'src');
4
+ const OUTPUT_DIR = path.join(__dirname, 'target');
5
+
6
+ module.exports = {
7
+ mode: 'development',
8
+ entry: {
9
+ app: path.join(FRONTEND_SRC_DIR, 'app.js'),
10
+ },
11
+ devtool: false,
12
+ module: {
13
+ rules: [
14
+ {
15
+ test: /\.(png|svg)$/,
16
+ loader: 'file-loader',
17
+ },
18
+ ],
19
+ },
20
+ plugins: [
21
+ new WrmPlugin({
22
+ pluginKey: 'com.atlassian.plugin.test',
23
+ xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
24
+ verbose: false,
25
+ }),
26
+ ],
27
+ output: {
28
+ filename: '[name].js',
29
+ path: OUTPUT_DIR,
30
+ },
31
+ };
@@ -0,0 +1,82 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const webpack = require('webpack');
4
+ const expect = require('chai').expect;
5
+
6
+ const config = require('./webpack.config');
7
+
8
+ const targetDir = path.join(__dirname, 'target/classes');
9
+ const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
10
+
11
+ describe('associations-complex', () => {
12
+ before(done => {
13
+ webpack(config, (err, stats) => {
14
+ if (err) {
15
+ throw err;
16
+ }
17
+
18
+ if (stats.hasErrors() || stats.hasWarnings()) {
19
+ throw Error('Webpack build failed.');
20
+ }
21
+
22
+ done();
23
+ });
24
+ });
25
+
26
+ it('compiles an xml file', () => {
27
+ expect(fs.existsSync(webresourceOutput)).to.be.equal(true);
28
+ });
29
+
30
+ it('output includes compiled and copied files', () => {
31
+ const files = fs.readdirSync(targetDir);
32
+ const jsFiles = files.filter(file => path.extname(file) === '.js');
33
+
34
+ expect(jsFiles).to.deep.equal([
35
+ 'copied-file-should-be-ignored.js',
36
+ 'qunit-require-shim-DEV_PSEUDO_HASH.js',
37
+ 'simple-entry-2.js',
38
+ 'simple-entry.js',
39
+ 'simple-entry~simple-entry-2.js',
40
+ ]);
41
+ });
42
+
43
+ describe('association file', () => {
44
+ let associationJsonContent;
45
+
46
+ before(() => {
47
+ const jsonPath = path.join(
48
+ targetDir,
49
+ 'META-INF/fe-manifest-associations/com.atlassian.plugin.test-webpack.intermediary.json'
50
+ );
51
+
52
+ const isJsonExisting = fs.existsSync(jsonPath);
53
+ if (!isJsonExisting) {
54
+ throw new Error('Association JSON was not created.');
55
+ }
56
+
57
+ associationJsonContent = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
58
+ });
59
+
60
+ it('association file structure is correct', () => {
61
+ expect(associationJsonContent).to.have.property('packageName');
62
+ expect(typeof associationJsonContent.packageName).to.equal('string');
63
+ expect(associationJsonContent).to.have.property('outputDirectoryFiles');
64
+ expect(associationJsonContent.outputDirectoryFiles).to.be.an('array');
65
+ });
66
+
67
+ it('association package name is inferred from build context', () => {
68
+ expect(associationJsonContent.packageName).to.equal(
69
+ '@atlassian/webpack-webresource-plugin.tests.associations-complex'
70
+ );
71
+ });
72
+
73
+ it('association file includes relatives paths for files compiled through entries (exclusively) plus qunit-require-shim', () => {
74
+ expect(associationJsonContent.outputDirectoryFiles).to.deep.equal([
75
+ 'simple-entry~simple-entry-2.js',
76
+ 'simple-entry.js',
77
+ 'simple-entry-2.js',
78
+ 'qunit-require-shim-DEV_PSEUDO_HASH.js',
79
+ ]);
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-complex",
3
+ "version": "0.0.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-complex",
9
+ "version": "0.0.1",
10
+ "dependencies": {
11
+ "atlassian-webresource-webpack-plugin": "file:../../.."
12
+ },
13
+ "engines": {
14
+ "node": ">=12",
15
+ "npm": ">=6.9"
16
+ }
17
+ },
18
+ "../../..": {
19
+ "version": "4.9.0",
20
+ "license": "Apache-2.0",
21
+ "dependencies": {
22
+ "glob": "^7.1.2",
23
+ "lodash": "^4.17.15",
24
+ "mkdirp": "^0.5.1",
25
+ "pretty-data": "^0.40.0",
26
+ "tapable": "^1.1.0",
27
+ "url-join": "^4.0.0",
28
+ "uuid": "^3.3.2",
29
+ "webpack-merge": "^4.2.2",
30
+ "webpack-sources": "^1.1.0"
31
+ },
32
+ "devDependencies": {
33
+ "babel-eslint": "^10.0.1",
34
+ "chai": "^4.2.0",
35
+ "chai-string": "^1.5.0",
36
+ "chai-uuid": "^1.0.6",
37
+ "css-loader": "^1.0.1",
38
+ "eslint": "^5.9.0",
39
+ "eslint-config-prettier": "^3.3.0",
40
+ "eslint-plugin-babel": "^5.2.1",
41
+ "eslint-plugin-filenames": "^1.3.2",
42
+ "eslint-plugin-jasmine": "^2.10.1",
43
+ "eslint-plugin-mocha": "^5.2.0",
44
+ "eslint-plugin-node": "^8.0.0",
45
+ "eslint-plugin-prettier": "^3.0.0",
46
+ "extract-text-webpack-plugin": "4.0.0-beta.0",
47
+ "file-loader": "^2.0.0",
48
+ "jquery": "^3.4.1",
49
+ "mini-css-extract-plugin": "^0.4.4",
50
+ "mocha": "^5.2.0",
51
+ "mocha-junit-reporter": "^1.18.0",
52
+ "prettier": "^1.15.2",
53
+ "prettier-eslint": "^8.8.2",
54
+ "style-loader": "^0.23.1",
55
+ "underscore": "^1.9.1",
56
+ "webpack": "^4.41.3",
57
+ "webpack-cli": "^3.1.2",
58
+ "xml-parser": "^1.2.1"
59
+ },
60
+ "engines": {
61
+ "node": ">=8.12.0",
62
+ "npm": ">=6.9.0"
63
+ },
64
+ "peerDependencies": {
65
+ "webpack": "^4"
66
+ }
67
+ },
68
+ "node_modules/atlassian-webresource-webpack-plugin": {
69
+ "resolved": "../../..",
70
+ "link": true
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-complex",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "engines": {
6
+ "node": ">=12",
7
+ "npm": ">=6.9"
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ import { logChunk } from './to-be-chunked';
2
+
3
+ define('module/a', [], function() {
4
+ logChunk();
5
+ });
@@ -0,0 +1,5 @@
1
+ import { logChunk } from './to-be-chunked';
2
+
3
+ define('module/a', [], function() {
4
+ logChunk();
5
+ });
@@ -0,0 +1,2 @@
1
+ // This file tests a use case where a project has qunit test files and WWRP
2
+ // injects the qunit-require-shim file into the output.
@@ -0,0 +1 @@
1
+ export const logChunk = () => console.log('this file will be chunked.');
@@ -0,0 +1,48 @@
1
+ const WrmPlugin = require('../../../src/WrmPlugin');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ const FRONTEND_SRC_DIR = path.resolve(__dirname, 'src');
6
+ const OUTPUT_DIR = path.resolve(__dirname, 'target/classes');
7
+
8
+ const DIRECT_COPY_FILE = 'copied-file-should-be-ignored.js';
9
+
10
+ module.exports = {
11
+ mode: 'development',
12
+ context: FRONTEND_SRC_DIR,
13
+ entry: {
14
+ 'simple-entry': path.join(FRONTEND_SRC_DIR, 'entry.js'),
15
+ 'simple-entry-2': path.join(FRONTEND_SRC_DIR, 'entry2.js'),
16
+ },
17
+ optimization: {
18
+ splitChunks: {
19
+ chunks: 'all',
20
+ minSize: 0,
21
+ },
22
+ },
23
+ plugins: [
24
+ new WrmPlugin({
25
+ pluginKey: 'com.atlassian.plugin.test',
26
+ contextMap: { 'simple-entry': [''] },
27
+ addEntrypointNameAsContext: true,
28
+ xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
29
+ verbose: false,
30
+ __testGlobs__: ['./**/*.tests.js'],
31
+ }),
32
+ {
33
+ apply: compiler => {
34
+ compiler.plugin('emit', (compilation, callback) => {
35
+ const sourceFile = path.join(compiler.context, DIRECT_COPY_FILE);
36
+ const destinationFile = path.join(compiler.outputPath, DIRECT_COPY_FILE);
37
+ fs.mkdirSync(path.dirname(destinationFile), { recursive: true });
38
+ fs.copyFileSync(sourceFile, destinationFile);
39
+ callback();
40
+ });
41
+ },
42
+ },
43
+ ],
44
+ output: {
45
+ filename: '[name].js',
46
+ path: path.resolve(OUTPUT_DIR),
47
+ },
48
+ };
@@ -0,0 +1,65 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const webpack = require('webpack');
4
+ const expect = require('chai').expect;
5
+
6
+ const config = require('./webpack.config');
7
+
8
+ const targetDir = path.join(__dirname, 'target/classes');
9
+ const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
10
+
11
+ describe('simple case with association', () => {
12
+ before(done => {
13
+ webpack(config, (err, stats) => {
14
+ if (err) {
15
+ throw err;
16
+ }
17
+
18
+ if (stats.hasErrors() || stats.hasWarnings()) {
19
+ throw Error('Webpack build failed.');
20
+ }
21
+
22
+ done();
23
+ });
24
+ });
25
+
26
+ it('compiles an xml file', () => {
27
+ expect(fs.existsSync(webresourceOutput)).to.be.equal(true);
28
+ });
29
+
30
+ describe('association file', () => {
31
+ let associationJsonContent;
32
+
33
+ before(() => {
34
+ const jsonPath = path.join(
35
+ targetDir,
36
+ 'META-INF/fe-manifest-associations/com.atlassian.plugin.test-webpack.intermediary.json'
37
+ );
38
+
39
+ const isJsonExisting = fs.existsSync(jsonPath);
40
+ if (!isJsonExisting) {
41
+ throw new Error('Association JSON was not created.');
42
+ }
43
+
44
+ associationJsonContent = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
45
+ });
46
+
47
+ it('association file structure is correct', () => {
48
+ expect(associationJsonContent).to.have.property('packageName');
49
+ expect(typeof associationJsonContent.packageName).to.equal('string');
50
+ expect(associationJsonContent).to.have.property('outputDirectoryFiles');
51
+ expect(associationJsonContent.outputDirectoryFiles).to.be.an('array');
52
+ });
53
+
54
+ it('association package name is taken from config', () => {
55
+ expect(associationJsonContent.packageName).to.equal(
56
+ '@atlassian/webpack-webresource-plugin.tests.associations-simple'
57
+ );
58
+ });
59
+
60
+ it('association file includes relatives paths for files compiled through entries (exclusively)', () => {
61
+ expect(associationJsonContent.outputDirectoryFiles).to.include('simple-entry.js');
62
+ expect(associationJsonContent.outputDirectoryFiles.length).to.equal(1);
63
+ });
64
+ });
65
+ });
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-simple",
3
+ "version": "0.0.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-simple",
9
+ "version": "0.0.1",
10
+ "dependencies": {
11
+ "atlassian-webresource-webpack-plugin": "file:../../.."
12
+ }
13
+ },
14
+ "../../..": {
15
+ "version": "4.9.0",
16
+ "license": "Apache-2.0",
17
+ "dependencies": {
18
+ "glob": "^7.1.2",
19
+ "lodash": "^4.17.15",
20
+ "mkdirp": "^0.5.1",
21
+ "pretty-data": "^0.40.0",
22
+ "tapable": "^1.1.0",
23
+ "url-join": "^4.0.0",
24
+ "uuid": "^3.3.2",
25
+ "webpack-merge": "^4.2.2",
26
+ "webpack-sources": "^1.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "babel-eslint": "^10.0.1",
30
+ "chai": "^4.2.0",
31
+ "chai-string": "^1.5.0",
32
+ "chai-uuid": "^1.0.6",
33
+ "css-loader": "^1.0.1",
34
+ "eslint": "^5.9.0",
35
+ "eslint-config-prettier": "^3.3.0",
36
+ "eslint-plugin-babel": "^5.2.1",
37
+ "eslint-plugin-filenames": "^1.3.2",
38
+ "eslint-plugin-jasmine": "^2.10.1",
39
+ "eslint-plugin-mocha": "^5.2.0",
40
+ "eslint-plugin-node": "^8.0.0",
41
+ "eslint-plugin-prettier": "^3.0.0",
42
+ "extract-text-webpack-plugin": "4.0.0-beta.0",
43
+ "file-loader": "^2.0.0",
44
+ "jquery": "^3.4.1",
45
+ "mini-css-extract-plugin": "^0.4.4",
46
+ "mocha": "^5.2.0",
47
+ "mocha-junit-reporter": "^1.18.0",
48
+ "prettier": "^1.15.2",
49
+ "prettier-eslint": "^8.8.2",
50
+ "style-loader": "^0.23.1",
51
+ "underscore": "^1.9.1",
52
+ "webpack": "^4.41.3",
53
+ "webpack-cli": "^3.1.2",
54
+ "xml-parser": "^1.2.1"
55
+ },
56
+ "engines": {
57
+ "node": ">=8.12.0",
58
+ "npm": ">=6.9.0"
59
+ },
60
+ "peerDependencies": {
61
+ "webpack": "^4"
62
+ }
63
+ },
64
+ "node_modules/atlassian-webresource-webpack-plugin": {
65
+ "resolved": "../../..",
66
+ "link": true
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@atlassian/webpack-webresource-plugin.tests.associations-simple",
3
+ "version": "0.0.1",
4
+ "private": true
5
+ }
@@ -0,0 +1,3 @@
1
+ define('module/a', [], function() {
2
+ console.log('it really is simple.');
3
+ });
@@ -0,0 +1,27 @@
1
+ const WrmPlugin = require('../../../src/WrmPlugin');
2
+ const path = require('path');
3
+
4
+ const FRONTEND_SRC_DIR = path.resolve(__dirname, 'src');
5
+ const OUTPUT_DIR = path.resolve(__dirname, 'target/classes');
6
+
7
+ module.exports = {
8
+ mode: 'development',
9
+ context: FRONTEND_SRC_DIR,
10
+ entry: {
11
+ 'simple-entry': path.join(FRONTEND_SRC_DIR, 'simple.js'),
12
+ },
13
+ plugins: [
14
+ new WrmPlugin({
15
+ pluginKey: 'com.atlassian.plugin.test',
16
+ packageName: '@atlassian/webpack-webresource-plugin.tests.associations-simple',
17
+ contextMap: { 'simple-entry': [''] },
18
+ addEntrypointNameAsContext: true,
19
+ xmlDescriptors: path.join(OUTPUT_DIR, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml'),
20
+ verbose: false,
21
+ }),
22
+ ],
23
+ output: {
24
+ filename: '[name].js',
25
+ path: path.resolve(OUTPUT_DIR),
26
+ },
27
+ };
@@ -0,0 +1,113 @@
1
+ const assert = require('chai').assert;
2
+ const parse = require('xml-parser');
3
+ const webpack = require('webpack');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const targetDir = path.join(__dirname, 'target');
8
+ const webresourceOutput = path.join(targetDir, 'META-INF', 'plugin-descriptor', 'wr-webpack-bundles.xml');
9
+
10
+ describe('async-chunks', function() {
11
+ const config = require('./webpack.config.js');
12
+
13
+ let stats;
14
+ let runtime;
15
+ let app;
16
+ let asyncChunk1;
17
+ let asyncChunk2;
18
+
19
+ function getDependencies(node) {
20
+ return node.children.filter(n => n.name === 'dependency');
21
+ }
22
+
23
+ function getContent(nodes) {
24
+ return nodes.map(n => n.content);
25
+ }
26
+
27
+ beforeEach(done => {
28
+ webpack(config, (err, st) => {
29
+ stats = st;
30
+
31
+ const xmlFile = fs.readFileSync(webresourceOutput, 'utf-8');
32
+ const results = parse(xmlFile);
33
+ runtime = results.root.children.find(n => n.attributes.key.startsWith('entry'));
34
+ app = results.root.children.find(n => n.attributes.key === 'split_app');
35
+ asyncChunk1 = results.root.children.find(n => n.attributes.key === '0');
36
+ asyncChunk2 = results.root.children.find(n => n.attributes.key === '1');
37
+ done();
38
+ });
39
+ });
40
+
41
+ it('should create a webresource for each async chunk', () => {
42
+ assert.ok(app, 'entry does not exist');
43
+ assert.ok(asyncChunk1, 'asyncChunk1 does not exist');
44
+ assert.ok(asyncChunk2, 'asyncChunk2 does not exist');
45
+ assert.equal(stats.hasErrors(), false, 'should not have errors');
46
+ assert.equal(stats.hasWarnings(), false, 'should not have warnings');
47
+ });
48
+
49
+ it('should inject a WRM pre-condition checker into the webpack runtime', () => {
50
+ // setup
51
+ const bundleFile = fs.readFileSync(path.join(targetDir, 'runtime~app.js'), 'utf-8');
52
+ const expectedRuntimeAdjustment = `
53
+ /******/ var promises = [];
54
+ /******/
55
+ /******/ if(installedChunks[chunkId] === 0) { // 0 means "already installed".
56
+ /******/ return Promise.resolve();
57
+ /******/ }
58
+ /******/
59
+ /******/ if (installedChunks[chunkId]) {
60
+ /******/ return installedChunks[chunkId][2];
61
+ /******/ }
62
+ /******/
63
+ /******/ promises.push(
64
+ /******/ new Promise(function(resolve, reject) {
65
+ /******/ installedChunks[chunkId] = [resolve, reject];
66
+ /******/ }),
67
+ /******/ new Promise(function(resolve, reject) {
68
+ /******/ WRM.require('wrc!com.atlassian.plugin.test:' + chunkId).then(resolve, reject);
69
+ /******/ })
70
+ /******/ );
71
+ /******/ return installedChunks[chunkId][2] = Promise.all(promises);`;
72
+
73
+ assert.include(bundleFile, expectedRuntimeAdjustment);
74
+ });
75
+
76
+ describe('web-resource dependencies', () => {
77
+ let entryDeps;
78
+ let appDeps;
79
+ let async1Deps;
80
+ let async2Deps;
81
+
82
+ beforeEach(() => {
83
+ entryDeps = getContent(getDependencies(runtime));
84
+ appDeps = getContent(getDependencies(app));
85
+ async1Deps = getContent(getDependencies(asyncChunk1));
86
+ async2Deps = getContent(getDependencies(asyncChunk2));
87
+ });
88
+
89
+ it('adds required WRM dependency only to the web-resource with the webpack runtime', () => {
90
+ const WRM_KEY = 'com.atlassian.plugins.atlassian-plugins-webresource-rest:web-resource-manager';
91
+ assert.equal(entryDeps.includes(WRM_KEY), true);
92
+ assert.notEqual(appDeps.includes(WRM_KEY), true);
93
+ assert.notEqual(async1Deps.includes(WRM_KEY), true);
94
+ assert.notEqual(async2Deps.includes(WRM_KEY), true);
95
+ });
96
+
97
+ it('adds shared provided dependencies only to the app', () => {
98
+ const UNDERSCORE_KEY = 'com.atlassian.plugin.jslibs:underscore-1.4.4';
99
+ assert.notEqual(entryDeps.includes(UNDERSCORE_KEY), true);
100
+ assert.equal(appDeps.includes(UNDERSCORE_KEY), true);
101
+ assert.notEqual(async1Deps.includes(UNDERSCORE_KEY), true);
102
+ assert.notEqual(async2Deps.includes(UNDERSCORE_KEY), true);
103
+ });
104
+
105
+ it('adds async-chunk-only deps only to the async-chunk-webresource', () => {
106
+ const JQUERY_KEY = 'jira.webresources:jquery';
107
+ assert.notEqual(entryDeps.includes(JQUERY_KEY), true);
108
+ assert.notEqual(appDeps.includes(JQUERY_KEY), true);
109
+ assert.equal(async1Deps.includes(JQUERY_KEY), true);
110
+ assert.notEqual(async2Deps.includes(JQUERY_KEY), true);
111
+ });
112
+ });
113
+ });
@@ -0,0 +1,9 @@
1
+ import _ from 'underscore';
2
+
3
+ import('./async-bar').then(x => {
4
+ console.log(x);
5
+ });
6
+
7
+ import('./async-foo').then(x => {
8
+ console.log(x);
9
+ });
@@ -0,0 +1,4 @@
1
+ import $ from 'jquery';
2
+ import _ from 'underscore';
3
+
4
+ export default 'bar';
@@ -0,0 +1,2 @@
1
+ export default 'foo';
2
+ import _ from 'underscore';