Socket
Socket
Sign inDemoInstall

@percy/cli-snapshot

Package Overview
Dependencies
Maintainers
6
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@percy/cli-snapshot - npm Package Compare versions

Comparing version 1.0.0-beta.71 to 1.0.0-beta.72

dist/file.js

22

dist/config.js

@@ -6,5 +6,5 @@ "use strict";

});
exports.configSchema = exports.cliSchema = void 0;
exports.migration = migration;
exports.snapshotListSchema = exports.schemas = void 0;
exports.commonSchema = void 0;
exports.configMigration = configMigration;
exports.snapshotsFileSchema = exports.configSchema = void 0;

@@ -14,3 +14,3 @@ var _config = require("@percy/core/dist/config");

// Common schemas referenced by other schemas
const cliSchema = {
const commonSchema = {
$id: '/snapshot/cli',

@@ -35,3 +35,3 @@ $refs: {

exports.cliSchema = cliSchema;
exports.commonSchema = commonSchema;
const configSchema = {

@@ -100,7 +100,7 @@ static: {

}
}; // Page listing schema
}; // Snapshots file schema
exports.configSchema = configSchema;
const snapshotListSchema = {
$id: '/snapshot/list',
const snapshotsFileSchema = {
$id: '/snapshot/file',
oneOf: [{

@@ -138,7 +138,5 @@ type: 'array',

};
exports.snapshotListSchema = snapshotListSchema;
const schemas = [cliSchema, configSchema, snapshotListSchema];
exports.schemas = schemas;
exports.snapshotsFileSchema = snapshotsFileSchema;
function migration(config, util) {
function configMigration(config, util) {
/* eslint-disable curly */

@@ -145,0 +143,0 @@ if (config.version < 2) {

"use strict";
module.exports = require('./commands/snapshot').Snapshot;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "snapshot", {
enumerable: true,
get: function () {
return _snapshot.snapshot;
}
});
var _snapshot = require("./snapshot");

@@ -6,17 +6,8 @@ "use strict";

});
exports.mapStaticSnapshots = mapStaticSnapshots;
exports.serve = serve;
exports.snapshotMatches = snapshotMatches;
exports.validURL = validURL;
exports.withDefaults = withDefaults;
var _path = _interopRequireDefault(require("path"));
var pathToRegexp = _interopRequireWildcard(require("path-to-regexp"));
var _picomatch = _interopRequireDefault(require("picomatch"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -52,55 +43,2 @@

return options;
}
function mapRewrites(map, arr) {
return Object.entries(map).reduce((r, [source, destination]) => {
return (r || []).concat({
source,
destination
});
}, arr);
} // Serves a static directory with the provided options and returns an object containing adjusted
// rewrites (combined with any baseUrl), the server host, a close method, and the server
// instance. The `dryRun` option will prevent the server from actually starting.
async function serve(dir, {
dryRun,
baseUrl,
cleanUrls,
rewrites = {}
}) {
let host = 'http://localhost'; // map rewrite options with any base-url
rewrites = mapRewrites(rewrites, baseUrl && [{
source: _path.default.posix.join(baseUrl, '/:path*'),
destination: '/:path*'
}]); // start the server
let server = !dryRun && (await new Promise(resolve => {
let server = require('http').createServer((req, res) => {
require('serve-handler')(req, res, {
public: dir,
cleanUrls,
rewrites
});
}).listen(() => resolve(server));
})); // easy clean up
let close = () => {
if (server) {
return new Promise(resolve => {
server.close(resolve);
});
}
}; // add the port to the host and return
if (server) host += `:${server.address().port}`;
return {
host,
rewrites,
server,
close
};
} // Returns true or false if a snapshot matches the provided include and exclude predicates. A

@@ -124,3 +62,3 @@ // predicate can be an array of predicates, a regular expression, a glob pattern, or a function.

result = new RegExp(parsed, flags).test(snapshot.name);
} catch (e) {}
} catch {}
}

@@ -146,62 +84,2 @@

return !test(exclude, false) && test(include, true);
} // Maps an array of snapshots or paths to options ready to pass along to the core snapshot
// method. Paths are normalized before overrides are conditionally applied via their own include and
// exclude options. Snapshot URLs are then rewritten accordingly before default options are applied,
// including prepending the appropriate host. The returned set of snapshot options are sorted and
// filtered by the top-level include and exclude options.
function mapStaticSnapshots(snapshots, {
host,
include,
exclude,
cleanUrls,
rewrites = [],
overrides = [],
server
} = {}) {
var _server$host, _server$rewrites;
// prioritize server properties
host = (_server$host = server === null || server === void 0 ? void 0 : server.host) !== null && _server$host !== void 0 ? _server$host : host;
rewrites = (_server$rewrites = server === null || server === void 0 ? void 0 : server.rewrites) !== null && _server$rewrites !== void 0 ? _server$rewrites : mapRewrites(rewrites, []); // reduce rewrites into a single function
let applyRewrites = [{
test: url => !/^(https?:\/)?\//.test(url) && url,
rewrite: url => _path.default.posix.normalize(_path.default.posix.join('/', url))
}, ...rewrites.map(({
source,
destination
}) => ({
test: pathToRegexp.match(destination),
rewrite: pathToRegexp.compile(source)
})), {
test: url => cleanUrls && url,
rewrite: url => url.replace(/(\/index)?\.html$/, '')
}].reduceRight((apply, {
test,
rewrite
}) => snap => {
var _snap$url, _res$params;
let res = test((_snap$url = snap.url) !== null && _snap$url !== void 0 ? _snap$url : snap);
if (res) snap = rewrite((_res$params = res.params) !== null && _res$params !== void 0 ? _res$params : res);
return apply(snap);
}, s => s); // reduce overrides into a single function
let applyOverrides = overrides.reduceRight((apply, {
include,
exclude,
...opts
}) => snap => {
if (snapshotMatches(snap, include, exclude)) Object.assign(snap, opts);
return apply(snap);
}, s => s); // sort and reduce snapshots with overrides
return [...snapshots].sort().reduce((snapshots, snap) => {
snap = withDefaults(applyRewrites(snap), {
host
});
return snapshotMatches(snap, include, exclude) ? snapshots.concat(applyOverrides(snap)) : snapshots;
}, []);
}
{
"name": "@percy/cli-snapshot",
"version": "1.0.0-beta.71",
"version": "1.0.0-beta.72",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/percy/cli",
"directory": "packages/cli-snapshot"
},
"publishConfig": {
"access": "public"
},
"main": "dist/index.js",
"files": [
"dist",
"oclif.manifest.json"
"dist"
],

@@ -16,23 +23,15 @@ "engines": {

"lint": "eslint --ignore-path ../../.gitignore .",
"postbuild": "oclif-dev manifest",
"readme": "oclif-dev readme",
"readme": "percy-cli-readme",
"test": "node ../../scripts/test",
"test:coverage": "yarn test --coverage"
},
"publishConfig": {
"access": "public"
"@percy/cli": {
"commands": [
"./dist/snapshot.js"
]
},
"oclif": {
"bin": "percy",
"commands": "./dist/commands",
"hooks": {
"init": "./dist/hooks/init"
}
},
"dependencies": {
"@percy/cli-command": "1.0.0-beta.71",
"@percy/config": "1.0.0-beta.71",
"@percy/core": "1.0.0-beta.71",
"@percy/dom": "1.0.0-beta.71",
"@percy/logger": "1.0.0-beta.71",
"@percy/cli-command": "1.0.0-beta.72",
"@percy/config": "1.0.0-beta.72",
"@percy/core": "1.0.0-beta.72",
"globby": "^11.0.4",

@@ -44,8 +43,3 @@ "path-to-regexp": "^6.2.0",

},
"repository": {
"type": "git",
"url": "https://github.com/percy/cli",
"directory": "packages/cli-snapshot"
},
"gitHead": "364d1df717fb19a26ccb024458df6e78a9c11f99"
"gitHead": "6219287e18a0cacb609d0c2696a5785abc9009b9"
}

@@ -7,35 +7,42 @@ # @percy/cli-snapshot

<!-- commands -->
* [`percy snapshot DIR|FILE|SITEMAP`](#percy-snapshot-dirfilesitemap)
* [`percy snapshot`](#percy-snapshot)
## `percy snapshot DIR|FILE|SITEMAP`
### `percy snapshot`
Take snapshots from a static directory, snapshots file, or sitemap url
Snapshot a static directory, snapshots file, or sitemap URL
```
USAGE
$ percy snapshot DIR|FILE|SITEMAP
Usage:
$ percy snapshot [options] <dir|file|sitemap>
ARGUMENTS
DIR|FILE|SITEMAP static directory, snapshots file, or sitemap url
Arguments:
dir|file|sitemap Static directory, snapshots file, or sitemap url
OPTIONS
-b, --base-url=base-url the base url pages are hosted at when snapshotting
-c, --config=config configuration file path
-d, --dry-run print logs only, do not run asset discovery or upload snapshots
-h, --allowed-hostname=allowed-hostname allowed hostnames to capture in asset discovery
-q, --quiet log errors only
-t, --network-idle-timeout=network-idle-timeout asset discovery network idle timeout
-v, --verbose log everything
--clean-urls rewrite static index and filepath URLs to be clean
--debug debug asset discovery and do not upload snapshots
--disable-cache disable asset discovery caches
--exclude=exclude one or more globs/patterns matching snapshots to exclude
--include=include one or more globs/patterns matching snapshots to include
--silent log nothing
Options:
-b, --base-url <string> The base url pages are hosted at when snapshotting
--include <pattern> One or more globs/patterns matching snapshots to include
--exclude <pattern> One or more globs/patterns matching snapshots to exclude
EXAMPLES
Static options:
--clean-urls Rewrite static index and filepath URLs to be clean
Percy options:
-c, --config <file> Config file path
-d, --dry-run Print snapshot names only
-h, --allowed-hostname <hostname> Allowed hostnames to capture in asset discovery
-t, --network-idle-timeout <ms> Asset discovery network idle timeout
--disable-cache Disable asset discovery caches
--debug Debug asset discovery and do not upload snapshots
Global options:
-v, --verbose Log everything
-q, --quiet Log errors only
-s, --silent Log nothing
--help Display command help
Examples:
$ percy snapshot ./public
$ percy snapshot snapshots.yml
$ percy snapshot https://percy.io/sitemap.xml
```
<!-- commandsstop -->

@@ -42,0 +49,0 @@

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