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