Skip to content

Commit 32c16d0

Browse files
authored
feat!: prune root tsconfig (#53)
Remove references and paths that are already in some tsconfig's further down the file structure tree. So we only have things in the root that haven't referenced somewhere else. - including some vulnerability fixes - migrating from jest to vitest BREAKING CHANGE: dropping support for older node.js versions before 22.13.0
1 parent b663164 commit 32c16d0

14 files changed

Lines changed: 775 additions & 3621 deletions

File tree

.eslintrc.js

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

.github/workflows/node.js.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
1+
# This workflow installs dependencies, runs lint, and executes tests on supported Node.js versions.
32

43
name: Node.js CI
54

@@ -15,30 +14,33 @@ jobs:
1514

1615
strategy:
1716
matrix:
18-
node-version: [14.x, 15.x, 16.x, 18.x]
17+
node-version: [22.13.0, 24.x]
1918

2019
steps:
21-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2221
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v2
22+
uses: actions/setup-node@v4
2423
with:
2524
node-version: ${{ matrix.node-version }}
25+
cache: yarn
2626
- run: yarn
27+
- run: yarn lint
2728
- run: yarn test
2829

2930
windows:
3031
runs-on: windows-latest
3132

3233
strategy:
3334
matrix:
34-
node-version: [18.x]
35+
node-version: [22.13.0]
3536

3637
steps:
37-
- uses: actions/checkout@v2
38+
- uses: actions/checkout@v4
3839
- name: Use Node.js ${{ matrix.node-version }} with windows
39-
uses: actions/setup-node@v2
40+
uses: actions/setup-node@v4
4041
with:
4142
node-version: ${{ matrix.node-version }}
43+
cache: yarn
4244
- run: yarn
4345
- run: scripts\prepareTests.ps1
44-
- run: yarn jest --testTimeout 30000
46+
- run: yarn vitest --testTimeout=30000

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ _update-ts-references_ is currently not supporting [Referencing workspace packag
121121

122122
# License
123123

124-
Copyright 2023 mobile.de
124+
Copyright 2026 mobile.de
125125
Developer: Mirko Kruschke
126126

127127
Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.

eslint.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const js = require('@eslint/js');
2+
3+
module.exports = [
4+
js.configs.recommended,
5+
{
6+
files: ['src/**/*.js', 'tests/**/*.js'],
7+
languageOptions: {
8+
ecmaVersion: 2020,
9+
sourceType: 'commonjs',
10+
globals: {
11+
afterEach: 'readonly',
12+
beforeEach: 'readonly',
13+
console: 'readonly',
14+
describe: 'readonly',
15+
expect: 'readonly',
16+
process: 'readonly',
17+
test: 'readonly',
18+
},
19+
},
20+
rules: {},
21+
},
22+
];

package.json

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "update-ts-references",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"description": "Updates TypeScript references automatically while using workspaces",
55
"bin": "src/index.js",
66
"scripts": {
77
"lint": "eslint src tests",
8-
"test": "scripts/prepareTests.sh && jest tests",
9-
"jest": "jest tests"
8+
"test": "scripts/prepareTests.sh && vitest run",
9+
"vitest": "vitest run"
1010
},
1111
"contributors": [
1212
{
@@ -20,19 +20,20 @@
2020
],
2121
"dependencies": {
2222
"comment-json": "^4.2.3",
23-
"glob": "^7.1.6",
24-
"js-yaml": "^4.0.0",
25-
"minimatch": "^3.0.5",
23+
"fast-glob": "^3.3.3",
24+
"js-yaml": "^4.1.1",
25+
"minimatch": "^9.0.5",
2626
"minimist": "^1.2.5"
2727
},
2828
"devDependencies": {
29-
"eslint": "^7.7.0",
30-
"eslint-plugin-jest": "^23.20.0",
29+
"@eslint/js": "^10.0.1",
30+
"eslint": "^10.0.3",
3131
"exec-sh": "^0.3.4",
32-
"jest": "^26.4.0"
32+
"vite": "^8.0.1",
33+
"vitest": "^4.1.0"
3334
},
3435
"engines": {
35-
"node": ">=14.0.0"
36+
"node": ">=22.13.0"
3637
},
3738
"license": "MIT",
3839
"keywords": [
@@ -60,12 +61,5 @@
6061
"url": "https://github.com/eBayClassifiedsGroup/update-ts-references/issues"
6162
},
6263
"homepage": "https://github.com/eBayClassifiedsGroup/update-ts-references",
63-
"jest": {
64-
"verbose": true,
65-
"modulePathIgnorePatterns": [
66-
"<rootDir>/test-scenarios/",
67-
"<rootDir>/test-run/"
68-
]
69-
},
7064
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
7165
}

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
/* eslint-disable no-console */
43
const minimist = require('minimist');
54
const { execute, defaultOptions } = require('./update-ts-references');
65

src/update-ts-references.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const glob = require('glob');
1+
const fastGlob = require('fast-glob');
22
const path = require('path');
33
const fs = require('fs');
44
const yaml = require('js-yaml');
5-
const minimatch = require('minimatch');
5+
const { minimatch } = require('minimatch');
66
const {
77
parse,
88
stringify,
@@ -41,19 +41,7 @@ const getAllPackageJsons = async (workspaces, cwd) => {
4141
});
4242

4343
return Promise.all(
44-
workspaceGlobs.map(
45-
(workspace) =>
46-
new Promise((resolve, reject) => {
47-
glob(`${workspace}/${PACKAGE_JSON}`, { cwd }, (error, files) => {
48-
if (error) {
49-
reject(error);
50-
}
51-
resolve(files);
52-
});
53-
}),
54-
55-
[]
56-
)
44+
workspaceGlobs.map((workspace) => fastGlob(`${workspace}/${PACKAGE_JSON}`, { cwd, onlyFiles: true }))
5745
)
5846
.then((allPackages) =>
5947
allPackages.reduce(
@@ -216,7 +204,7 @@ const updateTsConfig = (
216204
if (createPathMappings)
217205
assert.deepEqual(JSON.parse(JSON.stringify(config?.compilerOptions?.paths ?? {})), paths);
218206
isEqual = true;
219-
} catch (e) {
207+
} catch {
220208
// ignore me
221209
}
222210
if (!isEqual) {
@@ -243,7 +231,7 @@ const updateTsConfig = (
243231
} catch (error) {
244232
console.error(`could not read ${tsconfigFilePath}`, error);
245233
if (strict)
246-
throw new Error('Expect always a tsconfig.json in the package directory while running in strict mode')
234+
throw new Error('Expect always a tsconfig.json in the package directory while running in strict mode', { cause: error })
247235
}
248236
};
249237

@@ -269,7 +257,6 @@ const execute = async ({
269257
...configurable
270258
}) => {
271259
let changesCount = 0;
272-
// eslint-disable-next-line no-console
273260
console.log('updating tsconfigs');
274261
const packageJson = require(path.join(cwd, PACKAGE_JSON));
275262

@@ -336,10 +323,11 @@ const execute = async ({
336323
console.log('packagesMap', packagesMap);
337324
}
338325

339-
let rootReferences = [];
340-
let rootPaths = [];
341326
let tsconfigMap = {}
342327
let jsconfigMap = {}
328+
const referencesMap = {}
329+
const referencedPackageNames = new Set()
330+
const rootReferenceCandidates = []
343331
packagesMap.forEach((packageEntry, packageName) => {
344332
const detectedConfig = detectTSConfig(packageEntry.packageDir, configName, packageEntry.hasTsEntry && createTsConfig, cwd)
345333

@@ -379,18 +367,20 @@ const execute = async ({
379367
const detectedConfig = tsconfigMap[packageName]?.detectedConfig
380368

381369
if (detectedConfig) {
382-
rootReferences.push({
370+
rootReferenceCandidates.push(ensurePosixPathStyle({
383371
name: packageName,
384372
path: path.join(path.relative(cwd, packageEntry.packageDir), detectedConfig !== TSCONFIG_JSON ? detectedConfig : ''),
385373
folder: path.relative(cwd, packageEntry.packageDir),
386-
});
374+
}));
387375
const references = (getReferencesFromDependencies(
388376
configName,
389377
packageEntry,
390378
packageName,
391379
packagesMap,
392380
verbose
393381
) || []).map(ensurePosixPathStyle);
382+
referencesMap[packageName] = references
383+
references.forEach(({ name }) => referencedPackageNames.add(name))
394384

395385
const paths = getPathsFromReferences(references, tsconfigMap, jsconfigMap, ignorePathMappings)
396386

@@ -411,19 +401,13 @@ const execute = async ({
411401
} else {
412402
const detectedJsConfig = jsconfigMap[packageName]?.detectedConfig
413403
if (!detectedJsConfig) {
414-
// eslint-disable-next-line no-console
415404
console.log(`NO ${configName === TSCONFIG_JSON ? configName : `${configName} nor ${TSCONFIG_JSON}`} for ${packageName}`);
416405
}
417-
rootPaths.push({
418-
name: packageName,
419-
path: path.relative(cwd, packageEntry.packageDir),
420-
folder: path.relative(cwd, packageEntry.packageDir),
421-
});
422406
}
423407
});
424408

425-
rootReferences = (rootReferences || []).map(ensurePosixPathStyle);
426-
rootPaths = getPathsFromReferences((rootReferences || []).map(ensurePosixPathStyle), tsconfigMap, {}, ignorePathMappings)
409+
const rootReferences = rootReferenceCandidates.filter(({ name }) => !referencedPackageNames.has(name));
410+
const rootPaths = getPathsFromReferences(rootReferences, tsconfigMap, {}, ignorePathMappings)
427411

428412
if (verbose) {
429413
console.log('rootReferences', rootReferences);

test-scenarios/yarn-ws-check-no-changes/tsconfig.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,9 @@
77
{
88
"path": "workspace-a"
99
},
10-
{
11-
"path": "workspace-b"
12-
},
13-
{
14-
"path": "shared/workspace-c"
15-
},
1610
{
1711
"path": "shared/workspace-d"
18-
},
19-
{
20-
"path": "utils/foos/foo-a"
21-
},
22-
{
23-
"path": "utils/foos/foo-b"
2412
}
2513
]
2614
}
27-
15+
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
{
22
"files": [],
33
"compilerOptions": {
4-
"composite": true,
5-
"paths": { "foo-b": ["utils/foos/foo-b/src"] }
4+
"composite": true
65
},
76
"references": [
87
{
98
"path": "workspace-a"
109
},
11-
{
12-
"path": "workspace-b"
13-
},
14-
{
15-
"path": "utils/foos/foo-a"
16-
},
1710

1811
]
1912
}

tests/update-ts-references.check.test.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,9 @@ const rootTsConfig = [
4242
{
4343
path: 'workspace-a',
4444
},
45-
{
46-
path: 'workspace-b',
47-
},
48-
{
49-
path: 'shared/workspace-c',
50-
},
5145
{
5246
path: 'shared/workspace-d',
5347
},
54-
{
55-
path: 'utils/foos/foo-a',
56-
},
57-
{
58-
path: 'utils/foos/foo-b',
59-
},
6048
],
6149
},
6250
];
@@ -305,19 +293,13 @@ test('No changes paths detected with the --check option', async () => {
305293
{
306294
compilerOptions: {
307295
composite: true,
308-
paths: { "foo-b": ["utils/foos/foo-b/src"] }
296+
paths: undefined
309297
},
310298
files: [],
311299
references: [
312300
{
313301
path: 'workspace-a',
314302
},
315-
{
316-
path: 'workspace-b',
317-
},
318-
{
319-
path: 'utils/foos/foo-a',
320-
},
321303
],
322304
},
323305
];
@@ -362,5 +344,3 @@ test('No changes paths detected with the --check option', async () => {
362344
).toEqual(config);
363345
});
364346
});
365-
366-

0 commit comments

Comments
 (0)