@cssxjs/babel-plugin-rn-stylename-to-style 0.2.16 → 0.2.17

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.2.17 (Mon Nov 10 2025)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - fix(babel-plugin-rn-stylename-to-style): change the default extensions to compile to .cssx.css and .cssx.styl (cray0000@gmail.com)
6
+
7
+ #### Authors: 1
8
+
9
+ - Pavel Zhukov (cray0000@gmail.com)
10
+
11
+ ---
12
+
1
13
  # v0.2.16 (Sun Nov 09 2025)
2
14
 
3
15
  #### 🚀 Enhancement
package/README.md CHANGED
@@ -103,7 +103,7 @@ You must give one or more file extensions inside an array in the plugin options.
103
103
 
104
104
  #### `extensions`
105
105
 
106
- **Required**
106
+ **Default** `['cssx.css', 'cssx.styl']`
107
107
 
108
108
  List of css extensions to process (`css`, `styl`, `sass`, etc.)
109
109
 
package/index.js CHANGED
@@ -9,6 +9,7 @@ const { addNamed } = require('@babel/helper-module-imports')
9
9
  const COMPILERS = require('@cssxjs/loaders/compilers')
10
10
  const RUNTIME_LIBRARY = 'cssxjs/runtime'
11
11
  const DEFAULT_PLATFORM = 'web'
12
+ const DEFAULT_EXTENSIONS = ['cssx.css', 'cssx.styl']
12
13
  const STYLE_NAME_REGEX = /(?:^s|S)tyleName$/
13
14
  const STYLE_REGEX = /(?:^s|S)tyle$/
14
15
  const ROOT_STYLE_PROP_NAME = 'style'
@@ -293,28 +294,25 @@ module.exports = function (babel) {
293
294
  if (!hasObserver) hasObserver = checkObserverImport($this, state)
294
295
  if (!hasFrameworkImport) hasFrameworkImport = checkHasFrameworkImport($this, state)
295
296
 
296
- const extensions =
297
- Array.isArray(state.opts.extensions) &&
298
- state.opts.extensions
297
+ const extensions = state.opts.extensions ?? DEFAULT_EXTENSIONS
299
298
 
300
- if (!extensions) {
301
- throw new Error(
302
- 'You have not specified any extensions in the plugin options.'
303
- )
299
+ if (!Array.isArray(extensions)) {
300
+ throw Error(`
301
+ You have not specified any extensions in the plugin options.
302
+ The 'extensions' option must be an array of strings like ['styl', 'css'].
303
+ If you don't want to handle any CSS file imports then specify an empty array.
304
+ `)
304
305
  }
305
306
 
306
- const node = $this.node
307
-
308
- if (extensions.indexOf(getExt(node)) === -1) {
309
- return
310
- }
311
- const extension = getExt(node)
307
+ const source = $this.node.source.value
308
+ if (!extensions.some(ext => source.endsWith(`.${ext}`))) return
309
+ const compilerName = source.split('.').pop()
312
310
 
313
- const anonymousImports = $this.container.filter(n => {
311
+ const anonymousImports = $this.container.filter(node => {
314
312
  return (
315
- t.isImportDeclaration(n) &&
316
- n.specifiers.length === 0 &&
317
- extensions.indexOf(getExt(n)) > -1
313
+ t.isImportDeclaration(node) &&
314
+ node.specifiers.length === 0 &&
315
+ extensions.some(ext => node.source.value.endsWith(`.${ext}`))
318
316
  )
319
317
  })
320
318
 
@@ -324,13 +322,13 @@ module.exports = function (babel) {
324
322
  )
325
323
  }
326
324
 
327
- let specifier = node.specifiers[0]
325
+ let specifier = $this.node.specifiers[0]
328
326
 
329
327
  if (!specifier) {
330
328
  specifier = t.ImportDefaultSpecifier(
331
329
  $this.scope.generateUidIdentifier('css')
332
330
  )
333
- node.specifiers = [specifier]
331
+ $this.node.specifiers = [specifier]
334
332
  }
335
333
 
336
334
  const compileCssImports = state.opts.compileCssImports ?? true
@@ -340,17 +338,14 @@ module.exports = function (babel) {
340
338
  const filename = state.file?.opts?.filename
341
339
  const platform = state.opts?.platform || state.file?.opts?.caller?.platform || DEFAULT_PLATFORM
342
340
  // resolve the full path to the style file relative to the current file
343
- const styleFilepath = nodePath.resolve(
344
- nodePath.dirname(filename),
345
- node.source.value
346
- )
341
+ const styleFilepath = nodePath.resolve(nodePath.dirname(filename), source)
347
342
  // read the style file content
348
343
  const styleFileContent = fs.readFileSync(styleFilepath, 'utf8')
349
344
  // find the appropriate compiler
350
- const compiler = COMPILERS[extension]
345
+ const compiler = COMPILERS[compilerName]
351
346
  if (!compiler) {
352
347
  throw $this.buildCodeFrameError(
353
- `No compiler found for imported extension: "${extension}"`
348
+ `No compiler found for imported extension: "${source}"`
354
349
  )
355
350
  }
356
351
  const compiledString = compiler(
@@ -440,10 +435,6 @@ module.exports = function (babel) {
440
435
  }
441
436
  }
442
437
 
443
- function getExt (node) {
444
- return nodePath.extname(node.source.value).replace(/^\./, '')
445
- }
446
-
447
438
  function convertStyleName (name) {
448
439
  return name.replace(/Name$/, '')
449
440
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssxjs/babel-plugin-rn-stylename-to-style",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,13 +27,13 @@
27
27
  "@babel/parser": "^7.0.0",
28
28
  "@babel/template": "^7.4.0",
29
29
  "@babel/types": "^7.0.0",
30
- "@cssxjs/runtime": "^0.2.16"
30
+ "@cssxjs/runtime": "^0.2.17"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/plugin-syntax-jsx": "^7.0.0",
34
- "@cssxjs/babel-plugin-react-pug": "^0.2.16",
34
+ "@cssxjs/babel-plugin-react-pug": "^0.2.17",
35
35
  "babel-plugin-tester": "^9.1.0",
36
36
  "jest": "^30.0.4"
37
37
  },
38
- "gitHead": "4b62363af9606001df70548a69afc655545edab7"
38
+ "gitHead": "02b76ae074674c67f8d50a85b091e1190648449d"
39
39
  }