Skip to content

Commit 2d91920

Browse files
committed
Apply source field only in development parcel builds
1 parent 038b762 commit 2d91920

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

crates/parcel-resolver/src/package_json.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ impl PackageJson {
584584
for (key, value) in target {
585585
let matches = match key {
586586
ExportsKey::Condition(key) => {
587-
*key == ExportsCondition::SOURCE
588-
|| *key == ExportsCondition::DEFAULT
589-
|| conditions.contains(*key)
587+
*key == ExportsCondition::DEFAULT || conditions.contains(*key)
590588
}
591589
ExportsKey::CustomCondition(key) => custom_conditions.iter().any(|k| k == key),
592590
_ => false,

packages/core/package-manager/src/NodePackageManager.js

+7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ import {transformSync} from '@swc/core';
3636
// Package.json fields. Must match package_json.rs.
3737
const MAIN = 1 << 0;
3838
const SOURCE = 1 << 2;
39+
const SOURCE_CONDITION = 1 << 17;
3940
const ENTRIES =
4041
MAIN |
4142
(process.env.PARCEL_BUILD_ENV !== 'production' ||
4243
process.env.PARCEL_SELF_BUILD
4344
? SOURCE
4445
: 0);
4546

47+
const CONDITIONS =
48+
process.env.PARCEL_BUILD_ENV !== 'production' || process.env.PARCEL_SELF_BUILD
49+
? SOURCE_CONDITION
50+
: 0;
51+
4652
const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
4753

4854
const IS_FILE = 1 << 0;
@@ -111,6 +117,7 @@ export class NodePackageManager implements PackageManager {
111117
},
112118
mode: 2,
113119
entries: ENTRIES,
120+
conditions: CONDITIONS,
114121
packageExports: true,
115122
moduleDirResolver:
116123
process.versions.pnp != null

packages/dev/babel-register/babel-plugin-module-translate.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function resolveSource(specifier, from) {
99
if (pkg.source) {
1010
pkg.main = pkg.source;
1111
}
12+
if (pkg.exports?.source) {
13+
pkg.main = pkg.exports.source;
14+
}
1215
}
1316
return pkg;
1417
},

packages/utils/node-resolver-core/src/Wrapper.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,9 @@ function environmentToExportsConditions(
783783
const DEVELOPMENT = 1 << 8;
784784
const PRODUCTION = 1 << 9;
785785
const REACT_SERVER = 1 << 16;
786+
const SOURCE = 1 << 17;
786787

787-
let conditions = 0;
788+
let conditions = SOURCE;
788789
if (env.isBrowser()) {
789790
conditions |= BROWSER;
790791
}

0 commit comments

Comments
 (0)