vite-plugin-sitemap 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,12 @@
1
+ /// <reference types="node" />
2
+ interface NSArgs {
3
+ news: boolean;
4
+ video: boolean;
5
+ xhtml: boolean;
6
+ image: boolean;
7
+ custom?: string[];
8
+ }
9
+
1
10
  interface RobotOption {
2
11
  /**
3
12
  * User-agent value.
@@ -116,6 +125,12 @@ interface Options {
116
125
  * @default [{ userAgent: '*', allow: '/' }]
117
126
  */
118
127
  robots: RobotOption[];
128
+ /**
129
+ * Trim the xml namespace
130
+ * See https://www.npmjs.com/package/sitemap#options-you-can-pass
131
+ * @default undefined
132
+ */
133
+ xmlns?: NSArgs;
119
134
  }
120
135
  type UserOptions = Partial<Options>;
121
136
 
@@ -124,7 +139,7 @@ declare function sitemapPlugin(options?: UserOptions): {
124
139
  closeBundle(): void;
125
140
  transformIndexHtml(): {
126
141
  tag: string;
127
- injectTo: "head" | "body" | "head-prepend" | "body-prepend" | undefined;
142
+ injectTo: "head" | "body" | "head-prepend" | "body-prepend";
128
143
  attrs: {
129
144
  rel: string;
130
145
  type: string;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { createRequire } from 'module';
9
9
  import require$$1$1 from 'string_decoder';
10
10
  import require$$3$1 from 'zlib';
11
11
  import require$$0$3 from 'util';
12
- import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
12
+ import { isAbsolute as isAbsolute$1, resolve, parse as parse$4, join } from 'node:path';
13
13
  import require$$0$4 from 'os';
14
14
  import require$$0$5 from 'events';
15
15
 
@@ -1486,6 +1486,12 @@ var sax = {};
1486
1486
  parser.ns = Object.create(rootNS);
1487
1487
  }
1488
1488
 
1489
+ // disallow unquoted attribute values if not otherwise configured
1490
+ // and strict mode is true
1491
+ if (parser.opt.unquotedAttributeValues === undefined) {
1492
+ parser.opt.unquotedAttributeValues = !strict;
1493
+ }
1494
+
1489
1495
  // mostly just for error reporting
1490
1496
  parser.trackPosition = parser.opt.position !== false;
1491
1497
  if (parser.trackPosition) {
@@ -2503,15 +2509,22 @@ var sax = {};
2503
2509
  continue
2504
2510
 
2505
2511
  case S.SGML_DECL:
2506
- if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
2512
+ if (parser.sgmlDecl + c === '--') {
2513
+ parser.state = S.COMMENT;
2514
+ parser.comment = '';
2515
+ parser.sgmlDecl = '';
2516
+ continue;
2517
+ }
2518
+
2519
+ if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
2520
+ parser.state = S.DOCTYPE_DTD;
2521
+ parser.doctype += '<!' + parser.sgmlDecl + c;
2522
+ parser.sgmlDecl = '';
2523
+ } else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
2507
2524
  emitNode(parser, 'onopencdata');
2508
2525
  parser.state = S.CDATA;
2509
2526
  parser.sgmlDecl = '';
2510
2527
  parser.cdata = '';
2511
- } else if (parser.sgmlDecl + c === '--') {
2512
- parser.state = S.COMMENT;
2513
- parser.comment = '';
2514
- parser.sgmlDecl = '';
2515
2528
  } else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
2516
2529
  parser.state = S.DOCTYPE;
2517
2530
  if (parser.doctype || parser.sawRoot) {
@@ -2565,12 +2578,18 @@ var sax = {};
2565
2578
  continue
2566
2579
 
2567
2580
  case S.DOCTYPE_DTD:
2568
- parser.doctype += c;
2569
2581
  if (c === ']') {
2582
+ parser.doctype += c;
2570
2583
  parser.state = S.DOCTYPE;
2584
+ } else if (c === '<') {
2585
+ parser.state = S.OPEN_WAKA;
2586
+ parser.startTagPosition = parser.position;
2571
2587
  } else if (isQuote(c)) {
2588
+ parser.doctype += c;
2572
2589
  parser.state = S.DOCTYPE_DTD_QUOTED;
2573
2590
  parser.q = c;
2591
+ } else {
2592
+ parser.doctype += c;
2574
2593
  }
2575
2594
  continue
2576
2595
 
@@ -2611,6 +2630,8 @@ var sax = {};
2611
2630
  // which is a comment of " blah -- bloo "
2612
2631
  parser.comment += '--' + c;
2613
2632
  parser.state = S.COMMENT;
2633
+ } else if (parser.doctype && parser.doctype !== true) {
2634
+ parser.state = S.DOCTYPE_DTD;
2614
2635
  } else {
2615
2636
  parser.state = S.TEXT;
2616
2637
  }
@@ -2778,7 +2799,9 @@ var sax = {};
2778
2799
  parser.q = c;
2779
2800
  parser.state = S.ATTRIB_VALUE_QUOTED;
2780
2801
  } else {
2781
- strictFail(parser, 'Unquoted attribute value');
2802
+ if (!parser.opt.unquotedAttributeValues) {
2803
+ error(parser, 'Unquoted attribute value');
2804
+ }
2782
2805
  parser.state = S.ATTRIB_VALUE_UNQUOTED;
2783
2806
  parser.attribValue = c;
2784
2807
  }
@@ -2896,13 +2919,13 @@ var sax = {};
2896
2919
  }
2897
2920
 
2898
2921
  if (c === ';') {
2899
- if (parser.opt.unparsedEntities) {
2900
- var parsedEntity = parseEntity(parser);
2922
+ var parsedEntity = parseEntity(parser);
2923
+ if (parser.opt.unparsedEntities && !Object.values(sax.XML_ENTITIES).includes(parsedEntity)) {
2901
2924
  parser.entity = '';
2902
2925
  parser.state = returnState;
2903
2926
  parser.write(parsedEntity);
2904
2927
  } else {
2905
- parser[buffer] += parseEntity(parser);
2928
+ parser[buffer] += parsedEntity;
2906
2929
  parser.entity = '';
2907
2930
  parser.state = returnState;
2908
2931
  }
@@ -3838,7 +3861,7 @@ var cjs = {exports: {}};
3838
3861
  exports.ParsingError = ParsingError;
3839
3862
  let parsingState;
3840
3863
  function nextChild() {
3841
- return element(false) || text() || comment() || cdata();
3864
+ return element(false) || text() || comment() || cdata() || processingInstruction(false);
3842
3865
  }
3843
3866
  function nextRootChild() {
3844
3867
  match(/\s*/);
@@ -3874,7 +3897,7 @@ var cjs = {exports: {}};
3874
3897
  };
3875
3898
  }
3876
3899
  function processingInstruction(matchDeclaration) {
3877
- const m = matchDeclaration ? match(/^<\?(xml)\s*/) : match(/^<\?([\w-:.]+)\s*/);
3900
+ const m = matchDeclaration ? match(/^<\?(xml(-stylesheet)?)\s*/) : match(/^<\?([\w-:.]+)\s*/);
3878
3901
  if (!m)
3879
3902
  return;
3880
3903
  // tag
@@ -3949,7 +3972,7 @@ var cjs = {exports: {}};
3949
3972
  }
3950
3973
  }
3951
3974
  else {
3952
- match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/);
3975
+ match(/^<\/[\w-:.\u00C0-\u00FF]+\s*>/);
3953
3976
  }
3954
3977
  return {
3955
3978
  excluded,
@@ -4151,7 +4174,7 @@ var cjsExports$1 = cjs.exports;
4151
4174
  const nodeChildren = node.children;
4152
4175
  appendContent(state, '>');
4153
4176
  state.level++;
4154
- let nodePreserveSpace = node.attributes['xml:space'] === 'preserve';
4177
+ let nodePreserveSpace = node.attributes['xml:space'] === 'preserve' || preserveSpace;
4155
4178
  let ignoredPath = false;
4156
4179
  if (!nodePreserveSpace && state.options.ignoredPaths) {
4157
4180
  ignoredPath = isPathMatchingIgnoredPaths(state.path, state.options.ignoredPaths);
@@ -4173,7 +4196,8 @@ var cjsExports$1 = cjs.exports;
4173
4196
  child.content = '';
4174
4197
  }
4175
4198
  }
4176
- if (child.content.trim().length > 0) {
4199
+ // If there is some content or whitespaces have been removed and there is no other siblings
4200
+ if (child.content.trim().length > 0 || nodeChildren.length === 1) {
4177
4201
  containsTextNodes = true;
4178
4202
  }
4179
4203
  }
@@ -8119,7 +8143,12 @@ const util = require$$0$3;
8119
8143
  const braces = braces_1;
8120
8144
  const picomatch = picomatch$1;
8121
8145
  const utils$b = utils$f;
8122
- const isEmptyString = val => val === '' || val === './';
8146
+
8147
+ const isEmptyString = v => v === '' || v === './';
8148
+ const hasBraces = v => {
8149
+ const index = v.indexOf('{');
8150
+ return index > -1 && v.indexOf('}', index) > -1;
8151
+ };
8123
8152
 
8124
8153
  /**
8125
8154
  * Returns an array of strings that match one or more glob patterns.
@@ -8560,7 +8589,7 @@ micromatch$1.parse = (patterns, options) => {
8560
8589
 
8561
8590
  micromatch$1.braces = (pattern, options) => {
8562
8591
  if (typeof pattern !== 'string') throw new TypeError('Expected a string');
8563
- if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
8592
+ if ((options && options.nobrace === true) || !hasBraces(pattern)) {
8564
8593
  return [pattern];
8565
8594
  }
8566
8595
  return braces(pattern, options);
@@ -8579,10 +8608,12 @@ micromatch$1.braceExpand = (pattern, options) => {
8579
8608
  * Expose micromatch
8580
8609
  */
8581
8610
 
8611
+ // exposed for tests
8612
+ micromatch$1.hasBraces = hasBraces;
8582
8613
  var micromatch_1 = micromatch$1;
8583
8614
 
8584
8615
  Object.defineProperty(pattern$1, "__esModule", { value: true });
8585
- pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
8616
+ pattern$1.isAbsolute = pattern$1.partitionAbsoluteAndRelative = pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
8586
8617
  const path$5 = require$$0$2;
8587
8618
  const globParent = globParent$1;
8588
8619
  const micromatch = micromatch_1;
@@ -8768,6 +8799,24 @@ function removeDuplicateSlashes(pattern) {
8768
8799
  return pattern.replace(DOUBLE_SLASH_RE, '/');
8769
8800
  }
8770
8801
  pattern$1.removeDuplicateSlashes = removeDuplicateSlashes;
8802
+ function partitionAbsoluteAndRelative(patterns) {
8803
+ const absolute = [];
8804
+ const relative = [];
8805
+ for (const pattern of patterns) {
8806
+ if (isAbsolute(pattern)) {
8807
+ absolute.push(pattern);
8808
+ }
8809
+ else {
8810
+ relative.push(pattern);
8811
+ }
8812
+ }
8813
+ return [absolute, relative];
8814
+ }
8815
+ pattern$1.partitionAbsoluteAndRelative = partitionAbsoluteAndRelative;
8816
+ function isAbsolute(pattern) {
8817
+ return path$5.isAbsolute(pattern);
8818
+ }
8819
+ pattern$1.isAbsolute = isAbsolute;
8771
8820
 
8772
8821
  var stream$4 = {};
8773
8822
 
@@ -9899,19 +9948,19 @@ function queueAsPromised (context, worker, _concurrency) {
9899
9948
  }
9900
9949
 
9901
9950
  function drained () {
9902
- if (queue.idle()) {
9903
- return new Promise(function (resolve) {
9904
- resolve();
9905
- })
9906
- }
9907
-
9908
- var previousDrain = queue.drain;
9909
-
9910
9951
  var p = new Promise(function (resolve) {
9911
- queue.drain = function () {
9912
- previousDrain();
9913
- resolve();
9914
- };
9952
+ process.nextTick(function () {
9953
+ if (queue.idle()) {
9954
+ resolve();
9955
+ } else {
9956
+ var previousDrain = queue.drain;
9957
+ queue.drain = function () {
9958
+ if (typeof previousDrain === 'function') previousDrain();
9959
+ resolve();
9960
+ queue.drain = previousDrain;
9961
+ };
9962
+ }
9963
+ });
9915
9964
  });
9916
9965
 
9917
9966
  return p
@@ -10562,11 +10611,19 @@ class EntryFilter {
10562
10611
  this.index = new Map();
10563
10612
  }
10564
10613
  getFilter(positive, negative) {
10565
- const positiveRe = utils$3.pattern.convertPatternsToRe(positive, this._micromatchOptions);
10566
- const negativeRe = utils$3.pattern.convertPatternsToRe(negative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true }));
10567
- return (entry) => this._filter(entry, positiveRe, negativeRe);
10614
+ const [absoluteNegative, relativeNegative] = utils$3.pattern.partitionAbsoluteAndRelative(negative);
10615
+ const patterns = {
10616
+ positive: {
10617
+ all: utils$3.pattern.convertPatternsToRe(positive, this._micromatchOptions)
10618
+ },
10619
+ negative: {
10620
+ absolute: utils$3.pattern.convertPatternsToRe(absoluteNegative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true })),
10621
+ relative: utils$3.pattern.convertPatternsToRe(relativeNegative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true }))
10622
+ }
10623
+ };
10624
+ return (entry) => this._filter(entry, patterns);
10568
10625
  }
10569
- _filter(entry, positiveRe, negativeRe) {
10626
+ _filter(entry, patterns) {
10570
10627
  const filepath = utils$3.path.removeLeadingDotSegment(entry.path);
10571
10628
  if (this._settings.unique && this._isDuplicateEntry(filepath)) {
10572
10629
  return false;
@@ -10574,11 +10631,7 @@ class EntryFilter {
10574
10631
  if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
10575
10632
  return false;
10576
10633
  }
10577
- if (this._isSkippedByAbsoluteNegativePatterns(filepath, negativeRe)) {
10578
- return false;
10579
- }
10580
- const isDirectory = entry.dirent.isDirectory();
10581
- const isMatched = this._isMatchToPatterns(filepath, positiveRe, isDirectory) && !this._isMatchToPatterns(filepath, negativeRe, isDirectory);
10634
+ const isMatched = this._isMatchToPatternsSet(filepath, patterns, entry.dirent.isDirectory());
10582
10635
  if (this._settings.unique && isMatched) {
10583
10636
  this._createIndexRecord(filepath);
10584
10637
  }
@@ -10596,14 +10649,32 @@ class EntryFilter {
10596
10649
  _onlyDirectoryFilter(entry) {
10597
10650
  return this._settings.onlyDirectories && !entry.dirent.isDirectory();
10598
10651
  }
10599
- _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
10600
- if (!this._settings.absolute) {
10652
+ _isMatchToPatternsSet(filepath, patterns, isDirectory) {
10653
+ const isMatched = this._isMatchToPatterns(filepath, patterns.positive.all, isDirectory);
10654
+ if (!isMatched) {
10655
+ return false;
10656
+ }
10657
+ const isMatchedByRelativeNegative = this._isMatchToPatterns(filepath, patterns.negative.relative, isDirectory);
10658
+ if (isMatchedByRelativeNegative) {
10659
+ return false;
10660
+ }
10661
+ const isMatchedByAbsoluteNegative = this._isMatchToAbsoluteNegative(filepath, patterns.negative.absolute, isDirectory);
10662
+ if (isMatchedByAbsoluteNegative) {
10663
+ return false;
10664
+ }
10665
+ return true;
10666
+ }
10667
+ _isMatchToAbsoluteNegative(filepath, patternsRe, isDirectory) {
10668
+ if (patternsRe.length === 0) {
10601
10669
  return false;
10602
10670
  }
10603
- const fullpath = utils$3.path.makeAbsolute(this._settings.cwd, entryPath);
10604
- return utils$3.pattern.matchAny(fullpath, patternsRe);
10671
+ const fullpath = utils$3.path.makeAbsolute(this._settings.cwd, filepath);
10672
+ return this._isMatchToPatterns(fullpath, patternsRe, isDirectory);
10605
10673
  }
10606
10674
  _isMatchToPatterns(filepath, patternsRe, isDirectory) {
10675
+ if (patternsRe.length === 0) {
10676
+ return false;
10677
+ }
10607
10678
  // Trying to match files and directories by patterns.
10608
10679
  const isMatched = utils$3.pattern.matchAny(filepath, patternsRe);
10609
10680
  // A pattern with a trailling slash can be used for directory matching.
@@ -11027,7 +11098,7 @@ function resolveOptions(userOptions) {
11027
11098
  }
11028
11099
 
11029
11100
  function getResolvedPath(file, resolvedOptions) {
11030
- if (isAbsolute(resolvedOptions.outDir))
11101
+ if (isAbsolute$1(resolvedOptions.outDir))
11031
11102
  return resolve(`${resolvedOptions.outDir}/${file}`);
11032
11103
  return resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
11033
11104
  }
@@ -11131,7 +11202,9 @@ function generateSitemap(options = {}) {
11131
11202
  if (!routes.length)
11132
11203
  return;
11133
11204
  const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
11134
- const stream = new dist.SitemapStream();
11205
+ const stream = new dist.SitemapStream({
11206
+ xmlns: resolvedOptions.xmlns
11207
+ });
11135
11208
  formattedSitemap.forEach((item) => stream.write(item));
11136
11209
  dist.streamToPromise(stream).then((sitemap) => {
11137
11210
  const utfSitemap = sitemap.toString("utf-8");
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { createRequire } from 'module';
9
9
  import require$$1$1 from 'string_decoder';
10
10
  import require$$3$1 from 'zlib';
11
11
  import require$$0$3 from 'util';
12
- import { isAbsolute, resolve, parse as parse$4, join } from 'node:path';
12
+ import { isAbsolute as isAbsolute$1, resolve, parse as parse$4, join } from 'node:path';
13
13
  import require$$0$4 from 'os';
14
14
  import require$$0$5 from 'events';
15
15
 
@@ -1486,6 +1486,12 @@ var sax = {};
1486
1486
  parser.ns = Object.create(rootNS);
1487
1487
  }
1488
1488
 
1489
+ // disallow unquoted attribute values if not otherwise configured
1490
+ // and strict mode is true
1491
+ if (parser.opt.unquotedAttributeValues === undefined) {
1492
+ parser.opt.unquotedAttributeValues = !strict;
1493
+ }
1494
+
1489
1495
  // mostly just for error reporting
1490
1496
  parser.trackPosition = parser.opt.position !== false;
1491
1497
  if (parser.trackPosition) {
@@ -2503,15 +2509,22 @@ var sax = {};
2503
2509
  continue
2504
2510
 
2505
2511
  case S.SGML_DECL:
2506
- if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
2512
+ if (parser.sgmlDecl + c === '--') {
2513
+ parser.state = S.COMMENT;
2514
+ parser.comment = '';
2515
+ parser.sgmlDecl = '';
2516
+ continue;
2517
+ }
2518
+
2519
+ if (parser.doctype && parser.doctype !== true && parser.sgmlDecl) {
2520
+ parser.state = S.DOCTYPE_DTD;
2521
+ parser.doctype += '<!' + parser.sgmlDecl + c;
2522
+ parser.sgmlDecl = '';
2523
+ } else if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {
2507
2524
  emitNode(parser, 'onopencdata');
2508
2525
  parser.state = S.CDATA;
2509
2526
  parser.sgmlDecl = '';
2510
2527
  parser.cdata = '';
2511
- } else if (parser.sgmlDecl + c === '--') {
2512
- parser.state = S.COMMENT;
2513
- parser.comment = '';
2514
- parser.sgmlDecl = '';
2515
2528
  } else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {
2516
2529
  parser.state = S.DOCTYPE;
2517
2530
  if (parser.doctype || parser.sawRoot) {
@@ -2565,12 +2578,18 @@ var sax = {};
2565
2578
  continue
2566
2579
 
2567
2580
  case S.DOCTYPE_DTD:
2568
- parser.doctype += c;
2569
2581
  if (c === ']') {
2582
+ parser.doctype += c;
2570
2583
  parser.state = S.DOCTYPE;
2584
+ } else if (c === '<') {
2585
+ parser.state = S.OPEN_WAKA;
2586
+ parser.startTagPosition = parser.position;
2571
2587
  } else if (isQuote(c)) {
2588
+ parser.doctype += c;
2572
2589
  parser.state = S.DOCTYPE_DTD_QUOTED;
2573
2590
  parser.q = c;
2591
+ } else {
2592
+ parser.doctype += c;
2574
2593
  }
2575
2594
  continue
2576
2595
 
@@ -2611,6 +2630,8 @@ var sax = {};
2611
2630
  // which is a comment of " blah -- bloo "
2612
2631
  parser.comment += '--' + c;
2613
2632
  parser.state = S.COMMENT;
2633
+ } else if (parser.doctype && parser.doctype !== true) {
2634
+ parser.state = S.DOCTYPE_DTD;
2614
2635
  } else {
2615
2636
  parser.state = S.TEXT;
2616
2637
  }
@@ -2778,7 +2799,9 @@ var sax = {};
2778
2799
  parser.q = c;
2779
2800
  parser.state = S.ATTRIB_VALUE_QUOTED;
2780
2801
  } else {
2781
- strictFail(parser, 'Unquoted attribute value');
2802
+ if (!parser.opt.unquotedAttributeValues) {
2803
+ error(parser, 'Unquoted attribute value');
2804
+ }
2782
2805
  parser.state = S.ATTRIB_VALUE_UNQUOTED;
2783
2806
  parser.attribValue = c;
2784
2807
  }
@@ -2896,13 +2919,13 @@ var sax = {};
2896
2919
  }
2897
2920
 
2898
2921
  if (c === ';') {
2899
- if (parser.opt.unparsedEntities) {
2900
- var parsedEntity = parseEntity(parser);
2922
+ var parsedEntity = parseEntity(parser);
2923
+ if (parser.opt.unparsedEntities && !Object.values(sax.XML_ENTITIES).includes(parsedEntity)) {
2901
2924
  parser.entity = '';
2902
2925
  parser.state = returnState;
2903
2926
  parser.write(parsedEntity);
2904
2927
  } else {
2905
- parser[buffer] += parseEntity(parser);
2928
+ parser[buffer] += parsedEntity;
2906
2929
  parser.entity = '';
2907
2930
  parser.state = returnState;
2908
2931
  }
@@ -3838,7 +3861,7 @@ var cjs = {exports: {}};
3838
3861
  exports.ParsingError = ParsingError;
3839
3862
  let parsingState;
3840
3863
  function nextChild() {
3841
- return element(false) || text() || comment() || cdata();
3864
+ return element(false) || text() || comment() || cdata() || processingInstruction(false);
3842
3865
  }
3843
3866
  function nextRootChild() {
3844
3867
  match(/\s*/);
@@ -3874,7 +3897,7 @@ var cjs = {exports: {}};
3874
3897
  };
3875
3898
  }
3876
3899
  function processingInstruction(matchDeclaration) {
3877
- const m = matchDeclaration ? match(/^<\?(xml)\s*/) : match(/^<\?([\w-:.]+)\s*/);
3900
+ const m = matchDeclaration ? match(/^<\?(xml(-stylesheet)?)\s*/) : match(/^<\?([\w-:.]+)\s*/);
3878
3901
  if (!m)
3879
3902
  return;
3880
3903
  // tag
@@ -3949,7 +3972,7 @@ var cjs = {exports: {}};
3949
3972
  }
3950
3973
  }
3951
3974
  else {
3952
- match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/);
3975
+ match(/^<\/[\w-:.\u00C0-\u00FF]+\s*>/);
3953
3976
  }
3954
3977
  return {
3955
3978
  excluded,
@@ -4151,7 +4174,7 @@ var cjsExports$1 = cjs.exports;
4151
4174
  const nodeChildren = node.children;
4152
4175
  appendContent(state, '>');
4153
4176
  state.level++;
4154
- let nodePreserveSpace = node.attributes['xml:space'] === 'preserve';
4177
+ let nodePreserveSpace = node.attributes['xml:space'] === 'preserve' || preserveSpace;
4155
4178
  let ignoredPath = false;
4156
4179
  if (!nodePreserveSpace && state.options.ignoredPaths) {
4157
4180
  ignoredPath = isPathMatchingIgnoredPaths(state.path, state.options.ignoredPaths);
@@ -4173,7 +4196,8 @@ var cjsExports$1 = cjs.exports;
4173
4196
  child.content = '';
4174
4197
  }
4175
4198
  }
4176
- if (child.content.trim().length > 0) {
4199
+ // If there is some content or whitespaces have been removed and there is no other siblings
4200
+ if (child.content.trim().length > 0 || nodeChildren.length === 1) {
4177
4201
  containsTextNodes = true;
4178
4202
  }
4179
4203
  }
@@ -8119,7 +8143,12 @@ const util = require$$0$3;
8119
8143
  const braces = braces_1;
8120
8144
  const picomatch = picomatch$1;
8121
8145
  const utils$b = utils$f;
8122
- const isEmptyString = val => val === '' || val === './';
8146
+
8147
+ const isEmptyString = v => v === '' || v === './';
8148
+ const hasBraces = v => {
8149
+ const index = v.indexOf('{');
8150
+ return index > -1 && v.indexOf('}', index) > -1;
8151
+ };
8123
8152
 
8124
8153
  /**
8125
8154
  * Returns an array of strings that match one or more glob patterns.
@@ -8560,7 +8589,7 @@ micromatch$1.parse = (patterns, options) => {
8560
8589
 
8561
8590
  micromatch$1.braces = (pattern, options) => {
8562
8591
  if (typeof pattern !== 'string') throw new TypeError('Expected a string');
8563
- if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
8592
+ if ((options && options.nobrace === true) || !hasBraces(pattern)) {
8564
8593
  return [pattern];
8565
8594
  }
8566
8595
  return braces(pattern, options);
@@ -8579,10 +8608,12 @@ micromatch$1.braceExpand = (pattern, options) => {
8579
8608
  * Expose micromatch
8580
8609
  */
8581
8610
 
8611
+ // exposed for tests
8612
+ micromatch$1.hasBraces = hasBraces;
8582
8613
  var micromatch_1 = micromatch$1;
8583
8614
 
8584
8615
  Object.defineProperty(pattern$1, "__esModule", { value: true });
8585
- pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
8616
+ pattern$1.isAbsolute = pattern$1.partitionAbsoluteAndRelative = pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
8586
8617
  const path$5 = require$$0$2;
8587
8618
  const globParent = globParent$1;
8588
8619
  const micromatch = micromatch_1;
@@ -8768,6 +8799,24 @@ function removeDuplicateSlashes(pattern) {
8768
8799
  return pattern.replace(DOUBLE_SLASH_RE, '/');
8769
8800
  }
8770
8801
  pattern$1.removeDuplicateSlashes = removeDuplicateSlashes;
8802
+ function partitionAbsoluteAndRelative(patterns) {
8803
+ const absolute = [];
8804
+ const relative = [];
8805
+ for (const pattern of patterns) {
8806
+ if (isAbsolute(pattern)) {
8807
+ absolute.push(pattern);
8808
+ }
8809
+ else {
8810
+ relative.push(pattern);
8811
+ }
8812
+ }
8813
+ return [absolute, relative];
8814
+ }
8815
+ pattern$1.partitionAbsoluteAndRelative = partitionAbsoluteAndRelative;
8816
+ function isAbsolute(pattern) {
8817
+ return path$5.isAbsolute(pattern);
8818
+ }
8819
+ pattern$1.isAbsolute = isAbsolute;
8771
8820
 
8772
8821
  var stream$4 = {};
8773
8822
 
@@ -9899,19 +9948,19 @@ function queueAsPromised (context, worker, _concurrency) {
9899
9948
  }
9900
9949
 
9901
9950
  function drained () {
9902
- if (queue.idle()) {
9903
- return new Promise(function (resolve) {
9904
- resolve();
9905
- })
9906
- }
9907
-
9908
- var previousDrain = queue.drain;
9909
-
9910
9951
  var p = new Promise(function (resolve) {
9911
- queue.drain = function () {
9912
- previousDrain();
9913
- resolve();
9914
- };
9952
+ process.nextTick(function () {
9953
+ if (queue.idle()) {
9954
+ resolve();
9955
+ } else {
9956
+ var previousDrain = queue.drain;
9957
+ queue.drain = function () {
9958
+ if (typeof previousDrain === 'function') previousDrain();
9959
+ resolve();
9960
+ queue.drain = previousDrain;
9961
+ };
9962
+ }
9963
+ });
9915
9964
  });
9916
9965
 
9917
9966
  return p
@@ -10562,11 +10611,19 @@ class EntryFilter {
10562
10611
  this.index = new Map();
10563
10612
  }
10564
10613
  getFilter(positive, negative) {
10565
- const positiveRe = utils$3.pattern.convertPatternsToRe(positive, this._micromatchOptions);
10566
- const negativeRe = utils$3.pattern.convertPatternsToRe(negative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true }));
10567
- return (entry) => this._filter(entry, positiveRe, negativeRe);
10614
+ const [absoluteNegative, relativeNegative] = utils$3.pattern.partitionAbsoluteAndRelative(negative);
10615
+ const patterns = {
10616
+ positive: {
10617
+ all: utils$3.pattern.convertPatternsToRe(positive, this._micromatchOptions)
10618
+ },
10619
+ negative: {
10620
+ absolute: utils$3.pattern.convertPatternsToRe(absoluteNegative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true })),
10621
+ relative: utils$3.pattern.convertPatternsToRe(relativeNegative, Object.assign(Object.assign({}, this._micromatchOptions), { dot: true }))
10622
+ }
10623
+ };
10624
+ return (entry) => this._filter(entry, patterns);
10568
10625
  }
10569
- _filter(entry, positiveRe, negativeRe) {
10626
+ _filter(entry, patterns) {
10570
10627
  const filepath = utils$3.path.removeLeadingDotSegment(entry.path);
10571
10628
  if (this._settings.unique && this._isDuplicateEntry(filepath)) {
10572
10629
  return false;
@@ -10574,11 +10631,7 @@ class EntryFilter {
10574
10631
  if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
10575
10632
  return false;
10576
10633
  }
10577
- if (this._isSkippedByAbsoluteNegativePatterns(filepath, negativeRe)) {
10578
- return false;
10579
- }
10580
- const isDirectory = entry.dirent.isDirectory();
10581
- const isMatched = this._isMatchToPatterns(filepath, positiveRe, isDirectory) && !this._isMatchToPatterns(filepath, negativeRe, isDirectory);
10634
+ const isMatched = this._isMatchToPatternsSet(filepath, patterns, entry.dirent.isDirectory());
10582
10635
  if (this._settings.unique && isMatched) {
10583
10636
  this._createIndexRecord(filepath);
10584
10637
  }
@@ -10596,14 +10649,32 @@ class EntryFilter {
10596
10649
  _onlyDirectoryFilter(entry) {
10597
10650
  return this._settings.onlyDirectories && !entry.dirent.isDirectory();
10598
10651
  }
10599
- _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
10600
- if (!this._settings.absolute) {
10652
+ _isMatchToPatternsSet(filepath, patterns, isDirectory) {
10653
+ const isMatched = this._isMatchToPatterns(filepath, patterns.positive.all, isDirectory);
10654
+ if (!isMatched) {
10655
+ return false;
10656
+ }
10657
+ const isMatchedByRelativeNegative = this._isMatchToPatterns(filepath, patterns.negative.relative, isDirectory);
10658
+ if (isMatchedByRelativeNegative) {
10659
+ return false;
10660
+ }
10661
+ const isMatchedByAbsoluteNegative = this._isMatchToAbsoluteNegative(filepath, patterns.negative.absolute, isDirectory);
10662
+ if (isMatchedByAbsoluteNegative) {
10663
+ return false;
10664
+ }
10665
+ return true;
10666
+ }
10667
+ _isMatchToAbsoluteNegative(filepath, patternsRe, isDirectory) {
10668
+ if (patternsRe.length === 0) {
10601
10669
  return false;
10602
10670
  }
10603
- const fullpath = utils$3.path.makeAbsolute(this._settings.cwd, entryPath);
10604
- return utils$3.pattern.matchAny(fullpath, patternsRe);
10671
+ const fullpath = utils$3.path.makeAbsolute(this._settings.cwd, filepath);
10672
+ return this._isMatchToPatterns(fullpath, patternsRe, isDirectory);
10605
10673
  }
10606
10674
  _isMatchToPatterns(filepath, patternsRe, isDirectory) {
10675
+ if (patternsRe.length === 0) {
10676
+ return false;
10677
+ }
10607
10678
  // Trying to match files and directories by patterns.
10608
10679
  const isMatched = utils$3.pattern.matchAny(filepath, patternsRe);
10609
10680
  // A pattern with a trailling slash can be used for directory matching.
@@ -11027,7 +11098,7 @@ function resolveOptions(userOptions) {
11027
11098
  }
11028
11099
 
11029
11100
  function getResolvedPath(file, resolvedOptions) {
11030
- if (isAbsolute(resolvedOptions.outDir))
11101
+ if (isAbsolute$1(resolvedOptions.outDir))
11031
11102
  return resolve(`${resolvedOptions.outDir}/${file}`);
11032
11103
  return resolve(`${ensurePrefix("./", resolvedOptions.outDir)}/${file}`);
11033
11104
  }
@@ -11131,7 +11202,9 @@ function generateSitemap(options = {}) {
11131
11202
  if (!routes.length)
11132
11203
  return;
11133
11204
  const formattedSitemap = getFormattedSitemap(resolvedOptions, routes);
11134
- const stream = new dist.SitemapStream();
11205
+ const stream = new dist.SitemapStream({
11206
+ xmlns: resolvedOptions.xmlns
11207
+ });
11135
11208
  formattedSitemap.forEach((item) => stream.write(item));
11136
11209
  dist.streamToPromise(stream).then((sitemap) => {
11137
11210
  const utfSitemap = sitemap.toString("utf-8");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-sitemap",
3
3
  "type": "module",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "packageManager": "pnpm@9.1.2",
6
6
  "description": "Sitemap generator plugin for Vite",
7
7
  "main": "dist/index.js",