From d1731248336df55974ebfef94011871875502444 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Thu, 26 Oct 2023 14:41:47 +0200 Subject: [PATCH] Refactor readCanisterId to allow reading the test_app id as well This PR is in preparation for the migration of the selnium tests out of docker. After the migration, vite needs to know about the test_app canister id too. This refactoring allows using the existing helper for that. --- vite.plugins.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/vite.plugins.ts b/vite.plugins.ts index 6f6c70053d..c58187873a 100644 --- a/vite.plugins.ts +++ b/vite.plugins.ts @@ -4,24 +4,25 @@ import { minify } from "html-minifier-terser"; import { extname } from "path"; import { Plugin } from "vite"; import viteCompression from "vite-plugin-compression"; - /** - * Read the II canister ID from dfx's local state + * Read a canister ID from dfx's local state */ -const readCanisterId = (): string => { - const canisterIdsJsonFile = "./.dfx/local/canister_ids.json"; - +export const readCanisterId = ( + canisterName: string, + canisterIdsJsonFile: string +): string => { try { - const { - internet_identity: { local: canisterId }, - } = JSON.parse(readFileSync(canisterIdsJsonFile, "utf-8")); - + const canisterIds: Record = JSON.parse( + readFileSync(canisterIdsJsonFile, "utf-8") + ); + const canisterId = canisterIds[canisterName]?.local; assertNonNullish( canisterId, `Could not get canister ID from ${canisterIdsJsonFile}` ); - - console.log("Read canister ID:", canisterId); + console.log( + `Read canister ID '${canisterId} for canister with name '${canisterName}'` + ); return canisterId; } catch (e) { @@ -42,7 +43,10 @@ export const injectCanisterIdPlugin = (): { const rgx = /`; + return ``; }); }, });