Skip to content

Commit 4f832fb

Browse files
committed
fix injecting versions
1 parent 195e814 commit 4f832fb

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

packages/gateway/scripts/inject-version.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const version = process.argv[2] || pkg.version;
77

88
console.log(`Injecting version ${version} to build and bundle`);
99

10-
const source = '// @inject-version globalThis.__VERSION__ here';
10+
const source = /globalThis\.__VERSION__ = .*;/;
1111
const inject = `globalThis.__VERSION__ = '${version}';`;
1212

1313
const __dirname = fileURLToPath(new URL('.', import.meta.url));
@@ -23,10 +23,12 @@ for (const file of [
2323
]) {
2424
try {
2525
const content = await readFile(file, 'utf-8');
26-
if (content.includes(source)) {
26+
if (content.match(source)) {
2727
await writeFile(file, content.replace(source, inject));
28+
console.info(`✅ Version injected to "${file}"`);
29+
} else {
30+
console.info(`❌ Version cannot be injected to "${file}"`);
2831
}
29-
console.info(`✅ Version injected to "${file}"`);
3032
} catch (e) {
3133
if (Object(e).code === 'ENOENT') {
3234
console.warn(

packages/gateway/src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { InitializeData } from '@graphql-hive/importer/hooks';
66
import { Logger } from '@graphql-hive/logger';
77
import { enableModuleCachingIfPossible, handleNodeWarnings, run } from './cli';
88

9-
// @inject-version globalThis.__VERSION__ here
9+
globalThis.__VERSION__ = 'dev';
1010

1111
module.register('@graphql-hive/importer/hooks', {
1212
parentURL:

packages/gateway/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export async function run(userCtx: Partial<CLIContext>) {
468468
productLink: 'https://the-guild.dev/graphql/hive/docs/gateway',
469469
binName: 'hive-gateway',
470470
configFileName: 'gateway.config',
471-
version: globalThis.__VERSION__ || 'dev',
471+
version: globalThis.__VERSION__ || 'unknown',
472472
...userCtx,
473473
};
474474

packages/plugins/opentelemetry/scripts/inject-version.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const version = process.argv[2] || pkg.version;
77

88
console.log(`Injecting version ${version} to build and bundle`);
99

10-
const source = '// @inject-version globalThis.__OTEL_PLUGIN_VERSION__ here';
10+
const source = /globalThis\.__OTEL_PLUGIN_VERSION__ = .*;/;
1111
const inject = `globalThis.__OTEL_PLUGIN_VERSION__ = '${version}';`;
1212

1313
const __dirname = fileURLToPath(new URL('.', import.meta.url));
@@ -19,10 +19,12 @@ for (const file of [
1919
]) {
2020
try {
2121
const content = await readFile(file, 'utf-8');
22-
if (content.includes(source)) {
22+
if (content.match(source)) {
2323
await writeFile(file, content.replace(source, inject));
24+
console.info(`✅ Version injected to "${file}"`);
25+
} else {
26+
console.info(`❌ Version cannot be injected to "${file}"`);
2427
}
25-
console.info(`✅ Version injected to "${file}"`);
2628
} catch (e) {
2729
if (Object(e).code === 'ENOENT') {
2830
console.warn(

packages/plugins/opentelemetry/src/setup.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export * from './attributes';
4242
export * from './log-writer';
4343
export * from './hive-span-processor';
4444

45-
// @inject-version globalThis.__OTEL_PLUGIN_VERSION__ here
45+
globalThis.__OTEL_PLUGIN_VERSION__ = 'dev';
4646

4747
type TracingOptions = {
4848
traces?:
@@ -151,9 +151,10 @@ export function openTelemetrySetup(options: OpentelemetrySetupOptions) {
151151
options.resource && 'serviceVersion' in options.resource
152152
? options.resource?.serviceVersion
153153
: getEnvStr('OTEL_SERVICE_VERSION') ||
154-
globalThis.__OTEL_PLUGIN_VERSION__,
154+
globalThis.__OTEL_PLUGIN_VERSION__ ||
155+
'unknown',
155156
['hive.gateway.version']: globalThis.__VERSION__,
156-
['hive.otel.version']: globalThis.__OTEL_PLUGIN_VERSION__,
157+
['hive.otel.version']: globalThis.__OTEL_PLUGIN_VERSION__ || 'unknown',
157158
});
158159

159160
const resource =

0 commit comments

Comments
 (0)