@stylexswc/postcss-plugin 0.8.2-dev.1 → 0.9.0-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/dist/builder.js CHANGED
@@ -115,7 +115,7 @@ function createBuilder() {
115
115
  filesToTransform.forEach(file => {
116
116
  const filePath = node_path_1.default.resolve(cwd || '/', file);
117
117
  const contents = node_fs_1.default.readFileSync(filePath, 'utf-8');
118
- if (!bundler.shouldTransform(contents)) {
118
+ if (!bundler.shouldTransform(contents, rsOptions)) {
119
119
  return;
120
120
  }
121
121
  const transformedResult = bundler.transform(filePath, contents, rsOptions || {}, {
package/dist/bundler.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { StyleXOptions } from '@stylexswc/rs-compiler';
2
2
  import type { TransformOptions, StyleXPluginOption } from './types';
3
3
  export default function createBundler(): {
4
- shouldTransform: (sourceCode: string) => boolean;
4
+ shouldTransform: (sourceCode: string, rsOptions?: StyleXPluginOption["rsOptions"]) => boolean | undefined;
5
5
  transform: (id: string, sourceCode: string, rsOptions: StyleXOptions, options: TransformOptions) => import("@stylexswc/rs-compiler").StyleXTransformResult;
6
6
  remove: (id: string) => void;
7
7
  bundle: ({ useCSSLayers }: Pick<StyleXPluginOption, "useCSSLayers">) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGpE,MAAM,CAAC,OAAO,UAAU,aAAa;kCAIE,MAAM;oBAMrC,MAAM,cACE,MAAM,aACP,aAAa,WACf,gBAAgB;iBAmCP,MAAM;+BAKQ,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC;EAc3E"}
1
+ {"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGpE,MAAM,CAAC,OAAO,UAAU,aAAa;kCAIE,MAAM,cAAc,kBAAkB,CAAC,WAAW,CAAC;oBAqClF,MAAM,cACE,MAAM,aACP,aAAa,WACf,gBAAgB;iBAsCP,MAAM;+BAKQ,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC;EAc3E"}
package/dist/bundler.js CHANGED
@@ -10,8 +10,33 @@ const rs_compiler_1 = require("@stylexswc/rs-compiler");
10
10
  function createBundler() {
11
11
  const styleXRulesMap = new Map();
12
12
  // Determines if the source code should be transformed based on the presence of StyleX imports.
13
- function shouldTransform(sourceCode) {
14
- return sourceCode.includes('stylex');
13
+ function shouldTransform(sourceCode, rsOptions) {
14
+ const { importSources } = rsOptions ?? {};
15
+ let parsedImportSources;
16
+ try {
17
+ parsedImportSources = importSources?.map(importSource => {
18
+ const a = typeof importSource === 'string' ? JSON.parse(importSource) : importSource;
19
+ return a;
20
+ });
21
+ }
22
+ catch (error) {
23
+ parsedImportSources = importSources;
24
+ }
25
+ const shouldTransform = parsedImportSources?.some(importSource => {
26
+ if (typeof importSource === 'string') {
27
+ return sourceCode.includes(importSource);
28
+ }
29
+ return sourceCode.includes(importSource.from);
30
+ });
31
+ // if (importSourcesExtend != null) {
32
+ // shouldTransform ||= importSourcesExtend.some(importSource => {
33
+ // if (typeof importSource === 'string') {
34
+ // return sourceCode.includes(importSource);
35
+ // }
36
+ // return sourceCode.includes(importSource.from);
37
+ // });
38
+ // }
39
+ return shouldTransform;
15
40
  }
16
41
  // Transforms the source code using Babel, extracting StyleX rules and storing them.
17
42
  function transform(id, sourceCode, rsOptions, options) {
@@ -22,7 +47,8 @@ function createBundler() {
22
47
  metadata: { stylex: [] },
23
48
  };
24
49
  try {
25
- transformResult = (0, rs_compiler_1.transform)(id, sourceCode, (0, rs_compiler_1.normalizeRsOptions)(rsOptions ?? {}));
50
+ const rsOptionsNormalized = (0, rs_compiler_1.normalizeRsOptions)(rsOptions);
51
+ transformResult = (0, rs_compiler_1.transform)(id, sourceCode, rsOptionsNormalized);
26
52
  }
27
53
  catch (error) {
28
54
  if (shouldSkipTransformError) {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import postcss from 'postcss';
2
- import type { StyleXPluginOption } from './types';
3
1
  declare const plugin: {
4
- ({ cwd, rsOptions, include, exclude, useCSSLayers, }: StyleXPluginOption): {
2
+ ({ cwd, rsOptions, include, exclude, useCSSLayers, }: import("./types").StyleXPluginOption): {
5
3
  postcssPlugin: string;
6
- plugins: ((root: postcss.Root, result: postcss.Result) => void)[];
4
+ plugins: ((root: import("postcss").Root, result: import("postcss").Result) => void)[];
7
5
  };
8
6
  postcss: boolean;
9
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAQlD,QAAA,MAAM,MAAM;0DAQT,kBAAkB;;yBAiBC,OAAO,CAAC,IAAI,UAAU,OAAO,CAAC,MAAM;;;CAsDzD,CAAC;AAKF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM;;;;;;CAAiB,CAAC;AAG9B,eAAe,MAAM,CAAC"}
package/dist/index.js CHANGED
@@ -3,75 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const postcss_1 = __importDefault(require("postcss"));
7
- const builder_1 = __importDefault(require("./builder"));
8
- const PLUGIN_NAME = '@stylexswc/postcss-plugin';
9
- const builder = (0, builder_1.default)();
10
- const isDev = process.env.NODE_ENV === 'development';
11
- const plugin = ({ cwd = process.cwd(),
12
- // By default reuses the Babel configuration from the project root.
13
- // Use `babelrc: false` to disable this behavior.
14
- rsOptions = {}, include, exclude, useCSSLayers = false, }) => {
15
- exclude = [
16
- // Exclude type declaration files by default because it never contains any CSS rules.
17
- '**/*.d.ts',
18
- '**/*.flow',
19
- ...(exclude ?? []),
20
- ];
21
- // Whether to skip the error when transforming StyleX rules.
22
- // Useful in watch mode where Fast Refresh can recover from errors.
23
- // Initial transform will still throw errors in watch mode to surface issues early.
24
- let shouldSkipTransformError = false;
25
- return {
26
- postcssPlugin: PLUGIN_NAME,
27
- plugins: [
28
- // Processes the PostCSS root node to find and transform StyleX at-rules.
29
- function (root, result) {
30
- const fileName = result.opts.from;
31
- // Configure the builder with the provided options
32
- builder.configure({
33
- include,
34
- exclude,
35
- cwd,
36
- rsOptions,
37
- useCSSLayers,
38
- isDev,
39
- });
40
- // Find the "@stylex" at-rule
41
- const styleXAtRule = builder.findStyleXAtRule(root);
42
- if (styleXAtRule == null) {
43
- return;
44
- }
45
- // Get dependencies to be watched for changes
46
- const dependencies = builder.getDependencies();
47
- // Add each dependency to the PostCSS result messages.
48
- // This watches the entire "./src" directory for "./src/**/*.{ts,tsx}"
49
- // to handle new files and deletions reliably in watch mode.
50
- for (const dependency of dependencies) {
51
- result.messages.push({
52
- plugin: PLUGIN_NAME,
53
- parent: fileName,
54
- ...dependency,
55
- });
56
- }
57
- // Build and parse the CSS from collected StyleX rules
58
- const css = builder.build({
59
- shouldSkipTransformError,
60
- });
61
- const parsed = postcss_1.default.parse(css, {
62
- from: fileName,
63
- });
64
- // Replace the "@stylex" rule with the generated CSS
65
- styleXAtRule.replaceWith(parsed);
66
- result.root = root;
67
- if (!shouldSkipTransformError) {
68
- // Build was successful, subsequent builds are for watch mode
69
- shouldSkipTransformError = true;
70
- }
71
- },
72
- ],
73
- };
74
- };
75
- plugin.postcss = true;
6
+ const plugin_1 = __importDefault(require("./plugin"));
7
+ const plugin = (0, plugin_1.default)();
76
8
  module.exports = plugin;
77
9
  exports.default = plugin;
@@ -0,0 +1,11 @@
1
+ import postcss from 'postcss';
2
+ import type { StyleXPluginOption } from './types';
3
+ declare function createPlugin(): {
4
+ ({ cwd, rsOptions, include, exclude, useCSSLayers, }: StyleXPluginOption): {
5
+ postcssPlugin: string;
6
+ plugins: ((root: postcss.Root, result: postcss.Result) => void)[];
7
+ };
8
+ postcss: boolean;
9
+ };
10
+ export default createPlugin;
11
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,iBAAS,YAAY;0DAchB,kBAAkB;;yBAiBC,OAAO,CAAC,IAAI,UAAU,OAAO,CAAC,MAAM;;;EA8D3D;AAED,eAAe,YAAY,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const postcss_1 = __importDefault(require("postcss"));
7
+ const builder_1 = __importDefault(require("./builder"));
8
+ function createPlugin() {
9
+ const PLUGIN_NAME = '@stylexswc/postcss-plugin';
10
+ const builder = (0, builder_1.default)();
11
+ const isDev = process.env.NODE_ENV === 'development';
12
+ const plugin = ({
13
+ // By default reuses the Babel configuration from the project root.
14
+ cwd = process.cwd(), rsOptions = {}, include, exclude, useCSSLayers = false, }) => {
15
+ exclude = [
16
+ // Exclude type declaration files by default because it never contains any CSS rules.
17
+ '**/*.d.ts',
18
+ '**/*.flow',
19
+ ...(exclude ?? []),
20
+ ];
21
+ // Whether to skip the error when transforming StyleX rules.
22
+ // Useful in watch mode where Fast Refresh can recover from errors.
23
+ // Initial transform will still throw errors in watch mode to surface issues early.
24
+ let shouldSkipTransformError = false;
25
+ return {
26
+ postcssPlugin: PLUGIN_NAME,
27
+ plugins: [
28
+ // Processes the PostCSS root node to find and transform StyleX at-rules.
29
+ function (root, result) {
30
+ const fileName = result.opts.from;
31
+ // Configure the builder with the provided options
32
+ builder.configure({
33
+ include,
34
+ exclude,
35
+ cwd,
36
+ rsOptions: {
37
+ ...rsOptions,
38
+ importSources: rsOptions?.importSources ?? ['@stylexjs/stylex', 'stylex'],
39
+ },
40
+ useCSSLayers,
41
+ isDev,
42
+ });
43
+ // Find the "@stylex" at-rule
44
+ const styleXAtRule = builder.findStyleXAtRule(root);
45
+ if (styleXAtRule == null) {
46
+ return;
47
+ }
48
+ // Get dependencies to be watched for changes
49
+ const dependencies = builder.getDependencies();
50
+ // Add each dependency to the PostCSS result messages.
51
+ // This watches the entire "./src" directory for "./src/**/*.{ts,tsx}"
52
+ // to handle new files and deletions reliably in watch mode.
53
+ for (const dependency of dependencies) {
54
+ result.messages.push({
55
+ plugin: PLUGIN_NAME,
56
+ parent: fileName,
57
+ ...dependency,
58
+ });
59
+ }
60
+ // Build and parse the CSS from collected StyleX rules
61
+ const css = builder.build({
62
+ shouldSkipTransformError,
63
+ });
64
+ const parsed = postcss_1.default.parse(css, {
65
+ from: fileName,
66
+ });
67
+ // Replace the "@stylex" rule with the generated CSS
68
+ styleXAtRule.replaceWith(parsed);
69
+ result.root = root;
70
+ if (!shouldSkipTransformError) {
71
+ // Build was successful, subsequent builds are for watch mode
72
+ shouldSkipTransformError = true;
73
+ }
74
+ },
75
+ ],
76
+ };
77
+ };
78
+ plugin.postcss = true;
79
+ return plugin;
80
+ }
81
+ exports.default = createPlugin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stylexswc/postcss-plugin",
3
3
  "description": "StyleX PostCSS plugin with NAPI-RS compiler",
4
- "version": "0.8.2-dev.1",
4
+ "version": "0.9.0-rc.1",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -19,21 +19,25 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@stylexjs/babel-plugin": "^0.12.0",
22
- "@stylexswc/rs-compiler": "0.8.2-dev.1",
22
+ "@stylexswc/rs-compiler": "0.9.0-rc.1",
23
23
  "fast-glob": "^3.3.3",
24
24
  "glob-parent": "^6.0.2",
25
25
  "is-glob": "^4.0.3",
26
26
  "postcss": "^8.5.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/types": "^7.27.3",
30
- "@stylexswc/eslint-config": "0.8.2-dev.1",
31
- "@stylexswc/typescript-config": "0.8.2-dev.1",
29
+ "@babel/types": "^7.27.7",
30
+ "@stylexswc/eslint-config": "0.9.0-rc.1",
31
+ "@stylexswc/typescript-config": "0.9.0-rc.1",
32
32
  "@types/babel__core": "^7.20.5",
33
33
  "@types/glob-parent": "^5.1.3",
34
34
  "@types/is-glob": "^4.0.4",
35
+ "@types/jest": "^29.5.14",
35
36
  "@types/loader-utils": "^2.0.6",
36
- "@types/node": "^22.15.29"
37
+ "@types/node": "^22.15.29",
38
+ "jest": "^29.7.0",
39
+ "jest-chain-transform": "^0.0.8",
40
+ "ts-jest": "^29.4.0"
37
41
  },
38
42
  "keywords": [
39
43
  "postcss",
@@ -52,7 +56,7 @@
52
56
  "postbuild": "pnpm run check:artifacts",
53
57
  "precommit": "lint-staged",
54
58
  "prepush": "lint-prepush",
55
- "test": "echo \"Error: no test specified\" && exit 0",
59
+ "test": "jest",
56
60
  "typecheck": "scripty"
57
61
  }
58
62
  }