Skip to content

Commit e67433c

Browse files
authored
fix: include eventual compilerOptions.paths changes to the check option (#38)
1 parent 3ba9ae6 commit e67433c

File tree

26 files changed

+681
-64
lines changed

26 files changed

+681
-64
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "update-ts-references",
3-
"version": "3.2.0",
3+
"version": "3.2.1",
44
"description": "Updates TypeScript references automatically while using workspaces",
55
"bin": "src/index.js",
66
"scripts": {

src/update-ts-references.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ const updateTsConfig = (
187187
let isEqual = false;
188188
try {
189189
assert.deepEqual(JSON.parse(JSON.stringify(currentReferences)), mergedReferences);
190+
if (createPathMappings)
191+
assert.deepEqual(JSON.parse(JSON.stringify(config?.compilerOptions?.paths ?? {})), paths);
190192
isEqual = true;
191193
} catch (e) {
192194
// ignore me
@@ -195,10 +197,11 @@ const updateTsConfig = (
195197
if (check === false) {
196198

197199
const compilerOptions = config?.compilerOptions ?? {};
198-
if (createPathMappings && paths && Object.keys(paths).length > 0)
199-
assign(compilerOptions, {
200-
paths
201-
})
200+
if (createPathMappings && paths)
201+
assign(compilerOptions,
202+
paths && Object.keys(paths).length > 0 ? {
203+
paths
204+
} : {paths: undefined})
202205

203206
const newTsConfig = assign(config,
204207
{
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
22
"compilerOptions": {
33
"outDir": "dist",
4-
"rootDir": "src"
5-
}
4+
"rootDir": "src",
5+
"paths": { "replace-me": ["../utils/old-one/src"]},
6+
},
7+
"references": [
8+
{
9+
"path": "../utils/foos/foo-a"
10+
},
11+
{
12+
"path": "../workspace-b"
13+
}
14+
]
615
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "yarn-workspace",
3+
"version": "0.0.1",
4+
"private": true,
5+
"workspaces": [
6+
"workspace-a",
7+
"workspace-b",
8+
"shared/*",
9+
"utils/**"
10+
],
11+
"devDependencies": {
12+
"typescript": "latest"
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"files": [],
3+
"compilerOptions": {
4+
"composite": true,
5+
"paths": { "foo-b": ["utils/foos/foo-b/src"] }
6+
},
7+
"references": [
8+
{
9+
"path": "workspace-a"
10+
},
11+
{
12+
"path": "workspace-b"
13+
},
14+
{
15+
"path": "utils/foos/foo-a"
16+
},
17+
18+
]
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "foo-a",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"foo-b": "1.0.0"
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"rootDir": "src"
5+
}
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "foo-b",
3+
"version": "1.0.0"
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "workspace-a",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"workspace-b": "1.0.0"
6+
},
7+
"devDependencies": {
8+
"foo-a": "1.0.0"
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist",
4+
"rootDir": "src",
5+
"paths": { "foo-a": ["../utils/foos/foo-a/src"], "workspace-b": ["../workspace-b/src"]}
6+
},
7+
"references": [
8+
{
9+
"path": "../utils/foos/foo-a"
10+
},
11+
{
12+
"path": "../workspace-b"
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)