@react-native-windows/telemetry 0.73.1 → 0.74.0-preview.1
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/e2etest/telemetry.test.d.ts +28 -28
- package/lib-commonjs/e2etest/telemetry.test.js +496 -496
- package/lib-commonjs/index.d.ts +11 -11
- package/lib-commonjs/index.js +26 -26
- package/lib-commonjs/telemetry.d.ts +84 -84
- package/lib-commonjs/telemetry.js +370 -370
- package/lib-commonjs/telemetry.js.map +1 -1
- package/lib-commonjs/test/basePropUtils.test.d.ts +7 -7
- package/lib-commonjs/test/basePropUtils.test.js +137 -137
- package/lib-commonjs/test/errorUtils.test.d.ts +7 -7
- package/lib-commonjs/test/errorUtils.test.js +159 -159
- package/lib-commonjs/test/projectUtils.test.d.ts +7 -7
- package/lib-commonjs/test/projectUtils.test.js +87 -87
- package/lib-commonjs/test/sanitizeUtils.test.d.ts +7 -7
- package/lib-commonjs/test/sanitizeUtils.test.js +97 -97
- package/lib-commonjs/test/versionUtils.test.d.ts +7 -7
- package/lib-commonjs/test/versionUtils.test.js +114 -114
- package/lib-commonjs/utils/basePropUtils.d.ts +81 -81
- package/lib-commonjs/utils/basePropUtils.js +173 -173
- package/lib-commonjs/utils/errorUtils.d.ts +87 -87
- package/lib-commonjs/utils/errorUtils.js +178 -178
- package/lib-commonjs/utils/optionUtils.d.ts +45 -45
- package/lib-commonjs/utils/optionUtils.js +95 -95
- package/lib-commonjs/utils/projectUtils.d.ts +50 -50
- package/lib-commonjs/utils/projectUtils.js +186 -186
- package/lib-commonjs/utils/sanitizeUtils.d.ts +12 -12
- package/lib-commonjs/utils/sanitizeUtils.js +81 -81
- package/lib-commonjs/utils/versionUtils.d.ts +38 -38
- package/lib-commonjs/utils/versionUtils.js +155 -155
- package/package.json +14 -16
|
@@ -1,179 +1,179 @@
|
|
|
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
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
-
if (mod && mod.__esModule) return mod;
|
|
25
|
-
var result = {};
|
|
26
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
-
__setModuleDefault(result, mod);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.sanitizeErrorStackFrame = exports.sanitizeErrorMessage = exports.tryGetErrorCode = exports.CodedError = exports.CodedErrors = void 0;
|
|
32
|
-
const sanitizeUtils = __importStar(require("./sanitizeUtils"));
|
|
33
|
-
// Note: All CLI commands will set process.exitCode to the numerical value of
|
|
34
|
-
// a thrown CodedError. However node reserves codes 1-192 as per:
|
|
35
|
-
// https://nodejs.org/api/process.html#process_exit_codes so we shouldn't
|
|
36
|
-
// override those as other tools may be monitoring the error code
|
|
37
|
-
exports.CodedErrors = {
|
|
38
|
-
Success: 0,
|
|
39
|
-
Unknown: -1,
|
|
40
|
-
// react-native-windows-init
|
|
41
|
-
UnsupportedReactNativeVersion: 1000,
|
|
42
|
-
UserCancel: 1001,
|
|
43
|
-
NoReactNativeFound: 1002,
|
|
44
|
-
NoPackageJson: 1003,
|
|
45
|
-
NoLatestReactNativeWindows: 1004,
|
|
46
|
-
NoAutoMatchingReactNativeWindows: 1005,
|
|
47
|
-
IncompatibleOptions: 1006,
|
|
48
|
-
NoReactNativeDependencies: 1007,
|
|
49
|
-
NoMatchingPackageVersion: 1008,
|
|
50
|
-
// run-windows
|
|
51
|
-
NoSolution: 2000,
|
|
52
|
-
// Project generation
|
|
53
|
-
NoPropertyInProject: 2100,
|
|
54
|
-
CopyProjectTemplateNoSourcePath: 2101,
|
|
55
|
-
CopyProjectTemplateNoDestPath: 2102,
|
|
56
|
-
CopyProjectTemplateNoProjectName: 2103,
|
|
57
|
-
// SDK requirements
|
|
58
|
-
MinSDKVersionNotMet: 2200,
|
|
59
|
-
BadSDKVersionFormat: 2201,
|
|
60
|
-
NoSDK: 2202,
|
|
61
|
-
// Build
|
|
62
|
-
NoMSBuild: 2300,
|
|
63
|
-
NoVSWhere: 2301,
|
|
64
|
-
MSBuildError: 2302,
|
|
65
|
-
// Deploy
|
|
66
|
-
NoAppPackage: 2400,
|
|
67
|
-
NoAppxManifest: 2401,
|
|
68
|
-
NoDevice: 2402,
|
|
69
|
-
AppDidNotDeploy: 2403,
|
|
70
|
-
InvalidDevicesOutput: 2404,
|
|
71
|
-
RemoveOldAppVersionFailure: 2405,
|
|
72
|
-
EnableDevModeFailure: 2406,
|
|
73
|
-
InstallAppFailure: 2407,
|
|
74
|
-
InstallAppDependenciesFailure: 2408,
|
|
75
|
-
CheckNetIsolationFailure: 2409,
|
|
76
|
-
InstallAppToDeviceFailure: 2410,
|
|
77
|
-
UninstallAppOnDeviceFailure: 2411,
|
|
78
|
-
DeployRecipeFailure: 2412,
|
|
79
|
-
// Launch
|
|
80
|
-
AppStartupFailure: 2500,
|
|
81
|
-
// autolink-windows
|
|
82
|
-
NoWindowsConfig: 3000,
|
|
83
|
-
IncompleteConfig: 3001,
|
|
84
|
-
InvalidConfig: 3002,
|
|
85
|
-
NeedAutolinking: 3003,
|
|
86
|
-
AddProjectToSolution: 3004,
|
|
87
|
-
Autolinking: 3005,
|
|
88
|
-
// codegen-windows
|
|
89
|
-
NeedCodegen: 4000,
|
|
90
|
-
InvalidCodegenConfig: 4001,
|
|
91
|
-
// init-windows
|
|
92
|
-
NoTemplatesFound: 5000,
|
|
93
|
-
NoDefaultTemplate: 5001,
|
|
94
|
-
InvalidTemplateName: 5002,
|
|
95
|
-
NoProjectName: 5003,
|
|
96
|
-
InvalidProjectName: 5004,
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Represents an error whose message might contain user-originating content,
|
|
100
|
-
* therefore when transmitting telemetry, only the type should be sent.
|
|
101
|
-
* @param type a stable ID identifying the type of error.
|
|
102
|
-
* @param message the error text. This should only be used for display to the user.
|
|
103
|
-
* @param data any additional metadata that is safe to collect for telemetry purposes.
|
|
104
|
-
*/
|
|
105
|
-
class CodedError extends Error {
|
|
106
|
-
constructor(type, message, data) {
|
|
107
|
-
super(message);
|
|
108
|
-
this.type = type;
|
|
109
|
-
this.data = data;
|
|
110
|
-
this.name = type;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.CodedError = CodedError;
|
|
114
|
-
/**
|
|
115
|
-
* Tries to parse an error code out of an error message.
|
|
116
|
-
* @param msg An error message to process.
|
|
117
|
-
* @returns The parsed error code.
|
|
118
|
-
*/
|
|
119
|
-
function tryGetErrorCode(msg) {
|
|
120
|
-
const errorRegEx = /error (\w+\d+):/gi;
|
|
121
|
-
const m = errorRegEx.exec(msg);
|
|
122
|
-
return m ? m[1] : undefined;
|
|
123
|
-
}
|
|
124
|
-
exports.tryGetErrorCode = tryGetErrorCode;
|
|
125
|
-
/**
|
|
126
|
-
* Sanitize an error message by anonymizing any paths that appear between quotes (''), brackets ([]), or double quotes ("").
|
|
127
|
-
* @param msg The error message to sanitize.
|
|
128
|
-
* @return The message with any paths anonymized.
|
|
129
|
-
*/
|
|
130
|
-
function sanitizeErrorMessage(msg) {
|
|
131
|
-
const msBuildErrorMessage = /^\d+:\d+>(.*)(\(\d+,\d+\)): error (\w+\d+): (.*)/g;
|
|
132
|
-
msg = msg.replace(msBuildErrorMessage, '[$1]$2: error $3: $4');
|
|
133
|
-
const cpuThreadId = /^\d+(:\d+)?>/g;
|
|
134
|
-
msg = msg.replace(cpuThreadId, '');
|
|
135
|
-
const parts = msg.split(/['[\]"]/g);
|
|
136
|
-
const clean = [];
|
|
137
|
-
const pathRegEx = /(['["]?)([A-Za-z]:|\\)[\\/]([^<>:;,?"*\t\r\n|/\\]+[\\/])+([^<>:;,?"*\t\r\n|]+\/?(['["]?))/gi;
|
|
138
|
-
for (const part of parts) {
|
|
139
|
-
if (pathRegEx.test(part)) {
|
|
140
|
-
pathRegEx.lastIndex = -1;
|
|
141
|
-
let matches;
|
|
142
|
-
let noPath = '';
|
|
143
|
-
let last = 0;
|
|
144
|
-
while ((matches = pathRegEx.exec(part))) {
|
|
145
|
-
noPath +=
|
|
146
|
-
part.substr(last, matches.index - last) +
|
|
147
|
-
sanitizeUtils.getAnonymizedPath(matches[0]);
|
|
148
|
-
last = matches.index + matches[0].length;
|
|
149
|
-
}
|
|
150
|
-
if (noPath !== '') {
|
|
151
|
-
clean.push(noPath);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (part !== '') {
|
|
155
|
-
clean.push(part);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return clean.join('').trim();
|
|
159
|
-
}
|
|
160
|
-
exports.sanitizeErrorMessage = sanitizeErrorMessage;
|
|
161
|
-
/**
|
|
162
|
-
* Sanitizes an error stack frame.
|
|
163
|
-
* @param frame
|
|
164
|
-
*/
|
|
165
|
-
function sanitizeErrorStackFrame(frame) {
|
|
166
|
-
const parens = frame.method.indexOf('(');
|
|
167
|
-
if (parens !== -1) {
|
|
168
|
-
// case 1: method === 'methodName (rootOfThePath'
|
|
169
|
-
frame.method = frame.method.substr(0, parens).trim();
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
// case 2: method === <no_method> or something without '(', fileName is full path
|
|
173
|
-
}
|
|
174
|
-
// anonymize the filename
|
|
175
|
-
frame.fileName = sanitizeUtils.getAnonymizedPath(frame.fileName);
|
|
176
|
-
frame.assembly = '';
|
|
177
|
-
}
|
|
178
|
-
exports.sanitizeErrorStackFrame = sanitizeErrorStackFrame;
|
|
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
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
+
if (mod && mod.__esModule) return mod;
|
|
25
|
+
var result = {};
|
|
26
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
+
__setModuleDefault(result, mod);
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.sanitizeErrorStackFrame = exports.sanitizeErrorMessage = exports.tryGetErrorCode = exports.CodedError = exports.CodedErrors = void 0;
|
|
32
|
+
const sanitizeUtils = __importStar(require("./sanitizeUtils"));
|
|
33
|
+
// Note: All CLI commands will set process.exitCode to the numerical value of
|
|
34
|
+
// a thrown CodedError. However node reserves codes 1-192 as per:
|
|
35
|
+
// https://nodejs.org/api/process.html#process_exit_codes so we shouldn't
|
|
36
|
+
// override those as other tools may be monitoring the error code
|
|
37
|
+
exports.CodedErrors = {
|
|
38
|
+
Success: 0,
|
|
39
|
+
Unknown: -1,
|
|
40
|
+
// react-native-windows-init
|
|
41
|
+
UnsupportedReactNativeVersion: 1000,
|
|
42
|
+
UserCancel: 1001,
|
|
43
|
+
NoReactNativeFound: 1002,
|
|
44
|
+
NoPackageJson: 1003,
|
|
45
|
+
NoLatestReactNativeWindows: 1004,
|
|
46
|
+
NoAutoMatchingReactNativeWindows: 1005,
|
|
47
|
+
IncompatibleOptions: 1006,
|
|
48
|
+
NoReactNativeDependencies: 1007,
|
|
49
|
+
NoMatchingPackageVersion: 1008,
|
|
50
|
+
// run-windows
|
|
51
|
+
NoSolution: 2000,
|
|
52
|
+
// Project generation
|
|
53
|
+
NoPropertyInProject: 2100,
|
|
54
|
+
CopyProjectTemplateNoSourcePath: 2101,
|
|
55
|
+
CopyProjectTemplateNoDestPath: 2102,
|
|
56
|
+
CopyProjectTemplateNoProjectName: 2103,
|
|
57
|
+
// SDK requirements
|
|
58
|
+
MinSDKVersionNotMet: 2200,
|
|
59
|
+
BadSDKVersionFormat: 2201,
|
|
60
|
+
NoSDK: 2202,
|
|
61
|
+
// Build
|
|
62
|
+
NoMSBuild: 2300,
|
|
63
|
+
NoVSWhere: 2301,
|
|
64
|
+
MSBuildError: 2302,
|
|
65
|
+
// Deploy
|
|
66
|
+
NoAppPackage: 2400,
|
|
67
|
+
NoAppxManifest: 2401,
|
|
68
|
+
NoDevice: 2402,
|
|
69
|
+
AppDidNotDeploy: 2403,
|
|
70
|
+
InvalidDevicesOutput: 2404,
|
|
71
|
+
RemoveOldAppVersionFailure: 2405,
|
|
72
|
+
EnableDevModeFailure: 2406,
|
|
73
|
+
InstallAppFailure: 2407,
|
|
74
|
+
InstallAppDependenciesFailure: 2408,
|
|
75
|
+
CheckNetIsolationFailure: 2409,
|
|
76
|
+
InstallAppToDeviceFailure: 2410,
|
|
77
|
+
UninstallAppOnDeviceFailure: 2411,
|
|
78
|
+
DeployRecipeFailure: 2412,
|
|
79
|
+
// Launch
|
|
80
|
+
AppStartupFailure: 2500,
|
|
81
|
+
// autolink-windows
|
|
82
|
+
NoWindowsConfig: 3000,
|
|
83
|
+
IncompleteConfig: 3001,
|
|
84
|
+
InvalidConfig: 3002,
|
|
85
|
+
NeedAutolinking: 3003,
|
|
86
|
+
AddProjectToSolution: 3004,
|
|
87
|
+
Autolinking: 3005,
|
|
88
|
+
// codegen-windows
|
|
89
|
+
NeedCodegen: 4000,
|
|
90
|
+
InvalidCodegenConfig: 4001,
|
|
91
|
+
// init-windows
|
|
92
|
+
NoTemplatesFound: 5000,
|
|
93
|
+
NoDefaultTemplate: 5001,
|
|
94
|
+
InvalidTemplateName: 5002,
|
|
95
|
+
NoProjectName: 5003,
|
|
96
|
+
InvalidProjectName: 5004,
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Represents an error whose message might contain user-originating content,
|
|
100
|
+
* therefore when transmitting telemetry, only the type should be sent.
|
|
101
|
+
* @param type a stable ID identifying the type of error.
|
|
102
|
+
* @param message the error text. This should only be used for display to the user.
|
|
103
|
+
* @param data any additional metadata that is safe to collect for telemetry purposes.
|
|
104
|
+
*/
|
|
105
|
+
class CodedError extends Error {
|
|
106
|
+
constructor(type, message, data) {
|
|
107
|
+
super(message);
|
|
108
|
+
this.type = type;
|
|
109
|
+
this.data = data;
|
|
110
|
+
this.name = type;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.CodedError = CodedError;
|
|
114
|
+
/**
|
|
115
|
+
* Tries to parse an error code out of an error message.
|
|
116
|
+
* @param msg An error message to process.
|
|
117
|
+
* @returns The parsed error code.
|
|
118
|
+
*/
|
|
119
|
+
function tryGetErrorCode(msg) {
|
|
120
|
+
const errorRegEx = /error (\w+\d+):/gi;
|
|
121
|
+
const m = errorRegEx.exec(msg);
|
|
122
|
+
return m ? m[1] : undefined;
|
|
123
|
+
}
|
|
124
|
+
exports.tryGetErrorCode = tryGetErrorCode;
|
|
125
|
+
/**
|
|
126
|
+
* Sanitize an error message by anonymizing any paths that appear between quotes (''), brackets ([]), or double quotes ("").
|
|
127
|
+
* @param msg The error message to sanitize.
|
|
128
|
+
* @return The message with any paths anonymized.
|
|
129
|
+
*/
|
|
130
|
+
function sanitizeErrorMessage(msg) {
|
|
131
|
+
const msBuildErrorMessage = /^\d+:\d+>(.*)(\(\d+,\d+\)): error (\w+\d+): (.*)/g;
|
|
132
|
+
msg = msg.replace(msBuildErrorMessage, '[$1]$2: error $3: $4');
|
|
133
|
+
const cpuThreadId = /^\d+(:\d+)?>/g;
|
|
134
|
+
msg = msg.replace(cpuThreadId, '');
|
|
135
|
+
const parts = msg.split(/['[\]"]/g);
|
|
136
|
+
const clean = [];
|
|
137
|
+
const pathRegEx = /(['["]?)([A-Za-z]:|\\)[\\/]([^<>:;,?"*\t\r\n|/\\]+[\\/])+([^<>:;,?"*\t\r\n|]+\/?(['["]?))/gi;
|
|
138
|
+
for (const part of parts) {
|
|
139
|
+
if (pathRegEx.test(part)) {
|
|
140
|
+
pathRegEx.lastIndex = -1;
|
|
141
|
+
let matches;
|
|
142
|
+
let noPath = '';
|
|
143
|
+
let last = 0;
|
|
144
|
+
while ((matches = pathRegEx.exec(part))) {
|
|
145
|
+
noPath +=
|
|
146
|
+
part.substr(last, matches.index - last) +
|
|
147
|
+
sanitizeUtils.getAnonymizedPath(matches[0]);
|
|
148
|
+
last = matches.index + matches[0].length;
|
|
149
|
+
}
|
|
150
|
+
if (noPath !== '') {
|
|
151
|
+
clean.push(noPath);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (part !== '') {
|
|
155
|
+
clean.push(part);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return clean.join('').trim();
|
|
159
|
+
}
|
|
160
|
+
exports.sanitizeErrorMessage = sanitizeErrorMessage;
|
|
161
|
+
/**
|
|
162
|
+
* Sanitizes an error stack frame.
|
|
163
|
+
* @param frame
|
|
164
|
+
*/
|
|
165
|
+
function sanitizeErrorStackFrame(frame) {
|
|
166
|
+
const parens = frame.method.indexOf('(');
|
|
167
|
+
if (parens !== -1) {
|
|
168
|
+
// case 1: method === 'methodName (rootOfThePath'
|
|
169
|
+
frame.method = frame.method.substr(0, parens).trim();
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// case 2: method === <no_method> or something without '(', fileName is full path
|
|
173
|
+
}
|
|
174
|
+
// anonymize the filename
|
|
175
|
+
frame.fileName = sanitizeUtils.getAnonymizedPath(frame.fileName);
|
|
176
|
+
frame.assembly = '';
|
|
177
|
+
}
|
|
178
|
+
exports.sanitizeErrorStackFrame = sanitizeErrorStackFrame;
|
|
179
179
|
//# sourceMappingURL=errorUtils.js.map
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
* @format
|
|
5
|
-
*/
|
|
6
|
-
export type OptionSanitizer = (key: string, value: any) => any;
|
|
7
|
-
export 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>;
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
export type OptionSanitizer = (key: string, value: any) => any;
|
|
7
|
+
export 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>;
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.optionsToArgs = exports.argsContainsOption = exports.commanderOptionsToOptions = exports.yargsOptionsToOptions = exports.commanderNameToOptionName = void 0;
|
|
9
|
-
const lodash_1 = require("lodash");
|
|
10
|
-
/**
|
|
11
|
-
* Converts a raw Commander arg name ('--no-bad-dog') into an options property name ('badDog').
|
|
12
|
-
* @param name The raw Commander arg name.
|
|
13
|
-
* @returns The options name.
|
|
14
|
-
*/
|
|
15
|
-
function commanderNameToOptionName(name) {
|
|
16
|
-
if (name.startsWith('--')) {
|
|
17
|
-
name = name.slice('--'.length);
|
|
18
|
-
}
|
|
19
|
-
if (name.startsWith('no-')) {
|
|
20
|
-
name = name.slice('no-'.length);
|
|
21
|
-
}
|
|
22
|
-
if (name.endsWith(' [string]')) {
|
|
23
|
-
name = name.slice(0, name.length - ' [string]'.length);
|
|
24
|
-
}
|
|
25
|
-
if (name.endsWith(' [number]')) {
|
|
26
|
-
name = name.slice(0, name.length - ' [number]'.length);
|
|
27
|
-
}
|
|
28
|
-
return (0, lodash_1.camelCase)(name);
|
|
29
|
-
}
|
|
30
|
-
exports.commanderNameToOptionName = commanderNameToOptionName;
|
|
31
|
-
/**
|
|
32
|
-
* Converts a yargs-parsed options object into an options object suitable for telemetry.
|
|
33
|
-
* @param options The options object as parsed by yargs.
|
|
34
|
-
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
35
|
-
* @returns An options object suitable for telemetry.
|
|
36
|
-
*/
|
|
37
|
-
function yargsOptionsToOptions(options, sanitizer) {
|
|
38
|
-
const result = {};
|
|
39
|
-
for (const key of Object.keys(options)) {
|
|
40
|
-
if (!(key in Object.prototype) &&
|
|
41
|
-
key !== '$0' &&
|
|
42
|
-
key !== '_' &&
|
|
43
|
-
key.includes('-') !== (0, lodash_1.camelCase)(key) in options) {
|
|
44
|
-
result[key] = sanitizer ? sanitizer(key, options[key]) : options[key];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
exports.yargsOptionsToOptions = yargsOptionsToOptions;
|
|
50
|
-
/**
|
|
51
|
-
* Converts a Commander-parsed options object into an options object suitable for telemetry.
|
|
52
|
-
* @param options The options object as parsed by Commander.
|
|
53
|
-
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
54
|
-
* @returns An options object suitable for telemetry.
|
|
55
|
-
*/
|
|
56
|
-
function commanderOptionsToOptions(options, sanitizer) {
|
|
57
|
-
const result = {};
|
|
58
|
-
for (const key of Object.keys(options)) {
|
|
59
|
-
if (!(key in Object.prototype)) {
|
|
60
|
-
result[key] = sanitizer ? sanitizer(key, options[key]) : options[key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
exports.commanderOptionsToOptions = commanderOptionsToOptions;
|
|
66
|
-
/**
|
|
67
|
-
* Checks whether the given command-line args contains the given option key.
|
|
68
|
-
* @param key The option key to look for.
|
|
69
|
-
* @param argv The raw command-line args.
|
|
70
|
-
* @returns Whether the given command-line args contains the given option key.
|
|
71
|
-
*/
|
|
72
|
-
function argsContainsOption(key, argv) {
|
|
73
|
-
const kebabKey = (0, lodash_1.kebabCase)(key);
|
|
74
|
-
return (argv.includes(`--${key}`) ||
|
|
75
|
-
argv.includes(`--no-${key}`) ||
|
|
76
|
-
argv.includes(`--${kebabKey}`) ||
|
|
77
|
-
argv.includes(`--no-${kebabKey}`));
|
|
78
|
-
}
|
|
79
|
-
exports.argsContainsOption = argsContainsOption;
|
|
80
|
-
/**
|
|
81
|
-
* Filters down a given set of options to only include those that were present in the command-line args.
|
|
82
|
-
* @param options The full set of options.
|
|
83
|
-
* @param argv The raw command-line args.
|
|
84
|
-
* @returns The filtered set of options.
|
|
85
|
-
*/
|
|
86
|
-
function optionsToArgs(options, argv) {
|
|
87
|
-
const result = {};
|
|
88
|
-
for (const key of Object.keys(options)) {
|
|
89
|
-
if (!(key in Object.prototype) && argsContainsOption(key, argv)) {
|
|
90
|
-
result[key] = options[key];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
exports.optionsToArgs = optionsToArgs;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.optionsToArgs = exports.argsContainsOption = exports.commanderOptionsToOptions = exports.yargsOptionsToOptions = exports.commanderNameToOptionName = void 0;
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
/**
|
|
11
|
+
* Converts a raw Commander arg name ('--no-bad-dog') into an options property name ('badDog').
|
|
12
|
+
* @param name The raw Commander arg name.
|
|
13
|
+
* @returns The options name.
|
|
14
|
+
*/
|
|
15
|
+
function commanderNameToOptionName(name) {
|
|
16
|
+
if (name.startsWith('--')) {
|
|
17
|
+
name = name.slice('--'.length);
|
|
18
|
+
}
|
|
19
|
+
if (name.startsWith('no-')) {
|
|
20
|
+
name = name.slice('no-'.length);
|
|
21
|
+
}
|
|
22
|
+
if (name.endsWith(' [string]')) {
|
|
23
|
+
name = name.slice(0, name.length - ' [string]'.length);
|
|
24
|
+
}
|
|
25
|
+
if (name.endsWith(' [number]')) {
|
|
26
|
+
name = name.slice(0, name.length - ' [number]'.length);
|
|
27
|
+
}
|
|
28
|
+
return (0, lodash_1.camelCase)(name);
|
|
29
|
+
}
|
|
30
|
+
exports.commanderNameToOptionName = commanderNameToOptionName;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a yargs-parsed options object into an options object suitable for telemetry.
|
|
33
|
+
* @param options The options object as parsed by yargs.
|
|
34
|
+
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
35
|
+
* @returns An options object suitable for telemetry.
|
|
36
|
+
*/
|
|
37
|
+
function yargsOptionsToOptions(options, sanitizer) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const key of Object.keys(options)) {
|
|
40
|
+
if (!(key in Object.prototype) &&
|
|
41
|
+
key !== '$0' &&
|
|
42
|
+
key !== '_' &&
|
|
43
|
+
key.includes('-') !== (0, lodash_1.camelCase)(key) in options) {
|
|
44
|
+
result[key] = sanitizer ? sanitizer(key, options[key]) : options[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
exports.yargsOptionsToOptions = yargsOptionsToOptions;
|
|
50
|
+
/**
|
|
51
|
+
* Converts a Commander-parsed options object into an options object suitable for telemetry.
|
|
52
|
+
* @param options The options object as parsed by Commander.
|
|
53
|
+
* @param sanitizer Function to sanitize the option values for telemetry.
|
|
54
|
+
* @returns An options object suitable for telemetry.
|
|
55
|
+
*/
|
|
56
|
+
function commanderOptionsToOptions(options, sanitizer) {
|
|
57
|
+
const result = {};
|
|
58
|
+
for (const key of Object.keys(options)) {
|
|
59
|
+
if (!(key in Object.prototype)) {
|
|
60
|
+
result[key] = sanitizer ? sanitizer(key, options[key]) : options[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
exports.commanderOptionsToOptions = commanderOptionsToOptions;
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether the given command-line args contains the given option key.
|
|
68
|
+
* @param key The option key to look for.
|
|
69
|
+
* @param argv The raw command-line args.
|
|
70
|
+
* @returns Whether the given command-line args contains the given option key.
|
|
71
|
+
*/
|
|
72
|
+
function argsContainsOption(key, argv) {
|
|
73
|
+
const kebabKey = (0, lodash_1.kebabCase)(key);
|
|
74
|
+
return (argv.includes(`--${key}`) ||
|
|
75
|
+
argv.includes(`--no-${key}`) ||
|
|
76
|
+
argv.includes(`--${kebabKey}`) ||
|
|
77
|
+
argv.includes(`--no-${kebabKey}`));
|
|
78
|
+
}
|
|
79
|
+
exports.argsContainsOption = argsContainsOption;
|
|
80
|
+
/**
|
|
81
|
+
* Filters down a given set of options to only include those that were present in the command-line args.
|
|
82
|
+
* @param options The full set of options.
|
|
83
|
+
* @param argv The raw command-line args.
|
|
84
|
+
* @returns The filtered set of options.
|
|
85
|
+
*/
|
|
86
|
+
function optionsToArgs(options, argv) {
|
|
87
|
+
const result = {};
|
|
88
|
+
for (const key of Object.keys(options)) {
|
|
89
|
+
if (!(key in Object.prototype) && argsContainsOption(key, argv)) {
|
|
90
|
+
result[key] = options[key];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
exports.optionsToArgs = optionsToArgs;
|
|
96
96
|
//# sourceMappingURL=optionUtils.js.map
|