-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore support for Bolt monorepos (#174)
* Restore support for Bolt monorepos * Update packages/get-packages/src/index.ts Co-authored-by: Mateusz Burzyński <[email protected]> * Move BoltTool down --------- Co-authored-by: Mateusz Burzyński <[email protected]>
- Loading branch information
1 parent
bf7f69f
commit de0fff3
Showing
13 changed files
with
197 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@manypkg/get-packages": minor | ||
"@manypkg/find-root": minor | ||
"@manypkg/tools": minor | ||
"@manypkg/cli": minor | ||
--- | ||
|
||
Restored support for Bolt monorepos. |
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,11 @@ | ||
{ | ||
"private": true, | ||
"name": "bolt-workspaces", | ||
"description": "bolt-workspaces", | ||
"version": "1.0.0", | ||
"bolt": { | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"name": "bolt-workspace-pkg-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"pkg-b": "1.0.0" | ||
} | ||
} |
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,4 @@ | ||
{ | ||
"name": "bolt-workspace-pkg-b", | ||
"version": "1.0.0" | ||
} |
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 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 |
---|---|---|
@@ -1,21 +1,35 @@ | ||
# @manypkg/get-packages | ||
|
||
> A simple utility to get the packages from a monorepo, whether they're using Yarn, Lerna, pnpm or Rush | ||
> A simple utility to get the packages from a monorepo, whether they're using Yarn, Bolt, Lerna, pnpm or Rush | ||
This library exports `getPackages` and `getPackagesSync`. It is intended mostly for use of developers building tools that want to support different kinds of monorepos as an easy way to write tools without having to write tool-specific code. It supports Yarn, Lerna, pnpm, Rush and single-package repos(where the only package is the the same as the root package). This library uses `@manypkg/find-root` to search up from the directory that's passed to `getPackages` or `getPackagesSync` to find the project root. | ||
This library exports `getPackages` and `getPackagesSync`. It is intended mostly for use of developers building tools that want to support different kinds of monorepos as an easy way to write tools without having to write tool-specific code. It supports Yarn, Bolt, Lerna, pnpm, Rush and single-package repos(where the only package is the the same as the root package). This library uses `@manypkg/find-root` to search up from the directory that's passed to `getPackages` or `getPackagesSync` to find the project root. | ||
|
||
```typescript | ||
import { getPackages, getPackagesSync } from "@manypkg/get-packages"; | ||
|
||
const { tool, root, packages } = await getPackages(process.cwd()); | ||
const { tool, root, packages } = getPackagesSync(process.cwd()); | ||
const { tool, packages, rootPackage, rootDir } = await getPackages(process.cwd()); | ||
const { tool, packages, rootPackage, rootDir } = getPackagesSync(process.cwd()); | ||
|
||
type Package = { packageJson: PackageJSON; dir: string }; | ||
// From @manypkg/tools | ||
|
||
type Packages = { | ||
interface Tool { | ||
readonly type: string; | ||
isMonorepoRoot(directory: string): Promise<boolean>; | ||
isMonorepoRootSync(directory: string): boolean; | ||
getPackages(directory: string): Promise<Packages>; | ||
getPackagesSync(directory: string): Packages; | ||
} | ||
|
||
interface Package { | ||
packageJson: PackageJSON; | ||
dir: string; | ||
relativeDir: string; | ||
} | ||
|
||
interface Packages { | ||
tool: Tool; | ||
packages: Package[]; | ||
rootPackage?: Package; | ||
rootDir: 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
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,120 @@ | ||
import path from "path"; | ||
import fs from "fs-extra"; | ||
|
||
import { Tool, PackageJSON, Packages, InvalidMonorepoError } from "./Tool"; | ||
import { | ||
expandPackageGlobs, | ||
expandPackageGlobsSync, | ||
} from "./expandPackageGlobs"; | ||
|
||
export interface BoltPackageJSON extends PackageJSON { | ||
bolt?: { | ||
workspaces?: string[]; | ||
}; | ||
} | ||
|
||
export const BoltTool: Tool = { | ||
type: "bolt", | ||
|
||
async isMonorepoRoot(directory: string): Promise<boolean> { | ||
try { | ||
const pkgJson = (await fs.readJson( | ||
path.join(directory, "package.json") | ||
)) as BoltPackageJSON; | ||
if (pkgJson.bolt && pkgJson.bolt.workspaces) { | ||
return true; | ||
} | ||
} catch (err) { | ||
if (err && (err as { code: string }).code === "ENOENT") { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
return false; | ||
}, | ||
|
||
isMonorepoRootSync(directory: string): boolean { | ||
try { | ||
const pkgJson = fs.readJsonSync( | ||
path.join(directory, "package.json") | ||
) as BoltPackageJSON; | ||
if (pkgJson.bolt && pkgJson.bolt.workspaces) { | ||
return true; | ||
} | ||
} catch (err) { | ||
if (err && (err as { code: string }).code === "ENOENT") { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
return false; | ||
}, | ||
|
||
async getPackages(directory: string): Promise<Packages> { | ||
const rootDir = path.resolve(directory); | ||
|
||
try { | ||
const pkgJson = (await fs.readJson( | ||
path.join(rootDir, "package.json") | ||
)) as BoltPackageJSON; | ||
if (!pkgJson.bolt || !pkgJson.bolt.workspaces) { | ||
throw new InvalidMonorepoError( | ||
`Directory ${rootDir} is not a valid ${BoltTool.type} monorepo root: missing bolt.workspaces entry` | ||
); | ||
} | ||
const packageGlobs: string[] = pkgJson.bolt.workspaces; | ||
|
||
return { | ||
tool: BoltTool, | ||
packages: await expandPackageGlobs(packageGlobs, rootDir), | ||
rootPackage: { | ||
dir: rootDir, | ||
relativeDir: ".", | ||
packageJson: pkgJson, | ||
}, | ||
rootDir, | ||
}; | ||
} catch (err) { | ||
if (err && (err as { code: string }).code === "ENOENT") { | ||
throw new InvalidMonorepoError( | ||
`Directory ${rootDir} is not a valid ${BoltTool.type} monorepo root: missing package.json` | ||
); | ||
} | ||
throw err; | ||
} | ||
}, | ||
|
||
getPackagesSync(directory: string): Packages { | ||
const rootDir = path.resolve(directory); | ||
|
||
try { | ||
const pkgJson = fs.readJsonSync( | ||
path.join(rootDir, "package.json") | ||
) as BoltPackageJSON; | ||
if (!pkgJson.bolt || !pkgJson.bolt.workspaces) { | ||
throw new InvalidMonorepoError( | ||
`Directory ${directory} is not a valid ${BoltTool.type} monorepo root: missing bolt.workspaces entry` | ||
); | ||
} | ||
const packageGlobs: string[] = pkgJson.bolt.workspaces; | ||
|
||
return { | ||
tool: BoltTool, | ||
packages: expandPackageGlobsSync(packageGlobs, rootDir), | ||
rootPackage: { | ||
dir: rootDir, | ||
relativeDir: ".", | ||
packageJson: pkgJson, | ||
}, | ||
rootDir, | ||
}; | ||
} catch (err) { | ||
if (err && (err as { code: string }).code === "ENOENT") { | ||
throw new InvalidMonorepoError( | ||
`Directory ${rootDir} is not a valid ${BoltTool.type} monorepo root: missing package.json` | ||
); | ||
} | ||
throw err; | ||
} | ||
}, | ||
}; |
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