mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-08-28 13:50:53 +02:00
adding mermaid packages
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
../@puppeteer/browsers/lib/cjs/main-cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../extract-zip/cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../gitbook-cli/bin/gitbook.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../image-size/bin/image-size.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../js-yaml/bin/js-yaml.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../mimer/bin/mimer
|
||||
+1
@@ -0,0 +1 @@
|
||||
../@mermaid-js/mermaid-cli/src/cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../npm/bin/npm-cli.js
|
||||
+1
@@ -0,0 +1 @@
|
||||
../semver/bin/semver
|
||||
+6368
File diff suppressed because it is too large
Load Diff
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# @babel/code-frame
|
||||
|
||||
> Generate errors that contain a code frame that point to source locations.
|
||||
|
||||
See our website [@babel/code-frame](https://babeljs.io/docs/babel-code-frame) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/code-frame
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/code-frame --dev
|
||||
```
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var picocolors = require('picocolors');
|
||||
var jsTokens = require('js-tokens');
|
||||
var helperValidatorIdentifier = require('@babel/helper-validator-identifier');
|
||||
|
||||
function isColorSupported() {
|
||||
return (typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? false : picocolors.isColorSupported
|
||||
);
|
||||
}
|
||||
const compose = (f, g) => v => f(g(v));
|
||||
function buildDefs(colors) {
|
||||
return {
|
||||
keyword: colors.cyan,
|
||||
capitalized: colors.yellow,
|
||||
jsxIdentifier: colors.yellow,
|
||||
punctuator: colors.yellow,
|
||||
number: colors.magenta,
|
||||
string: colors.green,
|
||||
regex: colors.magenta,
|
||||
comment: colors.gray,
|
||||
invalid: compose(compose(colors.white, colors.bgRed), colors.bold),
|
||||
gutter: colors.gray,
|
||||
marker: compose(colors.red, colors.bold),
|
||||
message: compose(colors.red, colors.bold),
|
||||
reset: colors.reset
|
||||
};
|
||||
}
|
||||
const defsOn = buildDefs(picocolors.createColors(true));
|
||||
const defsOff = buildDefs(picocolors.createColors(false));
|
||||
function getDefs(enabled) {
|
||||
return enabled ? defsOn : defsOff;
|
||||
}
|
||||
|
||||
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
|
||||
const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
|
||||
const BRACKET = /^[()[\]{}]$/;
|
||||
let tokenize;
|
||||
const JSX_TAG = /^[a-z][\w-]*$/i;
|
||||
const getTokenType = function (token, offset, text) {
|
||||
if (token.type === "name") {
|
||||
const tokenValue = token.value;
|
||||
if (helperValidatorIdentifier.isKeyword(tokenValue) || helperValidatorIdentifier.isStrictReservedWord(tokenValue, true) || sometimesKeywords.has(tokenValue)) {
|
||||
return "keyword";
|
||||
}
|
||||
if (JSX_TAG.test(tokenValue) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) {
|
||||
return "jsxIdentifier";
|
||||
}
|
||||
const firstChar = String.fromCodePoint(tokenValue.codePointAt(0));
|
||||
if (firstChar !== firstChar.toLowerCase()) {
|
||||
return "capitalized";
|
||||
}
|
||||
}
|
||||
if (token.type === "punctuator" && BRACKET.test(token.value)) {
|
||||
return "bracket";
|
||||
}
|
||||
if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
|
||||
return "punctuator";
|
||||
}
|
||||
return token.type;
|
||||
};
|
||||
tokenize = function* (text) {
|
||||
let match;
|
||||
while (match = jsTokens.default.exec(text)) {
|
||||
const token = jsTokens.matchToToken(match);
|
||||
yield {
|
||||
type: getTokenType(token, match.index, text),
|
||||
value: token.value
|
||||
};
|
||||
}
|
||||
};
|
||||
function highlight(text) {
|
||||
if (text === "") return "";
|
||||
const defs = getDefs(true);
|
||||
let highlighted = "";
|
||||
for (const {
|
||||
type,
|
||||
value
|
||||
} of tokenize(text)) {
|
||||
if (type in defs) {
|
||||
highlighted += value.split(NEWLINE$1).map(str => defs[type](str)).join("\n");
|
||||
} else {
|
||||
highlighted += value;
|
||||
}
|
||||
}
|
||||
return highlighted;
|
||||
}
|
||||
|
||||
let deprecationWarningShown = false;
|
||||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
||||
function getMarkerLines(loc, source, opts) {
|
||||
const startLoc = Object.assign({
|
||||
column: 0,
|
||||
line: -1
|
||||
}, loc.start);
|
||||
const endLoc = Object.assign({}, startLoc, loc.end);
|
||||
const {
|
||||
linesAbove = 2,
|
||||
linesBelow = 3
|
||||
} = opts || {};
|
||||
const startLine = startLoc.line;
|
||||
const startColumn = startLoc.column;
|
||||
const endLine = endLoc.line;
|
||||
const endColumn = endLoc.column;
|
||||
let start = Math.max(startLine - (linesAbove + 1), 0);
|
||||
let end = Math.min(source.length, endLine + linesBelow);
|
||||
if (startLine === -1) {
|
||||
start = 0;
|
||||
}
|
||||
if (endLine === -1) {
|
||||
end = source.length;
|
||||
}
|
||||
const lineDiff = endLine - startLine;
|
||||
const markerLines = {};
|
||||
if (lineDiff) {
|
||||
for (let i = 0; i <= lineDiff; i++) {
|
||||
const lineNumber = i + startLine;
|
||||
if (!startColumn) {
|
||||
markerLines[lineNumber] = true;
|
||||
} else if (i === 0) {
|
||||
const sourceLength = source[lineNumber - 1].length;
|
||||
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
||||
} else if (i === lineDiff) {
|
||||
markerLines[lineNumber] = [0, endColumn];
|
||||
} else {
|
||||
const sourceLength = source[lineNumber - i].length;
|
||||
markerLines[lineNumber] = [0, sourceLength];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (startColumn === endColumn) {
|
||||
if (startColumn) {
|
||||
markerLines[startLine] = [startColumn, 0];
|
||||
} else {
|
||||
markerLines[startLine] = true;
|
||||
}
|
||||
} else {
|
||||
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
||||
}
|
||||
}
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
markerLines
|
||||
};
|
||||
}
|
||||
function codeFrameColumns(rawLines, loc, opts = {}) {
|
||||
const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode;
|
||||
const defs = getDefs(shouldHighlight);
|
||||
const lines = rawLines.split(NEWLINE);
|
||||
const {
|
||||
start,
|
||||
end,
|
||||
markerLines
|
||||
} = getMarkerLines(loc, lines, opts);
|
||||
const hasColumns = loc.start && typeof loc.start.column === "number";
|
||||
const numberMaxWidth = String(end).length;
|
||||
const highlightedLines = shouldHighlight ? highlight(rawLines) : rawLines;
|
||||
let frame = highlightedLines.split(NEWLINE, end).slice(start, end).map((line, index) => {
|
||||
const number = start + 1 + index;
|
||||
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
||||
const gutter = ` ${paddedNumber} |`;
|
||||
const hasMarker = markerLines[number];
|
||||
const lastMarkerLine = !markerLines[number + 1];
|
||||
if (hasMarker) {
|
||||
let markerLine = "";
|
||||
if (Array.isArray(hasMarker)) {
|
||||
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
||||
const numberOfMarkers = hasMarker[1] || 1;
|
||||
markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join("");
|
||||
if (lastMarkerLine && opts.message) {
|
||||
markerLine += " " + defs.message(opts.message);
|
||||
}
|
||||
}
|
||||
return [defs.marker(">"), defs.gutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
||||
} else {
|
||||
return ` ${defs.gutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
|
||||
}
|
||||
}).join("\n");
|
||||
if (opts.message && !hasColumns) {
|
||||
frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
|
||||
}
|
||||
if (shouldHighlight) {
|
||||
return defs.reset(frame);
|
||||
} else {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
function index (rawLines, lineNumber, colNumber, opts = {}) {
|
||||
if (!deprecationWarningShown) {
|
||||
deprecationWarningShown = true;
|
||||
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
|
||||
if (process.emitWarning) {
|
||||
process.emitWarning(message, "DeprecationWarning");
|
||||
} else {
|
||||
const deprecationError = new Error(message);
|
||||
deprecationError.name = "DeprecationWarning";
|
||||
console.warn(new Error(message));
|
||||
}
|
||||
}
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
const location = {
|
||||
start: {
|
||||
column: colNumber,
|
||||
line: lineNumber
|
||||
}
|
||||
};
|
||||
return codeFrameColumns(rawLines, location, opts);
|
||||
}
|
||||
|
||||
exports.codeFrameColumns = codeFrameColumns;
|
||||
exports.default = index;
|
||||
exports.highlight = highlight;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+32
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@babel/code-frame",
|
||||
"version": "7.28.6",
|
||||
"description": "Generate errors that contain a code frame that point to source locations.",
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-code-frame",
|
||||
"bugs": "https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-code-frame"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"dependencies": {
|
||||
"@babel/helper-validator-identifier": "^7.28.5",
|
||||
"js-tokens": "^4.0.0",
|
||||
"picocolors": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"charcodes": "^0.2.0",
|
||||
"import-meta-resolve": "^4.1.0",
|
||||
"strip-ansi": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"type": "commonjs"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# @babel/helper-validator-identifier
|
||||
|
||||
> Validate identifier/keywords name
|
||||
|
||||
See our website [@babel/helper-validator-identifier](https://babeljs.io/docs/babel-helper-validator-identifier) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save @babel/helper-validator-identifier
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-validator-identifier
|
||||
```
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isIdentifierChar = isIdentifierChar;
|
||||
exports.isIdentifierName = isIdentifierName;
|
||||
exports.isIdentifierStart = isIdentifierStart;
|
||||
let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088f\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5c\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdc-\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7dc\ua7f1-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
|
||||
let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1add\u1ae0-\u1aeb\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
|
||||
const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
||||
const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
||||
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
||||
const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 7, 25, 39, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 5, 57, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 24, 43, 261, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 33, 24, 3, 24, 45, 74, 6, 0, 67, 12, 65, 1, 2, 0, 15, 4, 10, 7381, 42, 31, 98, 114, 8702, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 208, 30, 2, 2, 2, 1, 2, 6, 3, 4, 10, 1, 225, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4381, 3, 5773, 3, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 8489];
|
||||
const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 78, 5, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 199, 7, 137, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 55, 9, 266, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 233, 0, 3, 0, 8, 1, 6, 0, 475, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
||||
function isInAstralSet(code, set) {
|
||||
let pos = 0x10000;
|
||||
for (let i = 0, length = set.length; i < length; i += 2) {
|
||||
pos += set[i];
|
||||
if (pos > code) return false;
|
||||
pos += set[i + 1];
|
||||
if (pos >= code) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isIdentifierStart(code) {
|
||||
if (code < 65) return code === 36;
|
||||
if (code <= 90) return true;
|
||||
if (code < 97) return code === 95;
|
||||
if (code <= 122) return true;
|
||||
if (code <= 0xffff) {
|
||||
return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
||||
}
|
||||
return isInAstralSet(code, astralIdentifierStartCodes);
|
||||
}
|
||||
function isIdentifierChar(code) {
|
||||
if (code < 48) return code === 36;
|
||||
if (code < 58) return true;
|
||||
if (code < 65) return false;
|
||||
if (code <= 90) return true;
|
||||
if (code < 97) return code === 95;
|
||||
if (code <= 122) return true;
|
||||
if (code <= 0xffff) {
|
||||
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
||||
}
|
||||
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
||||
}
|
||||
function isIdentifierName(name) {
|
||||
let isFirst = true;
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
let cp = name.charCodeAt(i);
|
||||
if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) {
|
||||
const trail = name.charCodeAt(++i);
|
||||
if ((trail & 0xfc00) === 0xdc00) {
|
||||
cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
|
||||
}
|
||||
}
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
if (!isIdentifierStart(cp)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!isIdentifierChar(cp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !isFirst;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=identifier.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierChar", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierChar;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierName", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierName;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isIdentifierStart", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _identifier.isIdentifierStart;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isKeyword", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isKeyword;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictBindOnlyReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictBindReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictBindReservedWord;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "isStrictReservedWord", {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _keyword.isStrictReservedWord;
|
||||
}
|
||||
});
|
||||
var _identifier = require("./identifier.js");
|
||||
var _keyword = require("./keyword.js");
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_identifier","require","_keyword"],"sources":["../src/index.ts"],"sourcesContent":["export {\n isIdentifierName,\n isIdentifierChar,\n isIdentifierStart,\n} from \"./identifier.ts\";\nexport {\n isReservedWord,\n isStrictBindOnlyReservedWord,\n isStrictBindReservedWord,\n isStrictReservedWord,\n isKeyword,\n} from \"./keyword.ts\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA","ignoreList":[]}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.isKeyword = isKeyword;
|
||||
exports.isReservedWord = isReservedWord;
|
||||
exports.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
|
||||
exports.isStrictBindReservedWord = isStrictBindReservedWord;
|
||||
exports.isStrictReservedWord = isStrictReservedWord;
|
||||
const reservedWords = {
|
||||
keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
|
||||
strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
|
||||
strictBind: ["eval", "arguments"]
|
||||
};
|
||||
const keywords = new Set(reservedWords.keyword);
|
||||
const reservedWordsStrictSet = new Set(reservedWords.strict);
|
||||
const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
|
||||
function isReservedWord(word, inModule) {
|
||||
return inModule && word === "await" || word === "enum";
|
||||
}
|
||||
function isStrictReservedWord(word, inModule) {
|
||||
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
|
||||
}
|
||||
function isStrictBindOnlyReservedWord(word) {
|
||||
return reservedWordsStrictBindSet.has(word);
|
||||
}
|
||||
function isStrictBindReservedWord(word, inModule) {
|
||||
return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
|
||||
}
|
||||
function isKeyword(word) {
|
||||
return keywords.has(word);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=keyword.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["reservedWords","keyword","strict","strictBind","keywords","Set","reservedWordsStrictSet","reservedWordsStrictBindSet","isReservedWord","word","inModule","isStrictReservedWord","has","isStrictBindOnlyReservedWord","isStrictBindReservedWord","isKeyword"],"sources":["../src/keyword.ts"],"sourcesContent":["const reservedWords = {\n keyword: [\n \"break\",\n \"case\",\n \"catch\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"do\",\n \"else\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"return\",\n \"switch\",\n \"throw\",\n \"try\",\n \"var\",\n \"const\",\n \"while\",\n \"with\",\n \"new\",\n \"this\",\n \"super\",\n \"class\",\n \"extends\",\n \"export\",\n \"import\",\n \"null\",\n \"true\",\n \"false\",\n \"in\",\n \"instanceof\",\n \"typeof\",\n \"void\",\n \"delete\",\n ],\n strict: [\n \"implements\",\n \"interface\",\n \"let\",\n \"package\",\n \"private\",\n \"protected\",\n \"public\",\n \"static\",\n \"yield\",\n ],\n strictBind: [\"eval\", \"arguments\"],\n};\nconst keywords = new Set(reservedWords.keyword);\nconst reservedWordsStrictSet = new Set(reservedWords.strict);\nconst reservedWordsStrictBindSet = new Set(reservedWords.strictBind);\n\n/**\n * Checks if word is a reserved word in non-strict mode\n */\nexport function isReservedWord(word: string, inModule: boolean): boolean {\n return (inModule && word === \"await\") || word === \"enum\";\n}\n\n/**\n * Checks if word is a reserved word in non-binding strict mode\n *\n * Includes non-strict reserved words\n */\nexport function isStrictReservedWord(word: string, inModule: boolean): boolean {\n return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode, but it is allowed as\n * a normal identifier.\n */\nexport function isStrictBindOnlyReservedWord(word: string): boolean {\n return reservedWordsStrictBindSet.has(word);\n}\n\n/**\n * Checks if word is a reserved word in binding strict mode\n *\n * Includes non-strict reserved words and non-binding strict reserved words\n */\nexport function isStrictBindReservedWord(\n word: string,\n inModule: boolean,\n): boolean {\n return (\n isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word)\n );\n}\n\nexport function isKeyword(word: string): boolean {\n return keywords.has(word);\n}\n"],"mappings":";;;;;;;;;;AAAA,MAAMA,aAAa,GAAG;EACpBC,OAAO,EAAE,CACP,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,EACV,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,QAAQ,CACT;EACDC,MAAM,EAAE,CACN,YAAY,EACZ,WAAW,EACX,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,OAAO,CACR;EACDC,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW;AAClC,CAAC;AACD,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAACL,aAAa,CAACC,OAAO,CAAC;AAC/C,MAAMK,sBAAsB,GAAG,IAAID,GAAG,CAACL,aAAa,CAACE,MAAM,CAAC;AAC5D,MAAMK,0BAA0B,GAAG,IAAIF,GAAG,CAACL,aAAa,CAACG,UAAU,CAAC;AAK7D,SAASK,cAAcA,CAACC,IAAY,EAAEC,QAAiB,EAAW;EACvE,OAAQA,QAAQ,IAAID,IAAI,KAAK,OAAO,IAAKA,IAAI,KAAK,MAAM;AAC1D;AAOO,SAASE,oBAAoBA,CAACF,IAAY,EAAEC,QAAiB,EAAW;EAC7E,OAAOF,cAAc,CAACC,IAAI,EAAEC,QAAQ,CAAC,IAAIJ,sBAAsB,CAACM,GAAG,CAACH,IAAI,CAAC;AAC3E;AAMO,SAASI,4BAA4BA,CAACJ,IAAY,EAAW;EAClE,OAAOF,0BAA0B,CAACK,GAAG,CAACH,IAAI,CAAC;AAC7C;AAOO,SAASK,wBAAwBA,CACtCL,IAAY,EACZC,QAAiB,EACR;EACT,OACEC,oBAAoB,CAACF,IAAI,EAAEC,QAAQ,CAAC,IAAIG,4BAA4B,CAACJ,IAAI,CAAC;AAE9E;AAEO,SAASM,SAASA,CAACN,IAAY,EAAW;EAC/C,OAAOL,QAAQ,CAACQ,GAAG,CAACH,IAAI,CAAC;AAC3B","ignoreList":[]}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "@babel/helper-validator-identifier",
|
||||
"version": "7.28.5",
|
||||
"description": "Validate identifier/keywords name",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-validator-identifier"
|
||||
},
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "./lib/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@unicode/unicode-17.0.0": "^1.6.10",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"author": "The Babel Team (https://babel.dev/team)",
|
||||
"type": "commonjs"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2020 Tyler Long
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
# mermaid-cli
|
||||
|
||||
[](https://www.npmjs.com/package/@mermaid-js/mermaid-cli)
|
||||
[](https://www.npmjs.com/package/@mermaid-js/mermaid-cli)
|
||||
[](https://hub.docker.com/r/minlag/mermaid-cli)
|
||||
[](https://github.com/mermaid-js/mermaid-cli/actions/workflows/compile-mermaid.yml)
|
||||
[](https://percy.io/Mermaid/mermaid-cli)
|
||||
[](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE)
|
||||
|
||||
This is a command-line interface (CLI) for [mermaid](https://mermaid-js.github.io/). It takes a mermaid definition file as input and generates an svg/png/pdf file as output.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install -g @mermaid-js/mermaid-cli
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Convert Mermaid mmd Diagram File To SVG
|
||||
|
||||
```sh
|
||||
mmdc -i input.mmd -o output.svg
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> See [Alternative installations](#alternative-installations) if you don't want to install the package globally.
|
||||
>
|
||||
> Locate how to call the mmdc executable for your preferred method
|
||||
> i.e. Docker, Yarn, NPM, local install, etc.
|
||||
|
||||
## Examples
|
||||
|
||||
### Create A PNG With A Dark Theme And Transparent Background
|
||||
|
||||
```sh
|
||||
mmdc -i input.mmd -o output.png -t dark -b transparent
|
||||
```
|
||||
|
||||
### Animating an SVG file with custom CSS
|
||||
|
||||
The `--cssFile` option can be used to inline some custom CSS.
|
||||
|
||||
Please see [./test-positive/flowchart1.css](test-positive/flowchart1.css) for an example of a CSS file that has animations.
|
||||
|
||||
**Warning**: If you want to override `mermaid`'s [`themeCSS`](https://mermaid-js.github.io/mermaid/#/Setup?id=theme), we recommend instead adding `{"themeCSS": "..."})` to your mermaid `--configFile`. You may also need to use [`!important`](https://developer.mozilla.org/en-US/docs/Web/CSS/important) to override mermiad's `themeCSS`.
|
||||
|
||||
**Warning**: Inline CSS files may be blocked by your browser, depending on the [HTTP Content-Security-Policy header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) of the website that hosts your SVG.
|
||||
|
||||
```sh
|
||||
mmdc --input test-positive/flowchart1.mmd --cssFile test-positive/flowchart1.css -o docs/animated-flowchart.svg
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Example output: docs/animated-flowchart.svg</summary>
|
||||
|
||||

|
||||
</details>
|
||||
|
||||
### Transform a markdown file with mermaid diagrams
|
||||
|
||||
```sh
|
||||
mmdc -i readme.template.md -o readme.md
|
||||
```
|
||||
|
||||
This command transforms a markdown file itself. The mermaid-cli will find the mermaid diagrams, create SVG files from them and refer to those in the markdown output.
|
||||
|
||||
This:
|
||||
|
||||
~~~md
|
||||
### Some markdown
|
||||
```mermaid
|
||||
graph
|
||||
[....]
|
||||
```
|
||||
|
||||
### Some more markdown
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
[....]
|
||||
```
|
||||
|
||||
### Mermaid with custom title/desc
|
||||
```mermaid
|
||||
graph
|
||||
accTitle: My title here
|
||||
accDescr: My description here
|
||||
A-->B
|
||||
```
|
||||
~~~
|
||||
|
||||
Becomes:
|
||||
|
||||
```md
|
||||
### Some markdown
|
||||

|
||||
|
||||
### Some more markdown
|
||||

|
||||
|
||||
### Mermaid with custom title/desc
|
||||

|
||||
```
|
||||
|
||||
### Piping from stdin
|
||||
|
||||
You can easily pipe input from stdin. This example shows how to use a heredoc to
|
||||
send a diagram as stdin to mermaid-cli (mmdc).
|
||||
|
||||
```sh
|
||||
cat << EOF | mmdc --input -
|
||||
graph TD
|
||||
A[Client] --> B[Load Balancer]
|
||||
EOF
|
||||
```
|
||||
|
||||
### See All Available Options
|
||||
|
||||
```sh
|
||||
mmdc -h
|
||||
```
|
||||
|
||||
# Alternative installations
|
||||
|
||||
## Use Docker:
|
||||
|
||||
```sh
|
||||
docker pull minlag/mermaid-cli
|
||||
```
|
||||
|
||||
or pull from Github Container Registry
|
||||
|
||||
```sh
|
||||
docker pull ghcr.io/mermaid-js/mermaid-cli/mermaid-cli
|
||||
```
|
||||
|
||||
or e.g. version 8.8.0
|
||||
|
||||
```sh
|
||||
docker pull minlag/mermaid-cli:8.8.0
|
||||
```
|
||||
|
||||
The container looks for input files in `/data`. So for example, if you have a
|
||||
diagram defined on your system in `/path/to/diagrams/diagram.mmd`, you can use
|
||||
the container to generate an SVG file as follows:
|
||||
|
||||
```sh
|
||||
docker run --rm -u `id -u`:`id -g` -v /path/to/diagrams:/data minlag/mermaid-cli -i diagram.mmd
|
||||
```
|
||||
|
||||
In previous version, the input files were mounted in `/home/mermaidcli`. You can
|
||||
restore this behaviour with the `--workdir` option:
|
||||
|
||||
```sh
|
||||
docker run [...] --workdir=/home/mermaidcli minlag/mermaid-cli [...]
|
||||
```
|
||||
|
||||
|
||||
## Use Node.JS API
|
||||
|
||||
It's possible to call `mermaid-cli` via a Node.JS API.
|
||||
Please be aware that **the NodeJS API is not covered by semver**, as `mermaid-cli` follows
|
||||
`mermaid`'s versioning.
|
||||
|
||||
```js
|
||||
import { run } from "@mermaid-js/mermaid-cli"
|
||||
|
||||
await run(
|
||||
"input.mmd", "output.svg", // {optional options},
|
||||
)
|
||||
```
|
||||
|
||||
## Install locally
|
||||
|
||||
Some people are [having issues](https://github.com/mermaidjs/mermaid.cli/issues/15)
|
||||
installing this tool globally. Installing it locally is an alternative solution:
|
||||
|
||||
```
|
||||
yarn add @mermaid-js/mermaid-cli
|
||||
./node_modules/.bin/mmdc -h
|
||||
```
|
||||
|
||||
Or use NPM:
|
||||
|
||||
```
|
||||
npm install @mermaid-js/mermaid-cli
|
||||
./node_modules/.bin/mmdc -h
|
||||
```
|
||||
|
||||
### Run with npx
|
||||
|
||||
[`npx`](https://www.npmjs.com/package/npx) is installed by default with NPM. It
|
||||
downloads and runs commands at the same time. To use Mermaid CLI with npx, you
|
||||
need to use the `-p` flag because the package name is different than the command
|
||||
it installs (`mmdc`). `npx -p @mermaid-js/mermaid-cli mmdc -h`
|
||||
|
||||
|
||||
## Install with [brew](https://brew.sh)
|
||||
|
||||
> **Warning**
|
||||
>
|
||||
> This method of installation is no longer supported.
|
||||
> For more details, see the [discussion](https://github.com/mermaid-js/mermaid-cli/issues/288).
|
||||
> An old version of mermaid-cli can be installed with brew.
|
||||
> ```sh
|
||||
> brew install mermaid-cli
|
||||
> ```
|
||||
|
||||
|
||||
## Known issues
|
||||
|
||||
1. [Linux sandbox issue](docs/linux-sandbox-issue.md)
|
||||
2. [Docker permission denied issue](docs/docker-permission-denied.md)
|
||||
3. [How to setup up mermaid to use already installed chromium?](docs/already-installed-chromium.md)
|
||||
|
||||
## For contributors
|
||||
|
||||
Contributions are welcome. See the [contribution guide](CONTRIBUTING.md).
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "@mermaid-js/mermaid-cli",
|
||||
"version": "9.4.0",
|
||||
"description": "Command-line interface for mermaid",
|
||||
"license": "MIT",
|
||||
"repository": "git@github.com:mermaid-js/mermaid-cli.git",
|
||||
"type": "module",
|
||||
"author": "Tyler Long <tyler4long@gmail.com>",
|
||||
"bin": {
|
||||
"mmdc": "./src/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^14.13 || >=16.0"
|
||||
},
|
||||
"exports": "./src/index.js",
|
||||
"scripts": {
|
||||
"prepare": "vite build",
|
||||
"prepack": "vite build",
|
||||
"test": "standard && yarn node --experimental-vm-modules $(yarn bin jest)",
|
||||
"lint": "standard",
|
||||
"lint-fix": "standard --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^5.0.1",
|
||||
"commander": "^10.0.0",
|
||||
"puppeteer": "^19.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fortawesome/fontawesome-free-webfonts": "^1.0.9",
|
||||
"@mermaid-js/mermaid-mindmap": "^9.2.2",
|
||||
"mermaid": "^9.2.2",
|
||||
"jest": "^29.0.1",
|
||||
"standard": "^17.0.0",
|
||||
"vite": "^4.0.3",
|
||||
"vite-plugin-singlefile": "^0.13.1",
|
||||
"vite-svg-loader": "^4.0.0",
|
||||
"yarn-upgrade-all": "^0.7.0"
|
||||
},
|
||||
"files": [
|
||||
"src/",
|
||||
"dist/"
|
||||
],
|
||||
"jest": {
|
||||
"moduleNameMapper": {
|
||||
"#(.*)": "<rootDir>/node_modules/$1"
|
||||
}
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"/dist/"
|
||||
]
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { cli, error } from './index.js'
|
||||
|
||||
process.title = 'mmdc'
|
||||
cli().catch((exception) => error(exception instanceof Error ? exception.stack : exception))
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
import { Command, Option, InvalidArgumentError } from 'commander'
|
||||
import chalk from 'chalk'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import puppeteer from 'puppeteer'
|
||||
import url from 'url'
|
||||
|
||||
// importing JSON is still experimental in Node.JS https://nodejs.org/docs/latest-v16.x/api/esm.html#json-modules
|
||||
import { createRequire } from 'module'
|
||||
const require = createRequire(import.meta.url)
|
||||
const pkg = require('../package.json')
|
||||
// __dirname is not available in ESM modules by default
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const error = message => {
|
||||
console.error(chalk.red(`\n${message}\n`))
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const warn = message => {
|
||||
console.warn(chalk.yellow(`\n${message}\n`))
|
||||
}
|
||||
|
||||
const checkConfigFile = file => {
|
||||
if (!fs.existsSync(file)) {
|
||||
error(`Configuration file "${file}" doesn't exist`)
|
||||
}
|
||||
}
|
||||
|
||||
const getInputData = async inputFile => new Promise((resolve, reject) => {
|
||||
// if an input file has been specified using '-i', it takes precedence over
|
||||
// piping from stdin
|
||||
if (typeof inputFile !== 'undefined') {
|
||||
return fs.readFile(inputFile, 'utf-8', (err, data) => {
|
||||
if (err) {
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
return resolve(data)
|
||||
})
|
||||
}
|
||||
|
||||
let data = ''
|
||||
process.stdin.on('readable', function () {
|
||||
const chunk = this.read()
|
||||
|
||||
if (chunk !== null) {
|
||||
data += chunk
|
||||
}
|
||||
})
|
||||
|
||||
process.stdin.on('error', function (err) {
|
||||
reject(err)
|
||||
})
|
||||
|
||||
process.stdin.on('end', function () {
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Commander parser that converts a string to an integer.
|
||||
*
|
||||
* @param {string} value - The value from commander.
|
||||
* @param {*} _unused - Unused.
|
||||
* @returns {number} The value parsed as a number.
|
||||
* @throws {InvalidArgumentError} If the arg is not valid.
|
||||
* @see https://github.com/tj/commander.js/wiki/Class:-Option#argparserfn
|
||||
*/
|
||||
function parseCommanderInt (value, _unused) {
|
||||
const parsedValue = parseInt(value, 10)
|
||||
if (isNaN(parsedValue) || parsedValue < 1) {
|
||||
throw new InvalidArgumentError('Not an positive integer.')
|
||||
}
|
||||
return parsedValue
|
||||
}
|
||||
|
||||
async function cli () {
|
||||
const commander = new Command()
|
||||
commander
|
||||
.version(pkg.version)
|
||||
.addOption(new Option('-t, --theme [theme]', 'Theme of the chart').choices(['default', 'forest', 'dark', 'neutral']).default('default'))
|
||||
.addOption(new Option('-w, --width [width]', 'Width of the page').argParser(parseCommanderInt).default(800))
|
||||
.addOption(new Option('-H, --height [height]', 'Height of the page').argParser(parseCommanderInt).default(600))
|
||||
.option('-i, --input <input>', 'Input mermaid file. Files ending in .md will be treated as Markdown and all charts (e.g. ```mermaid (...)```) will be extracted and generated. Use `-` to read from stdin.')
|
||||
.option('-o, --output [output]', 'Output file. It should be either md, svg, png or pdf. Optional. Default: input + ".svg"')
|
||||
.addOption(new Option('-e, --outputFormat [format]', 'Output format for the generated image.').choices(['svg', 'png', 'pdf']).default(null, 'Loaded from the output file extension'))
|
||||
.addOption(new Option('-b, --backgroundColor [backgroundColor]', 'Background color for pngs/svgs (not pdfs). Example: transparent, red, \'#F0F0F0\'.').default('white'))
|
||||
.option('-c, --configFile [configFile]', 'JSON configuration file for mermaid.')
|
||||
.option('-C, --cssFile [cssFile]', 'CSS file for the page.')
|
||||
.addOption(new Option('-s, --scale [scale]', 'Puppeteer scale factor').argParser(parseCommanderInt).default(1))
|
||||
.option('-f, --pdfFit [pdfFit]', 'Scale PDF to fit chart')
|
||||
.option('-q, --quiet', 'Suppress log output')
|
||||
.option('-p --puppeteerConfigFile [puppeteerConfigFile]', 'JSON configuration file for puppeteer.')
|
||||
.parse(process.argv)
|
||||
|
||||
const options = commander.opts()
|
||||
|
||||
let { theme, width, height, input, output, outputFormat, backgroundColor, configFile, cssFile, puppeteerConfigFile, scale, pdfFit, quiet } = options
|
||||
|
||||
// check input file
|
||||
if (!input) {
|
||||
warn('No input file specfied, reading from stdin. ' +
|
||||
'If you want to specify an input file, please use `-i <input>.` ' +
|
||||
'You can use `-i -` to read from stdin and to suppress this warning.'
|
||||
)
|
||||
} else if (input === '-') {
|
||||
// `--input -` means read from stdin, but suppress the above warning
|
||||
input = undefined
|
||||
} else if (!fs.existsSync(input)) {
|
||||
error(`Input file "${input}" doesn't exist`)
|
||||
}
|
||||
|
||||
// check output file
|
||||
if (!output) {
|
||||
// if an input file is defined, it should take precedence, otherwise, input is
|
||||
// coming from stdin and just name the file out.svg, if it hasn't been
|
||||
// specified with the '-o' option
|
||||
if (outputFormat) {
|
||||
output = input ? (`${input}.${outputFormat}`) : `out.${outputFormat}`
|
||||
} else {
|
||||
output = input ? (`${input}.svg`) : 'out.svg'
|
||||
}
|
||||
}
|
||||
if (!/\.(?:svg|png|pdf|md|markdown)$/.test(output)) {
|
||||
error('Output file must end with ".md"/".markdown", ".svg", ".png" or ".pdf"')
|
||||
}
|
||||
const outputDir = path.dirname(output)
|
||||
if (!fs.existsSync(outputDir)) {
|
||||
error(`Output directory "${outputDir}/" doesn't exist`)
|
||||
}
|
||||
|
||||
// check config files
|
||||
let mermaidConfig = { theme }
|
||||
if (configFile) {
|
||||
checkConfigFile(configFile)
|
||||
mermaidConfig = Object.assign(mermaidConfig, JSON.parse(fs.readFileSync(configFile, 'utf-8')))
|
||||
}
|
||||
let puppeteerConfig = {}
|
||||
if (puppeteerConfigFile) {
|
||||
checkConfigFile(puppeteerConfigFile)
|
||||
puppeteerConfig = JSON.parse(fs.readFileSync(puppeteerConfigFile, 'utf-8'))
|
||||
}
|
||||
|
||||
// check cssFile
|
||||
let myCSS
|
||||
if (cssFile) {
|
||||
if (!fs.existsSync(cssFile)) {
|
||||
error(`CSS file "${cssFile}" doesn't exist`)
|
||||
}
|
||||
myCSS = fs.readFileSync(cssFile, 'utf-8')
|
||||
}
|
||||
|
||||
await run(
|
||||
input, output, {
|
||||
puppeteerConfig,
|
||||
quiet,
|
||||
outputFormat,
|
||||
parseMMDOptions: {
|
||||
mermaidConfig, backgroundColor, myCSS, pdfFit, viewport: { width, height, deviceScaleFactor: scale }
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} ParseMDDOptions Options to pass to {@link parseMMD}
|
||||
* @property {puppeteer.Viewport} [viewport] - Puppeteer viewport (e.g. `width`, `height`, `deviceScaleFactor`)
|
||||
* @property {string | "transparent"} [backgroundColor] - Background color.
|
||||
* @property {Parameters<import("mermaid").Mermaid["initialize"]>[0]} [mermaidConfig] - Mermaid config.
|
||||
* @property {CSSStyleDeclaration["cssText"]} [myCSS] - Optional CSS text.
|
||||
* @property {boolean} pdfFit - If set, scale PDF to fit chart.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse and render a mermaid diagram.
|
||||
*
|
||||
* @deprecated Prefer {@link renderMermaid}, as it also returns useful metadata.
|
||||
*
|
||||
* @param {puppeteer.Browser} browser - Puppeteer Browser
|
||||
* @param {string} definition - Mermaid diagram definition
|
||||
* @param {"svg" | "png" | "pdf"} outputFormat - Mermaid output format.
|
||||
* @param {ParseMDDOptions} [opt] - Options, see {@link ParseMDDOptions} for details.
|
||||
*
|
||||
* @returns {Promise<Buffer>} The output file in bytes.
|
||||
*/
|
||||
async function parseMMD (...args) {
|
||||
const { data } = await renderMermaid(...args)
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a mermaid diagram.
|
||||
*
|
||||
* @param {puppeteer.Browser} browser - Puppeteer Browser
|
||||
* @param {string} definition - Mermaid diagram definition
|
||||
* @param {"svg" | "png" | "pdf"} outputFormat - Mermaid output format.
|
||||
* @param {ParseMDDOptions} [opt] - Options, see {@link ParseMDDOptions} for details.
|
||||
* @returns {Promise<{title?: string, desc?: string, data: Buffer}>} The output file in bytes,
|
||||
* with optional metadata.
|
||||
*/
|
||||
async function renderMermaid (browser, definition, outputFormat, { viewport, backgroundColor = 'white', mermaidConfig = {}, myCSS, pdfFit } = {}) {
|
||||
const page = await browser.newPage()
|
||||
page.on('console', (msg) => {
|
||||
console.log(msg.text())
|
||||
})
|
||||
try {
|
||||
if (viewport) {
|
||||
await page.setViewport(viewport)
|
||||
}
|
||||
const mermaidHTMLPath = path.join(__dirname, '..', 'dist', 'index.html')
|
||||
await page.goto(url.pathToFileURL(mermaidHTMLPath))
|
||||
await page.$eval('body', (body, backgroundColor) => {
|
||||
body.style.background = backgroundColor
|
||||
}, backgroundColor)
|
||||
const metadata = await page.$eval('#container', async (container, definition, mermaidConfig, myCSS, backgroundColor) => {
|
||||
container.textContent = definition
|
||||
|
||||
/** @type {import("mermaid")} Already imported mermaid instance */
|
||||
const mermaid = globalThis.mermaid
|
||||
/** @type {import("@mermaid-js/mermaid-mindmap")} */
|
||||
const mermaidMindmap = globalThis.mermaidMindmap
|
||||
|
||||
await mermaid.registerExternalDiagrams([mermaidMindmap])
|
||||
|
||||
mermaid.initialize(mermaidConfig)
|
||||
// should throw an error if mmd diagram is invalid
|
||||
try {
|
||||
await mermaid.initThrowsErrorsAsync(undefined, container)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
// mermaid-js doesn't currently throws JS Errors, but let's leave this
|
||||
// here in case it does in the future
|
||||
throw error
|
||||
} else {
|
||||
throw new Error(error?.message ?? 'Unknown mermaid render error')
|
||||
}
|
||||
}
|
||||
|
||||
const svg = container.getElementsByTagName?.('svg')?.[0]
|
||||
if (svg?.style) {
|
||||
svg.style.backgroundColor = backgroundColor
|
||||
} else {
|
||||
warn('svg not found. Not applying background color.')
|
||||
}
|
||||
if (myCSS) {
|
||||
// add CSS as a <svg>...<style>... element
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/API/SVGStyleElement
|
||||
const style = document.createElementNS('http://www.w3.org/2000/svg', 'style')
|
||||
style.appendChild(document.createTextNode(myCSS))
|
||||
svg.appendChild(style)
|
||||
}
|
||||
|
||||
// Finds SVG metadata for accessibility purposes
|
||||
/** SVG title */
|
||||
let title = null
|
||||
// If <title> exists, it must be the first child Node,
|
||||
// see https://www.w3.org/TR/SVG11/struct.html#DescriptionAndTitleElements
|
||||
/* global SVGTitleElement, SVGDescElement */ // These exist in browser-based code
|
||||
if (svg.firstChild instanceof SVGTitleElement) {
|
||||
title = svg.firstChild.textContent
|
||||
}
|
||||
/** SVG description. According to SVG spec, we should use the first one we find */
|
||||
let desc = null
|
||||
for (const svgNode of svg.children) {
|
||||
if (svgNode instanceof SVGDescElement) {
|
||||
desc = svgNode.textContent
|
||||
}
|
||||
}
|
||||
return {
|
||||
title, desc
|
||||
}
|
||||
}, definition, mermaidConfig, myCSS, backgroundColor)
|
||||
|
||||
if (outputFormat === 'svg') {
|
||||
const svgXML = await page.$eval('svg', (svg) => {
|
||||
// SVG might have HTML <foreignObject> that are not valid XML
|
||||
// E.g. <br> must be replaced with <br/>
|
||||
// Luckily the DOM Web API has the XMLSerializer for this
|
||||
// eslint-disable-next-line no-undef
|
||||
const xmlSerializer = new XMLSerializer()
|
||||
return xmlSerializer.serializeToString(svg)
|
||||
})
|
||||
return {
|
||||
...metadata,
|
||||
data: Buffer.from(svgXML, 'utf8')
|
||||
}
|
||||
} else if (outputFormat === 'png') {
|
||||
const clip = await page.$eval('svg', svg => {
|
||||
const react = svg.getBoundingClientRect()
|
||||
return { x: Math.floor(react.left), y: Math.floor(react.top), width: Math.ceil(react.width), height: Math.ceil(react.height) }
|
||||
})
|
||||
await page.setViewport({ ...viewport, width: clip.x + clip.width, height: clip.y + clip.height })
|
||||
return {
|
||||
...metadata,
|
||||
data: await page.screenshot({ clip, omitBackground: backgroundColor === 'transparent' })
|
||||
}
|
||||
} else { // pdf
|
||||
if (pdfFit) {
|
||||
const clip = await page.$eval('svg', svg => {
|
||||
const react = svg.getBoundingClientRect()
|
||||
return { x: react.left, y: react.top, width: react.width, height: react.height }
|
||||
})
|
||||
return {
|
||||
...metadata,
|
||||
data: await page.pdf({
|
||||
omitBackground: backgroundColor === 'transparent',
|
||||
width: (Math.ceil(clip.width) + clip.x * 2) + 'px',
|
||||
height: (Math.ceil(clip.height) + clip.y * 2) + 'px',
|
||||
pageRanges: '1-1'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
...metadata,
|
||||
data: await page.pdf({
|
||||
omitBackground: backgroundColor === 'transparent'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await page.close()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a markdown image syntax.
|
||||
*
|
||||
* @param {object} params - Parameters.
|
||||
* @param {string} params.url - Path to image.
|
||||
* @param {string} params.alt - Image alt text, required.
|
||||
* @param {string} [params.title] - Image title text.
|
||||
* @returns {``} The markdown image text.
|
||||
*/
|
||||
function markdownImage ({ url, title, alt }) {
|
||||
// we can't use String.prototype.replaceAll since it's not supported in Node v14
|
||||
const altEscaped = alt.replace(/[[\]\\]/g, '\\$&')
|
||||
if (title) {
|
||||
const titleEscaped = title.replace(/["\\]/g, '\\$&')
|
||||
return ``
|
||||
} else {
|
||||
return ``
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a mermaid diagram or mermaid markdown file.
|
||||
*
|
||||
* @param {`${string}.${"md" | "markdown"}` | string} [input] - If this ends with `.md`/`.markdown`,
|
||||
* path to a markdown file containing mermaid.
|
||||
* If this is a string, loads the mermaid definition from the given file.
|
||||
* If this is `undefined`, loads the mermaid definition from stdin.
|
||||
* @param {`${string}.${"md" | "markdown" | "svg" | "png" | "pdf"}`} output - Path to the output file.
|
||||
* @param {Object} [opts] - Options
|
||||
* @param {puppeteer.LaunchOptions} [opts.puppeteerConfig] - Puppeteer launch options.
|
||||
* @param {boolean} [opts.quiet] - If set, suppress log output.
|
||||
* @param {"svg" | "png" | "pdf"} [opts.outputFormat] - Mermaid output format.
|
||||
* Defaults to `output` extension. Overrides `output` extension if set.
|
||||
* @param {ParseMDDOptions} [opts.parseMMDOptions] - Options to pass to {@link parseMMDOptions}.
|
||||
*/
|
||||
async function run (input, output, { puppeteerConfig = {}, quiet = false, outputFormat, parseMMDOptions } = {}) {
|
||||
const info = message => {
|
||||
if (!quiet) {
|
||||
console.info(message)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: should we use a Markdown parser like remark instead of rolling our own parser?
|
||||
const mermaidChartsInMarkdown = /^[^\S\n]*```(?:mermaid)(\r?\n([\s\S]*?))```[^\S\n]*$/
|
||||
const mermaidChartsInMarkdownRegexGlobal = new RegExp(mermaidChartsInMarkdown, 'gm')
|
||||
const browser = await puppeteer.launch(puppeteerConfig)
|
||||
try {
|
||||
if (!outputFormat) {
|
||||
outputFormat = path.extname(output).replace('.', '')
|
||||
}
|
||||
if (outputFormat === 'md' || outputFormat === 'markdown') {
|
||||
// fallback to svg in case no outputFormat is given and output file is MD
|
||||
outputFormat = 'svg'
|
||||
}
|
||||
if (!/(?:svg|png|pdf)$/.test(outputFormat)) {
|
||||
throw new Error('Output format must be one of "svg", "png" or "pdf"')
|
||||
}
|
||||
|
||||
const definition = await getInputData(input)
|
||||
if (/\.(md|markdown)$/.test(input)) {
|
||||
const imagePromises = []
|
||||
for (const mermaidCodeblockMatch of definition.matchAll(mermaidChartsInMarkdownRegexGlobal)) {
|
||||
const mermaidDefinition = mermaidCodeblockMatch[1]
|
||||
|
||||
// Output can be either a template image file, or a `.md` output file.
|
||||
// If it is a template image file, use that to created numbered diagrams
|
||||
// I.e. if "out.png", use "out-1.png", "out-2.png", etc
|
||||
// If it is an output `.md` file, use that to base .svg numbered diagrams on
|
||||
// I.e. if "out.md". use "out-1.svg", "out-2.svg", etc
|
||||
const outputFile = output.replace(
|
||||
/(\.(md|markdown|png|svg|pdf))$/,
|
||||
`-${imagePromises.length + 1}$1`
|
||||
).replace(/\.(md|markdown)$/, `.${outputFormat}`)
|
||||
const outputFileRelative = `./${path.relative(path.dirname(path.resolve(output)), path.resolve(outputFile))}`
|
||||
|
||||
const imagePromise = (async () => {
|
||||
const { title, desc, data } = await renderMermaid(browser, mermaidDefinition, outputFormat, parseMMDOptions)
|
||||
await fs.promises.writeFile(outputFile, data)
|
||||
info(` ✅ ${outputFileRelative}`)
|
||||
|
||||
return {
|
||||
url: outputFileRelative,
|
||||
title,
|
||||
alt: desc
|
||||
}
|
||||
})()
|
||||
imagePromises.push(imagePromise)
|
||||
}
|
||||
|
||||
if (imagePromises.length) {
|
||||
info(`Found ${imagePromises.length} mermaid charts in Markdown input`)
|
||||
} else {
|
||||
info('No mermaid charts found in Markdown input')
|
||||
}
|
||||
|
||||
const images = await Promise.all(imagePromises)
|
||||
|
||||
if (/\.(md|markdown)$/.test(output)) {
|
||||
const outDefinition = definition.replace(mermaidChartsInMarkdownRegexGlobal, (_mermaidMd) => {
|
||||
// pop first image from front of array
|
||||
const { url, title, alt } = images.shift()
|
||||
return markdownImage({ url, title, alt: alt || 'diagram' })
|
||||
})
|
||||
await fs.promises.writeFile(output, outDefinition, 'utf-8')
|
||||
info(` ✅ ${output}`)
|
||||
}
|
||||
} else {
|
||||
info('Generating single mermaid chart')
|
||||
const data = await parseMMD(browser, definition, outputFormat, parseMMDOptions)
|
||||
await fs.promises.writeFile(output, data)
|
||||
}
|
||||
} finally {
|
||||
await browser.close()
|
||||
}
|
||||
}
|
||||
|
||||
export { run, renderMermaid, parseMMD, cli, error }
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
# @puppeteer/browsers
|
||||
|
||||
Manage and launch browsers/drivers from a CLI or programmatically.
|
||||
|
||||
## CLI
|
||||
|
||||
Use `npx` to run the CLI:
|
||||
|
||||
```sh
|
||||
npx @puppeteer/browsers --help
|
||||
```
|
||||
|
||||
CLI help will provide all documentation you need to use the CLI.
|
||||
|
||||
```sh
|
||||
npx @puppeteer/browsers --help # help for all commands
|
||||
npx @puppeteer/browsers install --help # help for the install command
|
||||
npx @puppeteer/browsers launch --help # help for the launch command
|
||||
```
|
||||
|
||||
## Known limitations
|
||||
|
||||
1. We support installing and running Firefox and Chrome/Chromium. The `latest` keyword only works during the installation. For the `launch` command you need to specify an exact build ID. The build ID is provided by the `install` command (see `npx @puppeteer/browsers install --help` for the format).
|
||||
2. Launching the system browsers is only possible for Chrome/Chromium.
|
||||
|
||||
## API
|
||||
|
||||
The programmatic API allows installing and launching browsers from your code. See the `test` folder for examples on how to use the `install`, `canInstall`, `launch`, `computeExecutablePath`, `computeSystemExecutablePath` and other methods.
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import * as readline from 'readline';
|
||||
import { Browser } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare class CLI {
|
||||
#private;
|
||||
constructor(cachePath?: string, rl?: readline.Interface);
|
||||
run(argv: string[]): Promise<void>;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function makeProgressCallback(browser: Browser, buildId: string): (downloadedBytes: number, totalBytes: number) => void;
|
||||
//# sourceMappingURL=CLI.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"CLI.d.ts","sourceRoot":"","sources":["../../src/CLI.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;AAGH,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAOrC,OAAO,EAEL,OAAO,EAGR,MAAM,gCAAgC,CAAC;AAmCxC;;GAEG;AACH,qBAAa,GAAG;;gBAIF,SAAS,SAAgB,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,SAAS;IAwCxD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAuKzC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAqBvD"}
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _CLI_instances, _CLI_cachePath, _CLI_rl, _CLI_defineBrowserParameter, _CLI_definePlatformParameter, _CLI_definePathParameter, _CLI_parseBrowser, _CLI_parseBuildId;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeProgressCallback = exports.CLI = void 0;
|
||||
const process_1 = require("process");
|
||||
const readline = __importStar(require("readline"));
|
||||
const progress_1 = __importDefault(require("progress"));
|
||||
const helpers_1 = require("yargs/helpers");
|
||||
const yargs_1 = __importDefault(require("yargs/yargs"));
|
||||
const browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
const Cache_js_1 = require("./Cache.js");
|
||||
const detectPlatform_js_1 = require("./detectPlatform.js");
|
||||
const install_js_1 = require("./install.js");
|
||||
const launch_js_1 = require("./launch.js");
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
class CLI {
|
||||
constructor(cachePath = process.cwd(), rl) {
|
||||
_CLI_instances.add(this);
|
||||
_CLI_cachePath.set(this, void 0);
|
||||
_CLI_rl.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _CLI_cachePath, cachePath, "f");
|
||||
__classPrivateFieldSet(this, _CLI_rl, rl, "f");
|
||||
}
|
||||
async run(argv) {
|
||||
const yargsInstance = (0, yargs_1.default)((0, helpers_1.hideBin)(argv));
|
||||
await yargsInstance
|
||||
.scriptName('@puppeteer/browsers')
|
||||
.command('install <browser>', 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_defineBrowserParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePlatformParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs);
|
||||
yargs.option('base-url', {
|
||||
type: 'string',
|
||||
desc: 'Base URL to download from',
|
||||
});
|
||||
yargs.example('$0 install chrome', 'Install the latest available build of the Chrome browser.');
|
||||
yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.');
|
||||
yargs.example('$0 install chromium@1083080', 'Install the revision 1083080 of the Chromium browser.');
|
||||
yargs.example('$0 install firefox', 'Install the latest available build of the Firefox browser.');
|
||||
yargs.example('$0 install firefox --platform mac', 'Install the latest Mac (Intel) build of the Firefox browser.');
|
||||
yargs.example('$0 install firefox --path /tmp/my-browser-cache', 'Install to the specified cache directory.');
|
||||
}, async (argv) => {
|
||||
var _a, _b, _c;
|
||||
const args = argv;
|
||||
(_a = args.platform) !== null && _a !== void 0 ? _a : (args.platform = (0, detectPlatform_js_1.detectBrowserPlatform)());
|
||||
if (!args.platform) {
|
||||
throw new Error(`Could not resolve the current platform`);
|
||||
}
|
||||
args.browser.buildId = await (0, browser_data_js_1.resolveBuildId)(args.browser.name, args.platform, args.browser.buildId);
|
||||
await (0, install_js_1.install)({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
platform: args.platform,
|
||||
cacheDir: (_b = args.path) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId),
|
||||
baseUrl: args.baseUrl,
|
||||
});
|
||||
console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
cacheDir: (_c = args.path) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
platform: args.platform,
|
||||
})}`);
|
||||
})
|
||||
.command('launch <browser>', 'Launch the specified browser', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_defineBrowserParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePlatformParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs);
|
||||
yargs.option('detached', {
|
||||
type: 'boolean',
|
||||
desc: 'Detach the child process.',
|
||||
default: false,
|
||||
});
|
||||
yargs.option('system', {
|
||||
type: 'boolean',
|
||||
desc: 'Search for a browser installed on the system instead of the cache folder.',
|
||||
default: false,
|
||||
});
|
||||
yargs.example('$0 launch chrome@1083080', 'Launch the Chrome browser identified by the revision 1083080.');
|
||||
yargs.example('$0 launch firefox@112.0a1', 'Launch the Firefox browser identified by the milestone 112.0a1.');
|
||||
yargs.example('$0 launch chrome@1083080 --detached', 'Launch the browser but detach the sub-processes.');
|
||||
yargs.example('$0 launch chrome@canary --system', 'Try to locate the Canary build of Chrome installed on the system and launch it.');
|
||||
}, async (argv) => {
|
||||
var _a;
|
||||
const args = argv;
|
||||
const executablePath = args.system
|
||||
? (0, launch_js_1.computeSystemExecutablePath)({
|
||||
browser: args.browser.name,
|
||||
// TODO: throw an error if not a ChromeReleaseChannel is provided.
|
||||
channel: args.browser.buildId,
|
||||
platform: args.platform,
|
||||
})
|
||||
: (0, launch_js_1.computeExecutablePath)({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
cacheDir: (_a = args.path) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
platform: args.platform,
|
||||
});
|
||||
(0, launch_js_1.launch)({
|
||||
executablePath,
|
||||
detached: args.detached,
|
||||
});
|
||||
})
|
||||
.command('clear', 'Removes all installed browsers from the specified cache directory', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs, true);
|
||||
}, async (argv) => {
|
||||
var _a, _b;
|
||||
const args = argv;
|
||||
const cacheDir = (_a = args.path) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _CLI_cachePath, "f");
|
||||
const rl = (_b = __classPrivateFieldGet(this, _CLI_rl, "f")) !== null && _b !== void 0 ? _b : readline.createInterface({ input: process_1.stdin, output: process_1.stdout });
|
||||
rl.question(`Do you want to permanently and recursively delete the content of ${cacheDir} (yes/No)? `, answer => {
|
||||
rl.close();
|
||||
if (!['y', 'yes'].includes(answer.toLowerCase().trim())) {
|
||||
console.log('Cancelled.');
|
||||
return;
|
||||
}
|
||||
const cache = new Cache_js_1.Cache(cacheDir);
|
||||
cache.clear();
|
||||
console.log(`${cacheDir} cleared.`);
|
||||
});
|
||||
})
|
||||
.demandCommand(1)
|
||||
.help()
|
||||
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
||||
.parse();
|
||||
}
|
||||
}
|
||||
exports.CLI = CLI;
|
||||
_CLI_cachePath = new WeakMap(), _CLI_rl = new WeakMap(), _CLI_instances = new WeakSet(), _CLI_defineBrowserParameter = function _CLI_defineBrowserParameter(yargs) {
|
||||
yargs.positional('browser', {
|
||||
description: 'Which browser to install <browser>[@<buildId|latest>]. `latest` will try to find the latest available build. `buildId` is a browser-specific identifier such as a version or a revision.',
|
||||
type: 'string',
|
||||
coerce: (opt) => {
|
||||
return {
|
||||
name: __classPrivateFieldGet(this, _CLI_instances, "m", _CLI_parseBrowser).call(this, opt),
|
||||
buildId: __classPrivateFieldGet(this, _CLI_instances, "m", _CLI_parseBuildId).call(this, opt),
|
||||
};
|
||||
},
|
||||
});
|
||||
}, _CLI_definePlatformParameter = function _CLI_definePlatformParameter(yargs) {
|
||||
yargs.option('platform', {
|
||||
type: 'string',
|
||||
desc: 'Platform that the binary needs to be compatible with.',
|
||||
choices: Object.values(browser_data_js_1.BrowserPlatform),
|
||||
defaultDescription: 'Auto-detected',
|
||||
});
|
||||
}, _CLI_definePathParameter = function _CLI_definePathParameter(yargs, required = false) {
|
||||
yargs.option('path', {
|
||||
type: 'string',
|
||||
desc: 'Path to the root folder for the browser downloads and installation. The installation folder structure is compatible with the cache structure used by Puppeteer.',
|
||||
defaultDescription: 'Current working directory',
|
||||
...(required ? {} : { default: process.cwd() }),
|
||||
});
|
||||
if (required) {
|
||||
yargs.demandOption('path');
|
||||
}
|
||||
}, _CLI_parseBrowser = function _CLI_parseBrowser(version) {
|
||||
return version.split('@').shift();
|
||||
}, _CLI_parseBuildId = function _CLI_parseBuildId(version) {
|
||||
var _a;
|
||||
return (_a = version.split('@').pop()) !== null && _a !== void 0 ? _a : 'latest';
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function makeProgressCallback(browser, buildId) {
|
||||
let progressBar;
|
||||
let lastDownloadedBytes = 0;
|
||||
return (downloadedBytes, totalBytes) => {
|
||||
if (!progressBar) {
|
||||
progressBar = new progress_1.default(`Downloading ${browser} r${buildId} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
width: 20,
|
||||
total: totalBytes,
|
||||
});
|
||||
}
|
||||
const delta = downloadedBytes - lastDownloadedBytes;
|
||||
lastDownloadedBytes = downloadedBytes;
|
||||
progressBar.tick(delta);
|
||||
};
|
||||
}
|
||||
exports.makeProgressCallback = makeProgressCallback;
|
||||
function toMegabytes(bytes) {
|
||||
const mb = bytes / 1000 / 1000;
|
||||
return `${Math.round(mb * 10) / 10} MB`;
|
||||
}
|
||||
//# sourceMappingURL=CLI.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Browser, BrowserPlatform } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type InstalledBrowser = {
|
||||
path: string;
|
||||
browser: Browser;
|
||||
buildId: string;
|
||||
platform: BrowserPlatform;
|
||||
};
|
||||
/**
|
||||
* The cache used by Puppeteer relies on the following structure:
|
||||
*
|
||||
* - rootDir
|
||||
* -- <browser1> | browserRoot(browser1)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* -- <browser2> | browserRoot(browser2)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* @internal
|
||||
*/
|
||||
export declare class Cache {
|
||||
#private;
|
||||
constructor(rootDir: string);
|
||||
browserRoot(browser: Browser): string;
|
||||
installationDir(browser: Browser, platform: BrowserPlatform, buildId: string): string;
|
||||
clear(): void;
|
||||
getInstalledBrowsers(): InstalledBrowser[];
|
||||
}
|
||||
//# sourceMappingURL=Cache.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAC,OAAO,EAAE,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAK;;gBAGJ,OAAO,EAAE,MAAM;IAI3B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IASrC,eAAe,CACb,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM;IAIT,KAAK,IAAI,IAAI;IASb,oBAAoB,IAAI,gBAAgB,EAAE;CA8B3C"}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _Cache_rootDir;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Cache = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
/**
|
||||
* The cache used by Puppeteer relies on the following structure:
|
||||
*
|
||||
* - rootDir
|
||||
* -- <browser1> | browserRoot(browser1)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* -- <browser2> | browserRoot(browser2)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* @internal
|
||||
*/
|
||||
class Cache {
|
||||
constructor(rootDir) {
|
||||
_Cache_rootDir.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _Cache_rootDir, rootDir, "f");
|
||||
}
|
||||
browserRoot(browser) {
|
||||
// Chromium is a special case for backward compatibility: we install it in
|
||||
// the Chrome folder so that Puppeteer can find it.
|
||||
return path_1.default.join(__classPrivateFieldGet(this, _Cache_rootDir, "f"), browser === browser_data_js_1.Browser.CHROMIUM ? browser_data_js_1.Browser.CHROME : browser);
|
||||
}
|
||||
installationDir(browser, platform, buildId) {
|
||||
return path_1.default.join(this.browserRoot(browser), `${platform}-${buildId}`);
|
||||
}
|
||||
clear() {
|
||||
fs_1.default.rmSync(__classPrivateFieldGet(this, _Cache_rootDir, "f"), {
|
||||
force: true,
|
||||
recursive: true,
|
||||
maxRetries: 10,
|
||||
retryDelay: 500,
|
||||
});
|
||||
}
|
||||
getInstalledBrowsers() {
|
||||
if (!fs_1.default.existsSync(__classPrivateFieldGet(this, _Cache_rootDir, "f"))) {
|
||||
return [];
|
||||
}
|
||||
const types = fs_1.default.readdirSync(__classPrivateFieldGet(this, _Cache_rootDir, "f"));
|
||||
const browsers = types.filter((t) => {
|
||||
return Object.values(browser_data_js_1.Browser).includes(t);
|
||||
});
|
||||
return browsers.flatMap(browser => {
|
||||
const files = fs_1.default.readdirSync(this.browserRoot(browser));
|
||||
return files
|
||||
.map(file => {
|
||||
const result = parseFolderPath(path_1.default.join(this.browserRoot(browser), file));
|
||||
if (!result) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
path: path_1.default.join(this.browserRoot(browser), file),
|
||||
browser,
|
||||
platform: result.platform,
|
||||
buildId: result.buildId,
|
||||
};
|
||||
})
|
||||
.filter((item) => {
|
||||
return item !== null;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Cache = Cache;
|
||||
_Cache_rootDir = new WeakMap();
|
||||
function parseFolderPath(folderPath) {
|
||||
const name = path_1.default.basename(folderPath);
|
||||
const splits = name.split('-');
|
||||
if (splits.length !== 2) {
|
||||
return;
|
||||
}
|
||||
const [platform, buildId] = splits;
|
||||
if (!buildId || !platform) {
|
||||
return;
|
||||
}
|
||||
return { platform, buildId };
|
||||
}
|
||||
//# sourceMappingURL=Cache.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Cache.js","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"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"}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import * as chrome from './chrome.js';
|
||||
import * as chromedriver from './chromedriver.js';
|
||||
import * as chromium from './chromium.js';
|
||||
import * as firefox from './firefox.js';
|
||||
import { Browser, BrowserPlatform, ChromeReleaseChannel, ProfileOptions } from './types.js';
|
||||
export { ProfileOptions };
|
||||
export declare const downloadUrls: {
|
||||
chromedriver: typeof chromedriver.resolveDownloadUrl;
|
||||
chrome: typeof chrome.resolveDownloadUrl;
|
||||
chromium: typeof chromium.resolveDownloadUrl;
|
||||
firefox: typeof firefox.resolveDownloadUrl;
|
||||
};
|
||||
export declare const downloadPaths: {
|
||||
chromedriver: typeof chromedriver.resolveDownloadPath;
|
||||
chrome: typeof chrome.resolveDownloadPath;
|
||||
chromium: typeof chromium.resolveDownloadPath;
|
||||
firefox: typeof firefox.resolveDownloadPath;
|
||||
};
|
||||
export declare const executablePathByBrowser: {
|
||||
chromedriver: typeof chromedriver.relativeExecutablePath;
|
||||
chrome: typeof chrome.relativeExecutablePath;
|
||||
chromium: typeof chromium.relativeExecutablePath;
|
||||
firefox: typeof firefox.relativeExecutablePath;
|
||||
};
|
||||
export { Browser, BrowserPlatform, ChromeReleaseChannel };
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function resolveBuildId(browser: Browser, platform: BrowserPlatform, tag: string): Promise<string>;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function createProfile(browser: Browser, opts: ProfileOptions): Promise<void>;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function resolveSystemExecutablePath(browser: Browser, platform: BrowserPlatform, channel: ChromeReleaseChannel): string;
|
||||
//# sourceMappingURL=browser-data.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"browser-data.d.ts","sourceRoot":"","sources":["../../../src/browser-data/browser-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EACL,OAAO,EACP,eAAe,EAEf,oBAAoB,EACpB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,cAAc,EAAC,CAAC;AAExB,eAAO,MAAM,YAAY;;;;;CAKxB,CAAC;AAEF,eAAO,MAAM,aAAa;;;;;CAKzB,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;CAKnC,CAAC;AAEF,OAAO,EAAC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAC,CAAC;AAExD;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CA0BjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAYR"}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveSystemExecutablePath = exports.createProfile = exports.resolveBuildId = exports.ChromeReleaseChannel = exports.BrowserPlatform = exports.Browser = exports.executablePathByBrowser = exports.downloadPaths = exports.downloadUrls = void 0;
|
||||
const chrome = __importStar(require("./chrome.js"));
|
||||
const chromedriver = __importStar(require("./chromedriver.js"));
|
||||
const chromium = __importStar(require("./chromium.js"));
|
||||
const firefox = __importStar(require("./firefox.js"));
|
||||
const types_js_1 = require("./types.js");
|
||||
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return types_js_1.Browser; } });
|
||||
Object.defineProperty(exports, "BrowserPlatform", { enumerable: true, get: function () { return types_js_1.BrowserPlatform; } });
|
||||
Object.defineProperty(exports, "ChromeReleaseChannel", { enumerable: true, get: function () { return types_js_1.ChromeReleaseChannel; } });
|
||||
exports.downloadUrls = {
|
||||
[types_js_1.Browser.CHROMEDRIVER]: chromedriver.resolveDownloadUrl,
|
||||
[types_js_1.Browser.CHROME]: chrome.resolveDownloadUrl,
|
||||
[types_js_1.Browser.CHROMIUM]: chromium.resolveDownloadUrl,
|
||||
[types_js_1.Browser.FIREFOX]: firefox.resolveDownloadUrl,
|
||||
};
|
||||
exports.downloadPaths = {
|
||||
[types_js_1.Browser.CHROMEDRIVER]: chromedriver.resolveDownloadPath,
|
||||
[types_js_1.Browser.CHROME]: chrome.resolveDownloadPath,
|
||||
[types_js_1.Browser.CHROMIUM]: chromium.resolveDownloadPath,
|
||||
[types_js_1.Browser.FIREFOX]: firefox.resolveDownloadPath,
|
||||
};
|
||||
exports.executablePathByBrowser = {
|
||||
[types_js_1.Browser.CHROMEDRIVER]: chromedriver.relativeExecutablePath,
|
||||
[types_js_1.Browser.CHROME]: chrome.relativeExecutablePath,
|
||||
[types_js_1.Browser.CHROMIUM]: chromium.relativeExecutablePath,
|
||||
[types_js_1.Browser.FIREFOX]: firefox.relativeExecutablePath,
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
async function resolveBuildId(browser, platform, tag) {
|
||||
switch (browser) {
|
||||
case types_js_1.Browser.FIREFOX:
|
||||
switch (tag) {
|
||||
case types_js_1.BrowserTag.LATEST:
|
||||
return await firefox.resolveBuildId('FIREFOX_NIGHTLY');
|
||||
}
|
||||
case types_js_1.Browser.CHROME:
|
||||
switch (tag) {
|
||||
case types_js_1.BrowserTag.LATEST:
|
||||
// In CfT beta is the latest version.
|
||||
return await chrome.resolveBuildId(platform, 'beta');
|
||||
}
|
||||
case types_js_1.Browser.CHROMEDRIVER:
|
||||
switch (tag) {
|
||||
case types_js_1.BrowserTag.LATEST:
|
||||
return await chromedriver.resolveBuildId('latest');
|
||||
}
|
||||
case types_js_1.Browser.CHROMIUM:
|
||||
switch (tag) {
|
||||
case types_js_1.BrowserTag.LATEST:
|
||||
return await chromium.resolveBuildId(platform, 'latest');
|
||||
}
|
||||
}
|
||||
// We assume the tag is the buildId if it didn't match any keywords.
|
||||
return tag;
|
||||
}
|
||||
exports.resolveBuildId = resolveBuildId;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
async function createProfile(browser, opts) {
|
||||
switch (browser) {
|
||||
case types_js_1.Browser.FIREFOX:
|
||||
return await firefox.createProfile(opts);
|
||||
case types_js_1.Browser.CHROME:
|
||||
case types_js_1.Browser.CHROMIUM:
|
||||
throw new Error(`Profile creation is not support for ${browser} yet`);
|
||||
}
|
||||
}
|
||||
exports.createProfile = createProfile;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function resolveSystemExecutablePath(browser, platform, channel) {
|
||||
switch (browser) {
|
||||
case types_js_1.Browser.CHROMEDRIVER:
|
||||
case types_js_1.Browser.FIREFOX:
|
||||
throw new Error(`System browser detection is not supported for ${browser} yet.`);
|
||||
case types_js_1.Browser.CHROME:
|
||||
return chromium.resolveSystemExecutablePath(platform, channel);
|
||||
case types_js_1.Browser.CHROMIUM:
|
||||
return chrome.resolveSystemExecutablePath(platform, channel);
|
||||
}
|
||||
}
|
||||
exports.resolveSystemExecutablePath = resolveSystemExecutablePath;
|
||||
//# sourceMappingURL=browser-data.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"browser-data.js","sourceRoot":"","sources":["../../../src/browser-data/browser-data.ts"],"names":[],"mappings":"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"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BrowserPlatform, ChromeReleaseChannel } from './types.js';
|
||||
export declare function resolveDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl?: string): string;
|
||||
export declare function resolveDownloadPath(platform: BrowserPlatform, buildId: string): string[];
|
||||
export declare function relativeExecutablePath(platform: BrowserPlatform, _buildId: string): string;
|
||||
export declare function resolveBuildId(platform: BrowserPlatform, channel?: 'beta' | 'stable'): Promise<string>;
|
||||
export declare function resolveSystemExecutablePath(platform: BrowserPlatform, channel: ChromeReleaseChannel): string;
|
||||
//# sourceMappingURL=chrome.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chrome.d.ts","sourceRoot":"","sources":["../../../src/browser-data/chrome.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,EAAC,eAAe,EAAE,oBAAoB,EAAC,MAAM,YAAY,CAAC;AAgCjE,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,SAAgE,GACtE,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CAEV;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,GACf,MAAM,CAiBR;AACD,wBAAsB,cAAc,CAClC,QAAQ,EAAE,eAAe,EACzB,OAAO,GAAE,MAAM,GAAG,QAAiB,GAClC,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAwCR"}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveSystemExecutablePath = exports.resolveBuildId = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const httpUtil_js_1 = require("../httpUtil.js");
|
||||
const types_js_1 = require("./types.js");
|
||||
function folder(platform) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'linux64';
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return 'mac-arm64';
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return 'mac-x64';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
return 'win32';
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return 'win64';
|
||||
}
|
||||
}
|
||||
function chromiumDashPlatform(platform) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'linux';
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return 'mac';
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return 'mac';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
return 'win';
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return 'win64';
|
||||
}
|
||||
}
|
||||
function resolveDownloadUrl(platform, buildId, baseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing') {
|
||||
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
|
||||
}
|
||||
exports.resolveDownloadUrl = resolveDownloadUrl;
|
||||
function resolveDownloadPath(platform, buildId) {
|
||||
return [buildId, folder(platform), `chrome-${folder(platform)}.zip`];
|
||||
}
|
||||
exports.resolveDownloadPath = resolveDownloadPath;
|
||||
function relativeExecutablePath(platform, _buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return path_1.default.join('chrome-' + folder(platform), 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return path_1.default.join('chrome-linux64', 'chrome');
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return path_1.default.join('chrome-' + folder(platform), 'chrome.exe');
|
||||
}
|
||||
}
|
||||
exports.relativeExecutablePath = relativeExecutablePath;
|
||||
async function resolveBuildId(platform, channel = 'beta') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = (0, httpUtil_js_1.httpRequest)(new URL(`https://chromiumdash.appspot.com/fetch_releases?platform=${chromiumDashPlatform(platform)}&channel=${channel}`), 'GET', response => {
|
||||
let data = '';
|
||||
if (response.statusCode && response.statusCode >= 400) {
|
||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||
}
|
||||
response.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', () => {
|
||||
try {
|
||||
const response = JSON.parse(String(data));
|
||||
return resolve(response[0].version);
|
||||
}
|
||||
catch {
|
||||
return reject(new Error('Chrome version not found'));
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
request.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.resolveBuildId = resolveBuildId;
|
||||
function resolveSystemExecutablePath(platform, channel) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
switch (channel) {
|
||||
case types_js_1.ChromeReleaseChannel.STABLE:
|
||||
return `${process.env['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe`;
|
||||
case types_js_1.ChromeReleaseChannel.BETA:
|
||||
return `${process.env['PROGRAMFILES']}\\Google\\Chrome Beta\\Application\\chrome.exe`;
|
||||
case types_js_1.ChromeReleaseChannel.CANARY:
|
||||
return `${process.env['PROGRAMFILES']}\\Google\\Chrome SxS\\Application\\chrome.exe`;
|
||||
case types_js_1.ChromeReleaseChannel.DEV:
|
||||
return `${process.env['PROGRAMFILES']}\\Google\\Chrome Dev\\Application\\chrome.exe`;
|
||||
}
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
switch (channel) {
|
||||
case types_js_1.ChromeReleaseChannel.STABLE:
|
||||
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
case types_js_1.ChromeReleaseChannel.BETA:
|
||||
return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta';
|
||||
case types_js_1.ChromeReleaseChannel.CANARY:
|
||||
return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
|
||||
case types_js_1.ChromeReleaseChannel.DEV:
|
||||
return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev';
|
||||
}
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
switch (channel) {
|
||||
case types_js_1.ChromeReleaseChannel.STABLE:
|
||||
return '/opt/google/chrome/chrome';
|
||||
case types_js_1.ChromeReleaseChannel.BETA:
|
||||
return '/opt/google/chrome-beta/chrome';
|
||||
case types_js_1.ChromeReleaseChannel.DEV:
|
||||
return '/opt/google/chrome-unstable/chrome';
|
||||
}
|
||||
}
|
||||
throw new Error(`Unable to detect browser executable path for '${channel}' on ${platform}.`);
|
||||
}
|
||||
exports.resolveSystemExecutablePath = resolveSystemExecutablePath;
|
||||
//# sourceMappingURL=chrome.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chrome.js","sourceRoot":"","sources":["../../../src/browser-data/chrome.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAEH,gDAAwB;AAExB,gDAA2C;AAE3C,yCAAiE;AAEjE,SAAS,MAAM,CAAC,QAAyB;IACvC,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,SAAS,CAAC;QACnB,KAAK,0BAAe,CAAC,OAAO;YAC1B,OAAO,WAAW,CAAC;QACrB,KAAK,0BAAe,CAAC,GAAG;YACtB,OAAO,SAAS,CAAC;QACnB,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,OAAO,CAAC;QACjB,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,OAAO,CAAC;KAClB;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAyB;IACrD,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,OAAO,CAAC;QACjB,KAAK,0BAAe,CAAC,OAAO;YAC1B,OAAO,KAAK,CAAC;QACf,KAAK,0BAAe,CAAC,GAAG;YACtB,OAAO,KAAK,CAAC;QACf,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,KAAK,CAAC;QACf,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,OAAO,CAAC;KAClB;AACH,CAAC;AAED,SAAgB,kBAAkB,CAChC,QAAyB,EACzB,OAAe,EACf,OAAO,GAAG,6DAA6D;IAEvE,OAAO,GAAG,OAAO,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC1E,CAAC;AAND,gDAMC;AAED,SAAgB,mBAAmB,CACjC,QAAyB,EACzB,OAAe;IAEf,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACvE,CAAC;AALD,kDAKC;AAED,SAAgB,sBAAsB,CACpC,QAAyB,EACzB,QAAgB;IAEhB,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,GAAG,CAAC;QACzB,KAAK,0BAAe,CAAC,OAAO;YAC1B,OAAO,cAAI,CAAC,IAAI,CACd,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAC5B,+BAA+B,EAC/B,UAAU,EACV,OAAO,EACP,2BAA2B,CAC5B,CAAC;QACJ,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,cAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC/C,KAAK,0BAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,cAAI,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC;KAChE;AACH,CAAC;AApBD,wDAoBC;AACM,KAAK,UAAU,cAAc,CAClC,QAAyB,EACzB,UAA6B,MAAM;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAA,yBAAW,EACzB,IAAI,GAAG,CACL,4DAA4D,oBAAoB,CAC9E,QAAQ,CACT,YAAY,OAAO,EAAE,CACvB,EACD,KAAK,EACL,QAAQ,CAAC,EAAE;YACT,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,IAAI,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAE;gBACrD,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;aACpE;YACD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;gBAC1B,IAAI,IAAI,KAAK,CAAC;YAChB,CAAC,CAAC,CAAC;YACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACtB,IAAI;oBACF,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC1C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBACrC;gBAAC,MAAM;oBACN,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;iBACtD;YACH,CAAC,CAAC,CAAC;QACL,CAAC,EACD,KAAK,CACN,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAnCD,wCAmCC;AAED,SAAgB,2BAA2B,CACzC,QAAyB,EACzB,OAA6B;IAE7B,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,0BAAe,CAAC,KAAK;YACxB,QAAQ,OAAO,EAAE;gBACf,KAAK,+BAAoB,CAAC,MAAM;oBAC9B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,2CAA2C,CAAC;gBACnF,KAAK,+BAAoB,CAAC,IAAI;oBAC5B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,gDAAgD,CAAC;gBACxF,KAAK,+BAAoB,CAAC,MAAM;oBAC9B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,+CAA+C,CAAC;gBACvF,KAAK,+BAAoB,CAAC,GAAG;oBAC3B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,+CAA+C,CAAC;aACxF;QACH,KAAK,0BAAe,CAAC,OAAO,CAAC;QAC7B,KAAK,0BAAe,CAAC,GAAG;YACtB,QAAQ,OAAO,EAAE;gBACf,KAAK,+BAAoB,CAAC,MAAM;oBAC9B,OAAO,8DAA8D,CAAC;gBACxE,KAAK,+BAAoB,CAAC,IAAI;oBAC5B,OAAO,wEAAwE,CAAC;gBAClF,KAAK,+BAAoB,CAAC,MAAM;oBAC9B,OAAO,4EAA4E,CAAC;gBACtF,KAAK,+BAAoB,CAAC,GAAG;oBAC3B,OAAO,sEAAsE,CAAC;aACjF;QACH,KAAK,0BAAe,CAAC,KAAK;YACxB,QAAQ,OAAO,EAAE;gBACf,KAAK,+BAAoB,CAAC,MAAM;oBAC9B,OAAO,2BAA2B,CAAC;gBACrC,KAAK,+BAAoB,CAAC,IAAI;oBAC5B,OAAO,gCAAgC,CAAC;gBAC1C,KAAK,+BAAoB,CAAC,GAAG;oBAC3B,OAAO,oCAAoC,CAAC;aAC/C;KACJ;IAED,MAAM,IAAI,KAAK,CACb,iDAAiD,OAAO,QAAQ,QAAQ,GAAG,CAC5E,CAAC;AACJ,CAAC;AA3CD,kEA2CC"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BrowserPlatform } from './types.js';
|
||||
export declare function resolveDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl?: string): string;
|
||||
export declare function resolveDownloadPath(platform: BrowserPlatform, buildId: string): string[];
|
||||
export declare function relativeExecutablePath(platform: BrowserPlatform, _buildId: string): string;
|
||||
export declare function resolveBuildId(_channel?: 'latest'): Promise<string>;
|
||||
//# sourceMappingURL=chromedriver.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chromedriver.d.ts","sourceRoot":"","sources":["../../../src/browser-data/chromedriver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAgB3C,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,SAAgD,GACtD,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CAEV;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,GACf,MAAM,CAUR;AACD,wBAAsB,cAAc,CAClC,QAAQ,GAAE,QAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveBuildId = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
|
||||
const httpUtil_js_1 = require("../httpUtil.js");
|
||||
const types_js_1 = require("./types.js");
|
||||
function archive(platform) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'chromedriver_linux64';
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return 'chromedriver_mac_arm64';
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return 'chromedriver_mac64';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return 'chromedriver_win32';
|
||||
}
|
||||
}
|
||||
function resolveDownloadUrl(platform, buildId, baseUrl = 'https://chromedriver.storage.googleapis.com') {
|
||||
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
|
||||
}
|
||||
exports.resolveDownloadUrl = resolveDownloadUrl;
|
||||
function resolveDownloadPath(platform, buildId) {
|
||||
return [buildId, `${archive(platform)}.zip`];
|
||||
}
|
||||
exports.resolveDownloadPath = resolveDownloadPath;
|
||||
function relativeExecutablePath(platform, _buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'chromedriver';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return 'chromedriver.exe';
|
||||
}
|
||||
}
|
||||
exports.relativeExecutablePath = relativeExecutablePath;
|
||||
async function resolveBuildId(_channel = 'latest') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = (0, httpUtil_js_1.httpRequest)(new URL(`https://chromedriver.storage.googleapis.com/LATEST_RELEASE`), 'GET', response => {
|
||||
let data = '';
|
||||
if (response.statusCode && response.statusCode >= 400) {
|
||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||
}
|
||||
response.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', () => {
|
||||
try {
|
||||
return resolve(String(data));
|
||||
}
|
||||
catch {
|
||||
return reject(new Error('Chrome version not found'));
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
request.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.resolveBuildId = resolveBuildId;
|
||||
//# sourceMappingURL=chromedriver.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chromedriver.js","sourceRoot":"","sources":["../../../src/browser-data/chromedriver.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,gDAA2C;AAE3C,yCAA2C;AAE3C,SAAS,OAAO,CAAC,QAAyB;IACxC,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,sBAAsB,CAAC;QAChC,KAAK,0BAAe,CAAC,OAAO;YAC1B,OAAO,wBAAwB,CAAC;QAClC,KAAK,0BAAe,CAAC,GAAG;YACtB,OAAO,oBAAoB,CAAC;QAC9B,KAAK,0BAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,oBAAoB,CAAC;KAC/B;AACH,CAAC;AAED,SAAgB,kBAAkB,CAChC,QAAyB,EACzB,OAAe,EACf,OAAO,GAAG,6CAA6C;IAEvD,OAAO,GAAG,OAAO,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC1E,CAAC;AAND,gDAMC;AAED,SAAgB,mBAAmB,CACjC,QAAyB,EACzB,OAAe;IAEf,OAAO,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AALD,kDAKC;AAED,SAAgB,sBAAsB,CACpC,QAAyB,EACzB,QAAgB;IAEhB,QAAQ,QAAQ,EAAE;QAChB,KAAK,0BAAe,CAAC,GAAG,CAAC;QACzB,KAAK,0BAAe,CAAC,OAAO,CAAC;QAC7B,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,cAAc,CAAC;QACxB,KAAK,0BAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,0BAAe,CAAC,KAAK;YACxB,OAAO,kBAAkB,CAAC;KAC7B;AACH,CAAC;AAbD,wDAaC;AACM,KAAK,UAAU,cAAc,CAClC,WAAqB,QAAQ;IAE7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAA,yBAAW,EACzB,IAAI,GAAG,CAAC,4DAA4D,CAAC,EACrE,KAAK,EACL,QAAQ,CAAC,EAAE;YACT,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,IAAI,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAE;gBACrD,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;aACpE;YACD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;gBAC1B,IAAI,IAAI,KAAK,CAAC;YAChB,CAAC,CAAC,CAAC;YACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACtB,IAAI;oBACF,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;iBAC9B;gBAAC,MAAM;oBACN,OAAO,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC;iBACtD;YACH,CAAC,CAAC,CAAC;QACL,CAAC,EACD,KAAK,CACN,CAAC;QACF,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA7BD,wCA6BC"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BrowserPlatform } from './types.js';
|
||||
export { resolveSystemExecutablePath } from './chrome.js';
|
||||
export declare function resolveDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl?: string): string;
|
||||
export declare function resolveDownloadPath(platform: BrowserPlatform, buildId: string): string[];
|
||||
export declare function relativeExecutablePath(platform: BrowserPlatform, _buildId: string): string;
|
||||
export declare function resolveBuildId(platform: BrowserPlatform, _channel?: 'latest'): Promise<string>;
|
||||
//# sourceMappingURL=chromium.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chromium.d.ts","sourceRoot":"","sources":["../../../src/browser-data/chromium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAC,2BAA2B,EAAC,MAAM,aAAa,CAAC;AA+BxD,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,SAA8D,GACpE,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CAEV;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,GACf,MAAM,CAiBR;AACD,wBAAsB,cAAc,CAClC,QAAQ,EAAE,eAAe,EAEzB,QAAQ,GAAE,QAAmB,GAC5B,OAAO,CAAC,MAAM,CAAC,CA+BjB"}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveBuildId = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = exports.resolveSystemExecutablePath = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const httpUtil_js_1 = require("../httpUtil.js");
|
||||
const types_js_1 = require("./types.js");
|
||||
var chrome_js_1 = require("./chrome.js");
|
||||
Object.defineProperty(exports, "resolveSystemExecutablePath", { enumerable: true, get: function () { return chrome_js_1.resolveSystemExecutablePath; } });
|
||||
function archive(platform, buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'chrome-linux';
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return 'chrome-mac';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
// Windows archive name changed at r591479.
|
||||
return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
|
||||
}
|
||||
}
|
||||
function folder(platform) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return 'Linux_x64';
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return 'Mac_Arm';
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return 'Mac';
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
return 'Win';
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return 'Win_x64';
|
||||
}
|
||||
}
|
||||
function resolveDownloadUrl(platform, buildId, baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots') {
|
||||
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
|
||||
}
|
||||
exports.resolveDownloadUrl = resolveDownloadUrl;
|
||||
function resolveDownloadPath(platform, buildId) {
|
||||
return [folder(platform), buildId, `${archive(platform, buildId)}.zip`];
|
||||
}
|
||||
exports.resolveDownloadPath = resolveDownloadPath;
|
||||
function relativeExecutablePath(platform, _buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
return path_1.default.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium');
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return path_1.default.join('chrome-linux', 'chrome');
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return path_1.default.join('chrome-win', 'chrome.exe');
|
||||
}
|
||||
}
|
||||
exports.relativeExecutablePath = relativeExecutablePath;
|
||||
async function resolveBuildId(platform,
|
||||
// We will need it for other channels/keywords.
|
||||
_channel = 'latest') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = (0, httpUtil_js_1.httpRequest)(new URL(`https://storage.googleapis.com/chromium-browser-snapshots/${folder(platform)}/LAST_CHANGE`), 'GET', response => {
|
||||
let data = '';
|
||||
if (response.statusCode && response.statusCode >= 400) {
|
||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||
}
|
||||
response.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', () => {
|
||||
try {
|
||||
return resolve(String(data));
|
||||
}
|
||||
catch {
|
||||
return reject(new Error('Chrome version not found'));
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
request.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.resolveBuildId = resolveBuildId;
|
||||
//# sourceMappingURL=chromium.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"chromium.js","sourceRoot":"","sources":["../../../src/browser-data/chromium.ts"],"names":[],"mappings":"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"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BrowserPlatform, ProfileOptions } from './types.js';
|
||||
export declare function resolveDownloadUrl(platform: BrowserPlatform, buildId: string, baseUrl?: string): string;
|
||||
export declare function resolveDownloadPath(platform: BrowserPlatform, buildId: string): string[];
|
||||
export declare function relativeExecutablePath(platform: BrowserPlatform, _buildId: string): string;
|
||||
export declare function resolveBuildId(channel?: 'FIREFOX_NIGHTLY'): Promise<string>;
|
||||
export declare function createProfile(options: ProfileOptions): Promise<void>;
|
||||
//# sourceMappingURL=firefox.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"firefox.d.ts","sourceRoot":"","sources":["../../../src/browser-data/firefox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,EAAC,eAAe,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAe3D,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,EACf,OAAO,SAA2E,GACjF,MAAM,CAER;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM,EAAE,CAEV;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,MAAM,GACf,MAAM,CAWR;AAED,wBAAsB,cAAc,CAClC,OAAO,GAAE,iBAAqC,GAC7C,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAa1E"}
|
||||
+285
@@ -0,0 +1,285 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createProfile = exports.resolveBuildId = exports.relativeExecutablePath = exports.resolveDownloadPath = exports.resolveDownloadUrl = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const httpUtil_js_1 = require("../httpUtil.js");
|
||||
const types_js_1 = require("./types.js");
|
||||
function archive(platform, buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return `firefox-${buildId}.en-US.${platform}-x86_64.tar.bz2`;
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return `firefox-${buildId}.en-US.mac.dmg`;
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return `firefox-${buildId}.en-US.${platform}.zip`;
|
||||
}
|
||||
}
|
||||
function resolveDownloadUrl(platform, buildId, baseUrl = 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central') {
|
||||
return `${baseUrl}/${resolveDownloadPath(platform, buildId).join('/')}`;
|
||||
}
|
||||
exports.resolveDownloadUrl = resolveDownloadUrl;
|
||||
function resolveDownloadPath(platform, buildId) {
|
||||
return [archive(platform, buildId)];
|
||||
}
|
||||
exports.resolveDownloadPath = resolveDownloadPath;
|
||||
function relativeExecutablePath(platform, _buildId) {
|
||||
switch (platform) {
|
||||
case types_js_1.BrowserPlatform.MAC_ARM:
|
||||
case types_js_1.BrowserPlatform.MAC:
|
||||
return path_1.default.join('Firefox Nightly.app', 'Contents', 'MacOS', 'firefox');
|
||||
case types_js_1.BrowserPlatform.LINUX:
|
||||
return path_1.default.join('firefox', 'firefox');
|
||||
case types_js_1.BrowserPlatform.WIN32:
|
||||
case types_js_1.BrowserPlatform.WIN64:
|
||||
return path_1.default.join('firefox', 'firefox.exe');
|
||||
}
|
||||
}
|
||||
exports.relativeExecutablePath = relativeExecutablePath;
|
||||
async function resolveBuildId(channel = 'FIREFOX_NIGHTLY') {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = (0, httpUtil_js_1.httpRequest)(new URL('https://product-details.mozilla.org/1.0/firefox_versions.json'), 'GET', response => {
|
||||
let data = '';
|
||||
if (response.statusCode && response.statusCode >= 400) {
|
||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||
}
|
||||
response.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', () => {
|
||||
try {
|
||||
const versions = JSON.parse(data);
|
||||
return resolve(versions[channel]);
|
||||
}
|
||||
catch {
|
||||
return reject(new Error('Firefox version not found'));
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
request.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.resolveBuildId = resolveBuildId;
|
||||
async function createProfile(options) {
|
||||
if (!fs_1.default.existsSync(options.path)) {
|
||||
await fs_1.default.promises.mkdir(options.path, {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
await writePreferences({
|
||||
preferences: {
|
||||
...defaultProfilePreferences(options.preferences),
|
||||
...options.preferences,
|
||||
},
|
||||
path: options.path,
|
||||
});
|
||||
}
|
||||
exports.createProfile = createProfile;
|
||||
function defaultProfilePreferences(extraPrefs) {
|
||||
const server = 'dummy.test';
|
||||
const defaultPrefs = {
|
||||
// Make sure Shield doesn't hit the network.
|
||||
'app.normandy.api_url': '',
|
||||
// Disable Firefox old build background check
|
||||
'app.update.checkInstallTime': false,
|
||||
// Disable automatically upgrading Firefox
|
||||
'app.update.disabledForTesting': true,
|
||||
// Increase the APZ content response timeout to 1 minute
|
||||
'apz.content_response_timeout': 60000,
|
||||
// Prevent various error message on the console
|
||||
// jest-puppeteer asserts that no error message is emitted by the console
|
||||
'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
|
||||
// Enable the dump function: which sends messages to the system
|
||||
// console
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
|
||||
'browser.dom.window.dump.enabled': true,
|
||||
// Disable topstories
|
||||
'browser.newtabpage.activity-stream.feeds.system.topstories': false,
|
||||
// Always display a blank page
|
||||
'browser.newtabpage.enabled': false,
|
||||
// Background thumbnails in particular cause grief: and disabling
|
||||
// thumbnails in general cannot hurt
|
||||
'browser.pagethumbnails.capturing_disabled': true,
|
||||
// Disable safebrowsing components.
|
||||
'browser.safebrowsing.blockedURIs.enabled': false,
|
||||
'browser.safebrowsing.downloads.enabled': false,
|
||||
'browser.safebrowsing.malware.enabled': false,
|
||||
'browser.safebrowsing.passwords.enabled': false,
|
||||
'browser.safebrowsing.phishing.enabled': false,
|
||||
// Disable updates to search engines.
|
||||
'browser.search.update': false,
|
||||
// Do not restore the last open set of tabs if the browser has crashed
|
||||
'browser.sessionstore.resume_from_crash': false,
|
||||
// Skip check for default browser on startup
|
||||
'browser.shell.checkDefaultBrowser': false,
|
||||
// Disable newtabpage
|
||||
'browser.startup.homepage': 'about:blank',
|
||||
// Do not redirect user when a milstone upgrade of Firefox is detected
|
||||
'browser.startup.homepage_override.mstone': 'ignore',
|
||||
// Start with a blank page about:blank
|
||||
'browser.startup.page': 0,
|
||||
// Do not allow background tabs to be zombified on Android: otherwise for
|
||||
// tests that open additional tabs: the test harness tab itself might get
|
||||
// unloaded
|
||||
'browser.tabs.disableBackgroundZombification': false,
|
||||
// Do not warn when closing all other open tabs
|
||||
'browser.tabs.warnOnCloseOtherTabs': false,
|
||||
// Do not warn when multiple tabs will be opened
|
||||
'browser.tabs.warnOnOpen': false,
|
||||
// Disable the UI tour.
|
||||
'browser.uitour.enabled': false,
|
||||
// Turn off search suggestions in the location bar so as not to trigger
|
||||
// network connections.
|
||||
'browser.urlbar.suggest.searches': false,
|
||||
// Disable first run splash page on Windows 10
|
||||
'browser.usedOnWindows10.introURL': '',
|
||||
// Do not warn on quitting Firefox
|
||||
'browser.warnOnQuit': false,
|
||||
// Defensively disable data reporting systems
|
||||
'datareporting.healthreport.documentServerURI': `http://${server}/dummy/healthreport/`,
|
||||
'datareporting.healthreport.logging.consoleEnabled': false,
|
||||
'datareporting.healthreport.service.enabled': false,
|
||||
'datareporting.healthreport.service.firstRun': false,
|
||||
'datareporting.healthreport.uploadEnabled': false,
|
||||
// Do not show datareporting policy notifications which can interfere with tests
|
||||
'datareporting.policy.dataSubmissionEnabled': false,
|
||||
'datareporting.policy.dataSubmissionPolicyBypassNotification': true,
|
||||
// DevTools JSONViewer sometimes fails to load dependencies with its require.js.
|
||||
// This doesn't affect Puppeteer but spams console (Bug 1424372)
|
||||
'devtools.jsonview.enabled': false,
|
||||
// Disable popup-blocker
|
||||
'dom.disable_open_during_load': false,
|
||||
// Enable the support for File object creation in the content process
|
||||
// Required for |Page.setFileInputFiles| protocol method.
|
||||
'dom.file.createInChild': true,
|
||||
// Disable the ProcessHangMonitor
|
||||
'dom.ipc.reportProcessHangs': false,
|
||||
// Disable slow script dialogues
|
||||
'dom.max_chrome_script_run_time': 0,
|
||||
'dom.max_script_run_time': 0,
|
||||
// Only load extensions from the application and user profile
|
||||
// AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
|
||||
'extensions.autoDisableScopes': 0,
|
||||
'extensions.enabledScopes': 5,
|
||||
// Disable metadata caching for installed add-ons by default
|
||||
'extensions.getAddons.cache.enabled': false,
|
||||
// Disable installing any distribution extensions or add-ons.
|
||||
'extensions.installDistroAddons': false,
|
||||
// Disabled screenshots extension
|
||||
'extensions.screenshots.disabled': true,
|
||||
// Turn off extension updates so they do not bother tests
|
||||
'extensions.update.enabled': false,
|
||||
// Turn off extension updates so they do not bother tests
|
||||
'extensions.update.notifyUser': false,
|
||||
// Make sure opening about:addons will not hit the network
|
||||
'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
|
||||
// Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263)
|
||||
'fission.bfcacheInParent': false,
|
||||
// Force all web content to use a single content process
|
||||
'fission.webContentIsolationStrategy': 0,
|
||||
// Allow the application to have focus even it runs in the background
|
||||
'focusmanager.testmode': true,
|
||||
// Disable useragent updates
|
||||
'general.useragent.updates.enabled': false,
|
||||
// Always use network provider for geolocation tests so we bypass the
|
||||
// macOS dialog raised by the corelocation provider
|
||||
'geo.provider.testing': true,
|
||||
// Do not scan Wifi
|
||||
'geo.wifi.scan': false,
|
||||
// No hang monitor
|
||||
'hangmonitor.timeout': 0,
|
||||
// Show chrome errors and warnings in the error console
|
||||
'javascript.options.showInConsole': true,
|
||||
// Disable download and usage of OpenH264: and Widevine plugins
|
||||
'media.gmp-manager.updateEnabled': false,
|
||||
// Prevent various error message on the console
|
||||
// jest-puppeteer asserts that no error message is emitted by the console
|
||||
'network.cookie.cookieBehavior': 0,
|
||||
// Disable experimental feature that is only available in Nightly
|
||||
'network.cookie.sameSite.laxByDefault': false,
|
||||
// Do not prompt for temporary redirects
|
||||
'network.http.prompt-temp-redirect': false,
|
||||
// Disable speculative connections so they are not reported as leaking
|
||||
// when they are hanging around
|
||||
'network.http.speculative-parallel-limit': 0,
|
||||
// Do not automatically switch between offline and online
|
||||
'network.manage-offline-status': false,
|
||||
// Make sure SNTP requests do not hit the network
|
||||
'network.sntp.pools': server,
|
||||
// Disable Flash.
|
||||
'plugin.state.flash': 0,
|
||||
'privacy.trackingprotection.enabled': false,
|
||||
// Can be removed once Firefox 89 is no longer supported
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1710839
|
||||
'remote.enabled': true,
|
||||
// Don't do network connections for mitm priming
|
||||
'security.certerrors.mitm.priming.enabled': false,
|
||||
// Local documents have access to all other local documents,
|
||||
// including directory listings
|
||||
'security.fileuri.strict_origin_policy': false,
|
||||
// Do not wait for the notification button security delay
|
||||
'security.notification_enable_delay': 0,
|
||||
// Ensure blocklist updates do not hit the network
|
||||
'services.settings.server': `http://${server}/dummy/blocklist/`,
|
||||
// Do not automatically fill sign-in forms with known usernames and
|
||||
// passwords
|
||||
'signon.autofillForms': false,
|
||||
// Disable password capture, so that tests that include forms are not
|
||||
// influenced by the presence of the persistent doorhanger notification
|
||||
'signon.rememberSignons': false,
|
||||
// Disable first-run welcome page
|
||||
'startup.homepage_welcome_url': 'about:blank',
|
||||
// Disable first-run welcome page
|
||||
'startup.homepage_welcome_url.additional': '',
|
||||
// Disable browser animations (tabs, fullscreen, sliding alerts)
|
||||
'toolkit.cosmeticAnimations.enabled': false,
|
||||
// Prevent starting into safe mode after application crashes
|
||||
'toolkit.startup.max_resumed_crashes': -1,
|
||||
};
|
||||
return Object.assign(defaultPrefs, extraPrefs);
|
||||
}
|
||||
/**
|
||||
* Populates the user.js file with custom preferences as needed to allow
|
||||
* Firefox's CDP support to properly function. These preferences will be
|
||||
* automatically copied over to prefs.js during startup of Firefox. To be
|
||||
* able to restore the original values of preferences a backup of prefs.js
|
||||
* will be created.
|
||||
*
|
||||
* @param prefs - List of preferences to add.
|
||||
* @param profilePath - Firefox profile to write the preferences to.
|
||||
*/
|
||||
async function writePreferences(options) {
|
||||
const lines = Object.entries(options.preferences).map(([key, value]) => {
|
||||
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
|
||||
});
|
||||
await fs_1.default.promises.writeFile(path_1.default.join(options.path, 'user.js'), lines.join('\n'));
|
||||
// Create a backup of the preferences file if it already exitsts.
|
||||
const prefsPath = path_1.default.join(options.path, 'prefs.js');
|
||||
if (fs_1.default.existsSync(prefsPath)) {
|
||||
const prefsBackupPath = path_1.default.join(options.path, 'prefs.js.puppeteer');
|
||||
await fs_1.default.promises.copyFile(prefsPath, prefsBackupPath);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=firefox.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import * as chrome from './chrome.js';
|
||||
import * as firefox from './firefox.js';
|
||||
/**
|
||||
* Supported browsers.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare enum Browser {
|
||||
CHROME = "chrome",
|
||||
CHROMIUM = "chromium",
|
||||
FIREFOX = "firefox",
|
||||
CHROMEDRIVER = "chromedriver"
|
||||
}
|
||||
/**
|
||||
* Platform names used to identify a OS platfrom x architecture combination in the way
|
||||
* that is relevant for the browser download.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export declare enum BrowserPlatform {
|
||||
LINUX = "linux",
|
||||
MAC = "mac",
|
||||
MAC_ARM = "mac_arm",
|
||||
WIN32 = "win32",
|
||||
WIN64 = "win64"
|
||||
}
|
||||
export declare const downloadUrls: {
|
||||
chrome: typeof chrome.resolveDownloadUrl;
|
||||
chromium: typeof chrome.resolveDownloadUrl;
|
||||
firefox: typeof firefox.resolveDownloadUrl;
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare enum BrowserTag {
|
||||
LATEST = "latest"
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface ProfileOptions {
|
||||
preferences: Record<string, unknown>;
|
||||
path: string;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare enum ChromeReleaseChannel {
|
||||
STABLE = "stable",
|
||||
DEV = "dev",
|
||||
CANARY = "canary",
|
||||
BETA = "beta"
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/browser-data/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC;;;;GAIG;AACH,oBAAY,OAAO;IACjB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,YAAY,iBAAiB;CAC9B;AAED;;;;;GAKG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,YAAY;;;;CAIxB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU;IACpB,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,oBAAY,oBAAoB;IAC9B,MAAM,WAAW;IACjB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,IAAI,SAAS;CACd"}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ChromeReleaseChannel = exports.BrowserTag = exports.downloadUrls = exports.BrowserPlatform = exports.Browser = void 0;
|
||||
const chrome = __importStar(require("./chrome.js"));
|
||||
const firefox = __importStar(require("./firefox.js"));
|
||||
/**
|
||||
* Supported browsers.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
var Browser;
|
||||
(function (Browser) {
|
||||
Browser["CHROME"] = "chrome";
|
||||
Browser["CHROMIUM"] = "chromium";
|
||||
Browser["FIREFOX"] = "firefox";
|
||||
Browser["CHROMEDRIVER"] = "chromedriver";
|
||||
})(Browser = exports.Browser || (exports.Browser = {}));
|
||||
/**
|
||||
* Platform names used to identify a OS platfrom x architecture combination in the way
|
||||
* that is relevant for the browser download.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
var BrowserPlatform;
|
||||
(function (BrowserPlatform) {
|
||||
BrowserPlatform["LINUX"] = "linux";
|
||||
BrowserPlatform["MAC"] = "mac";
|
||||
BrowserPlatform["MAC_ARM"] = "mac_arm";
|
||||
BrowserPlatform["WIN32"] = "win32";
|
||||
BrowserPlatform["WIN64"] = "win64";
|
||||
})(BrowserPlatform = exports.BrowserPlatform || (exports.BrowserPlatform = {}));
|
||||
exports.downloadUrls = {
|
||||
[Browser.CHROME]: chrome.resolveDownloadUrl,
|
||||
[Browser.CHROMIUM]: chrome.resolveDownloadUrl,
|
||||
[Browser.FIREFOX]: firefox.resolveDownloadUrl,
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
var BrowserTag;
|
||||
(function (BrowserTag) {
|
||||
BrowserTag["LATEST"] = "latest";
|
||||
})(BrowserTag = exports.BrowserTag || (exports.BrowserTag = {}));
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
var ChromeReleaseChannel;
|
||||
(function (ChromeReleaseChannel) {
|
||||
ChromeReleaseChannel["STABLE"] = "stable";
|
||||
ChromeReleaseChannel["DEV"] = "dev";
|
||||
ChromeReleaseChannel["CANARY"] = "canary";
|
||||
ChromeReleaseChannel["BETA"] = "beta";
|
||||
})(ChromeReleaseChannel = exports.ChromeReleaseChannel || (exports.ChromeReleaseChannel = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/browser-data/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;AACtC,sDAAwC;AAExC;;;;GAIG;AACH,IAAY,OAKX;AALD,WAAY,OAAO;IACjB,4BAAiB,CAAA;IACjB,gCAAqB,CAAA;IACrB,8BAAmB,CAAA;IACnB,wCAA6B,CAAA;AAC/B,CAAC,EALW,OAAO,GAAP,eAAO,KAAP,eAAO,QAKlB;AAED;;;;;GAKG;AACH,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,8BAAW,CAAA;IACX,sCAAmB,CAAA;IACnB,kCAAe,CAAA;IACf,kCAAe,CAAA;AACjB,CAAC,EANW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAM1B;AAEY,QAAA,YAAY,GAAG;IAC1B,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,kBAAkB;IAC3C,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,kBAAkB;IAC7C,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB;CAC9C,CAAC;AAEF;;GAEG;AACH,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,+BAAiB,CAAA;AACnB,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAUD;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,mCAAW,CAAA;IACX,yCAAiB,CAAA;IACjB,qCAAa,CAAA;AACf,CAAC,EALW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAK/B"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import debug from 'debug';
|
||||
export { debug };
|
||||
//# sourceMappingURL=debug.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,KAAK,EAAC,CAAC"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.debug = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
exports.debug = debug_1.default;
|
||||
//# sourceMappingURL=debug.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAEH,kDAA0B;AAElB,gBAFD,eAAK,CAEC"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { BrowserPlatform } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function detectBrowserPlatform(): BrowserPlatform | undefined;
|
||||
//# sourceMappingURL=detectPlatform.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"detectPlatform.d.ts","sourceRoot":"","sources":["../../src/detectPlatform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAC,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAE/D;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,eAAe,GAAG,SAAS,CAkBnE"}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.detectBrowserPlatform = void 0;
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function detectBrowserPlatform() {
|
||||
const platform = os_1.default.platform();
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return os_1.default.arch() === 'arm64'
|
||||
? browser_data_js_1.BrowserPlatform.MAC_ARM
|
||||
: browser_data_js_1.BrowserPlatform.MAC;
|
||||
case 'linux':
|
||||
return browser_data_js_1.BrowserPlatform.LINUX;
|
||||
case 'win32':
|
||||
return os_1.default.arch() === 'x64' ||
|
||||
// Windows 11 for ARM supports x64 emulation
|
||||
(os_1.default.arch() === 'arm64' && isWindows11(os_1.default.release()))
|
||||
? browser_data_js_1.BrowserPlatform.WIN64
|
||||
: browser_data_js_1.BrowserPlatform.WIN32;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
exports.detectBrowserPlatform = detectBrowserPlatform;
|
||||
/**
|
||||
* Windows 11 is identified by the version 10.0.22000 or greater
|
||||
* @internal
|
||||
*/
|
||||
function isWindows11(version) {
|
||||
const parts = version.split('.');
|
||||
if (parts.length > 2) {
|
||||
const major = parseInt(parts[0], 10);
|
||||
const minor = parseInt(parts[1], 10);
|
||||
const patch = parseInt(parts[2], 10);
|
||||
return (major > 10 ||
|
||||
(major === 10 && minor > 0) ||
|
||||
(major === 10 && minor === 0 && patch >= 22000));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=detectPlatform.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"detectPlatform.js","sourceRoot":"","sources":["../../src/detectPlatform.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAEH,4CAAoB;AAEpB,oEAA+D;AAE/D;;GAEG;AACH,SAAgB,qBAAqB;IACnC,MAAM,QAAQ,GAAG,YAAE,CAAC,QAAQ,EAAE,CAAC;IAC/B,QAAQ,QAAQ,EAAE;QAChB,KAAK,QAAQ;YACX,OAAO,YAAE,CAAC,IAAI,EAAE,KAAK,OAAO;gBAC1B,CAAC,CAAC,iCAAe,CAAC,OAAO;gBACzB,CAAC,CAAC,iCAAe,CAAC,GAAG,CAAC;QAC1B,KAAK,OAAO;YACV,OAAO,iCAAe,CAAC,KAAK,CAAC;QAC/B,KAAK,OAAO;YACV,OAAO,YAAE,CAAC,IAAI,EAAE,KAAK,KAAK;gBACxB,4CAA4C;gBAC5C,CAAC,YAAE,CAAC,IAAI,EAAE,KAAK,OAAO,IAAI,WAAW,CAAC,YAAE,CAAC,OAAO,EAAE,CAAC,CAAC;gBACpD,CAAC,CAAC,iCAAe,CAAC,KAAK;gBACvB,CAAC,CAAC,iCAAe,CAAC,KAAK,CAAC;QAC5B;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAlBD,sDAkBC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,OAAe;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC;QAC/C,OAAO,CACL,KAAK,GAAG,EAAE;YACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC;YAC3B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,CAChD,CAAC;KACH;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare function unpackArchive(archivePath: string, folderPath: string): Promise<void>;
|
||||
//# sourceMappingURL=fileUtil.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fileUtil.d.ts","sourceRoot":"","sources":["../../src/fileUtil.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH;;GAEG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unpackArchive = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const path = __importStar(require("path"));
|
||||
const util_1 = require("util");
|
||||
const extract_zip_1 = __importDefault(require("extract-zip"));
|
||||
const tar_fs_1 = __importDefault(require("tar-fs"));
|
||||
const unbzip2_stream_1 = __importDefault(require("unbzip2-stream"));
|
||||
const exec = (0, util_1.promisify)(child_process_1.exec);
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async function unpackArchive(archivePath, folderPath) {
|
||||
if (archivePath.endsWith('.zip')) {
|
||||
await (0, extract_zip_1.default)(archivePath, { dir: folderPath });
|
||||
}
|
||||
else if (archivePath.endsWith('.tar.bz2')) {
|
||||
await extractTar(archivePath, folderPath);
|
||||
}
|
||||
else if (archivePath.endsWith('.dmg')) {
|
||||
await (0, promises_1.mkdir)(folderPath);
|
||||
await installDMG(archivePath, folderPath);
|
||||
}
|
||||
else {
|
||||
throw new Error(`Unsupported archive format: ${archivePath}`);
|
||||
}
|
||||
}
|
||||
exports.unpackArchive = unpackArchive;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function extractTar(tarPath, folderPath) {
|
||||
return new Promise((fulfill, reject) => {
|
||||
const tarStream = tar_fs_1.default.extract(folderPath);
|
||||
tarStream.on('error', reject);
|
||||
tarStream.on('finish', fulfill);
|
||||
const readStream = (0, fs_1.createReadStream)(tarPath);
|
||||
readStream.pipe((0, unbzip2_stream_1.default)()).pipe(tarStream);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async function installDMG(dmgPath, folderPath) {
|
||||
const { stdout } = await exec(`hdiutil attach -nobrowse -noautoopen "${dmgPath}"`);
|
||||
const volumes = stdout.match(/\/Volumes\/(.*)/m);
|
||||
if (!volumes) {
|
||||
throw new Error(`Could not find volume path in ${stdout}`);
|
||||
}
|
||||
const mountPath = volumes[0];
|
||||
try {
|
||||
const fileNames = await (0, promises_1.readdir)(mountPath);
|
||||
const appName = fileNames.find(item => {
|
||||
return typeof item === 'string' && item.endsWith('.app');
|
||||
});
|
||||
if (!appName) {
|
||||
throw new Error(`Cannot find app in ${mountPath}`);
|
||||
}
|
||||
const mountedPath = path.join(mountPath, appName);
|
||||
await exec(`cp -R "${mountedPath}" "${folderPath}"`);
|
||||
}
|
||||
finally {
|
||||
await exec(`hdiutil detach "${mountPath}" -quiet`);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fileUtil.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fileUtil.js","sourceRoot":"","sources":["../../src/fileUtil.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAuD;AACvD,2BAAoC;AACpC,0CAA2C;AAC3C,2CAA6B;AAC7B,+BAA+B;AAE/B,8DAAqC;AACrC,oDAAyB;AACzB,oEAAkC;AAElC,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,oBAAgB,CAAC,CAAC;AAEzC;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,UAAkB;IAElB,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChC,MAAM,IAAA,qBAAU,EAAC,WAAW,EAAE,EAAC,GAAG,EAAE,UAAU,EAAC,CAAC,CAAC;KAClD;SAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QAC3C,MAAM,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;KAC3C;SAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACvC,MAAM,IAAA,gBAAK,EAAC,UAAU,CAAC,CAAC;QACxB,MAAM,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;KAC3C;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,+BAA+B,WAAW,EAAE,CAAC,CAAC;KAC/D;AACH,CAAC;AAdD,sCAcC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,OAAe,EAAE,UAAkB;IACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,SAAS,GAAG,gBAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1C,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9B,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,UAAU,GAAG,IAAA,qBAAgB,EAAC,OAAO,CAAC,CAAC;QAC7C,UAAU,CAAC,IAAI,CAAC,IAAA,wBAAI,GAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,UAAkB;IAC3D,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,IAAI,CACzB,yCAAyC,OAAO,GAAG,CACpD,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,EAAE,CAAC,CAAC;KAC5D;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;IAE9B,IAAI;QACF,MAAM,SAAS,GAAG,MAAM,IAAA,kBAAO,EAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;SACpD;QACD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAU,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,IAAI,CAAC,UAAU,WAAW,MAAM,UAAU,GAAG,CAAC,CAAC;KACtD;YAAS;QACR,MAAM,IAAI,CAAC,mBAAmB,SAAS,UAAU,CAAC,CAAC;KACpD;AACH,CAAC"}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import * as http from 'http';
|
||||
import { URL } from 'url';
|
||||
export declare function headHttpRequest(url: URL): Promise<boolean>;
|
||||
export declare function httpRequest(url: URL, method: string, response: (x: http.IncomingMessage) => void, keepAlive?: boolean): http.ClientRequest;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare function downloadFile(url: URL, destinationPath: string, progressCallback?: (downloadedBytes: number, totalBytes: number) => void): Promise<void>;
|
||||
//# sourceMappingURL=httpUtil.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"httpUtil.d.ts","sourceRoot":"","sources":["../../src/httpUtil.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;AAGH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAC,GAAG,EAAC,MAAM,KAAK,CAAC;AAKxB,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAc1D;AAED,wBAAgB,WAAW,CACzB,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,eAAe,KAAK,IAAI,EAC3C,SAAS,UAAO,GACf,IAAI,CAAC,aAAa,CA+CpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,eAAe,EAAE,MAAM,EACvB,gBAAgB,CAAC,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,GACvE,OAAO,CAAC,IAAI,CAAC,CAqCf"}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.downloadFile = exports.httpRequest = exports.headHttpRequest = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const http = __importStar(require("http"));
|
||||
const https = __importStar(require("https"));
|
||||
const url_1 = require("url");
|
||||
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
||||
const proxy_from_env_1 = require("proxy-from-env");
|
||||
function headHttpRequest(url) {
|
||||
return new Promise(resolve => {
|
||||
const request = httpRequest(url, 'HEAD', response => {
|
||||
resolve(response.statusCode === 200);
|
||||
}, false);
|
||||
request.on('error', () => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.headHttpRequest = headHttpRequest;
|
||||
function httpRequest(url, method, response, keepAlive = true) {
|
||||
const options = {
|
||||
protocol: url.protocol,
|
||||
hostname: url.hostname,
|
||||
port: url.port,
|
||||
path: url.pathname + url.search,
|
||||
method,
|
||||
headers: keepAlive ? { Connection: 'keep-alive' } : undefined,
|
||||
};
|
||||
const proxyURL = (0, proxy_from_env_1.getProxyForUrl)(url.toString());
|
||||
if (proxyURL) {
|
||||
const proxy = new url_1.URL(proxyURL);
|
||||
if (proxy.protocol === 'http:') {
|
||||
options.path = url.href;
|
||||
options.hostname = proxy.hostname;
|
||||
options.protocol = proxy.protocol;
|
||||
options.port = proxy.port;
|
||||
}
|
||||
else {
|
||||
options.agent = (0, https_proxy_agent_1.default)({
|
||||
host: proxy.host,
|
||||
path: proxy.pathname,
|
||||
port: proxy.port,
|
||||
secureProxy: proxy.protocol === 'https:',
|
||||
headers: options.headers,
|
||||
});
|
||||
}
|
||||
}
|
||||
const requestCallback = (res) => {
|
||||
if (res.statusCode &&
|
||||
res.statusCode >= 300 &&
|
||||
res.statusCode < 400 &&
|
||||
res.headers.location) {
|
||||
httpRequest(new url_1.URL(res.headers.location), method, response);
|
||||
}
|
||||
else {
|
||||
response(res);
|
||||
}
|
||||
};
|
||||
const request = options.protocol === 'https:'
|
||||
? https.request(options, requestCallback)
|
||||
: http.request(options, requestCallback);
|
||||
request.end();
|
||||
return request;
|
||||
}
|
||||
exports.httpRequest = httpRequest;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function downloadFile(url, destinationPath, progressCallback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let downloadedBytes = 0;
|
||||
let totalBytes = 0;
|
||||
function onData(chunk) {
|
||||
downloadedBytes += chunk.length;
|
||||
progressCallback(downloadedBytes, totalBytes);
|
||||
}
|
||||
const request = httpRequest(url, 'GET', response => {
|
||||
if (response.statusCode !== 200) {
|
||||
const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`);
|
||||
// consume response data to free up memory
|
||||
response.resume();
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
const file = (0, fs_1.createWriteStream)(destinationPath);
|
||||
file.on('finish', () => {
|
||||
return resolve();
|
||||
});
|
||||
file.on('error', error => {
|
||||
return reject(error);
|
||||
});
|
||||
response.pipe(file);
|
||||
totalBytes = parseInt(response.headers['content-length'], 10);
|
||||
if (progressCallback) {
|
||||
response.on('data', onData);
|
||||
}
|
||||
});
|
||||
request.on('error', error => {
|
||||
return reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.downloadFile = downloadFile;
|
||||
//# sourceMappingURL=httpUtil.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"httpUtil.js","sourceRoot":"","sources":["../../src/httpUtil.ts"],"names":[],"mappings":"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"}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright 2017 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Browser, BrowserPlatform } from './browser-data/browser-data.js';
|
||||
import { InstalledBrowser } from './Cache.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface InstallOptions {
|
||||
/**
|
||||
* Determines the path to download browsers to.
|
||||
*/
|
||||
cacheDir: string;
|
||||
/**
|
||||
* Determines which platform the browser will be suited for.
|
||||
*
|
||||
* @defaultValue **Auto-detected.**
|
||||
*/
|
||||
platform?: BrowserPlatform;
|
||||
/**
|
||||
* Determines which browser to install.
|
||||
*/
|
||||
browser: Browser;
|
||||
/**
|
||||
* Determines which buildId to dowloand. BuildId should uniquely identify
|
||||
* binaries and they are used for caching.
|
||||
*/
|
||||
buildId: string;
|
||||
/**
|
||||
* Provides information about the progress of the download.
|
||||
*/
|
||||
downloadProgressCallback?: (downloadedBytes: number, totalBytes: number) => void;
|
||||
/**
|
||||
* Determines the host that will be used for downloading.
|
||||
*
|
||||
* @defaultValue Either
|
||||
*
|
||||
* - https://storage.googleapis.com/chromium-browser-snapshots or
|
||||
* - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
|
||||
*
|
||||
*/
|
||||
baseUrl?: string;
|
||||
/**
|
||||
* Whether to unpack and install browser archives.
|
||||
*
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
unpack?: boolean;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function install(options: InstallOptions): Promise<InstalledBrowser>;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function canDownload(options: InstallOptions): Promise<boolean>;
|
||||
//# sourceMappingURL=install.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,OAAO,EACL,OAAO,EACP,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAQ,gBAAgB,EAAC,MAAM,YAAY,CAAC;AAwBnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,wBAAwB,CAAC,EAAE,CACzB,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,KACf,IAAI,CAAC;IACV;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAoF3B;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAe3E"}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2017 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.canDownload = exports.install = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
const Cache_js_1 = require("./Cache.js");
|
||||
const debug_js_1 = require("./debug.js");
|
||||
const detectPlatform_js_1 = require("./detectPlatform.js");
|
||||
const fileUtil_js_1 = require("./fileUtil.js");
|
||||
const httpUtil_js_1 = require("./httpUtil.js");
|
||||
const debugInstall = (0, debug_js_1.debug)('puppeteer:browsers:install');
|
||||
const times = new Map();
|
||||
function debugTime(label) {
|
||||
times.set(label, process.hrtime());
|
||||
}
|
||||
function debugTimeEnd(label) {
|
||||
const end = process.hrtime();
|
||||
const start = times.get(label);
|
||||
if (!start) {
|
||||
return;
|
||||
}
|
||||
const duration = end[0] * 1000 + end[1] / 1e6 - (start[0] * 1000 + start[1] / 1e6); // calculate duration in milliseconds
|
||||
debugInstall(`Duration for ${label}: ${duration}ms`);
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
async function install(options) {
|
||||
var _a, _b;
|
||||
(_a = options.platform) !== null && _a !== void 0 ? _a : (options.platform = (0, detectPlatform_js_1.detectBrowserPlatform)());
|
||||
(_b = options.unpack) !== null && _b !== void 0 ? _b : (options.unpack = true);
|
||||
if (!options.platform) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
const url = getDownloadUrl(options.browser, options.platform, options.buildId, options.baseUrl);
|
||||
const fileName = url.toString().split('/').pop();
|
||||
(0, assert_1.default)(fileName, `A malformed download URL was found: ${url}.`);
|
||||
const structure = new Cache_js_1.Cache(options.cacheDir);
|
||||
const browserRoot = structure.browserRoot(options.browser);
|
||||
const archivePath = path_1.default.join(browserRoot, fileName);
|
||||
if (!(0, fs_1.existsSync)(browserRoot)) {
|
||||
await (0, promises_1.mkdir)(browserRoot, { recursive: true });
|
||||
}
|
||||
if (!options.unpack) {
|
||||
if ((0, fs_1.existsSync)(archivePath)) {
|
||||
return {
|
||||
path: archivePath,
|
||||
browser: options.browser,
|
||||
platform: options.platform,
|
||||
buildId: options.buildId,
|
||||
};
|
||||
}
|
||||
debugInstall(`Downloading binary from ${url}`);
|
||||
debugTime('download');
|
||||
await (0, httpUtil_js_1.downloadFile)(url, archivePath, options.downloadProgressCallback);
|
||||
debugTimeEnd('download');
|
||||
return {
|
||||
path: archivePath,
|
||||
browser: options.browser,
|
||||
platform: options.platform,
|
||||
buildId: options.buildId,
|
||||
};
|
||||
}
|
||||
const outputPath = structure.installationDir(options.browser, options.platform, options.buildId);
|
||||
if ((0, fs_1.existsSync)(outputPath)) {
|
||||
return {
|
||||
path: outputPath,
|
||||
browser: options.browser,
|
||||
platform: options.platform,
|
||||
buildId: options.buildId,
|
||||
};
|
||||
}
|
||||
try {
|
||||
debugInstall(`Downloading binary from ${url}`);
|
||||
try {
|
||||
debugTime('download');
|
||||
await (0, httpUtil_js_1.downloadFile)(url, archivePath, options.downloadProgressCallback);
|
||||
}
|
||||
finally {
|
||||
debugTimeEnd('download');
|
||||
}
|
||||
debugInstall(`Installing ${archivePath} to ${outputPath}`);
|
||||
try {
|
||||
debugTime('extract');
|
||||
await (0, fileUtil_js_1.unpackArchive)(archivePath, outputPath);
|
||||
}
|
||||
finally {
|
||||
debugTimeEnd('extract');
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ((0, fs_1.existsSync)(archivePath)) {
|
||||
await (0, promises_1.unlink)(archivePath);
|
||||
}
|
||||
}
|
||||
return {
|
||||
path: outputPath,
|
||||
browser: options.browser,
|
||||
platform: options.platform,
|
||||
buildId: options.buildId,
|
||||
};
|
||||
}
|
||||
exports.install = install;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
async function canDownload(options) {
|
||||
var _a;
|
||||
(_a = options.platform) !== null && _a !== void 0 ? _a : (options.platform = (0, detectPlatform_js_1.detectBrowserPlatform)());
|
||||
if (!options.platform) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
return await (0, httpUtil_js_1.headHttpRequest)(getDownloadUrl(options.browser, options.platform, options.buildId, options.baseUrl));
|
||||
}
|
||||
exports.canDownload = canDownload;
|
||||
function getDownloadUrl(browser, platform, buildId, baseUrl) {
|
||||
return new URL(browser_data_js_1.downloadUrls[browser](platform, buildId, baseUrl));
|
||||
}
|
||||
//# sourceMappingURL=install.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"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"}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import childProcess from 'child_process';
|
||||
import { Browser, BrowserPlatform, ChromeReleaseChannel } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface ComputeExecutablePathOptions {
|
||||
/**
|
||||
* Root path to the storage directory.
|
||||
*/
|
||||
cacheDir: string;
|
||||
/**
|
||||
* Determines which platform the browser will be suited for.
|
||||
*
|
||||
* @defaultValue **Auto-detected.**
|
||||
*/
|
||||
platform?: BrowserPlatform;
|
||||
/**
|
||||
* Determines which browser to launch.
|
||||
*/
|
||||
browser: Browser;
|
||||
/**
|
||||
* Determines which buildId to download. BuildId should uniquely identify
|
||||
* binaries and they are used for caching.
|
||||
*/
|
||||
buildId: string;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function computeExecutablePath(options: ComputeExecutablePathOptions): string;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface SystemOptions {
|
||||
/**
|
||||
* Determines which platform the browser will be suited for.
|
||||
*
|
||||
* @defaultValue **Auto-detected.**
|
||||
*/
|
||||
platform?: BrowserPlatform;
|
||||
/**
|
||||
* Determines which browser to launch.
|
||||
*/
|
||||
browser: Browser;
|
||||
/**
|
||||
* Release channel to look for on the system.
|
||||
*/
|
||||
channel: ChromeReleaseChannel;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function computeSystemExecutablePath(options: SystemOptions): string;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type LaunchOptions = {
|
||||
executablePath: string;
|
||||
pipe?: boolean;
|
||||
dumpio?: boolean;
|
||||
args?: string[];
|
||||
env?: Record<string, string | undefined>;
|
||||
handleSIGINT?: boolean;
|
||||
handleSIGTERM?: boolean;
|
||||
handleSIGHUP?: boolean;
|
||||
detached?: boolean;
|
||||
onExit?: () => Promise<void>;
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function launch(opts: LaunchOptions): Process;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare const CDP_WEBSOCKET_ENDPOINT_REGEX: RegExp;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare const WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX: RegExp;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare class Process {
|
||||
#private;
|
||||
constructor(opts: LaunchOptions);
|
||||
get nodeProcess(): childProcess.ChildProcess;
|
||||
close(): Promise<void>;
|
||||
hasClosed(): Promise<void>;
|
||||
kill(): void;
|
||||
waitForLineOutput(regex: RegExp, timeout?: number): Promise<string>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface ErrorLike extends Error {
|
||||
name: string;
|
||||
message: string;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare function isErrorLike(obj: unknown): obj is ErrorLike;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare function isErrnoException(obj: unknown): obj is NodeJS.ErrnoException;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare class TimeoutError extends Error {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(message?: string);
|
||||
}
|
||||
//# sourceMappingURL=launch.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../src/launch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,OAAO,YAAY,MAAM,eAAe,CAAC;AAMzC,OAAO,EACL,OAAO,EACP,eAAe,EAGf,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AAOxC;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,4BAA4B,GACpC,MAAM,CAgBR;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAoB1E;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAEF;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,QACF,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,uCAAuC,QACP,CAAC;AAE9C;;GAEG;AACH,qBAAa,OAAO;;gBAYN,IAAI,EAAE,aAAa;IA8E/B,IAAI,WAAW,IAAI,YAAY,CAAC,YAAY,CAE3C;IA4CK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,IAAI,IAAI,IAAI;IAwDZ,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA8DpE;AAuBD;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAI1D;AACD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,cAAc,CAK3E;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC;;OAEG;gBACS,OAAO,CAAC,EAAE,MAAM;CAK7B"}
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _Process_instances, _Process_executablePath, _Process_args, _Process_browserProcess, _Process_exited, _Process_hooksRan, _Process_onExitHook, _Process_browserProcessExiting, _Process_runHooks, _Process_configureStdio, _Process_clearListeners, _Process_onDriverProcessExit, _Process_onDriverProcessSignal;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TimeoutError = exports.isErrnoException = exports.isErrorLike = exports.Process = exports.WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX = exports.CDP_WEBSOCKET_ENDPOINT_REGEX = exports.launch = exports.computeSystemExecutablePath = exports.computeExecutablePath = void 0;
|
||||
const child_process_1 = __importDefault(require("child_process"));
|
||||
const fs_1 = require("fs");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const readline_1 = __importDefault(require("readline"));
|
||||
const browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
const Cache_js_1 = require("./Cache.js");
|
||||
const debug_js_1 = require("./debug.js");
|
||||
const detectPlatform_js_1 = require("./detectPlatform.js");
|
||||
const debugLaunch = (0, debug_js_1.debug)('puppeteer:browsers:launcher');
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function computeExecutablePath(options) {
|
||||
var _a;
|
||||
(_a = options.platform) !== null && _a !== void 0 ? _a : (options.platform = (0, detectPlatform_js_1.detectBrowserPlatform)());
|
||||
if (!options.platform) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
const installationDir = new Cache_js_1.Cache(options.cacheDir).installationDir(options.browser, options.platform, options.buildId);
|
||||
return path_1.default.join(installationDir, browser_data_js_1.executablePathByBrowser[options.browser](options.platform, options.buildId));
|
||||
}
|
||||
exports.computeExecutablePath = computeExecutablePath;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function computeSystemExecutablePath(options) {
|
||||
var _a;
|
||||
(_a = options.platform) !== null && _a !== void 0 ? _a : (options.platform = (0, detectPlatform_js_1.detectBrowserPlatform)());
|
||||
if (!options.platform) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
const path = (0, browser_data_js_1.resolveSystemExecutablePath)(options.browser, options.platform, options.channel);
|
||||
try {
|
||||
(0, fs_1.accessSync)(path);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error(`Could not find Google Chrome executable for channel '${options.channel}' at '${path}'.`);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
exports.computeSystemExecutablePath = computeSystemExecutablePath;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
function launch(opts) {
|
||||
return new Process(opts);
|
||||
}
|
||||
exports.launch = launch;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
exports.CDP_WEBSOCKET_ENDPOINT_REGEX = /^DevTools listening on (ws:\/\/.*)$/;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
exports.WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX = /^WebDriver BiDi listening on (ws:\/\/.*)$/;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
class Process {
|
||||
constructor(opts) {
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
||||
_Process_instances.add(this);
|
||||
_Process_executablePath.set(this, void 0);
|
||||
_Process_args.set(this, void 0);
|
||||
_Process_browserProcess.set(this, void 0);
|
||||
_Process_exited.set(this, false);
|
||||
// The browser process can be closed externally or from the driver process. We
|
||||
// need to invoke the hooks only once though but we don't know how many times
|
||||
// we will be invoked.
|
||||
_Process_hooksRan.set(this, false);
|
||||
_Process_onExitHook.set(this, async () => { });
|
||||
_Process_browserProcessExiting.set(this, void 0);
|
||||
_Process_onDriverProcessExit.set(this, (_code) => {
|
||||
this.kill();
|
||||
});
|
||||
_Process_onDriverProcessSignal.set(this, (signal) => {
|
||||
switch (signal) {
|
||||
case 'SIGINT':
|
||||
this.kill();
|
||||
process.exit(130);
|
||||
case 'SIGTERM':
|
||||
case 'SIGHUP':
|
||||
this.close();
|
||||
break;
|
||||
}
|
||||
});
|
||||
__classPrivateFieldSet(this, _Process_executablePath, opts.executablePath, "f");
|
||||
__classPrivateFieldSet(this, _Process_args, (_a = opts.args) !== null && _a !== void 0 ? _a : [], "f");
|
||||
(_b = opts.pipe) !== null && _b !== void 0 ? _b : (opts.pipe = false);
|
||||
(_c = opts.dumpio) !== null && _c !== void 0 ? _c : (opts.dumpio = false);
|
||||
(_d = opts.handleSIGINT) !== null && _d !== void 0 ? _d : (opts.handleSIGINT = true);
|
||||
(_e = opts.handleSIGTERM) !== null && _e !== void 0 ? _e : (opts.handleSIGTERM = true);
|
||||
(_f = opts.handleSIGHUP) !== null && _f !== void 0 ? _f : (opts.handleSIGHUP = true);
|
||||
// On non-windows platforms, `detached: true` makes child process a
|
||||
// leader of a new process group, making it possible to kill child
|
||||
// process tree with `.kill(-pid)` command. @see
|
||||
// https://nodejs.org/api/child_process.html#child_process_options_detached
|
||||
(_g = opts.detached) !== null && _g !== void 0 ? _g : (opts.detached = process.platform !== 'win32');
|
||||
const stdio = __classPrivateFieldGet(this, _Process_instances, "m", _Process_configureStdio).call(this, {
|
||||
pipe: opts.pipe,
|
||||
dumpio: opts.dumpio,
|
||||
});
|
||||
debugLaunch(`Launching ${__classPrivateFieldGet(this, _Process_executablePath, "f")} ${__classPrivateFieldGet(this, _Process_args, "f").join(' ')}`, {
|
||||
detached: opts.detached,
|
||||
env: opts.env,
|
||||
stdio,
|
||||
});
|
||||
__classPrivateFieldSet(this, _Process_browserProcess, child_process_1.default.spawn(__classPrivateFieldGet(this, _Process_executablePath, "f"), __classPrivateFieldGet(this, _Process_args, "f"), {
|
||||
detached: opts.detached,
|
||||
env: opts.env,
|
||||
stdio,
|
||||
}), "f");
|
||||
debugLaunch(`Launched ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid}`);
|
||||
if (opts.dumpio) {
|
||||
(_h = __classPrivateFieldGet(this, _Process_browserProcess, "f").stderr) === null || _h === void 0 ? void 0 : _h.pipe(process.stderr);
|
||||
(_j = __classPrivateFieldGet(this, _Process_browserProcess, "f").stdout) === null || _j === void 0 ? void 0 : _j.pipe(process.stdout);
|
||||
}
|
||||
process.on('exit', __classPrivateFieldGet(this, _Process_onDriverProcessExit, "f"));
|
||||
if (opts.handleSIGINT) {
|
||||
process.on('SIGINT', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
}
|
||||
if (opts.handleSIGTERM) {
|
||||
process.on('SIGTERM', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
}
|
||||
if (opts.handleSIGHUP) {
|
||||
process.on('SIGHUP', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
}
|
||||
if (opts.onExit) {
|
||||
__classPrivateFieldSet(this, _Process_onExitHook, opts.onExit, "f");
|
||||
}
|
||||
__classPrivateFieldSet(this, _Process_browserProcessExiting, new Promise((resolve, reject) => {
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").once('exit', async () => {
|
||||
debugLaunch(`Browser process ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid} onExit`);
|
||||
__classPrivateFieldGet(this, _Process_instances, "m", _Process_clearListeners).call(this);
|
||||
__classPrivateFieldSet(this, _Process_exited, true, "f");
|
||||
try {
|
||||
await __classPrivateFieldGet(this, _Process_instances, "m", _Process_runHooks).call(this);
|
||||
}
|
||||
catch (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}), "f");
|
||||
}
|
||||
get nodeProcess() {
|
||||
return __classPrivateFieldGet(this, _Process_browserProcess, "f");
|
||||
}
|
||||
async close() {
|
||||
await __classPrivateFieldGet(this, _Process_instances, "m", _Process_runHooks).call(this);
|
||||
if (!__classPrivateFieldGet(this, _Process_exited, "f")) {
|
||||
this.kill();
|
||||
}
|
||||
return __classPrivateFieldGet(this, _Process_browserProcessExiting, "f");
|
||||
}
|
||||
hasClosed() {
|
||||
return __classPrivateFieldGet(this, _Process_browserProcessExiting, "f");
|
||||
}
|
||||
kill() {
|
||||
debugLaunch(`Trying to kill ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid}`);
|
||||
// If the process failed to launch (for example if the browser executable path
|
||||
// is invalid), then the process does not get a pid assigned. A call to
|
||||
// `proc.kill` would error, as the `pid` to-be-killed can not be found.
|
||||
if (__classPrivateFieldGet(this, _Process_browserProcess, "f") &&
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").pid &&
|
||||
pidExists(__classPrivateFieldGet(this, _Process_browserProcess, "f").pid)) {
|
||||
try {
|
||||
debugLaunch(`Browser process ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid} exists`);
|
||||
if (process.platform === 'win32') {
|
||||
try {
|
||||
child_process_1.default.execSync(`taskkill /pid ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid} /T /F`);
|
||||
}
|
||||
catch (error) {
|
||||
debugLaunch(`Killing ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid} using taskkill failed`, error);
|
||||
// taskkill can fail to kill the process e.g. due to missing permissions.
|
||||
// Let's kill the process via Node API. This delays killing of all child
|
||||
// processes of `this.proc` until the main Node.js process dies.
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").kill();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// on linux the process group can be killed with the group id prefixed with
|
||||
// a minus sign. The process group id is the group leader's pid.
|
||||
const processGroupId = -__classPrivateFieldGet(this, _Process_browserProcess, "f").pid;
|
||||
try {
|
||||
process.kill(processGroupId, 'SIGKILL');
|
||||
}
|
||||
catch (error) {
|
||||
debugLaunch(`Killing ${__classPrivateFieldGet(this, _Process_browserProcess, "f").pid} using process.kill failed`, error);
|
||||
// Killing the process group can fail due e.g. to missing permissions.
|
||||
// Let's kill the process via Node API. This delays killing of all child
|
||||
// processes of `this.proc` until the main Node.js process dies.
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").kill('SIGKILL');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error(`${PROCESS_ERROR_EXPLANATION}\nError cause: ${isErrorLike(error) ? error.stack : error}`);
|
||||
}
|
||||
}
|
||||
__classPrivateFieldGet(this, _Process_instances, "m", _Process_clearListeners).call(this);
|
||||
}
|
||||
waitForLineOutput(regex, timeout) {
|
||||
if (!__classPrivateFieldGet(this, _Process_browserProcess, "f").stderr) {
|
||||
throw new Error('`browserProcess` does not have stderr.');
|
||||
}
|
||||
const rl = readline_1.default.createInterface(__classPrivateFieldGet(this, _Process_browserProcess, "f").stderr);
|
||||
let stderr = '';
|
||||
return new Promise((resolve, reject) => {
|
||||
rl.on('line', onLine);
|
||||
rl.on('close', onClose);
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").on('exit', onClose);
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").on('error', onClose);
|
||||
const timeoutId = timeout ? setTimeout(onTimeout, timeout) : 0;
|
||||
const cleanup = () => {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
rl.off('line', onLine);
|
||||
rl.off('close', onClose);
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").off('exit', onClose);
|
||||
__classPrivateFieldGet(this, _Process_browserProcess, "f").off('error', onClose);
|
||||
};
|
||||
function onClose(error) {
|
||||
cleanup();
|
||||
reject(new Error([
|
||||
`Failed to launch the browser process!${error ? ' ' + error.message : ''}`,
|
||||
stderr,
|
||||
'',
|
||||
'TROUBLESHOOTING: https://pptr.dev/troubleshooting',
|
||||
'',
|
||||
].join('\n')));
|
||||
}
|
||||
function onTimeout() {
|
||||
cleanup();
|
||||
reject(new TimeoutError(`Timed out after ${timeout} ms while waiting for the WS endpoint URL to appear in stdout!`));
|
||||
}
|
||||
function onLine(line) {
|
||||
stderr += line + '\n';
|
||||
const match = line.match(regex);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
cleanup();
|
||||
// The RegExp matches, so this will obviously exist.
|
||||
resolve(match[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.Process = Process;
|
||||
_Process_executablePath = new WeakMap(), _Process_args = new WeakMap(), _Process_browserProcess = new WeakMap(), _Process_exited = new WeakMap(), _Process_hooksRan = new WeakMap(), _Process_onExitHook = new WeakMap(), _Process_browserProcessExiting = new WeakMap(), _Process_onDriverProcessExit = new WeakMap(), _Process_onDriverProcessSignal = new WeakMap(), _Process_instances = new WeakSet(), _Process_runHooks = async function _Process_runHooks() {
|
||||
if (__classPrivateFieldGet(this, _Process_hooksRan, "f")) {
|
||||
return;
|
||||
}
|
||||
__classPrivateFieldSet(this, _Process_hooksRan, true, "f");
|
||||
await __classPrivateFieldGet(this, _Process_onExitHook, "f").call(this);
|
||||
}, _Process_configureStdio = function _Process_configureStdio(opts) {
|
||||
if (opts.pipe) {
|
||||
if (opts.dumpio) {
|
||||
return ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
|
||||
}
|
||||
else {
|
||||
return ['ignore', 'ignore', 'ignore', 'pipe', 'pipe'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (opts.dumpio) {
|
||||
return ['pipe', 'pipe', 'pipe'];
|
||||
}
|
||||
else {
|
||||
return ['pipe', 'ignore', 'pipe'];
|
||||
}
|
||||
}
|
||||
}, _Process_clearListeners = function _Process_clearListeners() {
|
||||
process.off('exit', __classPrivateFieldGet(this, _Process_onDriverProcessExit, "f"));
|
||||
process.off('SIGINT', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
process.off('SIGTERM', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
process.off('SIGHUP', __classPrivateFieldGet(this, _Process_onDriverProcessSignal, "f"));
|
||||
};
|
||||
const PROCESS_ERROR_EXPLANATION = `Puppeteer was unable to kill the process which ran the browser binary.
|
||||
This means that, on future Puppeteer launches, Puppeteer might not be able to launch the browser.
|
||||
Please check your open processes and ensure that the browser processes that Puppeteer launched have been killed.
|
||||
If you think this is a bug, please report it on the Puppeteer issue tracker.`;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function pidExists(pid) {
|
||||
try {
|
||||
return process.kill(pid, 0);
|
||||
}
|
||||
catch (error) {
|
||||
if (isErrnoException(error)) {
|
||||
if (error.code && error.code === 'ESRCH') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function isErrorLike(obj) {
|
||||
return (typeof obj === 'object' && obj !== null && 'name' in obj && 'message' in obj);
|
||||
}
|
||||
exports.isErrorLike = isErrorLike;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function isErrnoException(obj) {
|
||||
return (isErrorLike(obj) &&
|
||||
('errno' in obj || 'code' in obj || 'path' in obj || 'syscall' in obj));
|
||||
}
|
||||
exports.isErrnoException = isErrnoException;
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
class TimeoutError extends Error {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
exports.TimeoutError = TimeoutError;
|
||||
//# sourceMappingURL=launch.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+18
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export {};
|
||||
//# sourceMappingURL=main-cli.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"main-cli.d.ts","sourceRoot":"","sources":["../../src/main-cli.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;GAcG"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const CLI_js_1 = require("./CLI.js");
|
||||
new CLI_js_1.CLI().run(process.argv);
|
||||
//# sourceMappingURL=main-cli.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"main-cli.js","sourceRoot":"","sources":["../../src/main-cli.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;GAcG;;AAEH,qCAA6B;AAE7B,IAAI,YAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { launch, computeExecutablePath, computeSystemExecutablePath, TimeoutError, LaunchOptions, ComputeExecutablePathOptions as Options, SystemOptions, CDP_WEBSOCKET_ENDPOINT_REGEX, WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX, Process, } from './launch.js';
|
||||
export { install, canDownload, InstallOptions } from './install.js';
|
||||
export { detectBrowserPlatform } from './detectPlatform.js';
|
||||
export { resolveBuildId, Browser, BrowserPlatform, ChromeReleaseChannel, createProfile, ProfileOptions, } from './browser-data/browser-data.js';
|
||||
export { CLI, makeProgressCallback } from './CLI.js';
|
||||
export { Cache, InstalledBrowser } from './Cache.js';
|
||||
//# sourceMappingURL=main.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,MAAM,EACN,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,aAAa,EACb,4BAA4B,IAAI,OAAO,EACvC,aAAa,EACb,4BAA4B,EAC5B,uCAAuC,EACvC,OAAO,GACR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAClE,OAAO,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,cAAc,GACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAC,GAAG,EAAE,oBAAoB,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,KAAK,EAAE,gBAAgB,EAAC,MAAM,YAAY,CAAC"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Cache = exports.makeProgressCallback = exports.CLI = exports.createProfile = exports.ChromeReleaseChannel = exports.BrowserPlatform = exports.Browser = exports.resolveBuildId = exports.detectBrowserPlatform = exports.canDownload = exports.install = exports.Process = exports.WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX = exports.CDP_WEBSOCKET_ENDPOINT_REGEX = exports.TimeoutError = exports.computeSystemExecutablePath = exports.computeExecutablePath = exports.launch = void 0;
|
||||
var launch_js_1 = require("./launch.js");
|
||||
Object.defineProperty(exports, "launch", { enumerable: true, get: function () { return launch_js_1.launch; } });
|
||||
Object.defineProperty(exports, "computeExecutablePath", { enumerable: true, get: function () { return launch_js_1.computeExecutablePath; } });
|
||||
Object.defineProperty(exports, "computeSystemExecutablePath", { enumerable: true, get: function () { return launch_js_1.computeSystemExecutablePath; } });
|
||||
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return launch_js_1.TimeoutError; } });
|
||||
Object.defineProperty(exports, "CDP_WEBSOCKET_ENDPOINT_REGEX", { enumerable: true, get: function () { return launch_js_1.CDP_WEBSOCKET_ENDPOINT_REGEX; } });
|
||||
Object.defineProperty(exports, "WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX", { enumerable: true, get: function () { return launch_js_1.WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX; } });
|
||||
Object.defineProperty(exports, "Process", { enumerable: true, get: function () { return launch_js_1.Process; } });
|
||||
var install_js_1 = require("./install.js");
|
||||
Object.defineProperty(exports, "install", { enumerable: true, get: function () { return install_js_1.install; } });
|
||||
Object.defineProperty(exports, "canDownload", { enumerable: true, get: function () { return install_js_1.canDownload; } });
|
||||
var detectPlatform_js_1 = require("./detectPlatform.js");
|
||||
Object.defineProperty(exports, "detectBrowserPlatform", { enumerable: true, get: function () { return detectPlatform_js_1.detectBrowserPlatform; } });
|
||||
var browser_data_js_1 = require("./browser-data/browser-data.js");
|
||||
Object.defineProperty(exports, "resolveBuildId", { enumerable: true, get: function () { return browser_data_js_1.resolveBuildId; } });
|
||||
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return browser_data_js_1.Browser; } });
|
||||
Object.defineProperty(exports, "BrowserPlatform", { enumerable: true, get: function () { return browser_data_js_1.BrowserPlatform; } });
|
||||
Object.defineProperty(exports, "ChromeReleaseChannel", { enumerable: true, get: function () { return browser_data_js_1.ChromeReleaseChannel; } });
|
||||
Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return browser_data_js_1.createProfile; } });
|
||||
var CLI_js_1 = require("./CLI.js");
|
||||
Object.defineProperty(exports, "CLI", { enumerable: true, get: function () { return CLI_js_1.CLI; } });
|
||||
Object.defineProperty(exports, "makeProgressCallback", { enumerable: true, get: function () { return CLI_js_1.makeProgressCallback; } });
|
||||
var Cache_js_1 = require("./Cache.js");
|
||||
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return Cache_js_1.Cache; } });
|
||||
//# sourceMappingURL=main.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,yCAWqB;AAVnB,mGAAA,MAAM,OAAA;AACN,kHAAA,qBAAqB,OAAA;AACrB,wHAAA,2BAA2B,OAAA;AAC3B,yGAAA,YAAY,OAAA;AAIZ,yHAAA,4BAA4B,OAAA;AAC5B,oIAAA,uCAAuC,OAAA;AACvC,oGAAA,OAAO,OAAA;AAET,2CAAkE;AAA1D,qGAAA,OAAO,OAAA;AAAE,yGAAA,WAAW,OAAA;AAC5B,yDAA0D;AAAlD,0HAAA,qBAAqB,OAAA;AAC7B,kEAOwC;AANtC,iHAAA,cAAc,OAAA;AACd,0GAAA,OAAO,OAAA;AACP,kHAAA,eAAe,OAAA;AACf,uHAAA,oBAAoB,OAAA;AACpB,gHAAA,aAAa,OAAA;AAGf,mCAAmD;AAA3C,6FAAA,GAAG,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AACjC,uCAAmD;AAA3C,iGAAA,KAAK,OAAA"}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import * as readline from 'readline';
|
||||
import { Browser } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare class CLI {
|
||||
#private;
|
||||
constructor(cachePath?: string, rl?: readline.Interface);
|
||||
run(argv: string[]): Promise<void>;
|
||||
}
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare function makeProgressCallback(browser: Browser, buildId: string): (downloadedBytes: number, totalBytes: number) => void;
|
||||
//# sourceMappingURL=CLI.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"CLI.d.ts","sourceRoot":"","sources":["../../src/CLI.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;AAGH,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAOrC,OAAO,EAEL,OAAO,EAGR,MAAM,gCAAgC,CAAC;AAmCxC;;GAEG;AACH,qBAAa,GAAG;;gBAIF,SAAS,SAAgB,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,SAAS;IAwCxD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAuKzC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAqBvD"}
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
||||
if (kind === "m") throw new TypeError("Private method is not writable");
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
||||
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
||||
};
|
||||
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
||||
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
||||
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
||||
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
||||
};
|
||||
var _CLI_instances, _CLI_cachePath, _CLI_rl, _CLI_defineBrowserParameter, _CLI_definePlatformParameter, _CLI_definePathParameter, _CLI_parseBrowser, _CLI_parseBuildId;
|
||||
import { stdin as input, stdout as output } from 'process';
|
||||
import * as readline from 'readline';
|
||||
import ProgressBar from 'progress';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import yargs from 'yargs/yargs';
|
||||
import { resolveBuildId, BrowserPlatform, } from './browser-data/browser-data.js';
|
||||
import { Cache } from './Cache.js';
|
||||
import { detectBrowserPlatform } from './detectPlatform.js';
|
||||
import { install } from './install.js';
|
||||
import { computeExecutablePath, computeSystemExecutablePath, launch, } from './launch.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export class CLI {
|
||||
constructor(cachePath = process.cwd(), rl) {
|
||||
_CLI_instances.add(this);
|
||||
_CLI_cachePath.set(this, void 0);
|
||||
_CLI_rl.set(this, void 0);
|
||||
__classPrivateFieldSet(this, _CLI_cachePath, cachePath, "f");
|
||||
__classPrivateFieldSet(this, _CLI_rl, rl, "f");
|
||||
}
|
||||
async run(argv) {
|
||||
const yargsInstance = yargs(hideBin(argv));
|
||||
await yargsInstance
|
||||
.scriptName('@puppeteer/browsers')
|
||||
.command('install <browser>', 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_defineBrowserParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePlatformParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs);
|
||||
yargs.option('base-url', {
|
||||
type: 'string',
|
||||
desc: 'Base URL to download from',
|
||||
});
|
||||
yargs.example('$0 install chrome', 'Install the latest available build of the Chrome browser.');
|
||||
yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.');
|
||||
yargs.example('$0 install chromium@1083080', 'Install the revision 1083080 of the Chromium browser.');
|
||||
yargs.example('$0 install firefox', 'Install the latest available build of the Firefox browser.');
|
||||
yargs.example('$0 install firefox --platform mac', 'Install the latest Mac (Intel) build of the Firefox browser.');
|
||||
yargs.example('$0 install firefox --path /tmp/my-browser-cache', 'Install to the specified cache directory.');
|
||||
}, async (argv) => {
|
||||
var _a, _b, _c;
|
||||
const args = argv;
|
||||
(_a = args.platform) !== null && _a !== void 0 ? _a : (args.platform = detectBrowserPlatform());
|
||||
if (!args.platform) {
|
||||
throw new Error(`Could not resolve the current platform`);
|
||||
}
|
||||
args.browser.buildId = await resolveBuildId(args.browser.name, args.platform, args.browser.buildId);
|
||||
await install({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
platform: args.platform,
|
||||
cacheDir: (_b = args.path) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId),
|
||||
baseUrl: args.baseUrl,
|
||||
});
|
||||
console.log(`${args.browser.name}@${args.browser.buildId} ${computeExecutablePath({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
cacheDir: (_c = args.path) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
platform: args.platform,
|
||||
})}`);
|
||||
})
|
||||
.command('launch <browser>', 'Launch the specified browser', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_defineBrowserParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePlatformParameter).call(this, yargs);
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs);
|
||||
yargs.option('detached', {
|
||||
type: 'boolean',
|
||||
desc: 'Detach the child process.',
|
||||
default: false,
|
||||
});
|
||||
yargs.option('system', {
|
||||
type: 'boolean',
|
||||
desc: 'Search for a browser installed on the system instead of the cache folder.',
|
||||
default: false,
|
||||
});
|
||||
yargs.example('$0 launch chrome@1083080', 'Launch the Chrome browser identified by the revision 1083080.');
|
||||
yargs.example('$0 launch firefox@112.0a1', 'Launch the Firefox browser identified by the milestone 112.0a1.');
|
||||
yargs.example('$0 launch chrome@1083080 --detached', 'Launch the browser but detach the sub-processes.');
|
||||
yargs.example('$0 launch chrome@canary --system', 'Try to locate the Canary build of Chrome installed on the system and launch it.');
|
||||
}, async (argv) => {
|
||||
var _a;
|
||||
const args = argv;
|
||||
const executablePath = args.system
|
||||
? computeSystemExecutablePath({
|
||||
browser: args.browser.name,
|
||||
// TODO: throw an error if not a ChromeReleaseChannel is provided.
|
||||
channel: args.browser.buildId,
|
||||
platform: args.platform,
|
||||
})
|
||||
: computeExecutablePath({
|
||||
browser: args.browser.name,
|
||||
buildId: args.browser.buildId,
|
||||
cacheDir: (_a = args.path) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _CLI_cachePath, "f"),
|
||||
platform: args.platform,
|
||||
});
|
||||
launch({
|
||||
executablePath,
|
||||
detached: args.detached,
|
||||
});
|
||||
})
|
||||
.command('clear', 'Removes all installed browsers from the specified cache directory', yargs => {
|
||||
__classPrivateFieldGet(this, _CLI_instances, "m", _CLI_definePathParameter).call(this, yargs, true);
|
||||
}, async (argv) => {
|
||||
var _a, _b;
|
||||
const args = argv;
|
||||
const cacheDir = (_a = args.path) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _CLI_cachePath, "f");
|
||||
const rl = (_b = __classPrivateFieldGet(this, _CLI_rl, "f")) !== null && _b !== void 0 ? _b : readline.createInterface({ input, output });
|
||||
rl.question(`Do you want to permanently and recursively delete the content of ${cacheDir} (yes/No)? `, answer => {
|
||||
rl.close();
|
||||
if (!['y', 'yes'].includes(answer.toLowerCase().trim())) {
|
||||
console.log('Cancelled.');
|
||||
return;
|
||||
}
|
||||
const cache = new Cache(cacheDir);
|
||||
cache.clear();
|
||||
console.log(`${cacheDir} cleared.`);
|
||||
});
|
||||
})
|
||||
.demandCommand(1)
|
||||
.help()
|
||||
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
||||
.parse();
|
||||
}
|
||||
}
|
||||
_CLI_cachePath = new WeakMap(), _CLI_rl = new WeakMap(), _CLI_instances = new WeakSet(), _CLI_defineBrowserParameter = function _CLI_defineBrowserParameter(yargs) {
|
||||
yargs.positional('browser', {
|
||||
description: 'Which browser to install <browser>[@<buildId|latest>]. `latest` will try to find the latest available build. `buildId` is a browser-specific identifier such as a version or a revision.',
|
||||
type: 'string',
|
||||
coerce: (opt) => {
|
||||
return {
|
||||
name: __classPrivateFieldGet(this, _CLI_instances, "m", _CLI_parseBrowser).call(this, opt),
|
||||
buildId: __classPrivateFieldGet(this, _CLI_instances, "m", _CLI_parseBuildId).call(this, opt),
|
||||
};
|
||||
},
|
||||
});
|
||||
}, _CLI_definePlatformParameter = function _CLI_definePlatformParameter(yargs) {
|
||||
yargs.option('platform', {
|
||||
type: 'string',
|
||||
desc: 'Platform that the binary needs to be compatible with.',
|
||||
choices: Object.values(BrowserPlatform),
|
||||
defaultDescription: 'Auto-detected',
|
||||
});
|
||||
}, _CLI_definePathParameter = function _CLI_definePathParameter(yargs, required = false) {
|
||||
yargs.option('path', {
|
||||
type: 'string',
|
||||
desc: 'Path to the root folder for the browser downloads and installation. The installation folder structure is compatible with the cache structure used by Puppeteer.',
|
||||
defaultDescription: 'Current working directory',
|
||||
...(required ? {} : { default: process.cwd() }),
|
||||
});
|
||||
if (required) {
|
||||
yargs.demandOption('path');
|
||||
}
|
||||
}, _CLI_parseBrowser = function _CLI_parseBrowser(version) {
|
||||
return version.split('@').shift();
|
||||
}, _CLI_parseBuildId = function _CLI_parseBuildId(version) {
|
||||
var _a;
|
||||
return (_a = version.split('@').pop()) !== null && _a !== void 0 ? _a : 'latest';
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function makeProgressCallback(browser, buildId) {
|
||||
let progressBar;
|
||||
let lastDownloadedBytes = 0;
|
||||
return (downloadedBytes, totalBytes) => {
|
||||
if (!progressBar) {
|
||||
progressBar = new ProgressBar(`Downloading ${browser} r${buildId} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
width: 20,
|
||||
total: totalBytes,
|
||||
});
|
||||
}
|
||||
const delta = downloadedBytes - lastDownloadedBytes;
|
||||
lastDownloadedBytes = downloadedBytes;
|
||||
progressBar.tick(delta);
|
||||
};
|
||||
}
|
||||
function toMegabytes(bytes) {
|
||||
const mb = bytes / 1000 / 1000;
|
||||
return `${Math.round(mb * 10) / 10} MB`;
|
||||
}
|
||||
//# sourceMappingURL=CLI.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Browser, BrowserPlatform } from './browser-data/browser-data.js';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type InstalledBrowser = {
|
||||
path: string;
|
||||
browser: Browser;
|
||||
buildId: string;
|
||||
platform: BrowserPlatform;
|
||||
};
|
||||
/**
|
||||
* The cache used by Puppeteer relies on the following structure:
|
||||
*
|
||||
* - rootDir
|
||||
* -- <browser1> | browserRoot(browser1)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* -- <browser2> | browserRoot(browser2)
|
||||
* ---- <platform>-<buildId> | installationDir()
|
||||
* ------ the browser-platform-buildId
|
||||
* ------ specific structure.
|
||||
* @internal
|
||||
*/
|
||||
export declare class Cache {
|
||||
#private;
|
||||
constructor(rootDir: string);
|
||||
browserRoot(browser: Browser): string;
|
||||
installationDir(browser: Browser, platform: BrowserPlatform, buildId: string): string;
|
||||
clear(): void;
|
||||
getInstalledBrowsers(): InstalledBrowser[];
|
||||
}
|
||||
//# sourceMappingURL=Cache.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../src/Cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAC,OAAO,EAAE,eAAe,EAAC,MAAM,gCAAgC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,KAAK;;gBAGJ,OAAO,EAAE,MAAM;IAI3B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IASrC,eAAe,CACb,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,MAAM,GACd,MAAM;IAIT,KAAK,IAAI,IAAI;IASb,oBAAoB,IAAI,gBAAgB,EAAE;CA8B3C"}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user