Skip to content

Commit 18a93cf

Browse files
authored
feat(js): ignore scoped export conditions (#32063)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> There is an emerging pattern of using scoped custom export conditions for pointing to source. See: - [Announcing TypeScript 5.7](https://devblogs.microsoft.com/typescript/announcing-typescript-5-7/#path-rewriting-for-relative-paths:~:text=As%20a%20result%2C%20if%20you%E2%80%99ve%20been%20using%20a%20workspace%2Dstyle%20layout%20with%20multiple%20packages%20referencing%20each%20other%2C%20you%20might%20need%20to%20use%20conditional%20exports%20with%20scoped%20custom%20conditions%20to%20make%20this%20work%3A) - [Live types in a TypeScript monorepo](https://colinhacks.com/essays/live-types-typescript-monorepo#:~:text=Here%27s%20how%20a%20custom%20condition%20might%20look%20in%20your%20package.json.%20There%27s%20nothing%20special%20about%20the%20string%20%22%40colinhacks/zod%22%20here!%20It%20could%20be%20anything.) - [Loading from Source](https://github.com/isaacs/tshy?tab=readme-ov-file#loading-from-source) ## Current Behavior <!-- This is the behavior we have today --> When including an export condition that points to the source code the typescript plugin does not add a build target. However, if this export condition is named `development` the build target is added. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Scoped export conditions pointing at source should not remove the build target. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. -->
1 parent 23cc746 commit 18a93cf

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • packages/js/src/plugins/typescript

packages/js/src/plugins/typescript/util.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export function isValidPackageJsonBuildConfig(
113113
return !isPathSourceFile(dotExport);
114114
} else if (typeof dotExport === 'object') {
115115
const hasMatch = Object.entries(dotExport).some(([key, value]) => {
116-
if (key === 'types' || key === 'development') return false;
116+
if (key === 'types' || key === 'development' || key.startsWith('@'))
117+
return false;
117118
return typeof value === 'string' && isPathSourceFile(value);
118119
});
119120
return !hasMatch;
@@ -193,7 +194,11 @@ export function isValidPackageJsonBuildConfig(
193194
} else if (typeof value === 'object') {
194195
return Object.entries(value).some(([currentKey, subValue]) => {
195196
// Skip types and development conditions
196-
if (currentKey === 'types' || currentKey === 'development') {
197+
if (
198+
currentKey === 'types' ||
199+
currentKey === 'development' ||
200+
currentKey.startsWith('@')
201+
) {
197202
return false;
198203
}
199204
if (typeof subValue === 'string') {

0 commit comments

Comments
 (0)