@cssxjs/babel-plugin-rn-stylename-to-style 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.cjs +29 -25
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.2.1 (Tue Nov 04 2025)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - fix: fix the auto-removal of css, styl, pug; add explicit check that pug is imported before trying to use it ([@cray0000](https://github.com/cray0000))
6
+
7
+ #### Authors: 1
8
+
9
+ - Pavel Zhukov ([@cray0000](https://github.com/cray0000))
10
+
11
+ ---
12
+
1
13
  # v0.2.0 (Tue Nov 04 2025)
2
14
 
3
15
  #### 🚀 Enhancement
package/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  const nodePath = require('path')
2
2
  const t = require('@babel/types')
3
3
  const template = require('@babel/template').default
4
+ const { GLOBAL_NAME, LOCAL_NAME } = require('@cssxjs/runtime/constants')
4
5
 
5
- const COMPILERS = ['css', 'styl'] // used in rn-stylename-inline. TODO: move to a shared place
6
+ const COMPILERS = ['css', 'styl', 'pug'] // used in rn-stylename-inline. TODO: move to a shared place
6
7
  const RUNTIME_LIBRARY = 'cssxjs/runtime'
7
8
  const STYLE_NAME_REGEX = /(?:^s|S)tyleName$/
8
9
  const STYLE_REGEX = /(?:^s|S)tyle$/
@@ -10,11 +11,9 @@ const ROOT_STYLE_PROP_NAME = 'style'
10
11
  const RUNTIME_PROCESS_NAME = 'cssx'
11
12
  const OPTIONS_CACHE = ['teamplay']
12
13
  const OPTIONS_PLATFORM = ['react-native', 'web']
13
-
14
- const GLOBAL_OBSERVER_LIBRARY = 'startupjs'
15
- const GLOBAL_OBSERVER_DEFAULT_NAME = 'observer'
16
-
17
- const { GLOBAL_NAME, LOCAL_NAME } = require('@cssxjs/runtime/constants')
14
+ const DEFAULT_MAGIC_IMPORTS = ['cssxjs', 'startupjs']
15
+ const DEFAULT_OBSERVER_NAME = 'observer'
16
+ const DEFAULT_OBSERVER_IMPORTS = ['teamplay', 'startupjs']
18
17
 
19
18
  const buildSafeVar = template.expression(`
20
19
  typeof %%variable%% !== 'undefined' && %%variable%%
@@ -253,14 +252,14 @@ module.exports = function (babel) {
253
252
  // TODO: Refactor this to move the sub-visitor out into getVisitor() function
254
253
  enter ($this, state) {
255
254
  // 1. Init
256
- usedCompilers = getUsedCompilers($this)
255
+ usedCompilers = getUsedCompilers($this, state)
257
256
  state.reqName = $this.scope.generateUidIdentifier(RUNTIME_PROCESS_NAME)
258
257
  $program = $this
259
258
 
260
259
  // 2. Run early traversal of everything
261
260
  $this.traverse({
262
261
  ImportDeclaration ($this, state) {
263
- if (!hasObserver) hasObserver = checkObserverImport($this)
262
+ if (!hasObserver) hasObserver = checkObserverImport($this, state)
264
263
 
265
264
  const extensions =
266
265
  Array.isArray(state.opts.extensions) &&
@@ -398,7 +397,7 @@ module.exports = function (babel) {
398
397
 
399
398
  if (lastImportOrRequire) {
400
399
  const useImport = state.opts.useImport == null ? true : state.opts.useImport
401
- const runtimePath = getRuntimePath($this, state)
400
+ const runtimePath = getRuntimePath($this, state, hasObserver)
402
401
  lastImportOrRequire.insertAfter(
403
402
  useImport
404
403
  ? buildImport({ name: state.reqName, runtimePath: t.stringLiteral(runtimePath) })
@@ -502,15 +501,15 @@ function buildDynamicPart (expr, part) {
502
501
  }
503
502
  }
504
503
 
505
- function checkObserverImport ($import, {
506
- observerLibrary = GLOBAL_OBSERVER_LIBRARY,
507
- observerDefaultName = GLOBAL_OBSERVER_DEFAULT_NAME
508
- } = {}) {
509
- if ($import.node.source.value !== observerLibrary) return
504
+ // if cache is 'teamplay'
505
+ function checkObserverImport ($import, state) {
506
+ const observerImports = state.opts.observerImports || DEFAULT_OBSERVER_IMPORTS
507
+ const observerName = state.opts.observerName || DEFAULT_OBSERVER_NAME
508
+ if (!observerImports.includes($import.node.source.value)) return
510
509
  for (const $specifier of $import.get('specifiers')) {
511
510
  if (!$specifier.isImportSpecifier()) continue
512
511
  const { imported } = $specifier.node
513
- if (imported.name === observerDefaultName) return true
512
+ if (imported.name === observerName) return true
514
513
  }
515
514
  }
516
515
 
@@ -537,30 +536,35 @@ function findReactFnComponent ($jsxAttribute) {
537
536
  }
538
537
 
539
538
  // Get compilers from the magic import
540
- function getUsedCompilers ($program) {
539
+ function getUsedCompilers ($program, state) {
540
+ const res = {}
541
+ const magicImports = state.opts.magicImports || DEFAULT_MAGIC_IMPORTS
541
542
  for (const $import of $program.get('body')) {
542
543
  if (!$import.isImportDeclaration()) continue
543
- if ($import.get('source').node.value !== GLOBAL_OBSERVER_LIBRARY) continue
544
- const usedCompilers = {}
544
+ if (!magicImports.includes($import.node.source.value)) continue
545
545
  for (const $specifier of $import.get('specifiers')) {
546
546
  if (!$specifier.isImportSpecifier()) continue
547
- const importedName = $specifier.get('imported').node.name
548
- if (COMPILERS.includes(importedName)) {
549
- const localName = $specifier.get('local').node.name
550
- usedCompilers[localName] = true
547
+ const { local, imported } = $specifier.node
548
+ if (COMPILERS.includes(imported.name)) {
549
+ res[local.name] = true
550
+ $specifier.remove()
551
551
  }
552
552
  }
553
- return usedCompilers
553
+ if ($import.get('specifiers').length === 0) $import.remove()
554
554
  }
555
+ return res
555
556
  }
556
557
 
557
- function getRuntimePath ($node, state) {
558
- const cache = state.opts.cache
558
+ function getRuntimePath ($node, state, hasObserver) {
559
+ let cache = state.opts.cache
559
560
  if (cache && !OPTIONS_CACHE.includes(cache)) {
560
561
  throw $node.buildCodeFrameError(
561
562
  `Invalid cache option value: "${cache}". Supported values: ${OPTIONS_CACHE.join(', ')}`
562
563
  )
563
564
  }
565
+ // If observer() is used in this file then we force cache to 'teamplay'
566
+ // TODO: this is a bit of a hack, think of a better way to do this
567
+ if (!cache && hasObserver) cache = 'teamplay'
564
568
  const platform = state.opts.platform
565
569
  if (platform && !OPTIONS_PLATFORM.includes(platform)) {
566
570
  throw $node.buildCodeFrameError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssxjs/babel-plugin-rn-stylename-to-style",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,16 +32,16 @@
32
32
  "dependencies": {
33
33
  "@babel/template": "^7.4.0",
34
34
  "@babel/types": "^7.0.0",
35
- "@cssxjs/runtime": "^0.2.0"
35
+ "@cssxjs/runtime": "^0.2.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@babel/plugin-syntax-jsx": "^7.0.0",
39
- "@cssxjs/babel-plugin-react-pug": "^0.2.0",
39
+ "@cssxjs/babel-plugin-react-pug": "^0.2.1",
40
40
  "babel-plugin-tester": "^9.1.0",
41
41
  "jest": "^30.0.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "teamplay": "*"
45
45
  },
46
- "gitHead": "a80a44b4d14c116871ca03997ce772b6beabf5d8"
46
+ "gitHead": "44fe78c4d462f9720bb40aceecfceff0bbda6c2f"
47
47
  }