@porotkin/vite-plugin-react-kotlinjs 1.0.4 → 1.0.6

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
@@ -7,7 +7,7 @@ A Vite plugin that enables Fast Refresh support for Kotlin/JS React applications
7
7
  Add the following dependency to your `build.gradle.kts`:
8
8
  ```kotlin
9
9
  dependencies {
10
- jsMainImplementation(devNpm("@porotkin/vite-plugin-react-kotlinjs", "^1.0.4"))
10
+ jsMainImplementation(devNpm("@porotkin/vite-plugin-react-kotlinjs", "^1.0.6"))
11
11
  }
12
12
  ```
13
13
 
@@ -46,6 +46,12 @@ Custom function to check if the code is a React functional component.
46
46
 
47
47
  Custom function to extract React component names from the code. Useful if your Kotlin/JS compiler generates different patterns.
48
48
 
49
+ ### `debug`
50
+
51
+ - **Type:** `boolean`
52
+
53
+ Output debug information about the transformed files.
54
+
49
55
  ## How it works
50
56
 
51
57
  Plugin post-processes generated Kotlin/JS files, so the official Vite React plugin can handle them.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
- import { Plugin } from "vite";
2
-
3
1
  //#region src/index.d.ts
4
2
  interface Options {
5
3
  isReactFC?: (code: string) => boolean;
6
4
  getComponentName?: (code: string) => string | undefined;
5
+ debug?: boolean;
7
6
  }
8
- declare const _default: (options?: Options) => Plugin;
7
+ declare const _default: (options?: Options) => {
8
+ name: string;
9
+ enforce: string;
10
+ apply: string;
11
+ transform(code: string, id: string): {
12
+ code: string;
13
+ map: null;
14
+ };
15
+ };
9
16
  //#endregion
10
17
  export { Options, _default as default };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  //#region src/index.ts
2
2
  const REACT_PLUGIN_ENABLER = `\nconst $$$___$$$___$$$ = "react/jsx-dev-runtime"\n`;
3
3
  var src_default = (options) => {
4
- const { isReactFC = (code) => code.includes("kotlin-react-core/react/ChildrenBuilder.mjs"), getComponentName = (code) => /export {(?:.|\s)*get_([A-Za-z]+) as get_(?:.|\s)*}/.exec(code)?.[1] } = options ?? {};
4
+ const { isReactFC = (code) => code.includes("kotlin-react/react/ChildrenBuilder.mjs"), getComponentName = (code) => /export {(?:.|\s)*get_([A-Za-z]+) as get_(?:.|\s)*}/.exec(code)?.[1], debug = false } = options ?? {};
5
5
  return {
6
6
  name: "vite:react-plugin-kotlinjs",
7
7
  enforce: "pre",
8
8
  apply: "serve",
9
- transform(code) {
9
+ transform(code, id) {
10
10
  if (!isReactFC(code)) return {
11
11
  code,
12
12
  map: null
@@ -16,8 +16,10 @@ var src_default = (options) => {
16
16
  code,
17
17
  map: null
18
18
  };
19
+ const transformedCode = code.replace(`function get_${componentName}() {`, `function Get${componentName}() {`).replace(`get_${componentName} as get_`, `Get${componentName} as get_`);
20
+ if (debug) console.log(`[vite-plugin-react-kotlinjs] transformed: ${id}`);
19
21
  return {
20
- code: code.replace(`function get_${componentName}() {`, `function Get${componentName}() {`).replace(`get_${componentName} as get_`, `Get${componentName} as get_`) + REACT_PLUGIN_ENABLER,
22
+ code: transformedCode + REACT_PLUGIN_ENABLER,
21
23
  map: null
22
24
  };
23
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porotkin/vite-plugin-react-kotlinjs",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Support React fast refresh in Kotlin/JS",
5
5
  "license": "MIT",
6
6
  "author": "Mikhail Porotkin",