From 157b58a2dd3a0ff2c2abc308bc3f5e1a306a0e17 Mon Sep 17 00:00:00 2001
From: James Long <longster@gmail.com>
Date: Thu, 1 Dec 2022 23:13:48 -0500
Subject: [PATCH] Import only what's needed from the API for importer packages

---
 packages/api/index.js             |  3 +--
 packages/import-ynab4/importer.js | 10 +++++++---
 packages/import-ynab5/importer.js |  6 +++++-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/packages/api/index.js b/packages/api/index.js
index dbdba25f3..6d163887e 100644
--- a/packages/api/index.js
+++ b/packages/api/index.js
@@ -1,8 +1,7 @@
 let bundle = require('./app/bundle.api.js');
+let injected = require('./injected');
 let methods = require('./methods');
 let utils = require('./utils');
-
-let injected = require('./injected');
 let actualApp;
 
 async function init({ budgetId, config } = {}) {
diff --git a/packages/import-ynab4/importer.js b/packages/import-ynab4/importer.js
index ee77397e7..c98a17f72 100644
--- a/packages/import-ynab4/importer.js
+++ b/packages/import-ynab4/importer.js
@@ -1,9 +1,13 @@
+// This is a special usage of the API because this package is embedded
+// into Actual itself. We only want to pull in the methods in that
+// case and ignore everything else; otherwise we'd be pulling in the
+// entire backend bundle from the API
+const actual = require('@actual-app/api/methods');
+const { amountToInteger } = require('@actual-app/api/utils');
+const AdmZip = require('adm-zip');
 const d = require('date-fns');
 const normalizePathSep = require('slash');
 const uuid = require('uuid');
-const AdmZip = require('adm-zip');
-const actual = require('@actual-app/api');
-const amountToInteger = actual.utils.amountToInteger;
 
 // Utils
 
diff --git a/packages/import-ynab5/importer.js b/packages/import-ynab5/importer.js
index a1966cf16..ea6b48cb6 100644
--- a/packages/import-ynab5/importer.js
+++ b/packages/import-ynab5/importer.js
@@ -1,6 +1,10 @@
+// This is a special usage of the API because this package is embedded
+// into Actual itself. We only want to pull in the methods in that
+// case and ignore everything else; otherwise we'd be pulling in the
+// entire backend bundle from the API
+const actual = require('@actual-app/api/methods');
 const d = require('date-fns');
 const uuid = require('uuid');
-const actual = require('@actual-app/api');
 
 function amountFromYnab(amount) {
   // ynabs multiplies amount by 1000 and actual by 100
-- 
GitLab