expo-modules-autolinking 0.5.1 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.5.2 — 2021-12-22
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Introduce `expo_patch_react_imports!` to transform double-quoted React imports into angle-brackets in order to fix third-party libraries incompatibility with SDK 44. ([#15655](https://github.com/expo/expo/pull/15655) by [@kudo](https://github.com/kudo))
18
+
13
19
  ## 0.5.1 — 2021-12-15
14
20
 
15
21
  _This version does not introduce any user-facing changes._
@@ -0,0 +1,14 @@
1
+ import { PatchReactImportsOptions } from './types';
2
+ /**
3
+ * Remove all double-quoted react header imports
4
+ * @param dirs target directories to patch
5
+ * @param options PatchReactImportsOptions
6
+ */
7
+ export declare function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions): Promise<void>;
8
+ /**
9
+ * Patch imports from a file
10
+ * @param headerSet prebuilt React-Core header set
11
+ * @param file target patch file
12
+ * @param dryRun true if not writing changes to file
13
+ */
14
+ export declare function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean): Promise<void>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ // Copyright 2018-present 650 Industries. All rights reserved.
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.patchFileAsync = exports.patchReactImportsAsync = void 0;
8
+ const fast_glob_1 = __importDefault(require("fast-glob"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const path_1 = __importDefault(require("path"));
11
+ /**
12
+ * Remove all double-quoted react header imports
13
+ * @param dirs target directories to patch
14
+ * @param options PatchReactImportsOptions
15
+ */
16
+ async function patchReactImportsAsync(dirs, options) {
17
+ const headerSet = await generateReactHeaderSetAsync(path_1.default.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React'));
18
+ await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));
19
+ }
20
+ exports.patchReactImportsAsync = patchReactImportsAsync;
21
+ /**
22
+ * Generate `React-Core` public header names as a set, will transform necessary headers based on this set.
23
+ */
24
+ async function generateReactHeaderSetAsync(reactHeaderDir) {
25
+ const files = await (0, fast_glob_1.default)('*.h', { cwd: reactHeaderDir });
26
+ return new Set(files);
27
+ }
28
+ /**
29
+ * Patch imports from a file
30
+ * @param headerSet prebuilt React-Core header set
31
+ * @param file target patch file
32
+ * @param dryRun true if not writing changes to file
33
+ */
34
+ async function patchFileAsync(headerSet, file, dryRun) {
35
+ let changed = false;
36
+ const content = await fs_extra_1.default.readFile(file, 'utf-8');
37
+ const transformContent = content.replace(/^#import\s+"(.+)"$/gm, (match, headerName) => {
38
+ // `#import "RCTBridge.h"` -> `#import <React/RCTBridge.h>`
39
+ if (headerSet.has(headerName)) {
40
+ changed = true;
41
+ return `#import <React/${headerName}>`;
42
+ }
43
+ // `#import "React/RCTBridge.h"` -> `#import <React/RCTBridge.h>`
44
+ if (headerName.startsWith('React/')) {
45
+ const name = headerName.substring(6);
46
+ if (headerSet.has(name)) {
47
+ changed = true;
48
+ return `#import <React/${name}>`;
49
+ }
50
+ }
51
+ // Otherwise, return original import
52
+ return match;
53
+ });
54
+ if (changed) {
55
+ console.log(`Patching imports for file: ${file}`);
56
+ }
57
+ if (!dryRun) {
58
+ await fs_extra_1.default.writeFile(file, transformContent);
59
+ }
60
+ }
61
+ exports.patchFileAsync = patchFileAsync;
62
+ /**
63
+ * Patch imports from a directory
64
+ * @param headerSet prebuilt React-Core header set
65
+ * @param file target patch file
66
+ * @param dryRun true if not writing changes to file
67
+ */
68
+ async function patchDirAsync(headerSet, dir, dryRun) {
69
+ const files = await (0, fast_glob_1.default)('**/*.{h,m,mm}', { cwd: dir, absolute: true });
70
+ return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));
71
+ }
72
+ //# sourceMappingURL=ReactImportsPatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactImportsPatcher.js","sourceRoot":"","sources":["../src/ReactImportsPatcher.ts"],"names":[],"mappings":";AAAA,8DAA8D;;;;;;AAE9D,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB;;;;GAIG;AACI,KAAK,UAAU,sBAAsB,CAAC,IAAc,EAAE,OAAiC;IAC5F,MAAM,SAAS,GAAG,MAAM,2BAA2B,CACjD,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CACxE,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AALD,wDAKC;AAED;;GAEG;AACH,KAAK,UAAU,2BAA2B,CAAC,cAAsB;IAC/D,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAI,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC;IACzD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,SAAsB,EAAE,IAAY,EAAE,MAAe;IACxF,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,OAAO,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CACtC,sBAAsB,EACtB,CAAC,KAAa,EAAE,UAAkB,EAAU,EAAE;QAC5C,2DAA2D;QAC3D,IAAI,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YAC7B,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,kBAAkB,UAAU,GAAG,CAAC;SACxC;QAED,iEAAiE;QACjE,IAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YACnC,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACvB,OAAO,GAAG,IAAI,CAAC;gBACf,OAAO,kBAAkB,IAAI,GAAG,CAAC;aAClC;SACF;QAED,oCAAoC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC,CACF,CAAC;IAEF,IAAI,OAAO,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,EAAE,CAAC,CAAC;KACnD;IACD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,kBAAE,CAAC,SAAS,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;KAC5C;AACH,CAAC;AAhCD,wCAgCC;AAED;;;;;GAKG;AACH,KAAK,UAAU,aAAa,CAAC,SAAsB,EAAE,GAAW,EAAE,MAAe;IAC/E,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAI,EAAC,eAAe,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AACnF,CAAC","sourcesContent":["// Copyright 2018-present 650 Industries. All rights reserved.\n\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { PatchReactImportsOptions } from './types';\n\n/**\n * Remove all double-quoted react header imports\n * @param dirs target directories to patch\n * @param options PatchReactImportsOptions\n */\nexport async function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions) {\n const headerSet = await generateReactHeaderSetAsync(\n path.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React')\n );\n await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));\n}\n\n/**\n * Generate `React-Core` public header names as a set, will transform necessary headers based on this set.\n */\nasync function generateReactHeaderSetAsync(reactHeaderDir: string): Promise<Set<string>> {\n const files = await glob('*.h', { cwd: reactHeaderDir });\n return new Set(files);\n}\n\n/**\n * Patch imports from a file\n * @param headerSet prebuilt React-Core header set\n * @param file target patch file\n * @param dryRun true if not writing changes to file\n */\nexport async function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean) {\n let changed = false;\n const content = await fs.readFile(file, 'utf-8');\n const transformContent = content.replace(\n /^#import\\s+\"(.+)\"$/gm,\n (match: string, headerName: string): string => {\n // `#import \"RCTBridge.h\"` -> `#import <React/RCTBridge.h>`\n if (headerSet.has(headerName)) {\n changed = true;\n return `#import <React/${headerName}>`;\n }\n\n // `#import \"React/RCTBridge.h\"` -> `#import <React/RCTBridge.h>`\n if (headerName.startsWith('React/')) {\n const name = headerName.substring(6);\n if (headerSet.has(name)) {\n changed = true;\n return `#import <React/${name}>`;\n }\n }\n\n // Otherwise, return original import\n return match;\n }\n );\n\n if (changed) {\n console.log(`Patching imports for file: ${file}`);\n }\n if (!dryRun) {\n await fs.writeFile(file, transformContent);\n }\n}\n\n/**\n * Patch imports from a directory\n * @param headerSet prebuilt React-Core header set\n * @param file target patch file\n * @param dryRun true if not writing changes to file\n */\nasync function patchDirAsync(headerSet: Set<string>, dir: string, dryRun: boolean) {\n const files = await glob('**/*.{h,m,mm}', { cwd: dir, absolute: true });\n return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));\n}\n"]}
package/build/index.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = __importDefault(require("commander"));
7
+ const ReactImportsPatcher_1 = require("./ReactImportsPatcher");
7
8
  const autolinking_1 = require("./autolinking");
8
9
  /**
9
10
  * Registers a command that only searches for available expo modules.
@@ -30,6 +31,14 @@ function registerSearchCommand(commandName, fn) {
30
31
  function registerResolveCommand(commandName, fn) {
31
32
  return registerSearchCommand(commandName, fn);
32
33
  }
34
+ // Register for `patch-react-imports` command
35
+ function registerPatchReactImportsCommand() {
36
+ return commander_1.default
37
+ .command('patch-react-imports [paths...]')
38
+ .requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')
39
+ .option('--dry-run', 'Only list files without writing changes to the file system')
40
+ .action(ReactImportsPatcher_1.patchReactImportsAsync);
41
+ }
33
42
  module.exports = async function (args) {
34
43
  // Searches for available expo modules.
35
44
  registerSearchCommand('search', async (results, options) => {
@@ -65,6 +74,7 @@ module.exports = async function (args) {
65
74
  .option('-t, --target <path>', 'Path to the target file, where the package list should be written to.')
66
75
  .option('-n, --namespace <namespace>', 'Java package name under which the package list should be placed.')
67
76
  .option('--empty', 'Whether to only generate an empty list. Might be used when the user opts-out of autolinking.', false);
77
+ registerPatchReactImportsCommand();
68
78
  await commander_1.default
69
79
  .version(require('expo-modules-autolinking/package.json').version)
70
80
  .description('CLI command that searches for Expo modules to autolink them.')
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAElC,+CAMuB;AAGvB;;GAEG;AACH,SAAS,qBAAqB,CAC5B,WAAmB,EACnB,EAAwD;IAExD,OAAO,mBAAS;SACb,OAAO,CAAC,GAAG,WAAW,aAAa,CAAC;SACpC,MAAM,CACL,qCAAqC,EACrC,8CAA8C,EAC9C,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,4BAA4B,EAC5B,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CAAC,uCAAuC,CAAC,CAAC,OAAO,CAAC;SACjE,WAAW,CAAC,8DAA8D,CAAC;SAC3E,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import commander from 'commander';\n\nimport {\n findModulesAsync,\n resolveModulesAsync,\n verifySearchResults,\n generatePackageListAsync,\n mergeLinkingOptionsAsync,\n} from './autolinking';\nimport { GenerateOptions, ResolveOptions, SearchOptions, SearchResults } from './types';\n\n/**\n * Registers a command that only searches for available expo modules.\n */\nfunction registerSearchCommand<OptionsType extends SearchOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return commander\n .command(`${commandName} [paths...]`)\n .option<string[] | null>(\n '-i, --ignore-paths <ignorePaths...>',\n 'Paths to ignore when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option<string[] | null>(\n '-e, --exclude <exclude...>',\n 'Package names to exclude when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option(\n '-p, --platform [platform]',\n 'The platform that the resulting modules must support. Available options: \"ios\", \"android\"',\n 'ios'\n )\n .option('--silent', 'Silence resolution warnings')\n .action(async (searchPaths, providedOptions) => {\n const options = await mergeLinkingOptionsAsync<OptionsType>({\n ...providedOptions,\n searchPaths,\n });\n const searchResults = await findModulesAsync(options);\n return await fn(searchResults, options);\n });\n}\n\n/**\n * Registers a command that searches for modules and then resolves them for specific platform.\n */\nfunction registerResolveCommand<OptionsType extends ResolveOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return registerSearchCommand<OptionsType>(commandName, fn);\n}\n\nmodule.exports = async function (args: string[]) {\n // Searches for available expo modules.\n registerSearchCommand<SearchOptions & { json?: boolean }>('search', async (results, options) => {\n if (options.json) {\n console.log(JSON.stringify(results));\n } else {\n console.log(require('util').inspect(results, false, null, true));\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Checks whether there are no resolving issues in the current setup.\n registerSearchCommand('verify', (results) => {\n const numberOfDuplicates = verifySearchResults(results);\n if (!numberOfDuplicates) {\n console.log('✅ Everything is fine!');\n }\n });\n\n // Searches for available expo modules and resolves the results for given platform.\n registerResolveCommand('resolve', async (results, options) => {\n const modules = await resolveModulesAsync(results, options);\n\n if (options.json) {\n console.log(JSON.stringify({ modules }));\n } else {\n console.log({ modules });\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Generates a source file listing all packages to link.\n registerResolveCommand<GenerateOptions>('generate-package-list', async (results, options) => {\n const modules = options.empty ? [] : await resolveModulesAsync(results, options);\n generatePackageListAsync(modules, options);\n })\n .option(\n '-t, --target <path>',\n 'Path to the target file, where the package list should be written to.'\n )\n .option(\n '-n, --namespace <namespace>',\n 'Java package name under which the package list should be placed.'\n )\n .option(\n '--empty',\n 'Whether to only generate an empty list. Might be used when the user opts-out of autolinking.',\n false\n );\n\n await commander\n .version(require('expo-modules-autolinking/package.json').version)\n .description('CLI command that searches for Expo modules to autolink them.')\n .parseAsync(args, { from: 'user' });\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAElC,+DAA+D;AAC/D,+CAMuB;AAGvB;;GAEG;AACH,SAAS,qBAAqB,CAC5B,WAAmB,EACnB,EAAwD;IAExD,OAAO,mBAAS;SACb,OAAO,CAAC,GAAG,WAAW,aAAa,CAAC;SACpC,MAAM,CACL,qCAAqC,EACrC,8CAA8C,EAC9C,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,4BAA4B,EAC5B,uDAAuD,EACvD,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAA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A,MAAM,CACL,6BAA6B,EAC7B,kEAAkE,CACnE;SACA,MAAM,CACL,SAAS,EACT,8FAA8F,EAC9F,KAAK,CACN,CAAC;IAEJ,gCAAgC,EAAE,CAAC;IAEnC,MAAM,mBAAS;SACZ,OAAO,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC,OAAO,CAAC;SACjE,WAAW,CAAC,8DAA8D,CAAC;SAC3E,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import commander from 'commander';\n\nimport { patchReactImportsAsync } from './ReactImportsPatcher';\nimport {\n findModulesAsync,\n resolveModulesAsync,\n verifySearchResults,\n generatePackageListAsync,\n mergeLinkingOptionsAsync,\n} from './autolinking';\nimport { GenerateOptions, ResolveOptions, SearchOptions, SearchResults } from './types';\n\n/**\n * Registers a command that only searches for available expo modules.\n */\nfunction registerSearchCommand<OptionsType extends SearchOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return commander\n .command(`${commandName} [paths...]`)\n .option<string[] | null>(\n '-i, --ignore-paths <ignorePaths...>',\n 'Paths to ignore when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option<string[] | null>(\n '-e, --exclude <exclude...>',\n 'Package names to exclude when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option(\n '-p, --platform [platform]',\n 'The platform that the resulting modules must support. Available options: \"ios\", \"android\"',\n 'ios'\n )\n .option('--silent', 'Silence resolution warnings')\n .action(async (searchPaths, providedOptions) => {\n const options = await mergeLinkingOptionsAsync<OptionsType>({\n ...providedOptions,\n searchPaths,\n });\n const searchResults = await findModulesAsync(options);\n return await fn(searchResults, options);\n });\n}\n\n/**\n * Registers a command that searches for modules and then resolves them for specific platform.\n */\nfunction registerResolveCommand<OptionsType extends ResolveOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return registerSearchCommand<OptionsType>(commandName, fn);\n}\n\n// Register for `patch-react-imports` command\nfunction registerPatchReactImportsCommand() {\n return commander\n .command('patch-react-imports [paths...]')\n .requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')\n .option('--dry-run', 'Only list files without writing changes to the file system')\n .action(patchReactImportsAsync);\n}\n\nmodule.exports = async function (args: string[]) {\n // Searches for available expo modules.\n registerSearchCommand<SearchOptions & { json?: boolean }>('search', async (results, options) => {\n if (options.json) {\n console.log(JSON.stringify(results));\n } else {\n console.log(require('util').inspect(results, false, null, true));\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Checks whether there are no resolving issues in the current setup.\n registerSearchCommand('verify', (results) => {\n const numberOfDuplicates = verifySearchResults(results);\n if (!numberOfDuplicates) {\n console.log('✅ Everything is fine!');\n }\n });\n\n // Searches for available expo modules and resolves the results for given platform.\n registerResolveCommand('resolve', async (results, options) => {\n const modules = await resolveModulesAsync(results, options);\n\n if (options.json) {\n console.log(JSON.stringify({ modules }));\n } else {\n console.log({ modules });\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Generates a source file listing all packages to link.\n registerResolveCommand<GenerateOptions>('generate-package-list', async (results, options) => {\n const modules = options.empty ? [] : await resolveModulesAsync(results, options);\n generatePackageListAsync(modules, options);\n })\n .option(\n '-t, --target <path>',\n 'Path to the target file, where the package list should be written to.'\n )\n .option(\n '-n, --namespace <namespace>',\n 'Java package name under which the package list should be placed.'\n )\n .option(\n '--empty',\n 'Whether to only generate an empty list. Might be used when the user opts-out of autolinking.',\n false\n );\n\n registerPatchReactImportsCommand();\n\n await commander\n .version(require('expo-modules-autolinking/package.json').version)\n .description('CLI command that searches for Expo modules to autolink them.')\n .parseAsync(args, { from: 'user' });\n};\n"]}
package/build/types.d.ts CHANGED
@@ -16,6 +16,10 @@ export interface GenerateOptions extends ResolveOptions {
16
16
  namespace?: string;
17
17
  empty?: boolean;
18
18
  }
19
+ export interface PatchReactImportsOptions {
20
+ podsRoot: string;
21
+ dryRun: boolean;
22
+ }
19
23
  export declare type PackageRevision = {
20
24
  path: string;
21
25
  version: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ExpoModuleConfig } from './ExpoModuleConfig';\n\nexport type SupportedPlatform = 'ios' | 'android' | 'web';\n\nexport interface SearchOptions {\n // Available in the CLI\n searchPaths: string[];\n ignorePaths?: string[] | null;\n exclude?: string[] | null;\n platform: SupportedPlatform;\n silent?: boolean;\n\n // Scratched from project's config\n flags?: Record<string, any>;\n}\n\nexport interface ResolveOptions extends SearchOptions {\n json?: boolean;\n}\n\nexport interface GenerateOptions extends ResolveOptions {\n target: string;\n namespace?: string;\n empty?: boolean;\n}\n\nexport type PackageRevision = {\n path: string;\n version: string;\n config?: ExpoModuleConfig;\n duplicates?: PackageRevision[];\n};\n\nexport type SearchResults = {\n [moduleName: string]: PackageRevision;\n};\n\nexport type ModuleDescriptor = Record<string, any>;\n\n/**\n * Represents a raw config from `expo-module.json`.\n */\nexport interface RawExpoModuleConfig {\n /**\n * An array of supported platforms.\n */\n platforms?: SupportedPlatform[];\n\n /**\n * iOS-specific config.\n */\n ios?: {\n /**\n * Names of Swift native modules classes to put to the generated modules provider file.\n */\n modulesClassNames?: string[];\n\n /**\n * Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.\n */\n appDelegateSubscribers?: string[];\n\n /**\n * Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.\n */\n reactDelegateHandlers?: string[];\n\n /**\n * Podspec relative path.\n */\n podspecPath?: string;\n };\n\n /**\n * Android-specific config.\n */\n android?: {\n /**\n * Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.\n */\n modulesClassNames?: string[];\n };\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ExpoModuleConfig } from './ExpoModuleConfig';\n\nexport type SupportedPlatform = 'ios' | 'android' | 'web';\n\nexport interface SearchOptions {\n // Available in the CLI\n searchPaths: string[];\n ignorePaths?: string[] | null;\n exclude?: string[] | null;\n platform: SupportedPlatform;\n silent?: boolean;\n\n // Scratched from project's config\n flags?: Record<string, any>;\n}\n\nexport interface ResolveOptions extends SearchOptions {\n json?: boolean;\n}\n\nexport interface GenerateOptions extends ResolveOptions {\n target: string;\n namespace?: string;\n empty?: boolean;\n}\n\nexport interface PatchReactImportsOptions {\n podsRoot: string;\n dryRun: boolean;\n}\n\nexport type PackageRevision = {\n path: string;\n version: string;\n config?: ExpoModuleConfig;\n duplicates?: PackageRevision[];\n};\n\nexport type SearchResults = {\n [moduleName: string]: PackageRevision;\n};\n\nexport type ModuleDescriptor = Record<string, any>;\n\n/**\n * Represents a raw config from `expo-module.json`.\n */\nexport interface RawExpoModuleConfig {\n /**\n * An array of supported platforms.\n */\n platforms?: SupportedPlatform[];\n\n /**\n * iOS-specific config.\n */\n ios?: {\n /**\n * Names of Swift native modules classes to put to the generated modules provider file.\n */\n modulesClassNames?: string[];\n\n /**\n * Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.\n */\n appDelegateSubscribers?: string[];\n\n /**\n * Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.\n */\n reactDelegateHandlers?: string[];\n\n /**\n * Podspec relative path.\n */\n podspecPath?: string;\n };\n\n /**\n * Android-specific config.\n */\n android?: {\n /**\n * Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.\n */\n modulesClassNames?: string[];\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-modules-autolinking",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Scripts that autolink Expo modules.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "find-up": "^5.0.0",
48
48
  "fs-extra": "^9.1.0"
49
49
  },
50
- "gitHead": "779a011c9a6a436d3e69df0f8f7d1a4703fb297a"
50
+ "gitHead": "0546c63f2d7c25315dd709de8a1c7a3478d83564"
51
51
  }
@@ -0,0 +1,72 @@
1
+ # Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ module Expo
4
+ class ReactImportPatcher
5
+
6
+ public def initialize(installer, options)
7
+ @root = installer.sandbox.root
8
+ @module_dirs = get_module_dirs(installer)
9
+ @options = options
10
+ end
11
+
12
+ public def run!
13
+ args = [
14
+ 'node',
15
+ '--eval',
16
+ 'require(\'expo-modules-autolinking\')(process.argv.slice(1))',
17
+ 'patch-react-imports',
18
+ '--pods-root',
19
+ Shellwords.escape(File.expand_path(@root)),
20
+ ]
21
+
22
+ if @options[:dry_run]
23
+ args.append('--dry-run')
24
+ end
25
+
26
+ @module_dirs.each do |dir|
27
+ args.append(Shellwords.escape(File.expand_path(dir)))
28
+ end
29
+ Pod::UI.message "Executing ReactImportsPatcher node command: #{args.join(' ')}"
30
+
31
+ time_begin = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
+ system(*args)
33
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_begin
34
+ Pod::UI.info "expo_patch_react_imports! took #{elapsed_time.round(4)} seconds to transform files."
35
+ end
36
+
37
+ private def get_module_dirs(installer)
38
+ unless installer.pods_project
39
+ Pod::UI.message '`pods_project` not found. This is expected when `:incremental_installation` is enabled in your project\'s Podfile.'
40
+ return []
41
+ end
42
+
43
+ result = []
44
+ installer.pods_project.development_pods.children.each do |pod|
45
+ if pod.is_a?(Xcodeproj::Project::Object::PBXFileReference) && pod.path.end_with?('.xcodeproj')
46
+ # Support generate_multiple_pod_projects or use_frameworks!
47
+ project = Xcodeproj::Project.open(File.join(installer.sandbox.root, pod.path))
48
+ groups = project.groups.select { |group| !(['Dependencies', 'Frameworks', 'Products'].include? group.name) }
49
+ groups.each do |group|
50
+ unless group.path.start_with? '../'
51
+ raise 'CocoaPods does not put pod subprojects inside nested directories'
52
+ end
53
+ result.append(group.path[3..])
54
+ end
55
+ else
56
+ unless pod.path.start_with? '../'
57
+ raise 'CocoaPods does not put pod subgroups inside nested directories'
58
+ end
59
+ result.append(pod.path[3..])
60
+ end
61
+ end
62
+
63
+ return result.select { |dir|
64
+ # Exclude known dirs unnecessary to patch and reduce processing time
65
+ !dir.include?('/react-native/') &&
66
+ !dir.end_with?('/react-native') &&
67
+ !dir.include?('/expo-')
68
+ }
69
+ end
70
+
71
+ end # class ReactImportPatcher
72
+ end # module Expo
@@ -0,0 +1,78 @@
1
+ // Copyright 2018-present 650 Industries. All rights reserved.
2
+
3
+ import glob from 'fast-glob';
4
+ import fs from 'fs-extra';
5
+ import path from 'path';
6
+
7
+ import { PatchReactImportsOptions } from './types';
8
+
9
+ /**
10
+ * Remove all double-quoted react header imports
11
+ * @param dirs target directories to patch
12
+ * @param options PatchReactImportsOptions
13
+ */
14
+ export async function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions) {
15
+ const headerSet = await generateReactHeaderSetAsync(
16
+ path.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React')
17
+ );
18
+ await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));
19
+ }
20
+
21
+ /**
22
+ * Generate `React-Core` public header names as a set, will transform necessary headers based on this set.
23
+ */
24
+ async function generateReactHeaderSetAsync(reactHeaderDir: string): Promise<Set<string>> {
25
+ const files = await glob('*.h', { cwd: reactHeaderDir });
26
+ return new Set(files);
27
+ }
28
+
29
+ /**
30
+ * Patch imports from a file
31
+ * @param headerSet prebuilt React-Core header set
32
+ * @param file target patch file
33
+ * @param dryRun true if not writing changes to file
34
+ */
35
+ export async function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean) {
36
+ let changed = false;
37
+ const content = await fs.readFile(file, 'utf-8');
38
+ const transformContent = content.replace(
39
+ /^#import\s+"(.+)"$/gm,
40
+ (match: string, headerName: string): string => {
41
+ // `#import "RCTBridge.h"` -> `#import <React/RCTBridge.h>`
42
+ if (headerSet.has(headerName)) {
43
+ changed = true;
44
+ return `#import <React/${headerName}>`;
45
+ }
46
+
47
+ // `#import "React/RCTBridge.h"` -> `#import <React/RCTBridge.h>`
48
+ if (headerName.startsWith('React/')) {
49
+ const name = headerName.substring(6);
50
+ if (headerSet.has(name)) {
51
+ changed = true;
52
+ return `#import <React/${name}>`;
53
+ }
54
+ }
55
+
56
+ // Otherwise, return original import
57
+ return match;
58
+ }
59
+ );
60
+
61
+ if (changed) {
62
+ console.log(`Patching imports for file: ${file}`);
63
+ }
64
+ if (!dryRun) {
65
+ await fs.writeFile(file, transformContent);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Patch imports from a directory
71
+ * @param headerSet prebuilt React-Core header set
72
+ * @param file target patch file
73
+ * @param dryRun true if not writing changes to file
74
+ */
75
+ async function patchDirAsync(headerSet: Set<string>, dir: string, dryRun: boolean) {
76
+ const files = await glob('**/*.{h,m,mm}', { cwd: dir, absolute: true });
77
+ return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));
78
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import commander from 'commander';
2
2
 
3
+ import { patchReactImportsAsync } from './ReactImportsPatcher';
3
4
  import {
4
5
  findModulesAsync,
5
6
  resolveModulesAsync,
@@ -54,6 +55,15 @@ function registerResolveCommand<OptionsType extends ResolveOptions>(
54
55
  return registerSearchCommand<OptionsType>(commandName, fn);
55
56
  }
56
57
 
58
+ // Register for `patch-react-imports` command
59
+ function registerPatchReactImportsCommand() {
60
+ return commander
61
+ .command('patch-react-imports [paths...]')
62
+ .requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')
63
+ .option('--dry-run', 'Only list files without writing changes to the file system')
64
+ .action(patchReactImportsAsync);
65
+ }
66
+
57
67
  module.exports = async function (args: string[]) {
58
68
  // Searches for available expo modules.
59
69
  registerSearchCommand<SearchOptions & { json?: boolean }>('search', async (results, options) => {
@@ -102,6 +112,8 @@ module.exports = async function (args: string[]) {
102
112
  false
103
113
  );
104
114
 
115
+ registerPatchReactImportsCommand();
116
+
105
117
  await commander
106
118
  .version(require('expo-modules-autolinking/package.json').version)
107
119
  .description('CLI command that searches for Expo modules to autolink them.')
package/src/types.ts CHANGED
@@ -24,6 +24,11 @@ export interface GenerateOptions extends ResolveOptions {
24
24
  empty?: boolean;
25
25
  }
26
26
 
27
+ export interface PatchReactImportsOptions {
28
+ podsRoot: string;
29
+ dryRun: boolean;
30
+ }
31
+
27
32
  export type PackageRevision = {
28
33
  path: string;
29
34
  version: string;