-
Notifications
You must be signed in to change notification settings - Fork 2
/
external.d.ts
212 lines (209 loc) · 5.88 KB
/
external.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
declare module 'babel-plugin-module-resolver' {
import { PluginObj } from '@babel/core';
export type ResolvePath = (
sourcePath: string,
currentFile: string,
opts: BabelPluginModuleResolveOptions,
) => string;
export interface BabelPluginModuleResolveOptions {
/**
* A string or an array of root directories. Specify the paths or a glob
* path (eg. `./src/*.ts`). `node_modules` is an implicit root as it is a
* default directory to resolve modules
*/
root?: string | string[];
/**
* A map of alias. You can also alias `node_modules` dependencies, not just
* local files.
*
* ### Regular expressions
*
* It is possible to specify an alias using a regular expression. To do
* that, either start an alias with `'^'` or end it with `'$'`:
*
* ```json
* {
* "plugins": [
* ["module-resolver", {
* "alias": {
* "^@namespace/foo-(.+)": "packages/\\1"
* }
* }]
* ]
* }
* ```
*
* ### Passing a substitute function
*
* If you need even more power over the aliased path, you can pass a function in the alias configuration:
*
* ```js
* module.exports = {
* plugins: [
* ["module-resolver", {
* alias: {
* "foo": ([, name]) => `bar${name}`,
* "^@namespace/foo-(.+)": ([, name]) => `packages/${name}`
* }
* }]
* ]
* }
* ```
*
* Using the config from this example:
* - `'foo'` will become `'bar'` (`name` is empty)
* - `'foo/baz'` will become `'bar/baz'` (`name` includes the slash in this
* case)
* - `'@namespace/foo-bar'` will become `'packages/bar'`
*
* The only argument is the result of calling `RegExp.prototype.exec` on the
* matched path. It's an array with the matched string and all matched
* groups.
*
* Because the function is only called when there is a match, the argument
* can never be `null`.
*/
alias?: Record<string, string | ((result: RegExpExecArray) => string)>;
/**
* An array of extensions used in the resolver.
*
* ```json
* {
* "plugins": [
* [
* "module-resolver",
* {
* "extensions": [".js", ".jsx", ".es", ".es6", ".mjs"]
* }
* ]
* ]
* }
* ```
*/
extensions?: string[];
/**
* An array of extensions that will be stripped from file paths. Defaults to
* the `extensions` option value.
*
* ```json
* {
* "plugins": [
* [
* "module-resolver",
* {
* "stripExtensions": [".js", ".jsx", ".es", ".es6", ".mjs"]
* }
* ]
* ]
* }
* ```
*/
stripExtensions?: string[];
/**
* By default, the working directory is the one used for the resolver, but
* you can override it for your project.
* - The custom value `babelrc` will make the plugin look for the closest
* babelrc configuration based on the file to parse.
*
* ```json
* {
* "plugins": [
* ["module-resolver", {
* "cwd": "babelrc"
* }]
* ]
* }
* ```
*
* - The custom value `packagejson` will make the plugin look for the
* closest `package.json` based on the file to parse.
*
* ```json
* {
* "plugins": [
* ["module-resolver", {
* "cwd": "packagejson"
* }]
* ]
* }
* ```
*/
cwd?: string;
/**
* Array of functions and methods that will have their first argument
* transformed. By default those methods are: `require`, `require.resolve`,
* `System.import`, `jest.genMockFromModule`, `jest.mock`, `jest.unmock`,
* `jest.doMock`, `jest.dontMock`.
*
* ```json
* {
* "plugins": [
* ["module-resolver", {
* "transformFunctions": [
* "require",
* "require.resolve",
* "System.import",
* "jest.genMockFromModule",
* "jest.mock",
* "jest.unmock",
* "jest.doMock",
* "jest.dontMock"
* ]
* }]
* ]
* }
* ```
*/
transformFunctions?: string[];
/**
* A function that is called to resolve each path in the project. By default
* `babel-plugin-module-resolver` is using an internal function - the same
* one that's exported from the plugin itself (see [For plugin authors][0]
* for more info).
*
* ```js
* module.exports = {
* plugins: [
* ["module-resolver", {
* extensions: [".js"],
* resolvePath(sourcePath, currentFile, opts) {
* // The `opts` argument is the options object that is passed
* // through the Babel config.
* // opts = {
* // extensions: [".js"],
* // resolvePath: ...,
* return "resolvedPath";
* }
* }]
* ]
* }
* ```
*
* [0]: #TODO
*/
resolvePath?: ResolvePath;
/**
* One of the [NPM log level options][0] to configure console logging during
* build. Default is `"warn"`. Passing `"silent"` will disable all warnings
* for path resolution failures.
*
* ```js
* module.exports = {
* plugins: [
* ["module-resolver", {
* alias: {
* "dependency-string": "module-that-does-not-exist" // warning will not log
* },
* loglevel: 'silent'
* }]
* ]
* }
* ```
*
* [0]: https://docs.npmjs.com/misc/config#loglevel
*/
logLevel?: string;
}
export const resolvePath: ResolvePath;
export default function babelPluginModuleResolve(...args: any[]): PluginObj;
}