@react-native-community/cli-config 15.0.1 → 15.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default } from './loadConfig';
2
+ export { loadConfigAsync } from './loadConfig';
2
3
  export declare const commands: {
3
4
  name: string;
4
5
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,eAAO,MAAM,QAAQ;;;;;;;;GAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7C,eAAO,MAAM,QAAQ;;;;;;;;GAAW,CAAC"}
package/build/index.js CHANGED
@@ -10,8 +10,16 @@ Object.defineProperty(exports, "default", {
10
10
  return _loadConfig.default;
11
11
  }
12
12
  });
13
+ Object.defineProperty(exports, "loadConfigAsync", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _loadConfig.loadConfigAsync;
17
+ }
18
+ });
13
19
  var _config = _interopRequireDefault(require("./commands/config"));
14
- var _loadConfig = _interopRequireDefault(require("./loadConfig"));
20
+ var _loadConfig = _interopRequireWildcard(require("./loadConfig"));
21
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
24
  const commands = [_config.default];
17
25
  exports.commands = commands;
@@ -1 +1 @@
1
- {"version":3,"names":["commands","config"],"sources":["../src/index.ts"],"sourcesContent":["import config from './commands/config';\n\nexport {default} from './loadConfig';\n\nexport const commands = [config];\n"],"mappings":";;;;;;;;;;;;AAAA;AAEA;AAAqC;AAE9B,MAAMA,QAAQ,GAAG,CAACC,eAAM,CAAC;AAAC"}
1
+ {"version":3,"names":["commands","config"],"sources":["../src/index.ts"],"sourcesContent":["import config from './commands/config';\n\nexport {default} from './loadConfig';\nexport {loadConfigAsync} from './loadConfig';\n\nexport const commands = [config];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAEA;AAAqC;AAAA;AAAA;AAG9B,MAAMA,QAAQ,GAAG,CAACC,eAAM,CAAC;AAAC"}
@@ -2,9 +2,15 @@ import { Config } from '@react-native-community/cli-types';
2
2
  /**
3
3
  * Loads CLI configuration
4
4
  */
5
- declare function loadConfig({ projectRoot, selectedPlatform, }: {
5
+ export default function loadConfig({ projectRoot, selectedPlatform, }: {
6
6
  projectRoot?: string;
7
7
  selectedPlatform?: string;
8
8
  }): Config;
9
- export default loadConfig;
9
+ /**
10
+ * Load CLI configuration asynchronously, which supports reading ESM modules.
11
+ */
12
+ export declare function loadConfigAsync({ projectRoot, selectedPlatform, }: {
13
+ projectRoot?: string;
14
+ selectedPlatform?: string;
15
+ }): Promise<Config>;
10
16
  //# sourceMappingURL=loadConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../src/loadConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,MAAM,EAEP,MAAM,mCAAmC,CAAC;AA4E3C;;GAEG;AACH,iBAAS,UAAU,CAAC,EAClB,WAA+B,EAC/B,gBAAgB,GACjB,EAAE;IACD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,CAoFT;AAED,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../src/loadConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,MAAM,EAEP,MAAM,mCAAmC,CAAC;AA8E3C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,WAA+B,EAC/B,gBAAgB,GACjB,EAAE;IACD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,CAoFT;AAED;;GAEG;AAEH,wBAAsB,eAAe,CAAC,EACpC,WAA+B,EAC/B,gBAAgB,GACjB,EAAE;IACD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,OAAO,CAAC,MAAM,CAAC,CAwFlB"}
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = loadConfig;
7
+ exports.loadConfigAsync = loadConfigAsync;
7
8
  function _path() {
8
9
  const data = _interopRequireDefault(require("path"));
9
10
  _path = function () {
@@ -127,7 +128,70 @@ function loadConfig({
127
128
  }, initialConfig);
128
129
  return finalConfig;
129
130
  }
130
- var _default = loadConfig;
131
- exports.default = _default;
131
+
132
+ /**
133
+ * Load CLI configuration asynchronously, which supports reading ESM modules.
134
+ */
135
+
136
+ async function loadConfigAsync({
137
+ projectRoot = (0, _cliTools().findProjectRoot)(),
138
+ selectedPlatform
139
+ }) {
140
+ let lazyProject;
141
+ const userConfig = await (0, _readConfigFromDisk.readConfigFromDiskAsync)(projectRoot);
142
+ const initialConfig = {
143
+ root: projectRoot,
144
+ get reactNativePath() {
145
+ return userConfig.reactNativePath ? _path().default.resolve(projectRoot, userConfig.reactNativePath) : (0, _resolveReactNativePath.default)(projectRoot);
146
+ },
147
+ get reactNativeVersion() {
148
+ return getReactNativeVersion(initialConfig.reactNativePath);
149
+ },
150
+ dependencies: userConfig.dependencies,
151
+ commands: userConfig.commands,
152
+ healthChecks: userConfig.healthChecks || [],
153
+ platforms: userConfig.platforms,
154
+ assets: userConfig.assets,
155
+ get project() {
156
+ if (lazyProject) {
157
+ return lazyProject;
158
+ }
159
+ lazyProject = {};
160
+ for (const platform in finalConfig.platforms) {
161
+ const platformConfig = finalConfig.platforms[platform];
162
+ if (platformConfig) {
163
+ lazyProject[platform] = platformConfig.projectConfig(projectRoot, userConfig.project[platform] || {});
164
+ }
165
+ }
166
+ return lazyProject;
167
+ }
168
+ };
169
+ const finalConfig = await Array.from(new Set([...Object.keys(userConfig.dependencies), ...(0, _findDependencies.default)(projectRoot)])).reduce(async (accPromise, dependencyName) => {
170
+ const acc = await accPromise;
171
+ const localDependencyRoot = userConfig.dependencies[dependencyName] && userConfig.dependencies[dependencyName].root;
172
+ try {
173
+ let root = localDependencyRoot || (0, _cliTools().resolveNodeModuleDir)(projectRoot, dependencyName);
174
+ let config = await (0, _readConfigFromDisk.readDependencyConfigFromDiskAsync)(root, dependencyName);
175
+ return (0, _assign.default)({}, acc, {
176
+ dependencies: (0, _assign.default)({}, acc.dependencies, {
177
+ get [dependencyName]() {
178
+ return getDependencyConfig(root, dependencyName, finalConfig, config, userConfig);
179
+ }
180
+ }),
181
+ commands: removeDuplicateCommands([...config.commands, ...acc.commands]),
182
+ platforms: {
183
+ ...acc.platforms,
184
+ ...(selectedPlatform && config.platforms[selectedPlatform] ? {
185
+ [selectedPlatform]: config.platforms[selectedPlatform]
186
+ } : config.platforms)
187
+ },
188
+ healthChecks: [...acc.healthChecks, ...config.healthChecks]
189
+ });
190
+ } catch {
191
+ return acc;
192
+ }
193
+ }, Promise.resolve(initialConfig));
194
+ return finalConfig;
195
+ }
132
196
 
133
197
  //# sourceMappingURL=/Users/thymikee/Developer/oss/rncli/packages/cli-config/build/loadConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getDependencyConfig","root","dependencyName","finalConfig","config","userConfig","merge","name","platforms","Object","keys","reduce","dependency","platform","platformConfig","length","dependencyConfig","dependencies","getReactNativeVersion","reactNativePath","semver","version","current","major","minor","e","UnknownProjectError","removeDuplicateCommands","commands","uniqueCommandsMap","Map","forEach","command","set","Array","from","values","loadConfig","projectRoot","findProjectRoot","selectedPlatform","lazyProject","readConfigFromDisk","initialConfig","path","resolve","resolveReactNativePath","reactNativeVersion","healthChecks","assets","project","projectConfig","Set","findDependencies","acc","localDependencyRoot","resolveNodeModuleDir","readDependencyConfigFromDisk","assign"],"sources":["../src/loadConfig.ts"],"sourcesContent":["import path from 'path';\nimport {\n UserDependencyConfig,\n ProjectConfig,\n DependencyConfig,\n UserConfig,\n Config,\n Command,\n} from '@react-native-community/cli-types';\nimport {\n findProjectRoot,\n version,\n resolveNodeModuleDir,\n UnknownProjectError,\n} from '@react-native-community/cli-tools';\nimport findDependencies from './findDependencies';\nimport resolveReactNativePath from './resolveReactNativePath';\nimport {\n readConfigFromDisk,\n readDependencyConfigFromDisk,\n} from './readConfigFromDisk';\nimport assign from './assign';\nimport merge from './merge';\n\nfunction getDependencyConfig(\n root: string,\n dependencyName: string,\n finalConfig: Config,\n config: UserDependencyConfig,\n userConfig: UserConfig,\n): DependencyConfig {\n return merge(\n {\n root,\n name: dependencyName,\n platforms: Object.keys(finalConfig.platforms).reduce(\n (dependency, platform) => {\n const platformConfig = finalConfig.platforms[platform];\n dependency[platform] =\n // Linking platforms is not supported\n Object.keys(config.platforms).length > 0 || !platformConfig\n ? null\n : platformConfig.dependencyConfig(\n root,\n config.dependency.platforms?.[platform],\n );\n return dependency;\n },\n {} as Config['platforms'],\n ),\n },\n userConfig.dependencies[dependencyName] || {},\n ) as DependencyConfig;\n}\n\n// Try our best to figure out what version of React Native we're running. This is\n// currently being used to get our deeplinks working, so it's only worried with\n// the major and minor version.\nfunction getReactNativeVersion(reactNativePath: string) {\n try {\n let semver = version.current(reactNativePath);\n if (semver) {\n // Retain only these version, since they correspond with our documentation.\n return `${semver.major}.${semver.minor}`;\n }\n } catch (e) {\n // If we don't seem to be in a well formed project, give up quietly.\n if (!(e instanceof UnknownProjectError)) {\n throw e;\n }\n }\n return 'unknown';\n}\n\nconst removeDuplicateCommands = <T extends boolean>(commands: Command<T>[]) => {\n const uniqueCommandsMap = new Map();\n\n commands.forEach((command) => {\n uniqueCommandsMap.set(command.name, command);\n });\n\n return Array.from(uniqueCommandsMap.values());\n};\n\n/**\n * Loads CLI configuration\n */\nfunction loadConfig({\n projectRoot = findProjectRoot(),\n selectedPlatform,\n}: {\n projectRoot?: string;\n selectedPlatform?: string;\n}): Config {\n let lazyProject: ProjectConfig;\n const userConfig = readConfigFromDisk(projectRoot);\n\n const initialConfig: Config = {\n root: projectRoot,\n get reactNativePath() {\n return userConfig.reactNativePath\n ? path.resolve(projectRoot, userConfig.reactNativePath)\n : resolveReactNativePath(projectRoot);\n },\n get reactNativeVersion() {\n return getReactNativeVersion(initialConfig.reactNativePath);\n },\n dependencies: userConfig.dependencies,\n commands: userConfig.commands,\n healthChecks: userConfig.healthChecks || [],\n platforms: userConfig.platforms,\n assets: userConfig.assets,\n get project() {\n if (lazyProject) {\n return lazyProject;\n }\n\n lazyProject = {};\n for (const platform in finalConfig.platforms) {\n const platformConfig = finalConfig.platforms[platform];\n if (platformConfig) {\n lazyProject[platform] = platformConfig.projectConfig(\n projectRoot,\n userConfig.project[platform] || {},\n );\n }\n }\n\n return lazyProject;\n },\n };\n\n const finalConfig = Array.from(\n new Set([\n ...Object.keys(userConfig.dependencies),\n ...findDependencies(projectRoot),\n ]),\n ).reduce((acc: Config, dependencyName) => {\n const localDependencyRoot =\n userConfig.dependencies[dependencyName] &&\n userConfig.dependencies[dependencyName].root;\n try {\n let root =\n localDependencyRoot ||\n resolveNodeModuleDir(projectRoot, dependencyName);\n let config = readDependencyConfigFromDisk(root, dependencyName);\n\n return assign({}, acc, {\n dependencies: assign({}, acc.dependencies, {\n get [dependencyName](): DependencyConfig {\n return getDependencyConfig(\n root,\n dependencyName,\n finalConfig,\n config,\n userConfig,\n );\n },\n }),\n commands: removeDuplicateCommands([\n ...config.commands,\n ...acc.commands,\n ]),\n platforms: {\n ...acc.platforms,\n ...(selectedPlatform && config.platforms[selectedPlatform]\n ? {[selectedPlatform]: config.platforms[selectedPlatform]}\n : config.platforms),\n },\n healthChecks: [...acc.healthChecks, ...config.healthChecks],\n }) as Config;\n } catch {\n return acc;\n }\n }, initialConfig);\n\n return finalConfig;\n}\n\nexport default loadConfig;\n"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;AACA;AACA;AAIA;AACA;AAA4B;AAE5B,SAASA,mBAAmB,CAC1BC,IAAY,EACZC,cAAsB,EACtBC,WAAmB,EACnBC,MAA4B,EAC5BC,UAAsB,EACJ;EAClB,OAAO,IAAAC,cAAK,EACV;IACEL,IAAI;IACJM,IAAI,EAAEL,cAAc;IACpBM,SAAS,EAAEC,MAAM,CAACC,IAAI,CAACP,WAAW,CAACK,SAAS,CAAC,CAACG,MAAM,CAClD,CAACC,UAAU,EAAEC,QAAQ,KAAK;MAAA;MACxB,MAAMC,cAAc,GAAGX,WAAW,CAACK,SAAS,CAACK,QAAQ,CAAC;MACtDD,UAAU,CAACC,QAAQ,CAAC;MAClB;MACAJ,MAAM,CAACC,IAAI,CAACN,MAAM,CAAC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config","userConfig","merge","name","platforms","Object","keys","reduce","dependency","platform","platformConfig","length","dependencyConfig","dependencies","getReactNativeVersion","reactNativePath","semver","version","current","major","minor","e","UnknownProjectError","removeDuplicateCommands","commands","uniqueCommandsMap","Map","forEach","command","set","Array","from","values","loadConfig","projectRoot","findProjectRoot","selectedPlatform","lazyProject","readConfigFromDisk","initialConfig","path","resolve","resolveReactNativePath","reactNativeVersion","healthChecks","assets","project","projectConfig","Set","findDependencies","acc","localDependencyRoot","resolveNodeModuleDir","readDependencyConfigFromDisk","assign","loadConfigAsync","readConfigFromDiskAsync","accPromise","readDependencyConfigFromDiskAsync","Promise"],"sources":["../src/loadConfig.ts"],"sourcesContent":["import path from 'path';\nimport {\n UserDependencyConfig,\n ProjectConfig,\n DependencyConfig,\n UserConfig,\n Config,\n Command,\n} from '@react-native-community/cli-types';\nimport {\n findProjectRoot,\n version,\n resolveNodeModuleDir,\n UnknownProjectError,\n} from '@react-native-community/cli-tools';\nimport findDependencies from './findDependencies';\nimport resolveReactNativePath from './resolveReactNativePath';\nimport {\n readConfigFromDisk,\n readConfigFromDiskAsync,\n readDependencyConfigFromDisk,\n readDependencyConfigFromDiskAsync,\n} from './readConfigFromDisk';\nimport assign from './assign';\nimport merge from './merge';\n\nfunction getDependencyConfig(\n root: string,\n dependencyName: string,\n finalConfig: Config,\n config: UserDependencyConfig,\n userConfig: UserConfig,\n): DependencyConfig {\n return merge(\n {\n root,\n name: dependencyName,\n platforms: Object.keys(finalConfig.platforms).reduce(\n (dependency, platform) => {\n const platformConfig = finalConfig.platforms[platform];\n dependency[platform] =\n // Linking platforms is not supported\n Object.keys(config.platforms).length > 0 || !platformConfig\n ? null\n : platformConfig.dependencyConfig(\n root,\n config.dependency.platforms?.[platform],\n );\n return dependency;\n },\n {} as Config['platforms'],\n ),\n },\n userConfig.dependencies[dependencyName] || {},\n ) as DependencyConfig;\n}\n\n// Try our best to figure out what version of React Native we're running. This is\n// currently being used to get our deeplinks working, so it's only worried with\n// the major and minor version.\nfunction getReactNativeVersion(reactNativePath: string) {\n try {\n let semver = version.current(reactNativePath);\n if (semver) {\n // Retain only these version, since they correspond with our documentation.\n return `${semver.major}.${semver.minor}`;\n }\n } catch (e) {\n // If we don't seem to be in a well formed project, give up quietly.\n if (!(e instanceof UnknownProjectError)) {\n throw e;\n }\n }\n return 'unknown';\n}\n\nconst removeDuplicateCommands = <T extends boolean>(commands: Command<T>[]) => {\n const uniqueCommandsMap = new Map();\n\n commands.forEach((command) => {\n uniqueCommandsMap.set(command.name, command);\n });\n\n return Array.from(uniqueCommandsMap.values());\n};\n\n/**\n * Loads CLI configuration\n */\nexport default function loadConfig({\n projectRoot = findProjectRoot(),\n selectedPlatform,\n}: {\n projectRoot?: string;\n selectedPlatform?: string;\n}): Config {\n let lazyProject: ProjectConfig;\n const userConfig = readConfigFromDisk(projectRoot);\n\n const initialConfig: Config = {\n root: projectRoot,\n get reactNativePath() {\n return userConfig.reactNativePath\n ? path.resolve(projectRoot, userConfig.reactNativePath)\n : resolveReactNativePath(projectRoot);\n },\n get reactNativeVersion() {\n return getReactNativeVersion(initialConfig.reactNativePath);\n },\n dependencies: userConfig.dependencies,\n commands: userConfig.commands,\n healthChecks: userConfig.healthChecks || [],\n platforms: userConfig.platforms,\n assets: userConfig.assets,\n get project() {\n if (lazyProject) {\n return lazyProject;\n }\n\n lazyProject = {};\n for (const platform in finalConfig.platforms) {\n const platformConfig = finalConfig.platforms[platform];\n if (platformConfig) {\n lazyProject[platform] = platformConfig.projectConfig(\n projectRoot,\n userConfig.project[platform] || {},\n );\n }\n }\n\n return lazyProject;\n },\n };\n\n const finalConfig = Array.from(\n new Set([\n ...Object.keys(userConfig.dependencies),\n ...findDependencies(projectRoot),\n ]),\n ).reduce((acc: Config, dependencyName) => {\n const localDependencyRoot =\n userConfig.dependencies[dependencyName] &&\n userConfig.dependencies[dependencyName].root;\n try {\n let root =\n localDependencyRoot ||\n resolveNodeModuleDir(projectRoot, dependencyName);\n let config = readDependencyConfigFromDisk(root, dependencyName);\n\n return assign({}, acc, {\n dependencies: assign({}, acc.dependencies, {\n get [dependencyName](): DependencyConfig {\n return getDependencyConfig(\n root,\n dependencyName,\n finalConfig,\n config,\n userConfig,\n );\n },\n }),\n commands: removeDuplicateCommands([\n ...config.commands,\n ...acc.commands,\n ]),\n platforms: {\n ...acc.platforms,\n ...(selectedPlatform && config.platforms[selectedPlatform]\n ? {[selectedPlatform]: config.platforms[selectedPlatform]}\n : config.platforms),\n },\n healthChecks: [...acc.healthChecks, ...config.healthChecks],\n }) as Config;\n } catch {\n return acc;\n }\n }, initialConfig);\n\n return finalConfig;\n}\n\n/**\n * Load CLI configuration asynchronously, which supports reading ESM modules.\n */\n\nexport async function loadConfigAsync({\n projectRoot = findProjectRoot(),\n selectedPlatform,\n}: {\n projectRoot?: string;\n selectedPlatform?: string;\n}): Promise<Config> {\n let lazyProject: ProjectConfig;\n const userConfig = await readConfigFromDiskAsync(projectRoot);\n\n const initialConfig: Config = {\n root: projectRoot,\n get reactNativePath() {\n return userConfig.reactNativePath\n ? path.resolve(projectRoot, userConfig.reactNativePath)\n : resolveReactNativePath(projectRoot);\n },\n get reactNativeVersion() {\n return getReactNativeVersion(initialConfig.reactNativePath);\n },\n dependencies: userConfig.dependencies,\n commands: userConfig.commands,\n healthChecks: userConfig.healthChecks || [],\n platforms: userConfig.platforms,\n assets: userConfig.assets,\n get project() {\n if (lazyProject) {\n return lazyProject;\n }\n\n lazyProject = {};\n for (const platform in finalConfig.platforms) {\n const platformConfig = finalConfig.platforms[platform];\n if (platformConfig) {\n lazyProject[platform] = platformConfig.projectConfig(\n projectRoot,\n userConfig.project[platform] || {},\n );\n }\n }\n\n return lazyProject;\n },\n };\n\n const finalConfig = await Array.from(\n new Set([\n ...Object.keys(userConfig.dependencies),\n ...findDependencies(projectRoot),\n ]),\n ).reduce(async (accPromise: Promise<Config>, dependencyName) => {\n const acc = await accPromise;\n const localDependencyRoot =\n userConfig.dependencies[dependencyName] &&\n userConfig.dependencies[dependencyName].root;\n try {\n let root =\n localDependencyRoot ||\n resolveNodeModuleDir(projectRoot, dependencyName);\n let config = await readDependencyConfigFromDiskAsync(\n root,\n dependencyName,\n );\n\n return assign({}, acc, {\n dependencies: assign({}, acc.dependencies, {\n get [dependencyName](): DependencyConfig {\n return getDependencyConfig(\n root,\n dependencyName,\n finalConfig,\n config,\n userConfig,\n );\n },\n }),\n commands: removeDuplicateCommands([\n ...config.commands,\n ...acc.commands,\n ]),\n platforms: {\n ...acc.platforms,\n ...(selectedPlatform && config.platforms[selectedPlatform]\n ? {[selectedPlatform]: config.platforms[selectedPlatform]}\n : config.platforms),\n },\n healthChecks: [...acc.healthChecks, ...config.healthChecks],\n }) as Config;\n } catch {\n return acc;\n }\n }, Promise.resolve(initialConfig));\n\n return finalConfig;\n}\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;AACA;AACA;AAMA;AACA;AAA4B;AAE5B,SAASA,mBAAmB,CAC1BC,IAAY,EACZC,cAAsB,EACtBC,WAAmB,EACnBC,MAA4B,EAC5BC,UAAsB,EACJ;EAClB,OAAO,IAAAC,cAAK,EACV;IACEL,IAAI;IACJM,IAAI,EAAEL,cAAc;IACpBM,SAAS,EAAEC,MAAM,CAACC,IAAI,CAACP,WAAW,CAACK,SAAS,CAAC,CAACG,MAAM,CAClD,CAACC,UAAU,EAAEC,QAAQ,KAAK;MAAA;MACxB,MAAMC,cAAc,GAAGX,WAAW,CAACK,SAAS,CAACK,QAAQ,CAAC;MACtDD,UAAU,CAACC,QAAQ,CAAC;MAClB;MACAJ,MAAM,CAACC,IAAI,CAACN,MAAM,CAACI,SAAS,CAAC,CAACO,MAAM,GAAG,CAAC,IAAI,CAACD,cAAc,GACvD,IAAI,GACJA,cAAc,CAACE,gBAAgB,CAC7Bf,IAAI,2BACJG,MAAM,CAACQ,UAAU,CAACJ,SAAS,0DAA3B,sB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ACpB"}
@@ -3,10 +3,20 @@ import { UserConfig, UserDependencyConfig } from '@react-native-community/cli-ty
3
3
  * Reads a project configuration as defined by the user in the current
4
4
  * workspace.
5
5
  */
6
+ export declare function readConfigFromDiskAsync(rootFolder: string): Promise<UserConfig>;
7
+ /**
8
+ * Reads a project configuration as defined by the user in the current
9
+ * workspace synchronously.
10
+ */
6
11
  export declare function readConfigFromDisk(rootFolder: string): UserConfig;
7
12
  /**
8
13
  * Reads a dependency configuration as defined by the developer
9
14
  * inside `node_modules`.
10
15
  */
16
+ export declare function readDependencyConfigFromDiskAsync(rootFolder: string, dependencyName: string): Promise<UserDependencyConfig>;
17
+ /**
18
+ * Reads a dependency configuration as defined by the developer
19
+ * inside `node_modules` synchronously.
20
+ */
11
21
  export declare function readDependencyConfigFromDisk(rootFolder: string, dependencyName: string): UserDependencyConfig;
12
22
  //# sourceMappingURL=readConfigFromDisk.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"readConfigFromDisk.d.ts","sourceRoot":"","sources":["../src/readConfigFromDisk.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,oBAAoB,EACrB,MAAM,mCAAmC,CAAC;AAS3C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAejE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,GACrB,oBAAoB,CA0BtB"}
1
+ {"version":3,"file":"readConfigFromDisk.d.ts","sourceRoot":"","sources":["../src/readConfigFromDisk.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,oBAAoB,EACrB,MAAM,mCAAmC,CAAC;AAe3C;;;GAGG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CAgBrB;AAED;;;GAGG;AAEH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAgBjE;AAED;;;GAGG;AACH,wBAAsB,iCAAiC,CACrD,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,oBAAoB,CAAC,CA0B/B;AAED;;;GAGG;AAEH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,GACrB,oBAAoB,CA0BtB"}
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.readConfigFromDisk = readConfigFromDisk;
7
+ exports.readConfigFromDiskAsync = readConfigFromDiskAsync;
7
8
  exports.readDependencyConfigFromDisk = readDependencyConfigFromDisk;
9
+ exports.readDependencyConfigFromDiskAsync = readDependencyConfigFromDiskAsync;
8
10
  function _cosmiconfig() {
9
11
  const data = require("cosmiconfig");
10
12
  _cosmiconfig = function () {
@@ -34,12 +36,31 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
34
36
  /**
35
37
  * Places to look for the configuration file.
36
38
  */
37
- const searchPlaces = ['react-native.config.js', 'react-native.config.ts'];
39
+ const searchPlaces = ['react-native.config.js', 'react-native.config.cjs', 'react-native.config.mjs', 'react-native.config.ts', 'react-native.config.mjs'];
38
40
 
39
41
  /**
40
42
  * Reads a project configuration as defined by the user in the current
41
43
  * workspace.
42
44
  */
45
+ async function readConfigFromDiskAsync(rootFolder) {
46
+ const explorer = (0, _cosmiconfig().cosmiconfig)('react-native', {
47
+ stopDir: rootFolder,
48
+ searchPlaces
49
+ });
50
+ const searchResult = await explorer.search(rootFolder);
51
+ const config = searchResult ? searchResult.config : undefined;
52
+ const result = schema.projectConfig.validate(config);
53
+ if (result.error) {
54
+ throw new _errors.JoiError(result.error);
55
+ }
56
+ return result.value;
57
+ }
58
+
59
+ /**
60
+ * Reads a project configuration as defined by the user in the current
61
+ * workspace synchronously.
62
+ */
63
+
43
64
  function readConfigFromDisk(rootFolder) {
44
65
  const explorer = (0, _cosmiconfig().cosmiconfigSync)('react-native', {
45
66
  stopDir: rootFolder,
@@ -58,6 +79,31 @@ function readConfigFromDisk(rootFolder) {
58
79
  * Reads a dependency configuration as defined by the developer
59
80
  * inside `node_modules`.
60
81
  */
82
+ async function readDependencyConfigFromDiskAsync(rootFolder, dependencyName) {
83
+ const explorer = (0, _cosmiconfig().cosmiconfig)('react-native', {
84
+ stopDir: rootFolder,
85
+ searchPlaces
86
+ });
87
+ const searchResult = await explorer.search(rootFolder);
88
+ const config = searchResult ? searchResult.config : emptyDependencyConfig;
89
+ const result = schema.dependencyConfig.validate(config, {
90
+ abortEarly: false
91
+ });
92
+ if (result.error) {
93
+ const validationError = new _errors.JoiError(result.error);
94
+ _cliTools().logger.warn((0, _cliTools().inlineString)(`
95
+ Package ${_chalk().default.bold(dependencyName)} contains invalid configuration: ${_chalk().default.bold(validationError.message)}.
96
+
97
+ Please verify it's properly linked using "npx react-native config" command and contact the package maintainers about this.`));
98
+ }
99
+ return result.value;
100
+ }
101
+
102
+ /**
103
+ * Reads a dependency configuration as defined by the developer
104
+ * inside `node_modules` synchronously.
105
+ */
106
+
61
107
  function readDependencyConfigFromDisk(rootFolder, dependencyName) {
62
108
  const explorer = (0, _cosmiconfig().cosmiconfigSync)('react-native', {
63
109
  stopDir: rootFolder,
@@ -1 +1 @@
1
- {"version":3,"names":["searchPlaces","readConfigFromDisk","rootFolder","explorer","cosmiconfigSync","stopDir","searchResult","search","config","undefined","result","schema","projectConfig","validate","error","JoiError","value","readDependencyConfigFromDisk","dependencyName","emptyDependencyConfig","dependencyConfig","abortEarly","validationError","logger","warn","inlineString","chalk","bold","message","dependency","platforms","commands"],"sources":["../src/readConfigFromDisk.ts"],"sourcesContent":["import {cosmiconfigSync} from 'cosmiconfig';\nimport {JoiError} from './errors';\nimport * as schema from './schema';\nimport {\n UserConfig,\n UserDependencyConfig,\n} from '@react-native-community/cli-types';\nimport {logger, inlineString} from '@react-native-community/cli-tools';\nimport chalk from 'chalk';\n\n/**\n * Places to look for the configuration file.\n */\nconst searchPlaces = ['react-native.config.js', 'react-native.config.ts'];\n\n/**\n * Reads a project configuration as defined by the user in the current\n * workspace.\n */\nexport function readConfigFromDisk(rootFolder: string): UserConfig {\n const explorer = cosmiconfigSync('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = explorer.search(rootFolder);\n const config = searchResult ? searchResult.config : undefined;\n const result = schema.projectConfig.validate(config);\n\n if (result.error) {\n throw new JoiError(result.error);\n }\n\n return result.value as UserConfig;\n}\n\n/**\n * Reads a dependency configuration as defined by the developer\n * inside `node_modules`.\n */\nexport function readDependencyConfigFromDisk(\n rootFolder: string,\n dependencyName: string,\n): UserDependencyConfig {\n const explorer = cosmiconfigSync('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = explorer.search(rootFolder);\n const config = searchResult ? searchResult.config : emptyDependencyConfig;\n\n const result = schema.dependencyConfig.validate(config, {abortEarly: false});\n\n if (result.error) {\n const validationError = new JoiError(result.error);\n logger.warn(\n inlineString(`\n Package ${chalk.bold(\n dependencyName,\n )} contains invalid configuration: ${chalk.bold(\n validationError.message,\n )}.\n \n Please verify it's properly linked using \"npx react-native config\" command and contact the package maintainers about this.`),\n );\n }\n\n return result.value as UserDependencyConfig;\n}\n\nconst emptyDependencyConfig = {\n dependency: {\n platforms: {},\n },\n commands: [],\n platforms: {},\n};\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA0B;AAAA;AAAA;AAE1B;AACA;AACA;AACA,MAAMA,YAAY,GAAG,CAAC,wBAAwB,EAAE,wBAAwB,CAAC;;AAEzE;AACA;AACA;AACA;AACO,SAASC,kBAAkB,CAACC,UAAkB,EAAc;EACjE,MAAMC,QAAQ,GAAG,IAAAC,8BAAe,EAAC,cAAc,EAAE;IAC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AAU,EAAE;IACVC,SAAS,EAAE,CAAC;EACd,CAAC;EACDC,QAAQ,EAAE,EAAE;EACZD,SAAS,EAAE,CAAC;AACd,CAAC"}
1
+ {"version":3,"names":["searchPlaces","readConfigFromDiskAsync","rootFolder","explorer","cosmiconfig","stopDir","searchResult","search","config","undefined","result","schema","projectConfig","validate","error","JoiError","value","readConfigFromDisk","cosmiconfigSync","readDependencyConfigFromDiskAsync","dependencyName","emptyDependencyConfig","dependencyConfig","abortEarly","validationError","logger","warn","inlineString","chalk","bold","message","readDependencyConfigFromDisk","dependency","platforms","commands"],"sources":["../src/readConfigFromDisk.ts"],"sourcesContent":["import {cosmiconfig, cosmiconfigSync} from 'cosmiconfig';\nimport {JoiError} from './errors';\nimport * as schema from './schema';\nimport {\n UserConfig,\n UserDependencyConfig,\n} from '@react-native-community/cli-types';\nimport {logger, inlineString} from '@react-native-community/cli-tools';\nimport chalk from 'chalk';\n\n/**\n * Places to look for the configuration file.\n */\nconst searchPlaces = [\n 'react-native.config.js',\n 'react-native.config.cjs',\n 'react-native.config.mjs',\n 'react-native.config.ts',\n 'react-native.config.mjs',\n];\n\n/**\n * Reads a project configuration as defined by the user in the current\n * workspace.\n */\nexport async function readConfigFromDiskAsync(\n rootFolder: string,\n): Promise<UserConfig> {\n const explorer = cosmiconfig('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = await explorer.search(rootFolder);\n\n const config = searchResult ? searchResult.config : undefined;\n const result = schema.projectConfig.validate(config);\n\n if (result.error) {\n throw new JoiError(result.error);\n }\n\n return result.value as UserConfig;\n}\n\n/**\n * Reads a project configuration as defined by the user in the current\n * workspace synchronously.\n */\n\nexport function readConfigFromDisk(rootFolder: string): UserConfig {\n const explorer = cosmiconfigSync('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = explorer.search(rootFolder);\n\n const config = searchResult ? searchResult.config : undefined;\n const result = schema.projectConfig.validate(config);\n\n if (result.error) {\n throw new JoiError(result.error);\n }\n\n return result.value as UserConfig;\n}\n\n/**\n * Reads a dependency configuration as defined by the developer\n * inside `node_modules`.\n */\nexport async function readDependencyConfigFromDiskAsync(\n rootFolder: string,\n dependencyName: string,\n): Promise<UserDependencyConfig> {\n const explorer = cosmiconfig('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = await explorer.search(rootFolder);\n const config = searchResult ? searchResult.config : emptyDependencyConfig;\n\n const result = schema.dependencyConfig.validate(config, {abortEarly: false});\n\n if (result.error) {\n const validationError = new JoiError(result.error);\n logger.warn(\n inlineString(`\n Package ${chalk.bold(\n dependencyName,\n )} contains invalid configuration: ${chalk.bold(\n validationError.message,\n )}.\n \n Please verify it's properly linked using \"npx react-native config\" command and contact the package maintainers about this.`),\n );\n }\n\n return result.value as UserDependencyConfig;\n}\n\n/**\n * Reads a dependency configuration as defined by the developer\n * inside `node_modules` synchronously.\n */\n\nexport function readDependencyConfigFromDisk(\n rootFolder: string,\n dependencyName: string,\n): UserDependencyConfig {\n const explorer = cosmiconfigSync('react-native', {\n stopDir: rootFolder,\n searchPlaces,\n });\n\n const searchResult = explorer.search(rootFolder);\n const config = searchResult ? searchResult.config : emptyDependencyConfig;\n\n const result = schema.dependencyConfig.validate(config, {abortEarly: false});\n\n if (result.error) {\n const validationError = new JoiError(result.error);\n logger.warn(\n inlineString(`\n Package ${chalk.bold(\n dependencyName,\n )} contains invalid configuration: ${chalk.bold(\n validationError.message,\n )}.\n \n Please verify it's properly linked using \"npx react-native config\" command and contact the package maintainers about this.`),\n );\n }\n\n return result.value as UserDependencyConfig;\n}\n\nconst emptyDependencyConfig = {\n dependency: {\n platforms: {},\n },\n commands: [],\n platforms: {},\n};\n"],"mappings":";;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;AACA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAA0B;AAAA;AAAA;AAE1B;A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MAAMU,eAAe,GAAG,IAAIT,gBAAQ,CAACL,MAAM,CAACI,KAAK,CAAC;IAClDW,kBAAM,CAACC,IAAI,CACT,IAAAC,wBAAY,EAAE;AACpB,kBAAkBC,gBAAK,CAACC,IAAI,CAClBT,cAAc,CACd,oCAAmCQ,gBAAK,CAACC,IAAI,CAC/CL,eAAe,CAACM,OAAO,CACvB;AACR;AACA,iIAAiI,CAAC,CAC7H;EACH;EAEA,OAAOpB,MAAM,CAACM,KAAK;AACrB;AAEA,MAAMK,qBAAqB,GAAG;EAC5BW,UAAU,EAAE;IACVC,SAAS,EAAE,CAAC;EACd,CAAC;EACDC,QAAQ,EAAE,EAAE;EACZD,SAAS,EAAE,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-community/cli-config",
3
- "version": "15.0.1",
3
+ "version": "15.1.0",
4
4
  "license": "MIT",
5
5
  "main": "build/index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "types": "build/index.d.ts",
10
10
  "dependencies": {
11
- "@react-native-community/cli-tools": "15.0.1",
11
+ "@react-native-community/cli-tools": "15.1.0",
12
12
  "chalk": "^4.1.2",
13
13
  "cosmiconfig": "^9.0.0",
14
14
  "deepmerge": "^4.3.0",
@@ -21,7 +21,7 @@
21
21
  "!*.map"
22
22
  ],
23
23
  "devDependencies": {
24
- "@react-native-community/cli-types": "15.0.1",
24
+ "@react-native-community/cli-types": "15.1.0",
25
25
  "@types/cosmiconfig": "^5.0.3"
26
26
  },
27
27
  "homepage": "https://github.com/react-native-community/cli/tree/main/packages/cli-config",
@@ -30,5 +30,5 @@
30
30
  "url": "https://github.com/react-native-community/cli.git",
31
31
  "directory": "packages/cli-config"
32
32
  },
33
- "gitHead": "134e23e0d9a407006bed508da3f523a855dae5b5"
33
+ "gitHead": "577b9af7e38bc8a93472b2c869bbac75548f46bc"
34
34
  }