Skip to content

Commit 80c8a06

Browse files
authored
Merge pull request #72 from oklas/task-10
Add baseUrl support
2 parents 6aeda59 + eab2e98 commit 80c8a06

Some content is hidden

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

42 files changed

+12242
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
example/*/node_modules
33
test/dists
44
coverage
5+
.DS_Store

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,32 @@ and replace `react-scripts` in `package.json`:
180180
}
181181
```
182182

183+
184+
#### Using baseUrl
185+
186+
* **`baseUrl = '.'`**
187+
188+
* able to create alias outside of `src` (near `src`)
189+
* for each directory in `src` alias **does not** created automatically (must be declared manually)
190+
191+
* **baseUrl = 'src'**
192+
193+
* alias outside of `src` is not possible, only in directory specified in `baseUrl`
194+
* for each folder in `src` alias created automatically with same name as folder
195+
196+
See also experimental [autoscan](https://github.com/oklas/react-app-alias/issues/70) feature
197+
198+
183199
#### API
184200

185201
* **options**
186202

187203
```ts
188204
Options {
189205
alias?: { [alias: string]: string }; // optional alias map
190-
tsconfig?: string, // optinal tsconfig.json path
191-
jsconfig?: string, // options jsconfig.json path
206+
tsconfig?: string, // optional tsconfig.json path
207+
jsconfig?: string, // optional jsconfig.json path
208+
baseUrl?: string, // optional by default from config
192209
}
193210
```
194211

example/above/src/App.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ test('renders text', () => {
88
expect(linkElement).toBeInTheDocument();
99
});
1010

11+
test('renders internal component from src', () => {
12+
render(<App />);
13+
const nearElement = screen.getByText(/Internal/i);
14+
expect(nearElement).toBeInTheDocument();
15+
});
16+
1117
test('renders component from near src', () => {
1218
render(<App />);
1319
const nearElement = screen.getByText(/Near Src/i);

example/above/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React from 'react'
2-
import NearSrc from 'near-src/NearSrc'
32
import AboveRootJs from 'above-root-js/AboveRootJs'
43
import AboveRootTs from 'above-root-ts/AboveRootTs'
4+
import NearSrc from 'near-src/NearSrc'
5+
import Internal from 'InternalEx/index'
56
import './App.css'
67

78
function App() {
89
return (
910
<div className="App">
1011
<h2>Main</h2>
12+
<Internal />
1113
<NearSrc />
1214
<AboveRootJs/>
1315
<AboveRootTs />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
function Internal() {
4+
return (
5+
<h3>Internal</h3>
6+
)
7+
}
8+
9+
export default Internal

example/above/tsconfig.paths.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"paths": {
55
"above-root-ts/*": [ "../above-root-ts/src/*" ],
66
"above-root-js/*": [ "../above-root-js/src/*" ],
7-
"near-src/*": [ "near-src/src/*" ]
7+
"near-src/*": [ "near-src/src/*" ],
8+
"InternalEx/*": [ "src/InternalEx/*" ]
89
}
910
}
1011
}

example/above/yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9181,18 +9181,6 @@ [email protected]:
91819181
iconv-lite "0.4.24"
91829182
unpipe "1.0.0"
91839183

9184-
react-app-alias-ex@^0.0.0:
9185-
version "1.0.0"
9186-
resolved "https://registry.yarnpkg.com/react-app-alias-ex/-/react-app-alias-ex-1.0.0.tgz#d41a7c16be47915f6955fde2feeb1caeb3c55372"
9187-
integrity sha512-PIf7d+tZhJiwsBIzvBDYtWBuO/xhlRW2Jaxny4MfqnkSHPocAhD97a051Q7QMtiBEDt2WmFrBfVZ5Zx3IhjgPw==
9188-
dependencies:
9189-
react-app-alias "^0.0.0"
9190-
9191-
react-app-alias@^0.0.0:
9192-
version "1.0.0"
9193-
resolved "https://registry.yarnpkg.com/react-app-alias/-/react-app-alias-1.0.0.tgz#8c644e0f537e802e0a7de7d0cba327d1caee45ca"
9194-
integrity sha512-rOA8TKlN932zFCjnZjWzvTk9GLs7b6dgj2BDpJ3Pvi5oxpVvaGHroAL//YxEXxJiLE3lFLchTfAD9FbN7/SChQ==
9195-
91969184
react-app-polyfill@^2.0.0:
91979185
version "2.0.0"
91989186
resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-2.0.0.tgz#a0bea50f078b8a082970a9d853dc34b6dcc6a3cf"

example/below/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

example/below/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Demo
2+
3+
This example demonstrate base `alias` implementation (without `above root` imports)
4+
5+
*Configuration (with `above root`) imports is in `example/above` directory*
6+
7+
Here is example for crete-react-app versions 4.1 and above
8+
9+
The version 4.0 of create-react-app requires patch due to
10+
[create-react-app #9921](https://github.com/facebook/create-react-app/pull/9921)
11+
The example with patch available [here](https://github.com/oklas/react-app-rewire-alias/tree/055bd2fd79dd391b2b79be15dcaa2a78b7779e8e/example/main) use yarn (yarn.lock)
12+

example/below/config-overrides.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const {aliasWebpack, aliasJest} = require('react-app-alias')
2+
3+
const options = {
4+
}
5+
6+
module.exports = aliasWebpack(options)
7+
module.exports.jest = aliasJest(options)

0 commit comments

Comments
 (0)