-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- build as esm module project - add support to es2022 - add CI pipelines
- Loading branch information
Showing
12 changed files
with
4,460 additions
and
3,426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Main CI Workflow | ||
|
||
on: push | ||
|
||
|
||
jobs: | ||
build-test-eslint-node-18: | ||
name: Build, Test & Eslint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 18 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
- run: yarn install | ||
- run: yarn build | ||
- run: yarn test | ||
- run: yarn eslint | ||
|
||
build-test-eslint-node-20: | ||
name: Build, Test & Eslint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20 | ||
- run: yarn install | ||
- run: yarn build | ||
- run: yarn test | ||
- run: yarn eslint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import { dirname } from "node:path"; | ||
import { argv } from "node:process"; | ||
import { createRequire } from "node:module"; | ||
import callerPath from "caller-path"; | ||
|
||
/** | ||
* Allow to require modules relative to the caller file. | ||
* require() is not support in ESM modules. This function provides a workaround when you have to use require() in ESM modules. | ||
* e.g. use to load JSON files. | ||
* Or use to load legacy commonjs modules where formal `import` syntax is not convenient. | ||
* e.g. load legacy commonjs modules without type definition files. | ||
* | ||
* Please note: before use this function, you should try to use `import` syntax whenever possible. | ||
* | ||
* @param {string} id | ||
* @return {*} {*} | ||
*/ | ||
export function require(id: string): any { | ||
const requireFrom = createRequire(callerPath({ depth: 1 }) as string); | ||
return requireFrom(id); | ||
} | ||
|
||
export function requireResolve(id: string): string { | ||
const requireFrom = createRequire(callerPath({ depth: 1 }) as string); | ||
return requireFrom.resolve(id); | ||
} | ||
|
||
/** | ||
* This is an ESM replacement for `__filename`. | ||
* | ||
* Use it like this: `__filename()`. | ||
*/ | ||
export const __filename = (): string => | ||
fileURLToPath(callerPath({ depth: 1 }) as string); | ||
|
||
/** | ||
* This is an ESM replacement for `__dirname`. | ||
* | ||
* Use it like this: `__dirname()`. | ||
*/ | ||
export const __dirname = (): string => | ||
dirname(fileURLToPath(callerPath({ depth: 1 }) as string)); | ||
|
||
/** | ||
* Indicates that the script was run directly. | ||
* This is an ESM replacement for `require.main === module`. | ||
* | ||
* Use it like this: `isMain()`. | ||
*/ | ||
export const isMain = (): boolean => { | ||
if (!argv[1]) return false; | ||
const currentPath = callerPath({ depth: 1 }) as string; | ||
const require = createRequire(currentPath); | ||
const scriptPath = require.resolve(argv[1]); | ||
// get file path of caller module path | ||
const modulePath = fileURLToPath(currentPath); | ||
return scriptPath === modulePath; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.