diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 22df99b..014486d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,13 +2,12 @@ name: Node.js CI on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: build: - runs-on: ubuntu-latest strategy: @@ -46,4 +45,4 @@ jobs: run: node dist/prefab.cjs - name: Validate esm version - run: node dist/prefab.mjs + run: PREFAB_SKIP_PEER_DEPENDENCY_CHECK=true node dist/prefab.mjs diff --git a/src/loadConfig.ts b/src/loadConfig.ts index 0deebaf..5adcbf4 100644 --- a/src/loadConfig.ts +++ b/src/loadConfig.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import Long from "long"; +import type Long from "long"; import type { Config, Configs } from "./proto"; import { maxLong } from "./maxLong"; import { type ApiClient, fetchWithCache } from "./apiClient"; @@ -112,20 +112,6 @@ const parse = (parsed: Configs): Result => { const configs = parsed.configs ?? []; - // Check if configs has at least one item and verify if its id is a Long - if (configs.length > 0) { - const firstConfig = configs[0]; - if ( - firstConfig !== undefined && - firstConfig !== null && - !Long.isLong(firstConfig.id) - ) { - throw new Error( - 'Prefab requires the "long" package to be in your project. See https://www.npmjs.com/package/long' - ); - } - } - const defaultContext = extractDefaultContext(parsed.defaultContext); return { diff --git a/src/prefab.ts b/src/prefab.ts index a36c1e7..6b80d71 100644 --- a/src/prefab.ts +++ b/src/prefab.ts @@ -1,3 +1,4 @@ +import './verifyPeerDependencies'; import crypto from "crypto"; import Long from "long"; import { apiClient, type ApiClient } from "./apiClient"; diff --git a/src/verifyPeerDependencies.ts b/src/verifyPeerDependencies.ts new file mode 100644 index 0000000..a83ec17 --- /dev/null +++ b/src/verifyPeerDependencies.ts @@ -0,0 +1,11 @@ +try { + if (process.env['PREFAB_SKIP_PEER_DEPENDENCY_CHECK'] !== 'true') { + require('long'); + } +} catch { + throw new Error( + 'Prefab requires the "long" package to be in your project. See https://www.npmjs.com/package/long', + ); +} + +export {}; diff --git a/tsconfig.json b/tsconfig.json index f909161..1b359a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,8 +8,8 @@ "dist" ], "compilerOptions": { - "target": "es2018", - "module": "es2015", + "target": "es2020", + "module": "es2022", "declaration": true, "outDir": "./dist", "noEmit": false,