Skip to content

Commit

Permalink
fix: proper way to get version
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Oct 22, 2024
1 parent d1eb1bb commit b4e25c1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 44 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
cache: 'yarn'
- name: Install dependencies Node
run: yarn install --frozen-lockfile --non-interactive
- run: yarn build
- name: Release Node
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dc:down": "docker-compose -f docker-compose.yml down",
"dry-run": "npm publish --dry-run",
"eslint:fix": "./node_modules/.bin/eslint . --ignore-path ./.eslintignore --fix",
"generate:raw:scripts": "ts-node --project tsconfig-cjs.json generateRawScripts.ts",
"generate:raw:scripts": "ts-node --project tsconfig-cjs.json scripts/generateRawScripts.ts",
"lint": "./node_modules/.bin/eslint . --ignore-path ./.eslintignore",
"lint:staged": "lint-staged",
"prepublishOnly": "npm run build",
Expand All @@ -48,7 +48,7 @@
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
"test": "ts-mocha -p tsconfig-cjs.json --config ./.mocharc.js",
"test:watch": "ts-mocha -p tsconfig-cjs.json --paths 'tests/test_*.ts' -w --watch-extensions ts",
"transform:commands": "node ./commandTransform.js ./rawScripts ./src/scripts",
"transform:commands": "node ./scripts/commandTransform.js ./rawScripts ./src/scripts",
"tsc": "tsc",
"tsc:all": "tsc && tsc -p tsconfig-cjs.json"
},
Expand All @@ -67,6 +67,7 @@
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.1.0",
"@semantic-release/npm": "^9.0.1",
Expand Down Expand Up @@ -188,6 +189,12 @@
"changelogFile": "docs/gitbook/changelog.md"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "node scripts/updateVersion.js ${nextRelease.version} && yarn build"
}
],
[
"@semantic-release/npm",
{
Expand All @@ -201,6 +208,7 @@
"assets": [
"package.json",
"yarn.lock",
"src/version",
"docs/gitbook/changelog.md",
"docs/gitbook/api/**"
],
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions generateRawScripts.ts → scripts/generateRawScripts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScriptLoader } from './src/commands/index';
import { ScriptLoader } from '../src/commands/index';
import * as path from 'path';
import * as fs from 'fs';
import { promisify } from 'util';
Expand Down Expand Up @@ -39,6 +39,6 @@ export class RawScriptLoader extends ScriptLoader {
const scriptLoader = new RawScriptLoader();

scriptLoader.transpileScripts(
path.join(__dirname, './src/commands'),
path.join(__dirname, './rawScripts'),
path.join(__dirname, '../src/commands'),
path.join(__dirname, '../rawScripts'),
);
11 changes: 11 additions & 0 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');
const path = require('path');

const newVersion = process.argv[2];
const versionFilePath = path.join(__dirname, '../src/version.ts');

const content = `export const version = '${newVersion}';\n`;

fs.writeFileSync(versionFilePath, content, 'utf8');

console.log(`Updated version file to version ${newVersion}`);
10 changes: 5 additions & 5 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { QueueGetters } from './queue-getters';
import { Repeat } from './repeat';
import { RedisConnection } from './redis-connection';
import { JobScheduler } from './job-scheduler';
import { readPackageJson } from '../utils';
import { version } from '../version';

export interface ObliterateOpts {
/**
Expand Down Expand Up @@ -98,8 +98,10 @@ export class Queue<
token = v4();
jobsOpts: BaseJobOptions;
opts: QueueOptions;
private _repeat?: Repeat; // To be deprecated in v6 in favor of JobScheduler

protected libName = 'bullmq';

private _repeat?: Repeat; // To be deprecated in v6 in favor of JobScheduler
private _jobScheduler?: JobScheduler;

constructor(
Expand Down Expand Up @@ -169,11 +171,9 @@ export class Queue<
}

get metaValues(): Record<string, string | number> {
const { name, version } = readPackageJson();

return {
'opts.maxLenEvents': this.opts?.streams?.events?.maxLen ?? 10000,
version: `${name}:${version}`,
version: `${this.libName}:${version}`,
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/classes/redis-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
isRedisCluster,
isRedisInstance,
isRedisVersionLowerThan,
readPackageJson,
} from '../utils';
import { version } from '../version';
import * as scripts from '../scripts';

const overrideMessage = [
Expand Down Expand Up @@ -228,8 +228,6 @@ export class RedisConnection extends EventEmitter {

this._client.on('ready', this.handleClientReady);

const { version } = readPackageJson();

await RedisConnection.waitUntilReady(this._client);

this.loadCommands(version);
Expand Down
12 changes: 3 additions & 9 deletions src/classes/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,9 @@ import {
RedisJobOptions,
} from '../types';
import { ErrorCode } from '../enums';
import {
array2obj,
getParentKey,
isRedisVersionLowerThan,
readPackageJson,
} from '../utils';
import { array2obj, getParentKey, isRedisVersionLowerThan } from '../utils';
import { ChainableCommander } from 'ioredis';
import { read } from 'fs';

import { version } from '../version';
export type JobData = [JobJsonRaw | number, string?];

export class Scripts {
Expand All @@ -53,7 +47,7 @@ export class Scripts {
constructor(protected queue: MinimalQueue) {
const queueKeys = this.queue.keys;

this.version = readPackageJson().version;
this.version = version;

this.moveToFinishedKeys = [
queueKeys.wait,
Expand Down
21 changes: 0 additions & 21 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,3 @@ export const toString = (value: any): string => {
};

export const QUEUE_EVENT_SUFFIX = ':qe';

export const readPackageJson: () => { name: string; version: string } = () => {
const packageJsonPossiblePaths = [
join(__dirname, '../package.json'),
join(__dirname, '../../package.json'),
join(__dirname, '../../../package.json'),
];

for (const path of packageJsonPossiblePaths) {
try {
return JSON.parse(readFileSync(path, 'utf-8'));
} catch (err) {
if ((<any>err).code === 'ENOENT') {
continue;
}
console.log(err);
}
}

return { name: 'bullmq', version: '0.0.0' };
};
1 change: 1 addition & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = '5.21.1';
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,18 @@
resolved "https://registry.yarnpkg.com/@semantic-release/error/-/error-3.0.0.tgz#30a3b97bbb5844d695eb22f9d3aa40f6a92770c2"
integrity sha512-5hiM4Un+tpl4cKw3lV4UgzJj+SmfNIDCLLw0TepzQxz9ZGV5ixnqkzIVF+3tp0ZHgcMKE+VNGHJjEeyFG2dcSw==

"@semantic-release/exec@^6.0.3":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@semantic-release/exec/-/exec-6.0.3.tgz#d212fdf19633bdfb553de6cb6c7f8781933224db"
integrity sha512-bxAq8vLOw76aV89vxxICecEa8jfaWwYITw6X74zzlO0mc/Bgieqx9kBRz9z96pHectiTAtsCwsQcUyLYWnp3VQ==
dependencies:
"@semantic-release/error" "^3.0.0"
aggregate-error "^3.0.0"
debug "^4.0.0"
execa "^5.0.0"
lodash "^4.17.4"
parse-json "^5.0.0"

"@semantic-release/git@^10.0.1":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@semantic-release/git/-/git-10.0.1.tgz#c646e55d67fae623875bf3a06a634dd434904498"
Expand Down

0 comments on commit b4e25c1

Please sign in to comment.