vite-plugin-sitemap 0.6.0 → 0.6.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.
Files changed (3) hide show
  1. package/dist/index.js +315 -192
  2. package/dist/index.mjs +315 -192
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import require$$0$2 from 'path';
7
7
  import require$$1 from 'child_process';
8
8
  import { createRequire } from 'module';
9
9
  import require$$1$1 from 'string_decoder';
10
- import require$$1$2 from 'zlib';
10
+ import require$$3$1 from 'zlib';
11
11
  import require$$0$3 from 'util';
12
12
  import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
13
13
  import require$$0$4 from 'os';
@@ -1083,8 +1083,12 @@ utils$l.normalizeURL = normalizeURL;
1083
1083
  this.hasHeadOutput = true;
1084
1084
  this.push(getURLSetNs(this.xmlNS, this.xslUrl));
1085
1085
  }
1086
- this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler));
1087
- callback();
1086
+ if (!this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))) {
1087
+ this.smiStream.once('drain', callback);
1088
+ }
1089
+ else {
1090
+ process.nextTick(callback);
1091
+ }
1088
1092
  }
1089
1093
  _flush(cb) {
1090
1094
  if (!this.hasHeadOutput) {
@@ -1098,19 +1102,31 @@ utils$l.normalizeURL = normalizeURL;
1098
1102
  }
1099
1103
  exports.SitemapStream = SitemapStream;
1100
1104
  /**
1101
- * Takes a stream returns a promise that resolves when stream emits finish
1102
- * @param stream what you want wrapped in a promise
1105
+ * Converts a readable stream into a promise that resolves with the concatenated data from the stream.
1106
+ *
1107
+ * The function listens for 'data' events from the stream, and when the stream ends, it resolves the promise with the concatenated data. If an error occurs while reading from the stream, the promise is rejected with the error.
1108
+ *
1109
+ * ⚠️ CAUTION: This function should not generally be used in production / when writing to files as it holds a copy of the entire file contents in memory until finished.
1110
+ *
1111
+ * @param {Readable} stream - The readable stream to convert to a promise.
1112
+ * @returns {Promise<Buffer>} A promise that resolves with the concatenated data from the stream as a Buffer, or rejects with an error if one occurred while reading from the stream. If the stream is empty, the promise is rejected with an EmptyStream error.
1113
+ * @throws {EmptyStream} If the stream is empty.
1103
1114
  */
1104
1115
  function streamToPromise(stream) {
1105
1116
  return new Promise((resolve, reject) => {
1106
1117
  const drain = [];
1107
1118
  stream
1119
+ // Error propagation is not automatic
1120
+ // Bubble up errors on the read stream
1121
+ .on('error', reject)
1108
1122
  .pipe(new stream_1.Writable({
1109
1123
  write(chunk, enc, next) {
1110
1124
  drain.push(chunk);
1111
1125
  next();
1112
1126
  },
1113
1127
  }))
1128
+ // This bubbles up errors when writing to the internal buffer
1129
+ // This is unlikely to happen, but we have this for completeness
1114
1130
  .on('error', reject)
1115
1131
  .on('finish', () => {
1116
1132
  if (!drain.length) {
@@ -1142,7 +1158,27 @@ utils$l.normalizeURL = normalizeURL;
1142
1158
  const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
1143
1159
  const closetag = '</sitemapindex>';
1144
1160
  const defaultStreamOpts = {};
1161
+ /**
1162
+ * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
1163
+ *
1164
+ * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
1165
+ *
1166
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1167
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1168
+ *
1169
+ * @extends {Transform}
1170
+ */
1145
1171
  class SitemapIndexStream extends stream_1.Transform {
1172
+ /**
1173
+ * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
1174
+ *
1175
+ * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
1176
+ *
1177
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1178
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1179
+ *
1180
+ * @param {SitemapIndexStreamOptions} [opts=defaultStreamOpts] - Stream options.
1181
+ */
1146
1182
  constructor(opts = defaultStreamOpts) {
1147
1183
  var _a;
1148
1184
  opts.objectMode = true;
@@ -1152,14 +1188,17 @@ utils$l.normalizeURL = normalizeURL;
1152
1188
  this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
1153
1189
  this.xslUrl = opts.xslUrl;
1154
1190
  }
1191
+ writeHeadOutput() {
1192
+ this.hasHeadOutput = true;
1193
+ let stylesheet = '';
1194
+ if (this.xslUrl) {
1195
+ stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
1196
+ }
1197
+ this.push(xmlDec + stylesheet + sitemapIndexTagStart);
1198
+ }
1155
1199
  _transform(item, encoding, callback) {
1156
1200
  if (!this.hasHeadOutput) {
1157
- this.hasHeadOutput = true;
1158
- let stylesheet = '';
1159
- if (this.xslUrl) {
1160
- stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
1161
- }
1162
- this.push(xmlDec + stylesheet + sitemapIndexTagStart);
1201
+ this.writeHeadOutput();
1163
1202
  }
1164
1203
  this.push((0, sitemap_xml_1.otag)(IndexTagNames.sitemap));
1165
1204
  if (typeof item === 'string') {
@@ -1176,55 +1215,143 @@ utils$l.normalizeURL = normalizeURL;
1176
1215
  callback();
1177
1216
  }
1178
1217
  _flush(cb) {
1218
+ if (!this.hasHeadOutput) {
1219
+ this.writeHeadOutput();
1220
+ }
1179
1221
  this.push(closetag);
1180
1222
  cb();
1181
1223
  }
1182
1224
  }
1183
1225
  exports.SitemapIndexStream = SitemapIndexStream;
1184
- // const defaultSIStreamOpts: SitemapAndIndexStreamOptions = {};
1226
+ /**
1227
+ * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
1228
+ * writes them to sitemap files, adds the sitemap files to a sitemap index,
1229
+ * and creates new sitemap files when the count limit is reached.
1230
+ *
1231
+ * It waits for the target stream of the current sitemap file to finish before
1232
+ * moving on to the next if the target stream is returned by the `getSitemapStream`
1233
+ * callback in the 3rd position of the tuple.
1234
+ *
1235
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1236
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1237
+ *
1238
+ * @extends {SitemapIndexStream}
1239
+ */
1185
1240
  class SitemapAndIndexStream extends SitemapIndexStream {
1241
+ /**
1242
+ * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
1243
+ * writes them to sitemap files, adds the sitemap files to a sitemap index,
1244
+ * and creates new sitemap files when the count limit is reached.
1245
+ *
1246
+ * It waits for the target stream of the current sitemap file to finish before
1247
+ * moving on to the next if the target stream is returned by the `getSitemapStream`
1248
+ * callback in the 3rd position of the tuple.
1249
+ *
1250
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1251
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1252
+ *
1253
+ * @param {SitemapAndIndexStreamOptions} opts - Stream options.
1254
+ */
1186
1255
  constructor(opts) {
1187
1256
  var _a;
1188
1257
  opts.objectMode = true;
1189
1258
  super(opts);
1190
- this.i = 0;
1259
+ this.itemsWritten = 0;
1191
1260
  this.getSitemapStream = opts.getSitemapStream;
1192
- [this.idxItem, this.currentSitemap, this.currentSitemapPipeline] =
1193
- this.getSitemapStream(0);
1194
1261
  this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000;
1195
1262
  }
1196
- _writeSMI(item) {
1197
- this.currentSitemap.write(item);
1198
- this.i++;
1199
- }
1200
1263
  _transform(item, encoding, callback) {
1201
- var _a;
1202
- if (this.i === 0) {
1203
- this._writeSMI(item);
1204
- super._transform(this.idxItem, encoding, callback);
1264
+ if (this.itemsWritten % this.limit === 0) {
1265
+ if (this.currentSitemap) {
1266
+ const onFinish = new Promise((resolve, reject) => {
1267
+ var _a, _b, _c;
1268
+ (_a = this.currentSitemap) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
1269
+ (_b = this.currentSitemap) === null || _b === void 0 ? void 0 : _b.on('error', reject);
1270
+ (_c = this.currentSitemap) === null || _c === void 0 ? void 0 : _c.end();
1271
+ });
1272
+ const onPipelineFinish = this.currentSitemapPipeline
1273
+ ? new Promise((resolve, reject) => {
1274
+ var _a, _b;
1275
+ (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
1276
+ (_b = this.currentSitemapPipeline) === null || _b === void 0 ? void 0 : _b.on('error', reject);
1277
+ })
1278
+ : Promise.resolve();
1279
+ Promise.all([onFinish, onPipelineFinish])
1280
+ .then(() => {
1281
+ this.createSitemap(encoding);
1282
+ this.writeItem(item, callback);
1283
+ })
1284
+ .catch(callback);
1285
+ return;
1286
+ }
1287
+ else {
1288
+ this.createSitemap(encoding);
1289
+ }
1205
1290
  }
1206
- else if (this.i % this.limit === 0) {
1207
- const onFinish = () => {
1208
- const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.i / this.limit);
1209
- this.currentSitemap = currentSitemap;
1210
- this.currentSitemapPipeline = currentSitemapPipeline;
1211
- this._writeSMI(item);
1212
- // push to index stream
1213
- super._transform(idxItem, encoding, callback);
1214
- };
1215
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1216
- this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
1291
+ this.writeItem(item, callback);
1292
+ }
1293
+ writeItem(item, callback) {
1294
+ if (!this.currentSitemap) {
1295
+ callback(new Error('No sitemap stream available'));
1296
+ return;
1297
+ }
1298
+ if (!this.currentSitemap.write(item)) {
1299
+ this.currentSitemap.once('drain', callback);
1217
1300
  }
1218
1301
  else {
1219
- this._writeSMI(item);
1220
- callback();
1302
+ process.nextTick(callback);
1221
1303
  }
1304
+ // Increment the count of items written
1305
+ this.itemsWritten++;
1222
1306
  }
1307
+ /**
1308
+ * Called when the stream is finished.
1309
+ * If there is a current sitemap, we wait for it to finish before calling the callback.
1310
+ *
1311
+ * @param cb
1312
+ */
1223
1313
  _flush(cb) {
1224
- var _a;
1225
- const onFinish = () => super._flush(cb);
1226
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1227
- this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
1314
+ const onFinish = new Promise((resolve, reject) => {
1315
+ if (this.currentSitemap) {
1316
+ this.currentSitemap.on('finish', resolve);
1317
+ this.currentSitemap.on('error', reject);
1318
+ this.currentSitemap.end();
1319
+ }
1320
+ else {
1321
+ resolve();
1322
+ }
1323
+ });
1324
+ const onPipelineFinish = new Promise((resolve, reject) => {
1325
+ if (this.currentSitemapPipeline) {
1326
+ this.currentSitemapPipeline.on('finish', resolve);
1327
+ this.currentSitemapPipeline.on('error', reject);
1328
+ // The pipeline (pipe target) will get it's end() call
1329
+ // from the sitemap stream ending.
1330
+ }
1331
+ else {
1332
+ resolve();
1333
+ }
1334
+ });
1335
+ Promise.all([onFinish, onPipelineFinish])
1336
+ .then(() => {
1337
+ super._flush(cb);
1338
+ })
1339
+ .catch((err) => {
1340
+ cb(err);
1341
+ });
1342
+ }
1343
+ createSitemap(encoding) {
1344
+ const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.itemsWritten / this.limit);
1345
+ currentSitemap.on('error', (err) => this.emit('error', err));
1346
+ this.currentSitemap = currentSitemap;
1347
+ this.currentSitemapPipeline = currentSitemapPipeline;
1348
+ super._transform(idxItem, encoding, () => {
1349
+ // We are not too fussed about waiting for the index item to be written
1350
+ // we we'll wait for the file to finish at the end
1351
+ // and index file write volume tends to be small in comprarison to sitemap
1352
+ // writes.
1353
+ // noop
1354
+ });
1228
1355
  }
1229
1356
  }
1230
1357
  exports.SitemapAndIndexStream = SitemapAndIndexStream;
@@ -3283,12 +3410,17 @@ class XMLToSitemapItemStream extends stream_1$7.Transform {
3283
3410
  }
3284
3411
  _transform(data, encoding, callback) {
3285
3412
  try {
3413
+ const cb = () => callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
3286
3414
  // correcting the type here can be done without making it a breaking change
3287
3415
  // TODO fix this
3288
3416
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3289
3417
  // @ts-ignore
3290
- this.saxStream.write(data, encoding);
3291
- callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
3418
+ if (!this.saxStream.write(data, encoding)) {
3419
+ this.saxStream.once('drain', cb);
3420
+ }
3421
+ else {
3422
+ process.nextTick(cb);
3423
+ }
3292
3424
  }
3293
3425
  catch (error) {
3294
3426
  callback(error);
@@ -3557,152 +3689,138 @@ sitemapIndexParser.IndexObjectStreamToJSON = IndexObjectStreamToJSON;
3557
3689
 
3558
3690
  var sitemapSimple = {};
3559
3691
 
3560
- var hasRequiredSitemapSimple;
3561
-
3562
- function requireSitemapSimple () {
3563
- if (hasRequiredSitemapSimple) return sitemapSimple;
3564
- hasRequiredSitemapSimple = 1;
3565
- (function (exports) {
3566
- Object.defineProperty(exports, "__esModule", { value: true });
3567
- exports.simpleSitemapAndIndex = void 0;
3568
- const index_1 = requireDist();
3569
- const zlib_1 = require$$1$2;
3570
- const fs_1 = require$$0$1;
3571
- const path_1 = require$$0$2;
3572
- const stream_1 = require$$0;
3573
- const util_1 = require$$0$3;
3574
- const url_1 = require$$3;
3575
- const pipeline = (0, util_1.promisify)(stream_1.pipeline);
3576
- /**
3577
- *
3578
- * @param {object} options -
3579
- * @param {string} options.hostname - The hostname for all URLs
3580
- * @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
3581
- * @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
3582
- * @param {string} options.destinationDir - where to write the sitemaps and index
3583
- * @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
3584
- * @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
3585
- * @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
3586
- * @returns {Promise<void>} an empty promise that resolves when everything is done
3587
- */
3588
- const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
3589
- /**
3590
- * Pass a line separated list of sitemap items or a stream or an array
3591
- */
3592
- sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
3593
- await fs_1.promises.mkdir(destinationDir, { recursive: true });
3594
- const sitemapAndIndexStream = new index_1.SitemapAndIndexStream({
3595
- limit,
3596
- getSitemapStream: (i) => {
3597
- const sitemapStream = new index_1.SitemapStream({
3598
- hostname,
3599
- });
3600
- const path = `./sitemap-${i}.xml`;
3601
- const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
3602
- if (!publicBasePath.endsWith('/')) {
3603
- publicBasePath += '/';
3604
- }
3605
- const publicPath = (0, path_1.normalize)(publicBasePath + path);
3606
- let pipeline;
3607
- if (gzip) {
3608
- pipeline = sitemapStream
3609
- .pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
3610
- .pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3611
- }
3612
- else {
3613
- pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3614
- }
3615
- return [
3616
- new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
3617
- sitemapStream,
3618
- pipeline,
3619
- ];
3620
- },
3621
- });
3622
- let src;
3623
- if (typeof sourceData === 'string') {
3624
- src = (0, index_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
3625
- }
3626
- else if (sourceData instanceof stream_1.Readable) {
3627
- src = sourceData;
3628
- }
3629
- else if (Array.isArray(sourceData)) {
3630
- src = stream_1.Readable.from(sourceData);
3631
- }
3632
- else {
3633
- throw new Error("unhandled source type. You've passed in data that is not supported");
3634
- }
3635
- const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
3636
- if (gzip) {
3637
- return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
3638
- }
3639
- else {
3640
- return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
3641
- }
3642
- };
3643
- exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
3644
- exports.default = exports.simpleSitemapAndIndex;
3645
- } (sitemapSimple));
3646
- return sitemapSimple;
3647
- }
3648
-
3649
- var hasRequiredDist;
3650
-
3651
- function requireDist () {
3652
- if (hasRequiredDist) return dist;
3653
- hasRequiredDist = 1;
3654
- (function (exports) {
3655
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3656
- if (k2 === undefined) k2 = k;
3657
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3658
- }) : (function(o, m, k, k2) {
3659
- if (k2 === undefined) k2 = k;
3660
- o[k2] = m[k];
3661
- }));
3662
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3663
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3664
- };
3665
- Object.defineProperty(exports, "__esModule", { value: true });
3666
- exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
3667
- /*!
3668
- * Sitemap
3669
- * Copyright(c) 2011 Eugene Kalinin
3670
- * MIT Licensed
3671
- */
3672
- var sitemap_item_stream_1 = sitemapItemStream;
3673
- Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
3674
- var sitemap_index_stream_1 = sitemapIndexStream;
3675
- Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
3676
- Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
3677
- Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
3678
- var sitemap_stream_1 = sitemapStream;
3679
- Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
3680
- Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
3681
- __exportStar(errors, exports);
3682
- __exportStar(types, exports);
3683
- var utils_1 = utils$l;
3684
- Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
3685
- Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
3686
- Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
3687
- Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
3688
- Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
3689
- var xmllint_1 = xmllint;
3690
- Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
3691
- var sitemap_parser_1 = sitemapParser;
3692
- Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
3693
- Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
3694
- Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
3695
- var sitemap_index_parser_1 = sitemapIndexParser;
3696
- Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
3697
- Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
3698
- Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
3699
- var sitemap_simple_1 = requireSitemapSimple();
3700
- Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
3701
- } (dist));
3702
- return dist;
3703
- }
3704
-
3705
- var distExports = requireDist();
3692
+ (function (exports) {
3693
+ Object.defineProperty(exports, "__esModule", { value: true });
3694
+ exports.simpleSitemapAndIndex = void 0;
3695
+ const sitemap_index_stream_1 = sitemapIndexStream;
3696
+ const sitemap_stream_1 = sitemapStream;
3697
+ const utils_1 = utils$l;
3698
+ const zlib_1 = require$$3$1;
3699
+ const fs_1 = require$$0$1;
3700
+ const path_1 = require$$0$2;
3701
+ const stream_1 = require$$0;
3702
+ const util_1 = require$$0$3;
3703
+ const url_1 = require$$3;
3704
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
3705
+ /**
3706
+ *
3707
+ * @param {object} options -
3708
+ * @param {string} options.hostname - The hostname for all URLs
3709
+ * @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
3710
+ * @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
3711
+ * @param {string} options.destinationDir - where to write the sitemaps and index
3712
+ * @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
3713
+ * @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
3714
+ * @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
3715
+ * @returns {Promise<void>} an empty promise that resolves when everything is done
3716
+ */
3717
+ const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
3718
+ /**
3719
+ * Pass a line separated list of sitemap items or a stream or an array
3720
+ */
3721
+ sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
3722
+ await fs_1.promises.mkdir(destinationDir, { recursive: true });
3723
+ const sitemapAndIndexStream = new sitemap_index_stream_1.SitemapAndIndexStream({
3724
+ limit,
3725
+ getSitemapStream: (i) => {
3726
+ const sitemapStream = new sitemap_stream_1.SitemapStream({
3727
+ hostname,
3728
+ });
3729
+ const path = `./sitemap-${i}.xml`;
3730
+ const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
3731
+ if (!publicBasePath.endsWith('/')) {
3732
+ publicBasePath += '/';
3733
+ }
3734
+ const publicPath = (0, path_1.normalize)(publicBasePath + path);
3735
+ let pipeline;
3736
+ if (gzip) {
3737
+ pipeline = sitemapStream
3738
+ .pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
3739
+ .pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3740
+ }
3741
+ else {
3742
+ pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3743
+ }
3744
+ return [
3745
+ new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
3746
+ sitemapStream,
3747
+ pipeline,
3748
+ ];
3749
+ },
3750
+ });
3751
+ let src;
3752
+ if (typeof sourceData === 'string') {
3753
+ src = (0, utils_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
3754
+ }
3755
+ else if (sourceData instanceof stream_1.Readable) {
3756
+ src = sourceData;
3757
+ }
3758
+ else if (Array.isArray(sourceData)) {
3759
+ src = stream_1.Readable.from(sourceData);
3760
+ }
3761
+ else {
3762
+ throw new Error("unhandled source type. You've passed in data that is not supported");
3763
+ }
3764
+ const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
3765
+ if (gzip) {
3766
+ return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
3767
+ }
3768
+ else {
3769
+ return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
3770
+ }
3771
+ };
3772
+ exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
3773
+ exports.default = exports.simpleSitemapAndIndex;
3774
+ } (sitemapSimple));
3775
+
3776
+ (function (exports) {
3777
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3778
+ if (k2 === undefined) k2 = k;
3779
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3780
+ }) : (function(o, m, k, k2) {
3781
+ if (k2 === undefined) k2 = k;
3782
+ o[k2] = m[k];
3783
+ }));
3784
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3785
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3786
+ };
3787
+ Object.defineProperty(exports, "__esModule", { value: true });
3788
+ exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
3789
+ /*!
3790
+ * Sitemap
3791
+ * Copyright(c) 2011 Eugene Kalinin
3792
+ * MIT Licensed
3793
+ */
3794
+ var sitemap_item_stream_1 = sitemapItemStream;
3795
+ Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
3796
+ var sitemap_index_stream_1 = sitemapIndexStream;
3797
+ Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
3798
+ Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
3799
+ Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
3800
+ var sitemap_stream_1 = sitemapStream;
3801
+ Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
3802
+ Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
3803
+ __exportStar(errors, exports);
3804
+ __exportStar(types, exports);
3805
+ var utils_1 = utils$l;
3806
+ Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
3807
+ Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
3808
+ Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
3809
+ Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
3810
+ Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
3811
+ var xmllint_1 = xmllint;
3812
+ Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
3813
+ var sitemap_parser_1 = sitemapParser;
3814
+ Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
3815
+ Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
3816
+ Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
3817
+ var sitemap_index_parser_1 = sitemapIndexParser;
3818
+ Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
3819
+ Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
3820
+ Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
3821
+ var sitemap_simple_1 = sitemapSimple;
3822
+ Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
3823
+ } (dist));
3706
3824
 
3707
3825
  var cjs$1 = {exports: {}};
3708
3826
 
@@ -10986,8 +11104,13 @@ function getFormattedSitemap(options, routes) {
10986
11104
  priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
10987
11105
  lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
10988
11106
  };
10989
- if (options.i18n)
10990
- return Object.assign(formattedSitemap, { link: options.i18n.languages.map((str) => ({ lang: str, url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}` })) });
11107
+ if (options.i18n) {
11108
+ const languages = options.i18n.languages.map((str) => ({
11109
+ lang: str,
11110
+ url: str === options.i18n?.defaultLanguage ? url : `${removeMaybeSuffix("/", url)}${ensurePrefix("/", str)}`
11111
+ }));
11112
+ return Object.assign(formattedSitemap, { links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages });
11113
+ }
10991
11114
  return formattedSitemap;
10992
11115
  });
10993
11116
  }
@@ -11003,9 +11126,9 @@ function generateSitemap(options = {}) {
11003
11126
  if (!routes.length)
11004
11127
  return;
11005
11128
  const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
11006
- const stream = new distExports.SitemapStream();
11129
+ const stream = new dist.SitemapStream();
11007
11130
  formattedSitemap.forEach((item) => stream.write(item));
11008
- distExports.streamToPromise(stream).then((sitemap) => {
11131
+ dist.streamToPromise(stream).then((sitemap) => {
11009
11132
  const utfSitemap = sitemap.toString("utf-8");
11010
11133
  const formattedSitemap2 = resolvedOptions.readable ? format(utfSitemap) : utfSitemap;
11011
11134
  writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import require$$0$2 from 'path';
7
7
  import require$$1 from 'child_process';
8
8
  import { createRequire } from 'module';
9
9
  import require$$1$1 from 'string_decoder';
10
- import require$$1$2 from 'zlib';
10
+ import require$$3$1 from 'zlib';
11
11
  import require$$0$3 from 'util';
12
12
  import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
13
13
  import require$$0$4 from 'os';
@@ -1083,8 +1083,12 @@ utils$l.normalizeURL = normalizeURL;
1083
1083
  this.hasHeadOutput = true;
1084
1084
  this.push(getURLSetNs(this.xmlNS, this.xslUrl));
1085
1085
  }
1086
- this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler));
1087
- callback();
1086
+ if (!this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler))) {
1087
+ this.smiStream.once('drain', callback);
1088
+ }
1089
+ else {
1090
+ process.nextTick(callback);
1091
+ }
1088
1092
  }
1089
1093
  _flush(cb) {
1090
1094
  if (!this.hasHeadOutput) {
@@ -1098,19 +1102,31 @@ utils$l.normalizeURL = normalizeURL;
1098
1102
  }
1099
1103
  exports.SitemapStream = SitemapStream;
1100
1104
  /**
1101
- * Takes a stream returns a promise that resolves when stream emits finish
1102
- * @param stream what you want wrapped in a promise
1105
+ * Converts a readable stream into a promise that resolves with the concatenated data from the stream.
1106
+ *
1107
+ * The function listens for 'data' events from the stream, and when the stream ends, it resolves the promise with the concatenated data. If an error occurs while reading from the stream, the promise is rejected with the error.
1108
+ *
1109
+ * ⚠️ CAUTION: This function should not generally be used in production / when writing to files as it holds a copy of the entire file contents in memory until finished.
1110
+ *
1111
+ * @param {Readable} stream - The readable stream to convert to a promise.
1112
+ * @returns {Promise<Buffer>} A promise that resolves with the concatenated data from the stream as a Buffer, or rejects with an error if one occurred while reading from the stream. If the stream is empty, the promise is rejected with an EmptyStream error.
1113
+ * @throws {EmptyStream} If the stream is empty.
1103
1114
  */
1104
1115
  function streamToPromise(stream) {
1105
1116
  return new Promise((resolve, reject) => {
1106
1117
  const drain = [];
1107
1118
  stream
1119
+ // Error propagation is not automatic
1120
+ // Bubble up errors on the read stream
1121
+ .on('error', reject)
1108
1122
  .pipe(new stream_1.Writable({
1109
1123
  write(chunk, enc, next) {
1110
1124
  drain.push(chunk);
1111
1125
  next();
1112
1126
  },
1113
1127
  }))
1128
+ // This bubbles up errors when writing to the internal buffer
1129
+ // This is unlikely to happen, but we have this for completeness
1114
1130
  .on('error', reject)
1115
1131
  .on('finish', () => {
1116
1132
  if (!drain.length) {
@@ -1142,7 +1158,27 @@ utils$l.normalizeURL = normalizeURL;
1142
1158
  const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
1143
1159
  const closetag = '</sitemapindex>';
1144
1160
  const defaultStreamOpts = {};
1161
+ /**
1162
+ * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
1163
+ *
1164
+ * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
1165
+ *
1166
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1167
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1168
+ *
1169
+ * @extends {Transform}
1170
+ */
1145
1171
  class SitemapIndexStream extends stream_1.Transform {
1172
+ /**
1173
+ * `SitemapIndexStream` is a Transform stream that takes `IndexItem`s or sitemap URL strings and outputs a stream of sitemap index XML.
1174
+ *
1175
+ * It automatically handles the XML declaration and the opening and closing tags for the sitemap index.
1176
+ *
1177
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1178
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1179
+ *
1180
+ * @param {SitemapIndexStreamOptions} [opts=defaultStreamOpts] - Stream options.
1181
+ */
1146
1182
  constructor(opts = defaultStreamOpts) {
1147
1183
  var _a;
1148
1184
  opts.objectMode = true;
@@ -1152,14 +1188,17 @@ utils$l.normalizeURL = normalizeURL;
1152
1188
  this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
1153
1189
  this.xslUrl = opts.xslUrl;
1154
1190
  }
1191
+ writeHeadOutput() {
1192
+ this.hasHeadOutput = true;
1193
+ let stylesheet = '';
1194
+ if (this.xslUrl) {
1195
+ stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
1196
+ }
1197
+ this.push(xmlDec + stylesheet + sitemapIndexTagStart);
1198
+ }
1155
1199
  _transform(item, encoding, callback) {
1156
1200
  if (!this.hasHeadOutput) {
1157
- this.hasHeadOutput = true;
1158
- let stylesheet = '';
1159
- if (this.xslUrl) {
1160
- stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
1161
- }
1162
- this.push(xmlDec + stylesheet + sitemapIndexTagStart);
1201
+ this.writeHeadOutput();
1163
1202
  }
1164
1203
  this.push((0, sitemap_xml_1.otag)(IndexTagNames.sitemap));
1165
1204
  if (typeof item === 'string') {
@@ -1176,55 +1215,143 @@ utils$l.normalizeURL = normalizeURL;
1176
1215
  callback();
1177
1216
  }
1178
1217
  _flush(cb) {
1218
+ if (!this.hasHeadOutput) {
1219
+ this.writeHeadOutput();
1220
+ }
1179
1221
  this.push(closetag);
1180
1222
  cb();
1181
1223
  }
1182
1224
  }
1183
1225
  exports.SitemapIndexStream = SitemapIndexStream;
1184
- // const defaultSIStreamOpts: SitemapAndIndexStreamOptions = {};
1226
+ /**
1227
+ * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
1228
+ * writes them to sitemap files, adds the sitemap files to a sitemap index,
1229
+ * and creates new sitemap files when the count limit is reached.
1230
+ *
1231
+ * It waits for the target stream of the current sitemap file to finish before
1232
+ * moving on to the next if the target stream is returned by the `getSitemapStream`
1233
+ * callback in the 3rd position of the tuple.
1234
+ *
1235
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1236
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1237
+ *
1238
+ * @extends {SitemapIndexStream}
1239
+ */
1185
1240
  class SitemapAndIndexStream extends SitemapIndexStream {
1241
+ /**
1242
+ * `SitemapAndIndexStream` is a Transform stream that takes in sitemap items,
1243
+ * writes them to sitemap files, adds the sitemap files to a sitemap index,
1244
+ * and creates new sitemap files when the count limit is reached.
1245
+ *
1246
+ * It waits for the target stream of the current sitemap file to finish before
1247
+ * moving on to the next if the target stream is returned by the `getSitemapStream`
1248
+ * callback in the 3rd position of the tuple.
1249
+ *
1250
+ * ⚠️ CAUTION: This object is `readable` and must be read (e.g. piped to a file or to /dev/null)
1251
+ * before `finish` will be emitted. Failure to read the stream will result in hangs.
1252
+ *
1253
+ * @param {SitemapAndIndexStreamOptions} opts - Stream options.
1254
+ */
1186
1255
  constructor(opts) {
1187
1256
  var _a;
1188
1257
  opts.objectMode = true;
1189
1258
  super(opts);
1190
- this.i = 0;
1259
+ this.itemsWritten = 0;
1191
1260
  this.getSitemapStream = opts.getSitemapStream;
1192
- [this.idxItem, this.currentSitemap, this.currentSitemapPipeline] =
1193
- this.getSitemapStream(0);
1194
1261
  this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000;
1195
1262
  }
1196
- _writeSMI(item) {
1197
- this.currentSitemap.write(item);
1198
- this.i++;
1199
- }
1200
1263
  _transform(item, encoding, callback) {
1201
- var _a;
1202
- if (this.i === 0) {
1203
- this._writeSMI(item);
1204
- super._transform(this.idxItem, encoding, callback);
1264
+ if (this.itemsWritten % this.limit === 0) {
1265
+ if (this.currentSitemap) {
1266
+ const onFinish = new Promise((resolve, reject) => {
1267
+ var _a, _b, _c;
1268
+ (_a = this.currentSitemap) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
1269
+ (_b = this.currentSitemap) === null || _b === void 0 ? void 0 : _b.on('error', reject);
1270
+ (_c = this.currentSitemap) === null || _c === void 0 ? void 0 : _c.end();
1271
+ });
1272
+ const onPipelineFinish = this.currentSitemapPipeline
1273
+ ? new Promise((resolve, reject) => {
1274
+ var _a, _b;
1275
+ (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', resolve);
1276
+ (_b = this.currentSitemapPipeline) === null || _b === void 0 ? void 0 : _b.on('error', reject);
1277
+ })
1278
+ : Promise.resolve();
1279
+ Promise.all([onFinish, onPipelineFinish])
1280
+ .then(() => {
1281
+ this.createSitemap(encoding);
1282
+ this.writeItem(item, callback);
1283
+ })
1284
+ .catch(callback);
1285
+ return;
1286
+ }
1287
+ else {
1288
+ this.createSitemap(encoding);
1289
+ }
1205
1290
  }
1206
- else if (this.i % this.limit === 0) {
1207
- const onFinish = () => {
1208
- const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.i / this.limit);
1209
- this.currentSitemap = currentSitemap;
1210
- this.currentSitemapPipeline = currentSitemapPipeline;
1211
- this._writeSMI(item);
1212
- // push to index stream
1213
- super._transform(idxItem, encoding, callback);
1214
- };
1215
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1216
- this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
1291
+ this.writeItem(item, callback);
1292
+ }
1293
+ writeItem(item, callback) {
1294
+ if (!this.currentSitemap) {
1295
+ callback(new Error('No sitemap stream available'));
1296
+ return;
1297
+ }
1298
+ if (!this.currentSitemap.write(item)) {
1299
+ this.currentSitemap.once('drain', callback);
1217
1300
  }
1218
1301
  else {
1219
- this._writeSMI(item);
1220
- callback();
1302
+ process.nextTick(callback);
1221
1303
  }
1304
+ // Increment the count of items written
1305
+ this.itemsWritten++;
1222
1306
  }
1307
+ /**
1308
+ * Called when the stream is finished.
1309
+ * If there is a current sitemap, we wait for it to finish before calling the callback.
1310
+ *
1311
+ * @param cb
1312
+ */
1223
1313
  _flush(cb) {
1224
- var _a;
1225
- const onFinish = () => super._flush(cb);
1226
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1227
- this.currentSitemap.end(!this.currentSitemapPipeline ? onFinish : undefined);
1314
+ const onFinish = new Promise((resolve, reject) => {
1315
+ if (this.currentSitemap) {
1316
+ this.currentSitemap.on('finish', resolve);
1317
+ this.currentSitemap.on('error', reject);
1318
+ this.currentSitemap.end();
1319
+ }
1320
+ else {
1321
+ resolve();
1322
+ }
1323
+ });
1324
+ const onPipelineFinish = new Promise((resolve, reject) => {
1325
+ if (this.currentSitemapPipeline) {
1326
+ this.currentSitemapPipeline.on('finish', resolve);
1327
+ this.currentSitemapPipeline.on('error', reject);
1328
+ // The pipeline (pipe target) will get it's end() call
1329
+ // from the sitemap stream ending.
1330
+ }
1331
+ else {
1332
+ resolve();
1333
+ }
1334
+ });
1335
+ Promise.all([onFinish, onPipelineFinish])
1336
+ .then(() => {
1337
+ super._flush(cb);
1338
+ })
1339
+ .catch((err) => {
1340
+ cb(err);
1341
+ });
1342
+ }
1343
+ createSitemap(encoding) {
1344
+ const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.itemsWritten / this.limit);
1345
+ currentSitemap.on('error', (err) => this.emit('error', err));
1346
+ this.currentSitemap = currentSitemap;
1347
+ this.currentSitemapPipeline = currentSitemapPipeline;
1348
+ super._transform(idxItem, encoding, () => {
1349
+ // We are not too fussed about waiting for the index item to be written
1350
+ // we we'll wait for the file to finish at the end
1351
+ // and index file write volume tends to be small in comprarison to sitemap
1352
+ // writes.
1353
+ // noop
1354
+ });
1228
1355
  }
1229
1356
  }
1230
1357
  exports.SitemapAndIndexStream = SitemapAndIndexStream;
@@ -3283,12 +3410,17 @@ class XMLToSitemapItemStream extends stream_1$7.Transform {
3283
3410
  }
3284
3411
  _transform(data, encoding, callback) {
3285
3412
  try {
3413
+ const cb = () => callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
3286
3414
  // correcting the type here can be done without making it a breaking change
3287
3415
  // TODO fix this
3288
3416
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3289
3417
  // @ts-ignore
3290
- this.saxStream.write(data, encoding);
3291
- callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
3418
+ if (!this.saxStream.write(data, encoding)) {
3419
+ this.saxStream.once('drain', cb);
3420
+ }
3421
+ else {
3422
+ process.nextTick(cb);
3423
+ }
3292
3424
  }
3293
3425
  catch (error) {
3294
3426
  callback(error);
@@ -3557,152 +3689,138 @@ sitemapIndexParser.IndexObjectStreamToJSON = IndexObjectStreamToJSON;
3557
3689
 
3558
3690
  var sitemapSimple = {};
3559
3691
 
3560
- var hasRequiredSitemapSimple;
3561
-
3562
- function requireSitemapSimple () {
3563
- if (hasRequiredSitemapSimple) return sitemapSimple;
3564
- hasRequiredSitemapSimple = 1;
3565
- (function (exports) {
3566
- Object.defineProperty(exports, "__esModule", { value: true });
3567
- exports.simpleSitemapAndIndex = void 0;
3568
- const index_1 = requireDist();
3569
- const zlib_1 = require$$1$2;
3570
- const fs_1 = require$$0$1;
3571
- const path_1 = require$$0$2;
3572
- const stream_1 = require$$0;
3573
- const util_1 = require$$0$3;
3574
- const url_1 = require$$3;
3575
- const pipeline = (0, util_1.promisify)(stream_1.pipeline);
3576
- /**
3577
- *
3578
- * @param {object} options -
3579
- * @param {string} options.hostname - The hostname for all URLs
3580
- * @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
3581
- * @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
3582
- * @param {string} options.destinationDir - where to write the sitemaps and index
3583
- * @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
3584
- * @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
3585
- * @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
3586
- * @returns {Promise<void>} an empty promise that resolves when everything is done
3587
- */
3588
- const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
3589
- /**
3590
- * Pass a line separated list of sitemap items or a stream or an array
3591
- */
3592
- sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
3593
- await fs_1.promises.mkdir(destinationDir, { recursive: true });
3594
- const sitemapAndIndexStream = new index_1.SitemapAndIndexStream({
3595
- limit,
3596
- getSitemapStream: (i) => {
3597
- const sitemapStream = new index_1.SitemapStream({
3598
- hostname,
3599
- });
3600
- const path = `./sitemap-${i}.xml`;
3601
- const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
3602
- if (!publicBasePath.endsWith('/')) {
3603
- publicBasePath += '/';
3604
- }
3605
- const publicPath = (0, path_1.normalize)(publicBasePath + path);
3606
- let pipeline;
3607
- if (gzip) {
3608
- pipeline = sitemapStream
3609
- .pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
3610
- .pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3611
- }
3612
- else {
3613
- pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3614
- }
3615
- return [
3616
- new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
3617
- sitemapStream,
3618
- pipeline,
3619
- ];
3620
- },
3621
- });
3622
- let src;
3623
- if (typeof sourceData === 'string') {
3624
- src = (0, index_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
3625
- }
3626
- else if (sourceData instanceof stream_1.Readable) {
3627
- src = sourceData;
3628
- }
3629
- else if (Array.isArray(sourceData)) {
3630
- src = stream_1.Readable.from(sourceData);
3631
- }
3632
- else {
3633
- throw new Error("unhandled source type. You've passed in data that is not supported");
3634
- }
3635
- const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
3636
- if (gzip) {
3637
- return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
3638
- }
3639
- else {
3640
- return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
3641
- }
3642
- };
3643
- exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
3644
- exports.default = exports.simpleSitemapAndIndex;
3645
- } (sitemapSimple));
3646
- return sitemapSimple;
3647
- }
3648
-
3649
- var hasRequiredDist;
3650
-
3651
- function requireDist () {
3652
- if (hasRequiredDist) return dist;
3653
- hasRequiredDist = 1;
3654
- (function (exports) {
3655
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3656
- if (k2 === undefined) k2 = k;
3657
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3658
- }) : (function(o, m, k, k2) {
3659
- if (k2 === undefined) k2 = k;
3660
- o[k2] = m[k];
3661
- }));
3662
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3663
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3664
- };
3665
- Object.defineProperty(exports, "__esModule", { value: true });
3666
- exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
3667
- /*!
3668
- * Sitemap
3669
- * Copyright(c) 2011 Eugene Kalinin
3670
- * MIT Licensed
3671
- */
3672
- var sitemap_item_stream_1 = sitemapItemStream;
3673
- Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
3674
- var sitemap_index_stream_1 = sitemapIndexStream;
3675
- Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
3676
- Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
3677
- Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
3678
- var sitemap_stream_1 = sitemapStream;
3679
- Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
3680
- Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
3681
- __exportStar(errors, exports);
3682
- __exportStar(types, exports);
3683
- var utils_1 = utils$l;
3684
- Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
3685
- Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
3686
- Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
3687
- Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
3688
- Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
3689
- var xmllint_1 = xmllint;
3690
- Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
3691
- var sitemap_parser_1 = sitemapParser;
3692
- Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
3693
- Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
3694
- Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
3695
- var sitemap_index_parser_1 = sitemapIndexParser;
3696
- Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
3697
- Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
3698
- Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
3699
- var sitemap_simple_1 = requireSitemapSimple();
3700
- Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
3701
- } (dist));
3702
- return dist;
3703
- }
3704
-
3705
- var distExports = requireDist();
3692
+ (function (exports) {
3693
+ Object.defineProperty(exports, "__esModule", { value: true });
3694
+ exports.simpleSitemapAndIndex = void 0;
3695
+ const sitemap_index_stream_1 = sitemapIndexStream;
3696
+ const sitemap_stream_1 = sitemapStream;
3697
+ const utils_1 = utils$l;
3698
+ const zlib_1 = require$$3$1;
3699
+ const fs_1 = require$$0$1;
3700
+ const path_1 = require$$0$2;
3701
+ const stream_1 = require$$0;
3702
+ const util_1 = require$$0$3;
3703
+ const url_1 = require$$3;
3704
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
3705
+ /**
3706
+ *
3707
+ * @param {object} options -
3708
+ * @param {string} options.hostname - The hostname for all URLs
3709
+ * @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
3710
+ * @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
3711
+ * @param {string} options.destinationDir - where to write the sitemaps and index
3712
+ * @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
3713
+ * @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
3714
+ * @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
3715
+ * @returns {Promise<void>} an empty promise that resolves when everything is done
3716
+ */
3717
+ const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
3718
+ /**
3719
+ * Pass a line separated list of sitemap items or a stream or an array
3720
+ */
3721
+ sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
3722
+ await fs_1.promises.mkdir(destinationDir, { recursive: true });
3723
+ const sitemapAndIndexStream = new sitemap_index_stream_1.SitemapAndIndexStream({
3724
+ limit,
3725
+ getSitemapStream: (i) => {
3726
+ const sitemapStream = new sitemap_stream_1.SitemapStream({
3727
+ hostname,
3728
+ });
3729
+ const path = `./sitemap-${i}.xml`;
3730
+ const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
3731
+ if (!publicBasePath.endsWith('/')) {
3732
+ publicBasePath += '/';
3733
+ }
3734
+ const publicPath = (0, path_1.normalize)(publicBasePath + path);
3735
+ let pipeline;
3736
+ if (gzip) {
3737
+ pipeline = sitemapStream
3738
+ .pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
3739
+ .pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3740
+ }
3741
+ else {
3742
+ pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3743
+ }
3744
+ return [
3745
+ new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
3746
+ sitemapStream,
3747
+ pipeline,
3748
+ ];
3749
+ },
3750
+ });
3751
+ let src;
3752
+ if (typeof sourceData === 'string') {
3753
+ src = (0, utils_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
3754
+ }
3755
+ else if (sourceData instanceof stream_1.Readable) {
3756
+ src = sourceData;
3757
+ }
3758
+ else if (Array.isArray(sourceData)) {
3759
+ src = stream_1.Readable.from(sourceData);
3760
+ }
3761
+ else {
3762
+ throw new Error("unhandled source type. You've passed in data that is not supported");
3763
+ }
3764
+ const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
3765
+ if (gzip) {
3766
+ return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
3767
+ }
3768
+ else {
3769
+ return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
3770
+ }
3771
+ };
3772
+ exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
3773
+ exports.default = exports.simpleSitemapAndIndex;
3774
+ } (sitemapSimple));
3775
+
3776
+ (function (exports) {
3777
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3778
+ if (k2 === undefined) k2 = k;
3779
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3780
+ }) : (function(o, m, k, k2) {
3781
+ if (k2 === undefined) k2 = k;
3782
+ o[k2] = m[k];
3783
+ }));
3784
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3785
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3786
+ };
3787
+ Object.defineProperty(exports, "__esModule", { value: true });
3788
+ exports.simpleSitemapAndIndex = exports.IndexObjectStreamToJSON = exports.XMLToSitemapIndexStream = exports.parseSitemapIndex = exports.ObjectStreamToJSON = exports.XMLToSitemapItemStream = exports.parseSitemap = exports.xmlLint = exports.ReadlineStream = exports.normalizeURL = exports.validateSMIOptions = exports.mergeStreams = exports.lineSeparatedURLsToSitemapOptions = exports.SitemapStream = exports.streamToPromise = exports.SitemapAndIndexStream = exports.SitemapIndexStream = exports.IndexTagNames = exports.SitemapItemStream = void 0;
3789
+ /*!
3790
+ * Sitemap
3791
+ * Copyright(c) 2011 Eugene Kalinin
3792
+ * MIT Licensed
3793
+ */
3794
+ var sitemap_item_stream_1 = sitemapItemStream;
3795
+ Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
3796
+ var sitemap_index_stream_1 = sitemapIndexStream;
3797
+ Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
3798
+ Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
3799
+ Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
3800
+ var sitemap_stream_1 = sitemapStream;
3801
+ Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
3802
+ Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
3803
+ __exportStar(errors, exports);
3804
+ __exportStar(types, exports);
3805
+ var utils_1 = utils$l;
3806
+ Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
3807
+ Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
3808
+ Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
3809
+ Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
3810
+ Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
3811
+ var xmllint_1 = xmllint;
3812
+ Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
3813
+ var sitemap_parser_1 = sitemapParser;
3814
+ Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
3815
+ Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
3816
+ Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
3817
+ var sitemap_index_parser_1 = sitemapIndexParser;
3818
+ Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
3819
+ Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
3820
+ Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
3821
+ var sitemap_simple_1 = sitemapSimple;
3822
+ Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
3823
+ } (dist));
3706
3824
 
3707
3825
  var cjs$1 = {exports: {}};
3708
3826
 
@@ -10986,8 +11104,13 @@ function getFormattedSitemap(options, routes) {
10986
11104
  priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
10987
11105
  lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
10988
11106
  };
10989
- if (options.i18n)
10990
- return Object.assign(formattedSitemap, { link: options.i18n.languages.map((str) => ({ lang: str, url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}` })) });
11107
+ if (options.i18n) {
11108
+ const languages = options.i18n.languages.map((str) => ({
11109
+ lang: str,
11110
+ url: str === options.i18n?.defaultLanguage ? url : `${removeMaybeSuffix("/", url)}${ensurePrefix("/", str)}`
11111
+ }));
11112
+ return Object.assign(formattedSitemap, { links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages });
11113
+ }
10991
11114
  return formattedSitemap;
10992
11115
  });
10993
11116
  }
@@ -11003,9 +11126,9 @@ function generateSitemap(options = {}) {
11003
11126
  if (!routes.length)
11004
11127
  return;
11005
11128
  const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
11006
- const stream = new distExports.SitemapStream();
11129
+ const stream = new dist.SitemapStream();
11007
11130
  formattedSitemap.forEach((item) => stream.write(item));
11008
- distExports.streamToPromise(stream).then((sitemap) => {
11131
+ dist.streamToPromise(stream).then((sitemap) => {
11009
11132
  const utfSitemap = sitemap.toString("utf-8");
11010
11133
  const formattedSitemap2 = resolvedOptions.readable ? format(utfSitemap) : utfSitemap;
11011
11134
  writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-sitemap",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
5
5
  "packageManager": "pnpm@9.1.2",
6
6
  "description": "Sitemap generator plugin for Vite",
7
7
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "eslint-plugin-format": "^0.1.1",
28
28
  "pkgroll": "^2.1.1",
29
29
  "pnpm": "^9.1.2",
30
- "sitemap-ts": "^1.7.0",
30
+ "sitemap-ts": "^1.7.2",
31
31
  "taze": "^0.13.8",
32
32
  "typescript": "^5.4.5",
33
33
  "vite": "^5.2.11",