Commit c1a160c

Anton Golub <antongolub@antongolub.com>
2024-06-20 22:26:35
test: add bundles size check (#857)
1 parent e45ae8d
scripts/build-dts.mjs
@@ -99,11 +99,7 @@ for (const i in results) {
 }
 
 // Replaces redundant triple-slash directives
-for (const dts of await glob([
-  'build/**/*.d.ts',
-  '!build/vendor.d.ts',
-  '!build/core-vendor.d.ts',
-])) {
+for (const dts of await glob(['build/**/*.d.ts', '!build/vendor-*.d.ts'])) {
   const contents = (await fs.readFile(dts, 'utf8'))
     .split('\n')
     .filter((line) => !line.startsWith('/// <reference types'))
.size-limit.json
@@ -0,0 +1,37 @@
+[
+  {
+    "name": "zx/core",
+    "path": ["build/core.cjs", "build/util.cjs", "build/vendor-core.cjs"],
+    "limit": "70 kB",
+    "brotli": false,
+    "gzip": false
+  },
+  {
+    "name": "zx/index",
+    "path": "build/*.{js,cjs}",
+    "limit": "842 kB",
+    "brotli": false,
+    "gzip": false
+  },
+  {
+    "name": "dts libdefs",
+    "path": "build/*.d.ts",
+    "limit": "31 kB",
+    "brotli": false,
+    "gzip": false
+  },
+  {
+    "name": "vendor",
+    "path": "build/vendor-*",
+    "limit": "803 kB",
+    "brotli": false,
+    "gzip": false
+  },
+  {
+    "name": "all",
+    "path": "build/*",
+    "limit": "875 kB",
+    "brotli": false,
+    "gzip": false
+  }
+]
package-lock.json
@@ -1,17 +1,18 @@
 {
   "name": "zx",
-  "version": "8.1.2",
+  "version": "8.1.3",
   "lockfileVersion": 3,
   "requires": true,
   "packages": {
     "": {
       "name": "zx",
-      "version": "8.1.2",
+      "version": "8.1.3",
       "license": "Apache-2.0",
       "bin": {
         "zx": "build/cli.js"
       },
       "devDependencies": {
+        "@size-limit/file": "^11.1.4",
         "@types/fs-extra": "^11.0.4",
         "@types/minimist": "^1.2.5",
         "@types/node": ">=20.11.30",
@@ -37,6 +38,7 @@
         "minimist": "^1.2.8",
         "node-fetch-native": "^1.6.4",
         "prettier": "^3.3.2",
+        "size-limit": "^11.1.4",
         "ts-node": "^10.9.2",
         "tsd": "^0.31.1",
         "tsx": "^4.15.6",
@@ -691,6 +693,19 @@
         "url": "https://github.com/sponsors/sindresorhus"
       }
     },
+    "node_modules/@size-limit/file": {
+      "version": "11.1.4",
+      "resolved": "https://registry.npmjs.org/@size-limit/file/-/file-11.1.4.tgz",
+      "integrity": "sha512-QxnGj9cxhCEuqMAV01gqonXIKcc+caZqFHZpV51oL2ZJNGSPP9Q/yyf+7HbVe00faOFd1dZZwMwzZmX7HQ9LbA==",
+      "dev": true,
+      "license": "MIT",
+      "engines": {
+        "node": "^18.0.0 || >=20.0.0"
+      },
+      "peerDependencies": {
+        "size-limit": "11.1.4"
+      }
+    },
     "node_modules/@tsconfig/node10": {
       "version": "1.0.11",
       "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz",
@@ -994,6 +1009,20 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/anymatch": {
+      "version": "3.1.3",
+      "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
+      "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
+      "dev": true,
+      "license": "ISC",
+      "dependencies": {
+        "normalize-path": "^3.0.0",
+        "picomatch": "^2.0.4"
+      },
+      "engines": {
+        "node": ">= 8"
+      }
+    },
     "node_modules/app-module-path": {
       "version": "2.2.0",
       "resolved": "https://registry.npmjs.org/app-module-path/-/app-module-path-2.2.0.tgz",
@@ -1066,6 +1095,19 @@
       ],
       "license": "MIT"
     },
+    "node_modules/binary-extensions": {
+      "version": "2.3.0",
+      "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
+      "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==",
+      "dev": true,
+      "license": "MIT",
+      "engines": {
+        "node": ">=8"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/sindresorhus"
+      }
+    },
     "node_modules/bl": {
       "version": "4.1.0",
       "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
@@ -1127,6 +1169,16 @@
         "ieee754": "^1.1.13"
       }
     },
+    "node_modules/bytes-iec": {
+      "version": "3.1.1",
+      "resolved": "https://registry.npmjs.org/bytes-iec/-/bytes-iec-3.1.1.tgz",
+      "integrity": "sha512-fey6+4jDK7TFtFg/klGSvNKJctyU7n2aQdnM+CO0ruLPbqqMOM8Tio0Pc+deqUeVKX1tL5DQep1zQ7+37aTAsA==",
+      "dev": true,
+      "license": "MIT",
+      "engines": {
+        "node": ">= 0.8"
+      }
+    },
     "node_modules/c8": {
       "version": "9.1.0",
       "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz",
@@ -1194,6 +1246,31 @@
         "url": "https://github.com/chalk/chalk?sponsor=1"
       }
     },
+    "node_modules/chokidar": {
+      "version": "3.6.0",
+      "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
+      "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "anymatch": "~3.1.2",
+        "braces": "~3.0.2",
+        "glob-parent": "~5.1.2",
+        "is-binary-path": "~2.1.0",
+        "is-glob": "~4.0.1",
+        "normalize-path": "~3.0.0",
+        "readdirp": "~3.6.0"
+      },
+      "engines": {
+        "node": ">= 8.10.0"
+      },
+      "funding": {
+        "url": "https://paulmillr.com/funding/"
+      },
+      "optionalDependencies": {
+        "fsevents": "~2.3.2"
+      }
+    },
     "node_modules/cli-cursor": {
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@@ -2377,6 +2454,19 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/is-binary-path": {
+      "version": "2.1.0",
+      "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
+      "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "binary-extensions": "^2.0.0"
+      },
+      "engines": {
+        "node": ">=8"
+      }
+    },
     "node_modules/is-core-module": {
       "version": "2.13.1",
       "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz",
@@ -2634,6 +2724,16 @@
         "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
       }
     },
+    "node_modules/jiti": {
+      "version": "1.21.6",
+      "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.6.tgz",
+      "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==",
+      "dev": true,
+      "license": "MIT",
+      "bin": {
+        "jiti": "bin/jiti.js"
+      }
+    },
     "node_modules/js-tokens": {
       "version": "4.0.0",
       "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -2684,6 +2784,19 @@
         "node": ">=0.10.0"
       }
     },
+    "node_modules/lilconfig": {
+      "version": "3.1.2",
+      "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.2.tgz",
+      "integrity": "sha512-eop+wDAvpItUys0FWkHIKeC9ybYrTGbU41U5K7+bttZZeohvnY7M9dZ5kB21GNWiFT2q1OoPTvncPCgSOVO5ow==",
+      "dev": true,
+      "license": "MIT",
+      "engines": {
+        "node": ">=14"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/antonk52"
+      }
+    },
     "node_modules/lines-and-columns": {
       "version": "1.2.4",
       "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@@ -3109,6 +3222,16 @@
         "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
       }
     },
+    "node_modules/nanospinner": {
+      "version": "1.1.0",
+      "resolved": "https://registry.npmjs.org/nanospinner/-/nanospinner-1.1.0.tgz",
+      "integrity": "sha512-yFvNYMig4AthKYfHFl1sLj7B2nkHL4lzdig4osvl9/LdGbXwrdFRoqBS98gsEsOakr0yH+r5NZ/1Y9gdVB8trA==",
+      "dev": true,
+      "license": "ISC",
+      "dependencies": {
+        "picocolors": "^1.0.0"
+      }
+    },
     "node_modules/node-fetch-native": {
       "version": "1.6.4",
       "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.4.tgz",
@@ -3145,6 +3268,16 @@
         "node": ">=10"
       }
     },
+    "node_modules/normalize-path": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
+      "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
+      "dev": true,
+      "license": "MIT",
+      "engines": {
+        "node": ">=0.10.0"
+      }
+    },
     "node_modules/once": {
       "version": "1.4.0",
       "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@@ -3755,6 +3888,19 @@
         "node": ">= 6"
       }
     },
+    "node_modules/readdirp": {
+      "version": "3.6.0",
+      "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
+      "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "picomatch": "^2.2.1"
+      },
+      "engines": {
+        "node": ">=8.10.0"
+      }
+    },
     "node_modules/redent": {
       "version": "3.0.0",
       "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
@@ -3997,6 +4143,28 @@
         "url": "https://github.com/sponsors/isaacs"
       }
     },
+    "node_modules/size-limit": {
+      "version": "11.1.4",
+      "resolved": "https://registry.npmjs.org/size-limit/-/size-limit-11.1.4.tgz",
+      "integrity": "sha512-V2JAI/Z7h8sEuxU3V+Ig3XKA5FcYbI4CZ7sh6s7wvuy+TUwDZYqw7sAqrHhQ4cgcNfPKIAHAaH8VaqOdbcwJDA==",
+      "dev": true,
+      "license": "MIT",
+      "dependencies": {
+        "bytes-iec": "^3.1.1",
+        "chokidar": "^3.6.0",
+        "globby": "^14.0.1",
+        "jiti": "^1.21.0",
+        "lilconfig": "^3.1.1",
+        "nanospinner": "^1.1.0",
+        "picocolors": "^1.0.1"
+      },
+      "bin": {
+        "size-limit": "bin.js"
+      },
+      "engines": {
+        "node": "^18.0.0 || >=20.0.0"
+      }
+    },
     "node_modules/slash": {
       "version": "5.1.0",
       "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz",
package.json
@@ -68,11 +68,12 @@
     "build:vendor": "node scripts/build-js.mjs --format=cjs --entry=src/vendor-*.ts --bundle=all",
     "build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
     "pretest": "npm run build",
-    "test": "npm run test:unit && npm run test:types && npm run test:license",
+    "test": "npm run test:size && npm run test:unit && npm run test:types && npm run test:license",
     "test:unit": "node ./test/all.test.js",
     "test:circular": "madge --circular src/*",
     "test:types": "tsd",
     "test:license": "node ./test/extra.test.js",
+    "test:size": "size-limit",
     "test:smoke:tsx": "tsx test/smoke/ts.test.ts",
     "test:smoke:tsc": "cd test/smoke && mkdir -p node_modules && ln -s ../../../  ./node_modules/zx; tsc --esModuleInterop --module node16 --rootDir . --outdir ./temp ts.test.ts && node ./temp/ts.test.js",
     "test:smoke:ts-node": "node --loader ts-node/esm test/smoke/ts.test.ts",
@@ -89,6 +90,7 @@
     "@types/node": ">=20"
   },
   "devDependencies": {
+    "@size-limit/file": "^11.1.4",
     "@types/fs-extra": "^11.0.4",
     "@types/minimist": "^1.2.5",
     "@types/node": ">=20.11.30",
@@ -114,6 +116,7 @@
     "minimist": "^1.2.8",
     "node-fetch-native": "^1.6.4",
     "prettier": "^3.3.2",
+    "size-limit": "^11.1.4",
     "ts-node": "^10.9.2",
     "tsd": "^0.31.1",
     "tsx": "^4.15.6",