Skip to content

Commit

Permalink
feat: respect for .cjs files and move towards exports fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed Jan 16, 2022
1 parent 66bddfc commit cc391bb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const extensions = [".mjs", ".js", ".json"];
const extensions = [".mjs", ".js", ".cjs", ".json"];
module.exports = {
root: true,
extends: [
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
},
"license": "MIT",
"author": "Anton Kudryavtsev <boblobl4@gmail.com>",
"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"
],
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion src/utils/load-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const loaded: Record<string, unknown> = {};
const options: ResolveOpts = {
caller: "Module loader",
basedirs: [process.cwd()],
extensions: [".js", ".mjs", ".json"],
extensions: [".cjs", ".js", ".mjs", ".json"],
preserveSymlinks: false,
packageFilter: pkg => pkg,
};
Expand Down
4 changes: 2 additions & 2 deletions src/utils/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
/** don't resolve `basedirs` to real path before resolving. (defaults to `true`) */
preserveSymlinks?: boolean;
Expand All @@ -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;
Expand Down

0 comments on commit cc391bb

Please sign in to comment.