forked from MetaMask/snaps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
child-workspace-package-names-as-json
script in favour of `y…
…arn workspaces filter` command (MetaMask#1491) * Remove `child-workspace-package-names-as-json` script in favour of `yarn workspaces filter` command * Revert changes to Yarn binary * Load minimatch from execute * Update LavaMoat policies * Use await import * Return full name instead of workspace folder * Use older version of minimatch and patch @types/glob * Exclude root from child workspaces
- Loading branch information
Showing
8 changed files
with
161 additions
and
76 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,22 @@ | ||
diff --git a/index.d.ts b/index.d.ts | ||
index 8213c43da1204e92db61cd9af6018362986f0ad9..d9fa158b4fa858c8b9cf9d5cc75f5e7b2c6bcbb8 100755 | ||
--- a/index.d.ts | ||
+++ b/index.d.ts | ||
@@ -25,7 +25,7 @@ declare namespace G { | ||
let Glob: IGlobStatic; | ||
let GlobSync: IGlobSyncStatic; | ||
|
||
- interface IOptions extends minimatch.IOptions { | ||
+ interface IOptions extends minimatch.MinimatchOptions { | ||
cwd?: string | undefined; | ||
root?: string | undefined; | ||
dot?: boolean | undefined; | ||
@@ -69,7 +69,7 @@ declare namespace G { | ||
} | ||
|
||
interface IGlobBase { | ||
- minimatch: minimatch.IMinimatch; | ||
+ minimatch: minimatch.MinimatchOptions; | ||
options: IOptions; | ||
aborted: boolean; | ||
cache: { [path: string]: boolean | 'DIR' | 'FILE' | ReadonlyArray<string> }; |
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,97 @@ | ||
module.exports = { | ||
name: `plugin-workspaces-filter`, | ||
factory: (require) => { | ||
const { BaseCommand } = require('@yarnpkg/cli'); | ||
const { Configuration, Project, StreamReport } = require('@yarnpkg/core'); | ||
const { Command, Option, UsageError } = require('clipanion'); | ||
const { isString, isBoolean } = require('typanion'); | ||
|
||
class FilterCommand extends BaseCommand { | ||
static paths = [['workspaces', 'filter']]; | ||
|
||
static usage = Command.Usage({ | ||
description: 'Filter workspaces', | ||
details: ` | ||
This command will filter workspaces based on the given criteria. It's | ||
like \`yarn workspaces list\` but on steroids. | ||
`, | ||
examples: [ | ||
[ | ||
`List workspaces based on a glob pattern`, | ||
`yarn workspaces filter --include "packages/*"`, | ||
], | ||
[ | ||
'Exclude workspaces based on a glob pattern', | ||
`yarn workspaces filter --exclude "packages/*/foo"`, | ||
], | ||
], | ||
}); | ||
|
||
include = Option.String('--include', { | ||
description: `List workspaces based on a glob pattern`, | ||
validator: isString, | ||
}); | ||
|
||
exclude = Option.String('--exclude', { | ||
description: `Exclude workspaces based on a glob pattern`, | ||
validator: isString, | ||
}); | ||
|
||
json = Option.Boolean(`--json`, false, { | ||
description: `Format the output as a JSON array`, | ||
validator: isBoolean, | ||
}); | ||
|
||
async execute() { | ||
// Note: We have to import `minimatch` here, because Yarn will always | ||
// load the plugin, even if the command is not used, and `minimatch` | ||
// may not be installed. | ||
const { minimatch } = await import('minimatch'); | ||
|
||
const configuration = await Configuration.find( | ||
this.context.cwd, | ||
this.context.plugins, | ||
); | ||
const { project } = await Project.find(configuration, this.context.cwd); | ||
const { workspaces } = project; | ||
|
||
if (!this.include && !this.exclude) { | ||
throw new UsageError( | ||
`This command requires at least one of --include or --exclude to be specified.`, | ||
); | ||
} | ||
|
||
const report = await StreamReport.start( | ||
{ | ||
configuration, | ||
json: this.json, | ||
stdout: this.context.stdout, | ||
}, | ||
async (report) => { | ||
const filteredWorkspaces = workspaces.filter((workspace) => { | ||
return ( | ||
(!this.include || | ||
minimatch(workspace.relativeCwd, this.include)) && | ||
(!this.exclude || | ||
!minimatch(workspace.relativeCwd, this.exclude)) | ||
); | ||
}); | ||
|
||
for (const workspace of filteredWorkspaces) { | ||
report.reportInfo(null, workspace.relativeCwd); | ||
} | ||
|
||
const result = filteredWorkspaces.map((workspace) => workspace.manifest.raw.name); | ||
report.reportJson(result); | ||
}, | ||
); | ||
|
||
return report.exitCode(); | ||
} | ||
} | ||
|
||
return { | ||
commands: [FilterCommand], | ||
}; | ||
}, | ||
}; |
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
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 was deleted.
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