@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.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/common/index.js +2 -2
- package/dist/cjs/compilers/babel/preset/alias.js +2 -2
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +2 -2
- package/dist/esm/common/index.js +2 -2
- package/dist/esm/compilers/babel/preset/alias.js +2 -2
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +2 -2
- package/dist/esm-node/common/index.js +2 -2
- package/dist/esm-node/compilers/babel/preset/alias.js +2 -2
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +2 -2
- package/package.json +11 -19
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -56
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -13
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -28
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -21
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -157
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -92
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -24
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -19
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -98
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -92
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -73
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -74
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -118
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -863
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -21
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -50
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -1
- package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -12
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -41
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -8
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -17
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -10
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -162
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -86
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -15
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -8
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -57
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -87
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -68
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -71
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -124
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -862
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -16
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -45
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -0
- package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -2
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/index.js +0 -37
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/log.js +0 -3
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.js +0 -17
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.js +0 -10
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js +0 -146
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.js +0 -81
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js +0 -13
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.js +0 -8
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.js +0 -57
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.js +0 -87
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.js +0 -68
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.js +0 -69
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.js +0 -113
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.js +0 -857
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js +0 -16
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js +0 -45
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/first/index.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/node_modules/second/index.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json +0 -1
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/header.css +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.js +0 -0
- package/dist/esm-node/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.js +0 -2
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/index.d.ts +0 -19
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/log.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/mapPath.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/mapToRelative.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.d.ts +0 -24
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/resolvePath.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/import.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/src/utils.d.ts +0 -9
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/call.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/custom-call.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/dynamicImport.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/import.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/index.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.d.ts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/example-file.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/actions/something.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/App.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/SubHeader.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Header/index.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Root.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/SidebarFooterButton.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/Sidebar/Footer/index.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/components/index.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants/actions.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/constants.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/libs/custom.modernizr3.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/nodemodule.d.mts +0 -1
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.android.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/rn/index.ios.d.ts +0 -0
- package/dist/types/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/test/tools.d.ts +0 -1
- package/test-setup.js +0 -7
package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/mapToRelative.test.js
DELETED
|
@@ -1,21 +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 _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
7
|
-
const _mapToRelative = /* @__PURE__ */ _interop_require_default._(require("../src/mapToRelative"));
|
|
8
|
-
describe("mapToRelative", () => {
|
|
9
|
-
describe("should map to relative path with a custom cwd", () => {
|
|
10
|
-
it("with a relative filename", () => {
|
|
11
|
-
const currentFile = "./utils/test/file.js";
|
|
12
|
-
const result = (0, _mapToRelative.default)(_path.default.resolve("./test"), currentFile, "utils/dep");
|
|
13
|
-
expect(result).toBe("../dep");
|
|
14
|
-
});
|
|
15
|
-
it("with an absolute filename", () => {
|
|
16
|
-
const currentFile = _path.default.resolve("./utils/test/file.js");
|
|
17
|
-
const result = (0, _mapToRelative.default)(_path.default.resolve("."), currentFile, "utils/dep");
|
|
18
|
-
expect(result).toBe("../dep");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
});
|
package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/normalizeOptions.test.js
DELETED
|
@@ -1,50 +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 _normalizeOptions = /* @__PURE__ */ _interop_require_default._(require("../src/normalizeOptions"));
|
|
7
|
-
describe("normalizeOptions", () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
_normalizeOptions.default.resetRecomputations();
|
|
10
|
-
});
|
|
11
|
-
it("should return the memoized options when the dirnames are the same", () => {
|
|
12
|
-
const options = {};
|
|
13
|
-
const result = (0, _normalizeOptions.default)("path/a.js", options);
|
|
14
|
-
const result2 = (0, _normalizeOptions.default)("path/b.js", options);
|
|
15
|
-
expect(result).toBe(result2);
|
|
16
|
-
expect(_normalizeOptions.default.recomputations()).toEqual(1);
|
|
17
|
-
});
|
|
18
|
-
it("should return the memoized options when the special paths are the same", () => {
|
|
19
|
-
const options = {};
|
|
20
|
-
const result = (0, _normalizeOptions.default)("unknown", options);
|
|
21
|
-
const result2 = (0, _normalizeOptions.default)("unknown", options);
|
|
22
|
-
expect(result).toBe(result2);
|
|
23
|
-
expect(_normalizeOptions.default.recomputations()).toEqual(1);
|
|
24
|
-
});
|
|
25
|
-
it("should recompute when the options object is not the same", () => {
|
|
26
|
-
const options = {};
|
|
27
|
-
const options2 = {};
|
|
28
|
-
const result = (0, _normalizeOptions.default)("path/to/file.js", options);
|
|
29
|
-
const result2 = (0, _normalizeOptions.default)("path/to/file.js", options2);
|
|
30
|
-
expect(result).not.toBe(result2);
|
|
31
|
-
expect(_normalizeOptions.default.recomputations()).toEqual(2);
|
|
32
|
-
});
|
|
33
|
-
it("should correctly normalize alias option if it is an array", () => {
|
|
34
|
-
const options = {
|
|
35
|
-
alias: [
|
|
36
|
-
{
|
|
37
|
-
foo: "A",
|
|
38
|
-
bar: "B"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
baz: "C"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
};
|
|
45
|
-
const { alias } = (0, _normalizeOptions.default)("path/to/file.js", options);
|
|
46
|
-
expect(alias[0][0]).toEqual(/^foo(\/.*|)$/);
|
|
47
|
-
expect(alias[1][0]).toEqual(/^bar(\/.*|)$/);
|
|
48
|
-
expect(alias[2][0]).toEqual(/^baz(\/.*|)$/);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/cjs/compilers/babel/plugins/babel-plugin-module-resolver/test/testproject/src/app.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import normalizeOptions from "./normalizeOptions";
|
|
2
|
-
import resolvePath from "./resolvePath";
|
|
3
|
-
import transformCall from "./transformers/call";
|
|
4
|
-
import transformImport from "./transformers/import";
|
|
5
|
-
export { resolvePath };
|
|
6
|
-
var importVisitors = {
|
|
7
|
-
CallExpression: transformCall,
|
|
8
|
-
"ImportDeclaration|ExportDeclaration": transformImport
|
|
9
|
-
};
|
|
10
|
-
var visitor = {
|
|
11
|
-
Program: {
|
|
12
|
-
enter: function enter(programPath, state) {
|
|
13
|
-
programPath.traverse(importVisitors, state);
|
|
14
|
-
},
|
|
15
|
-
exit: function exit(programPath, state) {
|
|
16
|
-
programPath.traverse(importVisitors, state);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export default function(param) {
|
|
21
|
-
var types = param.types;
|
|
22
|
-
return {
|
|
23
|
-
name: "module-resolver",
|
|
24
|
-
manipulateOptions: function manipulateOptions(opts) {
|
|
25
|
-
if (opts.filename === void 0) {
|
|
26
|
-
opts.filename = "unknown";
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
pre: function pre(file) {
|
|
30
|
-
this.types = types;
|
|
31
|
-
var currentFile = file.opts.filename;
|
|
32
|
-
this.normalizedOpts = normalizeOptions(currentFile, this.opts);
|
|
33
|
-
this.moduleResolverVisited = /* @__PURE__ */ new Set();
|
|
34
|
-
},
|
|
35
|
-
visitor: visitor,
|
|
36
|
-
post: function post() {
|
|
37
|
-
this.moduleResolverVisited.clear();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
export function warn() {
|
|
3
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4
|
-
args[_key] = arguments[_key];
|
|
5
|
-
}
|
|
6
|
-
var _console;
|
|
7
|
-
(_console = console).warn.apply(_console, _to_consumable_array(args));
|
|
8
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import defaultResolvePath from "./resolvePath";
|
|
2
|
-
export default function mapPathString(nodePath, state) {
|
|
3
|
-
if (!state.types.isStringLiteral(nodePath)) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
var sourcePath = nodePath.node.value;
|
|
7
|
-
var currentFile = state.file.opts.filename;
|
|
8
|
-
var resolvePath = state.normalizedOpts.customResolvePath || defaultResolvePath;
|
|
9
|
-
var modulePath = resolvePath(sourcePath, currentFile, state.opts);
|
|
10
|
-
if (modulePath) {
|
|
11
|
-
if (nodePath.node.pathResolved) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
nodePath.replaceWith(state.types.stringLiteral(modulePath));
|
|
15
|
-
nodePath.node.pathResolved = true;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { toPosixPath } from "./utils";
|
|
3
|
-
export default function mapToRelative(cwd, currentFile, module) {
|
|
4
|
-
var from = path.dirname(currentFile);
|
|
5
|
-
var to = path.normalize(module);
|
|
6
|
-
from = path.resolve(cwd, from);
|
|
7
|
-
to = path.resolve(cwd, to);
|
|
8
|
-
var moduleMapped = path.relative(from, to);
|
|
9
|
-
return toPosixPath(moduleMapped);
|
|
10
|
-
}
|
package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/normalizeOptions.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { createSelector } from "reselect";
|
|
6
|
-
import findBabelConfig from "find-babel-config";
|
|
7
|
-
import glob from "glob";
|
|
8
|
-
import pkgUp from "pkg-up";
|
|
9
|
-
import { escapeRegExp } from "./utils";
|
|
10
|
-
var defaultExtensions = [
|
|
11
|
-
".js",
|
|
12
|
-
".jsx",
|
|
13
|
-
".es",
|
|
14
|
-
".es6",
|
|
15
|
-
".mjs"
|
|
16
|
-
];
|
|
17
|
-
var defaultTransformedFunctions = [
|
|
18
|
-
"require",
|
|
19
|
-
"require.resolve",
|
|
20
|
-
"System.import",
|
|
21
|
-
// Jest methods
|
|
22
|
-
"jest.genMockFromModule",
|
|
23
|
-
"jest.mock",
|
|
24
|
-
"jest.unmock",
|
|
25
|
-
"jest.doMock",
|
|
26
|
-
"jest.dontMock",
|
|
27
|
-
"jest.setMock",
|
|
28
|
-
"jest.requireActual",
|
|
29
|
-
"jest.requireMock",
|
|
30
|
-
// Older Jest methods
|
|
31
|
-
"require.requireActual",
|
|
32
|
-
"require.requireMock"
|
|
33
|
-
];
|
|
34
|
-
function isRegExp(string) {
|
|
35
|
-
return string.startsWith("^") || string.endsWith("$");
|
|
36
|
-
}
|
|
37
|
-
var specialCwd = {
|
|
38
|
-
babelrc: function(startPath) {
|
|
39
|
-
return findBabelConfig.sync(startPath).file;
|
|
40
|
-
},
|
|
41
|
-
packagejson: function(startPath) {
|
|
42
|
-
return pkgUp.sync({
|
|
43
|
-
cwd: startPath
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
function normalizeCwd(optsCwd, currentFile) {
|
|
48
|
-
var cwd;
|
|
49
|
-
if (optsCwd in specialCwd) {
|
|
50
|
-
var startPath = currentFile === "unknown" ? "./" : currentFile;
|
|
51
|
-
var computedCwd = specialCwd[optsCwd](startPath);
|
|
52
|
-
cwd = computedCwd ? path.dirname(computedCwd) : null;
|
|
53
|
-
} else {
|
|
54
|
-
cwd = optsCwd;
|
|
55
|
-
}
|
|
56
|
-
return cwd || process.cwd();
|
|
57
|
-
}
|
|
58
|
-
function normalizeRoot(optsRoot, cwd) {
|
|
59
|
-
if (!optsRoot) {
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
var rootArray = Array.isArray(optsRoot) ? optsRoot : [
|
|
63
|
-
optsRoot
|
|
64
|
-
];
|
|
65
|
-
return rootArray.map(function(dirPath) {
|
|
66
|
-
return path.resolve(cwd, dirPath);
|
|
67
|
-
}).reduce(function(resolvedDirs, absDirPath) {
|
|
68
|
-
if (glob.hasMagic(absDirPath)) {
|
|
69
|
-
var roots = glob.sync(absDirPath).filter(function(resolvedPath) {
|
|
70
|
-
return fs.lstatSync(resolvedPath).isDirectory();
|
|
71
|
-
});
|
|
72
|
-
return _to_consumable_array(resolvedDirs).concat(_to_consumable_array(roots));
|
|
73
|
-
}
|
|
74
|
-
return _to_consumable_array(resolvedDirs).concat([
|
|
75
|
-
absDirPath
|
|
76
|
-
]);
|
|
77
|
-
}, []);
|
|
78
|
-
}
|
|
79
|
-
function getAliasTarget(key, isKeyRegExp) {
|
|
80
|
-
var regExpPattern = isKeyRegExp ? key : "^".concat(escapeRegExp(key), "(/.*|)$");
|
|
81
|
-
return new RegExp(regExpPattern);
|
|
82
|
-
}
|
|
83
|
-
function getAliasSubstitute(value, isKeyRegExp) {
|
|
84
|
-
if (typeof value === "function") {
|
|
85
|
-
return value;
|
|
86
|
-
}
|
|
87
|
-
if (!isKeyRegExp) {
|
|
88
|
-
return function(param) {
|
|
89
|
-
var _param = _sliced_to_array(param, 2), match = _param[1];
|
|
90
|
-
if (Array.isArray(value)) {
|
|
91
|
-
return value.map(function(v) {
|
|
92
|
-
return "".concat(v).concat(match);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return "".concat(value).concat(match);
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
var parts = value.split("\\\\");
|
|
99
|
-
return function(execResult) {
|
|
100
|
-
return parts.map(function(part) {
|
|
101
|
-
return part.replace(/\\\d+/g, function(number) {
|
|
102
|
-
return execResult[number.slice(1)] || "";
|
|
103
|
-
});
|
|
104
|
-
}).join("\\");
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function normalizeAlias(optsAlias) {
|
|
108
|
-
if (!optsAlias) {
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
var aliasArray = Array.isArray(optsAlias) ? optsAlias : [
|
|
112
|
-
optsAlias
|
|
113
|
-
];
|
|
114
|
-
return aliasArray.reduce(function(aliasPairs, alias) {
|
|
115
|
-
var aliasKeys = Object.keys(alias);
|
|
116
|
-
aliasKeys.forEach(function(key) {
|
|
117
|
-
var isKeyRegExp = isRegExp(key);
|
|
118
|
-
aliasPairs.push([
|
|
119
|
-
getAliasTarget(key, isKeyRegExp),
|
|
120
|
-
getAliasSubstitute(alias[key], isKeyRegExp)
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
return aliasPairs;
|
|
124
|
-
}, []);
|
|
125
|
-
}
|
|
126
|
-
function normalizeTransformedFunctions(optsTransformFunctions) {
|
|
127
|
-
if (!optsTransformFunctions) {
|
|
128
|
-
return defaultTransformedFunctions;
|
|
129
|
-
}
|
|
130
|
-
return _to_consumable_array(defaultTransformedFunctions).concat(_to_consumable_array(optsTransformFunctions));
|
|
131
|
-
}
|
|
132
|
-
function normalizeLoglevel(optsLoglevel) {
|
|
133
|
-
return optsLoglevel || "warn";
|
|
134
|
-
}
|
|
135
|
-
export default createSelector(
|
|
136
|
-
// The currentFile should have an extension; otherwise it's considered a special value
|
|
137
|
-
function(currentFile) {
|
|
138
|
-
return currentFile.includes(".") ? path.dirname(currentFile) : currentFile;
|
|
139
|
-
},
|
|
140
|
-
function(_, opts) {
|
|
141
|
-
return opts;
|
|
142
|
-
},
|
|
143
|
-
function(currentFile, opts) {
|
|
144
|
-
var cwd = normalizeCwd(opts.cwd, currentFile);
|
|
145
|
-
var root = normalizeRoot(opts.root, cwd);
|
|
146
|
-
var alias = normalizeAlias(opts.alias);
|
|
147
|
-
var loglevel = normalizeLoglevel(opts.loglevel);
|
|
148
|
-
var transformFunctions = normalizeTransformedFunctions(opts.transformFunctions);
|
|
149
|
-
var extensions = opts.extensions || defaultExtensions;
|
|
150
|
-
var stripExtensions = opts.stripExtensions || extensions;
|
|
151
|
-
return {
|
|
152
|
-
cwd: cwd,
|
|
153
|
-
root: root,
|
|
154
|
-
alias: alias,
|
|
155
|
-
loglevel: loglevel,
|
|
156
|
-
transformFunctions: transformFunctions,
|
|
157
|
-
extensions: extensions,
|
|
158
|
-
stripExtensions: stripExtensions,
|
|
159
|
-
customResolvePath: opts.resolvePath
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
);
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { warn } from "./log";
|
|
4
|
-
import mapToRelative from "./mapToRelative";
|
|
5
|
-
import normalizeOptions from "./normalizeOptions";
|
|
6
|
-
import { nodeResolvePath, replaceExtension, isRelativePath, toLocalPath, toPosixPath } from "./utils";
|
|
7
|
-
function getRelativePath(sourcePath, currentFile, absFileInRoot, opts) {
|
|
8
|
-
var realSourceFileExtension = path.extname(absFileInRoot);
|
|
9
|
-
var sourceFileExtension = path.extname(sourcePath);
|
|
10
|
-
var relativePath = mapToRelative(opts.cwd, currentFile, absFileInRoot);
|
|
11
|
-
if (realSourceFileExtension !== sourceFileExtension) {
|
|
12
|
-
relativePath = replaceExtension(relativePath, opts);
|
|
13
|
-
}
|
|
14
|
-
return toLocalPath(toPosixPath(relativePath));
|
|
15
|
-
}
|
|
16
|
-
function findPathInRoots(sourcePath, param) {
|
|
17
|
-
var extensions = param.extensions, root = param.root;
|
|
18
|
-
var resolvedSourceFile;
|
|
19
|
-
root.some(function(basedir) {
|
|
20
|
-
resolvedSourceFile = nodeResolvePath("./".concat(sourcePath), basedir, extensions);
|
|
21
|
-
return resolvedSourceFile !== null;
|
|
22
|
-
});
|
|
23
|
-
return resolvedSourceFile;
|
|
24
|
-
}
|
|
25
|
-
function resolvePathFromRootConfig(sourcePath, currentFile, opts) {
|
|
26
|
-
var absFileInRoot = findPathInRoots(sourcePath, opts);
|
|
27
|
-
if (!absFileInRoot) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return getRelativePath(sourcePath, currentFile, absFileInRoot, opts);
|
|
31
|
-
}
|
|
32
|
-
function checkIfPackageExists(modulePath, currentFile, extensions, loglevel) {
|
|
33
|
-
var resolvedPath = nodeResolvePath(modulePath, currentFile, extensions);
|
|
34
|
-
if (resolvedPath === null && loglevel !== "silent") {
|
|
35
|
-
warn('Could not resolve "'.concat(modulePath, '" in file ').concat(currentFile, "."));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function resolvePathFromAliasConfig(sourcePath, currentFile, opts) {
|
|
39
|
-
var aliasedSourceFile;
|
|
40
|
-
opts.alias.find(function(param) {
|
|
41
|
-
var _param = _sliced_to_array(param, 2), regExp = _param[0], substitute = _param[1];
|
|
42
|
-
var execResult = regExp.exec(sourcePath);
|
|
43
|
-
if (execResult === null) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
aliasedSourceFile = substitute(execResult);
|
|
47
|
-
return true;
|
|
48
|
-
});
|
|
49
|
-
if (!aliasedSourceFile) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
if (Array.isArray(aliasedSourceFile)) {
|
|
53
|
-
return aliasedSourceFile.map(function(asf) {
|
|
54
|
-
if (isRelativePath(asf)) {
|
|
55
|
-
return toLocalPath(toPosixPath(mapToRelative(opts.cwd, currentFile, asf)));
|
|
56
|
-
}
|
|
57
|
-
return asf;
|
|
58
|
-
}).find(function(src) {
|
|
59
|
-
return nodeResolvePath(src, path.dirname(currentFile), opts.extensions);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (isRelativePath(aliasedSourceFile)) {
|
|
63
|
-
return toLocalPath(toPosixPath(mapToRelative(opts.cwd, currentFile, aliasedSourceFile)));
|
|
64
|
-
}
|
|
65
|
-
if (process.env.NODE_ENV !== "production") {
|
|
66
|
-
checkIfPackageExists(aliasedSourceFile, currentFile, opts.extensions, opts.loglevel);
|
|
67
|
-
}
|
|
68
|
-
return aliasedSourceFile;
|
|
69
|
-
}
|
|
70
|
-
var resolvers = [
|
|
71
|
-
resolvePathFromAliasConfig,
|
|
72
|
-
resolvePathFromRootConfig
|
|
73
|
-
];
|
|
74
|
-
export default function resolvePath(sourcePath, currentFile, opts) {
|
|
75
|
-
if (isRelativePath(sourcePath)) {
|
|
76
|
-
return sourcePath;
|
|
77
|
-
}
|
|
78
|
-
var normalizedOpts = normalizeOptions(currentFile, opts);
|
|
79
|
-
var absoluteCurrentFile = path.resolve(currentFile);
|
|
80
|
-
var resolvedPath = null;
|
|
81
|
-
resolvers.some(function(resolver) {
|
|
82
|
-
resolvedPath = resolver(sourcePath, absoluteCurrentFile, normalizedOpts);
|
|
83
|
-
return resolvedPath !== null;
|
|
84
|
-
});
|
|
85
|
-
return resolvedPath;
|
|
86
|
-
}
|
package/dist/esm/compilers/babel/plugins/babel-plugin-module-resolver/src/transformers/call.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { matchesPattern, isImportCall } from "../utils";
|
|
2
|
-
import mapPathString from "../mapPath";
|
|
3
|
-
export default function transformCall(nodePath, state) {
|
|
4
|
-
if (state.moduleResolverVisited.has(nodePath)) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
var calleePath = nodePath.get("callee");
|
|
8
|
-
var isNormalCall = state.normalizedOpts.transformFunctions.some(function(pattern) {
|
|
9
|
-
return matchesPattern(state.types, calleePath, pattern);
|
|
10
|
-
});
|
|
11
|
-
if (isNormalCall || isImportCall(state.types, nodePath)) {
|
|
12
|
-
state.moduleResolverVisited.add(nodePath);
|
|
13
|
-
mapPathString(nodePath.get("arguments.0"), state);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import resolve from "resolve";
|
|
3
|
-
export function nodeResolvePath(modulePath, basedir, extensions) {
|
|
4
|
-
try {
|
|
5
|
-
return resolve.sync(modulePath, {
|
|
6
|
-
basedir: basedir,
|
|
7
|
-
extensions: extensions
|
|
8
|
-
});
|
|
9
|
-
} catch (e) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export function isRelativePath(nodePath) {
|
|
14
|
-
return nodePath.match(/^\.?\.\//);
|
|
15
|
-
}
|
|
16
|
-
export function toPosixPath(modulePath) {
|
|
17
|
-
return modulePath.replace(/\\/g, "/");
|
|
18
|
-
}
|
|
19
|
-
export function toLocalPath(modulePath) {
|
|
20
|
-
var localPath = modulePath.replace(/\/index$/, "");
|
|
21
|
-
if (!isRelativePath(localPath)) {
|
|
22
|
-
localPath = "./".concat(localPath);
|
|
23
|
-
}
|
|
24
|
-
return localPath;
|
|
25
|
-
}
|
|
26
|
-
export function stripExtension(modulePath, stripExtensions) {
|
|
27
|
-
var name = path.basename(modulePath);
|
|
28
|
-
stripExtensions.some(function(extension) {
|
|
29
|
-
if (name.endsWith(extension)) {
|
|
30
|
-
name = name.slice(0, name.length - extension.length);
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
});
|
|
35
|
-
return name;
|
|
36
|
-
}
|
|
37
|
-
export function replaceExtension(modulePath, opts) {
|
|
38
|
-
var filename = stripExtension(modulePath, opts.stripExtensions);
|
|
39
|
-
return path.join(path.dirname(modulePath), filename);
|
|
40
|
-
}
|
|
41
|
-
export function matchesPattern(types, calleePath, pattern) {
|
|
42
|
-
var node = calleePath.node;
|
|
43
|
-
if (types.isMemberExpression(node)) {
|
|
44
|
-
return calleePath.matchesPattern(pattern);
|
|
45
|
-
}
|
|
46
|
-
if (!types.isIdentifier(node) || pattern.includes(".")) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
var name = pattern.split(".")[0];
|
|
50
|
-
return node.name === name;
|
|
51
|
-
}
|
|
52
|
-
export function isImportCall(types, calleePath) {
|
|
53
|
-
return types.isImport(calleePath.node.callee);
|
|
54
|
-
}
|
|
55
|
-
export function escapeRegExp(string) {
|
|
56
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
57
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { transform } from "@babel/core";
|
|
2
|
-
import plugin from "../src";
|
|
3
|
-
var calls = [
|
|
4
|
-
"require",
|
|
5
|
-
"require.resolve",
|
|
6
|
-
"System.import",
|
|
7
|
-
"jest.genMockFromModule",
|
|
8
|
-
"jest.mock",
|
|
9
|
-
"jest.unmock",
|
|
10
|
-
"jest.doMock",
|
|
11
|
-
"jest.dontMock",
|
|
12
|
-
"jest.setMock",
|
|
13
|
-
"jest.requireActual",
|
|
14
|
-
"jest.requireMock",
|
|
15
|
-
"require.requireActual",
|
|
16
|
-
"require.requireMock"
|
|
17
|
-
];
|
|
18
|
-
describe("function and method calls", function() {
|
|
19
|
-
var transformerOpts = {
|
|
20
|
-
babelrc: false,
|
|
21
|
-
plugins: [
|
|
22
|
-
[
|
|
23
|
-
plugin,
|
|
24
|
-
{
|
|
25
|
-
root: "./test/testproject/src",
|
|
26
|
-
alias: {
|
|
27
|
-
test: "./test/testproject/test"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
]
|
|
32
|
-
};
|
|
33
|
-
calls.forEach(function(name) {
|
|
34
|
-
describe(name, function() {
|
|
35
|
-
it("should resolve the path based on the root config", function() {
|
|
36
|
-
var code = "".concat(name, '("components/Header/SubHeader", ...args);');
|
|
37
|
-
var result = transform(code, transformerOpts);
|
|
38
|
-
expect(result.code).toBe("".concat(name, '("./test/testproject/src/components/Header/SubHeader", ...args);'));
|
|
39
|
-
});
|
|
40
|
-
it("should alias the path", function() {
|
|
41
|
-
var code = "".concat(name, '("test", ...args);');
|
|
42
|
-
var result = transform(code, transformerOpts);
|
|
43
|
-
expect(result.code).toBe("".concat(name, '("./test/testproject/test", ...args);'));
|
|
44
|
-
});
|
|
45
|
-
it("should not change a relative path", function() {
|
|
46
|
-
var code = "".concat(name, '("./utils", ...args);');
|
|
47
|
-
var result = transform(code, transformerOpts);
|
|
48
|
-
expect(result.code).toBe("".concat(name, '("./utils", ...args);'));
|
|
49
|
-
});
|
|
50
|
-
it("should handle no arguments", function() {
|
|
51
|
-
var code = "".concat(name, "();");
|
|
52
|
-
var result = transform(code, transformerOpts);
|
|
53
|
-
expect(result.code).toBe("".concat(name, "();"));
|
|
54
|
-
});
|
|
55
|
-
it("should handle the first argument not being a string literal", function() {
|
|
56
|
-
var code = "".concat(name, "(path, ...args);");
|
|
57
|
-
var result = transform(code, transformerOpts);
|
|
58
|
-
expect(result.code).toBe("".concat(name, "(path, ...args);"));
|
|
59
|
-
});
|
|
60
|
-
it("should handle an empty path", function() {
|
|
61
|
-
var code = "".concat(name, "('', ...args);");
|
|
62
|
-
var result = transform(code, transformerOpts);
|
|
63
|
-
expect(result.code).toBe("".concat(name, "('', ...args);"));
|
|
64
|
-
});
|
|
65
|
-
it("should ignore the call if the method name is not fully matched (suffix)", function() {
|
|
66
|
-
var code = "".concat(name, '.after("components/Sidebar/Footer", ...args);');
|
|
67
|
-
var result = transform(code, transformerOpts);
|
|
68
|
-
expect(result.code).toBe("".concat(name, '.after("components/Sidebar/Footer", ...args);'));
|
|
69
|
-
});
|
|
70
|
-
it("should ignore the call if the method name is not fully matched (prefix)", function() {
|
|
71
|
-
var code = "before.".concat(name, '("components/Sidebar/Footer", ...args);');
|
|
72
|
-
var result = transform(code, transformerOpts);
|
|
73
|
-
expect(result.code).toBe("before.".concat(name, '("components/Sidebar/Footer", ...args);'));
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
it("should resolve the path if the method name is a string literal", function() {
|
|
78
|
-
var code = 'require["resolve"]("components/Sidebar/Footer", ...args);';
|
|
79
|
-
var result = transform(code, transformerOpts);
|
|
80
|
-
expect(result.code).toBe('require["resolve"]("./test/testproject/src/components/Sidebar/Footer", ...args);');
|
|
81
|
-
});
|
|
82
|
-
it("should ignore the call if the method name is unknown", function() {
|
|
83
|
-
var code = 'unknown("components/Sidebar/Footer", ...args);';
|
|
84
|
-
var result = transform(code, transformerOpts);
|
|
85
|
-
expect(result.code).toBe('unknown("components/Sidebar/Footer", ...args);');
|
|
86
|
-
});
|
|
87
|
-
});
|