@percy/core 1.9.1 → 1.10.2
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/dist/api.js +6 -4
- package/dist/percy.js +8 -8
- package/dist/snapshot.js +14 -3
- package/package.json +6 -6
package/dist/api.js
CHANGED
|
@@ -189,15 +189,17 @@ export function createPercyServer(percy, port) {
|
|
|
189
189
|
export function createStaticServer(options) {
|
|
190
190
|
let {
|
|
191
191
|
serve: dir,
|
|
192
|
-
baseUrl = '
|
|
192
|
+
baseUrl = ''
|
|
193
193
|
} = options;
|
|
194
|
-
let server = Server.createServer(options); //
|
|
194
|
+
let server = Server.createServer(options); // remove trailing slashes so the base snapshot name matches other snapshots
|
|
195
|
+
|
|
196
|
+
baseUrl = baseUrl.replace(/\/$/, ''); // used when generating an automatic sitemap
|
|
195
197
|
|
|
196
198
|
let toURL = Server.createRewriter( // reverse rewrites' src, dest, & order
|
|
197
|
-
Object.entries((options === null || options === void 0 ? void 0 : options.rewrites) ?? {}).reduce((acc, rw) => [rw.reverse(), ...acc], []), (filename, rewrite) => new URL(path.posix.join(baseUrl, // cleanUrls will trim trailing .html/index.html from paths
|
|
199
|
+
Object.entries((options === null || options === void 0 ? void 0 : options.rewrites) ?? {}).reduce((acc, rw) => [rw.reverse(), ...acc], []), (filename, rewrite) => new URL(path.posix.join('/', baseUrl, // cleanUrls will trim trailing .html/index.html from paths
|
|
198
200
|
!options.cleanUrls ? rewrite(filename) : rewrite(filename).replace(/(\/index)?\.html$/, '')), server.address())); // include automatic sitemap route
|
|
199
201
|
|
|
200
|
-
server.route('get',
|
|
202
|
+
server.route('get', `${baseUrl}/sitemap.xml`, async (req, res) => {
|
|
201
203
|
let {
|
|
202
204
|
default: glob
|
|
203
205
|
} = await import('fast-glob');
|
package/dist/percy.js
CHANGED
|
@@ -31,7 +31,9 @@ export class Percy {
|
|
|
31
31
|
deferUploads,
|
|
32
32
|
// run without uploading anything
|
|
33
33
|
skipUploads,
|
|
34
|
-
//
|
|
34
|
+
// run without asset discovery
|
|
35
|
+
skipDiscovery,
|
|
36
|
+
// implies `skipUploads` and `skipDiscovery`
|
|
35
37
|
dryRun,
|
|
36
38
|
// implies `dryRun`, silent logs, and adds extra api endpoints
|
|
37
39
|
testing,
|
|
@@ -53,6 +55,7 @@ export class Percy {
|
|
|
53
55
|
this.testing = testing ? {} : null;
|
|
54
56
|
this.dryRun = !!testing || !!dryRun;
|
|
55
57
|
this.skipUploads = this.dryRun || !!skipUploads;
|
|
58
|
+
this.skipDiscovery = this.dryRun || !!skipDiscovery;
|
|
56
59
|
this.delayUploads = this.skipUploads || !!delayUploads;
|
|
57
60
|
this.deferUploads = this.delayUploads || !!deferUploads;
|
|
58
61
|
if (this.deferUploads) this.#uploads.stop();
|
|
@@ -150,7 +153,7 @@ export class Percy {
|
|
|
150
153
|
// at a later time when uploads are deferred, or run immediately when not deferred.
|
|
151
154
|
|
|
152
155
|
|
|
153
|
-
async *start(
|
|
156
|
+
async *start() {
|
|
154
157
|
// already starting or started
|
|
155
158
|
if (this.readyState != null) return;
|
|
156
159
|
this.readyState = 0; // create a percy build as the first immediately queued task
|
|
@@ -193,10 +196,7 @@ export class Percy {
|
|
|
193
196
|
// when not deferred, wait until the build is created first
|
|
194
197
|
if (!this.deferUploads) await buildTask; // maybe launch the discovery browser
|
|
195
198
|
|
|
196
|
-
if (!this.
|
|
197
|
-
yield this.browser.launch();
|
|
198
|
-
} // start the server after everything else is ready
|
|
199
|
-
|
|
199
|
+
if (!this.skipDiscovery) yield this.browser.launch(); // start the server after everything else is ready
|
|
200
200
|
|
|
201
201
|
yield (_this$server2 = this.server) === null || _this$server2 === void 0 ? void 0 : _this$server2.listen(); // mark instance as started
|
|
202
202
|
|
|
@@ -234,8 +234,8 @@ export class Percy {
|
|
|
234
234
|
if (this.#snapshots.size) {
|
|
235
235
|
if (close) this.#snapshots.close();
|
|
236
236
|
yield* this.#snapshots.flush(s => {
|
|
237
|
-
// do not log a count when not closing or
|
|
238
|
-
if (!close || this.
|
|
237
|
+
// do not log a count when not closing or if asset discovery is disabled
|
|
238
|
+
if (!close || this.skipDiscovery) return;
|
|
239
239
|
this.log.progress(`Processing ${s} snapshot${s !== 1 ? 's' : ''}...`, !!s);
|
|
240
240
|
});
|
|
241
241
|
} // run, close, and wait for the upload queue to empty
|
package/dist/snapshot.js
CHANGED
|
@@ -117,6 +117,8 @@ export async function* gatherSnapshots(percy, options) {
|
|
|
117
117
|
// other invalid options which are also scrubbed from the returned migrated options.
|
|
118
118
|
|
|
119
119
|
export function validateSnapshotOptions(options) {
|
|
120
|
+
var _migrated$baseUrl;
|
|
121
|
+
|
|
120
122
|
// decide which schema to validate against
|
|
121
123
|
let schema = ['domSnapshot', 'dom-snapshot', 'dom_snapshot'].some(k => k in options) && '/snapshot/dom' || 'url' in options && '/snapshot' || 'sitemap' in options && '/snapshot/sitemap' || 'serve' in options && '/snapshot/server' || 'snapshots' in options && '/snapshot/list' || '/snapshot';
|
|
122
124
|
let {
|
|
@@ -125,10 +127,12 @@ export function validateSnapshotOptions(options) {
|
|
|
125
127
|
environmentInfo,
|
|
126
128
|
snapshots,
|
|
127
129
|
...migrated
|
|
128
|
-
} = PercyConfig.migrate(options, schema); //
|
|
130
|
+
} = PercyConfig.migrate(options, schema); // maintain a trailing slash for base URLs to normalize them
|
|
131
|
+
|
|
132
|
+
if (((_migrated$baseUrl = migrated.baseUrl) === null || _migrated$baseUrl === void 0 ? void 0 : _migrated$baseUrl.endsWith('/')) === false) migrated.baseUrl += '/';
|
|
133
|
+
let baseUrl = schema === '/snapshot/server' ? 'http://localhost/' : migrated.baseUrl; // gather info for validating individual snapshot URLs
|
|
129
134
|
|
|
130
135
|
let isSnapshot = schema === '/snapshot/dom' || schema === '/snapshot';
|
|
131
|
-
let baseUrl = schema === '/snapshot/server' ? 'http://localhost' : options.baseUrl;
|
|
132
136
|
let snaps = isSnapshot ? [migrated] : Array.isArray(snapshots) ? snapshots : [];
|
|
133
137
|
|
|
134
138
|
for (let snap of snaps) validURL(typeof snap === 'string' ? snap : snap.url, baseUrl); // add back snapshots before validating and scrubbing; function snapshots are validated later
|
|
@@ -370,7 +374,14 @@ export async function* discoverSnapshotResources(percy, snapshot, callback) {
|
|
|
370
374
|
|
|
371
375
|
let cache = percy[RESOURCE_CACHE_KEY] || (percy[RESOURCE_CACHE_KEY] = new Map()); // preload the root resource for existing dom snapshots
|
|
372
376
|
|
|
373
|
-
let resources = new Map(snapshot.domSnapshot && [createRootResource(snapshot.url, snapshot.domSnapshot)].map(resource => [resource.url, resource])); //
|
|
377
|
+
let resources = new Map(snapshot.domSnapshot && [createRootResource(snapshot.url, snapshot.domSnapshot)].map(resource => [resource.url, resource])); // when no discovery browser is available, do not attempt to discover other resources
|
|
378
|
+
|
|
379
|
+
if (percy.skipDiscovery && !snapshot.domSnapshot) {
|
|
380
|
+
throw new Error('Cannot capture DOM snapshot when asset discovery is disabled');
|
|
381
|
+
} else if (percy.skipDiscovery) {
|
|
382
|
+
return handleSnapshotResources(snapshot, resources, callback);
|
|
383
|
+
} // open a new browser page
|
|
384
|
+
|
|
374
385
|
|
|
375
386
|
let page = yield percy.browser.page({
|
|
376
387
|
enableJavaScript: snapshot.enableJavaScript ?? !snapshot.domSnapshot,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"test:types": "tsd"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@percy/client": "1.
|
|
43
|
-
"@percy/config": "1.
|
|
44
|
-
"@percy/dom": "1.
|
|
45
|
-
"@percy/logger": "1.
|
|
42
|
+
"@percy/client": "1.10.2",
|
|
43
|
+
"@percy/config": "1.10.2",
|
|
44
|
+
"@percy/dom": "1.10.2",
|
|
45
|
+
"@percy/logger": "1.10.2",
|
|
46
46
|
"content-disposition": "^0.5.4",
|
|
47
47
|
"cross-spawn": "^7.0.3",
|
|
48
48
|
"extract-zip": "^2.0.1",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"rimraf": "^3.0.2",
|
|
54
54
|
"ws": "^8.0.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "66527175cdac3848157be7dd8368f5845d98e77e"
|
|
57
57
|
}
|