Skip to content

Commit

Permalink
Compatible with https://esm.sh
Browse files Browse the repository at this point in the history
I'm making a cloud playground website that can import any library registered in the NPM registry with `esm.sh`.

By the way, as `esm.sh` has been published for `deno`, it is not possible to import `NodeJS` built-in libraries.

In such reason, this PR removes every direct import statements to the NodeJS built-in libraries, and performed indirect import through `import2` library, so that bundler cannot merge them.
  • Loading branch information
samchon committed Mar 27, 2024
1 parent 5d60d6a commit b27b91e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 91 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "samchon.github@gmail.com",
"url": "https://github.com/samchon"
},
"version": "2.5.13",
"version": "2.5.16",
"typings": "./index.d.ts",
"main": "./index.js",
"scripts": {
Expand Down
71 changes: 0 additions & 71 deletions src/exception/global.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/exception/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ export * from "./SystemError";
export * from "./ErrorCategory";
export * from "./ErrorCode";
export * from "./ErrorCondition";

export * from "./global";
10 changes: 0 additions & 10 deletions src/test/exception/test_terminate.ts

This file was deleted.

25 changes: 18 additions & 7 deletions src/utility/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@
* @module std
*/
//================================================================
let is_node_: boolean | null = null;

/**
* Test whether the code is running on NodeJS.
*
* @return Whether NodeJS or not.
*/
export function is_node(): boolean {
if (is_node_ === null)
is_node_ =
typeof global === "object" &&
typeof global.process === "object" &&
typeof global.process.versions === "object" &&
typeof global.process.versions.node !== "undefined";
is_node_ = typeof global === "object" && is_node_process(global);
return is_node_;
}

/**
* @internal
*/
function is_node_process(m: typeof global | null): boolean {
return m !== null &&
typeof m.process === "object" &&
m.process !== null &&
typeof m.process.versions === "object" &&
m.process.versions !== null &&
typeof m.process.versions.node !== "undefined";
}

/**
* @internal
*/
let is_node_: boolean | null = null;

0 comments on commit b27b91e

Please sign in to comment.