Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit b868762

Browse files
authored
fix: use path.join and __dirname for require package.json (#1936)
1 parent 129ff51 commit b868762

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/gcs-resumable-upload.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {Readable, Writable} from 'stream';
2828
import retry = require('async-retry');
2929
import {RetryOptions, PreconditionOptions} from './storage';
3030
import * as uuid from 'uuid';
31+
import path = require('path');
3132

3233
const NOT_FOUND_STATUS_CODE = 404;
3334
const TERMINATED_UPLOAD_STATUS_CODE = 410;
@@ -36,10 +37,10 @@ const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
3637
let packageJson: ReturnType<JSON['parse']> = {};
3738
try {
3839
// if requiring from 'build' (default)
39-
packageJson = require('../../package.json');
40+
packageJson = require(path.join(__dirname, '../../package.json'));
4041
} catch (e) {
4142
// if requiring directly from TypeScript context
42-
packageJson = require('../package.json');
43+
packageJson = require(path.join(__dirname, '../package.json'));
4344
}
4445

4546
export const PROTOCOL_REGEX = /^(\w*):\/\//;

src/nodejs-common/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ import {Duplex, DuplexOptions, Readable, Transform, Writable} from 'stream';
2929
import {teenyRequest} from 'teeny-request';
3030
import {Interceptor} from './service-object';
3131
import * as uuid from 'uuid';
32+
import path = require('path');
3233
let packageJson: ReturnType<JSON['parse']> = {};
3334
try {
3435
// if requiring from 'build' (default)
35-
packageJson = require('../../../package.json');
36+
packageJson = require(path.join(__dirname, '../../../package.json'));
3637
} catch (e) {
3738
// if requiring directly from TypeScript context
38-
packageJson = require('../../package.json');
39+
packageJson = require(path.join(__dirname, '../../package.json'));
3940
}
4041

4142
// eslint-disable-next-line @typescript-eslint/no-var-requires

src/storage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {Channel} from './channel';
2323
import {File} from './file';
2424
import {normalize} from './util';
2525
import {HmacKey, HmacKeyMetadata, HmacKeyOptions} from './hmacKey';
26+
import path = require('path');
2627

2728
export interface GetServiceAccountOptions {
2829
userProject?: string;
@@ -618,10 +619,10 @@ export class Storage extends Service {
618619

619620
try {
620621
// if requiring from 'build' (default)
621-
packageJson = require('../../package.json');
622+
packageJson = require(path.join(__dirname, '../../package.json'));
622623
} catch (e) {
623624
// if requiring directly from TypeScript context
624-
packageJson = require('../package.json');
625+
packageJson = require(path.join(__dirname, '../package.json'));
625626
}
626627

627628
const config = {

0 commit comments

Comments
 (0)