diff --git a/README.md b/README.md index 5fd9eff..b5f93bd 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,18 @@ The output for the created file looks like the following }, "references": [ // will be added after running update-ts-references { - "path": "../some-other-package + "path": "../some-other-package" } ] } ``` +## using update-ts-references.yaml for configurations +You can configure paths via the update-ts-references.yaml file. This is useful if your repo is having no package.json or pnp-workspace.yaml in the root folder. Additional to that it can also expand the paths config next to the normal workspace setup via npm, pnpm, yarn and lerna. + +Example configuration see [here](./test-scenarios/ts-ref-yaml/update-ts-references.yaml) +```yaml + ## FAQ ### Why is my pnpm workspace alias not working? diff --git a/src/update-ts-references.js b/src/update-ts-references.js index b63e836..e1a7f61 100644 --- a/src/update-ts-references.js +++ b/src/update-ts-references.js @@ -28,7 +28,11 @@ const getAllPackageJsons = async (workspaces,cwd) => { workspaces.forEach((workspaceGlob) => { if (workspaceGlob.startsWith('!')) { - ignoreGlobs.push(workspaceGlob); + let ignoreGlob = workspaceGlob; + if (!ignoreGlob.includes('/')) { + ignoreGlob = `${ignoreGlob}/${PACKAGE_JSON}`; + } + ignoreGlobs.push(ignoreGlob); } else { workspaceGlobs.push(workspaceGlob); } @@ -60,6 +64,7 @@ const getAllPackageJsons = async (workspaces,cwd) => { (packageName) => ignoreGlobs.reduce((prev, actualPattern) => { if (!prev) return prev; + return minimatch(packageName, actualPattern); }, true) && !packageName.includes('node_modules') ) @@ -134,7 +139,6 @@ const getReferencesFromDependencies = ( } return Object.keys(mergedDependencies) - .filter(name => !name.includes('test-utils')) .reduce((referenceArray, dependency) => { if (packagesMap.has(dependency)) { const { packageDir: dependencyDir } = packagesMap.get(dependency); @@ -232,6 +236,10 @@ const execute = async ({ ); workspaces = [...(config.packages ? config.packages : []), ...(workspaces ? workspaces : [])]; + + if (verbose) { + console.log('joined workspaces config', workspaces); + } } if (!workspaces) { diff --git a/test-scenarios/ts-ref-yaml/update-ts-references.yaml b/test-scenarios/ts-ref-yaml/update-ts-references.yaml index 5ec5a20..431ed23 100644 --- a/test-scenarios/ts-ref-yaml/update-ts-references.yaml +++ b/test-scenarios/ts-ref-yaml/update-ts-references.yaml @@ -3,3 +3,4 @@ packages: - 'workspace-a' # exclude packages that are inside test directories - '!**/tests/**' + - '!workspace-ignore' diff --git a/test-scenarios/ts-ref-yaml/workspace-ignore/package.json b/test-scenarios/ts-ref-yaml/workspace-ignore/package.json new file mode 100644 index 0000000..280f2d0 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-ignore/package.json @@ -0,0 +1,10 @@ +{ + "name": "ignore", + "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-ignore/tsconfig.json b/test-scenarios/ts-ref-yaml/workspace-ignore/tsconfig.json new file mode 100644 index 0000000..1dd8e13 --- /dev/null +++ b/test-scenarios/ts-ref-yaml/workspace-ignore/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 52ee21c..f4b36f2 100644 --- a/tests/update-ts-references.test.js +++ b/tests/update-ts-references.test.js @@ -258,6 +258,11 @@ test('Support update-ts-reference.yaml workspaces', async () => { parse(fs.readFileSync(path.join(rootFolderTsRefYaml, configPath, 'tsconfig.json')).toString()) ).toEqual(config); }); + + // should not touch the ignore config + expect( + parse(fs.readFileSync(path.join(rootFolderTsRefYaml,'workspace-ignore', 'tsconfig.json')).toString()) + ).toEqual( {compilerOptions}); }); test('Test create tsconfig', async () => {