Skip to content

Commit 1d08a81

Browse files
author
Marcus Pousette
committed
feat: workspace runtime argument
1 parent b468ff1 commit 1d08a81

File tree

12 files changed

+64
-26
lines changed

12 files changed

+64
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
"scripts": {
209209
"clean": "node src/index.js clean",
210210
"build": "node src/index.js build --no-bundle",
211-
"lint": "node src/index.js lint",
211+
"lint": "node src/index.js lint --fix",
212212
"test": "node src/index.js test",
213213
"docs": "node src/index.js docs",
214214
"dep-check": "node src/index.js dep-check",

src/check-project/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl, ciFil
114114

115115
const projectDirs = []
116116

117-
for (const subProjectDir of await getSubprojectDirectories(projectDir, workspaces)) {
117+
for (const subProjectDir of await getSubprojectDirectories(workspaces, projectDir)) {
118118
const stat = await fs.stat(subProjectDir)
119119

120120
if (!stat.isDirectory()) {

src/cmds/run.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { loadUserConfig } from '../config/user.js'
22
import runCmd from '../run.js'
3+
import { listWorkspaces } from '../utils.js'
34

45
/**
56
* @typedef {import("yargs").Argv} Argv
@@ -39,6 +40,14 @@ export default {
3940
type: 'number',
4041
describe: 'How many scripts to run at the same time',
4142
default: userConfig.run.concurrency
43+
},
44+
45+
workspaces: {
46+
// an array of strings
47+
array: true,
48+
describe: 'Run the script in a specific workspace',
49+
default: await listWorkspaces(process.cwd()),
50+
alias: ['workspace', 'roots']
4251
}
4352
})
4453
.positional('script', {

src/docs/readme-updater-plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function load (app) {
1515
let projects = {}
1616

1717
if (isMonorepoParent) {
18-
projects = parseProjects(process.cwd(), pkg.workspaces)
18+
projects = parseProjects(pkg.workspaces)
1919
}
2020

2121
// when rendering has finished, work out which UrlMappings refer to the index

src/exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default {
1414
async run (ctx) {
1515
const forwardArgs = ctx['--'] ? ctx['--'] : []
1616

17-
await everyMonorepoProject(process.cwd(), async (project) => {
17+
await everyMonorepoProject(async (project) => {
1818
console.info('') // eslint-disable-line no-console
1919
console.info(kleur.grey(`${project.manifest.name}:`), `> ${ctx.command}${forwardArgs.length > 0 ? ` ${forwardArgs.join(' ')}` : ''}`) // eslint-disable-line no-console
2020

src/release-rc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function releaseMonorepoRcs (commit, ctx) {
2222
/** @type {Record<string, string>} */
2323
const versions = {}
2424

25-
await everyMonorepoProject(process.cwd(), async (project) => {
25+
await everyMonorepoProject(async (project) => {
2626
if (project.manifest.private === true) {
2727
console.info(`Skipping private package ${project.manifest.name}`)
2828
return
@@ -43,7 +43,7 @@ async function releaseMonorepoRcs (commit, ctx) {
4343
console.info('')
4444

4545
// publish packages
46-
await everyMonorepoProject(process.cwd(), async (project) => {
46+
await everyMonorepoProject(async (project) => {
4747
if (project.manifest.private === true) {
4848
console.info(`Skipping private package ${project.manifest.name}`)
4949
return

src/release.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const tasks = new Listr([
6969
const {
7070
siblingVersions,
7171
packageDirs
72-
} = await calculateSiblingVersions(rootDir, workspaces)
72+
} = await calculateSiblingVersions(workspaces, rootDir)
7373

7474
// check these dependency types for monorepo siblings
7575
const dependencyTypes = [
@@ -142,16 +142,16 @@ const tasks = new Listr([
142142
], { renderer: 'verbose' })
143143

144144
/**
145-
* @param {string} rootDir
146145
* @param {string[]} workspaces
146+
* @param {string} rootDir
147147
*/
148-
async function calculateSiblingVersions (rootDir, workspaces) {
148+
async function calculateSiblingVersions (workspaces, rootDir) {
149149
const packageDirs = []
150150

151151
/** @type {Record<string, string>} */
152152
const siblingVersions = {}
153153

154-
for (const subProjectDir of await getSubprojectDirectories(rootDir, workspaces)) {
154+
for (const subProjectDir of await getSubprojectDirectories(workspaces, rootDir)) {
155155
const pkg = JSON.parse(fs.readFileSync(path.join(subProjectDir, 'package.json'), {
156156
encoding: 'utf-8'
157157
}))

src/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020

2121
const forwardArgs = ctx['--'] == null ? [] : ['--', ...ctx['--']]
2222

23-
await everyMonorepoProject(process.cwd(), async (project) => {
23+
await everyMonorepoProject(async (project) => {
2424
for (const script of scripts) {
2525
if (project.manifest.scripts[script] == null) {
2626
continue
@@ -45,6 +45,7 @@ export default {
4545
}
4646
}
4747
}, {
48+
workspaces: ctx.workspaces,
4849
concurrency: ctx.concurrency
4950
})
5051
}

src/test-dependant/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const testMonoRepo = async (targetDir, deps, scriptName) => {
196196
}
197197

198198
// test each package that depends on passed deps
199-
for (const match of await getSubprojectDirectories(targetDir, config.workspaces)) {
199+
for (const match of await getSubprojectDirectories(config.workspaces, targetDir)) {
200200
await testModule(path.join(targetDir, match), deps, scriptName)
201201
}
202202
}

src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ interface GlobalOptions {
109109
* Full config from configuration file
110110
*/
111111
fileConfig: Options
112+
112113
}
113114

114115
interface BuildOptions {
@@ -391,9 +392,11 @@ interface ExecOptions {
391392
* Run commands in parallel up to this limit
392393
*/
393394
concurrency?: number
395+
394396
}
395397

396398
interface RunOptions {
399+
397400
/**
398401
* If false, the script will continue to be run in other packages
399402
*/
@@ -408,6 +411,12 @@ interface RunOptions {
408411
* Run scripts in parallel up to this limit
409412
*/
410413
concurrency?: number
414+
415+
/**
416+
* Workspaces to run the command in
417+
*/
418+
workspaces?: string[]
419+
411420
}
412421

413422
export type {

0 commit comments

Comments
 (0)