Skip to content

Commit 1f9c8b4

Browse files
committed
chore: modernize build tooling and packaging
1 parent fa6d94e commit 1f9c8b4

50 files changed

Lines changed: 6724 additions & 19460 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [16.x, 18.x, 20.x, 21.x]
15+
node-version: [22.x, 24.x, 25.x]
1616

1717
steps:
18-
- uses: actions/checkout@v1
18+
- uses: actions/checkout@v6
1919
- name: Use Node.js ${{ matrix.node-version }}
20-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v6
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323
- name: npm install, and build
@@ -29,7 +29,7 @@ jobs:
2929
- name: npm test
3030
run: npm run test:coverage
3131
- name: coverage
32-
uses: codecov/codecov-action@v1.0.5
33-
if: matrix.node-version == '13.x'
32+
uses: codecov/codecov-action@v5
33+
if: matrix.node-version == '26.x'
3434
with:
3535
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
/node_modules/
33
npm-debug.log
4+
dist/
45
lib/
56
coverage/

.oxfmtrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ignorePatterns": ["CHANGELOG.md"],
3+
"singleQuote": true
4+
}

.oxlintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignorePatterns": ["CHANGELOG.md"]
3+
}

.prettierrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

DOCS.md

Lines changed: 112 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
* [Getting Started](#getting-started)
2-
* [Options](#options)
3-
* [root](#root)
4-
* [alias](#alias)
5-
* [extensions](#extensions)
6-
* [stripExtensions](#stripExtensions)
7-
* [cwd](#cwd)
8-
* [transformFunctions](#transformfunctions)
9-
* [resolvePath](#resolvepath)
10-
* [Usage with Create React App](#usage-with-create-react-app)
11-
* [Usage with React Native](#usage-with-react-native)
12-
* [Usage with Proxyquire](#usage-with-proxyquire)
13-
* [Usage with Flow](#usage-with-flow)
14-
* [For plugin authors](#for-plugin-authors)
1+
- [Getting Started](#getting-started)
2+
- [Options](#options)
3+
- [root](#root)
4+
- [alias](#alias)
5+
- [extensions](#extensions)
6+
- [stripExtensions](#stripExtensions)
7+
- [cwd](#cwd)
8+
- [transformFunctions](#transformfunctions)
9+
- [resolvePath](#resolvepath)
10+
- [Usage with Create React App](#usage-with-create-react-app)
11+
- [Usage with React Native](#usage-with-react-native)
12+
- [Usage with Proxyquire](#usage-with-proxyquire)
13+
- [Usage with Flow](#usage-with-flow)
14+
- [For plugin authors](#for-plugin-authors)
1515

1616
# Getting Started
1717

@@ -20,7 +20,9 @@ Install the plugin
2020
```
2121
npm install --save-dev babel-plugin-module-resolver
2222
```
23+
2324
or
25+
2426
```
2527
yarn add --dev babel-plugin-module-resolver
2628
```
@@ -30,13 +32,16 @@ Specify the plugin in your `.babelrc` with the custom root or alias. Here's an e
3032
```json
3133
{
3234
"plugins": [
33-
["module-resolver", {
34-
"root": ["./src"],
35-
"alias": {
36-
"test": "./test",
37-
"underscore": "lodash"
35+
[
36+
"module-resolver",
37+
{
38+
"root": ["./src"],
39+
"alias": {
40+
"test": "./test",
41+
"underscore": "lodash"
42+
}
3843
}
39-
}]
44+
]
4045
]
4146
}
4247
```
@@ -59,11 +64,14 @@ It is possible to specify an alias using a regular expression. To do that, eithe
5964
```json
6065
{
6166
"plugins": [
62-
["module-resolver", {
63-
"alias": {
64-
"^@namespace/foo-(.+)": "packages/\\1"
67+
[
68+
"module-resolver",
69+
{
70+
"alias": {
71+
"^@namespace/foo-(.+)": "packages/\\1"
72+
}
6573
}
66-
}]
74+
]
6775
]
6876
}
6977
```
@@ -81,20 +89,24 @@ If you need even more power over the aliased path, you can pass a function in th
8189
```js
8290
module.exports = {
8391
plugins: [
84-
["module-resolver", {
85-
alias: {
86-
"foo": ([, name]) => `bar${name}`,
87-
"^@namespace/foo-(.+)": ([, name]) => `packages/${name}`
88-
}
89-
}]
90-
]
91-
}
92+
[
93+
'module-resolver',
94+
{
95+
alias: {
96+
foo: ([, name]) => `bar${name}`,
97+
'^@namespace/foo-(.+)': ([, name]) => `packages/${name}`,
98+
},
99+
},
100+
],
101+
],
102+
};
92103
```
93104

94105
Using the config from this example:
95-
* `'foo'` will become `'bar'` (`name` is empty)
96-
* `'foo/baz'` will become `'bar/baz'` (`name` includes the slash in this case)
97-
* `'@namespace/foo-bar'` will become `'packages/bar'`
106+
107+
- `'foo'` will become `'bar'` (`name` is empty)
108+
- `'foo/baz'` will become `'bar/baz'` (`name` includes the slash in this case)
109+
- `'@namespace/foo-bar'` will become `'packages/bar'`
98110

99111
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.
100112

@@ -137,23 +149,33 @@ An array of extensions that will be stripped from file paths. Defaults to the `e
137149
## cwd
138150

139151
By default, the working directory is the one used for the resolver, but you can override it for your project.
140-
* The custom value `babelrc` will make the plugin look for the closest babelrc configuration based on the file to parse.
152+
153+
- The custom value `babelrc` will make the plugin look for the closest babelrc configuration based on the file to parse.
154+
141155
```json
142156
{
143157
"plugins": [
144-
["module-resolver", {
145-
"cwd": "babelrc"
146-
}]
158+
[
159+
"module-resolver",
160+
{
161+
"cwd": "babelrc"
162+
}
163+
]
147164
]
148165
}
149166
```
150-
* The custom value `packagejson` will make the plugin look for the closest `package.json` based on the file to parse.
167+
168+
- The custom value `packagejson` will make the plugin look for the closest `package.json` based on the file to parse.
169+
151170
```json
152171
{
153172
"plugins": [
154-
["module-resolver", {
155-
"cwd": "packagejson"
156-
}]
173+
[
174+
"module-resolver",
175+
{
176+
"cwd": "packagejson"
177+
}
178+
]
157179
]
158180
}
159181
```
@@ -165,8 +187,10 @@ Array of functions and methods that will have their first argument transformed.
165187
```json
166188
{
167189
"plugins": [
168-
["module-resolver", {
169-
"transformFunctions": [
190+
[
191+
"module-resolver",
192+
{
193+
"transformFunctions": [
170194
"require",
171195
"require.resolve",
172196
"System.import",
@@ -175,8 +199,9 @@ Array of functions and methods that will have their first argument transformed.
175199
"jest.unmock",
176200
"jest.doMock",
177201
"jest.dontMock"
178-
]
179-
}]
202+
]
203+
}
204+
]
180205
]
181206
}
182207
```
@@ -188,21 +213,24 @@ A function that is called to resolve each path in the project. By default `modul
188213
```js
189214
module.exports = {
190215
plugins: [
191-
["module-resolver", {
192-
extensions: [".js"],
193-
resolvePath(sourcePath, currentFile, opts) {
194-
/**
195-
* The `opts` argument is the options object that is passed through the Babel config.
196-
* opts = {
197-
* extensions: [".js"],
198-
* resolvePath: ...,
199-
* }
200-
*/
201-
return "resolvedPath";
202-
}
203-
}]
204-
]
205-
}
216+
[
217+
'module-resolver',
218+
{
219+
extensions: ['.js'],
220+
resolvePath(sourcePath, currentFile, opts) {
221+
/**
222+
* The `opts` argument is the options object that is passed through the Babel config.
223+
* opts = {
224+
* extensions: [".js"],
225+
* resolvePath: ...,
226+
* }
227+
*/
228+
return 'resolvedPath';
229+
},
230+
},
231+
],
232+
],
233+
};
206234
```
207235

208236
If you want to leave some paths as-is, then you can return `undefined` or any other falsy value from the function.
@@ -214,14 +242,17 @@ One of the [NPM log level options](https://docs.npmjs.com/misc/config#loglevel)
214242
```js
215243
module.exports = {
216244
plugins: [
217-
["module-resolver", {
218-
alias: {
219-
"dependency-string": "module-that-does-not-exist" // warning will not log
245+
[
246+
'module-resolver',
247+
{
248+
alias: {
249+
'dependency-string': 'module-that-does-not-exist', // warning will not log
250+
},
251+
loglevel: 'silent',
220252
},
221-
loglevel: 'silent'
222-
}]
223-
]
224-
}
253+
],
254+
],
255+
};
225256
```
226257

227258
# Usage with create-react-app
@@ -250,7 +281,7 @@ create-react-app by default don't use .babelrc, so in webpack.config.dev.js, add
250281

251282
# Usage with React Native
252283

253-
To let the packager resolve the right module for each platform, you have to add the ```.ios.js```and ```.android.js``` extensions :
284+
To let the packager resolve the right module for each platform, you have to add the `.ios.js`and `.android.js` extensions :
254285

255286
```json
256287
{
@@ -268,17 +299,18 @@ To let the packager resolve the right module for each platform, you have to add
268299

269300
# Usage with Proxyquire
270301

271-
If you use the mocking library [proxyquire](https://github.com/thlorenz/proxyquire), or otherwise need to define path strings which aren't direct arguments to `transformFunctions`, you have a problem: the plug-in won't convert them.
302+
If you use the mocking library [proxyquire](https://github.com/thlorenz/proxyquire), or otherwise need to define path strings which aren't direct arguments to `transformFunctions`, you have a problem: the plug-in won't convert them.
272303

273304
Because proxyquire expects paths not just as direct arguments, but also as object keys, simply adding proxyquire to `transformFunctions` isn't enough:
274305

275306
```js
276-
const { functionToTest } = proxyquire('~/modifiedPathToTestedModule', { // this path will be converted
277-
'~/modifiedPathToDependency': { mockVersionOfDependency } // this path won't be converted
307+
const { functionToTest } = proxyquire('~/modifiedPathToTestedModule', {
308+
// this path will be converted
309+
'~/modifiedPathToDependency': { mockVersionOfDependency }, // this path won't be converted
278310
});
279311
```
280312

281-
The solution in this case is to use or create a function like Lodash's/Underscore's `_.identity`, which simply returns its argument. Next, add it to `transformFunctions`, and then use it to convert the problematic path string:
313+
The solution in this case is to use or create a function like Lodash's/Underscore's `_.identity`, which simply returns its argument. Next, add it to `transformFunctions`, and then use it to convert the problematic path string:
282314

283315
```json
284316
"transformFunctions": [
@@ -288,9 +320,10 @@ The solution in this case is to use or create a function like Lodash's/Underscor
288320
```
289321

290322
```js
291-
const resolvePath = x => x;
292-
const { functionToTest } = proxyquire('~/modifiedPathToTestedModule', { // this path will be converted
293-
[resolvePath('~/modifiedPathToDependency')]: { mockVersionOfDependency } // this path will be converted
323+
const resolvePath = (x) => x;
324+
const { functionToTest } = proxyquire('~/modifiedPathToTestedModule', {
325+
// this path will be converted
326+
[resolvePath('~/modifiedPathToDependency')]: { mockVersionOfDependency }, // this path will be converted
294327
});
295328
```
296329

@@ -324,8 +357,9 @@ directory tree:
324357

325358
```js
326359
// Located at src/store/actions
327-
import 'actions/User'
360+
import 'actions/User';
328361
```
362+
329363
```
330364
module.system.node.resolve_dirname=src/store
331365
```

0 commit comments

Comments
 (0)