Skip to content

Commit c7aebae

Browse files
authored
fix(zero): Change strategy for version consts (#2837)
We used to rely on the build replacing these consts. This does not work when we use `tsx` to run typescript directly. Instead, we will use `process.env` to set the version consts. We still replace `process.env.REPLICACHE_VERSION` and `process.env.ZERO_VERSION` in the build step.
1 parent a3e169f commit c7aebae

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/replicache/src/version.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// Filled in by esbuild.
2-
declare const REPLICACHE_VERSION: string;
1+
// The env value should be filled in by esbuild.
2+
3+
declare const process: {
4+
env: {
5+
['REPLICACHE_VERSION']?: string;
6+
};
7+
};
38

49
/**
510
* The current version of Replicache.
611
*/
7-
export const version: string = REPLICACHE_VERSION;
12+
export const version: string = process.env.REPLICACHE_VERSION ?? '0.0.0';

packages/shared/src/build.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ function getVersion(name) {
5555
export function makeDefine(mode = 'unknown') {
5656
/** @type {Record<string, string>} */
5757
const define = {
58-
['REPLICACHE_VERSION']: JSON.stringify(getVersion('replicache')),
59-
['ZERO_VERSION']: JSON.stringify(getVersion('zero-client')),
58+
['process.env.REPLICACHE_VERSION']: JSON.stringify(
59+
getVersion('replicache'),
60+
),
61+
['process.env.ZERO_VERSION']: JSON.stringify(getVersion('zero')),
6062
['TESTING']: 'false',
6163
};
6264
if (mode === 'unknown') {

packages/zero-client/src/client/version.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import {expect, test} from 'vitest';
22
import {version} from './version.js';
33

44
test('version basics', () => {
5-
expect(version).to.match(/^\d+\.\d+\.\d+$/);
5+
expect(version).to.match(/^\d+\.\d+\.\d+(\+[a-f0-9]+)?$/);
66
});
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
declare const ZERO_VERSION: string;
1+
// The env value should be filled in by esbuild.
2+
3+
declare const process: {
4+
env: {
5+
['ZERO_VERSION']?: string;
6+
};
7+
};
28

39
/**
410
* The current version of Zero.
511
*/
6-
export const version = ZERO_VERSION;
12+
export const version = process.env.ZERO_VERSION ?? '0.0.0';

0 commit comments

Comments
 (0)