Skip to content

Commit

Permalink
Merge pull request #2161 from Nesopie/feat/hybrid
Browse files Browse the repository at this point in the history
Add CJS and ESM support
  • Loading branch information
junderw authored Sep 8, 2024
2 parents f06bbce + 240be2f commit d6fe656
Show file tree
Hide file tree
Showing 165 changed files with 12,546 additions and 8,951 deletions.
57 changes: 0 additions & 57 deletions .eslintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"require": "tsx"
}
78 changes: 78 additions & 0 deletions eslint.config.js
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",
},
}];
25 changes: 25 additions & 0 deletions fixup.cjs
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);
Loading

0 comments on commit d6fe656

Please sign in to comment.