From b8d3b5eb84058e9a98ad57313f717f754e586b3c Mon Sep 17 00:00:00 2001 From: minicx Date: Fri, 18 Aug 2023 22:01:16 +0300 Subject: [PATCH] Fixed error with exports --- .eslintrc.json | 8 ++++++- .gitignore | 5 +++- README.md | 4 ++-- package.json | 32 ++++++++++++++++--------- rollup.config.mjs | 44 ++++++++++++++++++++++++++++++++++ src/index.ts | 1 - tsconfig-cjs.json | 7 ------ tsconfig.json | 61 ++++++++++++++++++++++------------------------- 8 files changed, 106 insertions(+), 56 deletions(-) create mode 100644 rollup.config.mjs delete mode 100644 tsconfig-cjs.json diff --git a/.eslintrc.json b/.eslintrc.json index 7fa29c4..f060460 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,5 @@ { + "$schema": "https://json.schemastore.org/eslintrc", "extends": [ "eslint:recommended", "plugin:unicorn/recommended", @@ -8,8 +9,13 @@ ], "parser": "@typescript-eslint/parser", "parserOptions": { - "project": "./tsconfig.json" + "project": true }, + "root": true, + + "ignorePatterns":[ + "dist/" + ], "plugins": [ "@typescript-eslint", "unicorn", diff --git a/.gitignore b/.gitignore index 25bed58..9670794 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ dist # Logs -*.log* \ No newline at end of file +*.log* + + +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 78e847f..e73e147 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ npm install flaresolverr.js # or yarn add flaresolverr.js ## Usage: ```typescript -const FlareSolverr = require('flaresolverr.js'); +const { FlareSolverr } = require('flaresolverr.js'); /* Also you can import this library via esm syntax: -import FlareSolverr from "Flaresolverr.js" +import { FlareSolverr } from "Flaresolverr.js" */ // Initialize FlareSolverr with the API endpoint URL diff --git a/package.json b/package.json index c295d5d..3a1023a 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,20 @@ { "name": "flaresolverr.js", "version": "0.0.1", - "type": "module", - "description": "Api for dockered FlareSolverr", - "main": "./dist/cjs/index.js", - "module": "./dist/mjs/index.js", - "types": "./dist/index.d.ts", + "description": "Api for bypassing cloudflare via dockered FlareSolverr", "files": [ "dist", "README.md", "LICENSE" ], + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "exports": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs", + "types": "./dist/index.d.ts" + }, "author": "minicx", "license": "MIT", "homepage": "https://git.disroot.org/minicx/FlareSolverr.js#README.md", @@ -27,17 +31,22 @@ "cloudflare bypass" ], "scripts": { - "build:mjs": "tsc -p tsconfig.json", - "build:cjs": "tsc -p tsconfig-cjs.json", - "build": "npm run build:mjs && npm run build:cjs", - "lint": "eslint --fix src/**", - "format": "prettier --write src/**", + "build:mjs": "rm -rf dist/mjs && tsc -p tsconfig.json", + "build:cjs": "rm -rf dist/cjs && tsc -p tsconfig-cjs.json", + "build": "rollup -c", + "lint": "eslint --fix .", + "format": "prettier --write src/** rollup.config.mjs", "prepublishOnly": "npm run lint && npm run build" }, "engines": { "node": ">=16" }, "devDependencies": { + "@rollup-extras/plugin-clean": "^1.3.6", + "@rollup/plugin-commonjs": "^25.0.4", + "@rollup/plugin-eslint": "^9.0.4", + "@rollup/plugin-terser": "^0.4.3", + "@rollup/plugin-typescript": "^11.1.2", "@types/mocha": "^10.0.1", "@types/node": "^16", "@typescript-eslint/eslint-plugin": "^6.4.0", @@ -50,7 +59,8 @@ "eslint-plugin-unicorn": "^48.0.1", "mocha": "^10.2.0", "prettier": "^3.0.2", - "ts-node": "^10.9.1", + "rollup": "^3.28.0", + "tslib": "^2.6.1", "typescript": "^5.1.6" } } diff --git a/rollup.config.mjs b/rollup.config.mjs new file mode 100644 index 0000000..d83816c --- /dev/null +++ b/rollup.config.mjs @@ -0,0 +1,44 @@ +import terser from '@rollup/plugin-terser'; +import ts from '@rollup/plugin-typescript'; +import eslint from '@rollup/plugin-eslint'; +import clean from '@rollup-extras/plugin-clean'; + +const output_dir = 'dist'; + +const rollupConfig = { + input: 'src/index.ts', + output: [ + { + dir: output_dir, + format: 'esm', + entryFileNames: '[name].mjs', + }, + { + dir: output_dir, + format: 'commonjs', + entryFileNames: '[name].cjs', + }, + ], + plugins: [ + clean('dist'), + eslint({ + fix: true, + useEslintrc: true, + }), + ts({ + tsconfig: 'tsconfig.json', + }), + terser({ + format: { + comments: 'some', + beautify: true, + ecma: 2020, + }, + compress: true, + mangle: false, + module: true, + }), + ], +}; + +export default rollupConfig; diff --git a/src/index.ts b/src/index.ts index 7270123..48181e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1 @@ -export { FlareSolverr as default } from './FlareSolverr.js'; export { FlareSolverr } from './FlareSolverr.js'; diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json deleted file mode 100644 index 1fce6c1..0000000 --- a/tsconfig-cjs.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "CommonJS", - "outDir": "./dist/cjs" - }, - } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 046febd..9c5622f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1,30 @@ { - "compilerOptions": { - "target": "ES6", - "module": "ES2022", - "moduleResolution": "Node16", - - "rootDir": "./src", - "outDir": "./dist/mjs", - - "types": [ - "node", - "mocha" + "compilerOptions": { + "rootDir":"src", + "esModuleInterop": true, + "importHelpers": true, + "moduleResolution": "Node16", + "outDir": "./dist", + "types": [ + "node", + "mocha" + ], + "declaration": true, + "declarationDir": "./dist", + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true + }, + "ts-node": { + "pretty": true, + "esm": true + }, + "include": [ + "src", ], - - "declaration": true, - "declarationDir": "dist", - "inlineSourceMap":true, - - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true - }, - "ts-node": { - "pretty": true, - "esm": true - }, - "include": [ - "src" - ], - "exclude": [ - "node_modules", - "dist" - ] -} \ No newline at end of file + "exclude": [ + "node_modules", + "dist" + ] + } \ No newline at end of file