Skip to content

Commit

Permalink
Add prepack script
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 committed Sep 1, 2022
1 parent 89c855f commit 84455cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions injectVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

const fs = require('fs');

// Reads dist/node/common/baseTelemetryReporter.js and replaces PACKAGE_JSON_VERSION with the number from the package.json
const packageJson = require('./package.json');
const baseTelemetryReporter = fs.readFileSync('./dist/node/common/baseTelemetryReporter.js', 'utf8');
const newBaseTelemetryReporter = baseTelemetryReporter.replace(/PACKAGE_JSON_VERSION/g, packageJson.version);
fs.writeFileSync('./dist/node/common/baseTelemetryReporter.js', newBaseTelemetryReporter);

// Reads dist/browser/common/baseTelemetryReporter.js and replaces PACKAGE_JSON_VERSION with the number from the package.json
const baseTelemetryReporterBrowser = fs.readFileSync('./dist/browser/common/baseTelemetryReporter.js', 'utf8');
const newBaseTelemetryReporterBrowser = baseTelemetryReporterBrowser.replace(/PACKAGE_JSON_VERSION/g, packageJson.version);
fs.writeFileSync('./dist/browser/common/baseTelemetryReporter.js', newBaseTelemetryReporterBrowser);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"vscode": "^1.60.0"
},
"scripts": {
"prepack": "node injectVersion.js",
"build": "npm run compile",
"test": "tsc -p 'test/tsconfig.json' && mocha dist/test/*",
"compile": "tsc -p 'src/browser/tsconfig.json' && tsc -p 'src/node/tsconfig.json'"
Expand Down
4 changes: 2 additions & 2 deletions src/common/baseTelemetryReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export class BaseTelemetryReporter {
commonProperties["common.platformversion"] = (this.osShim.release || "").replace(/^(\d+)(\.\d+)?(\.\d+)?(.*)/, "$1$2$3");
commonProperties["common.extname"] = this.extensionId;
commonProperties["common.extversion"] = this.extensionVersion;
// TODO @lramos15, this should be dynamic but loading JSON modules didn't play nicely
commonProperties["common.telemetryclientversion"] = "0.6.3";
// Do not change this string as it gets found and replaced upon packaging
commonProperties["common.telemetryclientversion"] = "PACKAGE_JSON_VERSION";
if (this.vscodeAPI && this.vscodeAPI.env) {
commonProperties["common.vscodemachineid"] = this.vscodeAPI.env.machineId;
commonProperties["common.vscodesessionid"] = this.vscodeAPI.env.sessionId;
Expand Down

0 comments on commit 84455cb

Please sign in to comment.