Skip to content

Commit

Permalink
fix: use path.join and __dirname for require package.json (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 authored May 17, 2022
1 parent 129ff51 commit b868762
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/gcs-resumable-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {Readable, Writable} from 'stream';
import retry = require('async-retry');
import {RetryOptions, PreconditionOptions} from './storage';
import * as uuid from 'uuid';
import path = require('path');

const NOT_FOUND_STATUS_CODE = 404;
const TERMINATED_UPLOAD_STATUS_CODE = 410;
Expand All @@ -36,10 +37,10 @@ const DEFAULT_API_ENDPOINT_REGEX = /.*\.googleapis\.com/;
let packageJson: ReturnType<JSON['parse']> = {};
try {
// if requiring from 'build' (default)
packageJson = require('../../package.json');
packageJson = require(path.join(__dirname, '../../package.json'));
} catch (e) {
// if requiring directly from TypeScript context
packageJson = require('../package.json');
packageJson = require(path.join(__dirname, '../package.json'));
}

export const PROTOCOL_REGEX = /^(\w*):\/\//;
Expand Down
5 changes: 3 additions & 2 deletions src/nodejs-common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ import {Duplex, DuplexOptions, Readable, Transform, Writable} from 'stream';
import {teenyRequest} from 'teeny-request';
import {Interceptor} from './service-object';
import * as uuid from 'uuid';
import path = require('path');
let packageJson: ReturnType<JSON['parse']> = {};
try {
// if requiring from 'build' (default)
packageJson = require('../../../package.json');
packageJson = require(path.join(__dirname, '../../../package.json'));
} catch (e) {
// if requiring directly from TypeScript context
packageJson = require('../../package.json');
packageJson = require(path.join(__dirname, '../../package.json'));
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
5 changes: 3 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {Channel} from './channel';
import {File} from './file';
import {normalize} from './util';
import {HmacKey, HmacKeyMetadata, HmacKeyOptions} from './hmacKey';
import path = require('path');

export interface GetServiceAccountOptions {
userProject?: string;
Expand Down Expand Up @@ -618,10 +619,10 @@ export class Storage extends Service {

try {
// if requiring from 'build' (default)
packageJson = require('../../package.json');
packageJson = require(path.join(__dirname, '../../package.json'));
} catch (e) {
// if requiring directly from TypeScript context
packageJson = require('../package.json');
packageJson = require(path.join(__dirname, '../package.json'));
}

const config = {
Expand Down

0 comments on commit b868762

Please sign in to comment.