@rohal12/twee-ts 1.15.3 → 1.16.0

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.
@@ -1,5 +1,6 @@
1
- import { basename, dirname, extname, join, parse, relative, resolve } from "node:path";
2
1
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
2
+ import * as nodePath from "node:path";
3
+ import { basename, dirname, extname, join, parse, relative, resolve } from "node:path";
3
4
  import { randomUUID } from "node:crypto";
4
5
  import { homedir } from "node:os";
5
6
  import { fileURLToPath } from "node:url";
@@ -557,11 +558,25 @@ function fontFormatHint(ext) {
557
558
  * Ported from filesystem.go.
558
559
  */
559
560
  /**
561
+ * Whether `filename` matches one of the `exclude` globs. The globs are matched
562
+ * against the file's path relative to the working directory, the path
563
+ * getFilenames reports; an absolute `filename` is made relative first. A leading
564
+ * `./` in a glob is dropped. Matching is Node's `path.matchesGlob`.
565
+ */
566
+ function isExcluded(filename, exclude) {
567
+ if (exclude.length === 0) return false;
568
+ const { matchesGlob } = nodePath;
569
+ if (typeof matchesGlob !== "function") throw new Error(`The exclude option needs Node.js 22.5 or newer (found ${process.version}).`);
570
+ const rel = relative(process.cwd(), resolve(filename)) || filename;
571
+ return exclude.some((pattern) => matchesGlob(rel, pattern.replace(/^\.\//, "")));
572
+ }
573
+ /**
560
574
  * Recursively walk directories, collecting regular file paths.
561
- * Filters out the output file to prevent circular compilation.
575
+ * Filters out the output file to prevent circular compilation, and the files
576
+ * that match an `exclude` glob (see isExcluded).
562
577
  * Like Tweego, a path that cannot be read is reported as a warning and skipped.
563
578
  */
564
- function getFilenames(pathnames, outFilename) {
579
+ function getFilenames(pathnames, outFilename, exclude = []) {
565
580
  const filenames = [];
566
581
  const diagnostics = [];
567
582
  const absOutFile = outFilename ? resolve(outFilename) : "";
@@ -583,6 +598,7 @@ function getFilenames(pathnames, outFilename) {
583
598
  const abs = resolve(pathname);
584
599
  if (abs === absOutFile) return;
585
600
  const rel = relative(process.cwd(), abs);
601
+ if (isExcluded(rel || abs, exclude)) return;
586
602
  filenames.push(rel || abs);
587
603
  } else if (stat.isDirectory()) {
588
604
  let entries;
@@ -4915,7 +4931,7 @@ async function buildOutput(options, cache, changedFiles) {
4915
4931
  const inlineSources = [];
4916
4932
  for (const source of options.sources) if (typeof source === "string") filePaths.push(source);
4917
4933
  else inlineSources.push(source);
4918
- const { filenames: sourceFilenames, diagnostics: sourcePathDiagnostics } = getFilenames(filePaths);
4934
+ const { filenames: sourceFilenames, diagnostics: sourcePathDiagnostics } = getFilenames(filePaths, void 0, options.exclude);
4919
4935
  diagnostics.push(...sourcePathDiagnostics);
4920
4936
  const story = createStory();
4921
4937
  const processedFiles = /* @__PURE__ */ new Set();
@@ -5069,6 +5085,6 @@ function storyToJSON(story) {
5069
5085
  return JSON.stringify(obj, null, 2);
5070
5086
  }
5071
5087
  //#endregion
5072
- export { mediaTypeFromFilename as i, compile as n, compileIncremental as r, TweeTsError as t };
5088
+ export { isExcluded as a, getFilenames as i, compile as n, mediaTypeFromFilename as o, compileIncremental as r, TweeTsError as t };
5073
5089
 
5074
- //# sourceMappingURL=compiler-Bfi1w-to.js.map
5090
+ //# sourceMappingURL=compiler-BiDNwR9q.js.map