@modern-js/server-utils 2.26.1-alpha.1 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/common/index.js +2 -2
  3. package/dist/cjs/compilers/babel/preset/alias.js +2 -2
  4. package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +2 -2
  5. package/dist/esm/common/index.js +2 -2
  6. package/dist/esm/compilers/babel/preset/alias.js +2 -2
  7. package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +2 -2
  8. package/dist/esm-node/common/index.js +2 -2
  9. package/dist/esm-node/compilers/babel/preset/alias.js +2 -2
  10. package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +2 -2
  11. package/package.json +11 -19
  12. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -56
  13. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -13
  14. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -28
  15. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -21
  16. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -157
  17. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -92
  18. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -24
  19. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -19
  20. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -98
  21. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -92
  22. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -73
  23. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -74
  24. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -118
  25. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -863
  26. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -21
  27. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -50
  28. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -1
  29. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -1
  30. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -1
  31. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
  32. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -1
  33. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -1
  34. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -1
  35. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -1
  36. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
  37. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -1
  38. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -1
  39. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -1
  40. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -1
  41. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -1
  42. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -1
  43. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -1
  44. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -1
  45. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -1
  46. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -1
  47. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -1
  48. package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -12
  49. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -41
  50. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -8
  51. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -17
  52. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -10
  53. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -162
  54. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -86
  55. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -15
  56. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -8
  57. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -57
  58. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -87
  59. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -68
  60. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -71
  61. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -124
  62. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -862
  63. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -16
  64. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -45
  65. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -0
  66. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -0
  67. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -0
  68. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
  69. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -0
  70. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -0
  71. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -0
  72. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -0
  73. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
  74. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -0
  75. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -0
  76. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -0
  77. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -0
  78. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -0
  79. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -0
  80. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -0
  81. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -0
  82. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -0
  83. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -0
  84. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -0
  85. package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -2
  86. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -37
  87. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -3
  88. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -17
  89. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -10
  90. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -146
  91. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -81
  92. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -13
  93. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -8
  94. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -57
  95. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -87
  96. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -68
  97. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -69
  98. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -113
  99. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -857
  100. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -16
  101. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -45
  102. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -0
  103. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -0
  104. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -0
  105. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
  106. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -0
  107. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -0
  108. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -0
  109. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -0
  110. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
  111. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -0
  112. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -0
  113. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -0
  114. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -0
  115. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -0
  116. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -0
  117. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -0
  118. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -0
  119. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -0
  120. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -0
  121. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -0
  122. package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -2
  123. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/index.d.ts +0 -19
  124. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/log.d.ts +0 -1
  125. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.d.ts +0 -1
  126. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.d.ts +0 -1
  127. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.d.ts +0 -24
  128. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.d.ts +0 -1
  129. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.d.ts +0 -1
  130. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.d.ts +0 -1
  131. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.d.ts +0 -9
  132. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.d.ts +0 -1
  133. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.d.ts +0 -1
  134. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.d.ts +0 -1
  135. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.d.ts +0 -1
  136. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.d.ts +0 -1
  137. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.d.ts +0 -1
  138. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.d.ts +0 -1
  139. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.d.ts +0 -0
  140. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.d.ts +0 -0
  141. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.d.ts +0 -0
  142. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.d.ts +0 -0
  143. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.d.ts +0 -0
  144. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.d.ts +0 -0
  145. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.d.ts +0 -0
  146. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.d.ts +0 -0
  147. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.d.ts +0 -0
  148. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.d.ts +0 -0
  149. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.d.ts +0 -0
  150. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.d.ts +0 -0
  151. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.d.ts +0 -0
  152. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.d.mts +0 -1
  153. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.d.ts +0 -0
  154. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.d.ts +0 -0
  155. package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.d.ts +0 -1
  156. package/test-setup.js +0 -7
@@ -1,863 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
6
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
7
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
8
- const _core = require("@babel/core");
9
- const _src = /* @__PURE__ */ _interop_require_wildcard._(require("../src"));
10
- describe("module-resolver", () => {
11
- function testWithImport(source, output, transformerOpts) {
12
- const code = `import something from "${source}";`;
13
- const result = (0, _core.transform)(code, transformerOpts);
14
- expect(result.code).toBe(`import something from "${output}";`);
15
- }
16
- describe("exports", () => {
17
- describe("resolvePath", () => {
18
- it("should be a function", () => {
19
- expect(_src.resolvePath).toEqual(expect.any(Function));
20
- });
21
- it("should resolve the file path", () => {
22
- const opts = {
23
- root: [
24
- "./test/testproject/src"
25
- ]
26
- };
27
- const result = (0, _src.resolvePath)("app", "./test/testproject/src/app", opts);
28
- expect(result).toBe("./app");
29
- });
30
- });
31
- });
32
- describe("root", () => {
33
- describe("simple root", () => {
34
- const rootTransformerOpts = {
35
- babelrc: false,
36
- plugins: [
37
- [
38
- _src.default,
39
- {
40
- root: "./test/testproject/src"
41
- }
42
- ]
43
- ]
44
- };
45
- it.only("should resolve the file path", () => {
46
- testWithImport("app", "./test/testproject/src/app", rootTransformerOpts);
47
- });
48
- it("should resolve the sub file path", () => {
49
- testWithImport("components/Root", "./test/testproject/src/components/Root", rootTransformerOpts);
50
- });
51
- it("should resolve a sub file path without /index", () => {
52
- testWithImport("components/Header", "./test/testproject/src/components/Header", rootTransformerOpts);
53
- });
54
- it("should resolve the file path while keeping the extension", () => {
55
- testWithImport("components/Header/header.css", "./test/testproject/src/components/Header/header.css", rootTransformerOpts);
56
- });
57
- it("should resolve the file path with an extension that is non-standard in node", () => {
58
- testWithImport("es6module", "./test/testproject/src/es6module", rootTransformerOpts);
59
- });
60
- it("should resolve the file path with the node module extension", () => {
61
- testWithImport("nodemodule", "./test/testproject/src/nodemodule", rootTransformerOpts);
62
- });
63
- it("should not resolve the file path with an unknown extension", () => {
64
- testWithImport("text", "text", rootTransformerOpts);
65
- });
66
- it("should resolve the file path with a filename containing a dot", () => {
67
- testWithImport("libs/custom.modernizr3", "./test/testproject/src/libs/custom.modernizr3", rootTransformerOpts);
68
- });
69
- it("should resolve to a file instead of a directory", () => {
70
- testWithImport("constants", "../constants", {
71
- ...rootTransformerOpts,
72
- filename: "./test/testproject/src/constants/actions.js"
73
- });
74
- });
75
- it("should not resolve a path outside of the root directory", () => {
76
- testWithImport("lodash/omit", "lodash/omit", rootTransformerOpts);
77
- });
78
- it("should not try to resolve a local path", () => {
79
- testWithImport("./something", "./something", rootTransformerOpts);
80
- });
81
- });
82
- describe("multiple roots", () => {
83
- const rootTransformerOpts = {
84
- babelrc: false,
85
- plugins: [
86
- [
87
- _src.default,
88
- {
89
- root: [
90
- "./test/testproject/src/actions",
91
- "./test/testproject/src/components"
92
- ]
93
- }
94
- ]
95
- ]
96
- };
97
- it("should resolve the file sub path in root 1", () => {
98
- testWithImport("something", "./test/testproject/src/actions/something", rootTransformerOpts);
99
- });
100
- it("should resolve the file sub path in root 2", () => {
101
- testWithImport("Root", "./test/testproject/src/components/Root", rootTransformerOpts);
102
- });
103
- });
104
- describe("glob root", () => {
105
- const globRootTransformerOpts = {
106
- babelrc: false,
107
- plugins: [
108
- [
109
- _src.default,
110
- {
111
- root: "./test/testproject/src/**"
112
- }
113
- ]
114
- ]
115
- };
116
- it("should resolve the file path right inside the glob", () => {
117
- testWithImport("app", "./test/testproject/src/app", globRootTransformerOpts);
118
- });
119
- it("should resolve the sub file path", () => {
120
- testWithImport("actions/something", "./test/testproject/src/actions/something", globRootTransformerOpts);
121
- });
122
- it("should resolve the sub file path without specifying the directory", () => {
123
- testWithImport("something", "./test/testproject/src/actions/something", globRootTransformerOpts);
124
- });
125
- it("should resolve the deep file", () => {
126
- testWithImport("SidebarFooterButton", "./test/testproject/src/components/Sidebar/Footer/SidebarFooterButton", globRootTransformerOpts);
127
- });
128
- });
129
- describe("non-standard extensions", () => {
130
- const rootTransformerOpts = {
131
- babelrc: false,
132
- plugins: [
133
- [
134
- _src.default,
135
- {
136
- root: "./test/testproject/src",
137
- extensions: [
138
- ".txt"
139
- ]
140
- }
141
- ]
142
- ]
143
- };
144
- it("should not resolve the file path with an unknown extension", () => {
145
- testWithImport("app", "app", rootTransformerOpts);
146
- });
147
- it("should resolve the file path with a known defined extension", () => {
148
- testWithImport("text", "./test/testproject/src/text", rootTransformerOpts);
149
- });
150
- });
151
- describe("non-standard double extensions", () => {
152
- const rootTransformerOpts = {
153
- babelrc: false,
154
- plugins: [
155
- [
156
- _src.default,
157
- {
158
- root: "./test/testproject/src",
159
- extensions: [
160
- ".ios.js",
161
- ".android.js",
162
- ".js"
163
- ]
164
- }
165
- ]
166
- ]
167
- };
168
- it("should not resolve the file path with an unknown extension", () => {
169
- testWithImport("text", "text", rootTransformerOpts);
170
- });
171
- it("should resolve the file path with a known defined extension & strip the extension", () => {
172
- testWithImport("rn", "./test/testproject/src/rn", rootTransformerOpts);
173
- });
174
- it("should resolve the file path with an explicit extension and not strip the extension", () => {
175
- testWithImport("rn/index.ios.js", "./test/testproject/src/rn/index.ios.js", rootTransformerOpts);
176
- });
177
- });
178
- describe("non-standard double extensions with strip extensions", () => {
179
- const rootTransformerOpts = {
180
- babelrc: false,
181
- plugins: [
182
- [
183
- _src.default,
184
- {
185
- root: "./test/testproject/src",
186
- extensions: [
187
- ".js",
188
- ".ios.js",
189
- ".android.js"
190
- ],
191
- stripExtensions: []
192
- }
193
- ]
194
- ]
195
- };
196
- it("should not resolve the file path with an unknown extension", () => {
197
- testWithImport("text", "text", rootTransformerOpts);
198
- });
199
- it("should resolve the file path with a known defined extension", () => {
200
- testWithImport("rn", "./test/testproject/src/rn/index.ios.js", rootTransformerOpts);
201
- });
202
- });
203
- describe("root and alias", () => {
204
- const aliasTransformerOpts = {
205
- babelrc: false,
206
- plugins: [
207
- [
208
- _src.default,
209
- {
210
- root: "./test/fakepath/",
211
- alias: {
212
- constants: "./test/testproject/src/constants"
213
- }
214
- }
215
- ]
216
- ]
217
- };
218
- it("should resolve the path using alias first and root otherwise", () => {
219
- testWithImport("constants", "./test/testproject/src/constants", aliasTransformerOpts);
220
- });
221
- });
222
- });
223
- describe("alias", () => {
224
- const aliasTransformerOpts = {
225
- babelrc: false,
226
- plugins: [
227
- [
228
- _src.default,
229
- {
230
- alias: {
231
- test: "./test/testproject/test",
232
- libs: "./test/testproject/src/libs",
233
- components: "./test/testproject/src/components",
234
- "~": "./test/testproject/src",
235
- "awesome/components": "./test/testproject/src/components",
236
- "babel-kernel": "@babel/core/lib",
237
- "^@namespace/foo-(.+)": "./packages/\\1",
238
- "styles/.+\\.(css|less|scss)$": "./style-proxy.\\1",
239
- "^single-backslash": "./pas\\\\sed",
240
- "^non-existing-match": "./pas\\42sed",
241
- "^regexp-priority": "./hit",
242
- "regexp-priority$": "./miss",
243
- "regexp-priority": "./miss",
244
- $src: "./test/testproject/src/"
245
- }
246
- }
247
- ]
248
- ]
249
- };
250
- describe("with a simple alias", () => {
251
- it("should alias the file path", () => {
252
- testWithImport("components", "./test/testproject/src/components", aliasTransformerOpts);
253
- });
254
- it("should not alias if there is no proper sub path", () => {
255
- testWithImport("components_dummy", "components_dummy", aliasTransformerOpts);
256
- });
257
- it("should alias the sub file path", () => {
258
- testWithImport("test/tools", "./test/testproject/test/tools", aliasTransformerOpts);
259
- });
260
- });
261
- describe("with alias for a relative path (with respect to the cwd)", () => {
262
- it("should alias the file path sharing a directory", () => {
263
- testWithImport("test", "./testproject/test", {
264
- ...aliasTransformerOpts,
265
- filename: "./test/foo.js"
266
- });
267
- });
268
- it("should alias the file path in another directory", () => {
269
- testWithImport("test", "../test/testproject/test", {
270
- ...aliasTransformerOpts,
271
- filename: "./lib/bar.js"
272
- });
273
- });
274
- });
275
- describe("with an alias containing a slash", () => {
276
- it("should alias the file path", () => {
277
- testWithImport("awesome/components", "./test/testproject/src/components", aliasTransformerOpts);
278
- });
279
- it("should not alias if there is no proper sub path", () => {
280
- testWithImport("awesome/componentss", "awesome/componentss", aliasTransformerOpts);
281
- });
282
- it("should alias the sub file path", () => {
283
- testWithImport("awesome/components/Header", "./test/testproject/src/components/Header", aliasTransformerOpts);
284
- });
285
- });
286
- it("should alias a path containing a dot in the filename", () => {
287
- testWithImport("libs/custom.modernizr3", "./test/testproject/src/libs/custom.modernizr3", aliasTransformerOpts);
288
- });
289
- it("should alias the path with its extension", () => {
290
- testWithImport("components/Header/header.css", "./test/testproject/src/components/Header/header.css", aliasTransformerOpts);
291
- });
292
- describe("should not alias a unknown path", () => {
293
- it("when requiring a node module", () => {
294
- testWithImport("other-lib", "other-lib", aliasTransformerOpts);
295
- });
296
- it("when requiring a specific un-mapped file", () => {
297
- testWithImport("./l/otherLib", "./l/otherLib", aliasTransformerOpts);
298
- });
299
- });
300
- it("should support aliasing a node module", () => {
301
- testWithImport("babel-kernel/transform", "@babel/core/lib/transform", aliasTransformerOpts);
302
- });
303
- it("should escape regexp", () => {
304
- testWithImport("$src/app", "./test/testproject/src/app", aliasTransformerOpts);
305
- });
306
- describe("with a regular expression", () => {
307
- it("should support replacing parts of a path", () => {
308
- testWithImport("@namespace/foo-bar", "./packages/bar", aliasTransformerOpts);
309
- });
310
- it("should support replacing parts of a complex path", () => {
311
- testWithImport("@namespace/foo-bar/component.js", "./packages/bar/component.js", aliasTransformerOpts);
312
- });
313
- describe("should support complex regular expressions", () => {
314
- [
315
- "css",
316
- "less",
317
- "scss"
318
- ].forEach((extension) => {
319
- it(`should handle the alias with the ${extension} extension`, () => {
320
- testWithImport(`styles/style.${extension}`, `./style-proxy.${extension}`, aliasTransformerOpts);
321
- });
322
- });
323
- });
324
- it("should ignore unmatched paths", () => {
325
- testWithImport("styles/style.js", "styles/style.js", aliasTransformerOpts);
326
- });
327
- it("should unescape a double backslash into a single one", () => {
328
- testWithImport(
329
- "single-backslash",
330
- // This is a string literal, so in the code it will actually be "pas\\sed"
331
- "./pas/sed",
332
- aliasTransformerOpts
333
- );
334
- });
335
- it("should replace missing matches with an empty string", () => {
336
- testWithImport("non-existing-match", "./passed", aliasTransformerOpts);
337
- });
338
- it("should have higher priority than a simple alias", () => {
339
- testWithImport("regexp-priority", "./hit", aliasTransformerOpts);
340
- });
341
- });
342
- describe("with a function", () => {
343
- const mockSubstitute = jest.fn();
344
- const regExpSubsituteOpts = {
345
- babelrc: false,
346
- plugins: [
347
- [
348
- _src.default,
349
- {
350
- alias: {
351
- "basic-function": mockSubstitute,
352
- "^@regexp-function/(.+)": mockSubstitute
353
- }
354
- }
355
- ]
356
- ]
357
- };
358
- beforeEach(() => {
359
- mockSubstitute.mockClear();
360
- });
361
- it("should call the substitute with the right arguments (basic)", () => {
362
- mockSubstitute.mockReturnValue("./test/testproject/test");
363
- testWithImport("basic-function/something", "./test/testproject/test", regExpSubsituteOpts);
364
- expect(mockSubstitute.mock.calls.length).toBe(1);
365
- const execResult = Object.assign([
366
- "basic-function/something",
367
- "/something"
368
- ], {
369
- index: 0,
370
- input: "basic-function/something"
371
- });
372
- expect(mockSubstitute).toBeCalledWith(execResult);
373
- });
374
- it("should call the substitute with the right arguments (regexp)", () => {
375
- mockSubstitute.mockReturnValue("./test/testproject/test");
376
- testWithImport("@regexp-function/something", "./test/testproject/test", regExpSubsituteOpts);
377
- expect(mockSubstitute.mock.calls.length).toBe(1);
378
- const execResult = Object.assign([
379
- "@regexp-function/something",
380
- "something"
381
- ], {
382
- index: 0,
383
- input: "@regexp-function/something"
384
- });
385
- expect(mockSubstitute).toBeCalledWith(execResult);
386
- });
387
- });
388
- describe("with the plugin applied twice", () => {
389
- const doubleAliasTransformerOpts = {
390
- babelrc: false,
391
- plugins: [
392
- [
393
- _src.default,
394
- {
395
- root: "."
396
- }
397
- ],
398
- [
399
- _src.default,
400
- {
401
- alias: {
402
- "^@namespace/foo-(.+)": "./packages/\\1"
403
- }
404
- },
405
- "second-module-resolver"
406
- ]
407
- ]
408
- };
409
- it("should support replacing parts of a path", () => {
410
- testWithImport("@namespace/foo-bar", "./packages/bar", doubleAliasTransformerOpts);
411
- });
412
- });
413
- describe("missing packages warning", () => {
414
- const mockWarn = jest.fn();
415
- jest.mock("../src/log", () => ({
416
- warn: mockWarn
417
- }));
418
- jest.resetModules();
419
- const pluginWithMock = jest.requireActual("../src").default;
420
- const fileName = _path.default.resolve("unknown");
421
- const missingAliasTransformerOpts = {
422
- babelrc: false,
423
- plugins: [
424
- [
425
- pluginWithMock,
426
- {
427
- alias: {
428
- legacy: "npm:legacy",
429
- "non-existing": "this-package-does-not-exist"
430
- }
431
- }
432
- ]
433
- ]
434
- };
435
- beforeEach(() => {
436
- mockWarn.mockClear();
437
- process.env.NODE_ENV = "development";
438
- });
439
- it("should print a warning for a legacy alias", () => {
440
- testWithImport("legacy/lib", "npm:legacy/lib", missingAliasTransformerOpts);
441
- expect(mockWarn.mock.calls.length).toBe(1);
442
- expect(mockWarn).toBeCalledWith(`Could not resolve "npm:legacy/lib" in file ${fileName}.`);
443
- });
444
- it("should print a warning for an unresolved package", () => {
445
- testWithImport("non-existing/lib", "this-package-does-not-exist/lib", missingAliasTransformerOpts);
446
- expect(mockWarn.mock.calls.length).toBe(1);
447
- expect(mockWarn).toBeCalledWith(`Could not resolve "this-package-does-not-exist/lib" in file ${fileName}.`);
448
- });
449
- describe("production environment", () => {
450
- beforeEach(() => {
451
- process.env.NODE_ENV = "production";
452
- });
453
- it("should print a warning for an unresolved package", () => {
454
- testWithImport("non-existing/lib", "this-package-does-not-exist/lib", missingAliasTransformerOpts);
455
- expect(mockWarn.mock.calls.length).toBe(0);
456
- });
457
- });
458
- const silentLoggingOpts = {
459
- babelrc: false,
460
- plugins: [
461
- [
462
- pluginWithMock,
463
- {
464
- alias: {
465
- legacy: "npm:legacy",
466
- "non-existing": "this-package-does-not-exist"
467
- },
468
- loglevel: "silent"
469
- }
470
- ]
471
- ]
472
- };
473
- it("should respect opt loglevel:silent", () => {
474
- testWithImport("legacy/lib", "npm:legacy/lib", silentLoggingOpts);
475
- expect(mockWarn.mock.calls.length).toBe(0);
476
- });
477
- });
478
- describe("multiple alias application", () => {
479
- it("should resolve the cyclic alias only once", () => {
480
- const fileName = _path.default.resolve("test/testproject/src/app.js");
481
- const cycleAliasTransformerOpts = {
482
- babelrc: false,
483
- plugins: [
484
- [
485
- _src.default,
486
- {
487
- alias: {
488
- first: "second",
489
- second: "first"
490
- }
491
- }
492
- ],
493
- [
494
- _src.default,
495
- {
496
- alias: {
497
- first: "second",
498
- second: "first"
499
- }
500
- },
501
- "second-module-resolver"
502
- ]
503
- ],
504
- filename: fileName
505
- };
506
- testWithImport("first", "second", cycleAliasTransformerOpts);
507
- });
508
- it("should resolve the prefix alias only once", () => {
509
- const fileName = _path.default.resolve("test/testproject/src/app.js");
510
- const cycleAliasTransformerOpts = {
511
- babelrc: false,
512
- plugins: [
513
- [
514
- _src.default,
515
- {
516
- alias: {
517
- prefix: "prefix/lib"
518
- }
519
- }
520
- ],
521
- [
522
- _src.default,
523
- {
524
- alias: {
525
- prefix: "prefix/lib"
526
- }
527
- },
528
- "second module-resolver"
529
- ]
530
- ],
531
- filename: fileName
532
- };
533
- testWithImport("prefix/test", "prefix/lib/test", cycleAliasTransformerOpts);
534
- });
535
- });
536
- describe("correct alias order application", () => {
537
- const arrayAliasTransformerOpts = {
538
- babelrc: false,
539
- plugins: [
540
- [
541
- _src.default,
542
- {
543
- alias: [
544
- {
545
- "~/foo": "./src/lib/foo"
546
- },
547
- {
548
- "~/bar": "./src/lib/bar"
549
- },
550
- {
551
- "~": "./src"
552
- }
553
- ]
554
- }
555
- ]
556
- ]
557
- };
558
- it("should resolve aliases following the insertion order", () => {
559
- testWithImport("~/foo", "./src/lib/foo", arrayAliasTransformerOpts);
560
- testWithImport("~/bar", "./src/lib/bar", arrayAliasTransformerOpts);
561
- testWithImport("~", "./src", arrayAliasTransformerOpts);
562
- });
563
- });
564
- describe("dot files", () => {
565
- const dotFileAliasTransformerOpts = {
566
- babelrc: false,
567
- plugins: [
568
- [
569
- _src.default,
570
- {
571
- alias: {
572
- ".babel": "@babel/core",
573
- elintrc: "./.eslintrc",
574
- folderdot: "./src/folder."
575
- }
576
- }
577
- ]
578
- ]
579
- };
580
- it("should not match folder names with dot at end", () => {
581
- testWithImport("folderdot/file", "./src/folder./file", dotFileAliasTransformerOpts);
582
- });
583
- it("should resolve alias with dot", () => {
584
- testWithImport(".babel/register", "@babel/core/register", dotFileAliasTransformerOpts);
585
- });
586
- it("should resolve sibling dot files using alias", () => {
587
- testWithImport("elintrc", "./.eslintrc", dotFileAliasTransformerOpts);
588
- });
589
- });
590
- });
591
- describe("with custom cwd", () => {
592
- describe("custom value", () => {
593
- const transformerOpts = {
594
- babelrc: false,
595
- plugins: [
596
- [
597
- _src.default,
598
- {
599
- root: "./testproject/src",
600
- cwd: _path.default.resolve("test"),
601
- alias: {
602
- constantsAlias: "./constants",
603
- "^constantsRegExp(.*)": "./constants\\1"
604
- }
605
- }
606
- ]
607
- ]
608
- };
609
- it("should resolve the file path", () => {
610
- testWithImport("components/Root", "./test/testproject/src/components/Root", transformerOpts);
611
- });
612
- it("should alias the relative path while honoring cwd", () => {
613
- testWithImport("constantsAlias/actions", "./test/constants/actions", transformerOpts);
614
- });
615
- it("should alias the relative path while honoring cwd", () => {
616
- testWithImport("constantsRegExp/actions", "./test/constants/actions", transformerOpts);
617
- });
618
- });
619
- describe("with root", () => {
620
- const transformerOpts = {
621
- babelrc: false,
622
- plugins: [
623
- [
624
- _src.default,
625
- {
626
- root: "./src",
627
- cwd: _path.default.resolve("test/testproject")
628
- }
629
- ]
630
- ]
631
- };
632
- it("should resolve the sub file path", () => {
633
- testWithImport("components/Root", "./test/testproject/src/components/Root", transformerOpts);
634
- });
635
- });
636
- describe("with glob root", () => {
637
- const transformerOpts = {
638
- babelrc: false,
639
- plugins: [
640
- [
641
- _src.default,
642
- {
643
- root: "./testproject/*",
644
- cwd: _path.default.resolve("test")
645
- }
646
- ]
647
- ]
648
- };
649
- it("should resolve the sub file path", () => {
650
- testWithImport("components/Root", "./test/testproject/src/components/Root", transformerOpts);
651
- });
652
- });
653
- });
654
- describe("babelrc", () => {
655
- const transformerOpts = {
656
- babelrc: false,
657
- plugins: [
658
- [
659
- _src.default,
660
- {
661
- root: "./src",
662
- alias: {
663
- test: "./test"
664
- },
665
- cwd: "babelrc"
666
- }
667
- ]
668
- ],
669
- filename: "./test/testproject/src/app.js"
670
- };
671
- it("should resolve the sub file path", () => {
672
- testWithImport("components/Root", "./components/Root", transformerOpts);
673
- });
674
- it("should alias the sub file path", () => {
675
- testWithImport("test/tools", "../test/tools", transformerOpts);
676
- });
677
- describe("unknown filename", () => {
678
- const unknownFileTransformerOpts = {
679
- babelrc: false,
680
- plugins: [
681
- [
682
- _src.default,
683
- {
684
- root: "./src",
685
- cwd: "babelrc"
686
- }
687
- ]
688
- ]
689
- };
690
- const cachedCwd = process.cwd();
691
- const babelRcDir = "test/testproject";
692
- beforeEach(() => {
693
- process.chdir(babelRcDir);
694
- });
695
- afterEach(() => {
696
- process.chdir(cachedCwd);
697
- });
698
- it("should resolve the sub file path", () => {
699
- testWithImport("components/Root", "./src/components/Root", unknownFileTransformerOpts);
700
- });
701
- });
702
- describe("missing babelrc in path (uses cwd)", () => {
703
- jest.mock("find-babel-config", () => ({
704
- // eslint-disable-next-line func-name-matching
705
- sync: function findBabelConfigSync() {
706
- return {
707
- file: null,
708
- config: null
709
- };
710
- }
711
- }));
712
- jest.resetModules();
713
- const pluginWithMock = jest.requireActual("../src").default;
714
- const missingBabelConfigTransformerOpts = {
715
- babelrc: false,
716
- plugins: [
717
- [
718
- pluginWithMock,
719
- {
720
- root: ".",
721
- cwd: "babelrc"
722
- }
723
- ]
724
- ],
725
- filename: "./test/testproject/src/app.js"
726
- };
727
- it("should resolve the sub file path", () => {
728
- testWithImport("test/testproject/src/components/Root", "./components/Root", missingBabelConfigTransformerOpts);
729
- });
730
- });
731
- });
732
- describe("packagejson", () => {
733
- const transformerOpts = {
734
- babelrc: false,
735
- plugins: [
736
- [
737
- _src.default,
738
- {
739
- root: "./src",
740
- alias: {
741
- test: "./test"
742
- },
743
- cwd: "packagejson"
744
- }
745
- ]
746
- ],
747
- filename: "./test/testproject/src/app.js"
748
- };
749
- it("should resolve the sub file path", () => {
750
- testWithImport("components/Root", "./components/Root", transformerOpts);
751
- });
752
- it("should alias the sub file path", () => {
753
- testWithImport("test/tools", "../test/tools", transformerOpts);
754
- });
755
- it("Alias with array of paths", () => {
756
- testWithImport("testArr/tools", "../test/tools", {
757
- babelrc: false,
758
- plugins: [
759
- [
760
- _src.default,
761
- {
762
- root: "./src",
763
- alias: {
764
- testArr: [
765
- "./src",
766
- "/test",
767
- "./test"
768
- ]
769
- },
770
- cwd: "packagejson"
771
- }
772
- ]
773
- ],
774
- filename: "./test/testproject/src/app.js"
775
- });
776
- });
777
- describe("unknown filename", () => {
778
- const unknownFileTransformerOpts = {
779
- babelrc: false,
780
- plugins: [
781
- [
782
- _src.default,
783
- {
784
- root: "./src",
785
- cwd: "packagejson"
786
- }
787
- ]
788
- ]
789
- };
790
- const cachedCwd = process.cwd();
791
- const packageJsonDir = "test/testproject";
792
- beforeEach(() => {
793
- process.chdir(packageJsonDir);
794
- });
795
- afterEach(() => {
796
- process.chdir(cachedCwd);
797
- });
798
- it("should resolve the sub file path", () => {
799
- testWithImport("components/Root", "./src/components/Root", unknownFileTransformerOpts);
800
- });
801
- });
802
- describe("missing package.json in path (uses cwd)", () => {
803
- jest.mock("pkg-up", () => ({
804
- // eslint-disable-next-line func-name-matching
805
- sync: function pkgUpSync() {
806
- return null;
807
- }
808
- }));
809
- jest.resetModules();
810
- const pluginWithMock = jest.requireActual("../src").default;
811
- const missingPkgJsonConfigTransformerOpts = {
812
- babelrc: false,
813
- plugins: [
814
- [
815
- pluginWithMock,
816
- {
817
- root: ".",
818
- cwd: "packagejson"
819
- }
820
- ]
821
- ],
822
- filename: "./test/testproject/src/app.js"
823
- };
824
- it("should resolve the sub file path", () => {
825
- testWithImport("test/testproject/src/components/Root", "./components/Root", missingPkgJsonConfigTransformerOpts);
826
- });
827
- });
828
- });
829
- describe("resolvePath", () => {
830
- it("should work with a custom function", () => {
831
- const rootTransformerOpts = {
832
- babelrc: false,
833
- plugins: [
834
- [
835
- _src.default,
836
- {
837
- root: "./test/testproject/src",
838
- resolvePath() {
839
- return "real path";
840
- }
841
- }
842
- ]
843
- ]
844
- };
845
- testWithImport("app", "real path", rootTransformerOpts);
846
- });
847
- it("should work with the original function", () => {
848
- const rootTransformerOpts = {
849
- babelrc: false,
850
- plugins: [
851
- [
852
- _src.default,
853
- {
854
- root: "./test/testproject/src",
855
- resolvePath: _src.resolvePath
856
- }
857
- ]
858
- ]
859
- };
860
- testWithImport("app", "./test/testproject/src/app", rootTransformerOpts);
861
- });
862
- });
863
- });