expo-codemod 56.0.0 → 56.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.
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codemod: Replace @react-navigation/* imports with expo-router equivalents.
|
|
3
|
-
*
|
|
4
|
-
* Mapping:
|
|
5
|
-
* @react-navigation/native → expo-router
|
|
6
|
-
* @react-navigation/stack → expo-router/js-stack
|
|
7
|
-
* @react-navigation/bottom-tabs → expo-router/js-tabs
|
|
8
|
-
* @react-navigation/material-top-tabs → expo-router/js-top-tabs
|
|
9
|
-
*
|
|
10
|
-
* After replacement, duplicate `expo-router` imports are merged into one.
|
|
11
|
-
*/
|
|
12
1
|
import type { Transform } from 'jscodeshift';
|
|
13
2
|
declare const transform: Transform;
|
|
14
3
|
export default transform;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* Codemod: Replace @react-navigation/* imports with expo-router equivalents.
|
|
8
|
+
*
|
|
9
|
+
* Mapping:
|
|
10
|
+
* @react-navigation/native → expo-router
|
|
11
|
+
* @react-navigation/stack → expo-router/js-stack
|
|
12
|
+
* @react-navigation/bottom-tabs → expo-router/js-tabs
|
|
13
|
+
* @react-navigation/material-top-tabs → expo-router/js-top-tabs
|
|
14
|
+
*
|
|
15
|
+
* Unsupported (no direct equivalent — throws to surface the migration step):
|
|
16
|
+
* @react-navigation/native-stack → use the `Stack` layout from expo-router
|
|
17
|
+
* @react-navigation/drawer → use the `Drawer` layout from expo-router
|
|
18
|
+
*
|
|
19
|
+
* After replacement, duplicate `expo-router` imports are merged into one.
|
|
20
|
+
*/
|
|
21
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
3
22
|
const IMPORT_MAP = {
|
|
4
23
|
'@react-navigation/native': 'expo-router/react-navigation',
|
|
5
24
|
'@react-navigation/elements': 'expo-router/react-navigation',
|
|
@@ -9,10 +28,21 @@ const IMPORT_MAP = {
|
|
|
9
28
|
'@react-navigation/bottom-tabs': 'expo-router/js-tabs',
|
|
10
29
|
'@react-navigation/material-top-tabs': 'expo-router/js-top-tabs',
|
|
11
30
|
};
|
|
31
|
+
const UNSUPPORTED_PACKAGES = {
|
|
32
|
+
'@react-navigation/native-stack': 'Use the `Stack` layout (https://docs.expo.dev/router/advanced/stack/) instead',
|
|
33
|
+
'@react-navigation/drawer': 'Use the `Drawer` layout (https://docs.expo.dev/router/advanced/drawer/) instead',
|
|
34
|
+
};
|
|
12
35
|
const UNSUPPORTED_SPECIFIERS = {
|
|
13
36
|
ImportDefaultSpecifier: 'default import',
|
|
14
37
|
ImportNamespaceSpecifier: 'namespace import (import * as ...)',
|
|
15
38
|
};
|
|
39
|
+
// Prints a prominent, color-formatted error block to stderr.
|
|
40
|
+
const printErrorBlock = (title, lines) => {
|
|
41
|
+
const divider = chalk_1.default.red.bold('━'.repeat(78));
|
|
42
|
+
const heading = chalk_1.default.red.bold(` ${title}`);
|
|
43
|
+
const body = lines.map((line) => chalk_1.default.red(` ${line}`));
|
|
44
|
+
console.error(['', divider, heading, divider, '', ...body, ''].join('\n'));
|
|
45
|
+
};
|
|
16
46
|
const isTypeOnlyImport = (path) => path.node.importKind === 'type';
|
|
17
47
|
/**
|
|
18
48
|
* Clone the specifier, changing its importKind to be type, for example:
|
|
@@ -23,6 +53,24 @@ const markAsInlineType = (spec) => {
|
|
|
23
53
|
clone.importKind = 'type';
|
|
24
54
|
return clone;
|
|
25
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Collects errors for imports from packages that have no direct expo-router
|
|
58
|
+
* equivalent (e.g. `@react-navigation/native-stack`, `@react-navigation/drawer`).
|
|
59
|
+
* These require a structural migration to the file-based `Stack`/`Drawer`
|
|
60
|
+
* layouts and cannot be rewritten automatically.
|
|
61
|
+
*/
|
|
62
|
+
const collectUnsupportedPackageErrors = (filePath, paths) => {
|
|
63
|
+
const errors = [];
|
|
64
|
+
for (const declarationPath of paths) {
|
|
65
|
+
const sourceModule = declarationPath.node.source.value;
|
|
66
|
+
const message = UNSUPPORTED_PACKAGES[sourceModule];
|
|
67
|
+
if (!message)
|
|
68
|
+
continue;
|
|
69
|
+
const line = declarationPath.node.loc?.start.line ?? '?';
|
|
70
|
+
errors.push(`${filePath}:${line} - import from "${sourceModule}" cannot be migrated. ${message}`);
|
|
71
|
+
}
|
|
72
|
+
return errors;
|
|
73
|
+
};
|
|
26
74
|
/**
|
|
27
75
|
* Collects errors for unsupported import styles in the given declarations:
|
|
28
76
|
* default imports (`import A from "b"`) and namespace imports
|
|
@@ -39,8 +87,11 @@ const collectUnsupportedImportStyleErrors = (filePath, paths) => {
|
|
|
39
87
|
continue;
|
|
40
88
|
const line = declarationPath.node.loc?.start.line ?? '?';
|
|
41
89
|
const sourceModule = declarationPath.node.source.value;
|
|
42
|
-
errors.push(
|
|
43
|
-
|
|
90
|
+
errors.push([
|
|
91
|
+
`${filePath}:${line} - ${label} from "${sourceModule}" is not supported.`,
|
|
92
|
+
'Only named imports can be rewritten by this codemod.',
|
|
93
|
+
'Replace this import with named imports and re-run the codemod.',
|
|
94
|
+
].join('\n'));
|
|
44
95
|
}
|
|
45
96
|
}
|
|
46
97
|
return errors;
|
|
@@ -80,6 +131,14 @@ const mergeGroup = (j, groupPaths) => {
|
|
|
80
131
|
const transform = (fileInfo, api) => {
|
|
81
132
|
const j = api.jscodeshift;
|
|
82
133
|
const root = j(fileInfo.source);
|
|
134
|
+
const unsupportedPackagePaths = root
|
|
135
|
+
.find(j.ImportDeclaration)
|
|
136
|
+
.filter((path) => path.node.source.value in UNSUPPORTED_PACKAGES)
|
|
137
|
+
.paths();
|
|
138
|
+
const unsupportedPackageErrors = collectUnsupportedPackageErrors(fileInfo.path, unsupportedPackagePaths);
|
|
139
|
+
if (unsupportedPackageErrors.length) {
|
|
140
|
+
printErrorBlock('Migration required — manual change needed', unsupportedPackageErrors);
|
|
141
|
+
}
|
|
83
142
|
const mappablePaths = root
|
|
84
143
|
.find(j.ImportDeclaration)
|
|
85
144
|
.filter((path) => path.node.source.value in IMPORT_MAP)
|
|
@@ -87,8 +146,11 @@ const transform = (fileInfo, api) => {
|
|
|
87
146
|
if (mappablePaths.length === 0)
|
|
88
147
|
return undefined;
|
|
89
148
|
const errors = collectUnsupportedImportStyleErrors(fileInfo.path, mappablePaths);
|
|
90
|
-
if (errors.length
|
|
91
|
-
|
|
149
|
+
if (errors.length) {
|
|
150
|
+
printErrorBlock('Unsupported import style — manual change needed', errors);
|
|
151
|
+
}
|
|
152
|
+
if (unsupportedPackageErrors.length || errors.length) {
|
|
153
|
+
return undefined;
|
|
92
154
|
}
|
|
93
155
|
for (const path of mappablePaths) {
|
|
94
156
|
const sourceModule = path.node.source.value;
|
|
@@ -1 +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":"
|
|
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":";;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,kDAA0B;AAoB1B,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,oBAAoB,GAA2B;IACnD,gCAAgC,EAC9B,+EAA+E;IACjF,0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AC;IACjF,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,eAAe,CAAC,iDAAiD,EAAE,MAAM,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,wBAAwB,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACrD,OAAO,SAAS,CAAC;IACnB,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-codemod",
|
|
3
|
-
"version": "56.0.
|
|
3
|
+
"version": "56.0.2",
|
|
4
4
|
"description": "Codemods for migrating Expo apps between SDK versions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -26,15 +26,6 @@
|
|
|
26
26
|
"bin",
|
|
27
27
|
"build"
|
|
28
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
29
|
"engines": {
|
|
39
30
|
"node": ">=18"
|
|
40
31
|
},
|
|
@@ -46,7 +37,15 @@
|
|
|
46
37
|
"devDependencies": {
|
|
47
38
|
"@types/jscodeshift": "^17.0.0",
|
|
48
39
|
"@types/node": "^22.14.0",
|
|
49
|
-
"expo-module-scripts": "56.0.
|
|
40
|
+
"expo-module-scripts": "56.0.2"
|
|
50
41
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
-
|
|
42
|
+
"gitHead": "a30353e69ca0d72b9fac5830abc631feda1ba3ae",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "expo-module tsc",
|
|
45
|
+
"clean": "expo-module clean",
|
|
46
|
+
"lint": "expo-module lint",
|
|
47
|
+
"typecheck": "expo-module typecheck",
|
|
48
|
+
"test": "expo-module test",
|
|
49
|
+
"watch": "pnpm run build --watch --preserveWatchOutput"
|
|
50
|
+
}
|
|
51
|
+
}
|