Skip to content

Commit 4d08b84

Browse files
committed
Reduce npm package size by 75%
1 parent 8a4cdcf commit 4d08b84

11 files changed

+79
-46
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
!/.*
2+
/build/
23
/test-config/

.eslintrc.base.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const pkg = require("./package.json");
3+
const fs = require("fs");
44

55
module.exports = {
66
extends: [
@@ -12,8 +12,12 @@ module.exports = {
1212
],
1313
plugins: [
1414
"prettier",
15-
...pkg.files
16-
.filter((name) => !name.includes("/") && name !== "index.js")
15+
...fs
16+
.readdirSync(__dirname)
17+
.filter(
18+
(file) =>
19+
!file.startsWith(".") && file.endsWith(".js") && file !== "index.js"
20+
)
1721
.map((ruleFileName) => ruleFileName.replace(/\.js$/, "")),
1822
],
1923
parserOptions: {

.eslintrc.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"use strict";
22

3-
const pkg = require("./package.json");
3+
const fs = require("fs");
44

55
module.exports = {
66
extends: [
77
"./.eslintrc.base.js",
8-
...pkg.files
9-
.filter((name) => !name.includes("/"))
8+
...fs
9+
.readdirSync(__dirname)
10+
.filter((file) => !file.startsWith(".") && file.endsWith(".js"))
1011
.map((ruleFileName) => `./${ruleFileName}`),
1112
],
1213
rules: {

.github/workflows/check.yml

+3
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ jobs:
3838

3939
- name: Prettier
4040
run: npx --no-install prettier --check .
41+
42+
- name: Build
43+
run: npm run build

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/build/
12
/node_modules/
23
/test-config/

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/build/
12
/test-config/
23
.vscode

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This lets you use your favorite shareable config without letting its stylistic c
66

77
Note that this config _only_ turns rules _off,_ so it only makes sense using it together with some other config.
88

9-
## Contents
9+
---
1010

1111
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1212
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -786,7 +786,6 @@ console.log();
786786

787787
Finally, you need to mention the plugin in several places:
788788

789-
- Add `"foobar.js"` to the "files" field in `package.json`.
790789
- Add eslint-plugin-foobar to the "devDependencies" field in `package.json`.
791790
- Make sure that at least one rule from eslint-plugin-foobar gets used in `.eslintrc.base.js`.
792791
- Add it to the list of supported plugins and to the Contributing section in `README.md`.

package-real.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "eslint-config-prettier",
3+
"version": "6.15.0",
4+
"license": "MIT",
5+
"author": "Simon Lydell",
6+
"description": "Turns off all rules that are unnecessary or might conflict with Prettier.",
7+
"repository": "prettier/eslint-config-prettier",
8+
"bin": "bin/cli.js",
9+
"keywords": ["eslint", "eslintconfig", "prettier"],
10+
"peerDependencies": {
11+
"eslint": ">=7.0.0"
12+
}
13+
}

package.json

+3-29
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
{
2-
"name": "eslint-config-prettier",
3-
"version": "6.15.0",
4-
"license": "MIT",
5-
"author": "Simon Lydell",
6-
"description": "Turns off all rules that are unnecessary or might conflict with Prettier.",
7-
"repository": "prettier/eslint-config-prettier",
8-
"files": [
9-
"bin/",
10-
"@typescript-eslint.js",
11-
"babel.js",
12-
"flowtype.js",
13-
"index.js",
14-
"prettier.js",
15-
"react.js",
16-
"standard.js",
17-
"unicorn.js",
18-
"vue.js"
19-
],
20-
"bin": "bin/cli.js",
21-
"keywords": [
22-
"eslint",
23-
"eslintconfig",
24-
"prettier"
25-
],
2+
"private": true,
263
"scripts": {
274
"doctoc": "doctoc README.md && replace \"\\[\\[([\\w/-]+)\\](?:([^\\[\\]]+)\\[([\\w/-]+)\\])?\\]\" \"[\\$1\\$2\\$3]\" README.md",
285
"prettier": "prettier --write .",
@@ -33,9 +10,9 @@
3310
"test:jest": "jest",
3411
"test:cli-sanity": "node ./bin/cli.js index.js",
3512
"test:cli-sanity-warning": "node ./bin/cli.js react.js ./bin/cli.js",
36-
"test": "npm run test:lint && npm run test:jest && npm run test:cli-sanity && npm run test:cli-sanity-warning"
13+
"test": "npm run test:lint && npm run test:jest && npm run test:cli-sanity && npm run test:cli-sanity-warning && npm run build",
14+
"build": "node scripts/build.js"
3715
},
38-
"dependencies": {},
3916
"devDependencies": {
4017
"@typescript-eslint/eslint-plugin": "4.8.2",
4118
"@typescript-eslint/parser": "4.8.2",
@@ -56,8 +33,5 @@
5633
"replace": "1.2.0",
5734
"rimraf": "3.0.2",
5835
"typescript": "4.1.2"
59-
},
60-
"peerDependencies": {
61-
"eslint": ">=7.0.0"
6236
}
6337
}

scripts/build.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const DIR = path.join(__dirname, "..");
7+
const BUILD = path.join(DIR, "build");
8+
9+
const READ_MORE =
10+
"**[➡️ Full readme](https://github.com/prettier/eslint-config-prettier/)**";
11+
12+
const FILES_TO_COPY = [
13+
{ src: "LICENSE" },
14+
{ src: "package-real.json", dest: "package.json" },
15+
{
16+
src: "README.md",
17+
transform: (content) => content.replace(/^---[^]*/m, READ_MORE),
18+
},
19+
...fs
20+
.readdirSync(path.join(DIR, "bin"))
21+
.filter((file) => !file.startsWith(".") && file.endsWith(".js"))
22+
.map((file) => ({ src: path.join("bin", file) })),
23+
...fs
24+
.readdirSync(DIR)
25+
.filter((file) => !file.startsWith(".") && file.endsWith(".js"))
26+
.map((file) => ({ src: file })),
27+
];
28+
29+
if (fs.existsSync(BUILD)) {
30+
fs.rmdirSync(BUILD, { recursive: true });
31+
}
32+
33+
fs.mkdirSync(BUILD);
34+
35+
for (const { src, dest = src, transform } of FILES_TO_COPY) {
36+
if (transform) {
37+
fs.writeFileSync(
38+
path.join(BUILD, dest),
39+
transform(fs.readFileSync(path.join(DIR, src), "utf8"))
40+
);
41+
} else {
42+
fs.mkdirSync(path.dirname(path.join(BUILD, dest)), { recursive: true });
43+
fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest));
44+
}
45+
}

test/rules.test.js

-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const childProcess = require("child_process");
44
const fs = require("fs");
55
const path = require("path");
66
const rimraf = require("rimraf");
7-
const pkg = require("../package.json");
87
const eslintConfig = require("../.eslintrc");
98
const eslintConfigBase = require("../.eslintrc.base");
109

@@ -55,14 +54,6 @@ function createTestConfigDir() {
5554
});
5655
}
5756

58-
describe("all rule files are listed in package.json", () => {
59-
ruleFiles.forEach((ruleFileName) => {
60-
test(ruleFileName, () => {
61-
expect(pkg.files).toContain(ruleFileName);
62-
});
63-
});
64-
});
65-
6657
describe("all rule files have tests in test-lint/", () => {
6758
ruleFiles.forEach((ruleFileName) => {
6859
test(ruleFileName, () => {

0 commit comments

Comments
 (0)