Skip to content

Commit

Permalink
Add experimental package exports config options
Browse files Browse the repository at this point in the history
Summary:
Add new experimental/unstable config options which will be used by incoming package exports support.

Changelog: **[Experimental]** Add `resolver.unstable_enablePackageExports` config option

Reviewed By: motiz88

Differential Revision: D42531005

fbshipit-source-id: a73500523a96106d1551d8796996551f32321cdd
  • Loading branch information
huntie authored and facebook-github-bot committed Jan 17, 2023
1 parent 311fd86 commit 5c6897e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ Object {
"ts",
"tsx",
],
"unstable_conditionNames": Array [
"import",
"require",
],
"unstable_conditionsByPlatform": Object {
"web": Array [
"browser",
],
},
"unstable_enablePackageExports": false,
"useWatchman": true,
},
"serializer": Object {
Expand Down Expand Up @@ -239,6 +249,16 @@ Object {
"ts",
"tsx",
],
"unstable_conditionNames": Array [
"import",
"require",
],
"unstable_conditionsByPlatform": Object {
"web": Array [
"browser",
],
},
"unstable_enablePackageExports": false,
"useWatchman": true,
},
"serializer": Object {
Expand Down Expand Up @@ -405,6 +425,16 @@ Object {
"ts",
"tsx",
],
"unstable_conditionNames": Array [
"import",
"require",
],
"unstable_conditionsByPlatform": Object {
"web": Array [
"browser",
],
},
"unstable_enablePackageExports": false,
"useWatchman": true,
},
"serializer": Object {
Expand Down Expand Up @@ -571,6 +601,16 @@ Object {
"ts",
"tsx",
],
"unstable_conditionNames": Array [
"import",
"require",
],
"unstable_conditionsByPlatform": Object {
"web": Array [
"browser",
],
},
"unstable_enablePackageExports": false,
"useWatchman": true,
},
"serializer": Object {
Expand Down
5 changes: 5 additions & 0 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ type ResolverConfigT = {
resolveRequest: ?CustomResolver,
resolverMainFields: $ReadOnlyArray<string>,
sourceExts: $ReadOnlyArray<string>,
unstable_conditionNames: $ReadOnlyArray<string>,
unstable_conditionsByPlatform: $ReadOnly<{
[platform: string]: $ReadOnlyArray<string>,
}>,
unstable_enablePackageExports: boolean,
useWatchman: boolean,
requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
};
Expand Down
5 changes: 5 additions & 0 deletions packages/metro-config/src/defaults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const getDefaultValues = (projectRoot: ?string): ConfigT => ({
nodeModulesPaths: [],
resolveRequest: null,
resolverMainFields: ['browser', 'main'],
unstable_conditionNames: ['import', 'require'],
unstable_conditionsByPlatform: {
web: ['browser'],
},
unstable_enablePackageExports: false,
useWatchman: true,
requireCycleIgnorePatterns: [/(^|\/|\\)node_modules($|\/|\\)/],
},
Expand Down
3 changes: 3 additions & 0 deletions packages/metro-resolver/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ const CONTEXT: ResolutionContext = (() => {
return null;
},
sourceExts: ['js'],
unstable_conditionNames: [],
unstable_conditionsByPlatform: {},
unstable_enablePackageExports: false,
};
})();

Expand Down
5 changes: 5 additions & 0 deletions packages/metro-resolver/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export type ResolutionContext = $ReadOnly<{
disableHierarchicalLookup: boolean,
extraNodeModules: ?{[string]: string, ...},
originModulePath: string,
unstable_conditionNames: $ReadOnlyArray<string>,
unstable_conditionsByPlatform: $ReadOnly<{
[platform: string]: $ReadOnlyArray<string>,
}>,
unstable_enablePackageExports: boolean,
resolveRequest?: ?CustomResolver,
customResolverOptions: CustomResolverOptions,
...
Expand Down
5 changes: 5 additions & 0 deletions packages/metro/src/node-haste/DependencyGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class DependencyGraph extends EventEmitter {
},
resolveRequest: this._config.resolver.resolveRequest,
sourceExts: this._config.resolver.sourceExts,
unstable_conditionNames: this._config.resolver.unstable_conditionNames,
unstable_conditionsByPlatform:
this._config.resolver.unstable_conditionsByPlatform,
unstable_enablePackageExports:
this._config.resolver.unstable_enablePackageExports,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ type Options<TPackage> = $ReadOnly<{
resolveAsset: ResolveAsset,
resolveRequest: ?CustomResolver,
sourceExts: $ReadOnlyArray<string>,
unstable_conditionNames: $ReadOnlyArray<string>,
unstable_conditionsByPlatform: $ReadOnly<{
[platform: string]: $ReadOnlyArray<string>,
}>,
unstable_enablePackageExports: boolean,
}>;

class ModuleResolver<TPackage: Packageish> {
Expand Down Expand Up @@ -187,6 +192,8 @@ class ModuleResolver<TPackage: Packageish> {
resolveHastePackage: (name: string) =>
this._options.getHastePackagePath(name, platform),
getPackageMainPath: this._getPackageMainPath,
unstable_enablePackageExports:
this._options.unstable_enablePackageExports,
},
moduleName,
platform,
Expand Down

0 comments on commit 5c6897e

Please sign in to comment.