Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Support targeting workspaces (#15)
Browse files Browse the repository at this point in the history
* chore: update yarn

* feat: support targetting workspaces
  • Loading branch information
Noah authored Aug 22, 2021
1 parent fe8d131 commit d48d414
Show file tree
Hide file tree
Showing 6 changed files with 533 additions and 400 deletions.
440 changes: 220 additions & 220 deletions .yarn/releases/yarn-3.0.0.cjs → .yarn/releases/yarn-3.0.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ npmRegistries:
plugins:
- ./bundles/@yarnpkg/plugin-semver-up.js

yarnPath: .yarn/releases/yarn-3.0.0.cjs
yarnPath: .yarn/releases/yarn-3.0.1.cjs
6 changes: 3 additions & 3 deletions bundles/@yarnpkg/plugin-semver-up.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"@types/micromatch": "^4.0.1",
"@types/node": "^14.0.0",
"@types/semver": "^7.3.6",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"@yarnpkg/builder": "^3.0.0-rc.13",
"@yarnpkg/cli": "^3.0.0",
"@yarnpkg/core": "^3.0.0",
"@yarnpkg/fslib": "^2.5.0",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"@yarnpkg/builder": "^3.0.2-rc.1",
"@yarnpkg/cli": "^3.0.1",
"@yarnpkg/core": "^3.1.0-rc.1",
"@yarnpkg/fslib": "^2.5.1",
"@yarnpkg/libzip": "^2.2.2",
"@yarnpkg/plugin-essentials": "^3.0.0",
"@yarnpkg/plugin-essentials": "^3.0.1-rc.1",
"@yarnpkg/plugin-npm": "^2.5.0",
"@yarnpkg/plugin-pack": "^3.0.0",
"@yarnpkg/sdks": "^2.4.1-rc.4",
Expand Down Expand Up @@ -97,5 +97,6 @@
"dependencies": {
"micromatch": "^4.0.4",
"semver": "^7.3.5"
}
},
"packageManager": "[email protected]"
}
134 changes: 87 additions & 47 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class SemverUpCommand extends Command<CommandContext> {

preserveSemVerRange: boolean = Option.Boolean('--preserve-semver', true)

include?: string = Option.String('--include', { required: false })

ruleGlobs: Array<string> = Option.Rest()

async execute(): Promise<number> {
Expand All @@ -89,7 +91,7 @@ class SemverUpCommand extends Command<CommandContext> {
this.context.cwd,
this.context.plugins,
)
const { project } = await Project.find(
const { project, workspace } = await Project.find(
configuration,
this.context.cwd,
)
Expand All @@ -98,54 +100,92 @@ class SemverUpCommand extends Command<CommandContext> {
await project.restoreInstallState()

const config = await this.parseConfigFile()
const workspace = project.topLevelWorkspace

const pipeline = async (report: Report) => {
const rulesWithPackages = ((await report.startTimerPromise<RulesWithPackages>(
'Processing Semver Up Rules',
{ skipIfEmpty: false },
async () =>
this.getRulesWithPackages({
config,
workspace,
report,
}),
)) as unknown) as RulesWithPackages

const rulesWithUpdates = ((await report.startTimerPromise<RulesWithUpdates>(
'Finding Updates',
{ skipIfEmpty: false },
async () =>
this.findUpdateCandidates({
workspace,
rulesWithPackages,
cache,
configuration,
report,
}),
)) as unknown) as RulesWithUpdates

const changeset = ((await report.startTimerPromise<Changeset>(
'Staging Updates',
{ skipIfEmpty: false },
async () =>
this.applyUpdates({
config,
workspace,
rulesWithUpdates,
report,
}),
)) as unknown) as Changeset

await report.startTimerPromise(
'Writing Changeset File',
{ skipIfEmpty: true },
async () => {
await this.writeChangeset({
changeset,
})
},
)
if (!workspace && !this.include) {
throw new Error('Must be run from within a workspace.')
}

const allWorkspaceIdents = project.workspaces
.filter(w => w.manifest.name)
.map(w => structUtils.stringifyIdent(w.manifest.name))

const workspaces = this.include
? new Set<Workspace>(
micromatch(allWorkspaceIdents, this.include)
.map(ident =>
project.tryWorkspaceByIdent(
structUtils.parseIdent(ident),
),
)
.filter(v => v),
)
: new Set<Workspace>([workspace])

if (!workspaces.size) {
throw new Error('No workspaces selected.')
}

const changesets: Changeset[] = []
for (const workspace of workspaces) {
const workspaceName = structUtils.stringifyIdent(
workspace.manifest.name,
)
const rulesWithPackages = ((await report.startTimerPromise<RulesWithPackages>(
`[${workspaceName}] Processing Semver Up Rules`,
{ skipIfEmpty: false },
async () =>
this.getRulesWithPackages({
config,
workspace,
report,
}),
)) as unknown) as RulesWithPackages

const rulesWithUpdates = ((await report.startTimerPromise<RulesWithUpdates>(
`[${workspaceName}] Finding Updates`,
{ skipIfEmpty: false },
async () =>
this.findUpdateCandidates({
workspace,
rulesWithPackages,
cache,
configuration,
report,
}),
)) as unknown) as RulesWithUpdates

const changeset = ((await report.startTimerPromise<Changeset>(
`[${workspaceName}] Staging Updates`,
{ skipIfEmpty: false },
async () =>
this.applyUpdates({
config,
workspace,
rulesWithUpdates,
report,
}),
)) as unknown) as Changeset

changesets.push(changeset)
}

if (workspaces.size > 1 && this.changesetFilename) {
report.reportError(
MessageName.UNNAMED,
'Changesets not supported when targetting more than one workspace.',
)
} else {
await report.startTimerPromise(
'Writing Changeset File',
{ skipIfEmpty: true },
async () => {
await this.writeChangeset({
changeset: changesets[0],
})
},
)
}

if (!this.dryRun) {
await project.install({ cache, report })
Expand Down
Loading

0 comments on commit d48d414

Please sign in to comment.