Skip to content

Commit

Permalink
product - guard against bad usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 16, 2019
1 parent 8405574 commit a63cf6c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/vs/platform/product/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
import { env } from 'vs/base/common/process';

let product: IProductConfiguration;

// Web
if (isWeb) {

// Built time configuration (do NOT modify)
Expand All @@ -24,15 +26,16 @@ if (isWeb) {
nameShort: 'VSCode Web Dev'
});
}
} else {
}

// Node: AMD loader
else if (typeof require !== 'undefined' && typeof require.__$__nodeRequire === 'function') {

// Obtain values from product.json and package.json
const rootPath = path.dirname(getPathFromAmdModule(require, ''));
const productJsonPath = path.join(rootPath, 'product.json');
const packageJsonPath = path.join(rootPath, 'package.json');

product = assign({}, require.__$__nodeRequire(productJsonPath) as IProductConfiguration);
const pkg = require.__$__nodeRequire(packageJsonPath) as { version: string; };
product = assign({}, require.__$__nodeRequire(path.join(rootPath, 'product.json')) as IProductConfiguration);
const pkg = require.__$__nodeRequire(path.join(rootPath, 'package.json')) as { version: string; };

// Running out of sources
if (env['VSCODE_DEV']) {
Expand All @@ -48,4 +51,9 @@ if (isWeb) {
});
}

// Unknown
else {
throw new Error('Unable to resolve product configuration');
}

export default product;

0 comments on commit a63cf6c

Please sign in to comment.