Compare commits

...

4 Commits

Author SHA1 Message Date
Brad Anderson
8a2ca6b07f fix: got to no zod errors 2025-05-20 13:31:06 -04:00
Brad Anderson
adb64bcbed chore: zod test before any RN rendering 2025-05-20 00:07:43 -04:00
Brad Anderson
69ba1f9348 chore: metro & babel changes 2025-05-20 00:03:15 -04:00
Brad Anderson
3e48c75cbf chore: fix zod dep across monorepo 2025-05-19 23:58:27 -04:00
7 changed files with 1111 additions and 474 deletions

View File

@@ -0,0 +1,81 @@
// Custom Babel plugin to transform Zod's dynamic class generation
// This makes it more compatible with Hermes
module.exports = function (babel) {
const { types: t } = babel;
return {
name: "transform-zod-multi-fixes",
visitor: {
FunctionDeclaration(path) {
// Part 1: Target Zod's $constructor function
if (path.node.id?.name === "$constructor") {
path.traverse({
CallExpression(callPath) {
const { node } = callPath;
const callee = node.callee;
if (
t.isMemberExpression(callee) &&
t.isIdentifier(callee.object, { name: "Object" }) &&
t.isIdentifier(callee.property, { name: "defineProperty" }) &&
node.arguments.length >= 3 &&
t.isIdentifier(node.arguments[0]) &&
node.arguments[0].name === "_" &&
t.isStringLiteral(node.arguments[1], { value: "name" })
) {
callPath.remove();
}
},
ClassDeclaration(classPath) {
// Ensure we're targeting the class '_' inside $constructor
if (classPath.node.id?.name === "_") {
classPath.traverse({
ClassMethod(methodPath) {
const { node: methodNode } = methodPath; // Renamed to avoid conflict with outer 'node'
if (
methodNode.static &&
methodNode.computed &&
t.isMemberExpression(methodNode.key) &&
t.isIdentifier(methodNode.key.object, {
name: "Symbol",
}) &&
t.isIdentifier(methodNode.key.property, {
name: "hasInstance",
})
) {
methodPath.remove();
}
},
});
}
},
});
}
// Part 2: Target Zod's setFunctionName utility (Temporarily Disabled)
/* if (path.node.id?.name === 'setFunctionName') {
const fnParam = path.node.params[0]; // First parameter, typically 'fn'
if (fnParam && t.isIdentifier(fnParam)) {
const fnParamName = fnParam.name;
path.traverse({
CallExpression(callPath) {
const { node } = callPath;
const callee = node.callee;
if (
t.isMemberExpression(callee) &&
t.isIdentifier(callee.object, { name: 'Object' }) &&
t.isIdentifier(callee.property, { name: 'defineProperty' }) &&
node.arguments.length >= 3 &&
t.isIdentifier(node.arguments[0], { name: fnParamName }) && // Target is the 'fn' param
t.isStringLiteral(node.arguments[1], { value: 'name' })
) {
callPath.remove();
}
}
});
}
} */
},
},
};
};

View File

@@ -1,9 +1,20 @@
module.exports = function (api) {
api.cache(true);
return {
presets: [
["babel-preset-expo", { jsxImportSource: "nativewind" }],
"nativewind/babel",
[
"babel-preset-expo",
{
"@babel/plugin-transform-classes": {
loose: false,
},
},
],
],
plugins: [
// Custom Zod transformer
"./babel-plugin-transform-zod.js",
],
};
};

View File

@@ -1,3 +1,19 @@
// // --- Zod Test Block ---
// import { z } from "zod/v4";
// try {
// console.log("Attempting Zod operation in index.js...");
// const schema = z.string();
// const result = schema.parse("test");
// console.log("Zod operation in index.js successful:", result);
// } catch (e) {
// console.error("Zod operation in index.js FAILED:");
// console.error(e.stack || e);
// // Optionally, re-throw to ensure it's visible if it doesn't crash already
// // throw e;
// }
// // --- End Zod Test Block ---
import "./polyfills";
import { registerRootComponent } from "expo";
import App from "./src/App";

View File

@@ -19,11 +19,34 @@ config.resolver.nodeModulesPaths = [
path.resolve(workspaceRoot, "node_modules"),
];
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
// even though this is true by default, it seems to help zod
// TODO: revisit if we find a smoking gun, and remove if we can
config.resolver.unstable_enablePackageExports = true;
config.resolver.requireCycleIgnorePatterns = [
/(^|\/|\\)node_modules($|\/|\\)/,
/(^|\/|\\)packages($|\/|\\)/,
];
// --- START: Added/Modified section to transpile Zod ---
// Ensure Zod is transformed by Babel along with other necessary React Native packages.
// The pattern below is a common one, with 'zod' added to the list of packages
// that SHOULD be transformed (i.e., not ignored by the transformer).
config.transformer = {
...config.transformer, // Preserve existing transformer settings if any from getDefaultConfig
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true, // Recommended for React Native for performance
},
}),
// This pattern tells Metro to transform Zod and other common RN/Expo packages.
transformIgnorePatterns: [
"node_modules/(?!(react-native|@react-native|@react-native-community|expo|@expo|zod)/)",
],
};
// --- END: Added/Modified section to transpile Zod ---
// Use turborepo to restore the cache when possible
config.cacheStores = [
new FileStore({
@@ -31,5 +54,4 @@ config.cacheStores = [
}),
];
// module.exports = config;
module.exports = withNativeWind(config, { input: "./global.css" });

View File

@@ -36,15 +36,16 @@
"react-dom": "19.0.0",
"react-native": "0.79.2",
"react-native-get-random-values": "^1.11.0",
"react-native-safe-area-context": "5.4.0",
"react-native-screens": "4.10.0",
"react-native-nitro-modules": "0.25.2",
"react-native-quick-crypto": "1.0.0-beta.15",
"react-native-safe-area-context": "5.4.0",
"react-native-screens": "4.10.0",
"react-native-url-polyfill": "^2.0.0",
"readable-stream": "4.7.0"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/plugin-transform-runtime": "^7.27.1",
"@types/react": "~19.0.14",
"tailwindcss": "^3.4.17",
"typescript": "5.8.3"

View File

@@ -50,7 +50,8 @@
"overrides": {
"react": "18.3.1",
"react-dom": "18.3.1",
"esbuild": "0.24.0"
"esbuild": "0.24.0",
"zod": "3.25.0-beta.20250518T002810"
},
"patchedDependencies": {
"expo-router": "patches/expo-router.patch"

1441
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff