-
Notifications
You must be signed in to change notification settings - Fork 229
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
Showing
4 changed files
with
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,19 @@ | ||
#! /usr/bin/env node | ||
// @ts-check | ||
/* eslint-env node */ | ||
import { spawn } from 'child_process'; | ||
import { execFileSync } from 'child_process'; | ||
import { basename } from 'path'; | ||
import { listWorkspaces } from '../src/lib/packageManager.js'; | ||
|
||
const ps = spawn('yarn', ['workspaces', '--silent', 'info'], { | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
shell: true, | ||
}); | ||
const workspaces = listWorkspaces({ execFileSync }); | ||
|
||
// Get Buffers of output. | ||
const chunks = []; | ||
ps.stdout.on('data', data => chunks.push(data)); | ||
const packageNames = workspaces.map(w => w.name); | ||
|
||
// Wait for the process to exit. | ||
ps.on('close', code => { | ||
if (code !== 0) { | ||
throw Error(`yarn info exited with code ${code}`); | ||
} | ||
|
||
// Get the output. | ||
const json = Buffer.concat(chunks).toString('utf8'); | ||
// process.stderr.write(json); | ||
|
||
// Write the module. | ||
const workspaces = Object.keys(JSON.parse(json)).sort(); | ||
process.stdout.write(`\ | ||
// Write the module. | ||
process.stdout.write(`\ | ||
// DO NOT EDIT - automatically generated by ${basename( | ||
new URL(import.meta.url).pathname, | ||
)} | ||
new URL(import.meta.url).pathname, | ||
)} | ||
// prettier-ignore | ||
export default ${JSON.stringify(workspaces, null, 2)}; | ||
export default ${JSON.stringify(packageNames.sort(), null, 2)}; | ||
`); | ||
}); |
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 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @import { execFileSync } from 'child_process'; | ||
*/ | ||
|
||
/** | ||
* Omits the root | ||
* | ||
* @param {{ execFileSync: execFileSync }} io | ||
* @returns {Array<{ location: string, name: string }>} | ||
*/ | ||
export const listWorkspaces = ({ execFileSync }) => { | ||
const out = execFileSync('npm', ['query', '.workspace'], { | ||
stdio: ['ignore', 'pipe', 'inherit'], | ||
shell: true, | ||
encoding: 'utf-8', | ||
}); | ||
/** @type {Array<{ location: string, name: string, description: string }>} */ | ||
const result = JSON.parse(out); | ||
return result.filter(({ location }) => location !== '.'); | ||
}; |
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