Skip to content

Commit

Permalink
fix: fix simple ignore pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko Kruschke committed Nov 17, 2023
1 parent d0d64f9 commit c4fa54a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 6 additions & 2 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getAllPackageJsons = async (workspaces,cwd) => {

workspaces.forEach((workspaceGlob) => {
if (workspaceGlob.startsWith('!')) {
ignoreGlobs.push(workspaceGlob);
ignoreGlobs.push(!workspaceGlob.includes('/') ? `${workspaceGlob}/${PACKAGE_JSON}`: workspaceGlob);
} else {
workspaceGlobs.push(workspaceGlob);
}
Expand Down Expand Up @@ -60,6 +60,7 @@ const getAllPackageJsons = async (workspaces,cwd) => {
(packageName) =>
ignoreGlobs.reduce((prev, actualPattern) => {
if (!prev) return prev;

return minimatch(packageName, actualPattern);
}, true) && !packageName.includes('node_modules')
)
Expand Down Expand Up @@ -134,7 +135,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);
Expand Down Expand Up @@ -232,6 +232,10 @@ const execute = async ({
);

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

if (verbose) {
console.log('joined workspaces config', workspaces);
}
}

if (!workspaces) {
Expand Down
1 change: 1 addition & 0 deletions test-scenarios/ts-ref-yaml/update-ts-references.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ packages:
- 'workspace-a'
# exclude packages that are inside test directories
- '!**/tests/**'
- '!workspace-ignore'
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-yaml/workspace-ignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ignore",
"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-ignore/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
5 changes: 5 additions & 0 deletions tests/update-ts-references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit c4fa54a

Please sign in to comment.