Repository: effector/effector
Pull request #996 (2023-10-11 11:45:39)

Add custom `patronum` handling
### Conventions
- [ ] Please check your messages [against the guidelines](https://cbea.ms/git-commit/) if not, perform [interactive rebase](https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history)
- [ ] [Link an issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) your pull request closes or relates



Patch:
diff --git a/src/babel/babel-plugin.js b/src/babel/babel-plugin.js
index a500a1c6..645b190f 100644
--- a/src/babel/babel-plugin.js
+++ b/src/babel/babel-plugin.js
@@ -4,7 +4,8 @@ const defaultFactories = [
   '@effector/reflect/ssr',
   '@effector/reflect/scope',
   'atomic-router',
-  '@withease/factories'
+  '@withease/factories',
+  'patronum' // there is also custom handling for patronum/{method} imports
 ]
 
 module.exports = function (babel, options = {}) {
@@ -330,7 +331,11 @@ module.exports = function (babel, options = {}) {
           normalizedSource = stripRoot(rootPath, resolvedImport, true)
         }
         normalizedSource = stripExtension(normalizedSource)
-        if (this.effector_factoryPaths.includes(normalizedSource)) {
+        if (
+          this.effector_factoryPaths.includes(normalizedSource)
+          // custom handling for patronum/{method} imports
+          || normalizedSource.startsWith('patronum/')
+          ) {
           this.effector_needFactoryImport = true
           createFactoryTemplate()
 


Test patch:
diff --git a/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap b/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
index 12e61cc6..009e0bb0 100644
--- a/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
+++ b/src/babel/__tests__/__snapshots__/babel-plugin.test.js.snap
@@ -1987,9 +1987,11 @@ exports[`babel-plugin should default factories 1`] = `
 "var _effectorFileName = '/src/babel/__tests__/fixtures/default-factories.js'
 import {withFactory as _withFactory} from 'effector'
 import {createQuery} from '@farfetched/core'
+import {debounce} from 'patronum'
+import {delay} from 'patronum/delay'
 
 const q = _withFactory({
-  sid: '-9en8j0',
+  sid: '-8gjzqm',
   fn: () =>
     createQuery({
       handler: async () => null,
@@ -1998,10 +2000,44 @@ const q = _withFactory({
   method: 'createQuery',
   loc: {
     file: _effectorFileName,
-    line: 3,
+    line: 5,
     column: 10,
   },
 })
+
+_withFactory({
+  sid: '-d76u2e',
+  fn: () =>
+    debounce({
+      source: q,
+      timeout: 100,
+      target: q.refresh,
+    }),
+  name: 'none',
+  method: 'debounce',
+  loc: {
+    file: _effectorFileName,
+    line: 7,
+    column: 0,
+  },
+})
+
+_withFactory({
+  sid: 'e9kkk1',
+  fn: () =>
+    delay({
+      source: q,
+      timeout: 100,
+      target: q.refresh,
+    }),
+  name: 'none',
+  method: 'delay',
+  loc: {
+    file: _effectorFileName,
+    line: 13,
+    column: 0,
+  },
+})
 "
 `;
 
diff --git a/src/babel/__tests__/fixtures/default-factories.js b/src/babel/__tests__/fixtures/default-factories.js
index ddba977d..7278b083 100644
--- a/src/babel/__tests__/fixtures/default-factories.js
+++ b/src/babel/__tests__/fixtures/default-factories.js
@@ -1,3 +1,17 @@
 import {createQuery} from '@farfetched/core'
+import {debounce} from 'patronum'
+import {delay} from 'patronum/delay'
 
 const q = createQuery({handler: async () => null})
+
+debounce({
+  source: q,
+  timeout: 100,
+  target: q.refresh,
+})
+
+delay({
+  source: q,
+  timeout: 100,
+  target: q.refresh,
+})