require and __filename is not supported for ESM

This commit is contained in:
Sebastian 2022-10-31 00:07:37 -03:00
parent 4feb79f3c9
commit 2f17d81802
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
7 changed files with 33 additions and 24 deletions

View File

@ -1,7 +0,0 @@
#!/usr/bin/env node
try {
require('source-map-support').install();
} catch (e) {
// Do nothing.
}
require('../dist/taler-wallet-cli.js').main();

View File

@ -0,0 +1,15 @@
#!/usr/bin/env node
import { main } from '../lib/index.js';
async function run() {
try {
(await import('source-map-support')).install();
} catch (e) {
// Do nothing.
}
main();
}
run();

View File

@ -13,7 +13,7 @@
"license": "GPL-3.0",
"main": "dist/taler-wallet-cli.js",
"bin": {
"taler-wallet-cli": "./bin/taler-wallet-cli"
"taler-wallet-cli": "./bin/taler-wallet-cli.js"
},
"type": "module",
"scripts": {

View File

@ -20,6 +20,8 @@
import path from "path";
import fs from "fs";
const assetFileUrl = import.meta.url;
/**
* Resolve an asset name into an absolute filename.
*
@ -27,8 +29,8 @@ import fs from "fs";
* at the top level of the package (i.e. next to package.json).
*/
export function resolveAsset(name: string): string {
const n = __filename;
const d = __dirname;
const n = path.basename(assetFileUrl);
const d = path.dirname(assetFileUrl);
let assetPath: string;
// Currently both asset paths are the same.
// This might change if the file that contains "resolveAsset"

View File

@ -57,6 +57,7 @@ import {
import { deepStrictEqual } from "assert";
import axiosImp, { AxiosError } from "axios";
import { ChildProcess, spawn } from "child_process";
import * as child_process from "child_process";
import * as fs from "fs";
import * as http from "http";
import * as path from "path";
@ -77,7 +78,7 @@ import {
TippingReserveStatus,
} from "./merchantApiTypes.js";
const exec = util.promisify(require("child_process").exec);
const exec = util.promisify(child_process.exec);
const axios = axiosImp.default;
@ -485,7 +486,7 @@ class BankServiceBase {
protected globalTestState: GlobalTestState,
protected bankConfig: BankConfig,
protected configFile: string,
) {}
) { }
}
/**
@ -779,8 +780,7 @@ class LibEuFinBankService extends BankServiceBase implements BankServiceHandle {
*/
export class FakebankService
extends BankServiceBase
implements BankServiceHandle
{
implements BankServiceHandle {
proc: ProcessWrapper | undefined;
http = new NodeHttpLib();
@ -1131,7 +1131,7 @@ export class ExchangeService implements ExchangeServiceInterface {
private exchangeConfig: ExchangeConfig,
private configFilename: string,
private keyPair: EddsaKeyPair,
) {}
) { }
get name() {
return this.exchangeConfig.name;
@ -1384,7 +1384,7 @@ export class MerchantApiClient {
constructor(
private baseUrl: string,
public readonly auth: MerchantAuthConfiguration,
) {}
) { }
async changeAuth(auth: MerchantAuthConfiguration): Promise<void> {
const url = new URL("private/auth", this.baseUrl);
@ -1577,7 +1577,7 @@ export class MerchantService implements MerchantServiceInterface {
private globalState: GlobalTestState,
private merchantConfig: MerchantConfig,
private configFilename: string,
) {}
) { }
private currentTimetravel: Duration | undefined;
@ -1899,10 +1899,8 @@ export class WalletCli {
const resp = await sh(
self.globalTestState,
`wallet-${self.name}`,
`taler-wallet-cli ${
self.timetravelArg ?? ""
} ${cryptoWorkerArg} --no-throttle -LTRACE --skip-defaults --wallet-db '${
self.dbfile
`taler-wallet-cli ${self.timetravelArg ?? ""
} ${cryptoWorkerArg} --no-throttle -LTRACE --skip-defaults --wallet-db '${self.dbfile
}' api '${op}' ${shellWrap(JSON.stringify(payload))}`,
);
logger.info("--- wallet core response ---");

View File

@ -26,8 +26,9 @@ import {
ProcessWrapper,
} from "../harness/harness.js";
import { Configuration } from "@gnu-taler/taler-util";
import * as child_process from "child_process";
const exec = util.promisify(require("child_process").exec);
const exec = util.promisify(child_process.exec);
export interface SyncConfig {
/**
@ -114,5 +115,5 @@ export class SyncService {
private globalState: GlobalTestState,
private syncConfig: SyncConfig,
private configFilename: string,
) {}
) { }
}

View File

@ -26,7 +26,7 @@ import { processRequestWithImpl } from "./worker-common.js";
const logger = new Logger("nodeThreadWorker.ts");
const f = __filename;
const f = import.meta.url;
const workerCode = `
// Try loading the glue library for embedded