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", "license": "GPL-3.0",
"main": "dist/taler-wallet-cli.js", "main": "dist/taler-wallet-cli.js",
"bin": { "bin": {
"taler-wallet-cli": "./bin/taler-wallet-cli" "taler-wallet-cli": "./bin/taler-wallet-cli.js"
}, },
"type": "module", "type": "module",
"scripts": { "scripts": {

View File

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

View File

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

View File

@ -26,8 +26,9 @@ import {
ProcessWrapper, ProcessWrapper,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { Configuration } from "@gnu-taler/taler-util"; 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 { export interface SyncConfig {
/** /**
@ -114,5 +115,5 @@ export class SyncService {
private globalState: GlobalTestState, private globalState: GlobalTestState,
private syncConfig: SyncConfig, private syncConfig: SyncConfig,
private configFilename: string, private configFilename: string,
) {} ) { }
} }

View File

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