Comparing version 6.3.1 to 6.3.2
# Changelog | ||
## 6.3.2 | ||
- fix unreported timing issue in SitemapAndIndexStream uncovered in latest unit tests | ||
## 6.3.1 | ||
@@ -4,0 +8,0 @@ |
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
import { SitemapStream } from './sitemap-stream'; | ||
import { WriteStream } from 'fs'; | ||
export declare enum IndexTagNames { | ||
@@ -46,3 +47,5 @@ sitemap = "sitemap", | ||
}): Promise<boolean>; | ||
declare type getSitemapStream = (i: number) => [IndexItem | string, SitemapStream]; | ||
declare type getSitemapStream = (i: number) => [IndexItem | string, SitemapStream, WriteStream]; | ||
/** @deprecated */ | ||
declare type getSitemapStreamDeprecated = (i: number) => [IndexItem | string, SitemapStream]; | ||
export interface SitemapAndIndexStreamOptions extends SitemapIndexStreamOptions { | ||
@@ -53,2 +56,7 @@ level?: ErrorLevel; | ||
} | ||
export interface SitemapAndIndexStreamOptionsDeprecated extends SitemapIndexStreamOptions { | ||
level?: ErrorLevel; | ||
limit?: number; | ||
getSitemapStream: getSitemapStreamDeprecated; | ||
} | ||
export declare class SitemapAndIndexStream extends SitemapIndexStream { | ||
@@ -58,4 +66,11 @@ private i; | ||
private currentSitemap; | ||
private currentSitemapPipeline?; | ||
private idxItem; | ||
private limit; | ||
/** | ||
* @deprecated this version does not properly wait for everything to write before resolving | ||
* pass a 3rd param in your return from getSitemapStream that is the writeable stream | ||
* to remove this warning | ||
*/ | ||
constructor(opts: SitemapAndIndexStreamOptionsDeprecated); | ||
constructor(opts: SitemapAndIndexStreamOptions); | ||
@@ -62,0 +77,0 @@ _writeSMI(item: SitemapItemLoose): void; |
@@ -123,3 +123,7 @@ "use strict"; | ||
this.getSitemapStream = opts.getSitemapStream; | ||
[this.idxItem, this.currentSitemap] = this.getSitemapStream(0); | ||
[ | ||
this.idxItem, | ||
this.currentSitemap, | ||
this.currentSitemapPipeline, | ||
] = this.getSitemapStream(0); | ||
this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000; | ||
@@ -132,2 +136,3 @@ } | ||
_transform(item, encoding, callback) { | ||
var _a; | ||
if (this.i === 0) { | ||
@@ -138,9 +143,12 @@ this._writeSMI(item); | ||
else if (this.i % this.limit === 0) { | ||
this.currentSitemap.end(() => { | ||
const [idxItem, currentSitemap] = this.getSitemapStream(this.i / this.limit); | ||
const onFinish = () => { | ||
const [idxItem, currentSitemap, currentSitemapPipeline,] = this.getSitemapStream(this.i / this.limit); | ||
this.currentSitemap = currentSitemap; | ||
this.currentSitemapPipeline = currentSitemapPipeline; | ||
this._writeSMI(item); | ||
// push to index stream | ||
super._transform(idxItem, encoding, callback); | ||
}); | ||
}; | ||
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish); | ||
this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined); | ||
} | ||
@@ -153,5 +161,8 @@ else { | ||
_flush(cb) { | ||
this.currentSitemap.end(() => super._flush(cb)); | ||
var _a; | ||
const onFinish = () => super._flush(cb); | ||
(_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish); | ||
this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined); | ||
} | ||
} | ||
exports.SitemapAndIndexStream = SitemapAndIndexStream; |
@@ -26,4 +26,5 @@ "use strict"; | ||
const writePath = path_1.resolve(destinationDir, path + (gzip ? '.gz' : '')); | ||
let pipeline; | ||
if (gzip) { | ||
sitemapStream | ||
pipeline = sitemapStream | ||
.pipe(zlib_1.createGzip()) // compress the output of the sitemap | ||
@@ -33,5 +34,9 @@ .pipe(fs_1.createWriteStream(writePath)); // write it to sitemap-NUMBER.xml | ||
else { | ||
sitemapStream.pipe(fs_1.createWriteStream(writePath)); // write it to sitemap-NUMBER.xml | ||
pipeline = sitemapStream.pipe(fs_1.createWriteStream(writePath)); // write it to sitemap-NUMBER.xml | ||
} | ||
return [new url_1.URL(path, sitemapHostname).toString(), sitemapStream]; | ||
return [ | ||
new url_1.URL(path, sitemapHostname).toString(), | ||
sitemapStream, | ||
pipeline, | ||
]; | ||
}, | ||
@@ -38,0 +43,0 @@ }); |
{ | ||
"name": "sitemap", | ||
"version": "6.3.1", | ||
"version": "6.3.2", | ||
"description": "Sitemap-generating lib/cli", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156338
2783