unplugin-stylex 0.3.0 → 0.3.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.
@@ -22,6 +22,7 @@ function getOptions(options) {
22
22
  return {
23
23
  ...options,
24
24
  dev: options.dev || isDev,
25
+ invalidExts: [".json", ".html", ".jade", ".json5", ..._nullishCoalesce(options.invalidExts, () => ( []))],
25
26
  stylex: {
26
27
  filename: stylex2.filename || "stylex.css",
27
28
  stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
@@ -97,7 +98,7 @@ var unpluginFactory = (rawOptions = {}) => {
97
98
  return {
98
99
  name: PLUGIN_NAME,
99
100
  transformInclude(id) {
100
- const invalidExts = [".json", ".html", ".jade", ".json5"];
101
+ const invalidExts = options.invalidExts;
101
102
  const extname2 = path.extname(id);
102
103
  const questionMarkIndex = extname2.indexOf("?");
103
104
  const validExtName = questionMarkIndex > -1 ? extname2.slice(0, questionMarkIndex) : extname2;
@@ -22,6 +22,7 @@ function getOptions(options) {
22
22
  return {
23
23
  ...options,
24
24
  dev: options.dev || isDev,
25
+ invalidExts: [".json", ".html", ".jade", ".json5", ...options.invalidExts ?? []],
25
26
  stylex: {
26
27
  filename: stylex2.filename || "stylex.css",
27
28
  stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
@@ -97,7 +98,7 @@ var unpluginFactory = (rawOptions = {}) => {
97
98
  return {
98
99
  name: PLUGIN_NAME,
99
100
  transformInclude(id) {
100
- const invalidExts = [".json", ".html", ".jade", ".json5"];
101
+ const invalidExts = options.invalidExts;
101
102
  const extname2 = path.extname(id);
102
103
  const questionMarkIndex = extname2.indexOf("?");
103
104
  const validExtName = questionMarkIndex > -1 ? extname2.slice(0, questionMarkIndex) : extname2;
package/dist/esbuild.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
3
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
4
4
  require('./chunk-ZBPRDZS4.cjs');
5
5
 
6
6
  // src/esbuild.ts
7
7
  var _unplugin = require('unplugin');
8
- var esbuildPlugin = _unplugin.createEsbuildPlugin.call(void 0, _chunkTCTVGJ42cjs.unpluginFactory);
8
+ var esbuildPlugin = _unplugin.createEsbuildPlugin.call(void 0, _chunk33MWAEKIcjs.unpluginFactory);
9
9
  var esbuild_default = esbuildPlugin;
10
10
 
11
11
 
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-MREBYPD2.js";
3
+ } from "./chunk-QTHUNRNO.js";
4
4
  import "./chunk-6F4PWJZI.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
5
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
6
6
  require('./chunk-ZBPRDZS4.cjs');
7
7
 
8
8
 
9
9
 
10
10
 
11
- exports.default = _chunkTCTVGJ42cjs.src_default; exports.unplugin = _chunkTCTVGJ42cjs.unplugin; exports.unpluginFactory = _chunkTCTVGJ42cjs.unpluginFactory;
11
+ exports.default = _chunk33MWAEKIcjs.src_default; exports.unplugin = _chunk33MWAEKIcjs.unplugin; exports.unpluginFactory = _chunk33MWAEKIcjs.unpluginFactory;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  src_default,
3
3
  unplugin,
4
4
  unpluginFactory
5
- } from "./chunk-MREBYPD2.js";
5
+ } from "./chunk-QTHUNRNO.js";
6
6
  import "./chunk-6F4PWJZI.js";
7
7
  export {
8
8
  src_default as default,
package/dist/rollup.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
3
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
4
4
  require('./chunk-ZBPRDZS4.cjs');
5
5
 
6
6
  // src/rollup.ts
7
7
  var _unplugin = require('unplugin');
8
- var rollupPlugin = _unplugin.createRollupPlugin.call(void 0, _chunkTCTVGJ42cjs.unpluginFactory);
8
+ var rollupPlugin = _unplugin.createRollupPlugin.call(void 0, _chunk33MWAEKIcjs.unpluginFactory);
9
9
  var rollup_default = rollupPlugin;
10
10
 
11
11
 
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-MREBYPD2.js";
3
+ } from "./chunk-QTHUNRNO.js";
4
4
  import "./chunk-6F4PWJZI.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
3
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
4
4
  require('./chunk-ZBPRDZS4.cjs');
5
5
 
6
6
  // src/rspack.ts
7
7
  var _unplugin = require('unplugin');
8
- var rspackPlugin = _unplugin.createRspackPlugin.call(void 0, _chunkTCTVGJ42cjs.unpluginFactory);
8
+ var rspackPlugin = _unplugin.createRspackPlugin.call(void 0, _chunk33MWAEKIcjs.unpluginFactory);
9
9
  var rspack_default = rspackPlugin;
10
10
 
11
11
 
package/dist/rspack.d.cts CHANGED
@@ -7,7 +7,7 @@ import { UnpluginStylexInstance } from './types.cjs';
7
7
  * @module
8
8
  */
9
9
 
10
- type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>;
10
+ type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance>;
11
11
  declare const rspackPlugin: RspackPluginType;
12
12
 
13
13
  export { rspackPlugin as default };
package/dist/rspack.d.ts CHANGED
@@ -7,7 +7,7 @@ import { UnpluginStylexInstance } from './types.js';
7
7
  * @module
8
8
  */
9
9
 
10
- type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>;
10
+ type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance>;
11
11
  declare const rspackPlugin: RspackPluginType;
12
12
 
13
13
  export { rspackPlugin as default };
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-MREBYPD2.js";
3
+ } from "./chunk-QTHUNRNO.js";
4
4
  import "./chunk-6F4PWJZI.js";
5
5
 
6
6
  // src/rspack.ts
package/dist/types.d.cts CHANGED
@@ -5,21 +5,22 @@ type BabelConfig = {
5
5
  };
6
6
  type StylexOptions = {
7
7
  filename?: string;
8
+ aliases?: string[];
8
9
  stylexImports?: string[];
9
10
  classNamePrefix?: string;
10
- useCSSLayers?: boolean;
11
11
  unstable_moduleResolution?: {
12
- type: 'commonjs' | 'haste';
12
+ type: 'commonJS' | 'haste';
13
13
  rootDir: string;
14
14
  };
15
15
  babelConfig?: BabelConfig;
16
- runtimeInjection: boolean;
17
- aliases?: string[];
16
+ useCSSLayers?: boolean;
17
+ genConditionalClasses?: boolean;
18
+ treeshakeCompensation?: boolean;
19
+ runtimeInjection?: boolean;
18
20
  };
19
21
  type UnpluginStylexOptions = {
20
- compiler?: string;
22
+ invalidExts?: string[];
21
23
  dev?: boolean;
22
- enforce?: 'post' | 'pre';
23
24
  stylex?: StylexOptions;
24
25
  };
25
26
  type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T;
package/dist/types.d.ts CHANGED
@@ -5,21 +5,22 @@ type BabelConfig = {
5
5
  };
6
6
  type StylexOptions = {
7
7
  filename?: string;
8
+ aliases?: string[];
8
9
  stylexImports?: string[];
9
10
  classNamePrefix?: string;
10
- useCSSLayers?: boolean;
11
11
  unstable_moduleResolution?: {
12
- type: 'commonjs' | 'haste';
12
+ type: 'commonJS' | 'haste';
13
13
  rootDir: string;
14
14
  };
15
15
  babelConfig?: BabelConfig;
16
- runtimeInjection: boolean;
17
- aliases?: string[];
16
+ useCSSLayers?: boolean;
17
+ genConditionalClasses?: boolean;
18
+ treeshakeCompensation?: boolean;
19
+ runtimeInjection?: boolean;
18
20
  };
19
21
  type UnpluginStylexOptions = {
20
- compiler?: string;
22
+ invalidExts?: string[];
21
23
  dev?: boolean;
22
- enforce?: 'post' | 'pre';
23
24
  stylex?: StylexOptions;
24
25
  };
25
26
  type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T;
package/dist/vite.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
3
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
4
4
  require('./chunk-ZBPRDZS4.cjs');
5
5
 
6
6
  // src/vite.ts
7
7
  var _unplugin = require('unplugin');
8
- var vitePlugin = _unplugin.createVitePlugin.call(void 0, _chunkTCTVGJ42cjs.unpluginFactory);
8
+ var vitePlugin = _unplugin.createVitePlugin.call(void 0, _chunk33MWAEKIcjs.unpluginFactory);
9
9
  var vite_default = vitePlugin;
10
10
 
11
11
 
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-MREBYPD2.js";
3
+ } from "./chunk-QTHUNRNO.js";
4
4
  import "./chunk-6F4PWJZI.js";
5
5
 
6
6
  // src/vite.ts
package/dist/webpack.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTCTVGJ42cjs = require('./chunk-TCTVGJ42.cjs');
3
+ var _chunk33MWAEKIcjs = require('./chunk-33MWAEKI.cjs');
4
4
  require('./chunk-ZBPRDZS4.cjs');
5
5
 
6
6
  // src/webpack.ts
7
7
  var _unplugin = require('unplugin');
8
- var webpackPlugin = _unplugin.createWebpackPlugin.call(void 0, _chunkTCTVGJ42cjs.unpluginFactory);
8
+ var webpackPlugin = _unplugin.createWebpackPlugin.call(void 0, _chunk33MWAEKIcjs.unpluginFactory);
9
9
  var webpack_default = webpackPlugin;
10
10
 
11
11
 
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-MREBYPD2.js";
3
+ } from "./chunk-QTHUNRNO.js";
4
4
  import "./chunk-6F4PWJZI.js";
5
5
 
6
6
  // src/webpack.ts
package/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eryue0220/unplugin-stylex",
3
- "version": "0.0.3",
3
+ "version": "0.3.2",
4
4
  "exports": {
5
5
  "./index": "./src/index.ts",
6
6
  "./esbuild": "./src/esbuild.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-stylex",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "packageManager": "pnpm@8.11.0",
5
5
  "description": "Unplugin for stylex",
6
6
  "repository": "https://github.com/eryue0220/unplugin-stylex",
@@ -57,16 +57,6 @@
57
57
  },
58
58
  "./*": "./*"
59
59
  },
60
- "scripts": {
61
- "dev": "tsup src/*ts --watch src",
62
- "build": "tsup src/*.ts --format cjs,esm --dts --splitting --clean",
63
- "test": "vitest",
64
- "test:update": "vitest -u",
65
- "test:cov": "vitest --coverage",
66
- "lint": "eslint . --ext .ts,.tsx,.js,.jsx",
67
- "check": "pnpm run lint && pnpm run typecheck",
68
- "typecheck": "tsc -p tsconfig.json --noEmit"
69
- },
70
60
  "engines": {
71
61
  "node": ">=16.14.0"
72
62
  },
@@ -74,7 +64,7 @@
74
64
  "@stylexjs/stylex": "^0.5.1"
75
65
  },
76
66
  "dependencies": {
77
- "@babel/core": "^7.24.4",
67
+ "@babel/core": "^7.24.5",
78
68
  "@babel/plugin-syntax-flow": "^7.24.1",
79
69
  "@babel/plugin-syntax-jsx": "^7.24.1",
80
70
  "@babel/plugin-syntax-typescript": "^7.24.1",
@@ -83,16 +73,26 @@
83
73
  "unplugin": "^1.10.1"
84
74
  },
85
75
  "devDependencies": {
86
- "@stylistic/eslint-plugin-ts": "^1.7.2",
87
- "@types/node": "^20.12.7",
76
+ "@stylistic/eslint-plugin-ts": "^1.8.1",
77
+ "@types/node": "^20.12.11",
88
78
  "@typescript-eslint/eslint-plugin": "^6.21.0",
89
79
  "@typescript-eslint/parser": "^6.21.0",
90
- "@vitest/coverage-v8": "^1.5.0",
80
+ "@vitest/coverage-v8": "^1.6.0",
91
81
  "babel-plugin-syntax-hermes-parser": "^0.19.2",
92
82
  "eslint": "^8.57.0",
93
83
  "tsup": "^8.0.2",
94
84
  "typescript": "^5.4.5",
95
- "vite": "^5.2.9",
96
- "vitest": "^1.5.0"
85
+ "vite": "^5.2.11",
86
+ "vitest": "^1.6.0"
87
+ },
88
+ "scripts": {
89
+ "dev": "tsup src/*ts --watch src",
90
+ "build": "tsup src/*.ts --format cjs,esm --dts --splitting --clean",
91
+ "test": "vitest",
92
+ "test:update": "vitest -u",
93
+ "test:cov": "vitest --coverage",
94
+ "lint": "eslint . --ext .ts,.tsx,.js,.jsx",
95
+ "check": "pnpm run lint && pnpm run typecheck",
96
+ "typecheck": "tsc -p tsconfig.json --noEmit"
97
97
  }
98
- }
98
+ }
package/.eslintignore DELETED
@@ -1,4 +0,0 @@
1
- .github/
2
- dist/
3
- node_modules/
4
- examples/
package/.eslintrc.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "env": {
3
- "node": true
4
- },
5
- "parser": "@typescript-eslint/parser",
6
- "plugins": ["@stylistic/ts"],
7
- "root": true,
8
- "rules": {
9
- "max-len": ["error", { "code": 120 }],
10
- "semi": ["error", "never"],
11
- "quotes": ["error", "single"],
12
- "@typescript-eslint/no-explicit-any": "off"
13
- }
14
- }
@@ -1,18 +0,0 @@
1
- name: Setup and Cache
2
- description: Setup for node, pnpm and cache for browser testing binaries
3
- inputs:
4
- node-version:
5
- required: false
6
- description: Node version for setup-node
7
- default: 20.x
8
-
9
- runs:
10
- using: composite
11
-
12
- steps:
13
- - name: install pnpm
14
- uses: pnpm/action-setup@v2
15
- - name: Set node version to ${{ inputs.node-version }}
16
- uses: actions/setup-node@v4
17
- with:
18
- node-version: ${{ inputs.node-version }}
@@ -1,27 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": ["config:base"],
4
- "lockFileMaintenance": {"enabled": true, "automerge": false},
5
- "rangeStrategy": "replace",
6
- "postUpdateOptions": ["pnpmDedupe"],
7
- "packageRules": [
8
- {
9
- "matchPackageNames": ["@tsd/typescript", "typescript"],
10
- "groupName": "typescript"
11
- },
12
- {
13
- "matchPackageNames": [
14
- "@babel/core",
15
- "@babel/plugin-syntax-flow",
16
- "@babel/plugin-syntax-jsx",
17
- "@babel/plugin-syntax-typescript"
18
- ],
19
- "groupName": "babel"
20
- },
21
-
22
- {
23
- "matchPackageNames": ["@stylexjs/stylex", "@stylexjs/babel-plugin"],
24
- "groupName": "stylex"
25
- }
26
- ]
27
- }
@@ -1,43 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches: [main]
6
-
7
- pull_request:
8
- branches: [main]
9
-
10
- jobs:
11
- lint:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v4
15
-
16
- - uses: ./.github/actions/setup-and-cache
17
-
18
- - name: Install
19
- run: pnpm i
20
-
21
- - name: Lint
22
- run: pnpm run check
23
-
24
- test:
25
- runs-on: ${{ matrix.os }}
26
-
27
- strategy:
28
- matrix:
29
- os: [ubuntu-latest, macos-latest, windows-latest]
30
- node: [16, 18, 20]
31
-
32
- steps:
33
- - uses: actions/checkout@v4
34
-
35
- - uses: ./.github/actions/setup-and-cache
36
- with:
37
- node-version: ${{ matrix.node }}
38
-
39
- - name: Install
40
- run: pnpm i
41
-
42
- - name: Unit Test
43
- run: pnpm run test
@@ -1,39 +0,0 @@
1
- name: Release
2
-
3
- permissions:
4
- contents: write
5
-
6
- on:
7
- push:
8
- tags:
9
- - 'v*'
10
-
11
- jobs:
12
- release:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v4
16
- with:
17
- fetch-depth: 0
18
-
19
- - name: Set node
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: lts/*
23
-
24
- - run: npx changelogithub
25
- env:
26
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
27
-
28
- publish-jsr:
29
- runs-on: ubuntu-latest
30
-
31
- permissions:
32
- contents: read
33
- id-token: write
34
-
35
- steps:
36
- - uses: actions/checkout@v4
37
-
38
- - name: Publish package
39
- run: npx jsr publish
@@ -1,15 +0,0 @@
1
- name: Spell Check
2
- on:
3
- pull_request:
4
- push:
5
- branches:
6
- - "main"
7
- jobs:
8
- typos:
9
- name: Spell Check with Typos
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Checkout Actions Repository
13
- uses: actions/checkout@v4
14
- - name: Check spelling
15
- uses: crate-ci/typos@master
package/src/core/build.ts DELETED
@@ -1,9 +0,0 @@
1
- import stylex from '@stylexjs/babel-plugin'
2
- import type { Rule } from '@stylexjs/babel-plugin'
3
-
4
- export function buildStylexRules(stylexRules: { [key: string]: Rule[] }, useCSSLayers: boolean): string {
5
- const rules = Object.values(stylexRules).flat()
6
- if (rules.length === 0) return ''
7
-
8
- return stylex.processStylexRules(rules, useCSSLayers)
9
- }
@@ -1,7 +0,0 @@
1
- export const PLUGIN_NAME = 'unplugin-stylex'
2
-
3
- export const isDevelopment = (
4
- process.env.NODE_ENV !== 'production' ||
5
- process.env.BABEL_ENV !== 'production'
6
- )
7
-
@@ -1,26 +0,0 @@
1
- import type { StylexOptions, UnpluginStylexOptions } from '@/types'
2
- import { isDevelopment } from './constants'
3
-
4
- export function getOptions(options: UnpluginStylexOptions) {
5
- const stylex = options.stylex || ({} as StylexOptions)
6
- const isDev = options.dev || isDevelopment
7
-
8
- return {
9
- ...options,
10
- dev: options.dev || isDev,
11
- stylex: {
12
- filename: stylex.filename || 'stylex.css',
13
- stylexImports: stylex.stylexImports || ['@stylexjs/stylex'],
14
- runtimeInjection: stylex.runtimeInjection ?? isDev,
15
- aliases: stylex.aliases,
16
- useCSSLayers: stylex.useCSSLayers || false,
17
- unstable_moduleResolution: stylex.unstable_moduleResolution || { type: 'commonJS', rootDir: process.cwd() },
18
- babelConfig: {
19
- babelrc: (stylex.babelConfig || {}).babelrc || false,
20
- plugins: (stylex.babelConfig || {}).plugins || [],
21
- presets: (stylex.babelConfig || {}).presets || [],
22
- },
23
- ...stylex,
24
- },
25
- }
26
- }
@@ -1,12 +0,0 @@
1
- import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript'
2
- import flowSyntaxPlugin from '@babel/plugin-syntax-flow'
3
-
4
- export function getSyntaxPlugins(extname: string) {
5
- const TSPlugin = extname === '.tsx'
6
- ? [[typescriptSyntaxPlugin, { isTSX: true }]]
7
- : [typescriptSyntaxPlugin]
8
-
9
- return ['.js', '.jsx'].includes(extname)
10
- ? [flowSyntaxPlugin]
11
- : TSPlugin
12
- }
@@ -1,44 +0,0 @@
1
- import { extname as pathExtname } from 'node:path'
2
- import { transformAsync } from '@babel/core'
3
- import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx'
4
- import stylexBabelPlugin from '@stylexjs/babel-plugin'
5
-
6
- import { getSyntaxPlugins } from './plugins'
7
-
8
- export async function transformer(context) {
9
- const { id, inputCode, options } = context
10
- const stylex = options.stylex
11
- const extname = pathExtname(id)
12
- const stylexRules = {}
13
- const stylexBabelPluginOptions = {
14
- dev: options.dev,
15
- importSources: stylex.stylexImports,
16
- ...stylex,
17
- }
18
- const plugins = [
19
- ...(stylex.babelConfig?.plugins || []),
20
- ...getSyntaxPlugins(extname),
21
- jsxSyntaxPlugin,
22
- stylexBabelPlugin.withOptions(stylexBabelPluginOptions),
23
- ]
24
-
25
- const { code, map, metadata } = await transformAsync(
26
- inputCode,
27
- {
28
- babelrc: stylex.babelConfig?.babelrc,
29
- filename: id,
30
- presets: stylex.babelConfig?.presets,
31
- plugins,
32
- }
33
- )
34
-
35
- if (metadata.stylex && metadata.stylex.length > 0) {
36
- stylexRules[id] = metadata.stylex
37
- }
38
-
39
- if (!stylex.babelConfig?.babelrc) {
40
- return { code, map, stylexRules }
41
- }
42
-
43
- return { code, stylexRules }
44
- }
package/src/esbuild.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * This entry file is for esbuild plugin. Requires esbuild >= 0.15
3
- *
4
- * @module
5
- */
6
-
7
- import { createEsbuildPlugin } from 'unplugin'
8
- import type { EsbuildPlugin } from 'unplugin'
9
- import { unpluginFactory } from './index'
10
- import type { UnpluginStylexInstance } from './types'
11
-
12
- const esbuildPlugin: UnpluginStylexInstance<EsbuildPlugin | EsbuildPlugin[]> = createEsbuildPlugin(unpluginFactory)
13
-
14
-
15
- /**
16
- * Esbuild plugin
17
- *
18
- * @example
19
- *
20
- * import { build } from 'esbuild'
21
- * import stylexPlugin from 'unplugin-stylex/esbuild'
22
- *
23
- * export default {
24
- * plugins: [
25
- * stylexPlugin(),
26
- * ],
27
- * }
28
- */
29
- export default esbuildPlugin
package/src/index.ts DELETED
@@ -1,141 +0,0 @@
1
- /**
2
- * This entry file is for main unplugin.
3
- *
4
- * @module
5
- */
6
-
7
- import * as path from 'node:path'
8
-
9
- import { createUnplugin } from 'unplugin'
10
- import type { UnpluginFactory, UnpluginInstance } from 'unplugin'
11
- import type { BuildOptions } from 'vite'
12
-
13
- import { buildStylexRules } from './core/build'
14
- import { PLUGIN_NAME } from './core/constants'
15
- import { getOptions } from './core/options'
16
- import { transformer } from './core/transformer'
17
- import type { UnpluginStylexOptions } from './types'
18
-
19
- /**
20
- * The main unplugin factory.
21
- */
22
- export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined> = (rawOptions = {}) => {
23
- const options = getOptions(rawOptions)
24
- const stylexRules = {}
25
- let viteConfig: { build: BuildOptions | undefined; base: string | undefined; } | null = null
26
-
27
- return {
28
- name: PLUGIN_NAME,
29
-
30
- transformInclude(id) {
31
- // webpack will contain these files, which will occur errors
32
- const invalidExts = ['.json', '.html', '.jade', '.json5']
33
- const extname = path.extname(id)
34
- // for handle vite
35
- const questionMarkIndex = extname.indexOf('?')
36
- const validExtName = questionMarkIndex > -1 ? extname.slice(0, questionMarkIndex) : extname
37
- return !invalidExts.includes(validExtName)
38
- },
39
-
40
- async transform(code, id) {
41
- const dir = path.dirname(id)
42
- const basename = path.basename(id)
43
- const file = path.join(dir, basename.includes('?') ? basename.split('?')[0] : basename)
44
-
45
- if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
46
- return
47
- }
48
-
49
- const context = {
50
- id: file,
51
- inputCode: code,
52
- pluginContext: this,
53
- options,
54
- }
55
-
56
- try {
57
- const result = await transformer(context)
58
-
59
- if (result.stylexRules && result.stylexRules[id]) {
60
- stylexRules[id] = result.stylexRules[id]
61
- }
62
-
63
- return result
64
- } catch (error) {
65
- console.error('transform::error::', error)
66
- this.error(error)
67
- }
68
- },
69
-
70
- buildEnd() {
71
- const fileName = options.stylex.filename
72
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
73
-
74
- if (!collectedCSS) return
75
-
76
- this.emitFile({
77
- fileName,
78
- source: collectedCSS,
79
- type: 'asset',
80
- })
81
- },
82
-
83
- vite: {
84
- config(config) {
85
- viteConfig = {
86
- build: config.build,
87
- base: config.base,
88
- }
89
- },
90
-
91
- configResolved(config) {
92
- config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
93
- config.optimizeDeps.exclude.push('@stylexjs/open-props')
94
- },
95
-
96
- buildEnd() {
97
- const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
98
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
99
-
100
- if (!collectedCSS) return
101
-
102
- this.emitFile({
103
- fileName,
104
- source: collectedCSS,
105
- type: 'asset',
106
- })
107
- },
108
-
109
- transformIndexHtml(html, ctx) {
110
- const fileName = `${viteConfig!.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
111
- const css = ctx.bundle?.[fileName]
112
-
113
- if (!css) {
114
- return html
115
- }
116
-
117
- const publicPath = path.posix.join(
118
- viteConfig!.base ?? '/',
119
- fileName.replace(/\\/g, '/')
120
- )
121
-
122
- return [
123
- {
124
- tag: 'link',
125
- attrs: {
126
- rel: 'stylesheet',
127
- href: publicPath,
128
- },
129
- injectTo: 'head',
130
- },
131
- ]
132
- },
133
- },
134
- }
135
- }
136
-
137
- export const unplugin: UnpluginInstance<UnpluginStylexOptions | undefined, boolean> = createUnplugin(unpluginFactory)
138
-
139
- export * from './types'
140
-
141
- export default unplugin
package/src/rollup.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * This entry file is for Rollup plugin.
3
- *
4
- * @module
5
- */
6
-
7
- import { createRollupPlugin } from 'unplugin'
8
- import type { RollupPlugin } from 'unplugin'
9
- import { unpluginFactory } from './index'
10
- import type { UnpluginStylexInstance } from './types'
11
-
12
- const rollupPlugin: UnpluginStylexInstance<RollupPlugin | RollupPlugin[]> = createRollupPlugin(unpluginFactory)
13
-
14
- /**
15
- * Rollup plugin
16
- *
17
- * @example
18
- *
19
- * import stylexPlugin from 'unplugin-stylex/rollup'
20
- *
21
- * export default {
22
- * plugins: [
23
- * stylexPlugin(),
24
- * ],
25
- * }
26
- */
27
- export default rollupPlugin
package/src/rspack.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * This entry file is for Rspac plugin.
3
- *
4
- * @module
5
- */
6
-
7
- import { createRspackPlugin } from 'unplugin'
8
- import type { RspackPluginInstance } from 'unplugin'
9
- import { unpluginFactory } from './index'
10
- import type { UnpluginStylexInstance } from './types'
11
-
12
- type RspackPluginType = UnpluginStylexInstance<RspackPluginInstance | RspackPluginInstance[]>
13
-
14
- const rspackPlugin: RspackPluginType = createRspackPlugin(unpluginFactory)
15
-
16
- /**
17
- * Rsapck plugin
18
- *
19
- * @example
20
- *
21
- * import stylexPlugin from 'unplugin-stylex/rspack'
22
- *
23
- * module.exports = {
24
- * plugins: [
25
- * stylexPlugin(),
26
- * ],
27
- * }
28
- */
29
- export default rspackPlugin
package/src/types.ts DELETED
@@ -1,28 +0,0 @@
1
- export type BabelConfig = {
2
- plugins: unknown[]
3
- presets: unknown[]
4
- babelrc: boolean
5
- }
6
-
7
- export type StylexOptions = {
8
- filename?: string
9
- stylexImports?: string[]
10
- classNamePrefix?: string
11
- useCSSLayers?: boolean
12
- unstable_moduleResolution?: {
13
- type: 'commonjs' | 'haste'
14
- rootDir: string
15
- }
16
- babelConfig?: BabelConfig
17
- runtimeInjection: boolean
18
- aliases?: string[]
19
- }
20
-
21
- export type UnpluginStylexOptions = {
22
- compiler?: string
23
- dev?: boolean
24
- enforce?: 'post' | 'pre'
25
- stylex?: StylexOptions
26
- }
27
-
28
- export type UnpluginStylexInstance<T> = (options?: UnpluginStylexOptions) => T
package/src/vite.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * This entry file is for Vite plugin.
3
- *
4
- * @module
5
- */
6
-
7
- import { createVitePlugin } from 'unplugin'
8
- import type { VitePlugin } from 'unplugin'
9
- import { unpluginFactory } from './index'
10
- import type { UnpluginStylexInstance } from './types'
11
-
12
- const vitePlugin: UnpluginStylexInstance<VitePlugin | VitePlugin[]> = createVitePlugin(unpluginFactory)
13
-
14
- /**
15
- * Vite example
16
- *
17
- * @example
18
- *
19
- * import { defineConfig } from 'vite'
20
- * import stylexPlugin from 'unplugin-stylex/vite'
21
- *
22
- * export default defineConfig({
23
- * plugins: [
24
- * stylexPlugin(),
25
- * ],
26
- * })
27
- */
28
- export default vitePlugin
package/src/webpack.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * This entry file is for Webpack plugin.
3
- *
4
- * @module
5
- */
6
-
7
- import { createWebpackPlugin } from 'unplugin'
8
- import type { WebpackPluginInstance } from 'unplugin'
9
- import { unpluginFactory } from './index'
10
- import type { UnpluginStylexInstance } from './types'
11
-
12
- const webpackPlugin: UnpluginStylexInstance<WebpackPluginInstance> = createWebpackPlugin(unpluginFactory)
13
-
14
- /**
15
- * Webpack plugin
16
- *
17
- * @example
18
- *
19
- * import stylexPlugin from 'unplugin-stylex/webpack'
20
- *
21
- * module.exports = {
22
- * plugins: [
23
- * stylexPlugin(),
24
- * ],
25
- * }
26
- */
27
- export default webpackPlugin
package/typos.toml DELETED
@@ -1,10 +0,0 @@
1
- [files]
2
- extend-exclude = [
3
- "*.snap",
4
- "examples/*",
5
- ]
6
-
7
- [default.extend-words]
8
- # Ignore false-positives
9
- stylex = "stylex"
10
- unplugin = "unplugin"
package/vitest.config.ts DELETED
@@ -1,13 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- coverage: {
6
- exclude: [
7
- 'examples/**',
8
- 'test/**'
9
- ],
10
- reporter: ['text', 'json', 'html'],
11
- },
12
- },
13
- })