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 24, 2024
1 parent d5495b1 commit 1a433d2
Show file tree
Hide file tree
Showing 11 changed files with 73 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 @@ -35,7 +35,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": "yarn build",
Expand All @@ -47,7 +47,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 @@ -68,6 +68,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.0.5",
"@semantic-release/npm": "^9.0.1",
Expand Down Expand Up @@ -202,6 +203,12 @@
"changelogFile": "docs/gitbook/changelog.md"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "node scripts/updateVersion.js ${nextRelease.version} && yarn build"
}
],
[
"@semantic-release/npm",
{
Expand All @@ -215,6 +222,7 @@
"assets": [
"package.json",
"yarn.lock",
"src/version.ts",
"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}`);
8 changes: 4 additions & 4 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Job } from './job';
import { QueueGetters } from './queue-getters';
import { Repeat } from './repeat';
import { RedisConnection } from './redis-connection';
import { readPackageJson } from '../utils';
import { version } from '../version';

export interface ObliterateOpts {
/**
Expand Down Expand Up @@ -100,6 +100,8 @@ export class Queue<
opts: QueueOptions;
private _repeat?: Repeat;

protected libName = 'bullmq';

constructor(
name: string,
opts?: QueueOptions,
Expand Down Expand Up @@ -167,11 +169,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 @@ -209,8 +209,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
10 changes: 3 additions & 7 deletions src/classes/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ 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 { version } from '../version';
export type JobData = [JobJsonRaw | number, string?];

export class Scripts {
Expand All @@ -50,7 +46,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 @@ -217,24 +217,3 @@ export const errorToJSON = (value: any): Record<string, any> => {
export const WORKER_SUFFIX = '';

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 = '4.18.1';
43 changes: 40 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,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 Expand Up @@ -7139,7 +7151,16 @@ string-argv@^0.3.1:
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -7221,7 +7242,14 @@ stringify-object@^3.2.1:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -7924,7 +7952,7 @@ workerpool@6.2.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -7942,6 +7970,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 1a433d2

Please sign in to comment.