@react-native-windows/telemetry 0.66.1 → 0.68.0-preview.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib-commonjs/index.d.ts +5 -2
- package/lib-commonjs/index.js +14 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/telemetry.d.ts +75 -20
- package/lib-commonjs/telemetry.js +285 -169
- package/lib-commonjs/telemetry.js.map +1 -1
- package/lib-commonjs/test/{sanitize.test.d.ts → basePropUtils.test.d.ts} +0 -0
- package/lib-commonjs/test/basePropUtils.test.js +116 -0
- package/lib-commonjs/test/basePropUtils.test.js.map +1 -0
- package/lib-commonjs/test/errorUtils.test.d.ts +7 -0
- package/lib-commonjs/test/errorUtils.test.js +159 -0
- package/lib-commonjs/test/errorUtils.test.js.map +1 -0
- package/lib-commonjs/test/projectUtils.test.d.ts +7 -0
- package/lib-commonjs/test/projectUtils.test.js +84 -0
- package/lib-commonjs/test/projectUtils.test.js.map +1 -0
- package/lib-commonjs/test/sanitizeUtils.test.d.ts +7 -0
- package/lib-commonjs/test/sanitizeUtils.test.js +94 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -0
- package/lib-commonjs/test/telemetry.test.d.ts +26 -0
- package/lib-commonjs/test/telemetry.test.js +469 -0
- package/lib-commonjs/test/telemetry.test.js.map +1 -0
- package/lib-commonjs/test/versionUtils.test.d.ts +7 -0
- package/lib-commonjs/test/versionUtils.test.js +111 -0
- package/lib-commonjs/test/versionUtils.test.js.map +1 -0
- package/lib-commonjs/utils/basePropUtils.d.ts +66 -0
- package/lib-commonjs/utils/basePropUtils.js +131 -0
- package/lib-commonjs/utils/basePropUtils.js.map +1 -0
- package/lib-commonjs/{CodedError.d.ts → utils/errorUtils.d.ts} +27 -8
- package/lib-commonjs/utils/errorUtils.js +164 -0
- package/lib-commonjs/utils/errorUtils.js.map +1 -0
- package/lib-commonjs/utils/optionUtils.d.ts +45 -0
- package/lib-commonjs/utils/optionUtils.js +96 -0
- package/lib-commonjs/utils/optionUtils.js.map +1 -0
- package/lib-commonjs/utils/projectUtils.d.ts +50 -0
- package/lib-commonjs/utils/projectUtils.js +187 -0
- package/lib-commonjs/utils/projectUtils.js.map +1 -0
- package/lib-commonjs/utils/sanitizeUtils.d.ts +12 -0
- package/lib-commonjs/utils/sanitizeUtils.js +82 -0
- package/lib-commonjs/utils/sanitizeUtils.js.map +1 -0
- package/lib-commonjs/utils/versionUtils.d.ts +38 -0
- package/lib-commonjs/utils/versionUtils.js +156 -0
- package/lib-commonjs/utils/versionUtils.js.map +1 -0
- package/package.json +26 -12
- package/CHANGELOG.json +0 -532
- package/CHANGELOG.md +0 -221
- package/lib-commonjs/CodedError.js +0 -77
- package/lib-commonjs/CodedError.js.map +0 -1
- package/lib-commonjs/test/sanitize.test.js +0 -259
- package/lib-commonjs/test/sanitize.test.js.map +0 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
const versionUtils = __importStar(require("../utils/versionUtils"));
|
|
32
|
+
const path_1 = __importDefault(require("path"));
|
|
33
|
+
const semver_1 = __importDefault(require("semver"));
|
|
34
|
+
function expectValidVersion(version, expectSemVer) {
|
|
35
|
+
expect(version).not.toBeNull();
|
|
36
|
+
expect(version).toBeDefined();
|
|
37
|
+
if (expectSemVer) {
|
|
38
|
+
expect(semver_1.default.valid(version)).toBe(version);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
version.split('.').forEach((s) => {
|
|
42
|
+
const tryParseInt = () => {
|
|
43
|
+
parseInt(s, 10);
|
|
44
|
+
};
|
|
45
|
+
expect(tryParseInt).not.toThrow();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
test('getNodeVersion() is valid', async () => {
|
|
50
|
+
const version = await versionUtils.getNodeVersion();
|
|
51
|
+
expectValidVersion(version, true);
|
|
52
|
+
});
|
|
53
|
+
test('getNpmVersion() is valid', async () => {
|
|
54
|
+
const version = await versionUtils.getNpmVersion();
|
|
55
|
+
if (version) {
|
|
56
|
+
expectValidVersion(version, true);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
test('getYarnVersion() is valid', async () => {
|
|
60
|
+
const version = await versionUtils.getYarnVersion();
|
|
61
|
+
if (version) {
|
|
62
|
+
expectValidVersion(version, true);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
test('getVisualStudioVersion() is valid', async () => {
|
|
66
|
+
const version = await versionUtils.getVisualStudioVersion();
|
|
67
|
+
expectValidVersion(version, false);
|
|
68
|
+
});
|
|
69
|
+
test('getVersionOfNpmPackage() of empty string is null', async () => {
|
|
70
|
+
const version = await versionUtils.getVersionOfNpmPackage('');
|
|
71
|
+
expect(version).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
test('getVersionOfNpmPackage() of invalid package is null', async () => {
|
|
74
|
+
const version = await versionUtils.getVersionOfNpmPackage('invalidpackage');
|
|
75
|
+
expect(version).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
test('getVersionOfNpmPackage() of valid package is valid', async () => {
|
|
78
|
+
const version = await versionUtils.getVersionOfNpmPackage('jest');
|
|
79
|
+
expectValidVersion(version, true);
|
|
80
|
+
});
|
|
81
|
+
test('getVersionsOfNuGetPackages() of valid package in packages.config is valid', async () => {
|
|
82
|
+
const projectFile = path_1.default.resolve(__dirname, 'projects/UsesPackagesConfig/UsesPackagesConfig.vcxproj');
|
|
83
|
+
const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [
|
|
84
|
+
'Microsoft.Windows.CppWinRT',
|
|
85
|
+
]);
|
|
86
|
+
expect(versions).not.toBeNull();
|
|
87
|
+
expectValidVersion(versions['Microsoft.Windows.CppWinRT'], false);
|
|
88
|
+
});
|
|
89
|
+
test('getVersionsOfNuGetPackages() of invalid package in packages.config is invalid', async () => {
|
|
90
|
+
const projectFile = path_1.default.resolve(__dirname, 'projects/UsesPackagesConfig/UsesPackagesConfig.vcxproj');
|
|
91
|
+
const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [
|
|
92
|
+
'Invalid.Package',
|
|
93
|
+
]);
|
|
94
|
+
expect(versions).toStrictEqual({});
|
|
95
|
+
});
|
|
96
|
+
test('getVersionsOfNuGetPackages() of valid package in project is valid', async () => {
|
|
97
|
+
const projectFile = path_1.default.resolve(__dirname, 'projects/UsesPackageReference/UsesPackageReference.csproj');
|
|
98
|
+
const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [
|
|
99
|
+
'Microsoft.NETCore.UniversalWindowsPlatform',
|
|
100
|
+
]);
|
|
101
|
+
expect(versions).not.toBeNull();
|
|
102
|
+
expectValidVersion(versions['Microsoft.NETCore.UniversalWindowsPlatform'], false);
|
|
103
|
+
});
|
|
104
|
+
test('getVersionsOfNuGetPackages() of invalid package in project is invalid', async () => {
|
|
105
|
+
const projectFile = path_1.default.resolve(__dirname, 'projects/UsesPackageReference/UsesPackageReference.csproj');
|
|
106
|
+
const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [
|
|
107
|
+
'Invalid.Package',
|
|
108
|
+
]);
|
|
109
|
+
expect(versions).toStrictEqual({});
|
|
110
|
+
});
|
|
111
|
+
//# sourceMappingURL=versionUtils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versionUtils.test.js","sourceRoot":"","sources":["../../src/test/versionUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oEAAsD;AAEtD,gDAAwB;AACxB,oDAA4B;AAE5B,SAAS,kBAAkB,CAAC,OAAsB,EAAE,YAAqB;IACvE,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC/B,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAI,YAAY,EAAE;QAChB,MAAM,CAAC,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KAC7C;SAAM;QACL,OAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAChC,MAAM,WAAW,GAAG,GAAG,EAAE;gBACvB,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAClB,CAAC,CAAC;YACF,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACp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QAAQ,EAAE,CAAC;IAChC,kBAAkB,CAChB,QAAQ,CAAC,4CAA4C,CAAC,EACtD,KAAK,CACN,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uEAAuE,EAAE,KAAK,IAAI,EAAE;IACvF,MAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAC9B,SAAS,EACT,2DAA2D,CAC5D,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,0BAA0B,CAAC,WAAW,EAAE;QAC1E,iBAAiB;KAClB,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport * as versionUtils from '../utils/versionUtils';\n\nimport path from 'path';\nimport semver from 'semver';\n\nfunction expectValidVersion(version: string | null, expectSemVer: boolean) {\n expect(version).not.toBeNull();\n expect(version).toBeDefined();\n if (expectSemVer) {\n expect(semver.valid(version)).toBe(version);\n } else {\n version!.split('.').forEach((s) => {\n const tryParseInt = () => {\n parseInt(s, 10);\n };\n expect(tryParseInt).not.toThrow();\n });\n }\n}\n\ntest('getNodeVersion() is valid', async () => {\n const version = await versionUtils.getNodeVersion();\n expectValidVersion(version, true);\n});\n\ntest('getNpmVersion() is valid', async () => {\n const version = await versionUtils.getNpmVersion();\n if (version) {\n expectValidVersion(version, true);\n }\n});\n\ntest('getYarnVersion() is valid', async () => {\n const version = await versionUtils.getYarnVersion();\n if (version) {\n expectValidVersion(version, true);\n }\n});\n\ntest('getVisualStudioVersion() is valid', async () => {\n const version = await versionUtils.getVisualStudioVersion();\n expectValidVersion(version, false);\n});\n\ntest('getVersionOfNpmPackage() of empty string is null', async () => {\n const version = await versionUtils.getVersionOfNpmPackage('');\n expect(version).toBeNull();\n});\n\ntest('getVersionOfNpmPackage() of invalid package is null', async () => {\n const version = await versionUtils.getVersionOfNpmPackage('invalidpackage');\n expect(version).toBeNull();\n});\n\ntest('getVersionOfNpmPackage() of valid package is valid', async () => {\n const version = await versionUtils.getVersionOfNpmPackage('jest');\n expectValidVersion(version, true);\n});\n\ntest('getVersionsOfNuGetPackages() of valid package in packages.config is valid', async () => {\n const projectFile = path.resolve(\n __dirname,\n 'projects/UsesPackagesConfig/UsesPackagesConfig.vcxproj',\n );\n const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [\n 'Microsoft.Windows.CppWinRT',\n ]);\n expect(versions).not.toBeNull();\n expectValidVersion(versions['Microsoft.Windows.CppWinRT'], false);\n});\n\ntest('getVersionsOfNuGetPackages() of invalid package in packages.config is invalid', async () => {\n const projectFile = path.resolve(\n __dirname,\n 'projects/UsesPackagesConfig/UsesPackagesConfig.vcxproj',\n );\n const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [\n 'Invalid.Package',\n ]);\n expect(versions).toStrictEqual({});\n});\n\ntest('getVersionsOfNuGetPackages() of valid package in project is valid', async () => {\n const projectFile = path.resolve(\n __dirname,\n 'projects/UsesPackageReference/UsesPackageReference.csproj',\n );\n const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [\n 'Microsoft.NETCore.UniversalWindowsPlatform',\n ]);\n expect(versions).not.toBeNull();\n expectValidVersion(\n versions['Microsoft.NETCore.UniversalWindowsPlatform'],\n false,\n );\n});\n\ntest('getVersionsOfNuGetPackages() of invalid package in project is invalid', async () => {\n const projectFile = path.resolve(\n __dirname,\n 'projects/UsesPackageReference/UsesPackageReference.csproj',\n );\n const versions = await versionUtils.getVersionsOfNuGetPackages(projectFile, [\n 'Invalid.Package',\n ]);\n expect(versions).toStrictEqual({});\n});\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Gets a telemetry-safe stable device ID.
|
|
8
|
+
* @returns A telemetry-safe stable device ID.
|
|
9
|
+
*/
|
|
10
|
+
export declare function deviceId(): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the device locale.
|
|
13
|
+
* @returns The device locale.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deviceLocale(): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the device's number of CPUs.
|
|
18
|
+
* @returns The device's number of CPUs.
|
|
19
|
+
*/
|
|
20
|
+
export declare function deviceNumCPUs(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the device's total memory in bytes.
|
|
23
|
+
* @returns The device's total memory in bytes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function deviceTotalMemory(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the free space of the give drive in bytes.
|
|
28
|
+
* @param drivePath A path on the drive to check.
|
|
29
|
+
* @returns The free space of the give drive in bytes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deviceDiskFreeSpace(drivePath?: string | null): number;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the telemetry sample rate.
|
|
34
|
+
* @returns The telemetry sample rate.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sampleRate(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Gets whether or not telemetry events are captured when running in CI.
|
|
39
|
+
* @returns Whether or not telemetry events are captured when running in CI.
|
|
40
|
+
*/
|
|
41
|
+
export declare function captureCI(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the whether the process is currently running in CI.
|
|
44
|
+
* @returns Whether the process is currently running in CI.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isCI(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the type of CI the process is running under.
|
|
49
|
+
* @returns The type of CI the process is running under.
|
|
50
|
+
*/
|
|
51
|
+
export declare function ciType(): string;
|
|
52
|
+
/**
|
|
53
|
+
* Gets whether the process is running on a Microsoft owned machine.
|
|
54
|
+
* @returns Whether the process is running on a Microsoft owned machine.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isMsftInternal(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Gets whether the process is running as part of our CLI tests.
|
|
59
|
+
* @returns Whether the process is running as part of our CLI tests.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isCliTest(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Gets a stable session ID for correlating telemetry events.
|
|
64
|
+
* @returns A stable session ID for correlating telemetry events.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getSessionId(): string;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.getSessionId = exports.isCliTest = exports.isMsftInternal = exports.ciType = exports.isCI = exports.captureCI = exports.sampleRate = exports.deviceDiskFreeSpace = exports.deviceTotalMemory = exports.deviceNumCPUs = exports.deviceLocale = exports.deviceId = void 0;
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const os_1 = require("os");
|
|
14
|
+
const ci_info_1 = __importDefault(require("ci-info"));
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
const node_machine_id_1 = require("node-machine-id");
|
|
17
|
+
const os_locale_1 = __importDefault(require("os-locale"));
|
|
18
|
+
/**
|
|
19
|
+
* Gets a telemetry-safe stable device ID.
|
|
20
|
+
* @returns A telemetry-safe stable device ID.
|
|
21
|
+
*/
|
|
22
|
+
async function deviceId() {
|
|
23
|
+
return await (0, node_machine_id_1.machineId)(false);
|
|
24
|
+
}
|
|
25
|
+
exports.deviceId = deviceId;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the device locale.
|
|
28
|
+
* @returns The device locale.
|
|
29
|
+
*/
|
|
30
|
+
async function deviceLocale() {
|
|
31
|
+
return await (0, os_locale_1.default)();
|
|
32
|
+
}
|
|
33
|
+
exports.deviceLocale = deviceLocale;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the device's number of CPUs.
|
|
36
|
+
* @returns The device's number of CPUs.
|
|
37
|
+
*/
|
|
38
|
+
function deviceNumCPUs() {
|
|
39
|
+
return (0, os_1.cpus)().length;
|
|
40
|
+
}
|
|
41
|
+
exports.deviceNumCPUs = deviceNumCPUs;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the device's total memory in bytes.
|
|
44
|
+
* @returns The device's total memory in bytes.
|
|
45
|
+
*/
|
|
46
|
+
function deviceTotalMemory() {
|
|
47
|
+
return (0, os_1.totalmem)();
|
|
48
|
+
}
|
|
49
|
+
exports.deviceTotalMemory = deviceTotalMemory;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the free space of the give drive in bytes.
|
|
52
|
+
* @param drivePath A path on the drive to check.
|
|
53
|
+
* @returns The free space of the give drive in bytes.
|
|
54
|
+
*/
|
|
55
|
+
function deviceDiskFreeSpace(drivePath) {
|
|
56
|
+
try {
|
|
57
|
+
const out = (0, child_process_1.execSync)(`dir /-C ${drivePath !== null && drivePath !== void 0 ? drivePath : process.cwd()}`)
|
|
58
|
+
.toString()
|
|
59
|
+
.split('\r\n');
|
|
60
|
+
const line = out[out.length - 2];
|
|
61
|
+
const result = line.match(/(\d+) [^\d]+(\d+) /);
|
|
62
|
+
if (result && result.length > 2) {
|
|
63
|
+
return Number(result[2]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (_a) { }
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
exports.deviceDiskFreeSpace = deviceDiskFreeSpace;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the telemetry sample rate.
|
|
72
|
+
* @returns The telemetry sample rate.
|
|
73
|
+
*/
|
|
74
|
+
function sampleRate() {
|
|
75
|
+
return 100;
|
|
76
|
+
}
|
|
77
|
+
exports.sampleRate = sampleRate;
|
|
78
|
+
/**
|
|
79
|
+
* Gets whether or not telemetry events are captured when running in CI.
|
|
80
|
+
* @returns Whether or not telemetry events are captured when running in CI.
|
|
81
|
+
*/
|
|
82
|
+
function captureCI() {
|
|
83
|
+
// Only capture events in CI if running tests
|
|
84
|
+
return isCliTest();
|
|
85
|
+
}
|
|
86
|
+
exports.captureCI = captureCI;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the whether the process is currently running in CI.
|
|
89
|
+
* @returns Whether the process is currently running in CI.
|
|
90
|
+
*/
|
|
91
|
+
function isCI() {
|
|
92
|
+
return ci_info_1.default.isCI;
|
|
93
|
+
}
|
|
94
|
+
exports.isCI = isCI;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the type of CI the process is running under.
|
|
97
|
+
* @returns The type of CI the process is running under.
|
|
98
|
+
*/
|
|
99
|
+
function ciType() {
|
|
100
|
+
var _a;
|
|
101
|
+
return ci_info_1.default.isCI ? (_a = ci_info_1.default.name) !== null && _a !== void 0 ? _a : 'Unknown' : 'None';
|
|
102
|
+
}
|
|
103
|
+
exports.ciType = ciType;
|
|
104
|
+
/**
|
|
105
|
+
* Gets whether the process is running on a Microsoft owned machine.
|
|
106
|
+
* @returns Whether the process is running on a Microsoft owned machine.
|
|
107
|
+
*/
|
|
108
|
+
function isMsftInternal() {
|
|
109
|
+
return (process.env.UserDNSDomain !== undefined &&
|
|
110
|
+
process.env.UserDNSDomain.toLowerCase().endsWith('corp.microsoft.com'));
|
|
111
|
+
}
|
|
112
|
+
exports.isMsftInternal = isMsftInternal;
|
|
113
|
+
/**
|
|
114
|
+
* Gets whether the process is running as part of our CLI tests.
|
|
115
|
+
* @returns Whether the process is running as part of our CLI tests.
|
|
116
|
+
*/
|
|
117
|
+
function isCliTest() {
|
|
118
|
+
return (process.env.RNW_CLI_TEST !== undefined &&
|
|
119
|
+
process.env.RNW_CLI_TEST.toLowerCase().trim() === 'true');
|
|
120
|
+
}
|
|
121
|
+
exports.isCliTest = isCliTest;
|
|
122
|
+
let sessionId;
|
|
123
|
+
/**
|
|
124
|
+
* Gets a stable session ID for correlating telemetry events.
|
|
125
|
+
* @returns A stable session ID for correlating telemetry events.
|
|
126
|
+
*/
|
|
127
|
+
function getSessionId() {
|
|
128
|
+
return (sessionId !== null && sessionId !== void 0 ? sessionId : (sessionId = (0, crypto_1.randomBytes)(16).toString('hex').padStart(32, '0')));
|
|
129
|
+
}
|
|
130
|
+
exports.getSessionId = getSessionId;
|
|
131
|
+
//# sourceMappingURL=basePropUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basePropUtils.js","sourceRoot":"","sources":["../../src/utils/basePropUtils.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,iDAAuC;AACvC,2BAAkC;AAElC,sDAAyB;AACzB,mCAAmC;AACnC,qDAA0C;AAC1C,0DAAiC;AAEjC;;;GAGG;AACI,KAAK,UAAU,QAAQ;IAC5B,OAAO,MAAM,IAAA,2BAAS,EAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAFD,4BAEC;AAED;;;GAGG;AACI,KAAK,UAAU,YAAY;IAChC,OAAO,MAAM,IAAA,mBAAQ,GAAE,CAAC;AAC1B,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,aAAa;IAC3B,OAAO,IAAA,SAAI,GAAE,CAAC,MAAM,CAAC;AACvB,CAAC;AAFD,sCAEC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,aAAQ,GAAE,CAAC;AACpB,CAAC;AAFD,8CAEC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,SAAyB;IAC3D,IAAI;QACF,MAAM,GAAG,GAAG,IAAA,wBAAQ,EAAC,WAAW,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,OAAO,CAAC,GAAG,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AAE,CAAC,IAAI,EAAE,KAAK,MAAM,CACzD,CAAC;AACJ,CAAC;AALD,8BAKC;AAED,IAAI,SAA6B,CAAC;AAElC;;;GAGG;AACH,SAAgB,YAAY;IAC1B,OAAO,CACL,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,CAAC,SAAS,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC;AAJD,oCAIC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport {execSync} from 'child_process';\nimport {totalmem, cpus} from 'os';\n\nimport ci from 'ci-info';\nimport {randomBytes} from 'crypto';\nimport {machineId} from 'node-machine-id';\nimport osLocale from 'os-locale';\n\n/**\n * Gets a telemetry-safe stable device ID.\n * @returns A telemetry-safe stable device ID.\n */\nexport async function deviceId(): Promise<string> {\n return await machineId(false);\n}\n\n/**\n * Gets the device locale.\n * @returns The device locale.\n */\nexport async function deviceLocale(): Promise<string> {\n return await osLocale();\n}\n\n/**\n * Gets the device's number of CPUs.\n * @returns The device's number of CPUs.\n */\nexport function deviceNumCPUs(): number {\n return cpus().length;\n}\n\n/**\n * Gets the device's total memory in bytes.\n * @returns The device's total memory in bytes.\n */\nexport function deviceTotalMemory(): number {\n return totalmem();\n}\n\n/**\n * Gets the free space of the give drive in bytes.\n * @param drivePath A path on the drive to check.\n * @returns The free space of the give drive in bytes.\n */\nexport function deviceDiskFreeSpace(drivePath?: string | null): number {\n try {\n const out = execSync(`dir /-C ${drivePath ?? process.cwd()}`)\n .toString()\n .split('\\r\\n');\n const line = out[out.length - 2];\n const result = line.match(/(\\d+) [^\\d]+(\\d+) /);\n if (result && result.length > 2) {\n return Number(result[2]);\n }\n } catch {}\n return -1;\n}\n\n/**\n * Gets the telemetry sample rate.\n * @returns The telemetry sample rate.\n */\nexport function sampleRate(): number {\n return 100;\n}\n\n/**\n * Gets whether or not telemetry events are captured when running in CI.\n * @returns Whether or not telemetry events are captured when running in CI.\n */\nexport function captureCI(): boolean {\n // Only capture events in CI if running tests\n return isCliTest();\n}\n\n/**\n * Gets the whether the process is currently running in CI.\n * @returns Whether the process is currently running in CI.\n */\nexport function isCI(): boolean {\n return ci.isCI;\n}\n\n/**\n * Gets the type of CI the process is running under.\n * @returns The type of CI the process is running under.\n */\nexport function ciType(): string {\n return ci.isCI ? ci.name ?? 'Unknown' : 'None';\n}\n\n/**\n * Gets whether the process is running on a Microsoft owned machine.\n * @returns Whether the process is running on a Microsoft owned machine.\n */\nexport function isMsftInternal(): boolean {\n return (\n process.env.UserDNSDomain !== undefined &&\n process.env.UserDNSDomain.toLowerCase().endsWith('corp.microsoft.com')\n );\n}\n\n/**\n * Gets whether the process is running as part of our CLI tests.\n * @returns Whether the process is running as part of our CLI tests.\n */\nexport function isCliTest(): boolean {\n return (\n process.env.RNW_CLI_TEST !== undefined &&\n process.env.RNW_CLI_TEST.toLowerCase().trim() === 'true'\n );\n}\n\nlet sessionId: string | undefined;\n\n/**\n * Gets a stable session ID for correlating telemetry events.\n * @returns A stable session ID for correlating telemetry events.\n */\nexport function getSessionId(): string {\n return (\n sessionId ?? (sessionId = randomBytes(16).toString('hex').padStart(32, '0'))\n );\n}\n"]}
|
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
* @format
|
|
5
5
|
*/
|
|
6
|
+
import * as appInsights from 'applicationinsights';
|
|
6
7
|
export declare const CodedErrors: {
|
|
7
8
|
Success: number;
|
|
9
|
+
Unknown: number;
|
|
8
10
|
UnsupportedReactNativeVersion: number;
|
|
9
11
|
UserCancel: number;
|
|
10
12
|
NoReactNativeFound: number;
|
|
11
|
-
|
|
13
|
+
NoPackageJson: number;
|
|
12
14
|
NoLatestReactNativeWindows: number;
|
|
13
15
|
NoAutoMatchingReactNativeWindows: number;
|
|
14
16
|
IncompatibleOptions: number;
|
|
@@ -19,12 +21,6 @@ export declare const CodedErrors: {
|
|
|
19
21
|
CopyProjectTemplateNoSourcePath: number;
|
|
20
22
|
CopyProjectTemplateNoDestPath: number;
|
|
21
23
|
CopyProjectTemplateNoProjectName: number;
|
|
22
|
-
NoWindowsConfig: number;
|
|
23
|
-
IncompleteConfig: number;
|
|
24
|
-
InvalidConfig: number;
|
|
25
|
-
NeedAutolinking: number;
|
|
26
|
-
AddProjectToSolution: number;
|
|
27
|
-
Autolinking: number;
|
|
28
24
|
MinSDKVersionNotMet: number;
|
|
29
25
|
BadSDKVersionFormat: number;
|
|
30
26
|
NoSDK: number;
|
|
@@ -45,7 +41,12 @@ export declare const CodedErrors: {
|
|
|
45
41
|
UninstallAppOnDeviceFailure: number;
|
|
46
42
|
DeployRecipeFailure: number;
|
|
47
43
|
AppStartupFailure: number;
|
|
48
|
-
|
|
44
|
+
NoWindowsConfig: number;
|
|
45
|
+
IncompleteConfig: number;
|
|
46
|
+
InvalidConfig: number;
|
|
47
|
+
NeedAutolinking: number;
|
|
48
|
+
AddProjectToSolution: number;
|
|
49
|
+
Autolinking: number;
|
|
49
50
|
};
|
|
50
51
|
export declare type CodedErrorType = keyof typeof CodedErrors;
|
|
51
52
|
/**
|
|
@@ -56,6 +57,24 @@ export declare type CodedErrorType = keyof typeof CodedErrors;
|
|
|
56
57
|
* @param data any additional metadata that is safe to collect for telemetry purposes.
|
|
57
58
|
*/
|
|
58
59
|
export declare class CodedError extends Error {
|
|
60
|
+
readonly type: CodedErrorType;
|
|
59
61
|
readonly data?: Record<string, any> | undefined;
|
|
60
62
|
constructor(type: CodedErrorType, message: string, data?: Record<string, any> | undefined);
|
|
61
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Tries to parse an error code out of an error message.
|
|
66
|
+
* @param msg An error message to process.
|
|
67
|
+
* @returns The parsed error code.
|
|
68
|
+
*/
|
|
69
|
+
export declare function tryGetErrorCode(msg: string): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Sanitize an error message by anonymizing any paths that appear between quotes (''), brackets ([]), or double quotes ("").
|
|
72
|
+
* @param msg The error message to sanitize.
|
|
73
|
+
* @return The message with any paths anonymized.
|
|
74
|
+
*/
|
|
75
|
+
export declare function sanitizeErrorMessage(msg: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Sanitizes an error stack frame.
|
|
78
|
+
* @param frame
|
|
79
|
+
*/
|
|
80
|
+
export declare function sanitizeErrorStackFrame(frame: appInsights.Contracts.StackFrame): void;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.sanitizeErrorStackFrame = exports.sanitizeErrorMessage = exports.tryGetErrorCode = exports.CodedError = exports.CodedErrors = void 0;
|
|
28
|
+
const sanitizeUtils = __importStar(require("./sanitizeUtils"));
|
|
29
|
+
// Note: All CLI commands will set process.exitCode to the numerical value of
|
|
30
|
+
// a thrown CodedError. However node reserves codes 1-192 as per:
|
|
31
|
+
// https://nodejs.org/api/process.html#process_exit_codes so we shouldn't
|
|
32
|
+
// override those as other tools may be monitoring the error code
|
|
33
|
+
exports.CodedErrors = {
|
|
34
|
+
Success: 0,
|
|
35
|
+
Unknown: -1,
|
|
36
|
+
// init
|
|
37
|
+
UnsupportedReactNativeVersion: 1000,
|
|
38
|
+
UserCancel: 1001,
|
|
39
|
+
NoReactNativeFound: 1002,
|
|
40
|
+
NoPackageJson: 1003,
|
|
41
|
+
NoLatestReactNativeWindows: 1004,
|
|
42
|
+
NoAutoMatchingReactNativeWindows: 1005,
|
|
43
|
+
IncompatibleOptions: 1006,
|
|
44
|
+
NoReactNativeDependencies: 1007,
|
|
45
|
+
NoMatchingPackageVersion: 1008,
|
|
46
|
+
// run-windows
|
|
47
|
+
NoSolution: 2000,
|
|
48
|
+
// Project generation
|
|
49
|
+
NoPropertyInProject: 2100,
|
|
50
|
+
CopyProjectTemplateNoSourcePath: 2101,
|
|
51
|
+
CopyProjectTemplateNoDestPath: 2102,
|
|
52
|
+
CopyProjectTemplateNoProjectName: 2103,
|
|
53
|
+
// SDK requirements
|
|
54
|
+
MinSDKVersionNotMet: 2200,
|
|
55
|
+
BadSDKVersionFormat: 2201,
|
|
56
|
+
NoSDK: 2202,
|
|
57
|
+
// Build
|
|
58
|
+
NoMSBuild: 2300,
|
|
59
|
+
NoVSWhere: 2301,
|
|
60
|
+
MSBuildError: 2302,
|
|
61
|
+
// Deploy
|
|
62
|
+
NoAppPackage: 2400,
|
|
63
|
+
NoAppxManifest: 2401,
|
|
64
|
+
NoDevice: 2402,
|
|
65
|
+
AppDidNotDeploy: 2403,
|
|
66
|
+
InvalidDevicesOutput: 2404,
|
|
67
|
+
RemoveOldAppVersionFailure: 2405,
|
|
68
|
+
EnableDevModeFailure: 2406,
|
|
69
|
+
InstallAppFailure: 2407,
|
|
70
|
+
InstallAppDependenciesFailure: 2408,
|
|
71
|
+
CheckNetIsolationFailure: 2409,
|
|
72
|
+
InstallAppToDeviceFailure: 2410,
|
|
73
|
+
UninstallAppOnDeviceFailure: 2411,
|
|
74
|
+
DeployRecipeFailure: 2412,
|
|
75
|
+
// Launch
|
|
76
|
+
AppStartupFailure: 2500,
|
|
77
|
+
// autolink-windows
|
|
78
|
+
NoWindowsConfig: 3000,
|
|
79
|
+
IncompleteConfig: 3001,
|
|
80
|
+
InvalidConfig: 3002,
|
|
81
|
+
NeedAutolinking: 3003,
|
|
82
|
+
AddProjectToSolution: 3004,
|
|
83
|
+
Autolinking: 3005,
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Represents an error whose message might contain user-originating content,
|
|
87
|
+
* therefore when transmitting telemetry, only the type should be sent.
|
|
88
|
+
* @param type a stable ID identifying the type of error.
|
|
89
|
+
* @param message the error text. This should only be used for display to the user.
|
|
90
|
+
* @param data any additional metadata that is safe to collect for telemetry purposes.
|
|
91
|
+
*/
|
|
92
|
+
class CodedError extends Error {
|
|
93
|
+
constructor(type, message, data) {
|
|
94
|
+
super(message);
|
|
95
|
+
this.type = type;
|
|
96
|
+
this.data = data;
|
|
97
|
+
this.name = type;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CodedError = CodedError;
|
|
101
|
+
/**
|
|
102
|
+
* Tries to parse an error code out of an error message.
|
|
103
|
+
* @param msg An error message to process.
|
|
104
|
+
* @returns The parsed error code.
|
|
105
|
+
*/
|
|
106
|
+
function tryGetErrorCode(msg) {
|
|
107
|
+
const errorRegEx = /error (\w+\d+):/gi;
|
|
108
|
+
const m = errorRegEx.exec(msg);
|
|
109
|
+
return m ? m[1] : undefined;
|
|
110
|
+
}
|
|
111
|
+
exports.tryGetErrorCode = tryGetErrorCode;
|
|
112
|
+
/**
|
|
113
|
+
* Sanitize an error message by anonymizing any paths that appear between quotes (''), brackets ([]), or double quotes ("").
|
|
114
|
+
* @param msg The error message to sanitize.
|
|
115
|
+
* @return The message with any paths anonymized.
|
|
116
|
+
*/
|
|
117
|
+
function sanitizeErrorMessage(msg) {
|
|
118
|
+
const cpuThreadId = /^\d+(:\d+)?>/g;
|
|
119
|
+
msg = msg.replace(cpuThreadId, '');
|
|
120
|
+
const parts = msg.split(/['[\]"]/g);
|
|
121
|
+
const clean = [];
|
|
122
|
+
const pathRegEx = /(['["]?)([A-Za-z]:|\\)[\\/]([^<>:;,?"*\t\r\n|/\\]+[\\/])+([^<>:;,?"*\t\r\n|]+\/?(['["]?))/gi;
|
|
123
|
+
for (const part of parts) {
|
|
124
|
+
if (pathRegEx.test(part)) {
|
|
125
|
+
pathRegEx.lastIndex = -1;
|
|
126
|
+
let matches;
|
|
127
|
+
let noPath = '';
|
|
128
|
+
let last = 0;
|
|
129
|
+
while ((matches = pathRegEx.exec(part))) {
|
|
130
|
+
noPath +=
|
|
131
|
+
part.substr(last, matches.index - last) +
|
|
132
|
+
sanitizeUtils.getAnonymizedPath(matches[0]);
|
|
133
|
+
last = matches.index + matches[0].length;
|
|
134
|
+
}
|
|
135
|
+
if (noPath !== '') {
|
|
136
|
+
clean.push(noPath);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (part !== '') {
|
|
140
|
+
clean.push(part);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return clean.join('').trim();
|
|
144
|
+
}
|
|
145
|
+
exports.sanitizeErrorMessage = sanitizeErrorMessage;
|
|
146
|
+
/**
|
|
147
|
+
* Sanitizes an error stack frame.
|
|
148
|
+
* @param frame
|
|
149
|
+
*/
|
|
150
|
+
function sanitizeErrorStackFrame(frame) {
|
|
151
|
+
const parens = frame.method.indexOf('(');
|
|
152
|
+
if (parens !== -1) {
|
|
153
|
+
// case 1: method === 'methodName (rootOfThePath'
|
|
154
|
+
frame.method = frame.method.substr(0, parens).trim();
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// case 2: method === <no_method> or something without '(', fileName is full path
|
|
158
|
+
}
|
|
159
|
+
// anonymize the filename
|
|
160
|
+
frame.fileName = sanitizeUtils.getAnonymizedPath(frame.fileName);
|
|
161
|
+
frame.assembly = '';
|
|
162
|
+
}
|
|
163
|
+
exports.sanitizeErrorStackFrame = sanitizeErrorStackFrame;
|
|
164
|
+
//# sourceMappingURL=errorUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorUtils.js","sourceRoot":"","sources":["../../src/utils/errorUtils.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;AAIH,+DAAiD;AAEjD,6EAA6E;AAC7E,iEAAiE;AACjE,yEAAyE;AACzE,iEAAiE;AAEpD,QAAA,WAAW,GAAG;IACzB,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC,CAAC;IAEX,OAAO;IACP,6BAA6B,EAAE,IAAI;IACnC,UAAU,EAAE,IAAI;IAChB,kBAAkB,EAAE,IAAI;IACxB,aAAa,EAAE,IAAI;IACnB,0BAA0B,EAAE,IAAI;IAChC,gCAAgC,EAAE,IAAI;IACtC,mBAAmB,EAAE,IAAI;IACzB,yBAAyB,EAAE,IAAI;IAC/B,wBAAwB,EAAE,IAAI;IAE9B,cAAc;IACd,UAAU,EAAE,IAAI;IAChB,qBAAqB;IACrB,mBAAmB,EAAE,IAAI;IACzB,+BAA+B,EAAE,IAAI;IACrC,6BAA6B,EAAE,IAAI;IACnC,gCAAgC,EAAE,IAAI;IACtC,mBAAmB;IACnB,mBAAmB,EAAE,IAAI;IACzB,mBAAmB,EAAE,IAAI;IACzB,KAAK,EAAE,IAAI;IACX,QAAQ;IACR,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,IAAI;IAClB,SAAS;IACT,YAAY,EAAE,IAAI;IA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AAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;KACtD;SAAM;QACL,iFAAiF;KAClF;IACD,yBAAyB;IACzB,KAAK,CAAC,QAAQ,GAAG,aAAa,CAAC,iBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACjE,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;AACtB,CAAC;AAbD,0DAaC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport * as appInsights from 'applicationinsights';\n\nimport * as sanitizeUtils from './sanitizeUtils';\n\n// Note: All CLI commands will set process.exitCode to the numerical value of\n// a thrown CodedError. However node reserves codes 1-192 as per:\n// https://nodejs.org/api/process.html#process_exit_codes so we shouldn't\n// override those as other tools may be monitoring the error code\n\nexport const CodedErrors = {\n Success: 0,\n Unknown: -1,\n\n // init\n UnsupportedReactNativeVersion: 1000,\n UserCancel: 1001,\n NoReactNativeFound: 1002,\n NoPackageJson: 1003,\n NoLatestReactNativeWindows: 1004,\n NoAutoMatchingReactNativeWindows: 1005,\n IncompatibleOptions: 1006,\n NoReactNativeDependencies: 1007,\n NoMatchingPackageVersion: 1008,\n\n // run-windows\n NoSolution: 2000,\n // Project generation\n NoPropertyInProject: 2100,\n CopyProjectTemplateNoSourcePath: 2101,\n CopyProjectTemplateNoDestPath: 2102,\n CopyProjectTemplateNoProjectName: 2103,\n // SDK requirements\n MinSDKVersionNotMet: 2200,\n BadSDKVersionFormat: 2201,\n NoSDK: 2202,\n // Build\n NoMSBuild: 2300,\n NoVSWhere: 2301,\n MSBuildError: 2302,\n // Deploy\n NoAppPackage: 2400,\n NoAppxManifest: 2401,\n NoDevice: 2402,\n AppDidNotDeploy: 2403,\n InvalidDevicesOutput: 2404,\n RemoveOldAppVersionFailure: 2405,\n EnableDevModeFailure: 2406,\n InstallAppFailure: 2407,\n InstallAppDependenciesFailure: 2408,\n CheckNetIsolationFailure: 2409,\n InstallAppToDeviceFailure: 2410,\n UninstallAppOnDeviceFailure: 2411,\n DeployRecipeFailure: 2412,\n // Launch\n AppStartupFailure: 2500,\n\n // autolink-windows\n NoWindowsConfig: 3000,\n IncompleteConfig: 3001,\n InvalidConfig: 3002,\n NeedAutolinking: 3003,\n AddProjectToSolution: 3004,\n Autolinking: 3005,\n};\n\nexport type CodedErrorType = keyof typeof CodedErrors;\n\n/**\n * Represents an error whose message might contain user-originating content,\n * therefore when transmitting telemetry, only the type should be sent.\n * @param type a stable ID identifying the type of error.\n * @param message the error text. This should only be used for display to the user.\n * @param data any additional metadata that is safe to collect for telemetry purposes.\n */\nexport class CodedError extends Error {\n constructor(\n public readonly type: CodedErrorType,\n message: string,\n public readonly data?: Record<string, any>,\n ) {\n super(message);\n this.name = type;\n }\n}\n\n/**\n * Tries to parse an error code out of an error message.\n * @param msg An error message to process.\n * @returns The parsed error code.\n */\nexport function tryGetErrorCode(msg: string): string | undefined {\n const errorRegEx = /error (\\w+\\d+):/gi;\n const m = errorRegEx.exec(msg);\n return m ? m[1] : undefined;\n}\n\n/**\n * Sanitize an error message by anonymizing any paths that appear between quotes (''), brackets ([]), or double quotes (\"\").\n * @param msg The error message to sanitize.\n * @return The message with any paths anonymized.\n */\nexport function sanitizeErrorMessage(msg: string): string {\n const cpuThreadId = /^\\d+(:\\d+)?>/g;\n msg = msg.replace(cpuThreadId, '');\n const parts = msg.split(/['[\\]\"]/g);\n const clean = [];\n const pathRegEx =\n /(['[\"]?)([A-Za-z]:|\\\\)[\\\\/]([^<>:;,?\"*\\t\\r\\n|/\\\\]+[\\\\/])+([^<>:;,?\"*\\t\\r\\n|]+\\/?(['[\"]?))/gi;\n for (const part of parts) {\n if (pathRegEx.test(part)) {\n pathRegEx.lastIndex = -1;\n let matches: RegExpExecArray | null;\n let noPath = '';\n let last = 0;\n while ((matches = pathRegEx.exec(part))) {\n noPath +=\n part.substr(last, matches!.index - last) +\n sanitizeUtils.getAnonymizedPath(matches[0]);\n last = matches!.index + matches![0].length;\n }\n if (noPath !== '') {\n clean.push(noPath);\n }\n } else if (part !== '') {\n clean.push(part);\n }\n }\n return clean.join('').trim();\n}\n\n/**\n * Sanitizes an error stack frame.\n * @param frame\n */\nexport function sanitizeErrorStackFrame(\n frame: appInsights.Contracts.StackFrame,\n): void {\n const parens = frame.method.indexOf('(');\n if (parens !== -1) {\n // case 1: method === 'methodName (rootOfThePath'\n frame.method = frame.method.substr(0, parens).trim();\n } else {\n // case 2: method === <no_method> or something without '(', fileName is full path\n }\n // anonymize the filename\n frame.fileName = sanitizeUtils.getAnonymizedPath(frame.fileName);\n frame.assembly = '';\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
export declare type OptionSanitizer = (key: string, value: any) => any;
|
|
7
|
+
export declare type YargsOptionsType = Record<string, any>;
|
|
8
|
+
export interface CommanderOptionsType extends Record<string, any> {
|
|
9
|
+
logging?: boolean;
|
|
10
|
+
telemetry?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Converts a raw Commander arg name ('--no-bad-dog') into an options property name ('badDog').
|
|
14
|
+
* @param name The raw Commander arg name.
|
|
15
|
+
* @returns The options name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function commanderNameToOptionName(name: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Converts a yargs-parsed options object into an options object suitable for telemetry.
|
|
20
|
+
* @param options The options object as parsed by yargs.
|
|
21
|
+
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
22
|
+
* @returns An options object suitable for telemetry.
|
|
23
|
+
*/
|
|
24
|
+
export declare function yargsOptionsToOptions(options: YargsOptionsType, sanitizer?: OptionSanitizer): Record<string, any>;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a Commander-parsed options object into an options object suitable for telemetry.
|
|
27
|
+
* @param options The options object as parsed by Commander.
|
|
28
|
+
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
29
|
+
* @returns An options object suitable for telemetry.
|
|
30
|
+
*/
|
|
31
|
+
export declare function commanderOptionsToOptions(options: CommanderOptionsType, sanitizer?: OptionSanitizer): Record<string, any>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks whether the given command-line args contains the given option key.
|
|
34
|
+
* @param key The option key to look for.
|
|
35
|
+
* @param argv The raw command-line args.
|
|
36
|
+
* @returns Whether the given command-line args contains the given option key.
|
|
37
|
+
*/
|
|
38
|
+
export declare function argsContainsOption(key: string, argv: string[]): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Filters down a given set of options to only include those that were present in the command-line args.
|
|
41
|
+
* @param options The full set of options.
|
|
42
|
+
* @param argv The raw command-line args.
|
|
43
|
+
* @returns The filtered set of options.
|
|
44
|
+
*/
|
|
45
|
+
export declare function optionsToArgs(options: Record<string, any>, argv: string[]): Record<string, any>;
|