@percy/cli-snapshot 1.0.0-beta.76 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +10 -14
- package/dist/config.js +0 -173
- package/dist/file.js +0 -71
- package/dist/index.js +0 -13
- package/dist/sitemap.js +0 -33
- package/dist/snapshot.js +0 -147
- package/dist/static.js +0 -164
- package/dist/utils.js +0 -81
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Percy options:
|
|
|
29
29
|
-c, --config <file> Config file path
|
|
30
30
|
-d, --dry-run Print snapshot names only
|
|
31
31
|
-h, --allowed-hostname <hostname> Allowed hostnames to capture in asset discovery
|
|
32
|
+
--disallowed-hostname <hostname> Disallowed hostnames to abort in asset discovery
|
|
32
33
|
-t, --network-idle-timeout <ms> Asset discovery network idle timeout
|
|
33
34
|
--disable-cache Disable asset discovery caches
|
|
34
35
|
--debug Debug asset discovery and do not upload snapshots
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/cli-snapshot",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,13 +10,15 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"main": "dist/index.js",
|
|
14
|
-
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
],
|
|
17
13
|
"engines": {
|
|
18
|
-
"node": ">=
|
|
14
|
+
"node": ">=14"
|
|
19
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"./dist"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": "./dist/index.js",
|
|
20
22
|
"scripts": {
|
|
21
23
|
"build": "node ../../scripts/build",
|
|
22
24
|
"lint": "eslint --ignore-path ../../.gitignore .",
|
|
@@ -30,14 +32,8 @@
|
|
|
30
32
|
]
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@percy/cli-command": "1.0.0
|
|
34
|
-
"@percy/config": "1.0.0-beta.76",
|
|
35
|
-
"@percy/core": "1.0.0-beta.76",
|
|
36
|
-
"globby": "^11.0.4",
|
|
37
|
-
"path-to-regexp": "^6.2.0",
|
|
38
|
-
"picomatch": "^2.3.0",
|
|
39
|
-
"serve-handler": "^6.1.3",
|
|
35
|
+
"@percy/cli-command": "1.0.0",
|
|
40
36
|
"yaml": "^1.10.0"
|
|
41
37
|
},
|
|
42
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6df509421a60144e4f9f5d59dc57a5675372a0b2"
|
|
43
39
|
}
|
package/dist/config.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.commonSchema = void 0;
|
|
7
|
-
exports.configMigration = configMigration;
|
|
8
|
-
exports.snapshotsFileSchema = exports.configSchema = void 0;
|
|
9
|
-
|
|
10
|
-
var _config = require("@percy/core/dist/config");
|
|
11
|
-
|
|
12
|
-
// Common schemas referenced by other schemas
|
|
13
|
-
const commonSchema = {
|
|
14
|
-
$id: '/snapshot/cli',
|
|
15
|
-
$refs: {
|
|
16
|
-
predicate: {
|
|
17
|
-
oneOf: [{
|
|
18
|
-
type: 'string'
|
|
19
|
-
}, {
|
|
20
|
-
instanceof: 'RegExp'
|
|
21
|
-
}, {
|
|
22
|
-
instanceof: 'Function'
|
|
23
|
-
}, {
|
|
24
|
-
type: 'array',
|
|
25
|
-
items: {
|
|
26
|
-
$ref: '#/$refs/predicate'
|
|
27
|
-
}
|
|
28
|
-
}]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}; // Config schema for static directories
|
|
32
|
-
|
|
33
|
-
exports.commonSchema = commonSchema;
|
|
34
|
-
const configSchema = {
|
|
35
|
-
static: {
|
|
36
|
-
type: 'object',
|
|
37
|
-
additionalProperties: false,
|
|
38
|
-
properties: {
|
|
39
|
-
baseUrl: {
|
|
40
|
-
type: 'string',
|
|
41
|
-
pattern: '^/',
|
|
42
|
-
errors: {
|
|
43
|
-
pattern: 'must start with a forward slash (/)'
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
include: {
|
|
47
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
48
|
-
},
|
|
49
|
-
exclude: {
|
|
50
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
51
|
-
},
|
|
52
|
-
cleanUrls: {
|
|
53
|
-
type: 'boolean',
|
|
54
|
-
default: false
|
|
55
|
-
},
|
|
56
|
-
rewrites: {
|
|
57
|
-
type: 'object',
|
|
58
|
-
normalize: false,
|
|
59
|
-
additionalProperties: {
|
|
60
|
-
type: 'string'
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
overrides: {
|
|
64
|
-
type: 'array',
|
|
65
|
-
items: {
|
|
66
|
-
type: 'object',
|
|
67
|
-
additionalProperties: false,
|
|
68
|
-
properties: {
|
|
69
|
-
include: {
|
|
70
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
71
|
-
},
|
|
72
|
-
exclude: {
|
|
73
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
74
|
-
},
|
|
75
|
-
// schemas have no concept of inheritance, but we can leverage JS for brevity
|
|
76
|
-
..._config.snapshotSchema.properties
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
sitemap: {
|
|
83
|
-
type: 'object',
|
|
84
|
-
additionalProperties: false,
|
|
85
|
-
properties: {
|
|
86
|
-
include: {
|
|
87
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
88
|
-
},
|
|
89
|
-
exclude: {
|
|
90
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
91
|
-
},
|
|
92
|
-
overrides: {
|
|
93
|
-
$ref: '/config/static#/properties/overrides'
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}; // Snapshots file schema
|
|
98
|
-
|
|
99
|
-
exports.configSchema = configSchema;
|
|
100
|
-
const snapshotsFileSchema = {
|
|
101
|
-
$id: '/snapshot/file',
|
|
102
|
-
oneOf: [{
|
|
103
|
-
type: 'array',
|
|
104
|
-
items: {
|
|
105
|
-
oneOf: [{
|
|
106
|
-
$ref: '/snapshot'
|
|
107
|
-
}, {
|
|
108
|
-
type: 'string'
|
|
109
|
-
}]
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
type: 'object',
|
|
113
|
-
required: ['snapshots'],
|
|
114
|
-
properties: {
|
|
115
|
-
baseUrl: {
|
|
116
|
-
type: 'string',
|
|
117
|
-
pattern: '^https?://',
|
|
118
|
-
errors: {
|
|
119
|
-
pattern: 'must include with a protocol and hostname'
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
include: {
|
|
123
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
124
|
-
},
|
|
125
|
-
exclude: {
|
|
126
|
-
$ref: '/snapshot/cli#/$refs/predicate'
|
|
127
|
-
},
|
|
128
|
-
snapshots: {
|
|
129
|
-
$ref: '#/oneOf/0'
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}]
|
|
133
|
-
};
|
|
134
|
-
exports.snapshotsFileSchema = snapshotsFileSchema;
|
|
135
|
-
|
|
136
|
-
function configMigration(config, util) {
|
|
137
|
-
/* eslint-disable curly */
|
|
138
|
-
if (config.version < 2) {
|
|
139
|
-
// static-snapshots and options were renamed
|
|
140
|
-
util.map('staticSnapshots.baseUrl', 'static.baseUrl');
|
|
141
|
-
util.map('staticSnapshots.snapshotFiles', 'static.include');
|
|
142
|
-
util.map('staticSnapshots.ignoreFiles', 'static.exclude');
|
|
143
|
-
util.del('staticSnapshots');
|
|
144
|
-
} else {
|
|
145
|
-
let notice = {
|
|
146
|
-
type: 'config',
|
|
147
|
-
until: '1.0.0'
|
|
148
|
-
}; // static files and ignore options were renamed
|
|
149
|
-
|
|
150
|
-
util.deprecate('static.files', {
|
|
151
|
-
map: 'static.include',
|
|
152
|
-
...notice
|
|
153
|
-
});
|
|
154
|
-
util.deprecate('static.ignore', {
|
|
155
|
-
map: 'static.exclude',
|
|
156
|
-
...notice
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
for (let i in ((_config$static = config.static) === null || _config$static === void 0 ? void 0 : _config$static.overrides) || []) {
|
|
160
|
-
var _config$static;
|
|
161
|
-
|
|
162
|
-
let k = `static.overrides[${i}]`;
|
|
163
|
-
util.deprecate(`${k}.files`, {
|
|
164
|
-
map: `${k}.include`,
|
|
165
|
-
...notice
|
|
166
|
-
});
|
|
167
|
-
util.deprecate(`${k}.ignore`, {
|
|
168
|
-
map: `${k}.exclude`,
|
|
169
|
-
...notice
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
package/dist/file.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadSnapshotsFile = loadSnapshotsFile;
|
|
7
|
-
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
var _config = _interopRequireDefault(require("@percy/config"));
|
|
13
|
-
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
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); }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
// Loads snapshots from a js, json, or yaml file.
|
|
23
|
-
async function loadSnapshotsFile(file, flags, invalid) {
|
|
24
|
-
var _PercyConfig$validate;
|
|
25
|
-
|
|
26
|
-
let ext = _path.default.extname(file);
|
|
27
|
-
|
|
28
|
-
let config = {}; // load snapshots file
|
|
29
|
-
|
|
30
|
-
if (ext === '.js') {
|
|
31
|
-
({
|
|
32
|
-
default: config
|
|
33
|
-
} = await Promise.resolve(`${_path.default.resolve(file)}`).then(s => _interopRequireWildcard(require(s))));
|
|
34
|
-
if (typeof config === 'function') config = await config();
|
|
35
|
-
} else if (ext === '.json') {
|
|
36
|
-
config = JSON.parse(_fs.default.readFileSync(file, {
|
|
37
|
-
encoding: 'utf-8'
|
|
38
|
-
}));
|
|
39
|
-
} else if (ext.match(/\.ya?ml$/)) {
|
|
40
|
-
let YAML = await Promise.resolve().then(() => _interopRequireWildcard(require('yaml')));
|
|
41
|
-
config = YAML.parse(_fs.default.readFileSync(file, {
|
|
42
|
-
encoding: 'utf-8'
|
|
43
|
-
}));
|
|
44
|
-
} else {
|
|
45
|
-
throw new Error(`Unsupported filetype: ${file}`);
|
|
46
|
-
} // validate base-url before config options
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (flags.baseUrl && !flags.baseUrl.startsWith('http')) {
|
|
50
|
-
throw new Error('The base-url must include a protocol ' + 'and hostname when providing a list of snapshots');
|
|
51
|
-
} // validate snapshot config options
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(_PercyConfig$validate = _config.default.validate(config, '/snapshot/file')) === null || _PercyConfig$validate === void 0 ? void 0 : _PercyConfig$validate.forEach(invalid); // flags override config options
|
|
55
|
-
|
|
56
|
-
let {
|
|
57
|
-
baseUrl,
|
|
58
|
-
include,
|
|
59
|
-
exclude
|
|
60
|
-
} = { ...config,
|
|
61
|
-
...flags
|
|
62
|
-
}; // support config that only contains a list of snapshots
|
|
63
|
-
|
|
64
|
-
return (Array.isArray(config) ? config : config.snapshots || []).reduce((snapshots, snap) => {
|
|
65
|
-
// reduce matching snapshots with default options
|
|
66
|
-
snap = (0, _utils.withDefaults)(snap, {
|
|
67
|
-
host: baseUrl
|
|
68
|
-
});
|
|
69
|
-
return (0, _utils.snapshotMatches)(snap, include, exclude) ? snapshots.concat(snap) : snapshots;
|
|
70
|
-
}, []);
|
|
71
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "snapshot", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _snapshot.snapshot;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
var _snapshot = require("./snapshot");
|
package/dist/sitemap.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadSitemapSnapshots = loadSitemapSnapshots;
|
|
7
|
-
|
|
8
|
-
var _static = require("./static");
|
|
9
|
-
|
|
10
|
-
var _utils = require("@percy/core/dist/utils");
|
|
11
|
-
|
|
12
|
-
// Fetches and maps sitemap URLs to snapshots.
|
|
13
|
-
async function loadSitemapSnapshots(sitemapUrl, config) {
|
|
14
|
-
// fetch sitemap URLs
|
|
15
|
-
let urls = await (0, _utils.request)(sitemapUrl, (body, res) => {
|
|
16
|
-
// validate sitemap content-type
|
|
17
|
-
let [contentType] = res.headers['content-type'].split(';');
|
|
18
|
-
|
|
19
|
-
if (!/^(application|text)\/xml$/.test(contentType)) {
|
|
20
|
-
throw new Error('The sitemap must be an XML document, ' + `but the content-type was "${contentType}"`);
|
|
21
|
-
} // parse XML content into a list of URLs
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let urls = body.match(/(?<=<loc>)(.*)(?=<\/loc>)/ig); // filter out duplicate URLs that differ by a trailing slash
|
|
25
|
-
|
|
26
|
-
return urls.filter((url, i) => {
|
|
27
|
-
let match = urls.indexOf(url.replace(/\/$/, ''));
|
|
28
|
-
return match === -1 || match === i;
|
|
29
|
-
});
|
|
30
|
-
}); // map with inherited static options
|
|
31
|
-
|
|
32
|
-
return (0, _static.mapStaticSnapshots)(urls, config);
|
|
33
|
-
}
|
package/dist/snapshot.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.snapshot = exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _fs = require("fs");
|
|
9
|
-
|
|
10
|
-
var _cliCommand = _interopRequireDefault(require("@percy/cli-command"));
|
|
11
|
-
|
|
12
|
-
var SnapshotConfig = _interopRequireWildcard(require("./config"));
|
|
13
|
-
|
|
14
|
-
var _package = _interopRequireDefault(require("../package.json"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
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); }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
const snapshot = (0, _cliCommand.default)('snapshot', {
|
|
23
|
-
description: 'Snapshot a static directory, snapshots file, or sitemap URL',
|
|
24
|
-
args: [{
|
|
25
|
-
name: 'dir|file|sitemap',
|
|
26
|
-
description: 'Static directory, snapshots file, or sitemap url',
|
|
27
|
-
required: true,
|
|
28
|
-
attribute: val => {
|
|
29
|
-
if (/^https?:\/\//.test(val)) return 'sitemap';
|
|
30
|
-
if (!(0, _fs.existsSync)(val)) throw new Error(`Not found: ${val}`);
|
|
31
|
-
return (0, _fs.lstatSync)(val).isDirectory() ? 'dir' : 'file';
|
|
32
|
-
}
|
|
33
|
-
}],
|
|
34
|
-
flags: [{
|
|
35
|
-
name: 'base-url',
|
|
36
|
-
description: 'The base url pages are hosted at when snapshotting',
|
|
37
|
-
type: 'string',
|
|
38
|
-
short: 'b'
|
|
39
|
-
}, {
|
|
40
|
-
name: 'include',
|
|
41
|
-
description: 'One or more globs/patterns matching snapshots to include',
|
|
42
|
-
type: 'pattern',
|
|
43
|
-
multiple: true
|
|
44
|
-
}, {
|
|
45
|
-
name: 'exclude',
|
|
46
|
-
description: 'One or more globs/patterns matching snapshots to exclude',
|
|
47
|
-
type: 'pattern',
|
|
48
|
-
multiple: true
|
|
49
|
-
}, {
|
|
50
|
-
// static only
|
|
51
|
-
name: 'clean-urls',
|
|
52
|
-
description: 'Rewrite static index and filepath URLs to be clean',
|
|
53
|
-
percyrc: 'static.cleanUrls',
|
|
54
|
-
group: 'Static'
|
|
55
|
-
}, {
|
|
56
|
-
// deprecated
|
|
57
|
-
name: 'files',
|
|
58
|
-
deprecated: ['1.0.0', '--include'],
|
|
59
|
-
percyrc: 'static.include',
|
|
60
|
-
type: 'pattern'
|
|
61
|
-
}, {
|
|
62
|
-
name: 'ignore',
|
|
63
|
-
deprecated: ['1.0.0', '--exclude'],
|
|
64
|
-
percyrc: 'static.exclude',
|
|
65
|
-
type: 'pattern'
|
|
66
|
-
}],
|
|
67
|
-
examples: ['$0 ./public', '$0 snapshots.yml', '$0 https://percy.io/sitemap.xml'],
|
|
68
|
-
percy: {
|
|
69
|
-
clientInfo: `${_package.default.name}/${_package.default.version}`,
|
|
70
|
-
environmentInfo: `node/${process.version}`
|
|
71
|
-
},
|
|
72
|
-
config: {
|
|
73
|
-
schemas: [SnapshotConfig.commonSchema, SnapshotConfig.configSchema, SnapshotConfig.snapshotsFileSchema],
|
|
74
|
-
migrations: [SnapshotConfig.configMigration]
|
|
75
|
-
}
|
|
76
|
-
}, async function* ({
|
|
77
|
-
percy,
|
|
78
|
-
args,
|
|
79
|
-
flags,
|
|
80
|
-
log,
|
|
81
|
-
exit
|
|
82
|
-
}) {
|
|
83
|
-
if (!percy) exit(0, 'Percy is disabled'); // set and validate static or sitemap config flags
|
|
84
|
-
|
|
85
|
-
if (args.dir || args.sitemap) {
|
|
86
|
-
percy.setConfig({
|
|
87
|
-
[args.dir ? 'static' : 'sitemap']: {
|
|
88
|
-
include: flags.include,
|
|
89
|
-
exclude: flags.exclude
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
} // gather snapshots
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let snapshots, server;
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
if (args.sitemap) {
|
|
99
|
-
let {
|
|
100
|
-
loadSitemapSnapshots
|
|
101
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./sitemap')));
|
|
102
|
-
let config = { ...percy.config.sitemap,
|
|
103
|
-
...flags
|
|
104
|
-
};
|
|
105
|
-
snapshots = yield loadSitemapSnapshots(args.sitemap, config);
|
|
106
|
-
} else if (args.dir) {
|
|
107
|
-
let {
|
|
108
|
-
serve,
|
|
109
|
-
loadStaticSnapshots
|
|
110
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./static')));
|
|
111
|
-
let config = { ...percy.config.static,
|
|
112
|
-
...flags
|
|
113
|
-
};
|
|
114
|
-
server = yield serve(args.dir, config);
|
|
115
|
-
snapshots = yield loadStaticSnapshots(args.dir, { ...config,
|
|
116
|
-
server
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
let {
|
|
120
|
-
loadSnapshotsFile
|
|
121
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./file')));
|
|
122
|
-
snapshots = yield loadSnapshotsFile(args.file, flags, (invalid, i) => {
|
|
123
|
-
if (i === 0) log.warn('Invalid snapshot options:');
|
|
124
|
-
log.warn(`- ${invalid.path}: ${invalid.message}`);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!snapshots.length) {
|
|
129
|
-
exit(1, 'No snapshots found');
|
|
130
|
-
} // start processing snapshots
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
yield* percy.start();
|
|
134
|
-
percy.snapshot(snapshots);
|
|
135
|
-
yield* percy.stop();
|
|
136
|
-
} catch (error) {
|
|
137
|
-
await percy.stop(true);
|
|
138
|
-
throw error;
|
|
139
|
-
} finally {
|
|
140
|
-
var _server;
|
|
141
|
-
|
|
142
|
-
await ((_server = server) === null || _server === void 0 ? void 0 : _server.close());
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
exports.snapshot = snapshot;
|
|
146
|
-
var _default = snapshot;
|
|
147
|
-
exports.default = _default;
|
package/dist/static.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.loadStaticSnapshots = loadStaticSnapshots;
|
|
7
|
-
exports.mapStaticSnapshots = mapStaticSnapshots;
|
|
8
|
-
exports.serve = serve;
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
var _http = require("http");
|
|
13
|
-
|
|
14
|
-
var _serveHandler = _interopRequireDefault(require("serve-handler"));
|
|
15
|
-
|
|
16
|
-
var pathToRegexp = _interopRequireWildcard(require("path-to-regexp"));
|
|
17
|
-
|
|
18
|
-
var _utils = require("./utils");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
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); }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
// Transforms a source-destination map into an array of source-destination objects
|
|
27
|
-
function mapRewrites(map, arr) {
|
|
28
|
-
return Object.entries(map).reduce((r, [source, destination]) => {
|
|
29
|
-
return (r || []).concat({
|
|
30
|
-
source,
|
|
31
|
-
destination
|
|
32
|
-
});
|
|
33
|
-
}, arr);
|
|
34
|
-
} // Serves a static directory with the provided options and returns an object containing adjusted
|
|
35
|
-
// rewrites (combined with any baseUrl), the server host, a close method, and the server
|
|
36
|
-
// instance. The `dryRun` option will prevent the server from actually starting.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
async function serve(dir, {
|
|
40
|
-
dryRun,
|
|
41
|
-
baseUrl,
|
|
42
|
-
cleanUrls,
|
|
43
|
-
rewrites = {}
|
|
44
|
-
}) {
|
|
45
|
-
let host = 'http://localhost';
|
|
46
|
-
let connections = new Set(); // coerce any provided base-url into a base-url path
|
|
47
|
-
|
|
48
|
-
if (baseUrl && !baseUrl.startsWith('/')) {
|
|
49
|
-
baseUrl = (0, _utils.validURL)(baseUrl).path;
|
|
50
|
-
} // map rewrite options with the base-url
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
rewrites = mapRewrites(rewrites, baseUrl && [{
|
|
54
|
-
source: _path.default.posix.join(baseUrl, '/:path*'),
|
|
55
|
-
destination: '/:path*'
|
|
56
|
-
}]); // start the server
|
|
57
|
-
|
|
58
|
-
let server = !dryRun && (await new Promise(resolve => {
|
|
59
|
-
let server = (0, _http.createServer)((req, res) => (0, _serveHandler.default)(req, res, {
|
|
60
|
-
public: dir,
|
|
61
|
-
cleanUrls,
|
|
62
|
-
rewrites
|
|
63
|
-
})).listen(() => resolve(server)).on('connection', s => {
|
|
64
|
-
connections.add(s.on('close', () => connections.delete(s)));
|
|
65
|
-
});
|
|
66
|
-
})); // easy clean up
|
|
67
|
-
|
|
68
|
-
let close = () => server && new Promise(resolve => {
|
|
69
|
-
/* istanbul ignore next: sometimes needed when connections are hanging */
|
|
70
|
-
connections.forEach(s => s.destroy());
|
|
71
|
-
server.close(resolve);
|
|
72
|
-
}); // add the port to the host and return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (server) host += `:${server.address().port}`;
|
|
76
|
-
return {
|
|
77
|
-
host,
|
|
78
|
-
rewrites,
|
|
79
|
-
server,
|
|
80
|
-
close
|
|
81
|
-
};
|
|
82
|
-
} // Maps an array of snapshots or paths to options ready to pass along to the core snapshot
|
|
83
|
-
// method. Paths are normalized before overrides are conditionally applied via their own include and
|
|
84
|
-
// exclude options. Snapshot URLs are then rewritten accordingly before default options are applied,
|
|
85
|
-
// including prepending the appropriate host. The returned set of snapshot options are sorted and
|
|
86
|
-
// filtered by the top-level include and exclude options.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
function mapStaticSnapshots(snapshots,
|
|
90
|
-
/* istanbul ignore next: safe defaults */
|
|
91
|
-
{
|
|
92
|
-
host,
|
|
93
|
-
include,
|
|
94
|
-
exclude,
|
|
95
|
-
cleanUrls,
|
|
96
|
-
rewrites = [],
|
|
97
|
-
overrides = [],
|
|
98
|
-
server
|
|
99
|
-
} = {}) {
|
|
100
|
-
var _server$host, _server$rewrites;
|
|
101
|
-
|
|
102
|
-
// prioritize server properties
|
|
103
|
-
host = (_server$host = server === null || server === void 0 ? void 0 : server.host) !== null && _server$host !== void 0 ? _server$host : host;
|
|
104
|
-
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
|
|
105
|
-
|
|
106
|
-
let applyRewrites = [{
|
|
107
|
-
test: url => !/^(https?:\/)?\//.test(url) && url,
|
|
108
|
-
rewrite: url => _path.default.posix.normalize(_path.default.posix.join('/', url))
|
|
109
|
-
}, ...rewrites.map(({
|
|
110
|
-
source,
|
|
111
|
-
destination
|
|
112
|
-
}) => ({
|
|
113
|
-
test: pathToRegexp.match(destination),
|
|
114
|
-
rewrite: pathToRegexp.compile(source)
|
|
115
|
-
})), {
|
|
116
|
-
test: url => cleanUrls && url,
|
|
117
|
-
rewrite: url => url.replace(/(\/index)?\.html$/, '')
|
|
118
|
-
}].reduceRight((apply, {
|
|
119
|
-
test,
|
|
120
|
-
rewrite
|
|
121
|
-
}) => snap => {
|
|
122
|
-
var _snap$url, _res$params;
|
|
123
|
-
|
|
124
|
-
let res = test((_snap$url = snap.url) !== null && _snap$url !== void 0 ? _snap$url : snap);
|
|
125
|
-
if (res) snap = rewrite((_res$params = res.params) !== null && _res$params !== void 0 ? _res$params : res);
|
|
126
|
-
return apply(snap);
|
|
127
|
-
}, s => s); // reduce overrides into a single function
|
|
128
|
-
|
|
129
|
-
let applyOverrides = overrides.reduceRight((apply, {
|
|
130
|
-
include,
|
|
131
|
-
exclude,
|
|
132
|
-
...opts
|
|
133
|
-
}) => snap => {
|
|
134
|
-
if ((0, _utils.snapshotMatches)(snap, include, exclude)) Object.assign(snap, opts);
|
|
135
|
-
return apply(snap);
|
|
136
|
-
}, s => s); // sort and reduce snapshots with overrides
|
|
137
|
-
|
|
138
|
-
return [...snapshots].sort().reduce((snapshots, snap) => {
|
|
139
|
-
snap = (0, _utils.withDefaults)(applyRewrites(snap), {
|
|
140
|
-
host
|
|
141
|
-
});
|
|
142
|
-
return (0, _utils.snapshotMatches)(snap, include, exclude) ? snapshots.concat(applyOverrides(snap)) : snapshots;
|
|
143
|
-
}, []);
|
|
144
|
-
} // Serves a static directory and returns a list of snapshots.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
async function loadStaticSnapshots(dir, config) {
|
|
148
|
-
let {
|
|
149
|
-
default: globby
|
|
150
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('globby'))); // gather paths with globby, which only accepts string patterns
|
|
151
|
-
|
|
152
|
-
let isStr = s => typeof s === 'string';
|
|
153
|
-
|
|
154
|
-
let strOr = (a, b) => a.length && a.every(isStr) ? a : b;
|
|
155
|
-
|
|
156
|
-
let files = strOr([].concat(config.include || []), '**/*.html');
|
|
157
|
-
let ignore = strOr([].concat(config.exclude || []), []);
|
|
158
|
-
let paths = await globby(files, {
|
|
159
|
-
cwd: dir,
|
|
160
|
-
ignore
|
|
161
|
-
}); // map snapshots from paths and config
|
|
162
|
-
|
|
163
|
-
return mapStaticSnapshots(paths, config);
|
|
164
|
-
}
|
package/dist/utils.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.snapshotMatches = snapshotMatches;
|
|
7
|
-
exports.validURL = validURL;
|
|
8
|
-
exports.withDefaults = withDefaults;
|
|
9
|
-
|
|
10
|
-
var _picomatch = _interopRequireDefault(require("picomatch"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
// used to deserialize regular expression strings
|
|
15
|
-
const RE_REGEXP = /^\/(.+)\/(\w+)?$/; // Throw a better error message for invalid urls
|
|
16
|
-
|
|
17
|
-
function validURL(url, base) {
|
|
18
|
-
try {
|
|
19
|
-
return new URL(url, base);
|
|
20
|
-
} catch (e) {
|
|
21
|
-
throw new Error(`Invalid URL: ${e.input}`);
|
|
22
|
-
}
|
|
23
|
-
} // Mutates an options object to have normalized and default values
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function withDefaults(options, {
|
|
27
|
-
host
|
|
28
|
-
}) {
|
|
29
|
-
var _options;
|
|
30
|
-
|
|
31
|
-
// allow URLs as the only option
|
|
32
|
-
if (typeof options === 'string') options = {
|
|
33
|
-
url: options
|
|
34
|
-
}; // validate URLs
|
|
35
|
-
|
|
36
|
-
let url = validURL(options.url, host); // default name to the url path
|
|
37
|
-
|
|
38
|
-
(_options = options).name || (_options.name = `${url.pathname}${url.search}${url.hash}`); // normalize the snapshot url
|
|
39
|
-
|
|
40
|
-
options.url = url.href;
|
|
41
|
-
return options;
|
|
42
|
-
} // Returns true or false if a snapshot matches the provided include and exclude predicates. A
|
|
43
|
-
// predicate can be an array of predicates, a regular expression, a glob pattern, or a function.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
function snapshotMatches(snapshot, include, exclude) {
|
|
47
|
-
if (!include && !exclude) return true;
|
|
48
|
-
|
|
49
|
-
let test = (predicate, fallback) => {
|
|
50
|
-
if (predicate && typeof predicate === 'string') {
|
|
51
|
-
// snapshot matches a glob
|
|
52
|
-
let result = (0, _picomatch.default)(predicate, {
|
|
53
|
-
basename: true
|
|
54
|
-
})(snapshot.name); // snapshot might match a string pattern
|
|
55
|
-
|
|
56
|
-
if (!result) {
|
|
57
|
-
try {
|
|
58
|
-
let [, parsed = predicate, flags] = RE_REGEXP.exec(predicate) || [];
|
|
59
|
-
result = new RegExp(parsed, flags).test(snapshot.name);
|
|
60
|
-
} catch {}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return result;
|
|
64
|
-
} else if (predicate instanceof RegExp) {
|
|
65
|
-
// snapshot matches a regular expression
|
|
66
|
-
return predicate.test(snapshot.name);
|
|
67
|
-
} else if (typeof predicate === 'function') {
|
|
68
|
-
// advanced matching
|
|
69
|
-
return predicate(snapshot);
|
|
70
|
-
} else if (Array.isArray(predicate) && predicate.length) {
|
|
71
|
-
// array of predicates
|
|
72
|
-
return predicate.some(p => test(p));
|
|
73
|
-
} else {
|
|
74
|
-
// default fallback
|
|
75
|
-
return fallback;
|
|
76
|
-
}
|
|
77
|
-
}; // not excluded or explicitly included
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return !test(exclude, false) && test(include, true);
|
|
81
|
-
}
|