vite-plugin-sitemap 0.5.3 → 0.6.1

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/index.js CHANGED
@@ -1,21 +1,18 @@
1
- 'use strict';
2
-
3
- var node_fs = require('node:fs');
4
- var require$$0 = require('stream');
5
- var require$$0$1 = require('fs');
6
- var require$$2 = require('readline');
7
- var require$$3 = require('url');
8
- var require$$0$2 = require('path');
9
- var require$$1 = require('child_process');
10
- var module$1 = require('module');
11
- var require$$1$1 = require('string_decoder');
12
- var require$$1$2 = require('zlib');
13
- var require$$0$3 = require('util');
14
- var node_path = require('node:path');
15
- var require$$0$4 = require('os');
16
- var require$$0$5 = require('events');
17
-
18
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
1
+ import { writeFileSync } from 'node:fs';
2
+ import require$$0 from 'stream';
3
+ import require$$0$1 from 'fs';
4
+ import require$$2 from 'readline';
5
+ import require$$3 from 'url';
6
+ import require$$0$2 from 'path';
7
+ import require$$1 from 'child_process';
8
+ import { createRequire } from 'module';
9
+ import require$$1$1 from 'string_decoder';
10
+ import require$$3$1 from 'zlib';
11
+ import require$$0$3 from 'util';
12
+ import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
13
+ import require$$0$4 from 'os';
14
+ import require$$0$5 from 'events';
15
+
19
16
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
20
17
 
21
18
  function getDefaultExportFromCjs (x) {
@@ -1086,8 +1083,12 @@ utils$l.normalizeURL = normalizeURL;
1086
1083
  this.hasHeadOutput = true;
1087
1084
  this.push(getURLSetNs(this.xmlNS, this.xslUrl));
1088
1085
  }
1089
- this.smiStream.write((0, utils_1.validateSMIOptions)((0, utils_1.normalizeURL)(item, this.hostname, this.lastmodDateOnly), this.level, this.errorHandler));
1090
- 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
+ }
1091
1092
  }
1092
1093
  _flush(cb) {
1093
1094
  if (!this.hasHeadOutput) {
@@ -1101,19 +1102,31 @@ utils$l.normalizeURL = normalizeURL;
1101
1102
  }
1102
1103
  exports.SitemapStream = SitemapStream;
1103
1104
  /**
1104
- * Takes a stream returns a promise that resolves when stream emits finish
1105
- * @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.
1106
1114
  */
1107
1115
  function streamToPromise(stream) {
1108
1116
  return new Promise((resolve, reject) => {
1109
1117
  const drain = [];
1110
1118
  stream
1119
+ // Error propagation is not automatic
1120
+ // Bubble up errors on the read stream
1121
+ .on('error', reject)
1111
1122
  .pipe(new stream_1.Writable({
1112
1123
  write(chunk, enc, next) {
1113
1124
  drain.push(chunk);
1114
1125
  next();
1115
1126
  },
1116
1127
  }))
1128
+ // This bubbles up errors when writing to the internal buffer
1129
+ // This is unlikely to happen, but we have this for completeness
1117
1130
  .on('error', reject)
1118
1131
  .on('finish', () => {
1119
1132
  if (!drain.length) {
@@ -1145,7 +1158,27 @@ utils$l.normalizeURL = normalizeURL;
1145
1158
  const sitemapIndexTagStart = '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
1146
1159
  const closetag = '</sitemapindex>';
1147
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
+ */
1148
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
+ */
1149
1182
  constructor(opts = defaultStreamOpts) {
1150
1183
  var _a;
1151
1184
  opts.objectMode = true;
@@ -1155,14 +1188,17 @@ utils$l.normalizeURL = normalizeURL;
1155
1188
  this.level = (_a = opts.level) !== null && _a !== void 0 ? _a : types_1.ErrorLevel.WARN;
1156
1189
  this.xslUrl = opts.xslUrl;
1157
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
+ }
1158
1199
  _transform(item, encoding, callback) {
1159
1200
  if (!this.hasHeadOutput) {
1160
- this.hasHeadOutput = true;
1161
- let stylesheet = '';
1162
- if (this.xslUrl) {
1163
- stylesheet = (0, sitemap_stream_1.stylesheetInclude)(this.xslUrl);
1164
- }
1165
- this.push(xmlDec + stylesheet + sitemapIndexTagStart);
1201
+ this.writeHeadOutput();
1166
1202
  }
1167
1203
  this.push((0, sitemap_xml_1.otag)(IndexTagNames.sitemap));
1168
1204
  if (typeof item === 'string') {
@@ -1179,55 +1215,143 @@ utils$l.normalizeURL = normalizeURL;
1179
1215
  callback();
1180
1216
  }
1181
1217
  _flush(cb) {
1218
+ if (!this.hasHeadOutput) {
1219
+ this.writeHeadOutput();
1220
+ }
1182
1221
  this.push(closetag);
1183
1222
  cb();
1184
1223
  }
1185
1224
  }
1186
1225
  exports.SitemapIndexStream = SitemapIndexStream;
1187
- // 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
+ */
1188
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
+ */
1189
1255
  constructor(opts) {
1190
1256
  var _a;
1191
1257
  opts.objectMode = true;
1192
1258
  super(opts);
1193
- this.i = 0;
1259
+ this.itemsWritten = 0;
1194
1260
  this.getSitemapStream = opts.getSitemapStream;
1195
- [this.idxItem, this.currentSitemap, this.currentSitemapPipeline] =
1196
- this.getSitemapStream(0);
1197
1261
  this.limit = (_a = opts.limit) !== null && _a !== void 0 ? _a : 45000;
1198
1262
  }
1199
- _writeSMI(item) {
1200
- this.currentSitemap.write(item);
1201
- this.i++;
1202
- }
1203
1263
  _transform(item, encoding, callback) {
1204
- var _a;
1205
- if (this.i === 0) {
1206
- this._writeSMI(item);
1207
- 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
+ }
1208
1290
  }
1209
- else if (this.i % this.limit === 0) {
1210
- const onFinish = () => {
1211
- const [idxItem, currentSitemap, currentSitemapPipeline] = this.getSitemapStream(this.i / this.limit);
1212
- this.currentSitemap = currentSitemap;
1213
- this.currentSitemapPipeline = currentSitemapPipeline;
1214
- this._writeSMI(item);
1215
- // push to index stream
1216
- super._transform(idxItem, encoding, callback);
1217
- };
1218
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1219
- 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);
1220
1300
  }
1221
1301
  else {
1222
- this._writeSMI(item);
1223
- callback();
1302
+ process.nextTick(callback);
1224
1303
  }
1304
+ // Increment the count of items written
1305
+ this.itemsWritten++;
1225
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
+ */
1226
1313
  _flush(cb) {
1227
- var _a;
1228
- const onFinish = () => super._flush(cb);
1229
- (_a = this.currentSitemapPipeline) === null || _a === void 0 ? void 0 : _a.on('finish', onFinish);
1230
- 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
+ });
1231
1355
  }
1232
1356
  }
1233
1357
  exports.SitemapAndIndexStream = SitemapAndIndexStream;
@@ -1281,8 +1405,8 @@ xmllint.xmlLint = xmlLint;
1281
1405
  var sitemapParser = {};
1282
1406
 
1283
1407
  var require$1 = (
1284
- false
1285
- ? /* @__PURE__ */ module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)))
1408
+ true
1409
+ ? /* @__PURE__ */ createRequire(import.meta.url)
1286
1410
  : require
1287
1411
  );
1288
1412
 
@@ -3286,12 +3410,17 @@ class XMLToSitemapItemStream extends stream_1$7.Transform {
3286
3410
  }
3287
3411
  _transform(data, encoding, callback) {
3288
3412
  try {
3413
+ const cb = () => callback(this.level === types_1$1.ErrorLevel.THROW ? this.error : null);
3289
3414
  // correcting the type here can be done without making it a breaking change
3290
3415
  // TODO fix this
3291
3416
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3292
3417
  // @ts-ignore
3293
- this.saxStream.write(data, encoding);
3294
- 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
+ }
3295
3424
  }
3296
3425
  catch (error) {
3297
3426
  callback(error);
@@ -3560,152 +3689,138 @@ sitemapIndexParser.IndexObjectStreamToJSON = IndexObjectStreamToJSON;
3560
3689
 
3561
3690
  var sitemapSimple = {};
3562
3691
 
3563
- var hasRequiredSitemapSimple;
3564
-
3565
- function requireSitemapSimple () {
3566
- if (hasRequiredSitemapSimple) return sitemapSimple;
3567
- hasRequiredSitemapSimple = 1;
3568
- (function (exports) {
3569
- Object.defineProperty(exports, "__esModule", { value: true });
3570
- exports.simpleSitemapAndIndex = void 0;
3571
- const index_1 = requireDist();
3572
- const zlib_1 = require$$1$2;
3573
- const fs_1 = require$$0$1;
3574
- const path_1 = require$$0$2;
3575
- const stream_1 = require$$0;
3576
- const util_1 = require$$0$3;
3577
- const url_1 = require$$3;
3578
- const pipeline = (0, util_1.promisify)(stream_1.pipeline);
3579
- /**
3580
- *
3581
- * @param {object} options -
3582
- * @param {string} options.hostname - The hostname for all URLs
3583
- * @param {string} [options.sitemapHostname] - The hostname for the sitemaps if different than hostname
3584
- * @param {SitemapItemLoose[] | string | Readable | string[]} options.sourceData - The urls you want to make a sitemap out of.
3585
- * @param {string} options.destinationDir - where to write the sitemaps and index
3586
- * @param {string} [options.publicBasePath] - where the sitemaps are relative to the hostname. Defaults to root.
3587
- * @param {number} [options.limit] - how many URLs to write before switching to a new file. Defaults to 50k
3588
- * @param {boolean} [options.gzip] - whether to compress the written files. Defaults to true
3589
- * @returns {Promise<void>} an empty promise that resolves when everything is done
3590
- */
3591
- const simpleSitemapAndIndex = async ({ hostname, sitemapHostname = hostname, // if different
3592
- /**
3593
- * Pass a line separated list of sitemap items or a stream or an array
3594
- */
3595
- sourceData, destinationDir, limit = 50000, gzip = true, publicBasePath = './', }) => {
3596
- await fs_1.promises.mkdir(destinationDir, { recursive: true });
3597
- const sitemapAndIndexStream = new index_1.SitemapAndIndexStream({
3598
- limit,
3599
- getSitemapStream: (i) => {
3600
- const sitemapStream = new index_1.SitemapStream({
3601
- hostname,
3602
- });
3603
- const path = `./sitemap-${i}.xml`;
3604
- const writePath = (0, path_1.resolve)(destinationDir, path + (gzip ? '.gz' : ''));
3605
- if (!publicBasePath.endsWith('/')) {
3606
- publicBasePath += '/';
3607
- }
3608
- const publicPath = (0, path_1.normalize)(publicBasePath + path);
3609
- let pipeline;
3610
- if (gzip) {
3611
- pipeline = sitemapStream
3612
- .pipe((0, zlib_1.createGzip)()) // compress the output of the sitemap
3613
- .pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3614
- }
3615
- else {
3616
- pipeline = sitemapStream.pipe((0, fs_1.createWriteStream)(writePath)); // write it to sitemap-NUMBER.xml
3617
- }
3618
- return [
3619
- new url_1.URL(`${publicPath}${gzip ? '.gz' : ''}`, sitemapHostname).toString(),
3620
- sitemapStream,
3621
- pipeline,
3622
- ];
3623
- },
3624
- });
3625
- let src;
3626
- if (typeof sourceData === 'string') {
3627
- src = (0, index_1.lineSeparatedURLsToSitemapOptions)((0, fs_1.createReadStream)(sourceData));
3628
- }
3629
- else if (sourceData instanceof stream_1.Readable) {
3630
- src = sourceData;
3631
- }
3632
- else if (Array.isArray(sourceData)) {
3633
- src = stream_1.Readable.from(sourceData);
3634
- }
3635
- else {
3636
- throw new Error("unhandled source type. You've passed in data that is not supported");
3637
- }
3638
- const writePath = (0, path_1.resolve)(destinationDir, `./sitemap-index.xml${gzip ? '.gz' : ''}`);
3639
- if (gzip) {
3640
- return pipeline(src, sitemapAndIndexStream, (0, zlib_1.createGzip)(), (0, fs_1.createWriteStream)(writePath));
3641
- }
3642
- else {
3643
- return pipeline(src, sitemapAndIndexStream, (0, fs_1.createWriteStream)(writePath));
3644
- }
3645
- };
3646
- exports.simpleSitemapAndIndex = simpleSitemapAndIndex;
3647
- exports.default = exports.simpleSitemapAndIndex;
3648
- } (sitemapSimple));
3649
- return sitemapSimple;
3650
- }
3651
-
3652
- var hasRequiredDist;
3653
-
3654
- function requireDist () {
3655
- if (hasRequiredDist) return dist;
3656
- hasRequiredDist = 1;
3657
- (function (exports) {
3658
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3659
- if (k2 === undefined) k2 = k;
3660
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3661
- }) : (function(o, m, k, k2) {
3662
- if (k2 === undefined) k2 = k;
3663
- o[k2] = m[k];
3664
- }));
3665
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
3666
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
3667
- };
3668
- Object.defineProperty(exports, "__esModule", { value: true });
3669
- 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;
3670
- /*!
3671
- * Sitemap
3672
- * Copyright(c) 2011 Eugene Kalinin
3673
- * MIT Licensed
3674
- */
3675
- var sitemap_item_stream_1 = sitemapItemStream;
3676
- Object.defineProperty(exports, "SitemapItemStream", { enumerable: true, get: function () { return sitemap_item_stream_1.SitemapItemStream; } });
3677
- var sitemap_index_stream_1 = sitemapIndexStream;
3678
- Object.defineProperty(exports, "IndexTagNames", { enumerable: true, get: function () { return sitemap_index_stream_1.IndexTagNames; } });
3679
- Object.defineProperty(exports, "SitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapIndexStream; } });
3680
- Object.defineProperty(exports, "SitemapAndIndexStream", { enumerable: true, get: function () { return sitemap_index_stream_1.SitemapAndIndexStream; } });
3681
- var sitemap_stream_1 = sitemapStream;
3682
- Object.defineProperty(exports, "streamToPromise", { enumerable: true, get: function () { return sitemap_stream_1.streamToPromise; } });
3683
- Object.defineProperty(exports, "SitemapStream", { enumerable: true, get: function () { return sitemap_stream_1.SitemapStream; } });
3684
- __exportStar(errors, exports);
3685
- __exportStar(types, exports);
3686
- var utils_1 = utils$l;
3687
- Object.defineProperty(exports, "lineSeparatedURLsToSitemapOptions", { enumerable: true, get: function () { return utils_1.lineSeparatedURLsToSitemapOptions; } });
3688
- Object.defineProperty(exports, "mergeStreams", { enumerable: true, get: function () { return utils_1.mergeStreams; } });
3689
- Object.defineProperty(exports, "validateSMIOptions", { enumerable: true, get: function () { return utils_1.validateSMIOptions; } });
3690
- Object.defineProperty(exports, "normalizeURL", { enumerable: true, get: function () { return utils_1.normalizeURL; } });
3691
- Object.defineProperty(exports, "ReadlineStream", { enumerable: true, get: function () { return utils_1.ReadlineStream; } });
3692
- var xmllint_1 = xmllint;
3693
- Object.defineProperty(exports, "xmlLint", { enumerable: true, get: function () { return xmllint_1.xmlLint; } });
3694
- var sitemap_parser_1 = sitemapParser;
3695
- Object.defineProperty(exports, "parseSitemap", { enumerable: true, get: function () { return sitemap_parser_1.parseSitemap; } });
3696
- Object.defineProperty(exports, "XMLToSitemapItemStream", { enumerable: true, get: function () { return sitemap_parser_1.XMLToSitemapItemStream; } });
3697
- Object.defineProperty(exports, "ObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_parser_1.ObjectStreamToJSON; } });
3698
- var sitemap_index_parser_1 = sitemapIndexParser;
3699
- Object.defineProperty(exports, "parseSitemapIndex", { enumerable: true, get: function () { return sitemap_index_parser_1.parseSitemapIndex; } });
3700
- Object.defineProperty(exports, "XMLToSitemapIndexStream", { enumerable: true, get: function () { return sitemap_index_parser_1.XMLToSitemapIndexStream; } });
3701
- Object.defineProperty(exports, "IndexObjectStreamToJSON", { enumerable: true, get: function () { return sitemap_index_parser_1.IndexObjectStreamToJSON; } });
3702
- var sitemap_simple_1 = requireSitemapSimple();
3703
- Object.defineProperty(exports, "simpleSitemapAndIndex", { enumerable: true, get: function () { return sitemap_simple_1.simpleSitemapAndIndex; } });
3704
- } (dist));
3705
- return dist;
3706
- }
3707
-
3708
- 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));
3709
3824
 
3710
3825
  var cjs$1 = {exports: {}};
3711
3826
 
@@ -4052,7 +4167,7 @@ var cjsExports$1 = cjs.exports;
4052
4167
  containsTextNodesWithLineBreaks = true;
4053
4168
  child.content = child.content.trim();
4054
4169
  }
4055
- else if (index === 0 || index === nodeChildren.length - 1) {
4170
+ else if ((index === 0 || index === nodeChildren.length - 1) && !preserveSpace) {
4056
4171
  if (child.content.trim().length === 0) {
4057
4172
  // If the text node is at the start or end and is empty, it should be ignored when formatting
4058
4173
  child.content = '';
@@ -4223,11 +4338,11 @@ const IS_WINDOWS_PLATFORM = os.platform() === 'win32';
4223
4338
  const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
4224
4339
  /**
4225
4340
  * All non-escaped special characters.
4226
- * Posix: ()*?[\]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
4227
- * Windows: (){}, !+@ before (, ! at the beginning.
4341
+ * Posix: ()*?[]{|}, !+@ before (, ! at the beginning, \\ before non-special characters.
4342
+ * Windows: (){}[], !+@ before (, ! at the beginning.
4228
4343
  */
4229
4344
  const POSIX_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\()|\\(?![!()*+?@[\]{|}]))/g;
4230
- const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([(){}]|^!|[!+@](?=\())/g;
4345
+ const WINDOWS_UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()[\]{}]|^!|[!+@](?=\())/g;
4231
4346
  /**
4232
4347
  * The device path (\\.\ or \\?\).
4233
4348
  * https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#dos-device-paths
@@ -4238,7 +4353,7 @@ const DOS_DEVICE_PATH_RE = /^\\\\([.?])/;
4238
4353
  * Windows: !()+@{}
4239
4354
  * https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
4240
4355
  */
4241
- const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@{}])/g;
4356
+ const WINDOWS_BACKSLASHES_RE = /\\(?![!()+@[\]{}])/g;
4242
4357
  /**
4243
4358
  * Designed to work only with simple paths: `dir\\file`.
4244
4359
  */
@@ -4533,7 +4648,7 @@ var utils$j = {};
4533
4648
  */
4534
4649
 
4535
4650
  exports.escapeNode = (block, n = 0, type) => {
4536
- let node = block.nodes[n];
4651
+ const node = block.nodes[n];
4537
4652
  if (!node) return;
4538
4653
 
4539
4654
  if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
@@ -4602,13 +4717,23 @@ var utils$j = {};
4602
4717
 
4603
4718
  exports.flatten = (...args) => {
4604
4719
  const result = [];
4720
+
4605
4721
  const flat = arr => {
4606
4722
  for (let i = 0; i < arr.length; i++) {
4607
- let ele = arr[i];
4608
- Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
4723
+ const ele = arr[i];
4724
+
4725
+ if (Array.isArray(ele)) {
4726
+ flat(ele);
4727
+ continue;
4728
+ }
4729
+
4730
+ if (ele !== undefined) {
4731
+ result.push(ele);
4732
+ }
4609
4733
  }
4610
4734
  return result;
4611
4735
  };
4736
+
4612
4737
  flat(args);
4613
4738
  return result;
4614
4739
  };
@@ -4617,9 +4742,9 @@ var utils$j = {};
4617
4742
  const utils$i = utils$j;
4618
4743
 
4619
4744
  var stringify$4 = (ast, options = {}) => {
4620
- let stringify = (node, parent = {}) => {
4621
- let invalidBlock = options.escapeInvalid && utils$i.isInvalidBrace(parent);
4622
- let invalidNode = node.invalid === true && options.escapeInvalid === true;
4745
+ const stringify = (node, parent = {}) => {
4746
+ const invalidBlock = options.escapeInvalid && utils$i.isInvalidBrace(parent);
4747
+ const invalidNode = node.invalid === true && options.escapeInvalid === true;
4623
4748
  let output = '';
4624
4749
 
4625
4750
  if (node.value) {
@@ -4634,7 +4759,7 @@ var stringify$4 = (ast, options = {}) => {
4634
4759
  }
4635
4760
 
4636
4761
  if (node.nodes) {
4637
- for (let child of node.nodes) {
4762
+ for (const child of node.nodes) {
4638
4763
  output += stringify(child);
4639
4764
  }
4640
4765
  }
@@ -5008,7 +5133,7 @@ const toMaxLen = (input, maxLength) => {
5008
5133
  return negative ? ('-' + input) : input;
5009
5134
  };
5010
5135
 
5011
- const toSequence = (parts, options) => {
5136
+ const toSequence = (parts, options, maxLen) => {
5012
5137
  parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
5013
5138
  parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
5014
5139
 
@@ -5018,11 +5143,11 @@ const toSequence = (parts, options) => {
5018
5143
  let result;
5019
5144
 
5020
5145
  if (parts.positives.length) {
5021
- positives = parts.positives.join('|');
5146
+ positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
5022
5147
  }
5023
5148
 
5024
5149
  if (parts.negatives.length) {
5025
- negatives = `-(${prefix}${parts.negatives.join('|')})`;
5150
+ negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
5026
5151
  }
5027
5152
 
5028
5153
  if (positives && negatives) {
@@ -5120,7 +5245,7 @@ const fillNumbers = (start, end, step = 1, options = {}) => {
5120
5245
 
5121
5246
  if (options.toRegex === true) {
5122
5247
  return step > 1
5123
- ? toSequence(parts, options)
5248
+ ? toSequence(parts, options, maxLen)
5124
5249
  : toRegex(range, null, { wrap: false, ...options });
5125
5250
  }
5126
5251
 
@@ -5132,7 +5257,6 @@ const fillLetters = (start, end, step = 1, options = {}) => {
5132
5257
  return invalidRange(start, end, options);
5133
5258
  }
5134
5259
 
5135
-
5136
5260
  let format = options.transform || (val => String.fromCharCode(val));
5137
5261
  let a = `${start}`.charCodeAt(0);
5138
5262
  let b = `${end}`.charCodeAt(0);
@@ -5200,30 +5324,32 @@ const fill$1 = fillRange;
5200
5324
  const utils$h = utils$j;
5201
5325
 
5202
5326
  const compile$1 = (ast, options = {}) => {
5203
- let walk = (node, parent = {}) => {
5204
- let invalidBlock = utils$h.isInvalidBrace(parent);
5205
- let invalidNode = node.invalid === true && options.escapeInvalid === true;
5206
- let invalid = invalidBlock === true || invalidNode === true;
5207
- let prefix = options.escapeInvalid === true ? '\\' : '';
5327
+ const walk = (node, parent = {}) => {
5328
+ const invalidBlock = utils$h.isInvalidBrace(parent);
5329
+ const invalidNode = node.invalid === true && options.escapeInvalid === true;
5330
+ const invalid = invalidBlock === true || invalidNode === true;
5331
+ const prefix = options.escapeInvalid === true ? '\\' : '';
5208
5332
  let output = '';
5209
5333
 
5210
5334
  if (node.isOpen === true) {
5211
5335
  return prefix + node.value;
5212
5336
  }
5337
+
5213
5338
  if (node.isClose === true) {
5339
+ console.log('node.isClose', prefix, node.value);
5214
5340
  return prefix + node.value;
5215
5341
  }
5216
5342
 
5217
5343
  if (node.type === 'open') {
5218
- return invalid ? (prefix + node.value) : '(';
5344
+ return invalid ? prefix + node.value : '(';
5219
5345
  }
5220
5346
 
5221
5347
  if (node.type === 'close') {
5222
- return invalid ? (prefix + node.value) : ')';
5348
+ return invalid ? prefix + node.value : ')';
5223
5349
  }
5224
5350
 
5225
5351
  if (node.type === 'comma') {
5226
- return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
5352
+ return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
5227
5353
  }
5228
5354
 
5229
5355
  if (node.value) {
@@ -5231,8 +5357,8 @@ const compile$1 = (ast, options = {}) => {
5231
5357
  }
5232
5358
 
5233
5359
  if (node.nodes && node.ranges > 0) {
5234
- let args = utils$h.reduce(node.nodes);
5235
- let range = fill$1(...args, { ...options, wrap: false, toRegex: true });
5360
+ const args = utils$h.reduce(node.nodes);
5361
+ const range = fill$1(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
5236
5362
 
5237
5363
  if (range.length !== 0) {
5238
5364
  return args.length > 1 && range.length > 1 ? `(${range})` : range;
@@ -5240,10 +5366,11 @@ const compile$1 = (ast, options = {}) => {
5240
5366
  }
5241
5367
 
5242
5368
  if (node.nodes) {
5243
- for (let child of node.nodes) {
5369
+ for (const child of node.nodes) {
5244
5370
  output += walk(child, node);
5245
5371
  }
5246
5372
  }
5373
+
5247
5374
  return output;
5248
5375
  };
5249
5376
 
@@ -5257,7 +5384,7 @@ const stringify$2 = stringify$4;
5257
5384
  const utils$g = utils$j;
5258
5385
 
5259
5386
  const append = (queue = '', stash = '', enclose = false) => {
5260
- let result = [];
5387
+ const result = [];
5261
5388
 
5262
5389
  queue = [].concat(queue);
5263
5390
  stash = [].concat(stash);
@@ -5267,15 +5394,15 @@ const append = (queue = '', stash = '', enclose = false) => {
5267
5394
  return enclose ? utils$g.flatten(stash).map(ele => `{${ele}}`) : stash;
5268
5395
  }
5269
5396
 
5270
- for (let item of queue) {
5397
+ for (const item of queue) {
5271
5398
  if (Array.isArray(item)) {
5272
- for (let value of item) {
5399
+ for (const value of item) {
5273
5400
  result.push(append(value, stash, enclose));
5274
5401
  }
5275
5402
  } else {
5276
5403
  for (let ele of stash) {
5277
5404
  if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
5278
- result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
5405
+ result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
5279
5406
  }
5280
5407
  }
5281
5408
  }
@@ -5283,9 +5410,9 @@ const append = (queue = '', stash = '', enclose = false) => {
5283
5410
  };
5284
5411
 
5285
5412
  const expand$1 = (ast, options = {}) => {
5286
- let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
5413
+ const rangeLimit = options.rangeLimit === undefined ? 1000 : options.rangeLimit;
5287
5414
 
5288
- let walk = (node, parent = {}) => {
5415
+ const walk = (node, parent = {}) => {
5289
5416
  node.queue = [];
5290
5417
 
5291
5418
  let p = parent;
@@ -5307,7 +5434,7 @@ const expand$1 = (ast, options = {}) => {
5307
5434
  }
5308
5435
 
5309
5436
  if (node.nodes && node.ranges > 0) {
5310
- let args = utils$g.reduce(node.nodes);
5437
+ const args = utils$g.reduce(node.nodes);
5311
5438
 
5312
5439
  if (utils$g.exceedsLimit(...args, options.step, rangeLimit)) {
5313
5440
  throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
@@ -5323,7 +5450,7 @@ const expand$1 = (ast, options = {}) => {
5323
5450
  return;
5324
5451
  }
5325
5452
 
5326
- let enclose = utils$g.encloseBrace(node);
5453
+ const enclose = utils$g.encloseBrace(node);
5327
5454
  let queue = node.queue;
5328
5455
  let block = node;
5329
5456
 
@@ -5333,7 +5460,7 @@ const expand$1 = (ast, options = {}) => {
5333
5460
  }
5334
5461
 
5335
5462
  for (let i = 0; i < node.nodes.length; i++) {
5336
- let child = node.nodes[i];
5463
+ const child = node.nodes[i];
5337
5464
 
5338
5465
  if (child.type === 'comma' && node.type === 'brace') {
5339
5466
  if (i === 1) queue.push('');
@@ -5365,7 +5492,7 @@ const expand$1 = (ast, options = {}) => {
5365
5492
  var expand_1 = expand$1;
5366
5493
 
5367
5494
  var constants$4 = {
5368
- MAX_LENGTH: 1024 * 64,
5495
+ MAX_LENGTH: 10000,
5369
5496
 
5370
5497
  // Digits
5371
5498
  CHAR_0: '0', /* 0 */
@@ -5453,18 +5580,18 @@ const parse$3 = (input, options = {}) => {
5453
5580
  throw new TypeError('Expected a string');
5454
5581
  }
5455
5582
 
5456
- let opts = options || {};
5457
- let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
5583
+ const opts = options || {};
5584
+ const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
5458
5585
  if (input.length > max) {
5459
5586
  throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
5460
5587
  }
5461
5588
 
5462
- let ast = { type: 'root', input, nodes: [] };
5463
- let stack = [ast];
5589
+ const ast = { type: 'root', input, nodes: [] };
5590
+ const stack = [ast];
5464
5591
  let block = ast;
5465
5592
  let prev = ast;
5466
5593
  let brackets = 0;
5467
- let length = input.length;
5594
+ const length = input.length;
5468
5595
  let index = 0;
5469
5596
  let depth = 0;
5470
5597
  let value;
@@ -5529,6 +5656,7 @@ const parse$3 = (input, options = {}) => {
5529
5656
 
5530
5657
  if (value === CHAR_LEFT_SQUARE_BRACKET$1) {
5531
5658
  brackets++;
5659
+
5532
5660
  let next;
5533
5661
 
5534
5662
  while (index < length && (next = advance())) {
@@ -5584,7 +5712,7 @@ const parse$3 = (input, options = {}) => {
5584
5712
  */
5585
5713
 
5586
5714
  if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
5587
- let open = value;
5715
+ const open = value;
5588
5716
  let next;
5589
5717
 
5590
5718
  if (options.keepQuotes !== true) {
@@ -5616,8 +5744,8 @@ const parse$3 = (input, options = {}) => {
5616
5744
  if (value === CHAR_LEFT_CURLY_BRACE$1) {
5617
5745
  depth++;
5618
5746
 
5619
- let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
5620
- let brace = {
5747
+ const dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
5748
+ const brace = {
5621
5749
  type: 'brace',
5622
5750
  open: true,
5623
5751
  close: false,
@@ -5644,7 +5772,7 @@ const parse$3 = (input, options = {}) => {
5644
5772
  continue;
5645
5773
  }
5646
5774
 
5647
- let type = 'close';
5775
+ const type = 'close';
5648
5776
  block = stack.pop();
5649
5777
  block.close = true;
5650
5778
 
@@ -5662,7 +5790,7 @@ const parse$3 = (input, options = {}) => {
5662
5790
  if (value === CHAR_COMMA$1 && depth > 0) {
5663
5791
  if (block.ranges > 0) {
5664
5792
  block.ranges = 0;
5665
- let open = block.nodes.shift();
5793
+ const open = block.nodes.shift();
5666
5794
  block.nodes = [open, { type: 'text', value: stringify$1(block) }];
5667
5795
  }
5668
5796
 
@@ -5676,7 +5804,7 @@ const parse$3 = (input, options = {}) => {
5676
5804
  */
5677
5805
 
5678
5806
  if (value === CHAR_DOT$1 && depth > 0 && block.commas === 0) {
5679
- let siblings = block.nodes;
5807
+ const siblings = block.nodes;
5680
5808
 
5681
5809
  if (depth === 0 || siblings.length === 0) {
5682
5810
  push({ type: 'text', value });
@@ -5703,7 +5831,7 @@ const parse$3 = (input, options = {}) => {
5703
5831
  if (prev.type === 'range') {
5704
5832
  siblings.pop();
5705
5833
 
5706
- let before = siblings[siblings.length - 1];
5834
+ const before = siblings[siblings.length - 1];
5707
5835
  before.value += prev.value + value;
5708
5836
  prev = before;
5709
5837
  block.ranges--;
@@ -5736,8 +5864,8 @@ const parse$3 = (input, options = {}) => {
5736
5864
  });
5737
5865
 
5738
5866
  // get the location of the block on parent.nodes (block's siblings)
5739
- let parent = stack[stack.length - 1];
5740
- let index = parent.nodes.indexOf(block);
5867
+ const parent = stack[stack.length - 1];
5868
+ const index = parent.nodes.indexOf(block);
5741
5869
  // replace the (invalid) block with it's nodes
5742
5870
  parent.nodes.splice(index, 1, ...block.nodes);
5743
5871
  }
@@ -5772,8 +5900,8 @@ const braces$1 = (input, options = {}) => {
5772
5900
  let output = [];
5773
5901
 
5774
5902
  if (Array.isArray(input)) {
5775
- for (let pattern of input) {
5776
- let result = braces$1.create(pattern, options);
5903
+ for (const pattern of input) {
5904
+ const result = braces$1.create(pattern, options);
5777
5905
  if (Array.isArray(result)) {
5778
5906
  output.push(...result);
5779
5907
  } else {
@@ -5907,7 +6035,7 @@ braces$1.create = (input, options = {}) => {
5907
6035
  return [input];
5908
6036
  }
5909
6037
 
5910
- return options.expand !== true
6038
+ return options.expand !== true
5911
6039
  ? braces$1.compile(input, options)
5912
6040
  : braces$1.expand(input, options);
5913
6041
  };
@@ -8588,7 +8716,7 @@ function expandPatternsWithBraceExpansion(patterns) {
8588
8716
  }
8589
8717
  pattern$1.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
8590
8718
  function expandBraceExpansion(pattern) {
8591
- const patterns = micromatch.braces(pattern, { expand: true, nodupes: true });
8719
+ const patterns = micromatch.braces(pattern, { expand: true, nodupes: true, keepEscaping: true });
8592
8720
  /**
8593
8721
  * Sort the patterns by length so that the same depth patterns are processed side by side.
8594
8722
  * `a/{b,}/{c,}/*` – `['a///*', 'a/b//*', 'a//c/*', 'a/b/c/*']`
@@ -9487,15 +9615,15 @@ var reusify_1 = reusify$1;
9487
9615
 
9488
9616
  var reusify = reusify_1;
9489
9617
 
9490
- function fastqueue (context, worker, concurrency) {
9618
+ function fastqueue (context, worker, _concurrency) {
9491
9619
  if (typeof context === 'function') {
9492
- concurrency = worker;
9620
+ _concurrency = worker;
9493
9621
  worker = context;
9494
9622
  context = null;
9495
9623
  }
9496
9624
 
9497
- if (concurrency < 1) {
9498
- throw new Error('fastqueue concurrency must be greater than 1')
9625
+ if (!(_concurrency >= 1)) {
9626
+ throw new Error('fastqueue concurrency must be equal to or greater than 1')
9499
9627
  }
9500
9628
 
9501
9629
  var cache = reusify(Task);
@@ -9510,7 +9638,23 @@ function fastqueue (context, worker, concurrency) {
9510
9638
  saturated: noop,
9511
9639
  pause: pause,
9512
9640
  paused: false,
9513
- concurrency: concurrency,
9641
+
9642
+ get concurrency () {
9643
+ return _concurrency
9644
+ },
9645
+ set concurrency (value) {
9646
+ if (!(value >= 1)) {
9647
+ throw new Error('fastqueue concurrency must be equal to or greater than 1')
9648
+ }
9649
+ _concurrency = value;
9650
+
9651
+ if (self.paused) return
9652
+ for (; queueHead && _running < _concurrency;) {
9653
+ _running++;
9654
+ release();
9655
+ }
9656
+ },
9657
+
9514
9658
  running: running,
9515
9659
  resume: resume,
9516
9660
  idle: idle,
@@ -9560,7 +9704,12 @@ function fastqueue (context, worker, concurrency) {
9560
9704
  function resume () {
9561
9705
  if (!self.paused) return
9562
9706
  self.paused = false;
9563
- for (var i = 0; i < self.concurrency; i++) {
9707
+ if (queueHead === null) {
9708
+ _running++;
9709
+ release();
9710
+ return
9711
+ }
9712
+ for (; queueHead && _running < _concurrency;) {
9564
9713
  _running++;
9565
9714
  release();
9566
9715
  }
@@ -9579,7 +9728,7 @@ function fastqueue (context, worker, concurrency) {
9579
9728
  current.callback = done || noop;
9580
9729
  current.errorHandler = errorHandler;
9581
9730
 
9582
- if (_running === self.concurrency || self.paused) {
9731
+ if (_running >= _concurrency || self.paused) {
9583
9732
  if (queueTail) {
9584
9733
  queueTail.next = current;
9585
9734
  queueTail = current;
@@ -9601,8 +9750,9 @@ function fastqueue (context, worker, concurrency) {
9601
9750
  current.release = release;
9602
9751
  current.value = value;
9603
9752
  current.callback = done || noop;
9753
+ current.errorHandler = errorHandler;
9604
9754
 
9605
- if (_running === self.concurrency || self.paused) {
9755
+ if (_running >= _concurrency || self.paused) {
9606
9756
  if (queueHead) {
9607
9757
  current.next = queueHead;
9608
9758
  queueHead = current;
@@ -9622,7 +9772,7 @@ function fastqueue (context, worker, concurrency) {
9622
9772
  cache.release(holder);
9623
9773
  }
9624
9774
  var next = queueHead;
9625
- if (next) {
9775
+ if (next && _running <= _concurrency) {
9626
9776
  if (!self.paused) {
9627
9777
  if (queueTail === queueHead) {
9628
9778
  queueTail = null;
@@ -9685,9 +9835,9 @@ function Task () {
9685
9835
  };
9686
9836
  }
9687
9837
 
9688
- function queueAsPromised (context, worker, concurrency) {
9838
+ function queueAsPromised (context, worker, _concurrency) {
9689
9839
  if (typeof context === 'function') {
9690
- concurrency = worker;
9840
+ _concurrency = worker;
9691
9841
  worker = context;
9692
9842
  context = null;
9693
9843
  }
@@ -9699,7 +9849,7 @@ function queueAsPromised (context, worker, concurrency) {
9699
9849
  }, cb);
9700
9850
  }
9701
9851
 
9702
- var queue = fastqueue(context, asyncWrapper, concurrency);
9852
+ var queue = fastqueue(context, asyncWrapper, _concurrency);
9703
9853
 
9704
9854
  var pushCb = queue.push;
9705
9855
  var unshiftCb = queue.unshift;
@@ -10848,8 +10998,6 @@ function assertPatternsInput(input) {
10848
10998
  }
10849
10999
  var out = FastGlob;
10850
11000
 
10851
- var fg = /*@__PURE__*/getDefaultExportFromCjs(out);
10852
-
10853
11001
  const defaultOptions = {
10854
11002
  hostname: "http://localhost/",
10855
11003
  dynamicRoutes: [],
@@ -10877,9 +11025,9 @@ function resolveOptions(userOptions) {
10877
11025
  }
10878
11026
 
10879
11027
  function getResolvedPath(file, resolvedOptions) {
10880
- if (node_path.isAbsolute(resolvedOptions.outDir))
10881
- return node_path.resolve(`${resolvedOptions.outDir}/${file}`);
10882
- return node_path.resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
11028
+ if (isAbsolute(resolvedOptions.outDir))
11029
+ return resolve(`${resolvedOptions.outDir}/${file}`);
11030
+ return resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
10883
11031
  }
10884
11032
  function removeMaybeSuffix(suffix, str) {
10885
11033
  if (!str.endsWith(suffix))
@@ -10925,16 +11073,16 @@ function getRoutes(options) {
10925
11073
  const ext = typeof options.extensions === "string" ? [options.extensions] : options.extensions;
10926
11074
  const strExt = ext.map((e) => `**/*.${e}`);
10927
11075
  return [
10928
- ...fg.sync(strExt, { cwd: options.outDir }).map((route) => {
11076
+ ...out.sync(strExt, { cwd: options.outDir }).map((route) => {
10929
11077
  let r = route;
10930
11078
  ext.forEach((e) => {
10931
11079
  const regex = new RegExp(`index.${e}`, "g");
10932
11080
  r = r.replace(regex, "");
10933
11081
  });
10934
- const parsedRoute = node_path.parse(r);
10935
- return slash$1(node_path.join("/", parsedRoute.dir, parsedRoute.name));
11082
+ const parsedRoute = parse$4(r);
11083
+ return slash$1(join("/", parsedRoute.dir, parsedRoute.name));
10936
11084
  }),
10937
- ...options.dynamicRoutes.map((route) => slash$1(node_path.join("/", node_path.join(node_path.parse(route).dir, node_path.parse(route).name))))
11085
+ ...options.dynamicRoutes.map((route) => slash$1(join("/", join(parse$4(route).dir, parse$4(route).name))))
10938
11086
  ].filter((route) => !options.exclude.includes(route));
10939
11087
  }
10940
11088
  function getOptionByRoute(options, route) {
@@ -10948,12 +11096,25 @@ function getOptionByRoute(options, route) {
10948
11096
  return void 0;
10949
11097
  }
10950
11098
  function getFormattedSitemap(options, routes) {
10951
- return routes.map((route) => ({
10952
- url: new URL(options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route), removeMaybeSuffix("/", options.hostname)).href,
10953
- changefreq: getOptionByRoute(options.changefreq, route) ?? defaultOptions.changefreq,
10954
- priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
10955
- lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
10956
- }));
11099
+ return routes.map((route) => {
11100
+ const url = new URL(options.basePath ? ensurePrefix("/", options.basePath) + ensurePrefix("/", route) : ensurePrefix("/", route), removeMaybeSuffix("/", options.hostname)).href;
11101
+ const formattedSitemap = {
11102
+ url,
11103
+ changefreq: getOptionByRoute(options.changefreq, route) ?? defaultOptions.changefreq,
11104
+ priority: getOptionByRoute(options.priority, route) ?? defaultOptions.priority,
11105
+ lastmod: getOptionByRoute(options.lastmod, route) ?? defaultOptions.lastmod
11106
+ };
11107
+ if (options.i18n) {
11108
+ const languages = options.i18n.languages.map((str) => ({
11109
+ lang: str,
11110
+ url: str === options.i18n?.defaultLanguage ? url : `${url}/${str}`
11111
+ }));
11112
+ return Object.assign(formattedSitemap, {
11113
+ links: options.i18n.defaultLanguage ? [...languages, { lang: "x-default", url }] : languages
11114
+ });
11115
+ }
11116
+ return formattedSitemap;
11117
+ });
10957
11118
  }
10958
11119
 
10959
11120
  function generateSitemap(options = {}) {
@@ -10961,18 +11122,18 @@ function generateSitemap(options = {}) {
10961
11122
  if (resolvedOptions.generateRobotsTxt) {
10962
11123
  const robotRules = getRules(resolvedOptions.robots);
10963
11124
  const robotContent = getContent(robotRules, resolvedOptions.hostname, resolvedOptions.externalSitemaps);
10964
- node_fs.writeFileSync(getResolvedPath("robots.txt", resolvedOptions), robotContent);
11125
+ writeFileSync(getResolvedPath("robots.txt", resolvedOptions), robotContent);
10965
11126
  }
10966
11127
  const routes = getRoutes(resolvedOptions);
10967
11128
  if (!routes.length)
10968
11129
  return;
10969
11130
  const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
10970
- const stream = new distExports.SitemapStream();
11131
+ const stream = new dist.SitemapStream();
10971
11132
  formattedSitemap.forEach((item) => stream.write(item));
10972
- distExports.streamToPromise(stream).then((sitemap) => {
11133
+ dist.streamToPromise(stream).then((sitemap) => {
10973
11134
  const utfSitemap = sitemap.toString("utf-8");
10974
11135
  const formattedSitemap2 = resolvedOptions.readable ? format(utfSitemap) : utfSitemap;
10975
- node_fs.writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
11136
+ writeFileSync(getResolvedPath("sitemap.xml", resolvedOptions), formattedSitemap2);
10976
11137
  });
10977
11138
  stream.end();
10978
11139
  }
@@ -11000,4 +11161,4 @@ function sitemapPlugin(options = {}) {
11000
11161
  };
11001
11162
  }
11002
11163
 
11003
- module.exports = sitemapPlugin;
11164
+ export { sitemapPlugin as default };