-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kelly Selden
committed
Apr 23, 2024
1 parent
5bd584c
commit 5fd881a
Showing
8 changed files
with
247 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Ensure workspace globs in package.json resolve to directories (ensure-workspaces) | ||
|
||
Check that the monorepo workspace globs find dirs with package.json files. | ||
|
||
|
||
## Rule Details | ||
|
||
This rule aims to ensure the workspace globs find dirs with package.json files. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```json | ||
{ | ||
"workspace": [ | ||
"packages/*/missing-dir" | ||
] | ||
} | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```json | ||
{ | ||
"workspace": [ | ||
"packages/*/dir-with-package-json" | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"workspace": [ | ||
"packages/dir-with-package-json" | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"workspace": { | ||
"packages": [ | ||
"packages/*/dir-with-package-json" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### Options | ||
|
||
|
||
|
||
## When Not To Use It | ||
|
||
If workspace globs are placeholders for future packages. | ||
|
||
## Further Reading | ||
|
||
https://docs.npmjs.com/cli/v10/configuring-npm/package-json#workspaces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fg = require('fast-glob'); | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'ensure workspace globs in package.json resolve to directories' | ||
}, | ||
schema: [ | ||
] | ||
}, | ||
|
||
create(context) { | ||
let filename = context.getFilename(); | ||
if (path.basename(filename) !== 'package.json') { | ||
return {}; | ||
} | ||
|
||
return { | ||
AssignmentExpression(node) { | ||
let json = node.right; | ||
let property = json.properties.find(p => p.key.value === 'workspaces'); | ||
if (!property) { | ||
return; | ||
} | ||
|
||
let workspaces = property.value; | ||
if (workspaces.type === 'ObjectExpression') { | ||
let property = workspaces.properties.find(p => p.key.value === 'packages'); | ||
if (!property) { | ||
return; | ||
} | ||
|
||
workspaces = property.value; | ||
} | ||
|
||
if (workspaces.type !== 'ArrayExpression') { | ||
return; | ||
} | ||
|
||
for (let node of workspaces.elements) { | ||
if (node.type !== 'Literal') { | ||
continue; | ||
} | ||
|
||
if (typeof node.value !== 'string') { | ||
continue; | ||
} | ||
|
||
let glob = path.join(node.value, 'package.json'); | ||
|
||
let entries = fg.sync(glob, { | ||
cwd: path.dirname(filename) | ||
}); | ||
|
||
if (!entries.length) { | ||
context.report({ | ||
node, | ||
message: 'workspace path/glob does not match any workspaces with a package.json.' | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Empty file.
Oops, something went wrong.