Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

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

name: Node.js CI

Expand All @@ -15,30 +14,33 @@ jobs:

strategy:
matrix:
node-version: [14.x, 15.x, 16.x, 18.x]
node-version: [22.13.0, 24.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn
- run: yarn lint
- run: yarn test

windows:
runs-on: windows-latest

strategy:
matrix:
node-version: [18.x]
node-version: [22.13.0]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }} with windows
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn
- run: scripts\prepareTests.ps1
- run: yarn jest --testTimeout 30000
- run: yarn vitest --testTimeout=30000
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ _update-ts-references_ is currently not supporting [Referencing workspace packag

# License

Copyright 2023 mobile.de
Copyright 2026 mobile.de
Developer: Mirko Kruschke

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.
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const js = require('@eslint/js');

module.exports = [
js.configs.recommended,
{
files: ['src/**/*.js', 'tests/**/*.js'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'commonjs',
globals: {
afterEach: 'readonly',
beforeEach: 'readonly',
console: 'readonly',
describe: 'readonly',
expect: 'readonly',
process: 'readonly',
test: 'readonly',
},
},
rules: {},
},
];
28 changes: 11 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "update-ts-references",
"version": "4.0.0",
"version": "5.0.0",
"description": "Updates TypeScript references automatically while using workspaces",
"bin": "src/index.js",
"scripts": {
"lint": "eslint src tests",
"test": "scripts/prepareTests.sh && jest tests",
"jest": "jest tests"
"test": "scripts/prepareTests.sh && vitest run",
"vitest": "vitest run"
},
"contributors": [
{
Expand All @@ -20,19 +20,20 @@
],
"dependencies": {
"comment-json": "^4.2.3",
"glob": "^7.1.6",
"js-yaml": "^4.0.0",
"minimatch": "^3.0.5",
"fast-glob": "^3.3.3",
"js-yaml": "^4.1.1",
"minimatch": "^9.0.5",
"minimist": "^1.2.5"
},
"devDependencies": {
"eslint": "^7.7.0",
"eslint-plugin-jest": "^23.20.0",
"@eslint/js": "^10.0.1",
"eslint": "^10.0.3",
"exec-sh": "^0.3.4",
"jest": "^26.4.0"
"vite": "^8.0.1",
"vitest": "^4.1.0"
},
"engines": {
"node": ">=14.0.0"
"node": ">=22.13.0"
},
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -60,12 +61,5 @@
"url": "https://github.com/eBayClassifiedsGroup/update-ts-references/issues"
},
"homepage": "https://github.com/eBayClassifiedsGroup/update-ts-references",
"jest": {
"verbose": true,
"modulePathIgnorePatterns": [
"<rootDir>/test-scenarios/",
"<rootDir>/test-run/"
]
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

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

Expand Down
44 changes: 14 additions & 30 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const glob = require('glob');
const fastGlob = require('fast-glob');
const path = require('path');
const fs = require('fs');
const yaml = require('js-yaml');
const minimatch = require('minimatch');
const { minimatch } = require('minimatch');
const {
parse,
stringify,
Expand Down Expand Up @@ -41,19 +41,7 @@ const getAllPackageJsons = async (workspaces, cwd) => {
});

return Promise.all(
workspaceGlobs.map(
(workspace) =>
new Promise((resolve, reject) => {
glob(`${workspace}/${PACKAGE_JSON}`, { cwd }, (error, files) => {
if (error) {
reject(error);
}
resolve(files);
});
}),

[]
)
workspaceGlobs.map((workspace) => fastGlob(`${workspace}/${PACKAGE_JSON}`, { cwd, onlyFiles: true }))
)
.then((allPackages) =>
allPackages.reduce(
Expand Down Expand Up @@ -216,7 +204,7 @@ const updateTsConfig = (
if (createPathMappings)
assert.deepEqual(JSON.parse(JSON.stringify(config?.compilerOptions?.paths ?? {})), paths);
isEqual = true;
} catch (e) {
} catch {
// ignore me
}
if (!isEqual) {
Expand All @@ -243,7 +231,7 @@ const updateTsConfig = (
} catch (error) {
console.error(`could not read ${tsconfigFilePath}`, error);
if (strict)
throw new Error('Expect always a tsconfig.json in the package directory while running in strict mode')
throw new Error('Expect always a tsconfig.json in the package directory while running in strict mode', { cause: error })
}
};

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

Expand Down Expand Up @@ -336,10 +323,11 @@ const execute = async ({
console.log('packagesMap', packagesMap);
}

let rootReferences = [];
let rootPaths = [];
let tsconfigMap = {}
let jsconfigMap = {}
const referencesMap = {}
const referencedPackageNames = new Set()
const rootReferenceCandidates = []
packagesMap.forEach((packageEntry, packageName) => {
const detectedConfig = detectTSConfig(packageEntry.packageDir, configName, packageEntry.hasTsEntry && createTsConfig, cwd)

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

if (detectedConfig) {
rootReferences.push({
rootReferenceCandidates.push(ensurePosixPathStyle({
name: packageName,
path: path.join(path.relative(cwd, packageEntry.packageDir), detectedConfig !== TSCONFIG_JSON ? detectedConfig : ''),
folder: path.relative(cwd, packageEntry.packageDir),
});
}));
const references = (getReferencesFromDependencies(
configName,
packageEntry,
packageName,
packagesMap,
verbose
) || []).map(ensurePosixPathStyle);
referencesMap[packageName] = references
references.forEach(({ name }) => referencedPackageNames.add(name))

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

Expand All @@ -411,19 +401,13 @@ const execute = async ({
} else {
const detectedJsConfig = jsconfigMap[packageName]?.detectedConfig
if (!detectedJsConfig) {
// eslint-disable-next-line no-console
console.log(`NO ${configName === TSCONFIG_JSON ? configName : `${configName} nor ${TSCONFIG_JSON}`} for ${packageName}`);
}
rootPaths.push({
name: packageName,
path: path.relative(cwd, packageEntry.packageDir),
folder: path.relative(cwd, packageEntry.packageDir),
});
}
});

rootReferences = (rootReferences || []).map(ensurePosixPathStyle);
rootPaths = getPathsFromReferences((rootReferences || []).map(ensurePosixPathStyle), tsconfigMap, {}, ignorePathMappings)
const rootReferences = rootReferenceCandidates.filter(({ name }) => !referencedPackageNames.has(name));
const rootPaths = getPathsFromReferences(rootReferences, tsconfigMap, {}, ignorePathMappings)

if (verbose) {
console.log('rootReferences', rootReferences);
Expand Down
14 changes: 1 addition & 13 deletions test-scenarios/yarn-ws-check-no-changes/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
{
"path": "workspace-a"
},
{
"path": "workspace-b"
},
{
"path": "shared/workspace-c"
},
{
"path": "shared/workspace-d"
},
{
"path": "utils/foos/foo-a"
},
{
"path": "utils/foos/foo-b"
}
]
}


9 changes: 1 addition & 8 deletions test-scenarios/yarn-ws-check-paths-no-changes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
{
"files": [],
"compilerOptions": {
"composite": true,
"paths": { "foo-b": ["utils/foos/foo-b/src"] }
"composite": true
},
"references": [
{
"path": "workspace-a"
},
{
"path": "workspace-b"
},
{
"path": "utils/foos/foo-a"
},

]
}
22 changes: 1 addition & 21 deletions tests/update-ts-references.check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,9 @@ const rootTsConfig = [
{
path: 'workspace-a',
},
{
path: 'workspace-b',
},
{
path: 'shared/workspace-c',
},
{
path: 'shared/workspace-d',
},
{
path: 'utils/foos/foo-a',
},
{
path: 'utils/foos/foo-b',
},
],
},
];
Expand Down Expand Up @@ -305,19 +293,13 @@ test('No changes paths detected with the --check option', async () => {
{
compilerOptions: {
composite: true,
paths: { "foo-b": ["utils/foos/foo-b/src"] }
paths: undefined
},
files: [],
references: [
{
path: 'workspace-a',
},
{
path: 'workspace-b',
},
{
path: 'utils/foos/foo-a',
},
],
},
];
Expand Down Expand Up @@ -362,5 +344,3 @@ test('No changes paths detected with the --check option', async () => {
).toEqual(config);
});
});


Loading
Loading