Skip to content

Commit

Permalink
fix: fix ESM error on CJS projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ASafaeirad committed Oct 19, 2024
1 parent db9c603 commit 86b9dd7
Show file tree
Hide file tree
Showing 25 changed files with 44 additions and 42 deletions.
3 changes: 3 additions & 0 deletions build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
entries: [{ input: './src', outDir: './cjs', format: 'cjs', builder: 'mkdist', declaration: false }],
rollup: {
cjsBridge: true,
},
});
2 changes: 1 addition & 1 deletion eslint.config.js → eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { init } from './src/index.js';
import { init } from './src/index.mjs';

export default init(
{
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
"pre-commit": "npm run test && lint-staged"
},
"main": "./cjs/index.js",
"module": "./src/index.js",
"module": "./src/index.mjs",
"exports": {
".": {
"import": "./src/index.js",
"import": "./src/index.mjs",
"require": "./cjs/index.js"
}
},
"type": "module",
"dependencies": {
"@eslint-react/eslint-plugin": "1.15.0",
"@next/eslint-plugin-next": "14.2.15",
Expand Down
36 changes: 18 additions & 18 deletions src/index.js → src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import merge from 'deepmerge';
import { isPackageExists } from 'local-pkg';

import base from './modules/base.js';
import cypress from './modules/cypress.js';
import fp from './modules/functional.js';
import ignores from './modules/ignore.js';
import imports from './modules/imports.js';
import jest from './modules/jest.js';
import next from './modules/next.js';
import node from './modules/node.js';
import perfectionist from './modules/perfectionist.js';
import playwright from './modules/playwright.js';
import prettier from './modules/prettier.js';
import react from './modules/react.js';
import storybook from './modules/storybook.js';
import tailwind from './modules/tailwind.js';
import tests from './modules/tests.js';
import typescript from './modules/typescript.js';
import vitest from './modules/vitest.js';
import base from './modules/base.mjs';
import cypress from './modules/cypress.mjs';
import fp from './modules/functional.mjs';
import ignores from './modules/ignore.mjs';
import imports from './modules/imports.mjs';
import jest from './modules/jest.mjs';
import next from './modules/next.mjs';
import node from './modules/node.mjs';
import perfectionist from './modules/perfectionist.mjs';
import playwright from './modules/playwright.mjs';
import prettier from './modules/prettier.mjs';
import react from './modules/react.mjs';
import storybook from './modules/storybook.mjs';
import tailwind from './modules/tailwind.mjs';
import tests from './modules/tests.mjs';
import typescript from './modules/typescript.mjs';
import vitest from './modules/vitest.mjs';

const testPackages = ['jest', 'vitest', 'cypress', 'playwright'];

/**
* @typedef {import('eslint').Linter.Config} Config
* @typedef {import('./option.d.ts').Options} Options
* @typedef {import('./option').Options} Options
* /
/** @type {Options} */
Expand Down
4 changes: 2 additions & 2 deletions src/modules/base.js → src/modules/base.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import globals from 'globals';

import { strict } from '../utils/conditions.js';
import { strict } from '../utils/conditions.mjs';

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
*/
function base(options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cypress.js → src/modules/cypress.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plugin from 'eslint-plugin-cypress/flat';

import { globs } from '../utils/globs.js';
import { globs } from '../utils/globs.mjs';

/** @return { import('eslint').Linter.Config } */
function cypress() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/ignore.js → src/modules/ignore.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ignoreGlobs } from '../utils/globs.js';
import { ignoreGlobs } from '../utils/globs.mjs';
/**
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
Expand Down
4 changes: 2 additions & 2 deletions src/modules/imports.js → src/modules/imports.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import plugin from 'eslint-plugin-import-x';

import { predicate } from '../utils/conditions.js';
import { predicate } from '../utils/conditions.mjs';

const tsExtensions = ['.ts', '.tsx', '.cts', '.mts', '.ctsx', '.mtsx'];
const jsExtensions = ['.mjs', '.js', '.jsx', '.cjs'];
const allExtensions = [...jsExtensions, ...tsExtensions];

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
*/
function imports(options = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/jest.js → src/modules/jest.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import plugin from 'eslint-plugin-jest';

import { globs } from '../utils/globs.js';
import { globs } from '../utils/globs.mjs';

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config } */
function jest() {
return {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/modules/node.js → src/modules/node.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import plugin from 'eslint-plugin-n';

import { strict } from '../utils/conditions.js';
import { strict } from '../utils/conditions.mjs';

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
*/
function node(options = {}) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/playwright.js → src/modules/playwright.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plugin from 'eslint-plugin-playwright';

import { globs } from '../utils/globs.js';
import { globs } from '../utils/globs.mjs';

/** @return { import('eslint').Linter.Config } */
function playwright() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/storybook.js → src/modules/storybook.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plugin from 'eslint-plugin-storybook';

import { globs } from '../utils/globs.js';
import { globs } from '../utils/globs.mjs';

/** @return { import('eslint').Linter.Config } */
function storybook() {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/modules/tests.js → src/modules/tests.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import plugin from 'eslint-plugin-jest-formatting';
import globals from 'globals';

import { predicate } from '../utils/conditions.js';
import { globs } from '../utils/globs.js';
import { predicate } from '../utils/conditions.mjs';
import { globs } from '../utils/globs.mjs';

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
*/
function tests(options = {}) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/typescript.js → src/modules/typescript.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { parser, plugin } from 'typescript-eslint';

import { predicate } from '../utils/conditions.js';
import { globs } from '../utils/globs.js';
import { namingConvention } from '../utils/naming-convention.js';
import { predicate } from '../utils/conditions.mjs';
import { globs } from '../utils/globs.mjs';
import { namingConvention } from '../utils/naming-convention.mjs';

/**
* @param { import('../option.d.ts').Options } options
* @param { import('../option').Options } options
* @return { import('eslint').Linter.Config }
*/
function typescript(options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/vitest.js → src/modules/vitest.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plugin from 'eslint-plugin-vitest';

import { globs } from '../utils/globs.js';
import { globs } from '../utils/globs.mjs';

/**
* @return { import('eslint').Linter.Config }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 86b9dd7

Please sign in to comment.