@teambit/dependencies 1.0.330 → 1.0.331

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 (276) hide show
  1. package/artifacts/__bit_junit.xml +203 -5
  2. package/artifacts/schema.json +2016 -1173
  3. package/dependencies-loader/apply-overrides.ts +3 -3
  4. package/dependencies-loader/auto-detect-deps.ts +16 -13
  5. package/dependencies-loader/dependencies-loader.ts +1 -1
  6. package/dist/dependencies-loader/apply-overrides.js +12 -5
  7. package/dist/dependencies-loader/apply-overrides.js.map +1 -1
  8. package/dist/dependencies-loader/auto-detect-deps.d.ts +4 -4
  9. package/dist/dependencies-loader/auto-detect-deps.js +14 -14
  10. package/dist/dependencies-loader/auto-detect-deps.js.map +1 -1
  11. package/dist/dependencies-loader/dependencies-loader.js +4 -4
  12. package/dist/dependencies-loader/dependencies-loader.js.map +1 -1
  13. package/dist/files-dependency-builder/build-tree.d.ts +11 -0
  14. package/dist/files-dependency-builder/build-tree.js +233 -0
  15. package/dist/files-dependency-builder/build-tree.js.map +1 -0
  16. package/dist/files-dependency-builder/build-tree.spec.d.ts +1 -0
  17. package/dist/files-dependency-builder/build-tree.spec.js +154 -0
  18. package/dist/files-dependency-builder/build-tree.spec.js.map +1 -0
  19. package/dist/files-dependency-builder/dependency-tree/Config.d.ts +4 -0
  20. package/dist/files-dependency-builder/dependency-tree/Config.js +74 -0
  21. package/dist/files-dependency-builder/dependency-tree/Config.js.map +1 -0
  22. package/dist/files-dependency-builder/dependency-tree/index.d.ts +15 -0
  23. package/dist/files-dependency-builder/dependency-tree/index.js +272 -0
  24. package/dist/files-dependency-builder/dependency-tree/index.js.map +1 -0
  25. package/dist/files-dependency-builder/dependency-tree/index.spec.d.ts +1 -0
  26. package/dist/files-dependency-builder/dependency-tree/index.spec.js +877 -0
  27. package/dist/files-dependency-builder/dependency-tree/index.spec.js.map +1 -0
  28. package/dist/files-dependency-builder/detectives/detective-css/index.d.ts +1 -0
  29. package/dist/files-dependency-builder/detectives/detective-css/index.js +18 -0
  30. package/dist/files-dependency-builder/detectives/detective-css/index.js.map +1 -0
  31. package/dist/files-dependency-builder/detectives/detective-es6/index.d.ts +1 -0
  32. package/dist/files-dependency-builder/detectives/detective-es6/index.js +18 -0
  33. package/dist/files-dependency-builder/detectives/detective-es6/index.js.map +1 -0
  34. package/dist/files-dependency-builder/detectives/detective-less/index.d.ts +1 -0
  35. package/dist/files-dependency-builder/detectives/detective-less/index.js +18 -0
  36. package/dist/files-dependency-builder/detectives/detective-less/index.js.map +1 -0
  37. package/dist/files-dependency-builder/detectives/detective-sass/index.d.ts +1 -0
  38. package/dist/files-dependency-builder/detectives/detective-sass/index.js +18 -0
  39. package/dist/files-dependency-builder/detectives/detective-sass/index.js.map +1 -0
  40. package/dist/files-dependency-builder/detectives/detective-scss/index.d.ts +1 -0
  41. package/dist/files-dependency-builder/detectives/detective-scss/index.js +18 -0
  42. package/dist/files-dependency-builder/detectives/detective-scss/index.js.map +1 -0
  43. package/dist/files-dependency-builder/detectives/detective-typescript/index.d.ts +1 -0
  44. package/dist/files-dependency-builder/detectives/detective-typescript/index.js +18 -0
  45. package/dist/files-dependency-builder/detectives/detective-typescript/index.js.map +1 -0
  46. package/dist/files-dependency-builder/detector-hook.d.ts +47 -0
  47. package/dist/files-dependency-builder/detector-hook.js +29 -0
  48. package/dist/files-dependency-builder/detector-hook.js.map +1 -0
  49. package/dist/files-dependency-builder/filing-cabinet/index.d.ts +17 -0
  50. package/dist/files-dependency-builder/filing-cabinet/index.js +140 -0
  51. package/dist/files-dependency-builder/filing-cabinet/index.js.map +1 -0
  52. package/dist/files-dependency-builder/filing-cabinet/index.spec.d.ts +1 -0
  53. package/dist/files-dependency-builder/filing-cabinet/index.spec.js +651 -0
  54. package/dist/files-dependency-builder/filing-cabinet/index.spec.js.map +1 -0
  55. package/dist/files-dependency-builder/fixtures/build-tree/a.d.ts +1 -0
  56. package/dist/files-dependency-builder/fixtures/build-tree/a.js +6 -0
  57. package/dist/files-dependency-builder/fixtures/build-tree/a.js.map +1 -0
  58. package/dist/files-dependency-builder/fixtures/build-tree/b.d.ts +1 -0
  59. package/dist/files-dependency-builder/fixtures/build-tree/b.js +6 -0
  60. package/dist/files-dependency-builder/fixtures/build-tree/b.js.map +1 -0
  61. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.d.ts +1 -0
  62. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js +3 -0
  63. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js.map +1 -0
  64. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.d.ts +1 -0
  65. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js +3 -0
  66. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js.map +1 -0
  67. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.d.ts +1 -0
  68. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js +10 -0
  69. package/dist/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js.map +1 -0
  70. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.d.ts +1 -0
  71. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js +3 -0
  72. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js.map +1 -0
  73. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.d.ts +1 -0
  74. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js +21 -0
  75. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js.map +1 -0
  76. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.d.ts +2 -0
  77. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js +18 -0
  78. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js.map +1 -0
  79. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.d.ts +2 -0
  80. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js +20 -0
  81. package/dist/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js.map +1 -0
  82. package/dist/files-dependency-builder/fixtures/build-tree/unparsed.d.ts +0 -0
  83. package/dist/files-dependency-builder/fixtures/build-tree/unparsed.js +5 -0
  84. package/dist/files-dependency-builder/fixtures/build-tree/unparsed.js.map +1 -0
  85. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.d.ts +0 -0
  86. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.js +10 -0
  87. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/a.js.map +1 -0
  88. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.d.ts +0 -0
  89. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.js +10 -0
  90. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/b.js.map +1 -0
  91. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.d.ts +0 -0
  92. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.js +6 -0
  93. package/dist/files-dependency-builder/fixtures/dependency-tree/amd/c.js.map +1 -0
  94. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.d.ts +1 -0
  95. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js +6 -0
  96. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js.map +1 -0
  97. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.d.ts +1 -0
  98. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js +6 -0
  99. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js.map +1 -0
  100. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.d.ts +1 -0
  101. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js +6 -0
  102. package/dist/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js.map +1 -0
  103. package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.d.ts +1 -0
  104. package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js +8 -0
  105. package/dist/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js.map +1 -0
  106. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.d.ts +1 -0
  107. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js +6 -0
  108. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js.map +1 -0
  109. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.d.ts +1 -0
  110. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js +6 -0
  111. package/dist/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js.map +1 -0
  112. package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.d.ts +221 -0
  113. package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.js +259 -0
  114. package/dist/files-dependency-builder/fixtures/filing-cabinet/ast.js.map +1 -0
  115. package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.d.ts +2 -0
  116. package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.js +12 -0
  117. package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.js.map +1 -0
  118. package/dist/files-dependency-builder/fixtures/filing-cabinet/foo.scss +1 -0
  119. package/dist/files-dependency-builder/fixtures/filing-cabinet/foo2.scss +0 -0
  120. package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.d.ts +59 -0
  121. package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js +65 -0
  122. package/dist/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js.map +1 -0
  123. package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.d.ts +1 -0
  124. package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js +5 -0
  125. package/dist/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js.map +1 -0
  126. package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.d.ts +1 -0
  127. package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js +5 -0
  128. package/dist/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js.map +1 -0
  129. package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.d.ts +6 -0
  130. package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js +12 -0
  131. package/dist/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js.map +1 -0
  132. package/dist/files-dependency-builder/fixtures/missing-deps.d.ts +0 -0
  133. package/dist/files-dependency-builder/fixtures/missing-deps.js +5 -0
  134. package/dist/files-dependency-builder/fixtures/missing-deps.js.map +1 -0
  135. package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.d.ts +2 -0
  136. package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.js +24 -0
  137. package/dist/files-dependency-builder/fixtures/precinct/Gruntfile.js.map +1 -0
  138. package/dist/files-dependency-builder/fixtures/precinct/amd.d.ts +0 -0
  139. package/dist/files-dependency-builder/fixtures/precinct/amd.js +6 -0
  140. package/dist/files-dependency-builder/fixtures/precinct/amd.js.map +1 -0
  141. package/dist/files-dependency-builder/fixtures/precinct/bar.foo +1 -0
  142. package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.d.ts +6 -0
  143. package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.js +11 -0
  144. package/dist/files-dependency-builder/fixtures/precinct/cjsExportLazy.js.map +1 -0
  145. package/dist/files-dependency-builder/fixtures/precinct/commonjs.d.ts +1 -0
  146. package/dist/files-dependency-builder/fixtures/precinct/commonjs.js +7 -0
  147. package/dist/files-dependency-builder/fixtures/precinct/commonjs.js.map +1 -0
  148. package/dist/files-dependency-builder/fixtures/precinct/coreModules.d.ts +1 -0
  149. package/dist/files-dependency-builder/fixtures/precinct/coreModules.js +9 -0
  150. package/dist/files-dependency-builder/fixtures/precinct/coreModules.js.map +1 -0
  151. package/dist/files-dependency-builder/fixtures/precinct/es6.d.ts +1 -0
  152. package/dist/files-dependency-builder/fixtures/precinct/es6.js +15 -0
  153. package/dist/files-dependency-builder/fixtures/precinct/es6.js.map +1 -0
  154. package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.d.ts +5 -0
  155. package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js +15 -0
  156. package/dist/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js.map +1 -0
  157. package/dist/files-dependency-builder/fixtures/precinct/es7.d.ts +1 -0
  158. package/dist/files-dependency-builder/fixtures/precinct/es7.js +7 -0
  159. package/dist/files-dependency-builder/fixtures/precinct/es7.js.map +1 -0
  160. package/dist/files-dependency-builder/fixtures/precinct/exampleAST.d.ts +24 -0
  161. package/dist/files-dependency-builder/fixtures/precinct/exampleAST.js +30 -0
  162. package/dist/files-dependency-builder/fixtures/precinct/exampleAST.js.map +1 -0
  163. package/dist/files-dependency-builder/fixtures/precinct/foo.foo +1 -0
  164. package/dist/files-dependency-builder/fixtures/precinct/styles.css +6 -0
  165. package/dist/files-dependency-builder/fixtures/precinct/styles.less +4 -0
  166. package/dist/files-dependency-builder/fixtures/precinct/styles.sass +2 -0
  167. package/dist/files-dependency-builder/fixtures/precinct/styles.scss +3 -0
  168. package/dist/files-dependency-builder/fixtures/precinct/styles.styl +5 -0
  169. package/dist/files-dependency-builder/fixtures/precinct/typescript.d.ts +0 -0
  170. package/dist/files-dependency-builder/fixtures/precinct/typescript.js +11 -0
  171. package/dist/files-dependency-builder/fixtures/precinct/typescript.js.map +1 -0
  172. package/dist/files-dependency-builder/fixtures/precinct/unparseable.d.ts +0 -0
  173. package/dist/files-dependency-builder/fixtures/precinct/unparseable.js +9 -0
  174. package/dist/files-dependency-builder/fixtures/precinct/unparseable.js.map +1 -0
  175. package/dist/files-dependency-builder/fixtures/unsupported-file.pdf +0 -0
  176. package/dist/files-dependency-builder/generate-tree-madge.d.ts +31 -0
  177. package/dist/files-dependency-builder/generate-tree-madge.js +196 -0
  178. package/dist/files-dependency-builder/generate-tree-madge.js.map +1 -0
  179. package/dist/files-dependency-builder/index.d.ts +3 -0
  180. package/dist/files-dependency-builder/index.js +34 -0
  181. package/dist/files-dependency-builder/index.js.map +1 -0
  182. package/dist/files-dependency-builder/missing-handler.d.ts +34 -0
  183. package/dist/files-dependency-builder/missing-handler.js +107 -0
  184. package/dist/files-dependency-builder/missing-handler.js.map +1 -0
  185. package/dist/files-dependency-builder/path-map.d.ts +20 -0
  186. package/dist/files-dependency-builder/path-map.js +46 -0
  187. package/dist/files-dependency-builder/path-map.js.map +1 -0
  188. package/dist/files-dependency-builder/precinct/index.d.ts +22 -0
  189. package/dist/files-dependency-builder/precinct/index.js +306 -0
  190. package/dist/files-dependency-builder/precinct/index.js.map +1 -0
  191. package/dist/files-dependency-builder/precinct/index.spec.d.ts +1 -0
  192. package/dist/files-dependency-builder/precinct/index.spec.js +300 -0
  193. package/dist/files-dependency-builder/precinct/index.spec.js.map +1 -0
  194. package/dist/files-dependency-builder/types/dependency-tree-type.d.ts +35 -0
  195. package/dist/files-dependency-builder/types/dependency-tree-type.js +34 -0
  196. package/dist/files-dependency-builder/types/dependency-tree-type.js.map +1 -0
  197. package/dist/files-dependency-builder/types/index.d.ts +0 -0
  198. package/dist/files-dependency-builder/types/index.js +7 -0
  199. package/dist/files-dependency-builder/types/index.js.map +1 -0
  200. package/dist/index.d.ts +1 -0
  201. package/dist/index.js +25 -0
  202. package/dist/index.js.map +1 -1
  203. package/dist/resolve-pkg-data.d.ts +23 -0
  204. package/dist/resolve-pkg-data.js +157 -0
  205. package/dist/resolve-pkg-data.js.map +1 -0
  206. package/files-dependency-builder/build-tree.spec.ts +130 -0
  207. package/files-dependency-builder/build-tree.ts +185 -0
  208. package/files-dependency-builder/dependency-tree/Config.ts +68 -0
  209. package/files-dependency-builder/dependency-tree/index.spec.ts +893 -0
  210. package/files-dependency-builder/dependency-tree/index.ts +244 -0
  211. package/files-dependency-builder/detectives/detective-css/index.ts +1 -0
  212. package/files-dependency-builder/detectives/detective-es6/index.ts +1 -0
  213. package/files-dependency-builder/detectives/detective-less/index.ts +1 -0
  214. package/files-dependency-builder/detectives/detective-sass/index.ts +1 -0
  215. package/files-dependency-builder/detectives/detective-scss/index.ts +1 -0
  216. package/files-dependency-builder/detectives/detective-typescript/index.ts +1 -0
  217. package/files-dependency-builder/detector-hook.ts +69 -0
  218. package/files-dependency-builder/filing-cabinet/index.spec.ts +718 -0
  219. package/files-dependency-builder/filing-cabinet/index.ts +119 -0
  220. package/files-dependency-builder/fixtures/build-tree/a.js +2 -0
  221. package/files-dependency-builder/fixtures/build-tree/b.js +2 -0
  222. package/files-dependency-builder/fixtures/build-tree/not-link-file/file-a.js +2 -0
  223. package/files-dependency-builder/fixtures/build-tree/not-link-file/file-b.js +4 -0
  224. package/files-dependency-builder/fixtures/build-tree/not-link-file/file-c.js +3 -0
  225. package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/foo.js +2 -0
  226. package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/index.js +2 -0
  227. package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/is-string.js +3 -0
  228. package/files-dependency-builder/fixtures/build-tree/tree-shaking-cycle/self-cycle.js +3 -0
  229. package/files-dependency-builder/fixtures/build-tree/unparsed.js +2 -0
  230. package/files-dependency-builder/fixtures/dependency-tree/amd/a.js +6 -0
  231. package/files-dependency-builder/fixtures/dependency-tree/amd/b.js +6 -0
  232. package/files-dependency-builder/fixtures/dependency-tree/amd/c.js +2 -0
  233. package/files-dependency-builder/fixtures/dependency-tree/commonjs/a.js +2 -0
  234. package/files-dependency-builder/fixtures/dependency-tree/commonjs/b.js +3 -0
  235. package/files-dependency-builder/fixtures/dependency-tree/commonjs/c.js +3 -0
  236. package/files-dependency-builder/fixtures/dependency-tree/onlyRealDeps/a.js +4 -0
  237. package/files-dependency-builder/fixtures/dependency-tree/webpack/aliased.js +2 -0
  238. package/files-dependency-builder/fixtures/dependency-tree/webpack/unaliased.js +2 -0
  239. package/files-dependency-builder/fixtures/filing-cabinet/ast.js +266 -0
  240. package/files-dependency-builder/fixtures/filing-cabinet/foo.jsx +3 -0
  241. package/files-dependency-builder/fixtures/filing-cabinet/foo.scss +1 -0
  242. package/files-dependency-builder/fixtures/filing-cabinet/foo2.scss +0 -0
  243. package/files-dependency-builder/fixtures/filing-cabinet/mockedJSFiles.js +61 -0
  244. package/files-dependency-builder/fixtures/filing-cabinet/root1/mod1.js +1 -0
  245. package/files-dependency-builder/fixtures/filing-cabinet/root2/mod2.js +1 -0
  246. package/files-dependency-builder/fixtures/filing-cabinet/webpack.config.js +8 -0
  247. package/files-dependency-builder/fixtures/missing-deps.js +2 -0
  248. package/files-dependency-builder/fixtures/precinct/Gruntfile.js +22 -0
  249. package/files-dependency-builder/fixtures/precinct/amd.js +2 -0
  250. package/files-dependency-builder/fixtures/precinct/bar.foo +1 -0
  251. package/files-dependency-builder/fixtures/precinct/cjsExportLazy.js +7 -0
  252. package/files-dependency-builder/fixtures/precinct/commonjs.js +3 -0
  253. package/files-dependency-builder/fixtures/precinct/coreModules.js +5 -0
  254. package/files-dependency-builder/fixtures/precinct/es6.js +4 -0
  255. package/files-dependency-builder/fixtures/precinct/es6MixedExportLazy.js +7 -0
  256. package/files-dependency-builder/fixtures/precinct/es7.js +3 -0
  257. package/files-dependency-builder/fixtures/precinct/exampleAST.js +32 -0
  258. package/files-dependency-builder/fixtures/precinct/foo.foo +1 -0
  259. package/files-dependency-builder/fixtures/precinct/styles.css +6 -0
  260. package/files-dependency-builder/fixtures/precinct/styles.less +4 -0
  261. package/files-dependency-builder/fixtures/precinct/styles.sass +2 -0
  262. package/files-dependency-builder/fixtures/precinct/styles.scss +3 -0
  263. package/files-dependency-builder/fixtures/precinct/styles.styl +5 -0
  264. package/files-dependency-builder/fixtures/precinct/typescript.ts +8 -0
  265. package/files-dependency-builder/fixtures/precinct/unparseable.js +6 -0
  266. package/files-dependency-builder/fixtures/unsupported-file.pdf +0 -0
  267. package/files-dependency-builder/generate-tree-madge.ts +200 -0
  268. package/files-dependency-builder/index.ts +5 -0
  269. package/files-dependency-builder/missing-handler.ts +76 -0
  270. package/files-dependency-builder/path-map.ts +38 -0
  271. package/files-dependency-builder/precinct/index.spec.ts +342 -0
  272. package/files-dependency-builder/precinct/index.ts +250 -0
  273. package/files-dependency-builder/types/dependency-tree-type.ts +46 -0
  274. package/files-dependency-builder/types/index.ts +3 -0
  275. package/package.json +37 -13
  276. /package/dist/{preview-1720513025675.js → preview-1720667996237.js} +0 -0
@@ -0,0 +1,877 @@
1
+ "use strict";
2
+
3
+ function _defenderFs() {
4
+ const data = require("@teambit/defender.fs.global-bit-temp-dir");
5
+ _defenderFs = function () {
6
+ return data;
7
+ };
8
+ return data;
9
+ }
10
+ function _assert() {
11
+ const data = _interopRequireDefault(require("assert"));
12
+ _assert = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _path() {
18
+ const data = _interopRequireDefault(require("path"));
19
+ _path = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _rewire() {
25
+ const data = _interopRequireDefault(require("rewire"));
26
+ _rewire = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _sinon() {
32
+ const data = _interopRequireDefault(require("sinon"));
33
+ _sinon = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _fsExtra() {
39
+ const data = _interopRequireDefault(require("fs-extra"));
40
+ _fsExtra = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _precinct() {
46
+ const data = _interopRequireDefault(require("../precinct"));
47
+ _precinct = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
52
+ function _Config() {
53
+ const data = _interopRequireDefault(require("./Config"));
54
+ _Config = function () {
55
+ return data;
56
+ };
57
+ return data;
58
+ }
59
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
60
+ const UNIT_TEST_DIR = _path().default.join(_defenderFs().BIT_TEMP_ROOT, 'unit-test');
61
+ const expect = require('chai').expect;
62
+ const dependencyTreeRewired = (0, _rewire().default)('./');
63
+ const dependencyTree = dependencyTreeRewired.default;
64
+ const fixtures = _path().default.resolve(`${__dirname}/../fixtures/dependency-tree`);
65
+ function mockfs(obj) {
66
+ Object.entries(obj).forEach(([key, value]) => {
67
+ _fsExtra().default.mkdirSync(key, {
68
+ recursive: true
69
+ });
70
+ // @ts-ignore
71
+ Object.entries(value).forEach(([file, content]) => {
72
+ const filePath = _path().default.join(key, file);
73
+ _fsExtra().default.writeFileSync(filePath, content);
74
+ });
75
+ });
76
+ }
77
+ function cleanUnitDir() {
78
+ _fsExtra().default.removeSync(UNIT_TEST_DIR);
79
+ }
80
+ describe('dependencyTree', function () {
81
+ // @ts-ignore
82
+ this.timeout(8000);
83
+ function testTreesForFormat(format, ext = '.js') {
84
+ it('returns an object form of the dependency tree for a file', () => {
85
+ const root = `${UNIT_TEST_DIR}/${format}`;
86
+ const filename = _path().default.normalize(`${root}/a${ext}`);
87
+ const tree = dependencyTree({
88
+ filename,
89
+ root
90
+ });
91
+ (0, _assert().default)(tree instanceof Object);
92
+ const aSubTree = tree[filename];
93
+ _assert().default.ok(aSubTree instanceof Object);
94
+ const filesInSubTree = Object.keys(aSubTree);
95
+ _assert().default.equal(filesInSubTree.length, 2);
96
+ });
97
+ }
98
+ function mockStylus() {
99
+ mockfs({
100
+ [`${UNIT_TEST_DIR}/stylus`]: {
101
+ 'a.styl': `
102
+ @import "b"
103
+ @require "c.styl"
104
+ `,
105
+ 'b.styl': '@import "c"',
106
+ 'c.styl': ''
107
+ }
108
+ });
109
+ }
110
+ function mockSass() {
111
+ mockfs({
112
+ [`${UNIT_TEST_DIR}/sass`]: {
113
+ 'a.scss': `
114
+ @import "_b";
115
+ @import "_c.scss";
116
+ `,
117
+ '_b.scss': 'body { color: blue; }',
118
+ '_c.scss': 'body { color: pink; }'
119
+ }
120
+ });
121
+ }
122
+ function mockLess() {
123
+ mockfs({
124
+ [`${UNIT_TEST_DIR}/less`]: {
125
+ 'a.less': `
126
+ @import "b.css";
127
+ @import "c.less";
128
+ `,
129
+ 'b.css': 'body { color: blue; }',
130
+ 'c.less': 'body { color: pink; }'
131
+ }
132
+ });
133
+ }
134
+ function mockcommonjs() {
135
+ mockfs({
136
+ [`${UNIT_TEST_DIR}/commonjs`]: {
137
+ 'a.js': `
138
+ var b = require('./b');
139
+ var c = require('./c');
140
+ `,
141
+ 'b.js': `
142
+ var path = require('path');
143
+ module.exports = {};
144
+ `,
145
+ 'c.js': `
146
+ var fs = require('fs');
147
+ module.exports = {};
148
+ `
149
+ }
150
+ });
151
+ }
152
+ function mockes6() {
153
+ mockfs({
154
+ [`${UNIT_TEST_DIR}/es6`]: {
155
+ 'a.js': `
156
+ import b from './b';
157
+ import c from './c';
158
+ `,
159
+ 'b.js': 'export default () => {};',
160
+ 'c.js': 'export default () => {};',
161
+ 'jsx.js': "import c from './c';\n export default <jsx />;",
162
+ 'foo.jsx': "import React from 'react';\n import b from './b';\n export default <jsx />;",
163
+ 'es7.js': "import c from './c';\n export default async function foo() {};"
164
+ }
165
+ });
166
+ }
167
+ function mockTS() {
168
+ mockfs({
169
+ [`${UNIT_TEST_DIR}/ts`]: {
170
+ 'a.ts': `
171
+ import b from './b';
172
+ import c from './c';
173
+ `,
174
+ 'b.ts': 'export default () => {};',
175
+ 'c.ts': 'export default () => {};'
176
+ }
177
+ });
178
+ }
179
+ afterEach(() => {
180
+ // mockfs.restore();
181
+ cleanUnitDir();
182
+ });
183
+ it('returns an empty object for a non-existent filename', () => {
184
+ mockfs({
185
+ imaginary: {}
186
+ });
187
+ const root = `${UNIT_TEST_DIR}/imaginary`;
188
+ const filename = `${root}/notafile.js`;
189
+ const tree = dependencyTree({
190
+ filename,
191
+ root
192
+ });
193
+ (0, _assert().default)(tree instanceof Object);
194
+ (0, _assert().default)(!Object.keys(tree).length);
195
+ });
196
+ it('handles nested tree structures', () => {
197
+ const directory = `${UNIT_TEST_DIR}/extended`;
198
+ mockfs({
199
+ [directory]: {
200
+ 'a.js': `
201
+ var b = require('./b');
202
+ var c = require('./c');`,
203
+ 'b.js': `
204
+ var d = require('./d');
205
+ var e = require('./e');`,
206
+ 'c.js': `
207
+ var f = require('./f');
208
+ var g = require('./g');`,
209
+ 'd.js': '',
210
+ 'e.js': '',
211
+ 'f.js': '',
212
+ 'g.js': ''
213
+ }
214
+ });
215
+ const filename = _path().default.normalize(`${directory}/a.js`);
216
+ const tree = dependencyTree({
217
+ filename,
218
+ directory
219
+ });
220
+ (0, _assert().default)(tree[filename] instanceof Object);
221
+
222
+ // b and c
223
+ const subTree = tree[filename];
224
+ _assert().default.equal(subTree.length, 2);
225
+ const bTree = tree[_path().default.normalize(`${directory}/b.js`)];
226
+ const cTree = tree[_path().default.normalize(`${directory}/c.js`)];
227
+ // d and e
228
+ _assert().default.equal(bTree.length, 2);
229
+ // f ang g
230
+ _assert().default.equal(cTree.length, 2);
231
+ });
232
+ it('does not include files that are not real (#13)', () => {
233
+ mockfs({
234
+ [`${UNIT_TEST_DIR}/onlyRealDeps`]: {
235
+ 'a.js': 'var notReal = require("./notReal");'
236
+ }
237
+ });
238
+ const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
239
+ const filename = _path().default.normalize(`${directory}/a.js`);
240
+ const tree = dependencyTree({
241
+ filename,
242
+ directory
243
+ });
244
+ const subTree = tree[filename];
245
+ _assert().default.ok(!Object.keys(subTree).some(dep => dep.indexOf('notReal') !== -1));
246
+ });
247
+ it('does not choke on cyclic dependencies', () => {
248
+ mockfs({
249
+ [`${UNIT_TEST_DIR}/cyclic`]: {
250
+ 'a.js': 'var b = require("./b");',
251
+ 'b.js': 'var a = require("./a");'
252
+ }
253
+ });
254
+ const directory = `${UNIT_TEST_DIR}/cyclic`;
255
+ const filename = _path().default.normalize(`${directory}/a.js`);
256
+ const spy = _sinon().default.spy(dependencyTreeRewired, '_getDependencies');
257
+ const tree = dependencyTreeRewired.default({
258
+ filename,
259
+ directory
260
+ });
261
+ (0, _assert().default)(spy.callCount === 2);
262
+ (0, _assert().default)(Object.keys(tree[filename]).length);
263
+ dependencyTreeRewired._getDependencies.restore();
264
+ });
265
+ it('excludes Nodejs core modules by default', () => {
266
+ const directory = `${fixtures}/commonjs`;
267
+ const filename = _path().default.normalize(`${directory}/b.js`);
268
+ const tree = dependencyTree({
269
+ filename,
270
+ directory
271
+ });
272
+ (0, _assert().default)(Object.keys(tree[filename]).length === 0);
273
+ (0, _assert().default)(Object.keys(tree)[0].indexOf('b.js') !== -1);
274
+ });
275
+ it('returns a list of absolutely pathed files', () => {
276
+ const directory = `${UNIT_TEST_DIR}/commonjs`;
277
+ const filename = `${directory}/b.js`;
278
+ const tree = dependencyTree({
279
+ filename,
280
+ directory
281
+ });
282
+ // eslint-disable-next-line
283
+ for (const node in tree.nodes) {
284
+ (0, _assert().default)(node.indexOf(process.cwd()) !== -1);
285
+ }
286
+ });
287
+ describe('when given a detective configuration', () => {
288
+ it('passes it through to precinct', () => {
289
+ const spy = _sinon().default.spy(_precinct().default, 'paperwork');
290
+ const directory = _path().default.normalize(`${fixtures}/onlyRealDeps`);
291
+ const filename = _path().default.normalize(`${directory}/a.js`);
292
+ const detectiveConfig = {
293
+ amd: {
294
+ skipLazyLoaded: true
295
+ }
296
+ };
297
+ dependencyTree({
298
+ filename,
299
+ directory,
300
+ detective: detectiveConfig
301
+ });
302
+ _assert().default.ok(spy.calledWith(filename, detectiveConfig));
303
+ spy.restore();
304
+ });
305
+ });
306
+ describe('when given a list to store non existent partials', () => {
307
+ describe('and the file contains no valid partials', () => {
308
+ it('stores the invalid partials', () => {
309
+ mockfs({
310
+ [`${UNIT_TEST_DIR}/onlyRealDeps`]: {
311
+ 'a.js': 'var notReal = require("./notReal");'
312
+ }
313
+ });
314
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/onlyRealDeps`);
315
+ const filename = _path().default.normalize(`${directory}/a.js`);
316
+ const nonExistent = [];
317
+ dependencyTree({
318
+ filename,
319
+ directory,
320
+ nonExistent
321
+ });
322
+ _assert().default.equal(Object.keys(nonExistent).length, 1);
323
+ _assert().default.equal(nonExistent[filename][0], './notReal');
324
+ });
325
+ });
326
+ describe('and the file contains all valid partials', () => {
327
+ it('does not store anything', () => {
328
+ mockfs({
329
+ [`${UNIT_TEST_DIR}/onlyRealDeps`]: {
330
+ 'a.js': 'var b = require("./b");',
331
+ 'b.js': 'export default 1;'
332
+ }
333
+ });
334
+ const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
335
+ const filename = `${directory}/a.js`;
336
+ const nonExistent = [];
337
+ dependencyTree({
338
+ filename,
339
+ directory,
340
+ nonExistent
341
+ });
342
+ _assert().default.equal(nonExistent.length, 0);
343
+ });
344
+ });
345
+ describe('and the file contains a mix of invalid and valid partials', () => {
346
+ it('stores the invalid ones', () => {
347
+ mockfs({
348
+ [`${UNIT_TEST_DIR}/onlyRealDeps`]: {
349
+ 'a.js': 'var b = require("./b");',
350
+ 'b.js': 'var c = require("./c"); export default 1;',
351
+ 'c.js': 'var crap = require("./notRealMan");'
352
+ }
353
+ });
354
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/onlyRealDeps`);
355
+ const filename = _path().default.normalize(`${directory}/a.js`);
356
+ const nonExistent = [];
357
+ dependencyTree({
358
+ filename,
359
+ directory,
360
+ nonExistent
361
+ });
362
+ _assert().default.equal(Object.keys(nonExistent).length, 1);
363
+ _assert().default.equal(nonExistent[_path().default.normalize(`${directory}/c.js`)][0], './notRealMan');
364
+ });
365
+ });
366
+ describe('and there is more than one reference to the invalid partial', () => {
367
+ it('should include the non-existent partial per file', () => {
368
+ mockfs({
369
+ [`${UNIT_TEST_DIR}/onlyRealDeps`]: {
370
+ 'a.js': 'var b = require("./b");\nvar crap = require("./notRealMan");',
371
+ 'b.js': 'var c = require("./c"); export default 1;',
372
+ 'c.js': 'var crap = require("./notRealMan");'
373
+ }
374
+ });
375
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/onlyRealDeps`);
376
+ const filename = _path().default.normalize(`${directory}/a.js`);
377
+ const nonExistent = [];
378
+ dependencyTree({
379
+ filename,
380
+ directory,
381
+ nonExistent
382
+ });
383
+ _assert().default.equal(Object.keys(nonExistent).length, 2);
384
+ _assert().default.equal(nonExistent[filename][0], './notRealMan');
385
+ _assert().default.equal(nonExistent[_path().default.normalize(`${directory}/c.js`)][0], './notRealMan');
386
+ });
387
+ });
388
+ });
389
+ describe('throws', () => {
390
+ beforeEach(() => {
391
+ // @ts-ignore
392
+ this._directory = `${UNIT_TEST_DIR}/commonjs`;
393
+ // @ts-ignore
394
+ this._revert = dependencyTreeRewired.__set__('traverse', () => []);
395
+ });
396
+ afterEach(() => {
397
+ // @ts-ignore
398
+ this._revert();
399
+ });
400
+ it('throws if the filename is missing', () => {
401
+ _assert().default.throws(() => {
402
+ dependencyTree({
403
+ filename: undefined,
404
+ // @ts-ignore
405
+ directory: this._directory
406
+ });
407
+ });
408
+ });
409
+ it('throws if the root is missing', () => {
410
+ _assert().default.throws(() => {
411
+ dependencyTree({
412
+ filename: undefined
413
+ });
414
+ });
415
+ });
416
+ it('throws if a supplied filter is not a function', () => {
417
+ _assert().default.throws(() => {
418
+ const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
419
+ const filename = `${directory}/a.js`;
420
+ dependencyTree({
421
+ filename,
422
+ directory,
423
+ filter: 'foobar'
424
+ });
425
+ });
426
+ });
427
+ it('does not throw on the legacy `root` option', () => {
428
+ _assert().default.doesNotThrow(() => {
429
+ const directory = `${UNIT_TEST_DIR}/onlyRealDeps`;
430
+ const filename = `${directory}/a.js`;
431
+ dependencyTree({
432
+ filename,
433
+ root: directory
434
+ });
435
+ });
436
+ });
437
+ });
438
+ describe('on file error', () => {
439
+ beforeEach(() => {
440
+ // @ts-ignore
441
+ this._directory = `${UNIT_TEST_DIR}/commonjs`;
442
+ });
443
+ it('does not throw', () => {
444
+ _assert().default.doesNotThrow(() => {
445
+ dependencyTree({
446
+ filename: 'foo',
447
+ // @ts-ignore
448
+ directory: this._directory
449
+ });
450
+ });
451
+ });
452
+ it('returns no dependencies', () => {
453
+ // @ts-ignore
454
+ const tree = dependencyTree({
455
+ filename: 'foo',
456
+ directory: this._directory
457
+ });
458
+ (0, _assert().default)(!tree.length);
459
+ });
460
+ });
461
+ describe('memoization (#2)', () => {
462
+ beforeEach(() => {
463
+ // @ts-ignore
464
+ this._spy = _sinon().default.spy(dependencyTreeRewired, '_getDependencies');
465
+ });
466
+ afterEach(() => {
467
+ dependencyTreeRewired._getDependencies.restore();
468
+ });
469
+ it('returns the precomputed list of a cached entry point', () => {
470
+ const filename = `${UNIT_TEST_DIR}/amd/a.js`;
471
+ const directory = `${UNIT_TEST_DIR}/amd`;
472
+ const cache = {
473
+ // Shouldn't process the first file's tree
474
+ [filename]: {
475
+ pathMap: {
476
+ dependencies: []
477
+ }
478
+ }
479
+ };
480
+ const tree = dependencyTree({
481
+ filename,
482
+ directory,
483
+ visited: cache
484
+ });
485
+ (0, _assert().default)(!tree.length);
486
+ });
487
+ });
488
+ describe('module formats', () => {
489
+ describe('commonjs', () => {
490
+ beforeEach(() => {
491
+ // @ts-ignore
492
+ this._directory = _path().default.normalize(`${UNIT_TEST_DIR}/es6`);
493
+ mockcommonjs();
494
+ });
495
+ testTreesForFormat('commonjs');
496
+ });
497
+ describe('es6', () => {
498
+ beforeEach(() => {
499
+ // @ts-ignore
500
+ this._directory = _path().default.normalize(`${UNIT_TEST_DIR}/es6`);
501
+ mockes6();
502
+ });
503
+ testTreesForFormat('es6');
504
+ it('resolves files that have jsx', () => {
505
+ // @ts-ignore
506
+ const filename = _path().default.normalize(`${this._directory}/jsx.js`);
507
+ const tree = dependencyTree({
508
+ filename,
509
+ // @ts-ignore
510
+ directory: this._directory
511
+ });
512
+ // @ts-ignore
513
+ _assert().default.ok(tree[filename].includes(_path().default.normalize(`${this._directory}/c.js`)));
514
+ });
515
+ it('resolves files with a jsx extension', () => {
516
+ // @ts-ignore
517
+ const filename = _path().default.normalize(`${this._directory}/foo.jsx`);
518
+ const tree = dependencyTree({
519
+ filename,
520
+ // @ts-ignore
521
+ directory: this._directory
522
+ });
523
+ // @ts-ignore
524
+ _assert().default.ok(tree[filename].includes(_path().default.normalize(`${this._directory}/b.js`)));
525
+ });
526
+ it('resolves files that have es7', () => {
527
+ // @ts-ignore
528
+ const filename = _path().default.normalize(`${this._directory}/es7.js`);
529
+ const tree = dependencyTree({
530
+ filename,
531
+ // @ts-ignore
532
+ directory: this._directory
533
+ });
534
+ // @ts-ignore
535
+ _assert().default.ok(tree[filename].includes(_path().default.normalize(`${this._directory}/c.js`)));
536
+ });
537
+ });
538
+ describe('sass', () => {
539
+ beforeEach(() => {
540
+ mockSass();
541
+ });
542
+ testTreesForFormat('sass', '.scss');
543
+ });
544
+ describe('stylus', () => {
545
+ beforeEach(() => {
546
+ mockStylus();
547
+ });
548
+ testTreesForFormat('stylus', '.styl');
549
+ });
550
+ describe('less', () => {
551
+ beforeEach(() => {
552
+ mockLess();
553
+ });
554
+ testTreesForFormat('less', '.less');
555
+ });
556
+ describe('typescript', () => {
557
+ beforeEach(() => {
558
+ mockTS();
559
+ });
560
+ testTreesForFormat('ts', '.ts');
561
+ });
562
+ });
563
+
564
+ // skipping the webpack unit tests for now as it's not easy to wire up all the files together.
565
+ // originally, in dependency-tree, the webpack.config.js is in the same directory of the index.js.
566
+ // doing the same here will be confusing. instead, we have already e2e-tests in bit legacy of custom
567
+ // module resolution, which takes advantage of the webpack config.
568
+ describe.skip('webpack', () => {
569
+ beforeEach(() => {
570
+ // Note: not mocking because webpack's resolver needs a real project with dependencies;
571
+ // otherwise, we'd have to mock a ton of files.
572
+ // @ts-ignore
573
+ this._root = _path().default.join(UNIT_TEST_DIR, '../');
574
+ // @ts-ignore
575
+ this._webpackConfig = `${this._root}/webpack.config.js`;
576
+ // @ts-ignore
577
+ this._testResolution = name => {
578
+ const results = dependencyTree.toList({
579
+ filename: `${UNIT_TEST_DIR}/webpack/${name}.js`,
580
+ // @ts-ignore
581
+ directory: this._root,
582
+ // @ts-ignore
583
+ webpackConfig: this._webpackConfig,
584
+ filter: filename => filename.indexOf('filing-cabinet') !== -1
585
+ });
586
+ _assert().default.ok(results.some(filename => filename.indexOf('node_modules/filing-cabinet') !== -1));
587
+ };
588
+ });
589
+ it('resolves unaliased modules', () => {
590
+ // @ts-ignore
591
+ this.timeout(5000);
592
+ // @ts-ignore
593
+ this._testResolution('unaliased');
594
+ });
595
+ });
596
+ describe('when a filter function is supplied', () => {
597
+ it('uses the filter to determine if a file should be included in the results', () => {
598
+ const directory = _path().default.normalize(`${fixtures}/onlyRealDeps`);
599
+ const filename = _path().default.normalize(`${directory}/a.js`);
600
+ const tree = dependencyTree({
601
+ filename,
602
+ directory,
603
+ // Skip all 3rd party deps
604
+ filter: (filePath, moduleFile) => {
605
+ _assert().default.ok(require.resolve('debug'));
606
+ _assert().default.ok(moduleFile.includes(_path().default.normalize('onlyRealDeps/a.js')));
607
+ return filePath.indexOf('node_modules') === -1;
608
+ }
609
+ });
610
+ const subTree = tree[filename];
611
+ _assert().default.ok(Object.keys(tree).length);
612
+ const has3rdPartyDep = Object.keys(subTree).some(dep => dep === require.resolve('debug'));
613
+ _assert().default.ok(!has3rdPartyDep);
614
+ });
615
+ });
616
+ describe('when given a CJS file with lazy requires', () => {
617
+ beforeEach(() => {
618
+ mockfs({
619
+ [`${UNIT_TEST_DIR}/cjs`]: {
620
+ 'foo.js': 'module.exports = function(bar = require("./bar")) {};',
621
+ 'bar.js': 'module.exports = 1;'
622
+ }
623
+ });
624
+ });
625
+ it('includes the lazy dependency', () => {
626
+ const directory = `${UNIT_TEST_DIR}/cjs`;
627
+ const filename = _path().default.normalize(`${directory}/foo.js`);
628
+ const tree = dependencyTree({
629
+ filename,
630
+ directory
631
+ });
632
+ _assert().default.ok(tree[filename].includes(_path().default.normalize(`${directory}/bar.js`)));
633
+ });
634
+ });
635
+ describe('when given an es6 file using CJS lazy requires', () => {
636
+ beforeEach(() => {
637
+ mockfs({
638
+ [`${UNIT_TEST_DIR}/es6`]: {
639
+ 'foo.js': 'export default function(bar = require("./bar")) {};',
640
+ 'bar.js': 'export default 1;'
641
+ }
642
+ });
643
+ });
644
+ describe('and mixedImport mode is turned on', () => {
645
+ it('includes the lazy dependency', () => {
646
+ const directory = `${UNIT_TEST_DIR}/es6`;
647
+ const filename = _path().default.normalize(`${directory}/foo.js`);
648
+ const tree = dependencyTree({
649
+ filename,
650
+ directory,
651
+ detective: {
652
+ es6: {
653
+ mixedImports: true
654
+ }
655
+ }
656
+ });
657
+ _assert().default.ok(tree[filename].includes(_path().default.normalize(`${directory}/bar.js`)));
658
+ });
659
+ });
660
+ });
661
+ describe('when given an es6 file using dynamic imports', () => {
662
+ beforeEach(() => {
663
+ mockfs({
664
+ [`${UNIT_TEST_DIR}/es6`]: {
665
+ 'foo.js': 'import("./bar");',
666
+ 'bar.js': 'export default 1;'
667
+ }
668
+ });
669
+ });
670
+ it('includes the dynamic import', () => {
671
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/es6`);
672
+ const filename = _path().default.normalize(`${directory}/foo.js`);
673
+ const tree = dependencyTree({
674
+ filename,
675
+ directory
676
+ });
677
+ const subTree = tree[filename];
678
+ _assert().default.ok(!(`${directory}/bar.js` in subTree));
679
+ });
680
+ });
681
+ describe('when a dependency of the main file is not supported', () => {
682
+ beforeEach(() => {
683
+ mockfs({
684
+ [`${UNIT_TEST_DIR}/baz`]: {
685
+ 'foo.js': 'require("./bar.json");',
686
+ 'bar.json': '{ "main": "I\'m a simple JSON object" }'
687
+ }
688
+ });
689
+ });
690
+ it('should include it as a dependency and not throw an error', () => {
691
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/baz`);
692
+ const filename = _path().default.normalize(`${directory}/foo.js`);
693
+ const tree = dependencyTree({
694
+ filename,
695
+ directory
696
+ });
697
+ _assert().default.ok(`${directory}/bar.json` in tree);
698
+ });
699
+ });
700
+
701
+ // nodeModulesConfig is a feature added to dependency-tree and filing-cabinet to support
702
+ // "module" attribute of package.json, see here what this attribute is good for:
703
+ // https://github.com/rollup/rollup/wiki/pkg.module
704
+ // the commit of supporting it in filing-cabinet is here: https://github.com/dependents/node-filing-cabinet/commit/abef861a5a725b29c2342d01de94c6e2dd881aa0
705
+ describe.skip('when given a CJS file with module property in package.json', () => {
706
+ beforeEach(() => {
707
+ mockfs({
708
+ [`${UNIT_TEST_DIR}/es6`]: {
709
+ 'module.entry.js': 'import * as module from "module.entry"',
710
+ node_modules: {
711
+ 'module.entry': {
712
+ 'index.main.js': 'module.exports = () => {};',
713
+ 'index.module.js': 'module.exports = () => {};',
714
+ 'package.json': '{ "main": "index.main.js", "module": "index.module.js" }'
715
+ }
716
+ }
717
+ }
718
+ });
719
+ });
720
+ it('it includes the module entry as dependency', () => {
721
+ const directory = `${UNIT_TEST_DIR}/es6`;
722
+ const filename = `${directory}/module.entry.js`;
723
+ const tree = dependencyTree({
724
+ filename,
725
+ directory,
726
+ nodeModulesConfig: {
727
+ entry: 'module'
728
+ }
729
+ });
730
+ const subTree = tree[filename];
731
+ _assert().default.ok(`${directory}/node_modules/module.entry/index.module.js` in subTree);
732
+ });
733
+ });
734
+ describe('Config', () => {
735
+ describe('when cloning', () => {
736
+ describe('and a detective config was set', () => {
737
+ it('retains the detective config in the clone', () => {
738
+ const detectiveConfig = {
739
+ es6: {
740
+ mixedImports: true
741
+ }
742
+ };
743
+ const config = new (_Config().default)({
744
+ detectiveConfig,
745
+ filename: 'foo',
746
+ directory: 'bar'
747
+ });
748
+ const clone = config.clone();
749
+ _assert().default.deepEqual(clone.detectiveConfig, detectiveConfig);
750
+ });
751
+ });
752
+ });
753
+ });
754
+ describe('when a dependency has missing packages and is retrieved from the cache (visited)', () => {
755
+ beforeEach(() => {
756
+ mockfs({
757
+ [`${UNIT_TEST_DIR}/baz`]: {
758
+ 'foo.js': 'require("non-exist-foo-pkg");',
759
+ 'bar.js': 'require("./foo"); require("non-exist-bar-pkg")',
760
+ 'baz.js': 'require("./foo"); require("./bar"); require("non-exist-baz-pkg")'
761
+ }
762
+ });
763
+ });
764
+ it('should not override the cache with wrong packages', () => {
765
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/baz`);
766
+ const fooFile = _path().default.normalize(`${directory}/foo.js`);
767
+ const barFile = _path().default.normalize(`${directory}/bar.js`);
768
+ const bazFile = _path().default.normalize(`${directory}/baz.js`);
769
+ const nonExistent = {};
770
+ const config = {
771
+ directory,
772
+ nonExistent,
773
+ visited: {}
774
+ };
775
+
776
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
777
+ config.filename = fooFile;
778
+ dependencyTree(config);
779
+ expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
780
+
781
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
782
+ config.filename = barFile;
783
+ dependencyTree(config);
784
+ expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
785
+ expect(nonExistent[barFile]).to.deep.equal(['non-exist-bar-pkg']);
786
+
787
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
788
+ config.filename = bazFile;
789
+ dependencyTree(config);
790
+ expect(nonExistent[fooFile]).to.deep.equal(['non-exist-foo-pkg']);
791
+ expect(nonExistent[barFile]).to.deep.equal(['non-exist-bar-pkg']);
792
+ expect(nonExistent[bazFile]).to.deep.equal(['non-exist-baz-pkg']);
793
+ });
794
+ });
795
+ describe('passing css files and then javascript files', () => {
796
+ beforeEach(() => {
797
+ mockfs({
798
+ [`${UNIT_TEST_DIR}/baz`]: {
799
+ 'base.scss': 'li {} a {}',
800
+ // don't change the content. it crash only with this for some reason
801
+ 'index.jsx': "require('some-module');"
802
+ }
803
+ });
804
+ });
805
+ it('should not crash with "RangeError: Maximum call stack size exceeded" error', () => {
806
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/baz`);
807
+ const baseFile = _path().default.normalize(`${directory}/base.scss`);
808
+ const indexFile = _path().default.normalize(`${directory}/index.jsx`);
809
+ const config = {
810
+ directory
811
+ };
812
+
813
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
814
+ config.filename = baseFile;
815
+ dependencyTree(config);
816
+
817
+ // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
818
+ config.filename = indexFile;
819
+ const dependencies = dependencyTree(config);
820
+ expect(dependencies).to.be.ok;
821
+ });
822
+ });
823
+ describe('files with dynamic import', () => {
824
+ it('should not show missing dependencies', () => {
825
+ mockfs({
826
+ [`${UNIT_TEST_DIR}/dynamic`]: {
827
+ 'foo.js': 'const a = "./b"; import(a); require(a);'
828
+ }
829
+ });
830
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/dynamic`);
831
+ const filename = _path().default.normalize(`${directory}/foo.js`);
832
+ const visited = {};
833
+ dependencyTree({
834
+ filename,
835
+ directory,
836
+ visited
837
+ });
838
+ expect(visited[filename].missing).to.be.undefined;
839
+ });
840
+ });
841
+ describe('files with import from cdn (http, https)', () => {
842
+ it('should not show missing dependencies when importing from https', () => {
843
+ mockfs({
844
+ [`${UNIT_TEST_DIR}/cdn`]: {
845
+ 'foo.js': 'import { a } from "https://unpkg.com";'
846
+ }
847
+ });
848
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/cdn`);
849
+ const filename = _path().default.normalize(`${directory}/foo.js`);
850
+ const visited = {};
851
+ dependencyTree({
852
+ filename,
853
+ directory,
854
+ visited
855
+ });
856
+ expect(visited[filename].missing).to.be.undefined;
857
+ });
858
+ it('should not show missing dependencies when importing from http', () => {
859
+ mockfs({
860
+ [`${UNIT_TEST_DIR}/cdn`]: {
861
+ 'bar.js': 'const b = require("http://pkg.com");'
862
+ }
863
+ });
864
+ const directory = _path().default.normalize(`${UNIT_TEST_DIR}/cdn`);
865
+ const filename = _path().default.normalize(`${directory}/bar.js`);
866
+ const visited = {};
867
+ dependencyTree({
868
+ filename,
869
+ directory,
870
+ visited
871
+ });
872
+ expect(visited[filename].missing).to.be.undefined;
873
+ });
874
+ });
875
+ });
876
+
877
+ //# sourceMappingURL=index.spec.js.map