expo-modules-autolinking 3.0.0 → 3.0.2

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/autolinking/findModules.d.ts +11 -5
  3. package/build/autolinking/findModules.js +8 -16
  4. package/build/autolinking/findModules.js.map +1 -1
  5. package/build/autolinking/generatePackageList.d.ts +16 -10
  6. package/build/autolinking/generatePackageList.js +13 -28
  7. package/build/autolinking/generatePackageList.js.map +1 -1
  8. package/build/autolinking/getConfiguration.d.ts +9 -2
  9. package/build/autolinking/getConfiguration.js +9 -4
  10. package/build/autolinking/getConfiguration.js.map +1 -1
  11. package/build/autolinking/index.d.ts +22 -17
  12. package/build/autolinking/index.js +23 -47
  13. package/build/autolinking/index.js.map +1 -1
  14. package/build/autolinking/resolveModules.d.ts +13 -9
  15. package/build/autolinking/resolveModules.js +21 -18
  16. package/build/autolinking/resolveModules.js.map +1 -1
  17. package/build/commands/autolinkingOptions.d.ts +50 -0
  18. package/build/commands/autolinkingOptions.js +168 -0
  19. package/build/commands/autolinkingOptions.js.map +1 -0
  20. package/build/commands/generateModulesProviderCommand.d.ts +3 -0
  21. package/build/commands/generateModulesProviderCommand.js +35 -0
  22. package/build/commands/generateModulesProviderCommand.js.map +1 -0
  23. package/build/commands/generatePackageListCommand.d.ts +6 -0
  24. package/build/commands/generatePackageListCommand.js +39 -0
  25. package/build/commands/generatePackageListCommand.js.map +1 -0
  26. package/build/commands/reactNativeConfigCommand.d.ts +3 -0
  27. package/build/commands/reactNativeConfigCommand.js +36 -0
  28. package/build/commands/reactNativeConfigCommand.js.map +1 -0
  29. package/build/commands/resolveCommand.d.ts +3 -0
  30. package/build/commands/resolveCommand.js +63 -0
  31. package/build/commands/resolveCommand.js.map +1 -0
  32. package/build/commands/searchCommand.d.ts +2 -0
  33. package/build/commands/searchCommand.js +27 -0
  34. package/build/commands/searchCommand.js.map +1 -0
  35. package/build/{autolinking/verifySearchResults.d.ts → commands/verifyCommand.d.ts} +4 -2
  36. package/build/{autolinking/verifySearchResults.js → commands/verifyCommand.js} +24 -3
  37. package/build/commands/verifyCommand.js.map +1 -0
  38. package/build/dependencies/CachedDependenciesLinker.d.ts +2 -1
  39. package/build/dependencies/CachedDependenciesLinker.js +23 -9
  40. package/build/dependencies/CachedDependenciesLinker.js.map +1 -1
  41. package/build/exports.d.ts +17 -1
  42. package/build/exports.js +48 -1
  43. package/build/exports.js.map +1 -1
  44. package/build/index.js +18 -162
  45. package/build/index.js.map +1 -1
  46. package/build/platforms/{android.d.ts → android/android.d.ts} +7 -2
  47. package/build/platforms/{android.js → android/android.js} +1 -5
  48. package/build/platforms/android/android.js.map +1 -0
  49. package/build/platforms/android/index.d.ts +1 -0
  50. package/build/platforms/android/index.js +9 -0
  51. package/build/platforms/android/index.js.map +1 -0
  52. package/build/platforms/{apple.d.ts → apple/apple.d.ts} +6 -6
  53. package/build/platforms/{apple.js → apple/apple.js} +5 -7
  54. package/build/platforms/apple/apple.js.map +1 -0
  55. package/build/platforms/apple/index.d.ts +1 -0
  56. package/build/platforms/apple/index.js +8 -0
  57. package/build/platforms/apple/index.js.map +1 -0
  58. package/build/platforms/index.d.ts +15 -0
  59. package/build/{autolinking/utils.js → platforms/index.js} +6 -1
  60. package/build/platforms/index.js.map +1 -0
  61. package/build/reactNativeConfig/reactNativeConfig.d.ts +11 -2
  62. package/build/reactNativeConfig/reactNativeConfig.js +13 -15
  63. package/build/reactNativeConfig/reactNativeConfig.js.map +1 -1
  64. package/build/reactNativeConfig/reactNativeConfig.types.d.ts +4 -33
  65. package/build/reactNativeConfig/reactNativeConfig.types.js.map +1 -1
  66. package/build/types.d.ts +1 -58
  67. package/build/types.js.map +1 -1
  68. package/package.json +3 -3
  69. package/src/autolinking/findModules.ts +18 -16
  70. package/src/autolinking/generatePackageList.ts +30 -31
  71. package/src/autolinking/getConfiguration.ts +16 -5
  72. package/src/autolinking/index.ts +48 -41
  73. package/src/autolinking/resolveModules.ts +47 -34
  74. package/src/commands/autolinkingOptions.ts +265 -0
  75. package/src/commands/generateModulesProviderCommand.ts +60 -0
  76. package/src/commands/generatePackageListCommand.ts +67 -0
  77. package/src/commands/reactNativeConfigCommand.ts +50 -0
  78. package/src/commands/resolveCommand.ts +101 -0
  79. package/src/commands/searchCommand.ts +35 -0
  80. package/src/{autolinking/verifySearchResults.ts → commands/verifyCommand.ts} +48 -6
  81. package/src/dependencies/CachedDependenciesLinker.ts +30 -12
  82. package/src/exports.ts +65 -0
  83. package/src/index.ts +18 -286
  84. package/src/platforms/{android.ts → android/android.ts} +10 -12
  85. package/src/platforms/android/index.ts +6 -0
  86. package/src/platforms/{apple.ts → apple/apple.ts} +10 -11
  87. package/src/platforms/apple/index.ts +5 -0
  88. package/src/platforms/index.ts +49 -0
  89. package/src/reactNativeConfig/reactNativeConfig.ts +25 -28
  90. package/src/reactNativeConfig/reactNativeConfig.types.ts +4 -35
  91. package/src/types.ts +10 -70
  92. package/build/autolinking/mergeLinkingOptions.d.ts +0 -27
  93. package/build/autolinking/mergeLinkingOptions.js +0 -112
  94. package/build/autolinking/mergeLinkingOptions.js.map +0 -1
  95. package/build/autolinking/utils.d.ts +0 -2
  96. package/build/autolinking/utils.js.map +0 -1
  97. package/build/autolinking/verifySearchResults.js.map +0 -1
  98. package/build/platforms/android.js.map +0 -1
  99. package/build/platforms/apple.js.map +0 -1
  100. package/src/autolinking/mergeLinkingOptions.ts +0 -146
  101. package/src/autolinking/utils.ts +0 -15
@@ -0,0 +1,101 @@
1
+ import commander from 'commander';
2
+
3
+ import {
4
+ AutolinkingCommonArguments,
5
+ createAutolinkingOptionsLoader,
6
+ registerAutolinkingArguments,
7
+ } from './autolinkingOptions';
8
+ import { findModulesAsync } from '../autolinking/findModules';
9
+ import { getConfiguration } from '../autolinking/getConfiguration';
10
+ import {
11
+ resolveModulesAsync,
12
+ resolveExtraBuildDependenciesAsync,
13
+ } from '../autolinking/resolveModules';
14
+ import type {
15
+ ModuleDescriptor,
16
+ CommonNativeModuleDescriptor,
17
+ ModuleDescriptorAndroid,
18
+ ModuleDescriptorIos,
19
+ } from '../types';
20
+
21
+ function hasCoreFeatures(
22
+ module: ModuleDescriptor
23
+ ): module is ModuleDescriptorAndroid | ModuleDescriptorIos {
24
+ return (module as CommonNativeModuleDescriptor).coreFeatures !== undefined;
25
+ }
26
+
27
+ interface ResolveArguments extends AutolinkingCommonArguments {
28
+ json?: boolean | null;
29
+ }
30
+
31
+ /** Searches for available expo modules and resolves the results for given platform. */
32
+ export function resolveCommand(cli: commander.CommanderStatic) {
33
+ return registerAutolinkingArguments(cli.command('resolve [searchPaths...]'))
34
+ .option('-j, --json', 'Output results in the plain JSON format.', () => true, false)
35
+ .action(async (searchPaths: string[] | null, commandArguments: ResolveArguments) => {
36
+ const platform = commandArguments.platform ?? 'apple';
37
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader({
38
+ ...commandArguments,
39
+ searchPaths,
40
+ });
41
+
42
+ const autolinkingOptions = await autolinkingOptionsLoader.getPlatformOptions(platform);
43
+ const appRoot = await autolinkingOptionsLoader.getAppRoot();
44
+
45
+ const expoModulesSearchResults = await findModulesAsync({
46
+ autolinkingOptions,
47
+ appRoot,
48
+ });
49
+
50
+ const expoModulesResolveResults = await resolveModulesAsync(
51
+ expoModulesSearchResults,
52
+ autolinkingOptions
53
+ );
54
+
55
+ const extraDependencies = await resolveExtraBuildDependenciesAsync({
56
+ commandRoot: autolinkingOptionsLoader.getCommandRoot(),
57
+ platform,
58
+ });
59
+
60
+ const configuration = getConfiguration({ autolinkingOptions });
61
+
62
+ const coreFeatures = [
63
+ ...expoModulesResolveResults.reduce<Set<string>>((acc, module) => {
64
+ if (hasCoreFeatures(module)) {
65
+ const features = module.coreFeatures ?? [];
66
+ for (const feature of features) {
67
+ acc.add(feature);
68
+ }
69
+ return acc;
70
+ }
71
+
72
+ return acc;
73
+ }, new Set()),
74
+ ];
75
+
76
+ if (commandArguments.json) {
77
+ console.log(
78
+ JSON.stringify({
79
+ extraDependencies,
80
+ coreFeatures,
81
+ modules: expoModulesResolveResults,
82
+ ...(configuration ? { configuration } : {}),
83
+ })
84
+ );
85
+ } else {
86
+ console.log(
87
+ require('util').inspect(
88
+ {
89
+ extraDependencies,
90
+ coreFeatures,
91
+ modules: expoModulesResolveResults,
92
+ ...(configuration ? { configuration } : {}),
93
+ },
94
+ false,
95
+ null,
96
+ true
97
+ )
98
+ );
99
+ }
100
+ });
101
+ }
@@ -0,0 +1,35 @@
1
+ import commander from 'commander';
2
+
3
+ import {
4
+ AutolinkingCommonArguments,
5
+ createAutolinkingOptionsLoader,
6
+ registerAutolinkingArguments,
7
+ } from './autolinkingOptions';
8
+ import { findModulesAsync } from '../autolinking/findModules';
9
+
10
+ interface SearchArguments extends AutolinkingCommonArguments {
11
+ json?: boolean | null;
12
+ }
13
+
14
+ export function searchCommand(cli: commander.CommanderStatic) {
15
+ return registerAutolinkingArguments(cli.command('search [searchPaths...]'))
16
+ .option('-j, --json', 'Output results in the plain JSON format.', () => true, false)
17
+ .action(async (searchPaths: string[] | null, commandArguments: SearchArguments) => {
18
+ const platform = commandArguments.platform ?? 'apple';
19
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader({
20
+ ...commandArguments,
21
+ searchPaths,
22
+ });
23
+
24
+ const expoModulesSearchResults = await findModulesAsync({
25
+ autolinkingOptions: await autolinkingOptionsLoader.getPlatformOptions(platform),
26
+ appRoot: await autolinkingOptionsLoader.getAppRoot(),
27
+ });
28
+
29
+ if (commandArguments.json) {
30
+ console.log(JSON.stringify(expoModulesSearchResults));
31
+ } else {
32
+ console.log(require('util').inspect(expoModulesSearchResults, false, null, true));
33
+ }
34
+ });
35
+ }
@@ -1,16 +1,58 @@
1
1
  import chalk from 'chalk';
2
+ import commander from 'commander';
2
3
  import fs from 'fs';
3
4
  import path from 'path';
4
5
 
5
6
  import {
6
- BaseDependencyResolution,
7
- DependencyResolution,
7
+ AutolinkingCommonArguments,
8
+ createAutolinkingOptionsLoader,
9
+ registerAutolinkingArguments,
10
+ } from './autolinkingOptions';
11
+ import {
12
+ type BaseDependencyResolution,
13
+ type DependencyResolution,
14
+ type ResolutionResult,
8
15
  DependencyResolutionSource,
9
- ResolutionResult,
16
+ makeCachedDependenciesLinker,
17
+ mergeResolutionResults,
18
+ scanDependencyResolutionsForPlatform,
10
19
  } from '../dependencies';
11
20
 
21
+ interface VerifyArguments extends AutolinkingCommonArguments {
22
+ verbose?: boolean | null;
23
+ json?: boolean | null;
24
+ }
25
+
26
+ export function verifyCommand(cli: commander.CommanderStatic) {
27
+ return registerAutolinkingArguments(cli.command('verify'))
28
+ .option('-v, --verbose', 'Output all results instead of just warnings.', () => true, false)
29
+ .option('-j, --json', 'Output results in the plain JSON format.', () => true, false)
30
+ .option(
31
+ '-p, --platform [platform]',
32
+ 'The platform to validate native modules for. Available options: "android", "ios", "both"',
33
+ 'both'
34
+ )
35
+ .action(async (commandArguments: VerifyArguments) => {
36
+ const platforms =
37
+ commandArguments.platform === 'both' ? ['android', 'ios'] : [commandArguments.platform!];
38
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader(commandArguments);
39
+ const appRoot = await autolinkingOptionsLoader.getAppRoot();
40
+ const linker = makeCachedDependenciesLinker({ projectRoot: appRoot });
41
+ const results = mergeResolutionResults(
42
+ await Promise.all(
43
+ platforms.map((platform) => scanDependencyResolutionsForPlatform(linker, platform))
44
+ )
45
+ );
46
+ await verifySearchResults(results, {
47
+ appRoot,
48
+ verbose: !!commandArguments.verbose,
49
+ json: !!commandArguments.json,
50
+ });
51
+ });
52
+ }
53
+
12
54
  interface VerifyOptions {
13
- projectRoot: string;
55
+ appRoot: string;
14
56
  verbose?: boolean;
15
57
  json?: boolean;
16
58
  }
@@ -29,7 +71,7 @@ export async function verifySearchResults(
29
71
  results: ResolutionResult,
30
72
  options: VerifyOptions
31
73
  ): Promise<void> {
32
- const { projectRoot } = options;
74
+ const { appRoot } = options;
33
75
 
34
76
  async function getHumanReadableDependency(dependency: BaseDependencyResolution): Promise<string> {
35
77
  let version = dependency.version || null;
@@ -47,7 +89,7 @@ export async function verifySearchResults(
47
89
  version = null;
48
90
  }
49
91
  }
50
- const relative = path.relative(projectRoot, dependency.originPath);
92
+ const relative = path.relative(appRoot, dependency.originPath);
51
93
  return version
52
94
  ? `${dependency.name}@${version} (at: ${relative})`
53
95
  : `${dependency.name} at: ${relative}`;
@@ -1,13 +1,13 @@
1
1
  import fs from 'fs';
2
2
 
3
- import { SearchOptions, SupportedPlatform } from '../autolinking';
3
+ import { PackageRevision, SupportedPlatform } from '../types';
4
4
  import { scanDependenciesRecursively } from './resolution';
5
5
  import { scanDependenciesFromRNProjectConfig } from './rncliLocal';
6
6
  import { scanDependenciesInSearchPath } from './scanning';
7
7
  import { type ResolutionResult, DependencyResolutionSource } from './types';
8
8
  import { filterMapResolutionResult, mergeResolutionResults } from './utils';
9
9
  import { resolveExpoModule } from '../autolinking/findModules';
10
- import { createLinkingOptionsFactory } from '../autolinking/mergeLinkingOptions';
10
+ import { AutolinkingOptions, createAutolinkingOptionsLoader } from '../commands/autolinkingOptions';
11
11
  import { resolveReactNativeModule, RNConfigReactNativeProjectConfig } from '../reactNativeConfig';
12
12
  import { loadConfigAsync } from '../reactNativeConfig/config';
13
13
 
@@ -27,14 +27,12 @@ export interface CachedDependenciesLinker {
27
27
  export function makeCachedDependenciesLinker(params: {
28
28
  projectRoot: string;
29
29
  }): CachedDependenciesLinker {
30
- const linkingOptionsFactory = createLinkingOptionsFactory<SearchOptions>({
30
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader({
31
31
  projectRoot: params.projectRoot,
32
- platform: 'apple', // Placeholder value
33
32
  });
34
33
 
35
- let projectRoot: Promise<string> | undefined;
36
- const getProjectRoot = () =>
37
- projectRoot || (projectRoot = linkingOptionsFactory.getProjectRoot());
34
+ let appRoot: Promise<string> | undefined;
35
+ const getAppRoot = () => appRoot || (appRoot = autolinkingOptionsLoader.getAppRoot());
38
36
 
39
37
  const dependenciesResultBySearchPath = new Map<string, Promise<ResolutionResult>>();
40
38
  let reactNativeProjectConfig: Promise<RNConfigReactNativeProjectConfig | null> | undefined;
@@ -43,13 +41,13 @@ export function makeCachedDependenciesLinker(params: {
43
41
 
44
42
  return {
45
43
  async getOptionsForPlatform(platform) {
46
- const options = await linkingOptionsFactory.getPlatformOptions(platform);
44
+ const options = await autolinkingOptionsLoader.getPlatformOptions(platform);
47
45
  return makeCachedDependenciesSearchOptions(options);
48
46
  },
49
47
  async loadReactNativeProjectConfig() {
50
48
  if (reactNativeProjectConfig === undefined) {
51
49
  reactNativeProjectConfig = loadConfigAsync<RNConfigReactNativeProjectConfig>(
52
- await getProjectRoot()
50
+ await getAppRoot()
53
51
  );
54
52
  }
55
53
  return reactNativeProjectConfig;
@@ -59,7 +57,7 @@ export function makeCachedDependenciesLinker(params: {
59
57
  return (
60
58
  reactNativeProjectConfigDependencies ||
61
59
  (reactNativeProjectConfigDependencies = scanDependenciesFromRNProjectConfig(
62
- await getProjectRoot(),
60
+ await getAppRoot(),
63
61
  reactNativeProjectConfig
64
62
  ))
65
63
  );
@@ -67,7 +65,7 @@ export function makeCachedDependenciesLinker(params: {
67
65
  async scanDependenciesRecursively() {
68
66
  return (
69
67
  recursiveDependencies ||
70
- (recursiveDependencies = scanDependenciesRecursively(await getProjectRoot()))
68
+ (recursiveDependencies = scanDependenciesRecursively(await getAppRoot()))
71
69
  );
72
70
  },
73
71
  async scanDependenciesInSearchPath(searchPath: string) {
@@ -134,7 +132,27 @@ export async function scanDependencyResolutionsForPlatform(
134
132
  return dependencies;
135
133
  }
136
134
 
137
- const makeCachedDependenciesSearchOptions = (options: SearchOptions) => ({
135
+ export async function scanExpoModuleResolutionsForPlatform(
136
+ linker: CachedDependenciesLinker,
137
+ platform: SupportedPlatform
138
+ ): Promise<Record<string, PackageRevision>> {
139
+ const { excludeNames, searchPaths } = await linker.getOptionsForPlatform(platform);
140
+ const resolutions = mergeResolutionResults(
141
+ await Promise.all([
142
+ ...searchPaths.map((searchPath) => {
143
+ return linker.scanDependenciesInSearchPath(searchPath);
144
+ }),
145
+ linker.scanDependenciesRecursively(),
146
+ ])
147
+ );
148
+ return await filterMapResolutionResult(resolutions, async (resolution) => {
149
+ return !excludeNames.has(resolution.name)
150
+ ? await resolveExpoModule(resolution, platform, excludeNames)
151
+ : null;
152
+ });
153
+ }
154
+
155
+ const makeCachedDependenciesSearchOptions = (options: AutolinkingOptions) => ({
138
156
  excludeNames: new Set(options.exclude),
139
157
  searchPaths:
140
158
  options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)
package/src/exports.ts CHANGED
@@ -1,4 +1,18 @@
1
+ import findUp from 'find-up';
2
+
3
+ import { findModulesAsync } from './autolinking/findModules';
4
+ import { resolveModulesAsync } from './autolinking/resolveModules';
5
+ import {
6
+ AutolinkingCommonArguments,
7
+ AutolinkingOptions,
8
+ createAutolinkingOptionsLoader,
9
+ filterMapSearchPaths,
10
+ } from './commands/autolinkingOptions';
11
+ import { ModuleDescriptor, SupportedPlatform } from './types';
12
+
13
+ export * from './types';
1
14
  export * from './autolinking';
15
+ export * from './platforms';
2
16
 
3
17
  export {
4
18
  ResolutionResult,
@@ -9,4 +23,55 @@ export {
9
23
  CachedDependenciesSearchOptions,
10
24
  makeCachedDependenciesLinker,
11
25
  scanDependencyResolutionsForPlatform,
26
+ scanExpoModuleResolutionsForPlatform,
12
27
  } from './dependencies';
28
+
29
+ /** @deprecated */
30
+ export async function mergeLinkingOptionsAsync<Options extends Partial<AutolinkingCommonArguments>>(
31
+ argumentsOptions: Options
32
+ ): Promise<Options & AutolinkingOptions> {
33
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader(argumentsOptions);
34
+ return {
35
+ ...argumentsOptions,
36
+ ...(await autolinkingOptionsLoader.getPlatformOptions()),
37
+ projectRoot: autolinkingOptionsLoader.getAppRoot(),
38
+ };
39
+ }
40
+
41
+ interface QueryAutolinkingModulesFromProjectParams extends Partial<AutolinkingCommonArguments> {
42
+ platform: SupportedPlatform;
43
+ [extra: string]: unknown;
44
+ }
45
+
46
+ /** @deprecated */
47
+ export async function queryAutolinkingModulesFromProjectAsync(
48
+ projectRoot: string,
49
+ options: QueryAutolinkingModulesFromProjectParams
50
+ ): Promise<ModuleDescriptor[]> {
51
+ const autolinkingOptionsLoader = createAutolinkingOptionsLoader({
52
+ ...options,
53
+ // NOTE(@kitten): This has always been duplicated
54
+ projectRoot: options.projectRoot ?? projectRoot,
55
+ });
56
+ const appRoot = await autolinkingOptionsLoader.getAppRoot();
57
+ const autolinkingOptions = await autolinkingOptionsLoader.getPlatformOptions(options.platform);
58
+ const searchResults = await findModulesAsync({ appRoot, autolinkingOptions });
59
+ return await resolveModulesAsync(searchResults, autolinkingOptions);
60
+ }
61
+
62
+ /** @deprecated */
63
+ export function findProjectRootSync(cwd: string = process.cwd()): string {
64
+ const result = findUp.sync('package.json', { cwd });
65
+ if (!result) {
66
+ throw new Error(`Couldn't find "package.json" up from path "${cwd}"`);
67
+ }
68
+ return result;
69
+ }
70
+
71
+ /** @deprecated */
72
+ export async function resolveSearchPathsAsync(
73
+ searchPaths: string[] | null,
74
+ cwd: string
75
+ ): Promise<string[]> {
76
+ return filterMapSearchPaths(searchPaths, cwd) ?? [];
77
+ }