Skip to content

Commit

Permalink
feat: introduce update-ts-reference.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko Kruschke committed Nov 17, 2023
1 parent a588e64 commit d0d64f9
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ const execute = async ({
workspaces = pnpmConfig.packages;
}

if (fs.existsSync(path.join(cwd, 'update-ts-references.yaml'))) {
const config = yaml.load(
fs.readFileSync(path.join(cwd, 'update-ts-references.yaml'))
);

workspaces = [...(config.packages ? config.packages : []), ...(workspaces ? workspaces : [])];
}

if (!workspaces) {
throw new Error(
'could not detect yarn/npm/pnpm workspaces or lerna in this repository'
Expand Down
13 changes: 13 additions & 0 deletions test-scenarios/ts-ref-yaml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ts-ref-yaml-workspace",
"version": "0.0.1",
"private": true,
"workspaces": [
"workspace-b",
"shared/*",
"utils/**/"
],
"devDependencies": {
"typescript": "latest"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-yaml/shared/workspace-c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-c",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"peerDependencies": {
"foo-a": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/shared/workspace-c/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
7 changes: 7 additions & 0 deletions test-scenarios/ts-ref-yaml/shared/workspace-d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-d",
"version": "1.0.0",
"dependencies": {
"workspace-c": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/shared/workspace-d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
8 changes: 8 additions & 0 deletions test-scenarios/ts-ref-yaml/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [],
"compilerOptions": {
/* Basic Options */
// "allowJs": true,
"composite": true
}
}
5 changes: 5 additions & 0 deletions test-scenarios/ts-ref-yaml/update-ts-references.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
# all packages in subdirs of packages/ and components/
- 'workspace-a'
# exclude packages that are inside test directories
- '!**/tests/**'
7 changes: 7 additions & 0 deletions test-scenarios/ts-ref-yaml/utils/foos/foo-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "foo-a",
"version": "1.0.0",
"dependencies": {
"foo-b": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/utils/foos/foo-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
4 changes: 4 additions & 0 deletions test-scenarios/ts-ref-yaml/utils/foos/foo-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "foo-b",
"version": "1.0.0"
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/utils/foos/foo-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test-a",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-yaml/workspace-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-a",
"version": "1.0.0",
"dependencies": {
"workspace-b": "1.0.0"
},
"devDependencies": {
"foo-a": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/workspace-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-yaml/workspace-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-b",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"devDependencies": {
"foo-b": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-yaml/workspace-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
13 changes: 13 additions & 0 deletions tests/update-ts-references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const rootFolderYarnCreate = path.join(
'yarn-ws-create'
);
const rootFolderPnpm = path.join(process.cwd(), 'test-run', 'pnpm');
const rootFolderTsRefYaml = path.join(process.cwd(), 'test-run', 'ts-ref-yaml');
const rootFolderYarnCheck = path.join(
process.cwd(),
'test-run',
Expand Down Expand Up @@ -247,6 +248,18 @@ test('Support pnpm workspaces', async () => {
});
});

test('Support update-ts-reference.yaml workspaces', async () => {
await setup(rootFolderTsRefYaml);

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

expect(
parse(fs.readFileSync(path.join(rootFolderTsRefYaml, configPath, 'tsconfig.json')).toString())
).toEqual(config);
});
});

test('Test create tsconfig', async () => {
await setup(rootFolderYarnCreate, undefined, true);
const r = [
Expand Down

0 comments on commit d0d64f9

Please sign in to comment.