-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2161 from Nesopie/feat/hybrid
Add CJS and ESM support
- Loading branch information
Showing
165 changed files
with
12,546 additions
and
8,951 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/mocharc.json", | ||
"require": "tsx" | ||
} |
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,78 @@ | ||
import typescriptEslint from "@typescript-eslint/eslint-plugin"; | ||
import globals from "globals"; | ||
import tsParser from "@typescript-eslint/parser"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import js from "@eslint/js"; | ||
import { FlatCompat } from "@eslint/eslintrc"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const compat = new FlatCompat({ | ||
baseDirectory: __dirname, | ||
recommendedConfig: js.configs.recommended, | ||
allConfig: js.configs.all | ||
}); | ||
|
||
export default [...compat.extends( | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended", | ||
), { | ||
plugins: { | ||
"@typescript-eslint": typescriptEslint, | ||
}, | ||
|
||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
...globals.amd, | ||
...globals.node, | ||
}, | ||
|
||
parser: tsParser, | ||
}, | ||
|
||
rules: { | ||
"prettier/prettier": ["error", { | ||
singleQuote: true, | ||
trailingComma: "all", | ||
endOfLine: "auto", | ||
arrowParens: "avoid", | ||
tabWidth: 2, | ||
}], | ||
|
||
"arrow-body-style": "off", | ||
"prefer-arrow-callback": "off", | ||
"@typescript-eslint/array-type": 0, | ||
"@typescript-eslint/no-inferrable-types": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"arrow-parens": "off", | ||
curly: "off", | ||
"no-case-declarations": "off", | ||
quotes: "off", | ||
|
||
"@/quotes": ["error", "single", { | ||
avoidEscape: true, | ||
allowTemplateLiterals: true, | ||
}], | ||
|
||
"prefer-rest-params": "off", | ||
"no-bitwise": "off", | ||
"no-console": "off", | ||
|
||
"no-empty": ["error", { | ||
allowEmptyCatch: true, | ||
}], | ||
|
||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"no-unused-expressions": "off", | ||
"@typescript-eslint/no-unused-expressions": "off", | ||
"@typescript-eslint/no-empty-object-type": "off", | ||
"space-before-function-paren": "off", | ||
}, | ||
}]; |
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,25 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const updateRequires = (filePath) => { | ||
let content = fs.readFileSync(filePath, 'utf8'); | ||
//replace local imports eg. require("./ecpair.js") to require("ecpair.cjs") | ||
content = content.replace(/require\('\.\/([^']*)\.js'\)/g, "require('./$1.cjs')"); | ||
content = content.replace(/require\('\.\.\/([^']*)\.js'\)/g, "require('../$1.cjs')"); | ||
|
||
fs.writeFileSync(filePath, content, 'utf8'); | ||
}; | ||
|
||
const processFiles = (dir) => { | ||
fs.readdirSync(dir).forEach((file) => { | ||
const filePath = path.join(dir, file); | ||
if (fs.lstatSync(filePath).isDirectory()) { | ||
processFiles(filePath); | ||
} else if (filePath.endsWith('.cjs')) { | ||
updateRequires(filePath); | ||
} | ||
}); | ||
}; | ||
|
||
const dir = path.join(__dirname, 'src', 'cjs'); | ||
processFiles(dir); |
Oops, something went wrong.