From 87b48947f3542f3c964b408ee8b2b37f209d8196 Mon Sep 17 00:00:00 2001 From: Dale Nguyen Date: Fri, 14 Feb 2025 23:05:07 -0500 Subject: [PATCH] chore: update build process --- .gitignore | 1 + CHANGELOG.md | 9 ++++++ package.json | 19 ++++++------ pnpm-lock.yaml | 70 +++++++++++++++++++++++++++++++++--------- src/export.ts | 6 ++-- test/firestore.spec.ts | 2 +- tsconfig.json | 14 ++++----- vite.config.js | 53 ++++++++++++++++++++++++++++++++ 8 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 vite.config.js diff --git a/.gitignore b/.gitignore index 0db1d46..26b8933 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,4 @@ test/serviceAccountKey.json .idea .DS_Store dist +qa \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cca90b..5802f82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,15 @@ > - :nail_care: [Polish] --- +## [1.6.0] - 2025-02-14 + +#### - :nail_care: [Polish] + +- Migrated build system to Vite +- Added dual ESM/CJS module support +- Improved minification using esbuild +- Removed manual minification process + ## [1.5.0] - 2025-01-01 #### - :nail_care: [Polish] diff --git a/package.json b/package.json index 5e5ee6e..69096c6 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,20 @@ { "name": "firestore-export-import", - "version": "1.5.0", + "version": "1.6.0", "description": "NPM package for backup and restore Firebase Firestore", "type": "module", - "main": "./dist/index.js", - "types": "dist/index.d.ts", + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "files": [ "readme.md", - "dist/*.*.*", - "dist/*.*" + "dist/**/*" ], "scripts": { - "build": "tsc --skipLibCheck --noCheck && pnpm run minify", - "build:vite": "vite build", + "build": "vite build", "test": "vitest", "coverage": "vitest run --coverage", - "typecheck": "tsc --noEmit", - "minify": "jsmin -o dist/index.js dist/index.js && jsmin -o dist/import.js dist/import.js && jsmin -o dist/export.js dist/export.js && jsmin -o dist/helper.js dist/helper.js" + "typecheck": "tsc --noEmit" }, "devDependencies": { "@types/node": "^20.11.5", @@ -26,7 +24,8 @@ "typescript": "^5.3.3", "vite": "^5.0.12", "vite-plugin-dts": "^3.7.1", - "vitest": "^1.2.1" + "vitest": "^1.2.1", + "terser": "^5.27.2" }, "dependencies": { "firebase-admin": "^13.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1bc97c4..f5cb2f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,25 +23,28 @@ importers: version: 20.17.10 '@vitest/coverage-v8': specifier: ^1.2.1 - version: 1.6.0(vitest@1.6.0(@types/node@20.17.10)) + version: 1.6.0(vitest@1.6.0(@types/node@20.17.10)(terser@5.39.0)) jsmin: specifier: ^1.0.1 version: 1.0.1 request-promise: specifier: ^4.2.6 version: 4.2.6(request@2.88.2) + terser: + specifier: ^5.39.0 + version: 5.39.0 typescript: specifier: ^5.3.3 version: 5.7.2 vite: specifier: ^5.0.12 - version: 5.4.11(@types/node@20.17.10) + version: 5.4.11(@types/node@20.17.10)(terser@5.39.0) vite-plugin-dts: specifier: ^3.7.1 - version: 3.9.1(@types/node@20.17.10)(rollup@4.29.1)(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.10)) + version: 3.9.1(@types/node@20.17.10)(rollup@4.29.1)(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.10)(terser@5.39.0)) vitest: specifier: ^1.2.1 - version: 1.6.0(@types/node@20.17.10) + version: 1.6.0(@types/node@20.17.10)(terser@5.39.0) packages: @@ -291,6 +294,9 @@ packages: resolution: {integrity: sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==} engines: {node: '>=6.0.0'} + '@jridgewell/source-map@0.3.6': + resolution: {integrity: sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==} + '@jridgewell/sourcemap-codec@1.5.0': resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} @@ -672,6 +678,9 @@ packages: buffer-equal-constant-time@1.0.1: resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==} + buffer-from@1.1.2: + resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + cac@6.7.14: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} @@ -701,6 +710,9 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + commander@2.20.3: + resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} + commander@9.5.0: resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==} engines: {node: ^12.20.0 || >=14} @@ -1349,6 +1361,9 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} + source-map-support@0.5.21: + resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} + source-map@0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} @@ -1425,6 +1440,11 @@ packages: resolution: {integrity: sha512-resvxdc6Mgb7YEThw6G6bExlXKkv6+YbuzGg9xuXxSgxJF7Ozs+o8Y9+2R3sArdWdW8nOokoQb1yrpFB0pQK2g==} engines: {node: '>=14'} + terser@5.39.0: + resolution: {integrity: sha512-LBAhFyLho16harJoWMg/nZsQYgTrg5jXOn2nCYjRUcZZEdE3qa2zb8QEDRUGVZBW4rlazf2fxkg8tztybTaqWw==} + engines: {node: '>=10'} + hasBin: true + test-exclude@6.0.0: resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} engines: {node: '>=8'} @@ -1863,6 +1883,11 @@ snapshots: '@jridgewell/set-array@1.2.1': {} + '@jridgewell/source-map@0.3.6': + dependencies: + '@jridgewell/gen-mapping': 0.3.8 + '@jridgewell/trace-mapping': 0.3.25 + '@jridgewell/sourcemap-codec@1.5.0': {} '@jridgewell/trace-mapping@0.3.25': @@ -2105,7 +2130,7 @@ snapshots: '@types/tough-cookie@4.0.5': {} - '@vitest/coverage-v8@1.6.0(vitest@1.6.0(@types/node@20.17.10))': + '@vitest/coverage-v8@1.6.0(vitest@1.6.0(@types/node@20.17.10)(terser@5.39.0))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 @@ -2120,7 +2145,7 @@ snapshots: std-env: 3.8.0 strip-literal: 2.1.1 test-exclude: 6.0.0 - vitest: 1.6.0(@types/node@20.17.10) + vitest: 1.6.0(@types/node@20.17.10)(terser@5.39.0) transitivePeerDependencies: - supports-color @@ -2277,6 +2302,8 @@ snapshots: buffer-equal-constant-time@1.0.1: {} + buffer-from@1.1.2: {} + cac@6.7.14: {} caseless@0.12.0: {} @@ -2311,6 +2338,8 @@ snapshots: dependencies: delayed-stream: 1.0.0 + commander@2.20.3: {} + commander@9.5.0: optional: true @@ -3052,6 +3081,11 @@ snapshots: source-map-js@1.2.1: {} + source-map-support@0.5.21: + dependencies: + buffer-from: 1.1.2 + source-map: 0.6.1 + source-map@0.6.1: {} sprintf-js@1.0.3: {} @@ -3130,6 +3164,13 @@ snapshots: - encoding - supports-color + terser@5.39.0: + dependencies: + '@jridgewell/source-map': 0.3.6 + acorn: 8.14.0 + commander: 2.20.3 + source-map-support: 0.5.21 + test-exclude@6.0.0: dependencies: '@istanbuljs/schema': 0.1.3 @@ -3194,13 +3235,13 @@ snapshots: core-util-is: 1.0.2 extsprintf: 1.3.0 - vite-node@1.6.0(@types/node@20.17.10): + vite-node@1.6.0(@types/node@20.17.10)(terser@5.39.0): dependencies: cac: 6.7.14 debug: 4.4.0 pathe: 1.1.2 picocolors: 1.1.1 - vite: 5.4.11(@types/node@20.17.10) + vite: 5.4.11(@types/node@20.17.10)(terser@5.39.0) transitivePeerDependencies: - '@types/node' - less @@ -3212,7 +3253,7 @@ snapshots: - supports-color - terser - vite-plugin-dts@3.9.1(@types/node@20.17.10)(rollup@4.29.1)(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.10)): + vite-plugin-dts@3.9.1(@types/node@20.17.10)(rollup@4.29.1)(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.10)(terser@5.39.0)): dependencies: '@microsoft/api-extractor': 7.43.0(@types/node@20.17.10) '@rollup/pluginutils': 5.1.4(rollup@4.29.1) @@ -3223,13 +3264,13 @@ snapshots: typescript: 5.7.2 vue-tsc: 1.8.27(typescript@5.7.2) optionalDependencies: - vite: 5.4.11(@types/node@20.17.10) + vite: 5.4.11(@types/node@20.17.10)(terser@5.39.0) transitivePeerDependencies: - '@types/node' - rollup - supports-color - vite@5.4.11(@types/node@20.17.10): + vite@5.4.11(@types/node@20.17.10)(terser@5.39.0): dependencies: esbuild: 0.21.5 postcss: 8.4.49 @@ -3237,8 +3278,9 @@ snapshots: optionalDependencies: '@types/node': 20.17.10 fsevents: 2.3.3 + terser: 5.39.0 - vitest@1.6.0(@types/node@20.17.10): + vitest@1.6.0(@types/node@20.17.10)(terser@5.39.0): dependencies: '@vitest/expect': 1.6.0 '@vitest/runner': 1.6.0 @@ -3257,8 +3299,8 @@ snapshots: strip-literal: 2.1.1 tinybench: 2.9.0 tinypool: 0.8.4 - vite: 5.4.11(@types/node@20.17.10) - vite-node: 1.6.0(@types/node@20.17.10) + vite: 5.4.11(@types/node@20.17.10)(terser@5.39.0) + vite-node: 1.6.0(@types/node@20.17.10)(terser@5.39.0) why-is-node-running: 2.3.0 optionalDependencies: '@types/node': 20.17.10 diff --git a/src/export.ts b/src/export.ts index cf5685b..6c00339 100644 --- a/src/export.ts +++ b/src/export.ts @@ -101,7 +101,7 @@ export const backupFromDocService = async ( return data as T } catch (error) { console.error(error) - throw new Error(error) + throw new Error((error as Error).message) } } @@ -189,7 +189,7 @@ export const backupService = async ( ? await options.queryCollection(collectionRef) : await collectionRef.get() const docs = - options?.docsFromEachCollection > 0 + (options?.docsFromEachCollection ?? 0) > 0 ? documents.docs.slice(0, options?.docsFromEachCollection) : documents.docs @@ -209,6 +209,6 @@ export const backupService = async ( return data as T } catch (error) { console.error(error) - throw new Error(error) + throw new Error((error as Error).message) } } diff --git a/test/firestore.spec.ts b/test/firestore.spec.ts index 73ce59b..26fdb3d 100644 --- a/test/firestore.spec.ts +++ b/test/firestore.spec.ts @@ -1,4 +1,4 @@ -// import { describe, it, expect } from 'vitest' +import { describe, it, expect } from 'vitest' import { Firestore } from 'firebase-admin/firestore' import request from 'request-promise' import { diff --git a/tsconfig.json b/tsconfig.json index c25437c..a6127cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,17 +2,15 @@ "compilerOptions": { "target": "ES2022", "module": "ESNext", - "moduleResolution": "Node", - "esModuleInterop": true, + "moduleResolution": "node", "outDir": "./dist", - "rootDir": "./src", + "declaration": true, "strict": true, + "esModuleInterop": true, "skipLibCheck": true, - "declaration": true, - "sourceMap": true, - "types": ["node", "vitest/globals"], - "lib": ["ES2022"] + "forceConsistentCasingInFileNames": true, + "noImplicitAny": false, }, "include": ["src/**/*"], - "exclude": ["node_modules", "dist", "**/*.spec.ts"] + "exclude": ["node_modules", "dist"] } \ No newline at end of file diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..f5beaa1 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,53 @@ +import { defineConfig } from 'vite'; +import dts from 'vite-plugin-dts'; +import { resolve } from 'path'; + +export default defineConfig({ + build: { + lib: { + entry: { + index: resolve(__dirname, 'src/index.ts'), + import: resolve(__dirname, 'src/import.ts'), + export: resolve(__dirname, 'src/export.ts'), + helper: resolve(__dirname, 'src/helper.ts') + }, + formats: ['es', 'cjs'] + }, + minify: 'esbuild', + rollupOptions: { + external: [ + 'firebase-admin', + 'google-gax', + 'uuid', + 'events', + 'fs', + 'path', + /^firebase-admin\/.*/, + /^google-gax\/.*/, + /^node:.*/ + ], + output: [ + { + format: 'es', + entryFileNames: '[name].js', + preserveModules: true, + exports: 'named', + interop: 'auto' + }, + { + format: 'cjs', + entryFileNames: '[name].cjs', + exports: 'named', + interop: 'auto' + } + ] + } + }, + plugins: [ + dts({ + include: ['src/**/*'], + exclude: ['**/*.spec.ts'], + outputDir: 'dist' + }) + ] +}); \ No newline at end of file