From 743ed5b060f90b42ba832b0ae7f934f63a8afb22 Mon Sep 17 00:00:00 2001 From: Frederik Rothenberger Date: Mon, 30 Oct 2023 10:18:10 +0100 Subject: [PATCH] Refactor readCanisterId to allow reading the test_app id as well (#1985) * 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. * Name parameters of --- vite.plugins.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/vite.plugins.ts b/vite.plugins.ts index 6f6c70053d..9059816c40 100644 --- a/vite.plugins.ts +++ b/vite.plugins.ts @@ -4,24 +4,28 @@ 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, + canisterIdsJsonFile, +}: { + 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 +46,10 @@ export const injectCanisterIdPlugin = (): { const rgx = /`; + return ``; }); }, });