Skip to content
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(build): add ignoreConditions option to BuildOptions #501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async function _build(
dependencies: [],
devDependencies: [],
peerDependencies: [],
ignoreConditions: [],
alias: {},
replace: {},
failOnWarn: true,
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ export interface BuildOptions {
* Run different types of builds (untyped, mkdist, Rollup, copy) simultaneously.
*/
parallel: boolean;

/**
* Ignore conditions.
* If the condition is met, the build will be ignored.
*/
ignoreConditions: string[];
}

export interface BuildContext {
Expand Down
16 changes: 16 additions & 0 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export function validatePackage(
return;
}

for (const item of ctx.options.ignoreConditions || []) {
if (typeof pkg.exports === "object" && !Array.isArray(pkg.exports)) {
for (const key of Object.keys(pkg.exports)) {
const exportEntry = pkg.exports[key];
if (
exportEntry &&
typeof exportEntry === "object" &&
!Array.isArray(exportEntry) &&
exportEntry[item] !== undefined
) {
delete exportEntry[item];
}
}
}
}

const filenames = new Set(
[
...(typeof pkg.bin === "string"
Expand Down