@stylexjs/babel-plugin 0.2.0-beta.18 → 0.2.0-beta.19

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.
Files changed (2) hide show
  1. package/lib/index.js +21 -10
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -113,8 +113,8 @@ class StateManager {
113
113
  if (!matchesFileSuffix(themeFileExtension)(importPath)) {
114
114
  return false;
115
115
  }
116
- const resolvedFilePath = filePathResolver(importPath, rootDir);
117
- return resolvedFilePath ? ["themeNameRef", resolvedFilePath] : false;
116
+ const resolvedFilePath = filePathResolver(importPath, sourceFilePath);
117
+ return resolvedFilePath ? ["themeNameRef", path.relative(rootDir, resolvedFilePath)] : false;
118
118
  }
119
119
  case "haste":
120
120
  {
@@ -145,16 +145,27 @@ class StateManager {
145
145
  }
146
146
  }
147
147
  const filePathResolver = (relativeFilePath, sourceFilePath) => {
148
- const fileToLookFor = addFileExtension(relativeFilePath, sourceFilePath);
149
- try {
150
- const resolvedFilePath = require.resolve(fileToLookFor, {
151
- paths: [path.dirname(sourceFilePath)]
152
- });
153
- return resolvedFilePath;
154
- } catch {}
148
+ const fileToLookFor = relativeFilePath;
149
+ if (EXTENSIONS.some(ext => fileToLookFor.endsWith(ext))) {
150
+ try {
151
+ const resolvedFilePath = require.resolve(fileToLookFor, {
152
+ paths: [path.dirname(sourceFilePath)]
153
+ });
154
+ return resolvedFilePath;
155
+ } catch {}
156
+ }
157
+ for (const ext of EXTENSIONS) {
158
+ try {
159
+ const resolvedFilePath = require.resolve(fileToLookFor + ext, {
160
+ paths: [path.dirname(sourceFilePath)]
161
+ });
162
+ return resolvedFilePath;
163
+ } catch {}
164
+ }
155
165
  };
166
+ const EXTENSIONS = [".js", ".ts", ".tsx", ".jsx", ".mjs", ".cjs"];
156
167
  const addFileExtension = (importedFilePath, sourceFile) => {
157
- if (importedFilePath.endsWith(".js") || importedFilePath.endsWith(".ts") || importedFilePath.endsWith(".tsx") || importedFilePath.endsWith(".jsx") || importedFilePath.endsWith(".mjs") || importedFilePath.endsWith(".cjs")) {
168
+ if (EXTENSIONS.some(ext => importedFilePath.endsWith(ext))) {
158
169
  return importedFilePath;
159
170
  }
160
171
  const fileExtension = path.extname(sourceFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/babel-plugin",
3
- "version": "0.2.0-beta.18",
3
+ "version": "0.2.0-beta.19",
4
4
  "description": "StyleX babel plugin.",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/facebook/stylex",
@@ -12,7 +12,7 @@
12
12
  "test": "jest"
13
13
  },
14
14
  "dependencies": {
15
- "@stylexjs/shared": "0.2.0-beta.18"
15
+ "@stylexjs/shared": "0.2.0-beta.19"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "@babel/core": "^7.19.6",