react-native-unistyles 3.8.2 → 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.
- package/README.md +3 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +8 -2
- package/cxx/core/Unistyle.h +2 -0
- package/cxx/core/UnistyleWrapper.h +2 -1
- package/cxx/core/UnistylesRegistry.cpp +12 -0
- package/cxx/core/UnistylesRegistry.h +2 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +23 -1
- package/cxx/parser/Parser.cpp +9 -0
- package/cxx/shadowTree/NativeProps.h +47 -14
- package/lib/commonjs/components/ScopedTheme.js +22 -8
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +4 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +3 -7
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +7 -10
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js +3 -7
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -1
- package/lib/commonjs/web/registry.js +3 -3
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/module/components/ScopedTheme.js +21 -7
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +4 -3
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +3 -7
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +7 -10
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/styleSource.js +3 -7
- package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -1
- package/lib/module/web/registry.js +3 -3
- package/lib/module/web/registry.js.map +1 -1
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -1
- package/metro/index.d.ts +1 -1
- package/metro/index.js +8 -4
- package/package.json +5 -4
- package/plugin/index.d.ts +20 -0
- package/plugin/index.js +33 -2
- package/repack-plugin/index.d.ts +41 -0
- package/repack-plugin/index.js +294 -9
- package/src/components/ScopedTheme.tsx +23 -7
- package/src/core/useProxifiedUnistyles/listener.native.ts +8 -3
- package/src/core/useProxifiedUnistyles/types.ts +1 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +2 -2
- package/src/core/withUnistyles/withUnistyles.native.tsx +3 -7
- package/src/specs/ShadowRegistry/index.ts +8 -11
- package/src/specs/ShadowRegistry/styleSource.ts +3 -7
- package/src/web/registry.ts +3 -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) {
|
package/repack-plugin/index.d.ts
CHANGED
|
@@ -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
|
package/repack-plugin/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
105
|
+
callback(null, result?.code ?? void 0, result?.map);
|
|
93
106
|
return;
|
|
94
107
|
}
|
|
95
108
|
);
|
|
96
109
|
}
|
|
97
110
|
|
|
98
|
-
// repack-plugin/src/
|
|
99
|
-
var
|
|
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
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
2
|
|
|
3
3
|
import type { UnistylesThemes } from '../global'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useUnistyles } from '../core'
|
|
6
6
|
import { AdaptiveTheme } from './AdaptiveTheme'
|
|
7
7
|
import { NamedTheme } from './NamedTheme'
|
|
8
|
+
import { ScopedThemeContext } from './ScopedThemeContext'
|
|
8
9
|
|
|
9
10
|
type ThemeProps =
|
|
10
11
|
| {
|
|
@@ -23,15 +24,30 @@ type ThemeProps =
|
|
|
23
24
|
reset: boolean
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
interface InvertedAdaptiveThemeProps extends React.PropsWithChildren {
|
|
28
|
+
previousScopedTheme?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const InvertedAdaptiveTheme: React.FunctionComponent<InvertedAdaptiveThemeProps> = ({
|
|
32
|
+
children,
|
|
33
|
+
previousScopedTheme,
|
|
34
|
+
}) => {
|
|
35
|
+
const { rt } = useUnistyles()
|
|
36
|
+
|
|
37
|
+
if (!rt.hasAdaptiveThemes) {
|
|
38
|
+
return children
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <AdaptiveTheme previousScopedTheme={previousScopedTheme}>{children}</AdaptiveTheme>
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({
|
|
27
45
|
name,
|
|
28
46
|
children,
|
|
29
47
|
invertedAdaptive,
|
|
30
48
|
reset,
|
|
31
49
|
}) => {
|
|
32
|
-
const
|
|
33
|
-
const isAdaptiveTheme = invertedAdaptive && hasAdaptiveThemes
|
|
34
|
-
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
|
50
|
+
const previousScopedTheme = useContext(ScopedThemeContext)?.name
|
|
35
51
|
|
|
36
52
|
switch (true) {
|
|
37
53
|
case name !== undefined:
|
|
@@ -40,8 +56,8 @@ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeP
|
|
|
40
56
|
{children}
|
|
41
57
|
</NamedTheme>
|
|
42
58
|
)
|
|
43
|
-
case
|
|
44
|
-
return <
|
|
59
|
+
case invertedAdaptive:
|
|
60
|
+
return <InvertedAdaptiveTheme previousScopedTheme={previousScopedTheme}>{children}</InvertedAdaptiveTheme>
|
|
45
61
|
case reset:
|
|
46
62
|
return (
|
|
47
63
|
<NamedTheme name={undefined} previousScopedTheme={previousScopedTheme}>
|
|
@@ -2,6 +2,9 @@ import type { ListenerProps } from './types'
|
|
|
2
2
|
|
|
3
3
|
import { StyleSheet, UnistyleDependency } from '../../specs'
|
|
4
4
|
|
|
5
|
+
const isThemeDependency = (dependency: UnistyleDependency) =>
|
|
6
|
+
dependency === UnistyleDependency.Theme || dependency === UnistyleDependency.ThemeName
|
|
7
|
+
|
|
5
8
|
export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
|
|
6
9
|
const listensToTheme = dependencies.includes(UnistyleDependency.Theme)
|
|
7
10
|
const dispose = StyleSheet.addChangeListener((changedDependencies) => {
|
|
@@ -9,10 +12,12 @@ export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerP
|
|
|
9
12
|
updateTheme()
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const changedListenedDependencies = changedDependencies.filter((dependency: UnistyleDependency) =>
|
|
16
|
+
dependencies.includes(dependency),
|
|
17
|
+
)
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
if (changedListenedDependencies.length > 0) {
|
|
20
|
+
updateRuntime(changedListenedDependencies.every(isThemeDependency))
|
|
16
21
|
}
|
|
17
22
|
})
|
|
18
23
|
|
|
@@ -52,8 +52,8 @@ export const useProxifiedUnistyles = () => {
|
|
|
52
52
|
|
|
53
53
|
setTheme(UnistylesRuntime.getTheme(scopedTheme))
|
|
54
54
|
},
|
|
55
|
-
updateRuntime: (
|
|
56
|
-
if (
|
|
55
|
+
updateRuntime: (isThemeChangeOnly: boolean) => {
|
|
56
|
+
if (isThemeChangeOnly && scopedTheme) {
|
|
57
57
|
return
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -144,11 +144,9 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
|
144
144
|
const [, stylesChanged] = useReducer(() => ({}), {})
|
|
145
145
|
|
|
146
146
|
const getScopedSecrets = () => {
|
|
147
|
-
const previousScopedTheme =
|
|
147
|
+
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
UnistylesShadowRegistry.setScopedTheme(scope.name)
|
|
151
|
-
}
|
|
149
|
+
UnistylesShadowRegistry.setScopedTheme(scope?.name)
|
|
152
150
|
|
|
153
151
|
try {
|
|
154
152
|
const styleSecrets = getSecrets(narrowedProps.style)
|
|
@@ -156,9 +154,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
|
156
154
|
|
|
157
155
|
return { styleSecrets, contentContainerStyleSecrets }
|
|
158
156
|
} finally {
|
|
159
|
-
|
|
160
|
-
UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
161
|
-
}
|
|
157
|
+
UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
162
158
|
}
|
|
163
159
|
}
|
|
164
160
|
|