Files
actual/packages/api/index.js
Alberto Gasparin cd00da76ef Convert commonjs to esm (#877)
This PR converts everything (aside from electron) from CommonJS to ESM.
It is needed to reduce the changes that will happen during the migration
to Typescript (as TS does not play nice with CJS).

Basically:
- rewrite `require()` to `import`
- rewrite `module.exports` to `exports`
- introduce `ts-node` to run importers so we can convert them to TS too

Lastly, sorry for this larg-ish PR, not my preference but when I tried
to reduce its scope, I would end up with mixed commons/esm that was even
more tricky to handle.
2023-04-10 20:40:40 +01:00

32 lines
588 B
JavaScript

import fetch from 'node-fetch';
import * as bundle from './app/bundle.api';
import * as injected from './injected';
let actualApp;
export const internal = bundle.lib;
export * as methods from './methods';
export * as utils from './utils';
export async function init(config = {}) {
if (actualApp) {
return;
}
global.fetch = fetch;
await bundle.init(config);
actualApp = bundle.lib;
injected.override(bundle.lib.send);
return bundle.lib;
}
export async function shutdown() {
if (actualApp) {
await actualApp.send('close-budget');
actualApp = null;
}
}