diff --git a/.eslintrc.js b/.eslintrc.js index b4788c3a..1f06c06f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,4 @@ -const extensions = [".mjs", ".js", ".json"]; +const extensions = [".mjs", ".js", ".cjs", ".json"]; module.exports = { root: true, extends: [ diff --git a/package.json b/package.json index 398f71fc..d98800e5 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,13 @@ }, "license": "MIT", "author": "Anton Kudryavtsev ", - "main": "dist/index.js", - "module": "dist/index.mjs", - "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "files": [ "dist" ], diff --git a/rollup.config.js b/rollup.config.js index b3b021a4..aeb9e960 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -11,7 +11,7 @@ import resolve from "@rollup/plugin-node-resolve"; import typescript from "@rollup/plugin-typescript"; import pkg from "./package.json"; -const extensions = [".ts", ".mjs", ".js", ".json"]; +const extensions = [".ts", ".mjs", ".js", ".cjs", ".json"]; /** @type {import('rollup').RollupOptions[]} */ const config = [ diff --git a/src/.eslintrc.js b/src/.eslintrc.js index e00433da..194b28d2 100644 --- a/src/.eslintrc.js +++ b/src/.eslintrc.js @@ -1,5 +1,5 @@ const { join } = require("path"); -const extensions = [".ts", ".mjs", ".js", ".json"]; +const extensions = [".ts", ".mjs", ".js", ".cjs", ".json"]; module.exports = { root: true, extends: [ diff --git a/src/utils/load-module.ts b/src/utils/load-module.ts index 9165d93d..f48d52c6 100644 --- a/src/utils/load-module.ts +++ b/src/utils/load-module.ts @@ -5,7 +5,7 @@ const loaded: Record = {}; const options: ResolveOpts = { caller: "Module loader", basedirs: [process.cwd()], - extensions: [".js", ".mjs", ".json"], + extensions: [".cjs", ".js", ".mjs", ".json"], preserveSymlinks: false, packageFilter: pkg => pkg, }; diff --git a/src/utils/resolve.ts b/src/utils/resolve.ts index 725f3265..60e4cfa8 100644 --- a/src/utils/resolve.ts +++ b/src/utils/resolve.ts @@ -6,7 +6,7 @@ export interface ResolveOpts { caller?: string; /** directories to begin resolving from (defaults to `[__dirname]`) */ basedirs?: string[]; - /** array of file extensions to search in order (defaults to `[".mjs", ".js", ".json"]`) */ + /** array of file extensions to search in order (defaults to `[".mjs", ".js", ".cjs", ".json"]`) */ extensions?: string | ReadonlyArray; /** don't resolve `basedirs` to real path before resolving. (defaults to `true`) */ preserveSymlinks?: boolean; @@ -31,7 +31,7 @@ interface Package { const defaultOpts: ResolveDefaultOpts = { caller: "Resolver", basedirs: [__dirname], - extensions: [".mjs", ".js", ".json"], + extensions: [".mjs", ".js", ".cjs", ".json"], preserveSymlinks: true, packageFilter(pkg) { if (pkg.module) pkg.main = pkg.module;