Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use path.join and __dirname for require package.json #1936

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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