diff --git a/.changeset/modern-pumpkins-explain.md b/.changeset/modern-pumpkins-explain.md new file mode 100644 index 0000000..ed46191 --- /dev/null +++ b/.changeset/modern-pumpkins-explain.md @@ -0,0 +1,5 @@ +--- +"eslint-config-prettier": minor +--- + +feat: migrate to exports field diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7a52360..90f1b9b 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -40,6 +40,3 @@ jobs: - name: Prettier run: yarn prettier --check . - - - name: Build - run: yarn build diff --git a/package.json b/package.json index c1f4f56..fbab760 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,26 @@ ], "license": "MIT", "packageManager": "yarn@4.7.0", - "bin": "build/bin/cli.js", - "main": "build/index.js", - "types": "build/index.d.ts", + "bin": "bin/cli.js", + "main": "index.js", + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "./prettier": { + "types": "./prettier.d.ts", + "default": "./prettier.js" + }, + "./package.json": "./package.json" + }, + "types": "index.d.ts", "files": [ - "build" + "bin", + "index.d.ts", + "index.js", + "prettier.d.ts", + "prettier.js" ], "keywords": [ "eslint", @@ -24,9 +39,8 @@ "prettier" ], "scripts": { - "build": "node scripts/build.js", "prettier": "prettier --write .", - "release": "yarn build && clean-pkg-json && changeset publish", + "release": "clean-pkg-json && changeset publish", "test": "yarn test:prettier && ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true yarn test:with-env && ESLINT_USE_FLAT_CONFIG=false yarn test:with-env && yarn build", "test:cli-sanity": "node ./bin/cli.js index.js", "test:cli-sanity-warning": "node ./bin/cli.js react.js ./bin/cli.js", diff --git a/prettier.d.ts b/prettier.d.ts new file mode 100644 index 0000000..19b02c2 --- /dev/null +++ b/prettier.d.ts @@ -0,0 +1 @@ +export const rules: Record; diff --git a/prettier.js b/prettier.js index aac873c..b9ec0f7 100644 --- a/prettier.js +++ b/prettier.js @@ -1,12 +1,10 @@ "use strict"; -module.exports = { - rules: { - // These are safe to use as long as the `"prettier/prettier"` rule from - // eslint-plugin-prettier isn’t enabled. - // These are also included in `"plugin:prettier/recommended"`: - // https://github.com/prettier/eslint-plugin-prettier#recommended-configuration - "arrow-body-style": 0, - "prefer-arrow-callback": 0, - }, +exports.rules = { + // These are safe to use as long as the `"prettier/prettier"` rule from + // eslint-plugin-prettier isn’t enabled. + // These are also included in `"plugin:prettier/recommended"`: + // https://github.com/prettier/eslint-plugin-prettier#recommended-configuration + "arrow-body-style": 0, + "prefer-arrow-callback": 0, }; diff --git a/scripts/build.js b/scripts/build.js deleted file mode 100644 index bfeab0d..0000000 --- a/scripts/build.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; - -const fs = require("fs"); -const path = require("path"); - -const DIR = path.join(__dirname, ".."); -const BUILD = path.join(DIR, "build"); - -const FILES_TO_COPY = [ - { src: "index.js" }, - { src: "index.d.ts" }, - { src: "prettier.js" }, - ...fs - .readdirSync(path.join(DIR, "bin")) - .filter((file) => !file.startsWith(".") && file.endsWith(".js")) - .map((file) => ({ src: path.join("bin", file) })), -]; - -fs.rmSync(BUILD, { recursive: true, force: true }); -fs.mkdirSync(BUILD); - -for (const { src, dest = src, transform } of FILES_TO_COPY) { - if (transform) { - fs.writeFileSync( - path.join(BUILD, dest), - transform(fs.readFileSync(path.join(DIR, src), "utf8")) - ); - } else { - fs.mkdirSync(path.dirname(path.join(BUILD, dest)), { recursive: true }); - fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest)); - } -} - -const LEGACY_CONFIGS = [ - "@typescript-eslint", - "babel", - "flowtype", - "react", - "standard", - "unicorn", - "vue", -]; - -function legacyConfigStub(name) { - return ` -throw new Error( - '"prettier/${name}" has been merged into "prettier" in eslint-config-prettier 8.0.0. See: https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21' -); - `.trim(); -} - -for (const name of LEGACY_CONFIGS) { - fs.writeFileSync(path.join(BUILD, `${name}.js`), legacyConfigStub(name)); -} diff --git a/yarn.lock b/yarn.lock index 7c3b713..c65a15c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2703,7 +2703,7 @@ __metadata: peerDependencies: eslint: ">=7.0.0" bin: - eslint-config-prettier: build/bin/cli.js + eslint-config-prettier: bin/cli.js languageName: unknown linkType: soft