Skip to content

Commit 46b048f

Browse files
authored
chore: vendor stack utils (#34719)
1 parent 8e51be9 commit 46b048f

File tree

9 files changed

+175
-95
lines changed

9 files changed

+175
-95
lines changed

packages/playwright-core/ThirdPartyNotices.txt

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This project incorporates components from the projects listed below. The origina
1919
- [email protected] (https://github.com/kpdecker/jsdiff)
2020
- [email protected] (https://github.com/motdotla/dotenv)
2121
- [email protected] (https://github.com/mafintosh/end-of-stream)
22-
- [email protected] (https://github.com/sindresorhus/escape-string-regexp)
2322
- [email protected] (https://github.com/maxogden/extract-zip)
2423
- [email protected] (https://github.com/andrewrk/node-fd-slicer)
2524
- [email protected] (https://github.com/sindresorhus/get-stream)
@@ -46,7 +45,6 @@ This project incorporates components from the projects listed below. The origina
4645
- [email protected] (https://github.com/TooTallNate/node-socks-proxy-agent)
4746
- [email protected] (https://github.com/JoshGlazebrook/socks)
4847
- [email protected] (https://github.com/alexei/sprintf.js)
49-
- [email protected] (https://github.com/tapjs/stack-utils)
5048
- [email protected] (https://github.com/npm/wrappy)
5149
- [email protected] (https://github.com/websockets/ws)
5250
- [email protected] (https://github.com/eemeli/yaml)
@@ -563,20 +561,6 @@ THE SOFTWARE.
563561
=========================================
564562
END OF [email protected] AND INFORMATION
565563

566-
%% [email protected] NOTICES AND INFORMATION BEGIN HERE
567-
=========================================
568-
MIT License
569-
570-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
571-
572-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
573-
574-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
575-
576-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
577-
=========================================
578-
END OF [email protected] AND INFORMATION
579-
580564
%% [email protected] NOTICES AND INFORMATION BEGIN HERE
581565
=========================================
582566
Copyright (c) 2014 Max Ogden and other contributors
@@ -1454,32 +1438,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14541438
=========================================
14551439
END OF [email protected] AND INFORMATION
14561440

1457-
%% [email protected] NOTICES AND INFORMATION BEGIN HERE
1458-
=========================================
1459-
The MIT License (MIT)
1460-
1461-
Copyright (c) Isaac Z. Schlueter <[email protected]>, James Talmage <[email protected]> (github.com/jamestalmage), and Contributors
1462-
1463-
Permission is hereby granted, free of charge, to any person obtaining a copy
1464-
of this software and associated documentation files (the "Software"), to deal
1465-
in the Software without restriction, including without limitation the rights
1466-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1467-
copies of the Software, and to permit persons to whom the Software is
1468-
furnished to do so, subject to the following conditions:
1469-
1470-
The above copyright notice and this permission notice shall be included in
1471-
all copies or substantial portions of the Software.
1472-
1473-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1474-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1475-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1476-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1477-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1478-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1479-
THE SOFTWARE.
1480-
=========================================
1481-
END OF [email protected] AND INFORMATION
1482-
14831441
%% [email protected] NOTICES AND INFORMATION BEGIN HERE
14841442
=========================================
14851443
The ISC License
@@ -1597,6 +1555,6 @@ END OF [email protected] AND INFORMATION
15971555

15981556
SUMMARY BEGIN HERE
15991557
=========================================
1600-
Total Packages: 48
1558+
Total Packages: 46
16011559
=========================================
16021560
END OF SUMMARY

packages/playwright-core/bundles/utils/package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/playwright-core/bundles/utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"retry": "0.12.0",
2727
"signal-exit": "3.0.7",
2828
"socks-proxy-agent": "6.1.1",
29-
"stack-utils": "2.0.5",
3029
"ws": "8.17.1",
3130
"yaml": "^2.6.0"
3231
},

packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ export const progress = progressLibrary;
5656

5757
export { SocksProxyAgent } from 'socks-proxy-agent';
5858

59-
import StackUtilsLibrary from 'stack-utils';
60-
export const StackUtils = StackUtilsLibrary;
61-
6259
import yamlLibrary from 'yaml';
6360
export const yaml = yamlLibrary;
6461

packages/playwright-core/src/utils/stackTrace.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,30 @@
1616

1717
import * as path from 'path';
1818

19-
import { parseStackTraceLine } from '../utilsBundle';
2019
import { colors } from '../utilsBundle';
2120
import { findRepeatedSubsequences } from './sequence';
21+
import { StackUtils } from './stackUtils';
2222

2323
import type { StackFrame } from '@protocol/channels';
2424

25+
const stackUtils = new StackUtils();
26+
27+
export function parseStackTraceLine(line: string): StackFrame | null {
28+
const frame = stackUtils.parseLine(line);
29+
if (!frame)
30+
return null;
31+
if (!process.env.PWDEBUGIMPL && (frame.file?.startsWith('internal') || frame.file?.startsWith('node:')))
32+
return null;
33+
if (!frame.file)
34+
return null;
35+
return {
36+
file: frame.file,
37+
line: frame.line || 0,
38+
column: frame.column || 0,
39+
function: frame.function,
40+
};
41+
}
42+
2543
export function rewriteErrorMessage<E extends Error>(e: E, newMessage: string): E {
2644
const lines: string[] = (e.stack?.split('\n') || []).filter(l => l.startsWith(' at '));
2745
e.message = newMessage;
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* The MIT License (MIT)
3+
* Modifications copyright (c) Microsoft Corporation.
4+
*
5+
* Copyright (c) 2016-2023 Isaac Z. Schlueter [email protected], James Talmage [email protected] (github.com/jamestalmage), and
6+
* Contributors
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
9+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
10+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
14+
* Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
import * as url from 'url';
23+
24+
type StackData = {
25+
line?: number;
26+
column?: number;
27+
file?: string;
28+
isConstructor?: boolean;
29+
evalOrigin?: string;
30+
native?: boolean;
31+
function?: string;
32+
method?: string;
33+
evalLine?: number | undefined;
34+
evalColumn?: number | undefined;
35+
evalFile?: string | undefined;
36+
};
37+
38+
export class StackUtils {
39+
parseLine(line: string) {
40+
const match = line && line.match(re);
41+
if (!match)
42+
return null;
43+
44+
const ctor = match[1] === 'new';
45+
let fname = match[2];
46+
const evalOrigin = match[3];
47+
const evalFile = match[4];
48+
const evalLine = Number(match[5]);
49+
const evalCol = Number(match[6]);
50+
let file = match[7];
51+
const lnum = match[8];
52+
const col = match[9];
53+
const native = match[10] === 'native';
54+
const closeParen = match[11] === ')';
55+
let method;
56+
57+
const res: StackData = {};
58+
59+
if (lnum)
60+
res.line = Number(lnum);
61+
62+
if (col)
63+
res.column = Number(col);
64+
65+
if (closeParen && file) {
66+
// make sure parens are balanced
67+
// if we have a file like "asdf) [as foo] (xyz.js", then odds are
68+
// that the fname should be += " (asdf) [as foo]" and the file
69+
// should be just "xyz.js"
70+
// walk backwards from the end to find the last unbalanced (
71+
let closes = 0;
72+
for (let i = file.length - 1; i > 0; i--) {
73+
if (file.charAt(i) === ')') {
74+
closes++;
75+
} else if (file.charAt(i) === '(' && file.charAt(i - 1) === ' ') {
76+
closes--;
77+
if (closes === -1 && file.charAt(i - 1) === ' ') {
78+
const before = file.slice(0, i - 1);
79+
const after = file.slice(i + 1);
80+
file = after;
81+
fname += ` (${before}`;
82+
break;
83+
}
84+
}
85+
}
86+
}
87+
88+
if (fname) {
89+
const methodMatch = fname.match(methodRe);
90+
if (methodMatch) {
91+
fname = methodMatch[1];
92+
method = methodMatch[2];
93+
}
94+
}
95+
96+
setFile(res, file);
97+
98+
if (ctor)
99+
res.isConstructor = true;
100+
101+
if (evalOrigin) {
102+
res.evalOrigin = evalOrigin;
103+
res.evalLine = evalLine;
104+
res.evalColumn = evalCol;
105+
res.evalFile = evalFile && evalFile.replace(/\\/g, '/');
106+
}
107+
108+
if (native)
109+
res.native = true;
110+
if (fname)
111+
res.function = fname;
112+
if (method && fname !== method)
113+
res.method = method;
114+
return res;
115+
}
116+
}
117+
118+
function setFile(result: StackData, filename: string) {
119+
if (filename) {
120+
if (filename.startsWith('file://'))
121+
filename = url.fileURLToPath(filename);
122+
result.file = filename;
123+
}
124+
}
125+
126+
const re = new RegExp('^' +
127+
// Sometimes we strip out the ' at' because it's noisy
128+
'(?:\\s*at )?' +
129+
// $1 = ctor if 'new'
130+
'(?:(new) )?' +
131+
// $2 = function name (can be literally anything)
132+
// May contain method at the end as [as xyz]
133+
'(?:(.*?) \\()?' +
134+
// (eval at <anonymous> (file.js:1:1),
135+
// $3 = eval origin
136+
// $4:$5:$6 are eval file/line/col, but not normally reported
137+
'(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?' +
138+
// file:line:col
139+
// $7:$8:$9
140+
// $10 = 'native' if native
141+
'(?:(.+?):(\\d+):(\\d+)|(native))' +
142+
// maybe close the paren, then end
143+
// if $11 is ), then we only allow balanced parens in the filename
144+
// any imbalance is placed on the fname. This is a heuristic, and
145+
// bound to be incorrect in some edge cases. The bet is that
146+
// having weird characters in method names is more common than
147+
// having weird characters in filenames, which seems reasonable.
148+
'(\\)?)$'
149+
);
150+
151+
const methodRe = /^(.*?) \[as (.*?)\]$/;

packages/playwright-core/src/utilsBundle.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as path from 'path';
18-
import * as url from 'url';
19-
2017
export const colors: typeof import('../bundles/utils/node_modules/colors/safe') = require('./utilsBundleImpl').colors;
2118
export const debug: typeof import('../bundles/utils/node_modules/@types/debug') = require('./utilsBundleImpl').debug;
2219
export const diff: typeof import('../bundles/utils/node_modules/@types/diff') = require('./utilsBundleImpl').diff;
@@ -40,28 +37,6 @@ export const wsReceiver = require('./utilsBundleImpl').wsReceiver;
4037
export const wsSender = require('./utilsBundleImpl').wsSender;
4138
export type { Command } from '../bundles/utils/node_modules/commander';
4239
export type { EventEmitter as WebSocketEventEmitter, RawData as WebSocketRawData, WebSocket, WebSocketServer } from '../bundles/utils/node_modules/@types/ws';
43-
import type { StackFrame } from '@protocol/channels';
44-
45-
const StackUtils: typeof import('../bundles/utils/node_modules/@types/stack-utils') = require('./utilsBundleImpl').StackUtils;
46-
const stackUtils = new StackUtils({ internals: StackUtils.nodeInternals() });
47-
48-
export function parseStackTraceLine(line: string): StackFrame | null {
49-
const frame = stackUtils.parseLine(line);
50-
if (!frame)
51-
return null;
52-
if (!process.env.PWDEBUGIMPL && (frame.file?.startsWith('internal') || frame.file?.startsWith('node:')))
53-
return null;
54-
if (!frame.file)
55-
return null;
56-
// ESM files return file:// URLs, see here: https://github.com/tapjs/stack-utils/issues/60
57-
const file = frame.file.startsWith('file://') ? url.fileURLToPath(frame.file) : path.resolve(process.cwd(), frame.file);
58-
return {
59-
file,
60-
line: frame.line || 0,
61-
column: frame.column || 0,
62-
function: frame.function,
63-
};
64-
}
6540

6641
export function ms(ms: number): string {
6742
if (!isFinite(ms))

packages/playwright/src/reporters/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import * as path from 'path';
1818

1919
import { getPackageManagerExecCommand } from 'playwright-core/lib/utils';
20-
import { colors as realColors, ms as milliseconds, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';
20+
import { parseStackTraceLine } from 'playwright-core/lib/utils';
21+
import { colors as realColors, ms as milliseconds } from 'playwright-core/lib/utilsBundle';
2122

2223
import { resolveReporterOutputPath } from '../util';
2324
import { getEastAsianWidth } from '../utilsBundle';

packages/playwright/src/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import util from 'util';
2121

2222
import { sanitizeForFilePath } from 'playwright-core/lib/server';
2323
import { calculateSha1, formatCallLog, isRegExp, isString, stringifyStackFrames } from 'playwright-core/lib/utils';
24-
import { debug, mime, minimatch, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';
24+
import { parseStackTraceLine } from 'playwright-core/lib/utils';
25+
import { debug, mime, minimatch } from 'playwright-core/lib/utilsBundle';
2526

2627
import type { Location } from './../types/testReporter';
2728
import type { TestInfoErrorImpl } from './common/ipc';

0 commit comments

Comments
 (0)