@stylexswc/rs-compiler 0.11.1 → 0.11.2-rc.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
@@ -53,7 +53,7 @@ Internally, this compiler takes your StyleX code and transforms it into a format
53
53
  optimized for further processing.
54
54
 
55
55
  ```ts
56
- var { transform } = require('@stylexswc/compiler-rs');
56
+ var { transform } = require('@stylexswc/rs-compiler');
57
57
 
58
58
  /// ...other logic
59
59
 
@@ -66,6 +66,100 @@ const { code, metadata, sourcemap } = transform(
66
66
  /// ...other logic
67
67
  ```
68
68
 
69
+ ### Path Filtering
70
+
71
+ > [!NOTE]
72
+ > **New Feature:** The `include` and `exclude` options are exclusive to this NAPI-RS compiler implementation and are not available in the official StyleX Babel plugin. They provide powerful file filtering capabilities to control which files are transformed.
73
+
74
+ The compiler exports a `shouldTransformFile` function to determine whether a file should be transformed based on include/exclude patterns:
75
+
76
+ ```ts
77
+ import { shouldTransformFile } from '@stylexswc/rs-compiler';
78
+
79
+ const shouldTransform = shouldTransformFile(
80
+ '/path/to/file.tsx',
81
+ ['src/**/*.{ts,tsx}'], // include patterns (optional)
82
+ ['**/*.test.*', '**/__tests__/**'] // exclude patterns (optional)
83
+ );
84
+
85
+ if (shouldTransform) {
86
+ // Transform the file
87
+ }
88
+ ```
89
+
90
+ #### Pattern Types
91
+
92
+ - **Glob patterns** (strings): Use standard glob syntax to match file paths
93
+ - `src/**/*.tsx` - All `.tsx` files in `src` directory and subdirectories
94
+ - `**/*.test.*` - All test files
95
+ - `**/node_modules/**` - All files in `node_modules`
96
+
97
+ - **Regular expressions**: Use RegExp objects for complex pattern matching
98
+ - `/\.test\./` - Files containing `.test.`
99
+ - `/^src\/.*\.tsx$/` - `.tsx` files directly in the `src` directory
100
+
101
+ **Advanced: Lookahead/Lookbehind Support**
102
+
103
+ The Rust regex engine fully supports lookahead and lookbehind assertions, enabling sophisticated filtering patterns:
104
+
105
+ - **Negative Lookahead** `(?!...)`: Match if NOT followed by pattern
106
+ - `/node_modules(?!\/@stylexjs)/` - Exclude all node_modules except @stylexjs packages
107
+ - `/\.tsx(?!\.test)/` - Match .tsx files that are NOT test files
108
+
109
+ - **Positive Lookahead** `(?=...)`: Match if followed by pattern
110
+ - `/.*\.test(?=\.tsx$)/` - Match only .test.tsx files
111
+
112
+ - **Negative Lookbehind** `(?<!...)`: Match if NOT preceded by pattern
113
+ - `/(?<!src\/).*\.tsx$/` - Exclude .tsx files not in src/
114
+
115
+ - **Positive Lookbehind** `(?<=...)`: Match if preceded by pattern
116
+ - `/(?<=components\/).*\.tsx$/` - Match only .tsx files in components/
117
+
118
+ #### Filtering Rules
119
+
120
+ 1. If `include` patterns are specified and not empty, files must match at least one pattern
121
+ 2. If `exclude` patterns are specified, files matching any pattern are excluded
122
+ 3. Exclude patterns take precedence over include patterns
123
+ 4. All paths are matched relative to the current working directory
124
+
125
+ #### Common Use Cases
126
+
127
+ **Exclude all node_modules except specific packages:**
128
+
129
+ ```ts
130
+ // Exclude all node_modules except @stylexjs/open-props
131
+ shouldTransformFile(
132
+ filePath,
133
+ undefined,
134
+ [/node_modules(?!\/@stylexjs\/open-props)/]
135
+ );
136
+ ```
137
+
138
+ **Transform only specific packages from node_modules:**
139
+
140
+ ```ts
141
+ shouldTransformFile(
142
+ filePath,
143
+ [
144
+ 'src/**/*.{ts,tsx}',
145
+ 'node_modules/@stylexjs/open-props/**/*.js',
146
+ 'node_modules/@my-org/design-system/**/*.js',
147
+ ],
148
+ ['**/*.test.*']
149
+ );
150
+ ```
151
+
152
+ **Exclude multiple node_modules packages except a few:**
153
+
154
+ ```ts
155
+ // Exclude all node_modules except @stylexjs packages
156
+ shouldTransformFile(
157
+ filePath,
158
+ undefined,
159
+ [/node_modules(?!\/@stylexjs)/]
160
+ );
161
+ ```
162
+
69
163
  ### Output
70
164
 
71
165
  The output from the compiler includes the transformed code, metadata about the
@@ -144,6 +238,7 @@ You can enable debug logging for the StyleX compiler using the `STYLEX_DEBUG` en
144
238
  ### Log Levels
145
239
 
146
240
  The following log levels are available:
241
+
147
242
  - `error`: Only shows error messages
148
243
  - `warn`: Shows warnings and errors (default)
149
244
  - `info`: Shows informational messages, warnings, and errors
@@ -163,11 +258,13 @@ STYLEX_DEBUG=trace npm run dev
163
258
  ```
164
259
 
165
260
  For Windows Command Prompt:
261
+
166
262
  ```cmd
167
263
  set STYLEX_DEBUG=debug && npm run build
168
264
  ```
169
265
 
170
266
  For PowerShell:
267
+
171
268
  ```powershell
172
269
  $env:STYLEX_DEBUG="debug"; npm run build
173
270
  ```
package/dist/index.d.ts CHANGED
@@ -46,6 +46,8 @@ export interface StyleXOptions {
46
46
  aliases?: Record<string, string[]>
47
47
  unstable_moduleResolution?: StyleXModuleResolution
48
48
  sourceMap?: SourceMaps
49
+ include?: Array<string | RegExp>
50
+ exclude?: Array<string | RegExp>
49
51
  }
50
52
  export interface StyleXMetadata {
51
53
  stylex: ([string, { ltr: string; rtl?: null | string }, number])[]
@@ -56,4 +58,5 @@ export interface StyleXTransformResult {
56
58
  map?: string
57
59
  }
58
60
  export declare function transform(filename: string, code: string, options: StyleXOptions): StyleXTransformResult
61
+ export declare function shouldTransformFile(filePath: string, include?: Array<unknown> | undefined | null, exclude?: Array<unknown> | undefined | null): boolean
59
62
  export declare function normalizeRsOptions(options: StyleXOptions): StyleXOptions
package/dist/index.js CHANGED
@@ -310,8 +310,9 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { SourceMaps, transform, normalizeRsOptions } = nativeBinding
313
+ const { SourceMaps, transform, shouldTransformFile, normalizeRsOptions } = nativeBinding
314
314
 
315
315
  module.exports.SourceMaps = SourceMaps
316
316
  module.exports.transform = transform
317
+ module.exports.shouldTransformFile = shouldTransformFile
317
318
  module.exports.normalizeRsOptions = normalizeRsOptions
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stylexswc/rs-compiler",
3
3
  "description": "NAPI-RS compiler for transform StyleX code",
4
- "version": "0.11.1",
4
+ "version": "0.11.2-rc.1",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "files": [
@@ -23,20 +23,20 @@
23
23
  "@napi-rs/cli": "^2.18.4",
24
24
  "@stylexjs/open-props": "^0.11.1",
25
25
  "@stylexjs/stylex": "^0.15.4",
26
- "@stylexswc/shared": "0.11.1",
27
- "@swc-node/register": "^1.10.10",
26
+ "@stylexswc/shared": "0.11.2-rc.1",
27
+ "@swc-node/register": "^1.11.1",
28
28
  "@swc/core": "^1.13.3",
29
29
  "@taplo/cli": "^0.7.0",
30
- "@types/node": "^24.1.0",
30
+ "@types/node": "^24.7.2",
31
31
  "ava": "^6.4.1",
32
32
  "benchmark": "^2.1.4",
33
- "chalk": "^5.4.1",
34
- "lint-staged": "^16.1.2",
33
+ "chalk": "^5.6.2",
34
+ "lint-staged": "^16.2.3",
35
35
  "npm-run-all2": "^8.0.4",
36
36
  "oxlint": "^0.17.0",
37
37
  "prettier": "^3.6.2",
38
38
  "tinybench": "^4.0.1",
39
- "typescript": "^5.9.2"
39
+ "typescript": "^5.9.3"
40
40
  },
41
41
  "ava": {
42
42
  "extensions": {
@@ -80,13 +80,13 @@
80
80
  },
81
81
  "repository": "https://github.com/Dwlad90/stylex-swc-plugin",
82
82
  "optionalDependencies": {
83
- "@stylexswc/rs-compiler-win32-x64-msvc": "0.11.1",
84
- "@stylexswc/rs-compiler-darwin-x64": "0.11.1",
85
- "@stylexswc/rs-compiler-linux-x64-gnu": "0.11.1",
86
- "@stylexswc/rs-compiler-darwin-arm64": "0.11.1",
87
- "@stylexswc/rs-compiler-linux-arm64-gnu": "0.11.1",
88
- "@stylexswc/rs-compiler-linux-x64-musl": "0.11.1",
89
- "@stylexswc/rs-compiler-win32-arm64-msvc": "0.11.1"
83
+ "@stylexswc/rs-compiler-win32-x64-msvc": "0.11.2-rc.1",
84
+ "@stylexswc/rs-compiler-darwin-x64": "0.11.2-rc.1",
85
+ "@stylexswc/rs-compiler-linux-x64-gnu": "0.11.2-rc.1",
86
+ "@stylexswc/rs-compiler-darwin-arm64": "0.11.2-rc.1",
87
+ "@stylexswc/rs-compiler-linux-arm64-gnu": "0.11.2-rc.1",
88
+ "@stylexswc/rs-compiler-linux-x64-musl": "0.11.2-rc.1",
89
+ "@stylexswc/rs-compiler-win32-arm64-msvc": "0.11.2-rc.1"
90
90
  },
91
91
  "scripts": {
92
92
  "artifacts": "napi artifacts",
@@ -105,6 +105,7 @@
105
105
  "lint:check": " cargo clippy --all-targets --all-features -- -D warnings",
106
106
  "postbuild": "pnpm run check:artifacts",
107
107
  "test": "ava",
108
+ "typecheck": "scripty --rs",
108
109
  "version": "napi version"
109
110
  }
110
111
  }