]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
chore: refactor size check docs-sync-zh
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 3 Apr 2023 15:38:15 +0000 (17:38 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 3 Apr 2023 15:38:15 +0000 (17:38 +0200)
package.json
scripts/check-size.mjs [moved from scripts/check-size.js with 59% similarity]

index 6bfd7a32cb4a5863fb6022e82638965e3198f476..63056b7657470f01e202e9467a67e4b90e1da5e2 100644 (file)
@@ -10,7 +10,7 @@
   ],
   "scripts": {
     "release": "node scripts/release.mjs",
-    "size": "pnpm run -r size",
+    "size": "node scripts/check-size.mjs",
     "build": "pnpm run -r build",
     "build:dts": "pnpm run -r build:dts",
     "docs:api": "pnpm run --filter ./packages/docs -r docs:api",
similarity index 59%
rename from scripts/check-size.js
rename to scripts/check-size.mjs
index 2c95c4f60cc6355f4f2d3ca59033637c105615dc..59a5bbc8de252706f6c5f5c8a067851fd8d3678f 100644 (file)
@@ -1,8 +1,10 @@
-const fs = require('fs').promises
-const path = require('path')
-const chalk = require('chalk')
-const { gzipSync } = require('zlib')
-const { compress } = require('brotli')
+import fs from 'node:fs/promises'
+import path from 'node:path'
+import chalk from 'chalk'
+import { gzipSync } from 'zlib'
+import { compress } from 'brotli'
+
+const __dirname = path.dirname(new URL(import.meta.url).pathname)
 
 async function checkFileSize(filePath) {
   const stat = await fs.stat(filePath).catch(() => null)
@@ -27,14 +29,16 @@ async function checkFileSize(filePath) {
 }
 
 ;(async () => {
-  const files = [
-    path.resolve(__dirname, '../packages/router/size-checks/dist/webRouter.js'),
-    path.resolve(
-      __dirname,
-      '../packages/router/dist/vue-router.global.prod.js'
-    ),
-  ]
-  for (const file of files) {
-    await checkFileSize(file)
-  }
+  await Promise.all(
+    [
+      path.resolve(
+        __dirname,
+        '../packages/router/size-checks/dist/webRouter.js'
+      ),
+      path.resolve(
+        __dirname,
+        '../packages/router/dist/vue-router.global.prod.js'
+      ),
+    ].map(checkFileSize)
+  )
 })()