@porotkin/vite-plugin-react-kotlinjs 0.0.8 → 1.0.1

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/README.md CHANGED
@@ -10,7 +10,7 @@ This plugin is inspired by the original
10
10
  Add the following dependency to your `build.gradle.kts`:
11
11
  ```kotlin
12
12
  dependencies {
13
- jsMainImplementation(devNpm("@porotkin/vite-plugin-react-kotlinjs", "^0.0.8"))
13
+ jsMainImplementation(devNpm("@porotkin/vite-plugin-react-kotlinjs", "^1.0.1"))
14
14
  }
15
15
  ```
16
16
 
@@ -0,0 +1,10 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region src/index.d.ts
4
+ interface Options {
5
+ isReactFC?: (code: string) => boolean;
6
+ getComponentName?: (code: string) => string | undefined;
7
+ }
8
+ declare const _default: (options?: Options) => Plugin;
9
+ //#endregion
10
+ export { Options, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ //#region src/index.ts
2
+ const REACT_PLUGIN_ENABLER = `const $$$___$$$___$$$ = "react/jsx-dev-runtime"\n`;
3
+ var src_default = (options) => {
4
+ const { isReactFC = (code) => code.includes("kotlin-react-core/react/ChildrenBuilder.mjs"), getComponentName = (code) => /^function get_([A-Za-z]+)\(\) {$/m.exec(code)?.[1] } = options ?? {};
5
+ return {
6
+ name: "vite:react-plugin-kotlinjs",
7
+ enforce: "pre",
8
+ transform(code) {
9
+ if (!isReactFC(code)) return {
10
+ code,
11
+ map: null
12
+ };
13
+ const componentName = getComponentName(code);
14
+ if (!componentName) return {
15
+ code,
16
+ map: null
17
+ };
18
+ return {
19
+ code: code.replace(`function get_${componentName}() {`, `function Get${componentName}() {`).replace(`get_${componentName} as get_`, `Get${componentName} as get_`) + REACT_PLUGIN_ENABLER,
20
+ map: null
21
+ };
22
+ }
23
+ };
24
+ };
25
+
26
+ //#endregion
27
+ export { src_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porotkin/vite-plugin-react-kotlinjs",
3
- "version": "0.0.8",
3
+ "version": "1.0.1",
4
4
  "description": "Support React fast refresh in Kotlin/JS",
5
5
  "license": "MIT",
6
6
  "author": "Mikhail Porotkin",