Skip to content

Commit

Permalink
build: simplify version placeholder replacement (#11266)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfranco authored Jan 12, 2025
1 parent 2320ee4 commit 26885c9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 41 deletions.
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/calcite-components/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions packages/calcite-components/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 7 additions & 11 deletions packages/calcite-components/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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)"],
Expand Down

0 comments on commit 26885c9

Please sign in to comment.