From 9c167db581b36ba57cd5efc45be08b316b5bce2b Mon Sep 17 00:00:00 2001 From: JC Franco Date: Sat, 11 Jan 2025 01:02:01 -0800 Subject: [PATCH 1/5] build: simplify version placeholder replacement --- package-lock.json | 23 ------------------- package.json | 1 - .../src/utils/config.spec.ts | 6 ++--- .../calcite-components/src/utils/config.ts | 6 ++--- packages/calcite-components/vite.config.ts | 18 ++++++--------- 5 files changed, 13 insertions(+), 41 deletions(-) diff --git a/package-lock.json b/package-lock.json index da052e374a4..7664ce3cb9f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "@octokit/webhooks-types": "7.6.1", "@prettier/sync": "0.5.2", "@rollup/plugin-node-resolve": "16.0.0", - "@rollup/plugin-replace": "6.0.2", "@rollup/plugin-typescript": "12.1.2", "@storybook/addon-a11y": "8.4.7", "@storybook/addon-controls": "8.4.7", @@ -6079,28 +6078,6 @@ } } }, - "node_modules/@rollup/plugin-replace": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-6.0.2.tgz", - "integrity": "sha512-7QaYCf8bqF04dOy7w/eHmJeNExxTYwvKAmlSAH/EaWWUzbT0h5sbF6bktFoX/0F/0qwng5/dWFMyf3gzaM8DsQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@rollup/pluginutils": "^5.0.1", - "magic-string": "^0.30.3" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } - } - }, "node_modules/@rollup/plugin-typescript": { "version": "12.1.2", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-12.1.2.tgz", diff --git a/package.json b/package.json index a5f59d52376..760c2c0468b 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "@octokit/webhooks-types": "7.6.1", "@prettier/sync": "0.5.2", "@rollup/plugin-node-resolve": "16.0.0", - "@rollup/plugin-replace": "6.0.2", "@rollup/plugin-typescript": "12.1.2", "@storybook/addon-a11y": "8.4.7", "@storybook/addon-controls": "8.4.7", diff --git a/packages/calcite-components/src/utils/config.spec.ts b/packages/calcite-components/src/utils/config.spec.ts index 6068a8ef97f..b8bfc6ed030 100644 --- a/packages/calcite-components/src/utils/config.spec.ts +++ b/packages/calcite-components/src/utils/config.spec.ts @@ -30,21 +30,21 @@ describe("config", () => { }); describe("stampVersion", () => { - const calciteVersionPreBuildPlaceholder = "__CALCITE_VERSION__"; + const buildVersion = __CALCITE_VERSION__; beforeEach(() => delete globalThis.calciteConfig); it("creates global config and stamps the version onto it", async () => { config = await loadConfig(); config.stampVersion(); - expect(globalThis.calciteConfig.version).toBe(calciteVersionPreBuildPlaceholder); + expect(globalThis.calciteConfig.version).toBe(buildVersion); }); it("stamps the version onto existing config if there's no version present", async () => { globalThis.calciteConfig = {}; config = await loadConfig(); config.stampVersion(); - expect(globalThis.calciteConfig.version).toBe(calciteVersionPreBuildPlaceholder); + expect(globalThis.calciteConfig.version).toBe(buildVersion); }); it("bails if version is already stamped onto existing config", async () => { diff --git a/packages/calcite-components/src/utils/config.ts b/packages/calcite-components/src/utils/config.ts index 356c6c36fd1..26240480e8f 100644 --- a/packages/calcite-components/src/utils/config.ts +++ b/packages/calcite-components/src/utils/config.ts @@ -32,9 +32,9 @@ const runningInE2ETest = import.meta.env.MODE === "test" && !isServer; export const logLevel: LogLevel = existingConfig?.logLevel || (runningInE2ETest ? "error" : "info"); // the following placeholders are replaced by the build -const version = "__CALCITE_VERSION__"; -const buildDate = "__CALCITE_BUILD_DATE__"; -const revision = "__CALCITE_REVISION__"; +const version = __CALCITE_VERSION__; +const buildDate = __CALCITE_BUILD_DATE__; +const revision = __CALCITE_REVISION__; /** Stamp the version onto the global config. */ export function stampVersion(): void { diff --git a/packages/calcite-components/vite.config.ts b/packages/calcite-components/vite.config.ts index 3cea1c90fa6..8b08cc4e896 100644 --- a/packages/calcite-components/vite.config.ts +++ b/packages/calcite-components/vite.config.ts @@ -6,7 +6,6 @@ import stylelint from "stylelint"; // TODO: [MIGRATION] evaluate the usages of the key={} props - most of the time key is not necessary in Lit. See https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-jsx--docs#key-prop import { defineConfig } from "vite"; import { useLumina } from "@arcgis/lumina-compiler"; -import replace from "@rollup/plugin-replace"; import { version } from "./package.json"; import tailwindConfig from "./tailwind.config"; @@ -53,16 +52,6 @@ export default defineConfig({ }, }, }), - process.env.NODE_ENV !== "test" && - replace({ - values: { - __CALCITE_BUILD_DATE__: () => new Date().toISOString().split("T")[0], - __CALCITE_REVISION__: execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim(), - __CALCITE_VERSION__: version, - }, - include: ["src/utils/config.ts"], - preventAssignment: true, - }), ], css: { @@ -95,6 +84,13 @@ export default defineConfig({ ], }, }, + + define: { + __CALCITE_BUILD_DATE__: JSON.stringify(new Date().toISOString().split("T")[0]), + __CALCITE_REVISION__: JSON.stringify(execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim()), + __CALCITE_VERSION__: JSON.stringify(version), + }, + test: { setupFiles: ["src/tests/setupTests.ts"], include: ["**/*.{e2e,spec}.?(c|m)[jt]s?(x)"], From f8424397f3757e2336e400a9f8e3d405b5e722c1 Mon Sep 17 00:00:00 2001 From: JC Franco Date: Sat, 11 Jan 2025 01:40:28 -0800 Subject: [PATCH 2/5] add missing .d.ts file for vitest env variables --- packages/calcite-components/vite-env.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/calcite-components/vite-env.d.ts diff --git a/packages/calcite-components/vite-env.d.ts b/packages/calcite-components/vite-env.d.ts new file mode 100644 index 00000000000..45a943aa02a --- /dev/null +++ b/packages/calcite-components/vite-env.d.ts @@ -0,0 +1,4 @@ +declare const __CALCITE_BUILD_DATE__: string; +declare const __CALCITE_REVISION__: string; +declare const __CALCITE_VERSION__: string; +declare const __STORYBOOK_SCREENSHOT_TEST_BUILD__: boolean; From 24a1e994d4b6a2ea174ff6d62cf5ea6890077d8f Mon Sep 17 00:00:00 2001 From: JC Franco Date: Sat, 11 Jan 2025 01:35:55 -0800 Subject: [PATCH 3/5] test: preload all icons for chromatic screenshot tests --- packages/calcite-components/src/components/icon/icon.tsx | 2 +- packages/calcite-components/vite.config.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/calcite-components/src/components/icon/icon.tsx b/packages/calcite-components/src/components/icon/icon.tsx index e42308a1005..46835ef6dfd 100644 --- a/packages/calcite-components/src/components/icon/icon.tsx +++ b/packages/calcite-components/src/components/icon/icon.tsx @@ -77,7 +77,7 @@ export class Icon extends LitElement { // #region Lifecycle override connectedCallback(): void { - if (this.preload) { + if (this.preload || (import.meta.env.DEV && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) { this.visible = true; this.loadIconPathData(); return; diff --git a/packages/calcite-components/vite.config.ts b/packages/calcite-components/vite.config.ts index 8b08cc4e896..c665274a3b7 100644 --- a/packages/calcite-components/vite.config.ts +++ b/packages/calcite-components/vite.config.ts @@ -89,6 +89,7 @@ export default defineConfig({ __CALCITE_BUILD_DATE__: JSON.stringify(new Date().toISOString().split("T")[0]), __CALCITE_REVISION__: JSON.stringify(execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim()), __CALCITE_VERSION__: JSON.stringify(version), + __STORYBOOK_SCREENSHOT_TEST_BUILD__: process.env.STORYBOOK_SCREENSHOT_TEST_BUILD, }, test: { From 661d856658a5647d3b58059cf30b12a7812d7f6f Mon Sep 17 00:00:00 2001 From: JC Franco Date: Sat, 11 Jan 2025 02:01:13 -0800 Subject: [PATCH 4/5] set dev mode for screenshot test build --- packages/calcite-components/package.json | 2 +- packages/calcite-components/src/components/icon/icon.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/calcite-components/package.json b/packages/calcite-components/package.json index b5389fc36eb..12812b807ec 100644 --- a/packages/calcite-components/package.json +++ b/packages/calcite-components/package.json @@ -49,7 +49,7 @@ "lint:scss": "stylelint --fix \"src/**/*.scss\" && prettier --write \"**/*.scss\" >/dev/null", "lint:ts": "eslint --fix . && prettier --write \"**/*.{ts,tsx,cjs,mjs}\" >/dev/null", "prepublish": "./support/cleanupDistFiles.sh", - "screenshot-tests": "npm run build-storybook", + "screenshot-tests": "npm run build-storybook --mode=dev", "screenshot-tests:preview": "npm run util:prep-build-reqs && NODE_OPTIONS=--openssl-legacy-provider STORYBOOK_SCREENSHOT_LOCAL_BUILD=true storybook dev", "screenshot-tests:publish": "npm run screenshot-tests && storybook-to-ghpages --existing-output-dir=docs", "start": "npm run util:clean-js-files && concurrently --kill-others --raw \"tsc --project ./tsconfig-demos.json --watch\" \"npm run build:watch-dev\"", diff --git a/packages/calcite-components/src/components/icon/icon.tsx b/packages/calcite-components/src/components/icon/icon.tsx index 46835ef6dfd..1b2df45b8fd 100644 --- a/packages/calcite-components/src/components/icon/icon.tsx +++ b/packages/calcite-components/src/components/icon/icon.tsx @@ -77,7 +77,7 @@ export class Icon extends LitElement { // #region Lifecycle override connectedCallback(): void { - if (this.preload || (import.meta.env.DEV && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) { + if (this.preload || (import.meta.env.MODE === "DEV" && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) { this.visible = true; this.loadIconPathData(); return; From 0965a828280d5675ca33477a707a29244dd9dbeb Mon Sep 17 00:00:00 2001 From: JC Franco Date: Sat, 11 Jan 2025 09:59:09 -0800 Subject: [PATCH 5/5] Use correct mode value --- packages/calcite-components/src/components/icon/icon.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/calcite-components/src/components/icon/icon.tsx b/packages/calcite-components/src/components/icon/icon.tsx index 1b2df45b8fd..f1f8854e353 100644 --- a/packages/calcite-components/src/components/icon/icon.tsx +++ b/packages/calcite-components/src/components/icon/icon.tsx @@ -77,7 +77,7 @@ export class Icon extends LitElement { // #region Lifecycle override connectedCallback(): void { - if (this.preload || (import.meta.env.MODE === "DEV" && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) { + if (this.preload || (import.meta.env.MODE === "development" && __STORYBOOK_SCREENSHOT_TEST_BUILD__)) { this.visible = true; this.loadIconPathData(); return;