Skip to content

Commit

Permalink
feat: preserve manually set reference option prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
MKruschke committed Apr 6, 2021
1 parent afc7d74 commit 17de99d
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 101 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "update-ts-references",
"version": "2.1.1",
"version": "2.2.0",
"bin": "src/index.js",
"scripts": {
"lint": "eslint src tests",
Expand Down
12 changes: 10 additions & 2 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,17 @@ Do you want to discard them and proceed?`
process.exit(0);
}
}

const currentReferences = config.references || [];

const mergedReferences = references.map((ref) => ({
...ref,
...currentReferences.find((currentRef) => currentRef.path === ref.path),
}));

let isEqual = false;
try {
assert.deepEqual(config.references || [], references);
assert.deepEqual(currentReferences, mergedReferences);
isEqual = true;
} catch {
// ignore me
Expand All @@ -166,7 +174,7 @@ Do you want to discard them and proceed?`
const newTsConfig = JSON.stringify(
{
...config,
references: references.length ? references : undefined,
references: mergedReferences.length ? mergedReferences : undefined,
},
null,
2
Expand Down
11 changes: 10 additions & 1 deletion test-scenarios/yarn-ws/workspace-a/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
},
"references": [
{
"path": "../utils/foos/foo-a",
"prepend": false
},
{
"path": "../some/old/ref"
}
]
}
232 changes: 135 additions & 97 deletions tests/update-ts-references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,109 +34,147 @@ const setup = async (rootFolder) => {
}
};

const tsconfigs = [
[
'.',
{
compilerOptions: {
composite: true,
},
files: [],
references: [
{
path: 'workspace-a',
},
{
path: 'workspace-b',
},
{
path: 'shared/workspace-c',
},
{
path: 'shared/workspace-d',
},
{
path: 'utils/foos/foo-a',
},
{
path: 'utils/foos/foo-b',
},
],
},
],
[
'./workspace-a',
{
compilerOptions,
references: [
{
path: '../utils/foos/foo-a',
},
{
path: '../workspace-b',
},
],
},
],
[
'./workspace-b',
{
compilerOptions,

references: [
{
path: '../utils/foos/foo-b',
},
],
},
],
[
'./shared/workspace-c',
{
compilerOptions,

references: [
{
path: '../../utils/foos/foo-a',
},
],
const rootTsConfig = [
'.',
{
compilerOptions: {
composite: true,
},
],
[
'./shared/workspace-d',
{
compilerOptions,

references: [
{
path: '../workspace-c',
},
],
},
],
[
'./utils/foos/foo-a',
{
compilerOptions,
references: [
{
path: '../foo-b',
},
],
},
],
[
'./utils/foos/foo-b',
{
compilerOptions,
references: undefined,
},
],
files: [],
references: [
{
path: 'workspace-a',
},
{
path: 'workspace-b',
},
{
path: 'shared/workspace-c',
},
{
path: 'shared/workspace-d',
},
{
path: 'utils/foos/foo-a',
},
{
path: 'utils/foos/foo-b',
},
],
},
];

const wsATsConfig = [
'./workspace-a',
{
compilerOptions,
references: [
{
path: '../utils/foos/foo-a',
},
{
path: '../workspace-b',
},
],
},
];

const wsBTsConfig = [
'./workspace-b',
{
compilerOptions,

references: [
{
path: '../utils/foos/foo-b',
},
],
},
];

const wsCTsConfig = [
'./shared/workspace-c',
{
compilerOptions,

references: [
{
path: '../../utils/foos/foo-a',
},
],
},
];

const wsDTsConfig = [
'./shared/workspace-d',
{
compilerOptions,

references: [
{
path: '../workspace-c',
},
],
},
];

const fooATsConfig = [
'./utils/foos/foo-a',
{
compilerOptions,
references: [
{
path: '../foo-b',
},
],
},
];

const fooBTsConfig = [
'./utils/foos/foo-b',
{
compilerOptions,
references: undefined,
},
];

const tsconfigs = [
rootTsConfig,
wsATsConfig,
wsBTsConfig,
wsCTsConfig,
wsDTsConfig,
fooATsConfig,
fooBTsConfig,
];

test('Support yarn workspaces', async () => {
await setup(rootFolderYarn);

const tsconfigs = [
rootTsConfig,
[
'./workspace-a',
{
compilerOptions,
references: [
{
path: '../utils/foos/foo-a',
prepend: false,
},
{
path: '../workspace-b',
},
],
},
],
wsBTsConfig,
wsCTsConfig,
wsDTsConfig,
fooATsConfig,
fooBTsConfig,
];

tsconfigs.forEach((tsconfig) => {
const [configPath, config] = tsconfig;

Expand Down

0 comments on commit 17de99d

Please sign in to comment.