diff --git a/src/update-ts-references.js b/src/update-ts-references.js index a4e7317..b63e836 100644 --- a/src/update-ts-references.js +++ b/src/update-ts-references.js @@ -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' diff --git a/test-scenarios/ts-ref-yaml/package.json b/test-scenarios/ts-ref-yaml/package.json new file mode 100644 index 0000000..73a13fb --- /dev/null +++ b/test-scenarios/ts-ref-yaml/package.json @@ -0,0 +1,13 @@ +{ + "name": "ts-ref-yaml-workspace", + "version": "0.0.1", + "private": true, + "workspaces": [ + "workspace-b", + "shared/*", + "utils/**/" + ], + "devDependencies": { + "typescript": "latest" + } +} diff --git a/test-scenarios/ts-ref-yaml/shared/workspace-c/package.json b/test-scenarios/ts-ref-yaml/shared/workspace-c/package.json new file mode 100644 index 0000000..a401b15 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/shared/workspace-c/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-c", + "version": "1.0.0", + "dependencies": { + "cross-env": "5.0.5" + }, + "peerDependencies": { + "foo-a": "1.0.0" + } +} diff --git a/test-scenarios/ts-ref-yaml/shared/workspace-c/tsconfig.json b/test-scenarios/ts-ref-yaml/shared/workspace-c/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/shared/workspace-c/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/shared/workspace-d/package.json b/test-scenarios/ts-ref-yaml/shared/workspace-d/package.json new file mode 100644 index 0000000..e5a993c --- /dev/null +++ b/test-scenarios/ts-ref-yaml/shared/workspace-d/package.json @@ -0,0 +1,7 @@ +{ + "name": "workspace-d", + "version": "1.0.0", + "dependencies": { + "workspace-c": "1.0.0" + } +} diff --git a/test-scenarios/ts-ref-yaml/shared/workspace-d/tsconfig.json b/test-scenarios/ts-ref-yaml/shared/workspace-d/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/shared/workspace-d/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/tsconfig.json b/test-scenarios/ts-ref-yaml/tsconfig.json new file mode 100644 index 0000000..23b6225 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/tsconfig.json @@ -0,0 +1,8 @@ +{ + "files": [], + "compilerOptions": { + /* Basic Options */ + // "allowJs": true, + "composite": true + } +} diff --git a/test-scenarios/ts-ref-yaml/update-ts-references.yaml b/test-scenarios/ts-ref-yaml/update-ts-references.yaml new file mode 100644 index 0000000..5ec5a20 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/update-ts-references.yaml @@ -0,0 +1,5 @@ +packages: + # all packages in subdirs of packages/ and components/ + - 'workspace-a' + # exclude packages that are inside test directories + - '!**/tests/**' diff --git a/test-scenarios/ts-ref-yaml/utils/foos/foo-a/package.json b/test-scenarios/ts-ref-yaml/utils/foos/foo-a/package.json new file mode 100644 index 0000000..699ec9c --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/foo-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "foo-a", + "version": "1.0.0", + "dependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/ts-ref-yaml/utils/foos/foo-a/tsconfig.json b/test-scenarios/ts-ref-yaml/utils/foos/foo-a/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/foo-a/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/utils/foos/foo-b/package.json b/test-scenarios/ts-ref-yaml/utils/foos/foo-b/package.json new file mode 100644 index 0000000..2c997b8 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/foo-b/package.json @@ -0,0 +1,4 @@ +{ + "name": "foo-b", + "version": "1.0.0" +} diff --git a/test-scenarios/ts-ref-yaml/utils/foos/foo-b/tsconfig.json b/test-scenarios/ts-ref-yaml/utils/foos/foo-b/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/foo-b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/package.json b/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/package.json new file mode 100644 index 0000000..ea4b7c6 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/package.json @@ -0,0 +1,4 @@ +{ + "name": "test-a", + "version": "1.0.0" +} diff --git a/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/tsconfig.json b/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/utils/foos/tests/test-a/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/workspace-a/package.json b/test-scenarios/ts-ref-yaml/workspace-a/package.json new file mode 100644 index 0000000..f35aa29 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-a/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-a", + "version": "1.0.0", + "dependencies": { + "workspace-b": "1.0.0" + }, + "devDependencies": { + "foo-a": "1.0.0" + } +} diff --git a/test-scenarios/ts-ref-yaml/workspace-a/tsconfig.json b/test-scenarios/ts-ref-yaml/workspace-a/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-a/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/test-scenarios/ts-ref-yaml/workspace-b/package.json b/test-scenarios/ts-ref-yaml/workspace-b/package.json new file mode 100644 index 0000000..552cf0e --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-b/package.json @@ -0,0 +1,10 @@ +{ + "name": "workspace-b", + "version": "1.0.0", + "dependencies": { + "cross-env": "5.0.5" + }, + "devDependencies": { + "foo-b": "1.0.0" + } +} diff --git a/test-scenarios/ts-ref-yaml/workspace-b/tsconfig.json b/test-scenarios/ts-ref-yaml/workspace-b/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "outDir": "dist", + "rootDir": "src" + } +} diff --git a/tests/update-ts-references.test.js b/tests/update-ts-references.test.js index b63f88e..52ee21c 100644 --- a/tests/update-ts-references.test.js +++ b/tests/update-ts-references.test.js @@ -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', @@ -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 = [