react-native-unistyles 3.8.1 → 3.9.0

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.
Files changed (123) hide show
  1. package/README.md +3 -0
  2. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +11 -12
  3. package/cxx/core/Unistyle.h +2 -0
  4. package/cxx/core/UnistyleWrapper.h +2 -1
  5. package/cxx/core/UnistylesRegistry.cpp +13 -1
  6. package/cxx/core/UnistylesRegistry.h +2 -0
  7. package/cxx/hybridObjects/HybridShadowRegistry.cpp +27 -3
  8. package/cxx/parser/Parser.cpp +9 -0
  9. package/cxx/shadowTree/NativeProps.h +47 -14
  10. package/lib/commonjs/components/ScopedTheme.js +22 -8
  11. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  12. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +4 -3
  13. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  14. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
  15. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  16. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +3 -7
  17. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/specs/ShadowRegistry/index.js +7 -10
  20. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  21. package/lib/commonjs/specs/ShadowRegistry/styleSource.js +3 -7
  22. package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -1
  23. package/lib/commonjs/web/registry.js +3 -3
  24. package/lib/commonjs/web/registry.js.map +1 -1
  25. package/lib/module/components/ScopedTheme.js +21 -7
  26. package/lib/module/components/ScopedTheme.js.map +1 -1
  27. package/lib/module/core/useProxifiedUnistyles/listener.native.js +4 -3
  28. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  29. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
  30. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  31. package/lib/module/core/withUnistyles/withUnistyles.native.js +3 -7
  32. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/specs/ShadowRegistry/index.js +7 -10
  35. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  36. package/lib/module/specs/ShadowRegistry/styleSource.js +3 -7
  37. package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -1
  38. package/lib/module/web/registry.js +3 -3
  39. package/lib/module/web/registry.js.map +1 -1
  40. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  41. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  42. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
  43. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
  44. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  45. package/lib/typescript/src/index.d.ts +1 -0
  46. package/lib/typescript/src/index.d.ts.map +1 -1
  47. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  48. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -1
  49. package/metro/index.d.ts +1 -1
  50. package/metro/index.js +8 -4
  51. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  52. package/nitrogen/generated/android/c++/JDimensions.hpp +1 -1
  53. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +1 -1
  54. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +1 -1
  55. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +1 -1
  56. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
  57. package/nitrogen/generated/android/c++/JInsets.hpp +1 -1
  58. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  59. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
  60. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +1 -1
  61. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
  62. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +1 -1
  63. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +1 -1
  64. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +1 -1
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +1 -1
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +1 -1
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +1 -1
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/unistylesOnLoad.kt +1 -1
  71. package/nitrogen/generated/android/unistyles+autolinking.cmake +1 -1
  72. package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
  73. package/nitrogen/generated/android/unistylesOnLoad.cpp +1 -1
  74. package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
  75. package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
  76. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +1 -1
  77. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +1 -1
  78. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -1
  79. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
  80. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
  81. package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
  82. package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
  83. package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +1 -1
  84. package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +1 -1
  85. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
  86. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +3 -3
  87. package/nitrogen/generated/ios/swift/Insets.swift +1 -1
  88. package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
  89. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
  90. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
  91. package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
  92. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
  93. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
  94. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
  95. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
  96. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
  97. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
  98. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
  99. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
  100. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
  101. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
  102. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
  103. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  104. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
  105. package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
  106. package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
  107. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +1 -1
  108. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
  109. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
  110. package/package.json +7 -6
  111. package/plugin/index.d.ts +20 -0
  112. package/plugin/index.js +33 -2
  113. package/repack-plugin/index.d.ts +41 -0
  114. package/repack-plugin/index.js +294 -9
  115. package/src/components/ScopedTheme.tsx +23 -7
  116. package/src/core/useProxifiedUnistyles/listener.native.ts +8 -3
  117. package/src/core/useProxifiedUnistyles/types.ts +1 -1
  118. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +2 -2
  119. package/src/core/withUnistyles/withUnistyles.native.tsx +3 -7
  120. package/src/index.ts +1 -0
  121. package/src/specs/ShadowRegistry/index.ts +8 -11
  122. package/src/specs/ShadowRegistry/styleSource.ts +3 -7
  123. package/src/web/registry.ts +3 -3
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// HybridUnistylesStyleSheetSpec.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// Insets.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// Orientation.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// UnistyleDependency.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// UnistylesCxxMiniRuntime.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
@@ -1,7 +1,7 @@
1
1
  ///
2
2
  /// UnistylesNativeMiniRuntime.hpp
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
4
+ /// https://github.com/margelo/nitro
5
5
  /// Copyright © Marc Rousavy @ Margelo
6
6
  ///
7
7
 
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.8.1",
3
+ "version": "3.9.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
- "test": "NODE_ENV=babel-test jest ./plugin ./metro ./codemods ./src/__tests__",
6
+ "test": "NODE_ENV=babel-test jest ./plugin ./metro ./repack-plugin ./codemods ./src/__tests__",
7
7
  "test:coverage": "NODE_ENV=babel-test jest --passWithNoTests --coverage",
8
- "tsc": "node_modules/typescript/bin/tsc --noEmit",
8
+ "tsc": "node_modules/typescript/bin/tsc --noEmit && node_modules/typescript/bin/tsc --noEmit -p repack-plugin/tsconfig.json",
9
9
  "format": "oxfmt src plugin repack-plugin metro codemods",
10
10
  "lint": "oxlint src plugin repack-plugin metro codemods",
11
11
  "check": "oxfmt src plugin repack-plugin metro codemods && oxlint --fix src plugin repack-plugin metro codemods",
@@ -153,6 +153,7 @@
153
153
  "!repack-plugin/__tests__",
154
154
  "!repack-plugin/src",
155
155
  "!repack-plugin/esbuild.js",
156
+ "!repack-plugin/tsconfig.json",
156
157
  "!plugin/__tests__",
157
158
  "!plugin/src",
158
159
  "!plugin/esbuild.js",
@@ -201,7 +202,6 @@
201
202
  "@babel/core": "7.29.7",
202
203
  "@babel/plugin-syntax-jsx": "7.29.7",
203
204
  "@babel/runtime": "7.29.10",
204
- "@callstack/repack": "5.4.2",
205
205
  "@commitlint/config-conventional": "21.2.4",
206
206
  "@react-native/babel-preset": "0.88.0",
207
207
  "@react-native/jest-preset": "0.88.0",
@@ -210,6 +210,7 @@
210
210
  "@rspack/core": "2.2.9",
211
211
  "@types/jest": "30.0.0",
212
212
  "@types/jscodeshift": "17.3.0",
213
+ "@types/node": "25.3.2",
213
214
  "@types/react": "19.3.0",
214
215
  "babel-plugin-tester": "12.0.0",
215
216
  "commitlint": "21.2.4",
@@ -219,13 +220,13 @@
219
220
  "jest": "30.5.2",
220
221
  "jscodeshift": "17.4.0",
221
222
  "jsdom": "26.1.0",
222
- "nitrogen": "0.37.1",
223
+ "nitrogen": "0.37.2",
223
224
  "oxfmt": "0.74.0",
224
225
  "oxlint": "1.89.0",
225
226
  "react": "19.3.0",
226
227
  "react-native": "0.88.0",
227
228
  "react-native-builder-bob": "0.43.2",
228
- "react-native-nitro-modules": "0.37.1",
229
+ "react-native-nitro-modules": "0.37.2",
229
230
  "react-native-reanimated": "4.7.1",
230
231
  "react-native-web": "0.21.4",
231
232
  "typescript": "6.0.3"
package/plugin/index.d.ts CHANGED
@@ -35,6 +35,14 @@ export interface RemapConfig {
35
35
  imports: Array<RemapImport>
36
36
  }
37
37
 
38
+ /**
39
+ * Options of the Babel plugin `react-native-unistyles/plugin`
40
+ *
41
+ * @deprecated since 3.9.0, removed in 4.0. With Metro use `withUnistylesConfig` from `react-native-unistyles/metro`,
42
+ * with Re.Pack, Rspack or Rsbuild use `UnistylesPlugin` from `react-native-unistyles/repack-plugin`, both have no options.
43
+ * Other bundlers (eg. Next.js, Vite or webpack) don't have a replacement yet, the Babel plugin keeps working in 3.x.
44
+ * See https://www.unistyl.es/v3/other/babel-plugin
45
+ */
38
46
  export interface UnistylesPluginOptions {
39
47
  /**
40
48
  * Required from RC.5
@@ -127,3 +135,15 @@ export interface UnistylesPluginOptions {
127
135
  */
128
136
  localPath?: string
129
137
  }
138
+
139
+ /**
140
+ * The Babel plugin of Unistyles, add it to `plugins` of babel.config.js: `['react-native-unistyles/plugin', { root: 'src' }]`
141
+ *
142
+ * @deprecated since 3.9.0, removed in 4.0. With Metro use `withUnistylesConfig` from `react-native-unistyles/metro`,
143
+ * with Re.Pack, Rspack or Rsbuild use `UnistylesPlugin` from `react-native-unistyles/repack-plugin`.
144
+ * Other bundlers (eg. Next.js, Vite or webpack) don't have a replacement yet, the Babel plugin keeps working in 3.x.
145
+ * See https://www.unistyl.es/v3/other/babel-plugin
146
+ */
147
+ declare function unistylesPlugin(api?: object): { name: string; visitor: object }
148
+
149
+ export default unistylesPlugin
package/plugin/index.js CHANGED
@@ -92,6 +92,36 @@ var NATIVE_COMPONENTS_PATHS = {
92
92
  ]
93
93
  };
94
94
  var METRO_ENV = "UNISTYLES_METRO";
95
+ var RSPACK_INTEGRATION = "rspack";
96
+ var REPACK_LOADER_CALLER = "react-native-unistyles/repack-plugin";
97
+
98
+ // plugin/src/deprecation.ts
99
+ var DEPRECATED = "Unistyles \u{1F984}: react-native-unistyles/plugin is deprecated and will be removed in Unistyles 4.0.";
100
+ var METRO = "With Metro, remove it from babel.config.js and wrap your metro.config.js with withUnistylesConfig from react-native-unistyles/metro, see https://www.unistyl.es/v3/other/metro";
101
+ var RSPACK = "With Re.Pack, Rspack or Rsbuild, use UnistylesPlugin from react-native-unistyles/repack-plugin, see https://www.unistyl.es/v3/other/repack";
102
+ var NO_REPLACEMENT = "Other bundlers (eg. Next.js, Vite or webpack) don't have a replacement yet, the Babel plugin keeps working there in Unistyles 3.x.";
103
+ var getDeprecationMessage = (callerName) => callerName === "metro" ? `${DEPRECATED} ${METRO}` : [DEPRECATED, `${METRO}.`, `${RSPACK}.`, NO_REPLACEMENT].join(" ");
104
+ var hasWarned = false;
105
+ var warnDeprecation = (api) => {
106
+ if (hasWarned) {
107
+ return;
108
+ }
109
+ if (process.env.NODE_ENV === "babel-test") {
110
+ return;
111
+ }
112
+ if (process.env[METRO_ENV]) {
113
+ return;
114
+ }
115
+ if (process.env.JEST_WORKER_ID && process.env.JEST_WORKER_ID !== "1") {
116
+ return;
117
+ }
118
+ const callerName = api?.caller?.((caller) => caller?.name);
119
+ if (callerName === REPACK_LOADER_CALLER) {
120
+ return;
121
+ }
122
+ hasWarned = true;
123
+ console.warn(getDeprecationMessage(callerName));
124
+ };
95
125
 
96
126
  // plugin/src/exotic.ts
97
127
  var t2 = __toESM(require("@babel/types"));
@@ -835,13 +865,14 @@ function extractVariants(path2, state) {
835
865
  }
836
866
 
837
867
  // plugin/src/index.ts
838
- function index_default() {
868
+ function index_default(api) {
839
869
  if (process.env.NODE_ENV === "test") {
840
870
  return {
841
871
  name: "babel-react-native-unistyles",
842
872
  visitor: {}
843
873
  };
844
874
  }
875
+ warnDeprecation(api);
845
876
  return {
846
877
  name: "babel-react-native-unistyles",
847
878
  visitor: {
@@ -849,7 +880,7 @@ function index_default() {
849
880
  enter(path2, state) {
850
881
  if (process.env[METRO_ENV]) {
851
882
  throw new Error(
852
- "Unistyles \u{1F984}: react-native-unistyles/metro is enabled in metro.config.js, remove react-native-unistyles/plugin from babel.config.js"
883
+ process.env[METRO_ENV] === RSPACK_INTEGRATION ? "Unistyles \u{1F984}: UnistylesPlugin of react-native-unistyles/repack-plugin is enabled in your Rspack config, remove react-native-unistyles/plugin from babel.config.js and RepackUnistylePlugin from your Rspack config" : "Unistyles \u{1F984}: react-native-unistyles/metro is enabled in metro.config.js, remove react-native-unistyles/plugin from babel.config.js"
853
884
  );
854
885
  }
855
886
  if (!state.opts.root) {
@@ -1,12 +1,45 @@
1
1
  import type { Compiler, LoaderContext, RspackPluginInstance } from '@rspack/core'
2
2
  import type { UnistylesPluginOptions } from 'react-native-unistyles/plugin'
3
3
 
4
+ /**
5
+ * Experimental, the Re.Pack (Rspack) counterpart of react-native-unistyles/metro,
6
+ * replaces the deprecated `react-native-unistyles/plugin` in babel.config.js and the deprecated `RepackUnistylePlugin`
7
+ *
8
+ * Every `react-native` import (also from node_modules) resolves to Unistyles components,
9
+ * except imports without an issuer and imports made by `@callstack/repack` and `@module-federation` packages,
10
+ * and Unistyles records the dependencies of every StyleSheet while it runs, there is no Babel transform.
11
+ * There is nothing to configure: no `root`, `autoProcessImports`, `autoProcessPaths` or `autoRemapImports`.
12
+ *
13
+ * It requires @rspack/core 1.7.5 or newer.
14
+ * With Module Federation, share `react-native-unistyles` and `react-native-unistyles/` like `react-native`.
15
+ *
16
+ * ```js
17
+ * import * as Repack from '@callstack/repack'
18
+ * import { UnistylesPlugin } from 'react-native-unistyles/repack-plugin'
19
+ *
20
+ * export default {
21
+ * plugins: [new Repack.RepackPlugin(), new UnistylesPlugin()],
22
+ * }
23
+ * ```
24
+ */
25
+ export declare class UnistylesPlugin implements RspackPluginInstance {
26
+ constructor()
27
+ apply(compiler: Compiler): void
28
+ }
29
+
30
+ /**
31
+ * @deprecated since 3.9.0, removed in 4.0, use `UnistylesPlugin`
32
+ */
4
33
  export declare const BASE_REPACK_EXCLUDE_PATHS: Array<RegExp>
34
+
5
35
  interface ConstructorParams {
6
36
  ruleExcludePaths?: Array<RegExp>
7
37
  unistylesPluginOptions?: UnistylesPluginOptions
8
38
  }
9
39
 
40
+ /**
41
+ * @deprecated since 3.9.0, removed in 4.0, use `UnistylesPlugin`
42
+ */
10
43
  export declare class RepackUnistylePlugin implements RspackPluginInstance {
11
44
  private ruleExcludePaths
12
45
  private unistylesPluginOptions
@@ -14,6 +47,14 @@ export declare class RepackUnistylePlugin implements RspackPluginInstance {
14
47
  apply(compiler: Compiler): void
15
48
  }
16
49
 
50
+ interface UnistylesLoaderOptions {
51
+ babelPlugins?: Array<string>
52
+ unistylesPluginOptions?: UnistylesPluginOptions
53
+ }
54
+
55
+ /**
56
+ * The loader of the deprecated `RepackUnistylePlugin`
57
+ */
17
58
  declare function unistylesLoader(this: LoaderContext<UnistylesLoaderOptions>, source: string): void
18
59
 
19
60
  export default unistylesLoader
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // repack-plugin/src/index.ts
@@ -22,13 +32,10 @@ var index_exports = {};
22
32
  __export(index_exports, {
23
33
  BASE_REPACK_EXCLUDE_PATHS: () => BASE_REPACK_EXCLUDE_PATHS,
24
34
  RepackUnistylePlugin: () => RepackUnistylePlugin,
35
+ UnistylesPlugin: () => UnistylesPlugin,
25
36
  default: () => index_default
26
37
  });
27
38
  module.exports = __toCommonJS(index_exports);
28
- var import_repack = require("@callstack/repack");
29
-
30
- // repack-plugin/src/loader.ts
31
- var import_core = require("@babel/core");
32
39
 
33
40
  // plugin/src/consts.ts
34
41
  var REACT_NATIVE_COMPONENT_NAMES = [
@@ -57,6 +64,9 @@ var REPLACE_WITH_UNISTYLES_PATHS = [
57
64
  "react-native-reanimated/src/component",
58
65
  "react-native-reanimated/lib/module/component"
59
66
  ];
67
+ var METRO_ENV = "UNISTYLES_METRO";
68
+ var RSPACK_INTEGRATION = "rspack";
69
+ var REPACK_LOADER_CALLER = "react-native-unistyles/repack-plugin";
60
70
 
61
71
  // repack-plugin/src/loader.ts
62
72
  var importName = "react-native-unistyles";
@@ -74,10 +84,13 @@ function unistylesLoader(source) {
74
84
  const unistylesOptions = options.unistylesPluginOptions;
75
85
  const unistylesPlugin = unistylesOptions ? ["react-native-unistyles/plugin", unistylesOptions] : "react-native-unistyles/plugin";
76
86
  const babelPlugins = options.babelPlugins ?? [];
77
- (0, import_core.transform)(
87
+ const { transform } = require("@babel/core");
88
+ transform(
78
89
  source,
79
90
  {
80
91
  filename: this.resourcePath,
92
+ // the Babel plugin doesn't repeat the deprecation warning of RepackUnistylePlugin
93
+ caller: { name: REPACK_LOADER_CALLER },
81
94
  babelrc: false,
82
95
  configFile: false,
83
96
  compact: false,
@@ -89,14 +102,276 @@ function unistylesLoader(source) {
89
102
  callback(err);
90
103
  return;
91
104
  }
92
- callback(null, result.code, result.map);
105
+ callback(null, result?.code ?? void 0, result?.map);
93
106
  return;
94
107
  }
95
108
  );
96
109
  }
97
110
 
98
- // repack-plugin/src/index.ts
99
- var BASE_REPACK_EXCLUDE_PATHS = (0, import_repack.getModulePaths)([
111
+ // repack-plugin/src/unistylesPlugin.ts
112
+ var import_node_fs2 = __toESM(require("node:fs"));
113
+ var import_node_path2 = __toESM(require("node:path"));
114
+
115
+ // metro/src/resolver.ts
116
+ var import_node_fs = __toESM(require("node:fs"));
117
+ var import_node_path = __toESM(require("node:path"));
118
+ var DEEP_IMPORTS = [...REACT_NATIVE_COMPONENT_NAMES, "ViewNativeComponent", "TextNativeComponent"];
119
+ var PASSTHROUGH_PACKAGES = ["react-native", "@react-native", "react-native-web"];
120
+ var getRealPath = (filePath) => {
121
+ try {
122
+ return import_node_fs.default.realpathSync(filePath);
123
+ } catch {
124
+ return filePath;
125
+ }
126
+ };
127
+ var isSourceFile = (resolution) => resolution.type === "sourceFile" && "filePath" in resolution;
128
+ var createResolveRequest = ({
129
+ unistylesRoot,
130
+ integration,
131
+ upstream,
132
+ path: path2 = import_node_path.default,
133
+ realpath = getRealPath
134
+ }) => {
135
+ const { sep } = path2;
136
+ const sourceDir = path2.join(unistylesRoot, "src");
137
+ const componentsDir = path2.join(sourceDir, "components", "native");
138
+ const componentsIndex = path2.join(componentsDir, "index.ts");
139
+ const trackDependencies = path2.join(sourceDir, "core", "trackDependencies.ts");
140
+ const trackDependenciesWithMetro = path2.join(sourceDir, "core", "trackDependencies.metro.ts");
141
+ const builds = [path2.join(unistylesRoot, "lib", "module"), path2.join(unistylesRoot, "lib", "commonjs")];
142
+ const getSourcePath = (filePath) => {
143
+ const build = builds.find((buildDir) => filePath.startsWith(`${buildDir}${sep}`));
144
+ if (!build) {
145
+ return void 0;
146
+ }
147
+ const modulePath = filePath.slice(build.length + 1).replace(/\.js$/, "").replace(/\.(native|ios|android|web)$/, "");
148
+ return path2.join(sourceDir, modulePath);
149
+ };
150
+ const getPackageName2 = (filePath) => {
151
+ const parts = filePath.split(`${sep}node_modules${sep}`);
152
+ if (parts.length === 1) {
153
+ return void 0;
154
+ }
155
+ const segments = parts.at(-1).split(sep);
156
+ return segments[0]?.startsWith("@") ? `${segments[0]}${sep}${segments[1]}` : segments[0];
157
+ };
158
+ const nestedModules = path2.join(unistylesRoot, "node_modules");
159
+ const shouldSwapFrom = (originModulePath) => {
160
+ if (originModulePath.startsWith(`${unistylesRoot}${sep}`) && !originModulePath.startsWith(`${nestedModules}${sep}`)) {
161
+ return false;
162
+ }
163
+ const packageName = getPackageName2(originModulePath);
164
+ return !PASSTHROUGH_PACKAGES.some((name) => packageName === name || packageName?.startsWith(`${name}${sep}`));
165
+ };
166
+ const getDeepImport = (filePath) => {
167
+ const segments = filePath.split(sep);
168
+ if (segments.at(-5) === "react-native-web" && segments.at(-4) === "dist" && segments.at(-3) === "exports") {
169
+ return segments.at(-2);
170
+ }
171
+ if (filePath.includes(`${sep}react-native${sep}Libraries${sep}`)) {
172
+ return segments.at(-1)?.split(".").at(0);
173
+ }
174
+ return void 0;
175
+ };
176
+ const getSwapTarget = (moduleName, filePath) => {
177
+ if (moduleName === "react-native" || filePath.endsWith(`${sep}react-native-web${sep}dist${sep}index.js`)) {
178
+ return componentsIndex;
179
+ }
180
+ const deepImport = getDeepImport(filePath);
181
+ return deepImport && DEEP_IMPORTS.includes(deepImport) ? path2.join(componentsDir, "deep", `${deepImport}.ts`) : void 0;
182
+ };
183
+ const copies = /* @__PURE__ */ new Map();
184
+ const packageDir = `${sep}node_modules${sep}react-native-unistyles${sep}`;
185
+ const toUnistylesPath = (filePath) => {
186
+ if (filePath.startsWith(`${unistylesRoot}${sep}`)) {
187
+ return filePath;
188
+ }
189
+ const index = filePath.lastIndexOf(packageDir);
190
+ if (index === -1) {
191
+ return filePath;
192
+ }
193
+ const copyRoot = filePath.slice(0, index + packageDir.length - 1);
194
+ if (!copies.has(copyRoot)) {
195
+ const realCopyRoot = realpath(copyRoot);
196
+ copies.set(copyRoot, realCopyRoot);
197
+ if (realCopyRoot !== unistylesRoot) {
198
+ console.warn(
199
+ `Unistyles \u{1F984}: Found a second copy of react-native-unistyles at ${realCopyRoot}, ${integration} handles only ${unistylesRoot}. Styles of the second copy won't update, make sure that your app installs react-native-unistyles once.`
200
+ );
201
+ }
202
+ }
203
+ const copyPath = filePath.slice(copyRoot.length + 1);
204
+ return copies.get(copyRoot) === unistylesRoot && !copyPath.startsWith(`node_modules${sep}`) ? path2.join(unistylesRoot, copyPath) : filePath;
205
+ };
206
+ const withTrackedDependencies = (resolution) => isSourceFile(resolution) && resolution.filePath === trackDependencies ? { type: "sourceFile", filePath: trackDependenciesWithMetro } : resolution;
207
+ return (context, moduleName, platform) => {
208
+ const resolve = upstream ?? context.resolveRequest;
209
+ const upstreamResolution = resolve(context, moduleName, platform);
210
+ if (!isSourceFile(upstreamResolution)) {
211
+ return upstreamResolution;
212
+ }
213
+ const filePath = toUnistylesPath(upstreamResolution.filePath);
214
+ const resolution = filePath === upstreamResolution.filePath ? upstreamResolution : { type: "sourceFile", filePath };
215
+ const sourcePath = getSourcePath(resolution.filePath);
216
+ if (sourcePath) {
217
+ return withTrackedDependencies(resolve(context, sourcePath, platform));
218
+ }
219
+ if (resolution.filePath === trackDependencies) {
220
+ return withTrackedDependencies(resolution);
221
+ }
222
+ if (!shouldSwapFrom(toUnistylesPath(context.originModulePath))) {
223
+ return resolution;
224
+ }
225
+ const swapTarget = getSwapTarget(moduleName, resolution.filePath);
226
+ return swapTarget ? { type: "sourceFile", filePath: swapTarget } : resolution;
227
+ };
228
+ };
229
+
230
+ // repack-plugin/src/unistylesPlugin.ts
231
+ var PLUGIN_NAME = "UnistylesPlugin";
232
+ var COMPONENTS_REQUEST = "react-native-unistyles/components/native";
233
+ var DEEP_COMPONENTS_REQUEST = `${COMPONENTS_REQUEST}/deep`;
234
+ var SWAPPABLE_REQUEST = /^react-native(-web|-unistyles)?($|\/)/;
235
+ var isPassthroughPackage = (packageName) => packageName === "@callstack/repack" || Boolean(packageName?.startsWith("@module-federation/"));
236
+ var MIN_RSPACK_VERSION = [1, 7, 5];
237
+ var isOlderThan = (version, minimum) => {
238
+ const [release = "", ...prerelease] = version.split("+")[0].split("-");
239
+ const parts = release.split(".").map(Number);
240
+ const index = minimum.findIndex((part, partIndex) => part !== (parts[partIndex] ?? 0));
241
+ return index === -1 ? prerelease.length > 0 : (parts[index] ?? 0) < minimum[index];
242
+ };
243
+ var getPackageName = (filePath) => {
244
+ const segments = filePath.split(`${import_node_path2.default.sep}node_modules${import_node_path2.default.sep}`).at(-1).split(import_node_path2.default.sep);
245
+ return segments[0]?.startsWith("@") ? `${segments[0]}/${segments[1]}` : segments[0];
246
+ };
247
+ var getEntryPointAliases = (unistylesRoot) => {
248
+ const { exports: exports2 = {} } = JSON.parse(import_node_fs2.default.readFileSync(import_node_path2.default.join(unistylesRoot, "package.json"), "utf8"));
249
+ return Object.fromEntries(
250
+ Object.entries(exports2).flatMap(([subpath, conditions]) => {
251
+ const source = conditions && typeof conditions === "object" ? conditions["react-native"] : void 0;
252
+ if (typeof source !== "string" || subpath.includes("*") || !/^\.\/src\/.+\.tsx?$/.test(source) || /\.(native|ios|android|web)\.tsx?$/.test(source)) {
253
+ return [];
254
+ }
255
+ return [[`react-native-unistyles${subpath.slice(1)}$`, import_node_path2.default.join(unistylesRoot, source)]];
256
+ })
257
+ );
258
+ };
259
+ var getReactNativeAliases = (alias) => Object.entries(alias || {}).flatMap(([name, targets]) => {
260
+ const [target] = [targets].flat();
261
+ return typeof target === "string" && SWAPPABLE_REQUEST.test(target) && !SWAPPABLE_REQUEST.test(name) ? [{ exact: name.endsWith("$"), name: name.replace(/\$$/, ""), target }] : [];
262
+ });
263
+ var splitQuery = (request) => {
264
+ const index = request.search(/[?#]/);
265
+ return index === -1 ? [request, ""] : [request.slice(0, index), request.slice(index)];
266
+ };
267
+ var UnistylesPlugin = class {
268
+ // replaced in tests
269
+ constructor(unistylesRoot = import_node_fs2.default.realpathSync(import_node_path2.default.join(__dirname, ".."))) {
270
+ this.unistylesRoot = unistylesRoot;
271
+ }
272
+ unistylesRoot;
273
+ apply(compiler) {
274
+ const rspackVersion = compiler.rspack?.rspackVersion;
275
+ if (rspackVersion && isOlderThan(rspackVersion, MIN_RSPACK_VERSION)) {
276
+ throw new Error(
277
+ `Unistyles \u{1F984}: ${PLUGIN_NAME} requires @rspack/core ${MIN_RSPACK_VERSION.join(".")} or newer, found ${rspackVersion}. Older versions share react-native before Unistyles can swap its components.`
278
+ );
279
+ }
280
+ const unistylesRoot = this.unistylesRoot;
281
+ const sourceDir = import_node_path2.default.join(unistylesRoot, "src");
282
+ const componentsIndex = import_node_path2.default.join(sourceDir, "components", "native", "index.ts");
283
+ const deepComponentsDir = import_node_path2.default.join(sourceDir, "components", "native", "deep");
284
+ compiler.options.resolve.alias = {
285
+ ...compiler.options.resolve.alias,
286
+ // the `browser` field and export condition lead to lib/module, the components import src,
287
+ // aliases keep these requests as they are, so Module Federation shares them
288
+ ...getEntryPointAliases(unistylesRoot),
289
+ [`${COMPONENTS_REQUEST}$`]: componentsIndex,
290
+ [DEEP_COMPONENTS_REQUEST]: deepComponentsDir
291
+ };
292
+ const toRequest = (filePath) => {
293
+ if (filePath === componentsIndex) {
294
+ return COMPONENTS_REQUEST;
295
+ }
296
+ return filePath.startsWith(`${deepComponentsDir}${import_node_path2.default.sep}`) ? `${DEEP_COMPONENTS_REQUEST}/${import_node_path2.default.basename(filePath, ".ts")}` : filePath;
297
+ };
298
+ process.env[METRO_ENV] = RSPACK_INTEGRATION;
299
+ const resolveRequest = createResolveRequest({ unistylesRoot, integration: PLUGIN_NAME });
300
+ const unresolvedRequests = /* @__PURE__ */ new Set();
301
+ compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (normalModuleFactory) => {
302
+ const { alias } = compiler.options.resolve;
303
+ const resolver = compiler.resolverFactory.get("normal", { dependencyType: "esm", alias });
304
+ const reactNativeAliases = getReactNativeAliases(alias);
305
+ const getModuleName = (request, issuer) => {
306
+ if (SWAPPABLE_REQUEST.test(request)) {
307
+ return request;
308
+ }
309
+ if (issuer.startsWith(`${unistylesRoot}${import_node_path2.default.sep}`) && request.endsWith("/trackDependencies")) {
310
+ return request;
311
+ }
312
+ for (const { exact, name, target } of reactNativeAliases) {
313
+ if (request === name) {
314
+ return target;
315
+ }
316
+ if (!exact && request.startsWith(`${name}/`)) {
317
+ return `${target}${request.slice(name.length)}`;
318
+ }
319
+ }
320
+ return void 0;
321
+ };
322
+ normalModuleFactory.hooks.beforeResolve.tap(PLUGIN_NAME, (resolveData) => {
323
+ const [request, query] = splitQuery(resolveData.request);
324
+ const issuer = resolveData.contextInfo?.issuer ?? "";
325
+ if (!issuer) {
326
+ return;
327
+ }
328
+ const moduleName = getModuleName(request, issuer);
329
+ if (!moduleName || isPassthroughPackage(getPackageName(issuer))) {
330
+ return;
331
+ }
332
+ let resolvedPath;
333
+ const context = {
334
+ originModulePath: issuer,
335
+ resolveRequest: (_context, name) => {
336
+ const result = resolver.resolveSync({}, resolveData.context, name);
337
+ if (typeof result !== "string") {
338
+ return { type: "empty" };
339
+ }
340
+ const filePath = result.split("?")[0];
341
+ resolvedPath ??= filePath;
342
+ return { type: "sourceFile", filePath };
343
+ }
344
+ };
345
+ let resolution;
346
+ try {
347
+ resolution = resolveRequest(context, moduleName, null);
348
+ } catch (error) {
349
+ if (!unresolvedRequests.has(request)) {
350
+ unresolvedRequests.add(request);
351
+ console.warn(
352
+ `Unistyles \u{1F984}: ${PLUGIN_NAME} couldn't resolve "${request}" imported by ${issuer}, Unistyles doesn't swap it. ${error instanceof Error ? error.message : String(error)}`
353
+ );
354
+ }
355
+ return;
356
+ }
357
+ if (isSourceFile(resolution) && resolution.filePath !== resolvedPath) {
358
+ resolveData.request = `${toRequest(resolution.filePath)}${query}`;
359
+ }
360
+ });
361
+ });
362
+ }
363
+ };
364
+
365
+ // repack-plugin/src/repackUnistylePlugin.ts
366
+ var getModulePaths = (moduleNames) => moduleNames.flatMap((moduleName) => {
367
+ const escapedClassic = moduleName.replace(/[/\\]/g, "[/\\\\]");
368
+ const escapedExotic = moduleName.replace(/[/\\]/g, "\\+");
369
+ return [
370
+ new RegExp(`node_modules([/\\\\])+${escapedClassic}[/\\\\]`),
371
+ new RegExp(`node_modules(.*[/\\\\])+${escapedExotic}[@\\+]`)
372
+ ];
373
+ });
374
+ var BASE_REPACK_EXCLUDE_PATHS = getModulePaths([
100
375
  "react",
101
376
  "react-native",
102
377
  "@react-native",
@@ -131,6 +406,7 @@ var getUnistyleModuleRules = (excludePathLoader, unistylesPluginOptions) => {
131
406
  ]
132
407
  };
133
408
  };
409
+ var hasWarned = false;
134
410
  var RepackUnistylePlugin = class {
135
411
  ruleExcludePaths;
136
412
  unistylesPluginOptions;
@@ -139,12 +415,21 @@ var RepackUnistylePlugin = class {
139
415
  this.unistylesPluginOptions = unistylesPluginOptions;
140
416
  }
141
417
  apply(compiler) {
418
+ if (!hasWarned) {
419
+ hasWarned = true;
420
+ console.warn(
421
+ "Unistyles \u{1F984}: RepackUnistylePlugin is deprecated and will be removed in Unistyles 4.0. Replace it with UnistylesPlugin from react-native-unistyles/repack-plugin, see https://www.unistyl.es/v3/other/repack#migrating-from-repackunistyleplugin"
422
+ );
423
+ }
142
424
  compiler.options.module.rules.push(getUnistyleModuleRules(this.ruleExcludePaths, this.unistylesPluginOptions));
143
425
  }
144
426
  };
427
+
428
+ // repack-plugin/src/index.ts
145
429
  var index_default = unistylesLoader;
146
430
  // Annotate the CommonJS export names for ESM import in node:
147
431
  0 && (module.exports = {
148
432
  BASE_REPACK_EXCLUDE_PATHS,
149
- RepackUnistylePlugin
433
+ RepackUnistylePlugin,
434
+ UnistylesPlugin
150
435
  });