one
Version:
One is a React framework for web, iOS, and Android apps.
1 lines • 5.29 kB
Source Map (JSON)
{"version":3,"file":"kotlinSourceModule.js","names":[],"sources":["esm/vite/plugins/kotlinSourceModule.js"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\nimport { methodSubscribed, methodWired, renderMethodCall, renderViewWires, toNativeSourceStructs } from \"./nativeSourceWires\";\nfunction renderKotlinSourceModule(id, platform, root) {\n if (platform !== \"android\") {\n throw new Error(\n `[one] ${id} is Kotlin source and cannot be imported into an iOS build; use an .ios.ts entry`\n );\n }\n const appManifest = join(root, \"package.json\");\n const app = existsSync(appManifest) ? JSON.parse(readFileSync(appManifest, \"utf8\")) : {};\n const requireFromFile = createRequire(id);\n const { kotlinSourceId, renderKotlinSourceGlue, writeNativeSourceDeclaration } = requireFromFile(\"vxrn/native-source-contract\");\n const contract = writeNativeSourceDeclaration(id);\n const sourceId = kotlinSourceId(root, id);\n if (Object.hasOwn(app.dependencies ?? {}, \"expo\") || Object.hasOwn(app.devDependencies ?? {}, \"expo\")) {\n if (!existsSync(join(root, \"android\", \"app\", \"src\", \"main\", \"java\", \"one\", \"source\", sourceId))) {\n throw new Error(\n `[one] ${id} needs one prebuild, or Expo prebuild with nativeSource enabled in the vxrn config plugin and android generated`\n );\n }\n }\n const hash = renderKotlinSourceGlue(sourceId, contract).hash;\n const oneRoot = dirname(requireFromFile.resolve(\"one/package.json\"));\n const nativeSource = join(oneRoot, \"dist/esm/platform/native-source/index.native.js\");\n const wireModule = join(oneRoot, \"dist/esm/platform/native-source/wire.native.js\");\n const eventsModule = join(oneRoot, \"dist/esm/platform/native-source/events.native.js\");\n const needsWire = contract.modules.some((module) => module.methods.some(methodWired));\n const needsEvents = contract.modules.some((module) => module.methods.some(methodSubscribed));\n const exports = contract.modules.map(\n (module) => `export const ${module.name} = Object.freeze({${module.methods.map((method) => renderMethodCall(`${sourceId}.${module.name}`, method, hash)).join(\",\")}})`\n ).join(\"\\n\");\n const viewHost = join(oneRoot, \"dist/esm/platform/native-source/view.native.js\");\n const views = contract.views.map(\n (view) => `export function ${view.name}(props) { return createElement(KotlinSourceView, { source: ${JSON.stringify(sourceId)}, view: ${JSON.stringify(view.name)}, contractHash: ${JSON.stringify(hash)}, props${renderViewWires(view, contract.structs)} }) }`\n ).join(\"\\n\");\n if (!exports && !views) {\n throw new Error(`[one] ${id} has no OneModule object or public @Composable function to import`);\n }\n const code = [\n exports && `import { callNativeSource } from ${JSON.stringify(nativeSource)}`,\n needsWire && `import { encodeNativeSourceArgs, decodeNativeSourceResult } from ${JSON.stringify(wireModule)}`,\n needsEvents && `import { subscribeNativeSourceEvent } from ${JSON.stringify(eventsModule)}`,\n (needsWire || needsEvents) && `const nativeSourceStructs = ${JSON.stringify(toNativeSourceStructs(contract.structs))}`,\n views && `import { createElement } from 'react'\nimport { KotlinSourceView } from ${JSON.stringify(viewHost)}`,\n exports,\n views\n ].filter(Boolean).join(\"\\n\") + \"\\n\";\n return { code, watchFiles: [id] };\n}\nexport {\n renderKotlinSourceModule\n};\n//# sourceMappingURL=kotlinSourceModule.js.map\n"],"mappings":";;;;;;AAIA,SAAS,yBAAyB,IAAI,UAAU,MAAM;CACpD,IAAI,aAAa,WAAW;EAC1B,MAAM,IAAI,MACR,SAAS,GAAG,iFACd;CACF;CACA,MAAM,cAAc,KAAK,MAAM,cAAc;CAC7C,MAAM,MAAM,WAAW,WAAW,IAAI,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC,IAAI,CAAC;CACvF,MAAM,kBAAkB,cAAc,EAAE;CACxC,MAAM,EAAE,gBAAgB,wBAAwB,iCAAiC,gBAAgB,6BAA6B;CAC9H,MAAM,WAAW,6BAA6B,EAAE;CAChD,MAAM,WAAW,eAAe,MAAM,EAAE;CACxC,IAAI,OAAO,OAAO,IAAI,gBAAgB,CAAC,GAAG,MAAM,KAAK,OAAO,OAAO,IAAI,mBAAmB,CAAC,GAAG,MAAM,G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