@porotkin/vite-plugin-react-kotlinjs 0.0.1 → 0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porotkin/vite-plugin-react-kotlinjs",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Support React fast refresh in Kotlin/JS",
5
5
  "license": "MIT",
6
6
  "author": "Mikhail Porotkin",
package/src/index.js CHANGED
@@ -16,7 +16,7 @@ export default (options) => {
16
16
 
17
17
  const derivedOptions = {
18
18
  skipFastRefresh: true,
19
- getComponentName: (code) => code.match(/function ([A-Za-z]+)\$lambda\(\$this\$FC\) {/)?.[1],
19
+ getComponentName: (code) => code.match(/function ([A-Za-z]+)\$lambda\(\$this\$FC(, props)?\) {/)?.[1],
20
20
  filter,
21
21
  ...options,
22
22
  };
@@ -8,16 +8,27 @@ window.$RefreshSig$ = () => (type) => type;`
8
8
 
9
9
  export const getPreambleCode = () => preambleCode
10
10
 
11
+ function capitalize(str) {
12
+ if (!str) return '';
13
+ return str.charAt(0).toUpperCase() + str.slice(1);
14
+ }
15
+
11
16
  export function addRefreshWrapper(code, pluginName, id, getComponentName) {
12
17
  const componentName = getComponentName?.(code)
13
18
  if (!componentName) return code;
14
19
 
20
+ const packageName = id.split('/kotlin/').pop()
21
+ .replace(`${componentName}.mjs`, '')
22
+ .split(/[\/\\-]/g)
23
+ .map(part => capitalize(part))
24
+ .join('')
25
+
15
26
  const registerHmr = `
16
27
  import * as RefreshRuntime from "${runtimePublicPath}";
17
28
  const inWebWorker = typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
18
29
  if (import.meta.hot && !inWebWorker) {
19
30
  const component = get_${componentName}?.()
20
- $RefreshReg$(component, "${componentName}")
31
+ $RefreshReg$(component, "${componentName + packageName}")
21
32
  RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
22
33
  RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
23
34
  import.meta.hot.accept((nextExports) => {