@stylexswc/jest 0.6.2-rc.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Vladislav Buinovski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # @stylexswc/jest
2
+
3
+ Jest transformer that enables StyleX SWC integration for JavaScript and TypeScript testing with Jest.
4
+
5
+ ## Overview
6
+
7
+ The `@stylexswc/jest` package provides a Jest transformer that integrates with
8
+ the StyleX RS compiler. This allows to transform source code using
9
+ StyleX during Jest tests, ensuring that styles are correctly processed and
10
+ applied.
11
+
12
+ ## Installation
13
+
14
+ To install the package, run the following command:
15
+
16
+ ```bash
17
+ npm install --save-dev @stylexswc/jest
18
+ ```
19
+
20
+ ## Configuration
21
+
22
+ To use the transformer, add it to Jest configuration. Here is an example
23
+ configuration:
24
+
25
+ ```javascript
26
+ // jest.config.js
27
+ const path = require('path');
28
+
29
+ module.exports = {
30
+ transform: {
31
+ '^.+\\.(ts|tsx|js|jsx|mjs|cjs|html)$': [
32
+ '@stylexswc/jest',
33
+ {
34
+ rsOptions: {
35
+ aliases: {
36
+ '@/*': [path.join(__dirname, '*')],
37
+ },
38
+ unstable_moduleResolution: {
39
+ type: 'commonJS',
40
+ },
41
+ },
42
+ },
43
+ ],
44
+ },
45
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
46
+ testEnvironment: 'jsdom',
47
+ };
48
+ ```
49
+
50
+ ## Options
51
+
52
+ ### `rsOptions`
53
+
54
+ - Type: `Partial<StyleXOptions>`
55
+ - Optional
56
+ - Description: StyleX compiler options that will be passed to the transformer.
57
+ See
58
+ [StyleX configuration docs](https://stylexjs.com/docs/api/configuration/babel-plugin/)
59
+ for details.
60
+
61
+ ## Example
62
+
63
+ Here is an example of how to use `@swc/jest` with other transformers:
64
+
65
+ ```javascript
66
+ // jest.config.js
67
+ const nextJest = require('next/jest');
68
+ const path = require('path');
69
+
70
+ const createJestConfig = nextJest({
71
+ dir: process.cwd(),
72
+ });
73
+
74
+ const customJestConfig = {
75
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
76
+ testEnvironment: 'jsdom',
77
+ transform: {
78
+ '^.+\\.(ts|tsx|js|jsx|mjs|cjs|html)$': [
79
+ 'jest-chain-transform',
80
+ {
81
+ transformers: [
82
+ [
83
+ '@stylexswc/jest',
84
+ {
85
+ rsOptions: {
86
+ aliases: {
87
+ '@/*': [path.join(__dirname, '*')],
88
+ },
89
+ unstable_moduleResolution: {
90
+ type: 'commonJS',
91
+ },
92
+ },
93
+ },
94
+ ],
95
+ [
96
+ '@swc/jest',
97
+ {
98
+ $schema: 'https://json.schemastore.org/swcrc',
99
+ jsc: {
100
+ parser: {
101
+ syntax: 'typescript',
102
+ tsx: true,
103
+ dynamicImport: true,
104
+ decorators: true,
105
+ dts: true,
106
+ },
107
+ transform: {
108
+ react: {
109
+ useBuiltins: true,
110
+ runtime: 'automatic',
111
+ },
112
+ },
113
+ target: 'esnext',
114
+ loose: false,
115
+ externalHelpers: false,
116
+ keepClassNames: true,
117
+ baseUrl: './',
118
+ paths: {
119
+ '@/*': ['./*'],
120
+ },
121
+ },
122
+ module: {
123
+ type: 'es6',
124
+ },
125
+ minify: false,
126
+ },
127
+ ],
128
+ ],
129
+ },
130
+ ],
131
+ },
132
+ };
133
+
134
+ module.exports = customJestConfig;
135
+ ```
136
+
137
+ Real example can be found in the [@stylexswc/next-example](../../apps/nextjs-example/jest.config.js)
138
+
139
+ ## License
140
+
141
+ This project is licensed under the MIT License. See the [LICENSE](../../LICENSE)
142
+ file for details.
@@ -0,0 +1,12 @@
1
+ import type { StyleXOptions } from '@stylexswc/rs-compiler';
2
+ import type { TransformerCreator, SyncTransformer } from '@jest/transform';
3
+ import type { Config } from '@jest/types';
4
+ type TransformerConfig = Config.TransformerConfig[1];
5
+ export interface JestTransformerConfig extends TransformerConfig {
6
+ rsOptions?: StyleXOptions;
7
+ }
8
+ declare const _default: {
9
+ createTransformer: TransformerCreator<SyncTransformer<JestTransformerConfig>, JestTransformerConfig>;
10
+ };
11
+ export default _default;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAErD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;;;;AAyCD,wBAAqC"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rs_compiler_1 = require("@stylexswc/rs-compiler");
4
+ const crypto_1 = require("crypto");
5
+ const process = function process(sourceText, sourcePath, options) {
6
+ const { code } = (0, rs_compiler_1.transform)(sourcePath, sourceText, options.transformerConfig.rsOptions ?? {});
7
+ return { code };
8
+ };
9
+ const processAsync = async function processAsync(sourceText, sourcePath, options) {
10
+ return process(sourceText, sourcePath, options);
11
+ };
12
+ const getCacheKey = function getCacheKey(sourceText, sourcePath, options) {
13
+ return (0, crypto_1.createHash)('sha256')
14
+ .update(sourceText)
15
+ .update(sourcePath)
16
+ .update(JSON.stringify(options.transformerConfig))
17
+ .digest('hex');
18
+ };
19
+ const createTransformer = () => {
20
+ return {
21
+ process,
22
+ processAsync,
23
+ getCacheKey,
24
+ };
25
+ };
26
+ module.exports = { createTransformer };
27
+ exports.default = { createTransformer };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@stylexswc/jest",
3
+ "description": "Jest transformer for Stylex SWC",
4
+ "version": "0.6.2-rc.4",
5
+ "config": {
6
+ "scripty": {
7
+ "path": "../../scripts/packages"
8
+ }
9
+ },
10
+ "devDependencies": {
11
+ "@babel/types": "^7.23.9",
12
+ "@jest/transform": "^29.7.0",
13
+ "@jest/types": "^29.5.14",
14
+ "@stylexswc/eslint-config": "0.6.2-rc.4",
15
+ "@stylexswc/rs-compiler": "0.6.2-rc.4",
16
+ "@stylexswc/typescript-config": "0.6.2-rc.4"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "jest",
23
+ "stylex",
24
+ "swc"
25
+ ],
26
+ "license": "MIT",
27
+ "main": "dist/index.js",
28
+ "peerDependencies": {
29
+ "next": ">=14.0.0"
30
+ },
31
+ "private": false,
32
+ "publishConfig": {
33
+ "registry": "https://registry.npmjs.org/",
34
+ "access": "public"
35
+ },
36
+ "repository": "https://github.com/Dwlad90/stylex-swc-plugin",
37
+ "sideEffects": false,
38
+ "scripts": {
39
+ "build": "scripty --ts",
40
+ "check:artifacts": "scripty",
41
+ "clean": "del-cli dist",
42
+ "lint": "eslint . --color",
43
+ "lint:check": "eslint . --color --format json --output-file dist/eslint_report.json",
44
+ "precommit": "lint-staged",
45
+ "prepush": "lint-prepush",
46
+ "test": "echo \"Error: no test specified\" && exit 0",
47
+ "typecheck": "scripty"
48
+ }
49
+ }