Skip to content

Commit

Permalink
refactor(@deltachat/stdio-rpc-server): use old school require instead…
Browse files Browse the repository at this point in the history
… of the experimental json import (#5628)

to get rid of warning. Should also make it possible to use nodejs versions older than 20.11.
  • Loading branch information
Simon-Laux authored Jun 7, 2024
1 parent 9c2526b commit d412887
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deltachat-rpc-server/npm-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This simplifies cross-compilation and even reduces binary size (no CFFI layer an

## Usage

> The **minimum** nodejs version for this package is `20.11`
> The **minimum** nodejs version for this package is `16`
```
npm i @deltachat/stdio-rpc-server @deltachat/jsonrpc-client
Expand Down
10 changes: 6 additions & 4 deletions deltachat-rpc-server/npm-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR,
} from "./src/errors.js";

// Because this is not compiled by typescript, esm needs this stuff (` with { type: "json" };`,
// nodejs still complains about it being experimental, but deno also uses it, so treefit bets taht it will become standard)
import package_json from "./package.json" with { type: "json" };
import { createRequire } from "node:module";

function findRPCServerInNodeModules() {
Expand All @@ -25,7 +22,12 @@ function findRPCServerInNodeModules() {
return resolve(package_name);
} catch (error) {
console.debug("findRpcServerInNodeModules", error);
if (Object.keys(package_json.optionalDependencies).includes(package_name)) {
const require = createRequire(import.meta.url);
if (
Object.keys(require("./package.json").optionalDependencies).includes(
package_name
)
) {
throw new Error(NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR(package_name));
} else {
throw new Error(NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR());
Expand Down

0 comments on commit d412887

Please sign in to comment.