-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support pnpm workspaces #160
Changes from all commits
2884da0
6a57f05
0c703a2
d09e52f
3a50112
3bc062c
c69d5b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"bob-the-bundler": minor | ||
--- | ||
|
||
Support pnpm workspaces from `pnpm-workspace.yaml`.. | ||
Throw an error in case both `pnpm-workspace.yaml` and `package.json#workspaces` fields exist. | ||
Add missing dependency `execa`. | ||
Cleanup and remove unused dependencies. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,24 +22,17 @@ | |
"jest-resolver.js" | ||
], | ||
"dependencies": { | ||
"@rollup/plugin-json": "^6.0.0", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@vercel/ncc": "^0.36.0", | ||
"builtins": "^5.0.1", | ||
"consola": "^2.15.3", | ||
"cross-spawn": "^7.0.3", | ||
"dependency-graph": "^0.11.0", | ||
"execa": "5.1.1", | ||
"fs-extra": "^10.1.0", | ||
"globby": "^11.0.0", | ||
"js-yaml": "^4.1.0", | ||
"lodash.get": "^4.4.2", | ||
"minimatch": "^5.1.0", | ||
"mkdirp": "^1.0.4", | ||
"p-limit": "^3.1.0", | ||
"param-case": "^3.0.4", | ||
"resolve.exports": "^1.1.0", | ||
"rollup": "^2.75.6", | ||
"rollup-plugin-generate-package-json": "^3.2.0", | ||
"rollup-plugin-typescript2": "^0.34.0", | ||
Comment on lines
-25
to
-42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems bunch of these dependencies were nowhere used |
||
"tslib": "^2.0.0", | ||
"tsup": "^6.5.0", | ||
"yargs": "^17.5.1", | ||
|
@@ -55,18 +48,17 @@ | |
}, | ||
"devDependencies": { | ||
"@actions/core": "1.9.1", | ||
"@changesets/cli": "2.24.4", | ||
"@changesets/changelog-github": "0.4.6", | ||
"@changesets/cli": "2.24.4", | ||
"@jest/types": "28.1.3", | ||
"@types/cross-spawn": "6.0.2", | ||
"@types/fs-extra": "9.0.13", | ||
"@types/jest": "28.1.8", | ||
"@types/js-yaml": "4.0.5", | ||
"@types/lodash.get": "4.4.7", | ||
"@types/minimatch": "3.0.5", | ||
"@types/mkdirp": "1.0.2", | ||
"@types/node": "16.11.58", | ||
"@types/yargs": "15.0.14", | ||
"execa": "5.1.1", | ||
"jest": "28.1.3", | ||
"rimraf": "3.0.2", | ||
"ts-jest": "28.0.8", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ interface PackageInfo { | |
} | ||
|
||
/** | ||
* A list of files that we don't need need within the published package. | ||
* A list of files that we don't need within the published package. | ||
* Also known as test files :) | ||
* This list is derived from scouting various of our repositories. | ||
*/ | ||
|
@@ -56,17 +56,14 @@ function typeScriptCompilerOptions( | |
}; | ||
} | ||
|
||
function compilerOptionsToArgs( | ||
options: Record<string, unknown> | ||
): Array<string> { | ||
const args: Array<string> = []; | ||
for (const [key, value] of Object.entries(options)) { | ||
args.push(`--${key}`, `${value}`); | ||
} | ||
return args; | ||
function compilerOptionsToArgs(options: Record<string, unknown>): string[] { | ||
return Object.entries(options).flatMap(([key, value]) => [ | ||
`--${key}`, | ||
`${value}`, | ||
]); | ||
Comment on lines
-59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just for better readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the former has better readability for me 😁 |
||
} | ||
|
||
function assertTypeScriptBuildResult(result: execa.ExecaReturnValue<string>) { | ||
function assertTypeScriptBuildResult(result: execa.ExecaReturnValue) { | ||
if (result.exitCode !== 0) { | ||
console.log("TypeScript compiler exited with non-zero exit code."); | ||
console.log(result.stdout); | ||
|
@@ -121,8 +118,8 @@ export const buildCommand = createCommand< | |
}, | ||
async handler({ incremental }) { | ||
const cwd = process.cwd(); | ||
const rootPackageJSON = await getRootPackageJSON(cwd); | ||
const workspaces = getWorkspaces(rootPackageJSON); | ||
const rootPackageJSON = await getRootPackageJSON(); | ||
const workspaces = await getWorkspaces(rootPackageJSON); | ||
const isSinglePackage = workspaces === null; | ||
|
||
if (isSinglePackage) { | ||
|
@@ -151,10 +148,7 @@ export const buildCommand = createCommand< | |
} | ||
|
||
const limit = pLimit(4); | ||
const workspacePackagePaths = await getWorkspacePackagePaths( | ||
cwd, | ||
workspaces | ||
); | ||
const workspacePackagePaths = await getWorkspacePackagePaths(workspaces); | ||
|
||
const packageInfoList: PackageInfo[] = await Promise.all( | ||
workspacePackagePaths.map((packagePath) => | ||
|
@@ -392,7 +386,7 @@ function rewritePackageJson(pkg: Record<string, any>, typesOnly: boolean) { | |
]; | ||
|
||
fields.forEach((field) => { | ||
if (typeof pkg[field] !== "undefined") { | ||
if (pkg[field] !== undefined) { | ||
newPkg[field] = pkg[field]; | ||
} | ||
}); | ||
|
@@ -461,7 +455,7 @@ export function validatePackageJson( | |
// If the package has NO binary we need to check the exports map. | ||
// a package should either | ||
// 1. have a bin property | ||
// 2. have a exports property | ||
// 2. have an exports property | ||
// 3. have an exports and bin property | ||
if (Object.keys(pkg.bin ?? {}).length > 0) { | ||
if (opts.includesCommonJS === true) { | ||
|
@@ -499,7 +493,7 @@ export function validatePackageJson( | |
expect("typings", presetFieldsESM.typings); | ||
expect("typescript.definition", presetFieldsESM.typescript.definition); | ||
|
||
// For now we enforce a top level exports property | ||
// For now, we enforce a top level exports property | ||
expect("exports['.']", presetFieldsESM.exports["."]); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
declare module 'rollup-plugin-generate-package-json'; | ||
declare module 'rollup-plugin-auto-external'; | ||
declare module 'builtins'; | ||
Comment on lines
-1
to
-3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does I was right that they are unused? |
||
declare module '@vercel/ncc'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import path from "node:path"; | ||
import zod from "zod"; | ||
import fse from "fs-extra"; | ||
import jsYaml from "js-yaml"; | ||
|
||
const WorkspaceModel = zod.optional( | ||
zod.union([ | ||
|
@@ -10,10 +13,25 @@ const WorkspaceModel = zod.optional( | |
]) | ||
); | ||
|
||
export function getWorkspaces( | ||
export async function getWorkspaces( | ||
packageJSON: Record<string, unknown> | ||
): Array<string> | null { | ||
const result = WorkspaceModel.parse(packageJSON.workspaces); | ||
): Promise<string[] | null> { | ||
let result = WorkspaceModel.parse(packageJSON.workspaces); | ||
|
||
const pnpmWorkspacePath = path.join(process.cwd(), "pnpm-workspace.yaml"); | ||
const isPnpmWorkspace = await fse.pathExists(pnpmWorkspacePath); | ||
|
||
if (isPnpmWorkspace) { | ||
if (result) { | ||
throw new Error( | ||
"Both `pnpm-workspace.yaml` and `package.json#workspaces` are not supported. Remove `package.json#workspaces` field." | ||
); | ||
} | ||
|
||
result = jsYaml.load(await fse.readFile(pnpmWorkspacePath, "utf8")) as { | ||
packages?: string[]; | ||
}; | ||
} | ||
Comment on lines
+21
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here magic happens and I think it is better place to validate it in |
||
if (result == null) { | ||
return null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execa
imported and should be present in dependencies