expo-codemod 1.1.6 → 56.0.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.
Files changed (36) hide show
  1. package/README.md +75 -102
  2. package/bin/expo-codemod.js +1 -6
  3. package/build/index.d.ts +1 -0
  4. package/build/index.js +70 -0
  5. package/build/index.js.map +1 -0
  6. package/build/log.d.ts +6 -0
  7. package/build/log.js +41 -0
  8. package/build/log.js.map +1 -0
  9. package/build/run/index.d.ts +17 -0
  10. package/build/run/index.js +136 -0
  11. package/build/run/index.js.map +1 -0
  12. package/build/transforms/index.d.ts +3 -0
  13. package/build/transforms/index.js +23 -0
  14. package/build/transforms/index.js.map +1 -0
  15. package/build/transforms/sdk-56-expo-router-react-navigation-replace.d.ts +14 -0
  16. package/build/transforms/sdk-56-expo-router-react-navigation-replace.js +106 -0
  17. package/build/transforms/sdk-56-expo-router-react-navigation-replace.js.map +1 -0
  18. package/build/utils/args.d.ts +3 -0
  19. package/build/utils/args.js +73 -0
  20. package/build/utils/args.js.map +1 -0
  21. package/build/utils/runner.d.ts +7 -0
  22. package/build/utils/runner.js +23 -0
  23. package/build/utils/runner.js.map +1 -0
  24. package/package.json +34 -24
  25. package/build/cli.d.ts +0 -1
  26. package/build/cli.js +0 -106
  27. package/build/cli.js.map +0 -1
  28. package/build/transforms/sdk33-imports.d.ts +0 -2
  29. package/build/transforms/sdk33-imports.js +0 -174
  30. package/build/transforms/sdk33-imports.js.map +0 -1
  31. package/build/transforms/sdk37-imports.d.ts +0 -2
  32. package/build/transforms/sdk37-imports.js +0 -66
  33. package/build/transforms/sdk37-imports.js.map +0 -1
  34. package/build/transforms/sdk41-async-storage.d.ts +0 -2
  35. package/build/transforms/sdk41-async-storage.js +0 -47
  36. package/build/transforms/sdk41-async-storage.js.map +0 -1
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const IMPORT_MAP = {
4
+ '@react-navigation/native': 'expo-router/react-navigation',
5
+ '@react-navigation/elements': 'expo-router/react-navigation',
6
+ '@react-navigation/core': 'expo-router/react-navigation',
7
+ '@react-navigation/routers': 'expo-router/react-navigation',
8
+ '@react-navigation/stack': 'expo-router/js-stack',
9
+ '@react-navigation/bottom-tabs': 'expo-router/js-tabs',
10
+ '@react-navigation/material-top-tabs': 'expo-router/js-top-tabs',
11
+ };
12
+ const UNSUPPORTED_SPECIFIERS = {
13
+ ImportDefaultSpecifier: 'default import',
14
+ ImportNamespaceSpecifier: 'namespace import (import * as ...)',
15
+ };
16
+ const isTypeOnlyImport = (path) => path.node.importKind === 'type';
17
+ /**
18
+ * Clone the specifier, changing its importKind to be type, for example:
19
+ * import { type A } from "b"
20
+ */
21
+ const markAsInlineType = (spec) => {
22
+ const clone = { ...spec };
23
+ clone.importKind = 'type';
24
+ return clone;
25
+ };
26
+ /**
27
+ * Collects errors for unsupported import styles in the given declarations:
28
+ * default imports (`import A from "b"`) and namespace imports
29
+ * (`import * as A from "b"`). Only named imports (`import { A } from "b"`)
30
+ * can be safely rewritten.
31
+ */
32
+ const collectUnsupportedImportStyleErrors = (filePath, paths) => {
33
+ const errors = [];
34
+ for (const declarationPath of paths) {
35
+ const specifiers = (declarationPath.node.specifiers ?? []);
36
+ for (const spec of specifiers) {
37
+ const label = UNSUPPORTED_SPECIFIERS[spec.type];
38
+ if (!label)
39
+ continue;
40
+ const line = declarationPath.node.loc?.start.line ?? '?';
41
+ const sourceModule = declarationPath.node.source.value;
42
+ errors.push(`${filePath}:${line} - ${label} from "${sourceModule}" is not supported. ` +
43
+ `Replace with named imports before running this codemod.`);
44
+ }
45
+ }
46
+ return errors;
47
+ };
48
+ const groupPathsBySource = (paths) => {
49
+ const groupsBySource = new Map();
50
+ for (const declarationPath of paths) {
51
+ const sourceModule = declarationPath.node.source.value;
52
+ const existing = groupsBySource.get(sourceModule);
53
+ if (existing) {
54
+ existing.push(declarationPath);
55
+ }
56
+ else {
57
+ groupsBySource.set(sourceModule, [declarationPath]);
58
+ }
59
+ }
60
+ return groupsBySource;
61
+ };
62
+ const mergeGroup = (j, groupPaths) => {
63
+ const hasAnyTypeOnlyImport = groupPaths.some(isTypeOnlyImport);
64
+ const allImportsAreTypeOnly = groupPaths.every(isTypeOnlyImport);
65
+ // Mixed: `import type { A }` + `import { B }` → `import { type A, B }`.
66
+ const mixesTypeAndValueImports = hasAnyTypeOnlyImport && !allImportsAreTypeOnly;
67
+ const [mergeTarget, ...declarationsToRemove] = groupPaths;
68
+ if (!mergeTarget)
69
+ return;
70
+ const specifiers = groupPaths.flatMap((declarationPath) => {
71
+ const specs = (declarationPath.node.specifiers ?? []);
72
+ return mixesTypeAndValueImports && isTypeOnlyImport(declarationPath)
73
+ ? specs.map(markAsInlineType)
74
+ : specs;
75
+ });
76
+ j(mergeTarget).replaceWith(j.importDeclaration(specifiers, mergeTarget.node.source, allImportsAreTypeOnly ? 'type' : 'value'));
77
+ for (const declarationPath of declarationsToRemove)
78
+ j(declarationPath).remove();
79
+ };
80
+ const transform = (fileInfo, api) => {
81
+ const j = api.jscodeshift;
82
+ const root = j(fileInfo.source);
83
+ const mappablePaths = root
84
+ .find(j.ImportDeclaration)
85
+ .filter((path) => path.node.source.value in IMPORT_MAP)
86
+ .paths();
87
+ if (mappablePaths.length === 0)
88
+ return undefined;
89
+ const errors = collectUnsupportedImportStyleErrors(fileInfo.path, mappablePaths);
90
+ if (errors.length > 0) {
91
+ throw new Error(`Unsupported import style(s) found:\n${errors.join('\n')}`);
92
+ }
93
+ for (const path of mappablePaths) {
94
+ const sourceModule = path.node.source.value;
95
+ path.node.source.value = IMPORT_MAP[sourceModule];
96
+ }
97
+ const groups = groupPathsBySource(root.find(j.ImportDeclaration).paths());
98
+ for (const [importPath, groupPaths] of groups.entries()) {
99
+ if (groupPaths.length > 1 && importPath.startsWith('expo-router')) {
100
+ mergeGroup(j, groupPaths);
101
+ }
102
+ }
103
+ return root.toSource();
104
+ };
105
+ exports.default = transform;
106
+ //# sourceMappingURL=sdk-56-expo-router-react-navigation-replace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-56-expo-router-react-navigation-replace.js","sourceRoot":"","sources":["../../src/transforms/sdk-56-expo-router-react-navigation-replace.ts"],"names":[],"mappings":";;AA8BA,MAAM,UAAU,GAA2B;IACzC,0BAA0B,EAAE,8BAA8B;IAC1D,4BAA4B,EAAE,8BAA8B;IAC5D,wBAAwB,EAAE,8BAA8B;IACxD,2BAA2B,EAAE,8BAA8B;IAC3D,yBAAyB,EAAE,sBAAsB;IACjD,+BAA+B,EAAE,qBAAqB;IACtD,qCAAqC,EAAE,yBAAyB;CACjE,CAAC;AAEF,MAAM,sBAAsB,GAA6D;IACvF,sBAAsB,EAAE,gBAAgB;IACxC,wBAAwB,EAAE,oCAAoC;CAC/D,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,IAAgC,EAAW,EAAE,CACrE,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAoC,IAAO,EAAK,EAAE;IACzE,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAC1B,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,mCAAmC,GAAG,CAC1C,QAAgB,EAChB,KAAmC,EACzB,EAAE;IACZ,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,eAAe,IAAI,KAAK,EAAE,CAAC;QACpC,MAAM,UAAU,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAA8B,CAAC;QACxF,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChD,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,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AC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,uCAAuC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAe,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1E,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACxD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAClE,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { parseArgs, type ParseArgsConfig } from 'util';
2
+ export declare function parseArgsOrExit<T extends ParseArgsConfig>(config: T): ReturnType<typeof parseArgs<T>>;
3
+ export declare function printHelp(info: string, usage: string, options: string, extra?: string): never;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.parseArgsOrExit = parseArgsOrExit;
40
+ exports.printHelp = printHelp;
41
+ const chalk_1 = __importDefault(require("chalk"));
42
+ const util_1 = require("util");
43
+ const Log = __importStar(require("../log"));
44
+ const isParseArgsError = (error) => {
45
+ if (!error || typeof error !== 'object' || !('code' in error))
46
+ return false;
47
+ const code = error.code;
48
+ return typeof code === 'string' && code.startsWith('ERR_PARSE_ARGS_');
49
+ };
50
+ function parseArgsOrExit(config) {
51
+ try {
52
+ return (0, util_1.parseArgs)(config);
53
+ }
54
+ catch (error) {
55
+ if (isParseArgsError(error)) {
56
+ Log.exit(error.message, 1);
57
+ }
58
+ throw error;
59
+ }
60
+ }
61
+ function printHelp(info, usage, options, extra = '') {
62
+ Log.exit((0, chalk_1.default) `
63
+ {bold Info}
64
+ ${info}
65
+
66
+ {bold Usage}
67
+ {dim $} ${usage}
68
+
69
+ {bold Options}
70
+ ${options.split('\n').join('\n ')}
71
+ ` + extra, 0);
72
+ }
73
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/utils/args.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,0CAWC;AAED,8BAcC;AAtCD,kDAA0B;AAC1B,+BAAuD;AAEvD,4CAA8B;AAE9B,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAqC,EAAE;IAC7E,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5E,MAAM,IAAI,GAAI,KAA2B,CAAC,IAAI,CAAC;IAC/C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,SAAgB,eAAe,CAC7B,MAAS;IAET,IAAI,CAAC;QACH,OAAO,IAAA,gBAAS,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAgB,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,OAAe,EAAE,QAAgB,EAAE;IACxF,GAAG,CAAC,IAAI,CACN,IAAA,eAAK,EAAA;;MAEH,IAAI;;;cAGI,KAAK;;;MAGb,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;CACvC,GAAG,KAAK,EACL,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import Runner from 'jscodeshift/src/Runner';
2
+ export type ParserKind = 'tsx' | 'jsx' | 'ts';
3
+ export declare function runTransformAsync({ files, parser, transform, }: {
4
+ files: string[];
5
+ parser: ParserKind;
6
+ transform: string;
7
+ }): ReturnType<(typeof Runner)['run']>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runTransformAsync = runTransformAsync;
7
+ const Runner_1 = __importDefault(require("jscodeshift/src/Runner"));
8
+ const transforms_1 = require("../transforms");
9
+ const JSCODESHIFT_PARSER = {
10
+ tsx: 'tsx',
11
+ jsx: 'babel',
12
+ ts: 'ts',
13
+ };
14
+ async function runTransformAsync({ files, parser, transform, }) {
15
+ return Runner_1.default.run((0, transforms_1.transformFilePath)(transform), files, {
16
+ // Transforms are pre-compiled to JS by our build, so jscodeshift's @babel/register hook is unnecessary.
17
+ babel: false,
18
+ parser: JSCODESHIFT_PARSER[parser],
19
+ verbose: 0,
20
+ silent: true,
21
+ });
22
+ }
23
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/utils/runner.ts"],"names":[],"mappings":";;;;;AAYA,8CAgBC;AA5BD,oEAA4C;AAE5C,8CAAkD;AAIlD,MAAM,kBAAkB,GAA+C;IACrE,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,OAAO;IACZ,EAAE,EAAE,IAAI;CACT,CAAC;AAEK,KAAK,UAAU,iBAAiB,CAAC,EACtC,KAAK,EACL,MAAM,EACN,SAAS,GAKV;IACC,OAAO,gBAAM,CAAC,GAAG,CAAC,IAAA,8BAAiB,EAAC,SAAS,CAAC,EAAE,KAAK,EAAE;QACrD,wGAAwG;QACxG,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,kBAAkB,CAAC,MAAM,CAAC;QAClC,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,42 +1,52 @@
1
1
  {
2
2
  "name": "expo-codemod",
3
- "version": "1.1.6",
4
- "description": "Codemod scripts for Expo apps",
5
- "author": "Expo",
3
+ "version": "56.0.0",
4
+ "description": "Codemods for migrating Expo apps between SDK versions",
6
5
  "license": "MIT",
6
+ "keywords": [
7
+ "codemod",
8
+ "expo",
9
+ "expo-router",
10
+ "react-navigation"
11
+ ],
12
+ "homepage": "https://github.com/expo/expo/tree/main/packages/expo-codemod",
7
13
  "repository": {
8
14
  "type": "git",
9
- "url": "https://github.com/expo/expo-cli.git",
15
+ "url": "https://github.com/expo/expo.git",
10
16
  "directory": "packages/expo-codemod"
11
17
  },
18
+ "bugs": {
19
+ "url": "https://github.com/expo/expo/issues"
20
+ },
12
21
  "bin": {
13
22
  "expo-codemod": "./bin/expo-codemod.js"
14
23
  },
15
- "scripts": {
16
- "watch": "tsc --watch --preserveWatchOutput",
17
- "build": "tsc",
18
- "prepare": "yarn run clean && yarn build",
19
- "clean": "rimraf build ./tsconfig.tsbuildinfo",
20
- "test": "jest",
21
- "test:watch": "jest --watch"
22
- },
24
+ "main": "build",
23
25
  "files": [
24
26
  "bin",
25
27
  "build"
26
28
  ],
29
+ "scripts": {
30
+ "build": "expo-module tsc",
31
+ "clean": "expo-module clean",
32
+ "lint": "expo-module lint",
33
+ "typecheck": "expo-module typecheck",
34
+ "test": "expo-module test",
35
+ "watch": "pnpm run build --watch --preserveWatchOutput",
36
+ "prepublishOnly": "pnpm run clean && pnpm run build"
37
+ },
38
+ "engines": {
39
+ "node": ">=18"
40
+ },
27
41
  "dependencies": {
28
- "@expo/spawn-async": "^1.5.0",
29
- "camelcase": "5.3.1",
30
- "chalk": "^4.0.0",
31
- "globby": "^11.0.0",
32
- "jscodeshift": "0.11.0",
33
- "multimatch": "^4.0.0",
34
- "yargs-parser": "^13.1.0"
42
+ "chalk": "^4.1.2",
43
+ "jscodeshift": "^17.1.2",
44
+ "tinyglobby": "^0.2.15"
35
45
  },
36
46
  "devDependencies": {
37
- "@types/jscodeshift": "^0.11.0",
38
- "@types/multimatch": "^2.1.3",
39
- "@types/yargs-parser": "^13.0.0",
40
- "ast-types": "^0.14.2"
41
- }
47
+ "@types/jscodeshift": "^17.0.0",
48
+ "@types/node": "^22.14.0",
49
+ "expo-module-scripts": "56.0.0"
50
+ },
51
+ "gitHead": "6dcd9ce9d615d25df78597f60520492e35e02efb"
42
52
  }
package/build/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function runAsync(argv: string[]): Promise<void>;
package/build/cli.js DELETED
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.runAsync = void 0;
7
- const spawn_async_1 = __importDefault(require("@expo/spawn-async"));
8
- const chalk_1 = __importDefault(require("chalk"));
9
- const globby_1 = __importDefault(require("globby"));
10
- // @ts-ignore
11
- const Runner_1 = __importDefault(require("jscodeshift/src/Runner"));
12
- const multimatch_1 = __importDefault(require("multimatch"));
13
- const path_1 = __importDefault(require("path"));
14
- const yargs_parser_1 = __importDefault(require("yargs-parser"));
15
- const jscodeshift = require.resolve('jscodeshift/bin/jscodeshift.js');
16
- const transformDir = path_1.default.join(__dirname, 'transforms');
17
- const totalStats = {};
18
- async function runAsync(argv) {
19
- const options = (0, yargs_parser_1.default)(argv);
20
- const [transform, ...paths] = options._.slice(2);
21
- const parser = options.parser;
22
- const transforms = await listTransformsAsync();
23
- if (options.help || !transform || paths.length === 0) {
24
- console.log(`
25
- Usage: expo-codemod <transform> <paths...>
26
-
27
- Options:
28
- <transform> (required) name of transform to apply to files
29
- (see a list of transforms available below)
30
- <paths...> one or more paths or globs (e.g. ./src/**/*.js) of sources to transform
31
- files in .gitignore are ignored by default
32
- -h, --help print this help message
33
- -p, --parser <babel|flow|ts|tsx> parser to use to parse the source files
34
- (default: babel, ts or tsx based on the file extension)
35
-
36
- Transforms available:
37
- ${transforms.join('\n ')}`);
38
- process.exit(1);
39
- return;
40
- }
41
- if (!transforms.includes(transform)) {
42
- throw new Error(`--transform: Transform ${transform} does not exist. Valid options: ` + transforms.join(', '));
43
- }
44
- const allFiles = await (0, globby_1.default)(paths, { gitignore: true, ignore: ['**/node_modules/**'] });
45
- if (parser) {
46
- console.log(`Transforming ${allFiles.length} files using parser '${parser}'...`);
47
- await transformAsync({ files: allFiles, parser, transform });
48
- }
49
- else {
50
- const jsFiles = (0, multimatch_1.default)(allFiles, ['**/*.js', '**/*.jsx']);
51
- if (jsFiles.length) {
52
- console.log(`Transforming ${jsFiles.length} JS files...`);
53
- await transformAsync({ files: jsFiles, parser: 'babel', transform });
54
- }
55
- const tsFiles = (0, multimatch_1.default)(allFiles, ['**/*.ts']);
56
- if (tsFiles.length) {
57
- console.log(`Transforming ${tsFiles.length} TS files...`);
58
- await transformAsync({ files: tsFiles, parser: 'ts', transform });
59
- }
60
- const tsxFiles = (0, multimatch_1.default)(allFiles, ['**/*.tsx']);
61
- if (tsxFiles.length) {
62
- console.log(`Transforming ${tsxFiles.length} TSX files...`);
63
- await transformAsync({ files: tsxFiles, parser: 'tsx', transform });
64
- }
65
- }
66
- if (transform === 'sdk33-imports' || transform === 'sdk37-imports') {
67
- const packages = Object.keys(totalStats).sort();
68
- if (packages.length) {
69
- console.log(chalk_1.default.bold(`\n🆕 Added imports from ${packages.length} packages. Installing packages with \`expo install\`...`));
70
- console.log(`> expo install ${packages.join(' ')}`);
71
- try {
72
- await (0, spawn_async_1.default)('expo', ['install', ...packages], { stdio: 'inherit' });
73
- }
74
- catch (error) {
75
- console.error(chalk_1.default.red('\n⚠️ expo install failed.'));
76
- console.log(chalk_1.default.dim(error.stack));
77
- console.error(chalk_1.default.red('To finish the codemod, please install the added packages manually using:'));
78
- console.log(chalk_1.default.bold.red(`> expo install ${packages.join(' ')}`));
79
- process.exit(1);
80
- }
81
- }
82
- }
83
- }
84
- exports.runAsync = runAsync;
85
- async function transformAsync({ files, parser, transform, }) {
86
- const transformFile = path_1.default.join(transformDir, `${transform}.js`);
87
- if (transform === 'sdk33-imports' || transform === 'sdk37-imports') {
88
- // Dry run to gather stats about which packages need to be installed.
89
- const { stats } = await Runner_1.default.run(transformFile, files, {
90
- dry: true,
91
- silent: true,
92
- babel: false,
93
- parser,
94
- });
95
- Object.keys(stats).forEach(key => {
96
- totalStats[key] = (totalStats[key] || 0) + stats[key];
97
- });
98
- }
99
- const args = ['--parser', parser, '--transform', transformFile, '--no-babel', ...files];
100
- return await (0, spawn_async_1.default)(jscodeshift, args, { stdio: 'inherit' });
101
- }
102
- async function listTransformsAsync() {
103
- const modules = await (0, globby_1.default)(['*.js'], { cwd: transformDir });
104
- return modules.map(filename => path_1.default.basename(filename, '.js'));
105
- }
106
- //# sourceMappingURL=cli.js.map
package/build/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA2C;AAC3C,kDAA0B;AAC1B,oDAA4B;AAC5B,aAAa;AACb,oEAA4C;AAC5C,4DAAoC;AACpC,gDAAwB;AACxB,gEAAiC;AAEjC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;AACtE,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAExD,MAAM,UAAU,GAA8B,EAAE,CAAC;AAE1C,KAAK,UAAU,QAAQ,CAAC,IAAc;IAC3C,MAAM,OAAO,GAAG,IAAA,sBAAK,EAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC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,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACnE,CAAC;AAED,KAAK,UAAU,mBAAmB;IAChC,MAAM,OAAO,GAAG,MAAM,IAAA,gBAAM,EAAC,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC;IAC9D,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,cAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import spawnAsync from '@expo/spawn-async';\nimport chalk from 'chalk';\nimport globby from 'globby';\n// @ts-ignore\nimport Runner from 'jscodeshift/src/Runner';\nimport multimatch from 'multimatch';\nimport path from 'path';\nimport parse from 'yargs-parser';\n\nconst jscodeshift = require.resolve('jscodeshift/bin/jscodeshift.js');\nconst transformDir = path.join(__dirname, 'transforms');\n\nconst totalStats: { [key: string]: number } = {};\n\nexport async function runAsync(argv: string[]) {\n const options = parse(argv);\n const [transform, ...paths] = options._.slice(2);\n const parser = options.parser;\n\n const transforms = await listTransformsAsync();\n if (options.help || !transform || paths.length === 0) {\n console.log(`\nUsage: expo-codemod <transform> <paths...>\n\nOptions:\n <transform> (required) name of transform to apply to files\n (see a list of transforms available below)\n <paths...> one or more paths or globs (e.g. ./src/**/*.js) of sources to transform\n files in .gitignore are ignored by default\n -h, --help print this help message\n -p, --parser <babel|flow|ts|tsx> parser to use to parse the source files\n (default: babel, ts or tsx based on the file extension)\n\nTransforms available:\n ${transforms.join('\\n ')}`);\n process.exit(1);\n return;\n }\n\n if (!transforms.includes(transform)) {\n throw new Error(\n `--transform: Transform ${transform} does not exist. Valid options: ` + transforms.join(', ')\n );\n }\n\n const allFiles = await globby(paths, { gitignore: true, ignore: ['**/node_modules/**'] });\n\n if (parser) {\n console.log(`Transforming ${allFiles.length} files using parser '${parser}'...`);\n await transformAsync({ files: allFiles, parser, transform });\n } else {\n const jsFiles = multimatch(allFiles, ['**/*.js', '**/*.jsx']);\n if (jsFiles.length) {\n console.log(`Transforming ${jsFiles.length} JS files...`);\n await transformAsync({ files: jsFiles, parser: 'babel', transform });\n }\n\n const tsFiles = multimatch(allFiles, ['**/*.ts']);\n if (tsFiles.length) {\n console.log(`Transforming ${tsFiles.length} TS files...`);\n await transformAsync({ files: tsFiles, parser: 'ts', transform });\n }\n\n const tsxFiles = multimatch(allFiles, ['**/*.tsx']);\n if (tsxFiles.length) {\n console.log(`Transforming ${tsxFiles.length} TSX files...`);\n await transformAsync({ files: tsxFiles, parser: 'tsx', transform });\n }\n }\n\n if (transform === 'sdk33-imports' || transform === 'sdk37-imports') {\n const packages = Object.keys(totalStats).sort();\n if (packages.length) {\n console.log(\n chalk.bold(\n `\\n🆕 Added imports from ${packages.length} packages. Installing packages with \\`expo install\\`...`\n )\n );\n console.log(`> expo install ${packages.join(' ')}`);\n try {\n await spawnAsync('expo', ['install', ...packages], { stdio: 'inherit' });\n } catch (error: any) {\n console.error(chalk.red('\\n⚠️ expo install failed.'));\n console.log(chalk.dim(error.stack));\n console.error(\n chalk.red('To finish the codemod, please install the added packages manually using:')\n );\n console.log(chalk.bold.red(`> expo install ${packages.join(' ')}`));\n process.exit(1);\n }\n }\n }\n}\n\nasync function transformAsync({\n files,\n parser,\n transform,\n}: {\n files: string[];\n parser: 'babel' | 'flow' | 'ts' | 'tsx';\n transform: string;\n}) {\n const transformFile = path.join(transformDir, `${transform}.js`);\n if (transform === 'sdk33-imports' || transform === 'sdk37-imports') {\n // Dry run to gather stats about which packages need to be installed.\n const { stats } = await Runner.run(transformFile, files, {\n dry: true,\n silent: true,\n babel: false,\n parser,\n });\n Object.keys(stats).forEach(key => {\n totalStats[key] = (totalStats[key] || 0) + stats[key];\n });\n }\n\n const args = ['--parser', parser, '--transform', transformFile, '--no-babel', ...files];\n return await spawnAsync(jscodeshift, args, { stdio: 'inherit' });\n}\n\nasync function listTransformsAsync() {\n const modules = await globby(['*.js'], { cwd: transformDir });\n return modules.map(filename => path.basename(filename, '.js'));\n}\n"]}
@@ -1,2 +0,0 @@
1
- import { API, FileInfo } from 'jscodeshift';
2
- export default function transform(fileInfo: FileInfo, api: API, options: object): string | undefined;
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const namedImports = new Map([
4
- ['Accelerometer', 'expo-sensors'],
5
- ['AdMobBanner', 'expo-ads-admob'],
6
- ['AdMobInterstitial', 'expo-ads-admob'],
7
- ['AdMobRewarded', 'expo-ads-admob'],
8
- ['Asset', 'expo-asset'],
9
- ['Audio', 'expo-av'],
10
- ['BarCodeScanner', 'expo-barcode-scanner'],
11
- ['Barometer', 'expo-sensors'],
12
- ['BlurView', 'expo-blur'],
13
- ['Camera', 'expo-camera'],
14
- ['GLView', 'expo-gl'],
15
- ['Gyroscope', 'expo-sensors'],
16
- ['LinearGradient', 'expo-linear-gradient'],
17
- ['Magnetometer', 'expo-sensors'],
18
- ['MagnetometerUncalibrated', 'expo-sensors'],
19
- ['PublisherBanner', 'expo-ads-admob'],
20
- ['SQLite', 'expo-sqlite'],
21
- ['Video', 'expo-av'],
22
- ['WebView', 'react-native-webview'],
23
- ]);
24
- const defaultImports = new Map([
25
- ['Constants', 'expo-constants'],
26
- ['KeepAwake', 'expo-keep-awake'],
27
- ['MapView', 'react-native-maps'],
28
- ]);
29
- const namespaceImports = new Map([
30
- ['Amplitude', 'expo-analytics-amplitude'],
31
- ['AppAuth', 'expo-app-auth'],
32
- ['BackgroundFetch', 'expo-background-fetch'],
33
- ['Brightness', 'expo-brightness'],
34
- ['Calendar', 'expo-calendar'],
35
- ['Contacts', 'expo-contacts'],
36
- ['Crypto', 'expo-crypto'],
37
- ['DocumentPicker', 'expo-document-picker'],
38
- ['Facebook', 'expo-facebook'],
39
- ['FacebookAds', 'expo-ads-facebook'],
40
- ['FaceDetector', 'expo-face-detector'],
41
- ['FileSystem', 'expo-file-system'],
42
- ['Font', 'expo-font'],
43
- ['GestureHandler', 'react-native-gesture-handler'],
44
- ['GL', 'expo-gl'],
45
- ['GoogleSignIn', 'expo-google-sign-in'],
46
- ['Haptic', 'expo-haptics'],
47
- ['Haptics', 'expo-haptics'],
48
- ['Icon', '@expo/vector-icons'],
49
- ['ImageManipulator', 'expo-image-manipulator'],
50
- ['ImagePicker', 'expo-image-picker'],
51
- ['IntentLauncher', 'expo-intent-launcher'],
52
- ['IntentLauncherAndroid', 'expo-intent-launcher'],
53
- ['LocalAuthentication', 'expo-local-authentication'],
54
- ['Localization', 'expo-localization'],
55
- ['Location', 'expo-location'],
56
- ['MailComposer', 'expo-mail-composer'],
57
- ['MediaLibrary', 'expo-media-library'],
58
- ['Permissions', 'expo-permissions'],
59
- ['Print', 'expo-print'],
60
- ['Random', 'expo-random'],
61
- ['SecureStore', 'expo-secure-store'],
62
- ['Segment', 'expo-analytics-segment'],
63
- ['Sensors', 'expo-sensors'],
64
- ['Sharing', 'expo-sharing'],
65
- ['SMS', 'expo-sms'],
66
- ['Speech', 'expo-speech'],
67
- ['Svg', 'react-native-svg'],
68
- ['TaskManager', 'expo-task-manager'],
69
- ['WebBrowser', 'expo-web-browser'],
70
- ]);
71
- const allDeprecatedImports = new Map();
72
- for (const [name, packageName] of namedImports) {
73
- allDeprecatedImports.set(name, { type: 'ImportSpecifier', packageName });
74
- }
75
- for (const [name, packageName] of defaultImports) {
76
- allDeprecatedImports.set(name, { type: 'ImportDefaultSpecifier', packageName });
77
- }
78
- for (const [name, packageName] of namespaceImports) {
79
- allDeprecatedImports.set(name, { type: 'ImportNamespaceSpecifier', packageName });
80
- }
81
- function transform(fileInfo, api, options) {
82
- const j = api.jscodeshift;
83
- const root = j(fileInfo.source);
84
- const getFirstNode = () => root.find(j.Program).get('body', 0).node;
85
- const originalFirstNode = getFirstNode();
86
- const originalComments = originalFirstNode.comments;
87
- // import { Name } from 'expo';
88
- const expoImports = root
89
- .find(j.ImportDeclaration)
90
- .filter(path => path.node.source.value === 'expo');
91
- const importedModules = new Map();
92
- expoImports
93
- .find(j.ImportSpecifier)
94
- .filter(p => allDeprecatedImports.has(p.node.imported.name))
95
- .forEach(path => {
96
- const importedName = path.node.imported.name;
97
- const local = path.node.local;
98
- importedModules.set(importedName, local !== null && local !== void 0 ? local : null);
99
- j(path).remove();
100
- });
101
- // import * as Expo from 'expo';
102
- expoImports.find(j.ImportNamespaceSpecifier).forEach(path => {
103
- if (path.node.local == null)
104
- return;
105
- const expoNamespace = path.node.local.name;
106
- root
107
- .find(j.MemberExpression)
108
- .filter(p => (p.node.object.type === 'Identifier' || p.node.object.type === 'JSXIdentifier') &&
109
- (p.node.property.type === 'Identifier' || p.node.property.type === 'JSXIdentifier') &&
110
- p.node.object.name === expoNamespace &&
111
- allDeprecatedImports.has(p.node.property.name))
112
- .forEach(p => {
113
- const property = p.node.property;
114
- const importedName = property.name;
115
- importedModules.set(importedName, null);
116
- p.replace(property);
117
- });
118
- });
119
- for (let [importedName, local] of importedModules.entries()) {
120
- local = local || j.identifier(importedName);
121
- const info = allDeprecatedImports.get(importedName);
122
- if (!info) {
123
- return;
124
- }
125
- api.stats(info.packageName);
126
- let specifier;
127
- if (info.type === 'ImportSpecifier') {
128
- specifier = j.importSpecifier(j.identifier(importedName), local);
129
- }
130
- else if (info.type === 'ImportDefaultSpecifier') {
131
- specifier = j.importDefaultSpecifier(local);
132
- }
133
- else {
134
- specifier = j.importNamespaceSpecifier(local);
135
- }
136
- const existingImports = findNonNamespaceImports(j, root, info.packageName);
137
- if (existingImports.size() && specifier.type !== 'ImportNamespaceSpecifier') {
138
- const specifiers = existingImports.get(0).node.specifiers;
139
- specifiers.push(specifier);
140
- specifiers.sort(specifierCompare);
141
- }
142
- else {
143
- const newImport = j.importDeclaration([specifier], j.literal(info.packageName));
144
- expoImports.insertAfter(newImport);
145
- }
146
- }
147
- const emptyImports = expoImports.filter(path => { var _a; return ((_a = path.node.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0; });
148
- emptyImports.remove();
149
- // If the first node has been modified or deleted, reattach the comments
150
- const firstNode = getFirstNode();
151
- if (firstNode !== originalFirstNode) {
152
- firstNode.comments = originalComments;
153
- }
154
- return root.toSource({ quote: 'single' });
155
- }
156
- exports.default = transform;
157
- function findNonNamespaceImports(j, root, sourceName) {
158
- return root.find(j.ImportDeclaration).filter((path) => {
159
- var _a;
160
- const node = path.node;
161
- return (node.source.value === sourceName &&
162
- ((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.some(specifier => specifier.type === 'ImportSpecifier' || specifier.type === 'ImportDefaultSpecifier')));
163
- });
164
- }
165
- function sortableName(specifier) {
166
- if (specifier.local) {
167
- return specifier.local.name;
168
- }
169
- return '';
170
- }
171
- function specifierCompare(a, b) {
172
- return sortableName(a).localeCompare(sortableName(b), 'en');
173
- }
174
- //# sourceMappingURL=sdk33-imports.js.map