@react-native-windows/telemetry 0.0.0-canary.28 → 0.0.0-canary.29
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/test/errorUtils.test.js +3 -5
- package/lib-commonjs/test/errorUtils.test.js.map +1 -1
- package/lib-commonjs/test/sanitizeUtils.test.js +6 -0
- package/lib-commonjs/test/sanitizeUtils.test.js.map +1 -1
- package/lib-commonjs/utils/sanitizeUtils.js +26 -21
- package/lib-commonjs/utils/sanitizeUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -83,16 +83,14 @@ test('sanitizeErrorMessage() other path', () => {
|
|
|
83
83
|
test("sanitizeErrorMessage() 'other path'", () => {
|
|
84
84
|
expect(errorUtils.sanitizeErrorMessage(`this is another path: 'A:\\foo\\bar\\baz'`)).toBe(`this is another path: [path]`);
|
|
85
85
|
});
|
|
86
|
-
test('sanitizeErrorMessage()
|
|
86
|
+
test('sanitizeErrorMessage() tracked packages in the npx cache', () => {
|
|
87
87
|
expect(errorUtils.sanitizeErrorMessage(`Cannot find module 'react-native/package.json'
|
|
88
88
|
Require stack:
|
|
89
89
|
- ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\lib-commonjs\\Cli.js
|
|
90
90
|
- ${process.env.AppData}\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\bin.js`)).toBe(`Cannot find module react-native/package.json
|
|
91
91
|
Require stack:
|
|
92
|
-
- [
|
|
93
|
-
|
|
94
|
-
- [AppData]\\???(${'\\npm-cache\\_npx\\1384\\node_modules\\react-native-windows-init\\bin.js'
|
|
95
|
-
.length})`);
|
|
92
|
+
- [node_modules]\\react-native-windows-init\\lib-commonjs\\Cli.js
|
|
93
|
+
- [node_modules]\\react-native-windows-init\\bin.js`);
|
|
96
94
|
});
|
|
97
95
|
test('sanitizeErrorMessage() forward slashes', () => {
|
|
98
96
|
expect(errorUtils.sanitizeErrorMessage(`EPERM: operation not permitted, scandir ${process.env.UserProfile.replace(/\\/g, '/')}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`)).toBe(`EPERM: operation not permitted, scandir [UserProfile]\\???(${'/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorUtils.test.js","sourceRoot":"","sources":["../../src/test/errorUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;AAIH,gEAAkD;AAElD,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,kCAAkC,CAAC,CAAC,CAAC,IAAI,CACzE,SAAS,CACV,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;AAC1E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;IACzD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACxD,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;IACvD,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sCAAsC,EAAE,GAAG,EAAE;IAChD,MAAM,CACJ,UAAU,CAAC,oBAAoB,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,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAqC;QAC/C,MAAM,EAAE,uBAAuB,OAAO,CAAC,GAAG,EAAE,EAAE;QAC9C,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB;QAC/C,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC;IACF,UAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACrB,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,2BAA2B;QACrC,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport * as appInsights from 'applicationinsights';\n\nimport * as errorUtils from '../utils/errorUtils';\n\ntest('tryGetErrorCode() with valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar error FOO2020: the thing')).toBe(\n 'FOO2020',\n );\n});\n\ntest('tryGetErrorCode() without valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar the thing')).toBeUndefined();\n});\n\ntest('tryGetErrorCode() with word error but no code', () => {\n expect(errorUtils.tryGetErrorCode('test error')).toBeUndefined();\n});\n\ntest('sanitizeErrorMessage() no-op on empty string', () => {\n expect(errorUtils.sanitizeErrorMessage('')).toBe('');\n});\n\ntest('sanitizeErrorMessage() no-op on test string', () => {\n expect(errorUtils.sanitizeErrorMessage('some text')).toBe('some text');\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}'`),\n ).toBe(`this is the cwd: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}'`,\n ),\n ).toBe(`uppercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}'`,\n ),\n ).toBe(`lowercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}' and something else`,\n ),\n ).toBe(`this is the cwd: [project_dir] and something else`);\n});\n\ntest('sanitizeErrorMessage() project_dir and something else', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()} and something else`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${' and something else'.length})`,\n );\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules'`,\n ),\n ).toBe(`this is the cwd: [project_dir]\\\\???(${'node_modules'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules\\\\foo'`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`uppercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`lowercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `trailing: '${process.cwd()}\\\\node_modules\\\\' and something else`,\n ),\n ).toBe(`trailing: [node_modules]\\\\???(0) and something else`);\n});\n\ntest('sanitizeErrorMessage() node_modules and something else that could be part of the path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules and something else that could be part of the path`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${\n 'node_modules and something else that could be part of the path'.length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() \\\\node_modules\\\\ a file under nm', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules\\\\ a file under nm`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${' a file under nm'.length})`);\n});\n\ntest('sanitizeErrorMessage() other path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is another path: A:\\\\foo\\\\bar\\\\baz`),\n ).toBe(`this is another path: [path]`);\n});\n\ntest(\"sanitizeErrorMessage() 'other path'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is another path: 'A:\\\\foo\\\\bar\\\\baz'`,\n ),\n ).toBe(`this is another path: [path]`);\n});\n\ntest('sanitizeErrorMessage() multiple known paths', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `Cannot find module 'react-native/package.json'\n Require stack:\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\bin.js`,\n ),\n ).toBe(`Cannot find module react-native/package.json\n Require stack:\n - [AppData]\\\\???(${\n '\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js'\n .length\n })\n - [AppData]\\\\???(${\n '\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\bin.js'\n .length\n })`);\n});\n\ntest('sanitizeErrorMessage() forward slashes', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `EPERM: operation not permitted, scandir ${process.env.UserProfile!.replace(\n /\\\\/g,\n '/',\n )}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`,\n ),\n ).toBe(\n `EPERM: operation not permitted, scandir [UserProfile]\\\\???(${\n '/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'\n .length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() file share path', () => {\n expect(errorUtils.sanitizeErrorMessage(`file here: \\\\\\\\server\\\\share`)).toBe(\n 'file here: [path]',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu id', () => {\n expect(errorUtils.sanitizeErrorMessage('5>This is an error')).toBe(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu/thread id', () => {\n expect(errorUtils.sanitizeErrorMessage('5:42>This is an error')).toEqual(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorStackFrame() with empty frame', () => {\n const emptyFrame: appInsights.Contracts.StackFrame = {\n level: 0,\n method: '',\n fileName: '',\n assembly: 'asdf',\n line: 0,\n };\n errorUtils.sanitizeErrorStackFrame(emptyFrame);\n expect(emptyFrame).toEqual({\n level: 0,\n assembly: '',\n fileName: '[path]',\n method: '',\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with assembly name', () => {\n const frame1: appInsights.Contracts.StackFrame = {\n method: '',\n fileName: `${process.cwd()}\\\\foo.js`,\n assembly: 'asdf',\n level: 0,\n line: 0,\n };\n errorUtils.sanitizeErrorStackFrame(frame1);\n expect(frame1).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(6)',\n method: '',\n level: 0,\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with method name', () => {\n const frame2: appInsights.Contracts.StackFrame = {\n method: `myMethod (something ${process.cwd()}`,\n fileName: `${process.cwd()}\\\\telemetry\\\\foo.js`,\n assembly: 'asdf',\n level: 1,\n line: 42,\n };\n errorUtils.sanitizeErrorStackFrame(frame2);\n expect(frame2).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(16)',\n method: 'myMethod',\n level: 1,\n line: 42,\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"errorUtils.test.js","sourceRoot":"","sources":["../../src/test/errorUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;AAIH,gEAAkD;AAElD,IAAI,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,kCAAkC,CAAC,CAAC,CAAC,IAAI,CACzE,SAAS,CACV,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;AAC1E,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;IACzD,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACxD,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACvD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;IACvD,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC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AAC;QACrB,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,0BAA0B;QACpC,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAqC;QAC/C,MAAM,EAAE,uBAAuB,OAAO,CAAC,GAAG,EAAE,EAAE;QAC9C,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB;QAC/C,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC;IACF,UAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACrB,QAAQ,EAAE,EAAE;QACZ,QAAQ,EAAE,2BAA2B;QACrC,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,EAAE;KACT,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport * as appInsights from 'applicationinsights';\n\nimport * as errorUtils from '../utils/errorUtils';\n\ntest('tryGetErrorCode() with valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar error FOO2020: the thing')).toBe(\n 'FOO2020',\n );\n});\n\ntest('tryGetErrorCode() without valid error code', () => {\n expect(errorUtils.tryGetErrorCode('foo bar the thing')).toBeUndefined();\n});\n\ntest('tryGetErrorCode() with word error but no code', () => {\n expect(errorUtils.tryGetErrorCode('test error')).toBeUndefined();\n});\n\ntest('sanitizeErrorMessage() no-op on empty string', () => {\n expect(errorUtils.sanitizeErrorMessage('')).toBe('');\n});\n\ntest('sanitizeErrorMessage() no-op on test string', () => {\n expect(errorUtils.sanitizeErrorMessage('some text')).toBe('some text');\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is the cwd: '${process.cwd()}'`),\n ).toBe(`this is the cwd: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}'`,\n ),\n ).toBe(`uppercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}'`,\n ),\n ).toBe(`lowercase: [project_dir]`);\n});\n\ntest(\"sanitizeErrorMessage() 'project_dir' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}' and something else`,\n ),\n ).toBe(`this is the cwd: [project_dir] and something else`);\n});\n\ntest('sanitizeErrorMessage() project_dir and something else', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()} and something else`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${' and something else'.length})`,\n );\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules'`,\n ),\n ).toBe(`this is the cwd: [project_dir]\\\\???(${'node_modules'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: '${process.cwd()}\\\\node_modules\\\\foo'`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' uppercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `uppercase: '${process.cwd().toUpperCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`uppercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\foo' lowercase\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `lowercase: '${process.cwd().toLowerCase()}\\\\NODE_MODULES\\\\foo'`,\n ),\n ).toBe(`lowercase: [node_modules]\\\\???(${'foo'.length})`);\n});\n\ntest(\"sanitizeErrorMessage() 'node_modules\\\\' and something else\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `trailing: '${process.cwd()}\\\\node_modules\\\\' and something else`,\n ),\n ).toBe(`trailing: [node_modules]\\\\???(0) and something else`);\n});\n\ntest('sanitizeErrorMessage() node_modules and something else that could be part of the path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules and something else that could be part of the path`,\n ),\n ).toBe(\n `this is the cwd: [project_dir]\\\\???(${\n 'node_modules and something else that could be part of the path'.length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() \\\\node_modules\\\\ a file under nm', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is the cwd: ${process.cwd()}\\\\node_modules\\\\ a file under nm`,\n ),\n ).toBe(`this is the cwd: [node_modules]\\\\???(${' a file under nm'.length})`);\n});\n\ntest('sanitizeErrorMessage() other path', () => {\n expect(\n errorUtils.sanitizeErrorMessage(`this is another path: A:\\\\foo\\\\bar\\\\baz`),\n ).toBe(`this is another path: [path]`);\n});\n\ntest(\"sanitizeErrorMessage() 'other path'\", () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `this is another path: 'A:\\\\foo\\\\bar\\\\baz'`,\n ),\n ).toBe(`this is another path: [path]`);\n});\n\ntest('sanitizeErrorMessage() tracked packages in the npx cache', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `Cannot find module 'react-native/package.json'\n Require stack:\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js\n - ${process.env.AppData}\\\\npm-cache\\\\_npx\\\\1384\\\\node_modules\\\\react-native-windows-init\\\\bin.js`,\n ),\n ).toBe(`Cannot find module react-native/package.json\n Require stack:\n - [node_modules]\\\\react-native-windows-init\\\\lib-commonjs\\\\Cli.js\n - [node_modules]\\\\react-native-windows-init\\\\bin.js`);\n});\n\ntest('sanitizeErrorMessage() forward slashes', () => {\n expect(\n errorUtils.sanitizeErrorMessage(\n `EPERM: operation not permitted, scandir ${process.env.UserProfile!.replace(\n /\\\\/g,\n '/',\n )}/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include`,\n ),\n ).toBe(\n `EPERM: operation not permitted, scandir [UserProfile]\\\\???(${\n '/source/repos/rn2/wintest/windows/packages/boost.1.76.0.0/lib/native/include'\n .length\n })`,\n );\n});\n\ntest('sanitizeErrorMessage() file share path', () => {\n expect(errorUtils.sanitizeErrorMessage(`file here: \\\\\\\\server\\\\share`)).toBe(\n 'file here: [path]',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu id', () => {\n expect(errorUtils.sanitizeErrorMessage('5>This is an error')).toBe(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorMessage() with cpu/thread id', () => {\n expect(errorUtils.sanitizeErrorMessage('5:42>This is an error')).toEqual(\n 'This is an error',\n );\n});\n\ntest('sanitizeErrorStackFrame() with empty frame', () => {\n const emptyFrame: appInsights.Contracts.StackFrame = {\n level: 0,\n method: '',\n fileName: '',\n assembly: 'asdf',\n line: 0,\n };\n errorUtils.sanitizeErrorStackFrame(emptyFrame);\n expect(emptyFrame).toEqual({\n level: 0,\n assembly: '',\n fileName: '[path]',\n method: '',\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with assembly name', () => {\n const frame1: appInsights.Contracts.StackFrame = {\n method: '',\n fileName: `${process.cwd()}\\\\foo.js`,\n assembly: 'asdf',\n level: 0,\n line: 0,\n };\n errorUtils.sanitizeErrorStackFrame(frame1);\n expect(frame1).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(6)',\n method: '',\n level: 0,\n line: 0,\n });\n});\n\ntest('sanitizeErrorStackFrame() with method name', () => {\n const frame2: appInsights.Contracts.StackFrame = {\n method: `myMethod (something ${process.cwd()}`,\n fileName: `${process.cwd()}\\\\telemetry\\\\foo.js`,\n assembly: 'asdf',\n level: 1,\n line: 42,\n };\n errorUtils.sanitizeErrorStackFrame(frame2);\n expect(frame2).toEqual({\n assembly: '',\n fileName: '[project_dir]\\\\???.js(16)',\n method: 'myMethod',\n level: 1,\n line: 42,\n });\n});\n"]}
|
|
@@ -79,6 +79,12 @@ test('getAnonymizedPath() with path under %%LocalAppData%% is anonymized', () =>
|
|
|
79
79
|
expect(anonymizedPath).not.toBe(originalPath);
|
|
80
80
|
expect(anonymizedPath.startsWith('[LocalAppData]\\???')).toBe(true);
|
|
81
81
|
});
|
|
82
|
+
test('getAnonymizedPath() with a tracked npm package under %%LocalAppData%% is anonymized', () => {
|
|
83
|
+
const originalPath = path_1.default.normalize(path_1.default.join(process.env.LocalAppData, 'node_modules/@react-native-windows/cli/index.js'));
|
|
84
|
+
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
85
|
+
expect(anonymizedPath).not.toBe(originalPath);
|
|
86
|
+
expect(anonymizedPath).toBe('[node_modules]\\@react-native-windows\\cli\\index.js');
|
|
87
|
+
});
|
|
82
88
|
test('getAnonymizedPath() with arbitrary path not under project dir is anonymized', () => {
|
|
83
89
|
const originalPath = 'test.sln';
|
|
84
90
|
const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeUtils.test.js","sourceRoot":"","sources":["../../src/test/sanitizeUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAwB;AAExB,sEAAwD;AAExD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAEjC,IAAI,CAAC,oDAAoD,EAAE,GAAG,EAA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C,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iDAAiD,CAAC,CACzE,CAAC;IACF,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CACzB,sDAAsD,CACvD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,oEAAoE,EAAE,GAAG,EAAE;IAC9E,MAAM,YAAY,GAAG,cAAI,CAAC,SAAS,CACjC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,EAAE,UAAU,CAAC,CACjD,CAAC;IACF,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6EAA6E,EAAE,GAAG,EAAE;IACvF,MAAM,YAAY,GAAG,UAAU,CAAC;IAChC,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\n\nimport * as sanitizeUtils from '../utils/sanitizeUtils';\n\nconst projectDir = process.cwd();\n\ntest('getAnonymizedPath() with project dir is anonymized', () => {\n const originalPath = projectDir;\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[project_dir]')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/index.js is anonymized', () => {\n const originalPath = path.join(projectDir, 'index.js');\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[project_dir]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/windows/test.sln is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'windows/test.sln'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[windows]\\\\???.sln')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/node_modules for untracked package is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/untracked/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[node_modules]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/node_modules for react-secret-pii package is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/react-secret-pii/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[node_modules]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with path under react-native-windows is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/react-native-windows/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe('[node_modules]\\\\react-native-windows\\\\index.js');\n});\n\ntest('getAnonymizedPath() with path under @react-native-windows/cli is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/@react-native-windows/cli/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe(\n '[node_modules]\\\\@react-native-windows\\\\cli\\\\index.js',\n );\n});\n\ntest('getAnonymizedPath() with path under %%LocalAppData%% is anonymized', () => {\n const originalPath = path.normalize(\n path.join(process.env.LocalAppData!, 'test.sln'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[LocalAppData]\\\\???')).toBe(true);\n});\n\ntest('getAnonymizedPath() with arbitrary path not under project dir is anonymized', () => {\n const originalPath = 'test.sln';\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe('[path]');\n});\n"]}
|
|
1
|
+
{"version":3,"file":"sanitizeUtils.test.js","sourceRoot":"","sources":["../../src/test/sanitizeUtils.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAwB;AAExB,sEAAwD;AAExD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAEjC,IAAI,CAAC,oDAAoD,EAAE,GAAG,EAAE;IAC9D,MAAM,YAAY,GAAG,UAAU,CAAC;IAChC,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yDAAyD,EAAE,GAAG,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E;IAC9E,MAAM,YAAY,GAAG,cAAI,CAAC,SAAS,CACjC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,EAAE,UAAU,CAAC,CACjD,CAAC;IACF,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qFAAqF,EAAE,GAAG,EAAE;IAC/F,MAAM,YAAY,GAAG,cAAI,CAAC,SAAS,CACjC,cAAI,CAAC,IAAI,CACP,OAAO,CAAC,GAAG,CAAC,YAAa,EACzB,iDAAiD,CAClD,CACF,CAAC;IACF,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CACzB,sDAAsD,CACvD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,6EAA6E,EAAE,GAAG,EAAE;IACvF,MAAM,YAAY,GAAG,UAAU,CAAC;IAChC,MAAM,cAAc,GAAG,aAAa,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport path from 'path';\n\nimport * as sanitizeUtils from '../utils/sanitizeUtils';\n\nconst projectDir = process.cwd();\n\ntest('getAnonymizedPath() with project dir is anonymized', () => {\n const originalPath = projectDir;\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[project_dir]')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/index.js is anonymized', () => {\n const originalPath = path.join(projectDir, 'index.js');\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[project_dir]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/windows/test.sln is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'windows/test.sln'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[windows]\\\\???.sln')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/node_modules for untracked package is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/untracked/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[node_modules]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with project/node_modules for react-secret-pii package is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/react-secret-pii/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[node_modules]\\\\???.js')).toBe(true);\n});\n\ntest('getAnonymizedPath() with path under react-native-windows is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/react-native-windows/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe('[node_modules]\\\\react-native-windows\\\\index.js');\n});\n\ntest('getAnonymizedPath() with path under @react-native-windows/cli is anonymized', () => {\n const originalPath = path.normalize(\n path.join(projectDir, 'node_modules/@react-native-windows/cli/index.js'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe(\n '[node_modules]\\\\@react-native-windows\\\\cli\\\\index.js',\n );\n});\n\ntest('getAnonymizedPath() with path under %%LocalAppData%% is anonymized', () => {\n const originalPath = path.normalize(\n path.join(process.env.LocalAppData!, 'test.sln'),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath.startsWith('[LocalAppData]\\\\???')).toBe(true);\n});\n\ntest('getAnonymizedPath() with a tracked npm package under %%LocalAppData%% is anonymized', () => {\n const originalPath = path.normalize(\n path.join(\n process.env.LocalAppData!,\n 'node_modules/@react-native-windows/cli/index.js',\n ),\n );\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe(\n '[node_modules]\\\\@react-native-windows\\\\cli\\\\index.js',\n );\n});\n\ntest('getAnonymizedPath() with arbitrary path not under project dir is anonymized', () => {\n const originalPath = 'test.sln';\n const anonymizedPath = sanitizeUtils.getAnonymizedPath(originalPath);\n expect(anonymizedPath).not.toBe(originalPath);\n expect(anonymizedPath).toBe('[path]');\n});\n"]}
|
|
@@ -32,27 +32,33 @@ function getAnonymizedPath(filepath, projectRoot) {
|
|
|
32
32
|
? projectRoot.slice(0, -1)
|
|
33
33
|
: projectRoot;
|
|
34
34
|
filepath = filepath.replace(/\//g, '\\');
|
|
35
|
+
const ext = path_1.default.extname(filepath);
|
|
36
|
+
// Check if we're under node_modules
|
|
37
|
+
const nodeModulesIndex = filepath.toLowerCase().lastIndexOf(nodeModules);
|
|
38
|
+
if (nodeModulesIndex >= 0) {
|
|
39
|
+
// We are under node_modules
|
|
40
|
+
// Check if it's an npm package we're tracking
|
|
41
|
+
for (const trackedNpmPackage of telemetry_1.NpmPackagesWeTrack) {
|
|
42
|
+
const startIndex = filepath
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
.lastIndexOf(nodeModules + trackedNpmPackage.replace(/\//g, '\\') + '\\');
|
|
45
|
+
if (startIndex >= 0) {
|
|
46
|
+
// We are under node_modules within an npm package we're tracking, anonymize by removing root
|
|
47
|
+
return ('[node_modules]\\' + filepath.slice(startIndex + nodeModules.length));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// It's an npm package we're not tracking, anonymize with [node_modules]
|
|
51
|
+
return `[node_modules]\\???${ext}(${filepath.slice(nodeModulesIndex)
|
|
52
|
+
.length - nodeModules.length})`;
|
|
53
|
+
}
|
|
54
|
+
// Check if we're under the projectRoot
|
|
35
55
|
if (filepath.toLowerCase().startsWith(projectRoot)) {
|
|
36
56
|
// We are under the projectRoot
|
|
37
|
-
const ext = path_1.default.extname(filepath);
|
|
38
57
|
const rest = filepath.slice(projectRoot.length);
|
|
39
58
|
if (rest.toLowerCase().startsWith(windows)) {
|
|
40
59
|
// We are under the windows path, anonymize with [windows]
|
|
41
60
|
return `[windows]\\???${ext}(${rest.length - windows.length - 1})`;
|
|
42
61
|
}
|
|
43
|
-
else if (rest.toLowerCase().startsWith(nodeModules)) {
|
|
44
|
-
// We are under the node_modules path
|
|
45
|
-
for (const trackedNpmPackage of telemetry_1.NpmPackagesWeTrack) {
|
|
46
|
-
if (rest
|
|
47
|
-
.toLowerCase()
|
|
48
|
-
.startsWith(nodeModules + trackedNpmPackage.replace(/\//g, '\\') + '\\')) {
|
|
49
|
-
// We are under node_modules within an npm package we're tracking, anonymize by removing root
|
|
50
|
-
return '[node_modules]' + rest.slice(nodeModules.length - 1);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// We are under node_modules within an npm package we're not tracking, anonymize with [node_modules]
|
|
54
|
-
return `[node_modules]\\???${ext}(${rest.length - nodeModules.length})`;
|
|
55
|
-
}
|
|
56
62
|
else {
|
|
57
63
|
// We are just within the projectRoot, anonymize with [project_dir]
|
|
58
64
|
if (rest === '' || rest === '\\') {
|
|
@@ -64,13 +70,12 @@ function getAnonymizedPath(filepath, projectRoot) {
|
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
73
|
+
// Check if we're under a known environmental variable path
|
|
74
|
+
for (const knownPath of knownEnvironmentVariablePaths) {
|
|
75
|
+
if (process.env[knownPath] &&
|
|
76
|
+
filepath.toLowerCase().startsWith(process.env[knownPath].toLowerCase())) {
|
|
77
|
+
return `[${knownPath}]\\???(${filepath.length -
|
|
78
|
+
process.env[knownPath].length})`;
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
// We are somewhere else, anonymize with [path]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeUtils.js","sourceRoot":"","sources":["../../src/utils/sanitizeUtils.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,gDAAwB;AAExB,4CAAgD;AAEhD,MAAM,WAAW,GAAG,kBAAkB,CAAC;AACvC,MAAM,OAAO,GAAG,aAAa,CAAC;AAE9B,MAAM,6BAA6B,GAAG;IACpC,SAAS;IACT,cAAc;IACd,aAAa;CACd,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,QAAgB,EAChB,WAAoB;IAEpB,WAAW,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,OAAO,CAAC,GAAG,EAAE,CAAC;SACzC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;SACpB,WAAW,EAAE,CAAC;IACjB,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;QACt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tB,QAAQ,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,WAAW,EAAE,CAAC,EACxE;YACA,OAAO,IAAI,SAAS,UAAU,QAAQ,CAAC,MAAM;gBAC3C,OAAO,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,MAAM,GAAG,CAAC;SACrC;KACF;IAED,+CAA+C;IAC/C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAtED,8CAsEC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport path from 'path';\n\nimport {NpmPackagesWeTrack} from '../telemetry';\n\nconst nodeModules = '\\\\node_modules\\\\';\nconst windows = '\\\\windows\\\\';\n\nconst knownEnvironmentVariablePaths = [\n 'AppData',\n 'LocalAppData',\n 'UserProfile',\n];\n\n/**\n * Gets an anonymized version of the given path, suitable for Telemetry.\n * @param filepath The path to anonymize.\n * @param projectRoot Optional root path for the project. Defaults to process.cwd().\n * @returns The anonymized path.\n */\nexport function getAnonymizedPath(\n filepath: string,\n projectRoot?: string,\n): string {\n projectRoot = (projectRoot ?? process.cwd())\n .replace(/\\//g, '\\\\')\n .toLowerCase();\n projectRoot = projectRoot.endsWith('\\\\')\n ? projectRoot.slice(0, -1)\n : projectRoot;\n filepath = filepath.replace(/\\//g, '\\\\');\n\n const ext = path.extname(filepath);\n\n // Check if we're under node_modules\n const nodeModulesIndex = filepath.toLowerCase().lastIndexOf(nodeModules);\n if (nodeModulesIndex >= 0) {\n // We are under node_modules\n\n // Check if it's an npm package we're tracking\n for (const trackedNpmPackage of NpmPackagesWeTrack) {\n const startIndex = filepath\n .toLowerCase()\n .lastIndexOf(\n nodeModules + trackedNpmPackage.replace(/\\//g, '\\\\') + '\\\\',\n );\n if (startIndex >= 0) {\n // We are under node_modules within an npm package we're tracking, anonymize by removing root\n return (\n '[node_modules]\\\\' + filepath.slice(startIndex + nodeModules.length)\n );\n }\n }\n\n // It's an npm package we're not tracking, anonymize with [node_modules]\n return `[node_modules]\\\\???${ext}(${filepath.slice(nodeModulesIndex)\n .length - nodeModules.length})`;\n }\n\n // Check if we're under the projectRoot\n if (filepath.toLowerCase().startsWith(projectRoot)) {\n // We are under the projectRoot\n const rest = filepath.slice(projectRoot.length);\n if (rest.toLowerCase().startsWith(windows)) {\n // We are under the windows path, anonymize with [windows]\n return `[windows]\\\\???${ext}(${rest.length - windows.length - 1})`;\n } else {\n // We are just within the projectRoot, anonymize with [project_dir]\n if (rest === '' || rest === '\\\\') {\n return '[project_dir]';\n } else {\n return `[project_dir]\\\\???${ext}(${rest.length -\n (rest.startsWith('\\\\') ? 1 : 0)})`;\n }\n }\n }\n\n // Check if we're under a known environmental variable path\n for (const knownPath of knownEnvironmentVariablePaths) {\n if (\n process.env[knownPath] &&\n filepath.toLowerCase().startsWith(process.env[knownPath]!.toLowerCase())\n ) {\n return `[${knownPath}]\\\\???(${filepath.length -\n process.env[knownPath]!.length})`;\n }\n }\n\n // We are somewhere else, anonymize with [path]\n return '[path]';\n}\n"]}
|