Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@percy/core

Package Overview
Dependencies
Maintainers
6
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/core - npm Package Compare versions

Comparing version 1.0.0-beta.31 to 1.0.0-beta.32

26

dist/config.js

@@ -6,2 +6,3 @@ "use strict";

});
exports.migration = migration;
exports.schema = void 0;

@@ -97,3 +98,24 @@ // Common options used in Percy commands

}
};
exports.schema = schema;
}; // Migration function
exports.schema = schema;
function migration(input, set) {
/* eslint-disable curly */
if (input.version < 2) {
var _input$agent, _input$agent$assetDis, _input$agent2, _input$agent2$assetDi, _input$agent3, _input$agent3$assetDi, _input$agent4, _input$agent4$assetDi, _input$agent5, _input$agent5$assetDi;
// previous snapshot options map 1:1
if (input.snapshot != null) set('snapshot', input.snapshot); // request-headers option moved
if (((_input$agent = input.agent) === null || _input$agent === void 0 ? void 0 : (_input$agent$assetDis = _input$agent.assetDiscovery) === null || _input$agent$assetDis === void 0 ? void 0 : _input$agent$assetDis.requestHeaders) != null) set('snapshot.requestHeaders', input.agent.assetDiscovery.requestHeaders); // allowed-hostnames moved
if (((_input$agent2 = input.agent) === null || _input$agent2 === void 0 ? void 0 : (_input$agent2$assetDi = _input$agent2.assetDiscovery) === null || _input$agent2$assetDi === void 0 ? void 0 : _input$agent2$assetDi.allowedHostnames) != null) set('discovery.allowedHostnames', input.agent.assetDiscovery.allowedHostnames); // network-idle-timeout moved
if (((_input$agent3 = input.agent) === null || _input$agent3 === void 0 ? void 0 : (_input$agent3$assetDi = _input$agent3.assetDiscovery) === null || _input$agent3$assetDi === void 0 ? void 0 : _input$agent3$assetDi.networkIdleTimeout) != null) set('discovery.networkIdleTimeout', input.agent.assetDiscovery.networkIdleTimeout); // page pooling was rewritten to be a concurrent task queue
if (((_input$agent4 = input.agent) === null || _input$agent4 === void 0 ? void 0 : (_input$agent4$assetDi = _input$agent4.assetDiscovery) === null || _input$agent4$assetDi === void 0 ? void 0 : _input$agent4$assetDi.pagePoolSizeMax) != null) set('discovery.concurrency', input.agent.assetDiscovery.pagePoolSizeMax); // cache-responses was renamed to match the CLI flag
if (((_input$agent5 = input.agent) === null || _input$agent5 === void 0 ? void 0 : (_input$agent5$assetDi = _input$agent5.assetDiscovery) === null || _input$agent5$assetDi === void 0 ? void 0 : _input$agent5$assetDi.cacheResponses) != null) set('discovery.disableCache', !input.agent.assetDiscovery.cacheResponses);
}
}

50

dist/discovery/browser.js

@@ -36,8 +36,4 @@ "use strict";

var _pages = new WeakMap();
var _callbacks = new WeakMap();
var _closed = new WeakMap();
var _lastid = new WeakMap();

@@ -49,9 +45,8 @@

_defineProperty(this, "log", (0, _logger.default)('core:discovery:browser'));
_defineProperty(this, "log", (0, _logger.default)('core:browser'));
_pages.set(this, {
writable: true,
value: new Map()
});
_defineProperty(this, "pages", new Map());
_defineProperty(this, "closed", false);
_callbacks.set(this, {

@@ -62,7 +57,2 @@ writable: true,

_closed.set(this, {
writable: true,
value: false
});
_lastid.set(this, {

@@ -132,7 +122,5 @@ writable: true,

async close() {
if (_classPrivateFieldGet(this, _closed)) return;
if (this.closed) return;
this.closed = true; // reject any pending callbacks
_classPrivateFieldSet(this, _closed, true); // reject any pending callbacks
for (let callback of _classPrivateFieldGet(this, _callbacks).values()) {

@@ -145,3 +133,3 @@ callback.reject(Object.assign(callback.error, {

for (let page of _classPrivateFieldGet(this, _pages).values()) {
for (let page of this.pages.values()) {
page._handleClose();

@@ -153,7 +141,6 @@ } // clear callback and page references

_classPrivateFieldGet(this, _pages).clear(); // no executable means the browser never launched
this.pages.clear(); // no executable means the browser never launched
/* istanbul ignore next: sanity */
if (!this.executable) return; // attempt to close the browser gracefully

@@ -209,3 +196,3 @@

});
return _classPrivateFieldGet(this, _pages).get(sessionId).init({
return this.pages.get(sessionId).init({
meta

@@ -248,5 +235,3 @@ });

async address(timeout = 30000) {
/* istanbul ignore next: this is not called twice but might be in the future */
if (this._address) return this._address;
this._address = await new Promise((resolve, reject) => {
this._address || (this._address = await new Promise((resolve, reject) => {
let stderr = '';

@@ -288,3 +273,3 @@

this.process.on('error', handleError);
});
}));
return this._address;

@@ -298,9 +283,7 @@ }

// create a new page reference when attached to a target
_classPrivateFieldGet(this, _pages).set(data.params.sessionId, new _page.default(this, data));
this.pages.set(data.params.sessionId, new _page.default(this, data));
} else if (data.method === 'Target.detachedFromTarget') {
// remove the old page reference when detached from a target
let page = _classPrivateFieldGet(this, _pages).get(data.params.sessionId);
_classPrivateFieldGet(this, _pages).delete(data.params.sessionId);
let page = this.pages.get(data.params.sessionId);
this.pages.delete(data.params.sessionId);
page === null || page === void 0 ? void 0 : page._handleClose();

@@ -311,4 +294,3 @@ }

// message was for a specific page that sent it
let page = _classPrivateFieldGet(this, _pages).get(data.sessionId);
let page = this.pages.get(data.sessionId);
page === null || page === void 0 ? void 0 : page._handleMessage(data);

@@ -326,3 +308,3 @@ } else if (data.id && _classPrivateFieldGet(this, _callbacks).has(data.id)) {

callback.reject(Object.assign(callback.error, {
message: `Protocol error (${callback.method}): ${data.error.message} ${data.error.data}`
message: `Protocol error (${callback.method}): ${data.error.message}` + ('data' in data.error ? `: ${data.error.data}` : '')
}));

@@ -329,0 +311,0 @@ } else {

@@ -10,3 +10,3 @@ "use strict";

var _queue2 = _interopRequireDefault(require("../queue"));
var _queue = _interopRequireDefault(require("../queue"));

@@ -19,3 +19,3 @@ var _assert = _interopRequireDefault(require("../utils/assert"));

var _browser2 = _interopRequireDefault(require("./browser"));
var _browser = _interopRequireDefault(require("./browser"));

@@ -28,4 +28,2 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to set private field on non-instance"); } if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } return value; }
const ALLOWED_STATUSES = [200, 201, 301, 302, 304, 307, 308]; // A PercyDiscoverer instance connects to a browser process and concurrently discovers resources

@@ -36,6 +34,2 @@ // for snapshots. Resources are only captured from the snapshot's root URL by default unless

var _queue = new WeakMap();
var _browser = new WeakMap();
var _cache = new WeakMap();

@@ -57,13 +51,7 @@

}) {
_defineProperty(this, "log", (0, _logger.default)('core:discovery'));
_defineProperty(this, "queue", null);
_queue.set(this, {
writable: true,
value: null
});
_defineProperty(this, "browser", null);
_browser.set(this, {
writable: true,
value: null
});
_defineProperty(this, "log", (0, _logger.default)('core:discovery'));

@@ -75,6 +63,4 @@ _cache.set(this, {

_classPrivateFieldSet(this, _queue, new _queue2.default(concurrency));
_classPrivateFieldSet(this, _browser, new _browser2.default());
this.queue = new _queue.default(concurrency);
this.browser = new _browser.default();
Object.assign(this, {

@@ -90,3 +76,3 @@ allowedHostnames,

async launch() {
await _classPrivateFieldGet(this, _browser).launch(this.launchOptions);
await this.browser.launch(this.launchOptions);
} // Returns true or false when the browser is connected.

@@ -96,3 +82,3 @@

isConnected() {
return _classPrivateFieldGet(this, _browser).isConnected();
return this.browser.isConnected();
} // Clears any unstarted discovery tasks and closes the browser.

@@ -102,5 +88,4 @@

async close() {
_classPrivateFieldGet(this, _queue).clear();
await _classPrivateFieldGet(this, _browser).close();
this.queue.clear();
await this.browser.close();
} // Returns a new browser page.

@@ -121,3 +106,3 @@

}) {
let page = await _classPrivateFieldGet(this, _browser).page({
let page = await this.browser.page({
meta

@@ -159,3 +144,3 @@ });

return _classPrivateFieldGet(this, _queue).push(async () => {
return this.queue.push(async () => {
this.log.debug(`Discovering resources @${width}px for ${rootUrl}`, { ...meta,

@@ -162,0 +147,0 @@ url: rootUrl

@@ -8,2 +8,4 @@ "use strict";

var _logger = _interopRequireDefault(require("@percy/logger"));
var _waitFor = _interopRequireDefault(require("../utils/wait-for"));

@@ -49,2 +51,4 @@

_defineProperty(this, "log", (0, _logger.default)('core:network'));
_defineProperty(this, "_handleAuthRequired", async event => {

@@ -253,2 +257,3 @@ let {

async idle(timeout = this.timeout) {
this.log.debug(`Wait for ${timeout}ms idle`, this.page.meta);
await (0, _waitFor.default)(() => {

@@ -255,0 +260,0 @@ if (this.page.closedReason) {

@@ -69,4 +69,2 @@ "use strict";

_defineProperty(this, "closedReason", null);
_callbacks.set(this, {

@@ -82,28 +80,23 @@ writable: true,

_defineProperty(this, "closedReason", null);
_defineProperty(this, "log", (0, _logger.default)('core:page'));
_defineProperty(this, "_handleLifecycleEvent", ({
frameId,
loaderId,
name
}) => {
if (_classPrivateFieldGet(this, _frameId) === frameId) {
if (name === 'init') _classPrivateFieldGet(this, _lifecycle).clear();
_defineProperty(this, "_handleLifecycleEvent", event => {
if (_classPrivateFieldGet(this, _frameId) === event.frameId) {
if (event.name === 'init') _classPrivateFieldGet(this, _lifecycle).clear();
_classPrivateFieldGet(this, _lifecycle).add(name);
_classPrivateFieldGet(this, _lifecycle).add(event.name);
}
});
_defineProperty(this, "_handleExecutionContextCreated", ({
context
}) => {
if (_classPrivateFieldGet(this, _frameId) === context.auxData.frameId) {
_classPrivateFieldSet(this, _contextId, context.id);
_defineProperty(this, "_handleExecutionContextCreated", event => {
if (_classPrivateFieldGet(this, _frameId) === event.context.auxData.frameId) {
_classPrivateFieldSet(this, _contextId, event.context.id);
}
});
_defineProperty(this, "_handleExecutionContextDestroyed", ({
executionContextId
}) => {
if (_classPrivateFieldGet(this, _contextId) === executionContextId) {
_defineProperty(this, "_handleExecutionContextDestroyed", event => {
/* istanbul ignore next: context cleared is usually called first */
if (_classPrivateFieldGet(this, _contextId) === event.executionContextId) {
_classPrivateFieldSet(this, _contextId, null);

@@ -169,15 +162,10 @@ }

} = {}) {
let handleNavigate = ({
frame
}) => {
this.log.debug('Handle page navigation', { ...this.meta,
frame
});
let handleNavigate = event => {
/* istanbul ignore next: sanity check */
if (_classPrivateFieldGet(this, _frameId) === frame.id) handleNavigate.done = true;
if (_classPrivateFieldGet(this, _frameId) === event.frame.id) handleNavigate.done = true;
};
try {
this.once('Page.frameNavigated', handleNavigate); // trigger navigation and handle error responses
this.once('Page.frameNavigated', handleNavigate);
this.log.debug(`Navigate to: ${url}`, this.meta); // trigger navigation and handle error responses

@@ -203,4 +191,5 @@ let navigate = this.send('Page.navigate', {

});
} // wait for the network to idle
}
this.log.debug('Page navigated', this.meta); // wait for the network to idle

@@ -249,4 +238,3 @@ await this.network.idle(); // wait for any specified timeout

fnbody = 'function withPercyHelpers() {' + (`return (${fnbody})({` + `waitFor: ${_waitFor.default}` + '}, ...arguments)') + '}';
this.log.debug('Evaluate function', this.meta); // send the call function command
fnbody = 'function withPercyHelpers() {' + (`return (${fnbody})({` + `waitFor: ${_waitFor.default}` + '}, ...arguments)') + '}'; // send the call function command

@@ -310,3 +298,5 @@ let {

callback.reject(Object.assign(callback.error, {
message: `Protocol error (${callback.method}): ${data.error.message} ${data.error.data}`
message: `Protocol error (${callback.method}): ${data.error.message}` + (
/* istanbul ignore next: doesn't always exist so don't print undefined */
'data' in data.error ? `: ${data.error.data}` : '')
}));

@@ -323,2 +313,3 @@ } else {

_handleClose() {
this.log.debug('Page closing', this.meta);
this.closedReason || (this.closedReason = 'Page closed.'); // reject any pending callbacks

@@ -325,0 +316,0 @@

"use strict";
// Register core config options
const {
default: PercyConfig
} = require('@percy/config');
const CoreConfig = require('./config');
PercyConfig.addSchema(CoreConfig.schema);
PercyConfig.addMigration(CoreConfig.migration); // Export the Percy class with commonjs compatibility
module.exports = require('./percy').default;

@@ -16,4 +16,2 @@ "use strict";

var _config2 = require("./config");
var _queue = _interopRequireDefault(require("./queue"));

@@ -41,9 +39,2 @@

// Register core config options
_config.default.addSchema(_config2.schema); // A Percy instance will create a new build when started, handle snapshot
// creation, asset discovery, and resource uploads, and will finalize the build
// when stopped. Snapshots are processed concurrently and the build is not
// finalized until all snapshots have been handled.
var _captures = new WeakMap();

@@ -57,2 +48,6 @@

// A Percy instance will create a new build when started, handle snapshot
// creation, asset discovery, and resource uploads, and will finalize the build
// when stopped. Snapshots are processed concurrently and the build is not
// finalized until all snapshots have been handled.
class Percy {

@@ -395,3 +390,3 @@ // Static shortcut to create and start an instance in one call

if (execute) {
this.log.debug('Executing page JS', { ...meta,
this.log.debug('Executing JavaScript', { ...meta,
execute

@@ -398,0 +393,0 @@ }); // accept function bodies as strings

@@ -30,6 +30,9 @@ "use strict";

browser = 'Chromium',
// default chromium version is 78.0.3904.x
revision = platform === 'win64' ?
/* istanbul ignore next */
'693951' : '693954',
// default chromium version is 87.0.4280.xx
revision = {
linux: '812847',
win64: '812845',
win32: '812822',
darwin: '812851'
}[platform],
// default download directory is in @percy/core root

@@ -36,0 +39,0 @@ directory = _path.default.resolve(__dirname, '../../.local-chromium'),

@@ -18,3 +18,3 @@ "use strict";

timeout,
ensure
idle
} = Number.isInteger(timeoutOrOptions) ? {

@@ -29,4 +29,4 @@ timeout: timeoutOrOptions

} else if (predicate()) {
if (ensure && !done) {
setTimeout(check, ensure, start, true);
if (idle && !done) {
setTimeout(check, idle, start, true);
} else {

@@ -33,0 +33,0 @@ resolve();

{
"name": "@percy/core",
"version": "1.0.0-beta.31",
"version": "1.0.0-beta.32",
"license": "MIT",

@@ -12,2 +12,5 @@ "main": "dist/index.js",

],
"engines": {
"node": ">=12"
},
"scripts": {

@@ -17,3 +20,3 @@ "build": "babel --root-mode upward src --out-dir dist",

"pretest": "node ../../scripts/install-browser",
"test": "cross-env NODE_ENV=test mocha",
"test": "cross-env NODE_ENV=test mocha --recursive",
"test:coverage": "nyc yarn test",

@@ -30,6 +33,6 @@ "test:types": "tsd"

"dependencies": {
"@percy/client": "^1.0.0-beta.31",
"@percy/config": "^1.0.0-beta.31",
"@percy/dom": "^1.0.0-beta.31",
"@percy/logger": "^1.0.0-beta.31",
"@percy/client": "^1.0.0-beta.32",
"@percy/config": "^1.0.0-beta.32",
"@percy/dom": "^1.0.0-beta.32",
"@percy/logger": "^1.0.0-beta.32",
"extract-zip": "^2.0.1",

@@ -40,3 +43,3 @@ "progress": "^2.0.3",

},
"gitHead": "6971cd1f6cf69c8516a091ee59bf6dabf8780820"
"gitHead": "edbef4c5ded9427447b25c13dda0ecd2639fc370"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc