@let-value/translate-extract 1.1.5-beta.3 → 1.1.6-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/bin/cli.cjs +40 -28
  2. package/dist/bin/{cli.js → cli.mjs} +39 -23
  3. package/dist/bin/cli.mjs.map +1 -0
  4. package/dist/{configuration-CTy0NMkD.d.cts → configuration-BVNh7M_I.d.cts} +33 -12
  5. package/dist/configuration-BVNh7M_I.d.cts.map +1 -0
  6. package/dist/{configuration-fs9HmV_j.d.ts → configuration-oHJyypq5.d.mts} +34 -12
  7. package/dist/configuration-oHJyypq5.d.mts.map +1 -0
  8. package/dist/exclude-CpTGSisK.mjs +21 -0
  9. package/dist/exclude-CpTGSisK.mjs.map +1 -0
  10. package/dist/exclude-CzNSDMG-.cjs +36 -0
  11. package/dist/{run-BosrCYRL.js → run-Bv3fv1N8.mjs} +227 -214
  12. package/dist/run-Bv3fv1N8.mjs.map +1 -0
  13. package/dist/{run-BZ-O4Oh0.cjs → run-oGs6tkeL.cjs} +291 -255
  14. package/dist/src/core.cjs +55 -4
  15. package/dist/src/core.d.cts +2 -3
  16. package/dist/src/core.d.mts +2 -0
  17. package/dist/{core-DR3oxhSq.js → src/core.mjs} +12 -15
  18. package/dist/src/core.mjs.map +1 -0
  19. package/dist/src/index.cjs +5 -6
  20. package/dist/src/index.d.cts +2 -4
  21. package/dist/src/index.d.cts.map +1 -1
  22. package/dist/src/index.d.mts +22 -0
  23. package/dist/src/index.d.mts.map +1 -0
  24. package/dist/src/index.mjs +3 -0
  25. package/dist/src/static.cjs +31 -6
  26. package/dist/src/static.d.cts +1 -1
  27. package/dist/src/static.d.mts +2 -0
  28. package/dist/{static-DQHT7uqP.js → src/static.mjs} +2 -2
  29. package/dist/src/static.mjs.map +1 -0
  30. package/package.json +62 -61
  31. package/dist/bin/cli.js.map +0 -1
  32. package/dist/chunk-CUT6urMc.cjs +0 -30
  33. package/dist/configuration-CTy0NMkD.d.cts.map +0 -1
  34. package/dist/configuration-fs9HmV_j.d.ts.map +0 -1
  35. package/dist/core-ACuLoi2B.d.ts +0 -1
  36. package/dist/core-CHb_Xdzl.cjs +0 -65
  37. package/dist/core-CPg6_re5.d.cts +0 -1
  38. package/dist/core-DR3oxhSq.js.map +0 -1
  39. package/dist/run-BosrCYRL.js.map +0 -1
  40. package/dist/src/core.d.ts +0 -3
  41. package/dist/src/core.js +0 -4
  42. package/dist/src/index.d.ts +0 -24
  43. package/dist/src/index.d.ts.map +0 -1
  44. package/dist/src/index.js +0 -5
  45. package/dist/src/static.d.ts +0 -2
  46. package/dist/src/static.js +0 -3
  47. package/dist/static-CNiWpXhx.cjs +0 -52
  48. package/dist/static-DQHT7uqP.js.map +0 -1
  49. /package/dist/bin/{cli.d.ts → cli.d.mts} +0 -0
@@ -1,43 +1,46 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- let node_util = require("node:util");
3
- node_util = require_chunk.__toESM(node_util);
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ const require_exclude = require("./exclude-CzNSDMG-.cjs");
4
24
  let node_path = require("node:path");
5
- node_path = require_chunk.__toESM(node_path);
6
- let fast_glob = require("fast-glob");
7
- fast_glob = require_chunk.__toESM(fast_glob);
25
+ node_path = __toESM(node_path, 1);
8
26
  let node_fs_promises = require("node:fs/promises");
9
- node_fs_promises = require_chunk.__toESM(node_fs_promises);
27
+ node_fs_promises = __toESM(node_fs_promises, 1);
10
28
  let gettext_parser = require("gettext-parser");
11
- gettext_parser = require_chunk.__toESM(gettext_parser);
29
+ gettext_parser = __toESM(gettext_parser, 1);
12
30
  let node_fs = require("node:fs");
13
- node_fs = require_chunk.__toESM(node_fs);
14
- let __keqingmoe_tree_sitter = require("@keqingmoe/tree-sitter");
15
- __keqingmoe_tree_sitter = require_chunk.__toESM(__keqingmoe_tree_sitter);
31
+ node_fs = __toESM(node_fs, 1);
32
+ let _keqingmoe_tree_sitter = require("@keqingmoe/tree-sitter");
33
+ _keqingmoe_tree_sitter = __toESM(_keqingmoe_tree_sitter, 1);
16
34
  let tree_sitter_javascript = require("tree-sitter-javascript");
17
- tree_sitter_javascript = require_chunk.__toESM(tree_sitter_javascript);
35
+ tree_sitter_javascript = __toESM(tree_sitter_javascript, 1);
18
36
  let tree_sitter_typescript = require("tree-sitter-typescript");
19
- tree_sitter_typescript = require_chunk.__toESM(tree_sitter_typescript);
37
+ tree_sitter_typescript = __toESM(tree_sitter_typescript, 1);
38
+ let node_module = require("node:module");
20
39
  let oxc_resolver = require("oxc-resolver");
21
- oxc_resolver = require_chunk.__toESM(oxc_resolver);
22
40
  let plural_forms = require("plural-forms");
23
- plural_forms = require_chunk.__toESM(plural_forms);
24
-
25
- //#region src/defer.ts
26
- var Defer = class {
27
- pending = 0;
28
- promise = Promise.resolve();
29
- resolve;
30
- enqueue() {
31
- if (this.pending++ === 0) this.promise = new Promise((res) => {
32
- this.resolve = res;
33
- });
34
- }
35
- dequeue() {
36
- if (this.pending > 0 && --this.pending === 0) this.resolve?.();
37
- }
38
- };
39
-
40
- //#endregion
41
+ let node_util = require("node:util");
42
+ let fast_glob = require("fast-glob");
43
+ fast_glob = __toESM(fast_glob, 1);
41
44
  //#region src/plugins/cleanup/cleanup.ts
42
45
  const namespace$2 = "cleanup";
43
46
  function cleanup() {
@@ -52,9 +55,9 @@ function cleanup() {
52
55
  build.onResolve({
53
56
  namespace: namespace$2,
54
57
  filter: /.*/
55
- }, ({ path: path$1 }) => {
56
- generated.add(path$1);
57
- dirs.add((0, node_path.dirname)(path$1));
58
+ }, ({ path }) => {
59
+ generated.add(path);
60
+ dirs.add((0, node_path.dirname)(path));
58
61
  Promise.all([
59
62
  build.defer("source"),
60
63
  build.defer("translate"),
@@ -62,9 +65,9 @@ function cleanup() {
62
65
  ]).then(() => {
63
66
  if (dispatched) return;
64
67
  dispatched = true;
65
- for (const path$2 of dirs.values()) build.process({
66
- entrypoint: path$2,
67
- path: path$2,
68
+ for (const path of dirs.values()) build.process({
69
+ entrypoint: path,
70
+ path,
68
71
  namespace: namespace$2,
69
72
  data: void 0
70
73
  });
@@ -73,12 +76,12 @@ function cleanup() {
73
76
  build.onProcess({
74
77
  namespace: namespace$2,
75
78
  filter: /.*/
76
- }, async ({ path: path$1 }) => {
77
- if (processed.has(path$1)) return;
78
- processed.add(path$1);
79
- const files = await node_fs_promises.default.readdir(path$1).catch(() => []);
79
+ }, async ({ path }) => {
80
+ if (processed.has(path)) return;
81
+ processed.add(path);
82
+ const files = await node_fs_promises.default.readdir(path).catch(() => []);
80
83
  for (const f of files.filter((p) => p.endsWith(".po"))) {
81
- const full = (0, node_path.join)(path$1, f);
84
+ const full = (0, node_path.join)(path, f);
82
85
  const contents = await node_fs_promises.default.readFile(full).catch(() => void 0);
83
86
  if (!contents) continue;
84
87
  const parsed = gettext_parser.po.parse(contents);
@@ -90,12 +93,11 @@ function cleanup() {
90
93
  }
91
94
  };
92
95
  }
93
-
94
96
  //#endregion
95
97
  //#region src/plugins/core/queries/comment.ts
96
- function getReference(node, { path: path$1 }) {
98
+ function getReference(node, { path }) {
97
99
  const line = node.startPosition.row + 1;
98
- return `${(0, node_path.relative)(process.cwd(), path$1).replace(/\\+/g, "/")}:${line}`;
100
+ return `${(0, node_path.relative)(process.cwd(), path).replace(/\\+/g, "/")}:${line}`;
99
101
  }
100
102
  function getComment(node) {
101
103
  const text = node.text;
@@ -120,7 +122,6 @@ const withComment = (query) => ({
120
122
  return result;
121
123
  }
122
124
  });
123
-
124
125
  //#endregion
125
126
  //#region src/plugins/core/queries/entrypoint.ts
126
127
  const entrypointCommentPattern = /(?:^|\s)@?translate-entrypoint(?:\s|$)/;
@@ -130,9 +131,20 @@ const entrypointQuery = {
130
131
  return match.captures.filter((capture) => capture.name === "comment").some((capture) => entrypointCommentPattern.test(getComment(capture.node)));
131
132
  }
132
133
  };
133
-
134
134
  //#endregion
135
135
  //#region src/plugins/core/queries/import.ts
136
+ function findImportParent(node) {
137
+ let current = node;
138
+ while (current) {
139
+ if (current.type === "import_statement" || current.type === "export_statement" || current.type === "call_expression") return current;
140
+ current = current.parent;
141
+ }
142
+ }
143
+ function isTypeOnly(parent) {
144
+ if (!parent) return false;
145
+ const text = parent.text.trimStart();
146
+ return /^import\s+type\b/.test(text) || /^export\s+type\b/.test(text) || /^export\s*{\s*type\b[^}]*}\s*from\b/.test(text);
147
+ }
136
148
  const importQuery = {
137
149
  pattern: `
138
150
  [
@@ -152,15 +164,21 @@ const importQuery = {
152
164
  (#eq? @obj "require")
153
165
  (#eq? @method "resolve"))
154
166
  (call_expression
155
- function: (import)
167
+ function: (import) @dynamic
156
168
  arguments: (arguments (string (string_fragment) @import)))
157
169
  ]
158
170
  `,
159
171
  extract(match) {
160
- return (match.captures.find((c) => c.name === "import")?.node)?.text;
172
+ const node = match.captures.find((c) => c.name === "import")?.node;
173
+ if (!node) return;
174
+ const parent = findImportParent(node);
175
+ return {
176
+ spec: node.text,
177
+ kind: match.captures.some((c) => c.name === "dynamic") ? "dynamic" : "static",
178
+ typeOnly: isTypeOnly(parent)
179
+ };
161
180
  }
162
181
  };
163
-
164
182
  //#endregion
165
183
  //#region src/plugins/core/queries/utils.ts
166
184
  const callPattern = (fnName, args, allowMember = true) => `(
@@ -181,7 +199,6 @@ function isDescendant(node, ancestor) {
181
199
  }
182
200
  return false;
183
201
  }
184
-
185
202
  //#endregion
186
203
  //#region src/plugins/core/queries/message.ts
187
204
  const notInPlural = (query) => ({
@@ -289,7 +306,6 @@ const messageInvalidQuery = notInPlural({
289
306
  };
290
307
  }
291
308
  });
292
-
293
309
  //#endregion
294
310
  //#region src/plugins/core/queries/plural-utils.ts
295
311
  const extractPluralForms = (name) => (match) => {
@@ -337,7 +353,6 @@ const extractPluralForms = (name) => (match) => {
337
353
  translation
338
354
  };
339
355
  };
340
-
341
356
  //#endregion
342
357
  //#region src/plugins/core/queries/context.ts
343
358
  const ctxCall = callPattern("context", `[
@@ -377,7 +392,6 @@ const contextMsgQuery = withComment({
377
392
  };
378
393
  }
379
394
  });
380
- const msgCall$3 = callPattern("message", messageArgs, false).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn");
381
395
  const contextPluralQuery = withComment({
382
396
  pattern: `(
383
397
  (call_expression
@@ -386,7 +400,7 @@ const contextPluralQuery = withComment({
386
400
  property: (property_identifier) @func
387
401
  )
388
402
  arguments: (arguments (
389
- (${msgCall$3} ("," )?)+
403
+ (${callPattern("message", messageArgs, false).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn")} ("," )?)+
390
404
  (number) @n
391
405
  ))
392
406
  ) @call
@@ -411,7 +425,6 @@ const contextInvalidQuery = withComment({
411
425
  };
412
426
  }
413
427
  });
414
-
415
428
  //#endregion
416
429
  //#region src/plugins/core/queries/gettext.ts
417
430
  const gettextQuery = withComment({
@@ -438,27 +451,20 @@ const gettextInvalidQuery = {
438
451
  };
439
452
  }
440
453
  };
441
-
442
454
  //#endregion
443
455
  //#region src/plugins/core/queries/ngettext.ts
444
- const msgCall$2 = callPattern("message", messageArgs).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn");
445
- const plainMsg$1 = `(${messageArg}) @msg`;
446
- const msgArg$1 = `[${msgCall$2} ${plainMsg$1}]`;
456
+ const msgArg$1 = `[${callPattern("message", messageArgs).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn")} ${`(${messageArg}) @msg`}]`;
447
457
  const ngettextQuery = withComment({
448
458
  pattern: callPattern("ngettext", `(arguments ${msgArg$1} "," ${msgArg$1} ("," ${msgArg$1})* "," (_) @n)`),
449
459
  extract: extractPluralForms("ngettext")
450
460
  });
451
-
452
461
  //#endregion
453
462
  //#region src/plugins/core/queries/npgettext.ts
454
- const msgCall$1 = callPattern("message", messageArgs).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn");
455
- const plainMsg = `(${messageArg}) @msg`;
456
- const msgArg = `[${msgCall$1} ${plainMsg}]`;
463
+ const msgArg = `[${callPattern("message", messageArgs).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn")} ${`(${messageArg}) @msg`}]`;
457
464
  const npgettextQuery = withComment({
458
465
  pattern: callPattern("npgettext", `(arguments (string (string_fragment) @msgctxt) "," ${msgArg} "," ${msgArg} ("," ${msgArg})* "," (_) @n)`),
459
466
  extract: extractPluralForms("npgettext")
460
467
  });
461
-
462
468
  //#endregion
463
469
  //#region src/plugins/core/queries/pgettext.ts
464
470
  const pgettextQuery = withComment({
@@ -476,18 +482,6 @@ const pgettextQuery = withComment({
476
482
  };
477
483
  }
478
484
  });
479
-
480
- //#endregion
481
- //#region src/plugins/core/queries/plural.ts
482
- const msgCall = callPattern("message", messageArgs, false).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn");
483
- const pluralQuery$1 = withComment({
484
- pattern: callPattern("plural", `(arguments (
485
- (${msgCall} ("," )?)+
486
- (number) @n
487
- ))`, false),
488
- extract: extractPluralForms("plural")
489
- });
490
-
491
485
  //#endregion
492
486
  //#region src/plugins/core/queries/index.ts
493
487
  const queries$1 = [
@@ -498,12 +492,17 @@ const queries$1 = [
498
492
  messageInvalidQuery,
499
493
  gettextQuery,
500
494
  gettextInvalidQuery,
501
- pluralQuery$1,
495
+ withComment({
496
+ pattern: callPattern("plural", `(arguments (
497
+ (${callPattern("message", messageArgs, false).replace(/@call/g, "@msg").replace(/@func/g, "@msgfn")} ("," )?)+
498
+ (number) @n
499
+ ))`, false),
500
+ extract: extractPluralForms("plural")
501
+ }),
502
502
  ngettextQuery,
503
503
  pgettextQuery,
504
504
  npgettextQuery
505
505
  ];
506
-
507
506
  //#endregion
508
507
  //#region src/plugins/core/parse.ts
509
508
  function getLanguage(ext) {
@@ -518,7 +517,7 @@ const queryCache = /* @__PURE__ */ new WeakMap();
518
517
  function getCachedParser(ext) {
519
518
  let cached = parserCache.get(ext);
520
519
  if (!cached) {
521
- const parser = new __keqingmoe_tree_sitter.default();
520
+ const parser = new _keqingmoe_tree_sitter.default();
522
521
  const language = getLanguage(ext);
523
522
  parser.setLanguage(language);
524
523
  cached = {
@@ -537,21 +536,20 @@ function getCachedQuery(language, pattern) {
537
536
  }
538
537
  let query = cache.get(pattern);
539
538
  if (!query) {
540
- query = new __keqingmoe_tree_sitter.default.Query(language, pattern);
539
+ query = new _keqingmoe_tree_sitter.default.Query(language, pattern);
541
540
  cache.set(pattern, query);
542
541
  }
543
542
  return query;
544
543
  }
545
- function getParser(path$1) {
546
- const ext = (0, node_path.extname)(path$1);
547
- return getCachedParser(ext);
544
+ function getParser(path) {
545
+ return getCachedParser((0, node_path.extname)(path));
548
546
  }
549
547
  function getQuery(language, pattern) {
550
548
  return getCachedQuery(language, pattern);
551
549
  }
552
- function parseSource$1(source, path$1) {
553
- const context = { path: path$1 };
554
- const { parser, language } = getParser(path$1);
550
+ function parseSource$1(source, path) {
551
+ const context = { path };
552
+ const { parser, language } = getParser(path);
555
553
  const tree = parser.parse(source);
556
554
  const entrypoint = getCachedQuery(language, entrypointQuery.pattern).matches(tree.rootNode).some(entrypointQuery.extract);
557
555
  const translations = [];
@@ -592,7 +590,6 @@ function parseSource$1(source, path$1) {
592
590
  entrypoint
593
591
  };
594
592
  }
595
-
596
593
  //#endregion
597
594
  //#region src/plugins/core/resolve.ts
598
595
  function findTsconfig(dir) {
@@ -606,6 +603,12 @@ function findTsconfig(dir) {
606
603
  }
607
604
  }
608
605
  const resolverCache = /* @__PURE__ */ new Map();
606
+ const builtins = new Set([...node_module.builtinModules, ...node_module.builtinModules.map((name) => `node:${name}`)]);
607
+ function isBuiltin(spec) {
608
+ if (builtins.has(spec)) return true;
609
+ const [base, subpath] = (spec.startsWith("node:") ? spec.slice(5) : spec).split("/", 2);
610
+ return subpath !== void 0 && builtins.has(base);
611
+ }
609
612
  function getResolver(dir) {
610
613
  const tsconfig = findTsconfig(dir);
611
614
  const key = tsconfig ?? "__default__";
@@ -632,30 +635,48 @@ function getResolver(dir) {
632
635
  }
633
636
  return resolver;
634
637
  }
638
+ function normalizeImportReference(imp) {
639
+ if (typeof imp === "string") return {
640
+ spec: imp,
641
+ kind: "static",
642
+ typeOnly: false
643
+ };
644
+ return imp;
645
+ }
635
646
  function resolveImportResults(file, imports) {
636
647
  const dir = node_path.default.dirname(node_path.default.resolve(file));
637
648
  const resolver = getResolver(dir);
638
649
  const resolved = [];
639
650
  const unresolved = [];
640
- for (const spec of imports) try {
641
- const res = resolver.sync(dir, spec);
642
- if (res.path) resolved.push(res.path);
643
- else unresolved.push({
644
- spec,
645
- error: res.error
646
- });
647
- } catch (error) {
648
- unresolved.push({
649
- spec,
650
- error: error instanceof Error ? error.message : String(error)
651
- });
651
+ for (const imp of imports) {
652
+ const ref = normalizeImportReference(imp);
653
+ const { spec } = ref;
654
+ if (isBuiltin(spec)) continue;
655
+ try {
656
+ const res = resolver.sync(dir, spec);
657
+ if (res.path) resolved.push({
658
+ path: res.path,
659
+ import: {
660
+ ...ref,
661
+ spec: res.path
662
+ }
663
+ });
664
+ else unresolved.push({
665
+ spec,
666
+ error: res.error
667
+ });
668
+ } catch (error) {
669
+ unresolved.push({
670
+ spec,
671
+ error: error instanceof Error ? error.message : String(error)
672
+ });
673
+ }
652
674
  }
653
675
  return {
654
676
  resolved,
655
677
  unresolved
656
678
  };
657
679
  }
658
-
659
680
  //#endregion
660
681
  //#region src/plugins/core/core.ts
661
682
  const filter$1 = /\.([cm]?tsx?|jsx?)$/;
@@ -668,56 +689,67 @@ function core() {
668
689
  build.onResolve({
669
690
  filter: filter$1,
670
691
  namespace: namespace$1
671
- }, ({ entrypoint, path: path$1 }) => {
692
+ }, ({ entrypoint, path, import: imp, data }) => {
672
693
  return {
673
694
  entrypoint,
674
695
  namespace: namespace$1,
675
- path: (0, node_path.resolve)(path$1)
696
+ path: (0, node_path.resolve)(path),
697
+ import: imp,
698
+ data
676
699
  };
677
700
  });
678
701
  build.onLoad({
679
702
  filter: filter$1,
680
703
  namespace: namespace$1
681
- }, async ({ entrypoint, path: path$1 }) => {
682
- const data = await (0, node_fs_promises.readFile)(path$1, "utf8");
704
+ }, async ({ entrypoint, path }) => {
683
705
  return {
684
706
  entrypoint,
685
- path: path$1,
707
+ path,
686
708
  namespace: namespace$1,
687
- data
709
+ data: await (0, node_fs_promises.readFile)(path, "utf8")
688
710
  };
689
711
  });
690
712
  build.onProcess({
691
713
  filter: filter$1,
692
714
  namespace: namespace$1
693
- }, ({ entrypoint, path: path$1, data }) => {
694
- const result = parseSource$1(data, path$1);
695
- if (result.entrypoint && entrypoint !== path$1) {
696
- build.source(path$1);
715
+ }, ({ entrypoint, path, data }) => {
716
+ const result = parseSource$1(data, path);
717
+ if (result.entrypoint && entrypoint !== path) {
718
+ build.source(path);
697
719
  return {
698
720
  entrypoint,
699
- path: path$1,
721
+ path,
700
722
  namespace: namespace$1,
701
723
  data: []
702
724
  };
703
725
  }
704
726
  const { translations, imports, warnings } = result;
705
727
  if (build.context.config.walk) {
706
- const { resolved: paths, unresolved } = resolveImportResults(path$1, imports);
707
- for (const path$2 of paths) {
708
- if (build.context.paths.has(path$2)) continue;
728
+ const { resolved, unresolved } = resolveImportResults(path, imports);
729
+ for (const result of resolved) {
730
+ if (build.context.paths.has(result.path)) continue;
709
731
  build.resolve({
710
732
  entrypoint,
711
- path: path$2,
712
- namespace: namespace$1
733
+ path: result.path,
734
+ namespace: namespace$1,
735
+ import: result.import
713
736
  });
714
737
  }
715
- for (const { spec, error } of unresolved) build.context.logger?.warn(`Unable to resolve import "${spec}" from ${path$1}${error ? `: ${error}` : ""}`);
738
+ for (const { spec, error } of unresolved) {
739
+ const imp = imports.find((imp) => imp.spec === spec);
740
+ if (imp && require_exclude.isExcluded({
741
+ entrypoint,
742
+ path: spec,
743
+ namespace: namespace$1,
744
+ import: imp
745
+ }, build.context.config.exclude)) continue;
746
+ build.context.logger?.warn(`Unable to resolve import "${spec}" from ${path}${error ? `: ${error}` : ""}`);
747
+ }
716
748
  }
717
749
  for (const warning of warnings) build.context.logger?.warn(`${warning.error} at ${warning.reference}`);
718
750
  build.resolve({
719
751
  entrypoint,
720
- path: path$1,
752
+ path,
721
753
  namespace: "translate",
722
754
  data: translations
723
755
  });
@@ -725,7 +757,6 @@ function core() {
725
757
  }
726
758
  };
727
759
  }
728
-
729
760
  //#endregion
730
761
  //#region src/plugins/po/collect.ts
731
762
  function collect(source, locale) {
@@ -760,7 +791,6 @@ function collect(source, locale) {
760
791
  }
761
792
  return translations;
762
793
  }
763
-
764
794
  //#endregion
765
795
  //#region src/plugins/po/hasChanges.ts
766
796
  const IGNORED_HEADER_KEYS = new Set(["pot-creation-date", "po-revision-date"]);
@@ -774,9 +804,7 @@ function normalizeHeaderString(value) {
774
804
  }).map((line) => {
775
805
  const separatorIndex = line.indexOf(":");
776
806
  if (separatorIndex === -1) return line;
777
- const key = line.slice(0, separatorIndex).trim().toLowerCase();
778
- const value$1 = line.slice(separatorIndex + 1);
779
- return `${key}:${value$1}`;
807
+ return `${line.slice(0, separatorIndex).trim().toLowerCase()}:${line.slice(separatorIndex + 1)}`;
780
808
  });
781
809
  if (hadTrailingNewline && filtered[filtered.length - 1] !== "") filtered.push("");
782
810
  return filtered.join("\n");
@@ -795,11 +823,8 @@ function normalize(translations) {
795
823
  }
796
824
  function hasChanges(left, right) {
797
825
  if (!right) return true;
798
- const normalizedLeft = normalize(left);
799
- const normalizedRight = normalize(right);
800
- return !(0, node_util.isDeepStrictEqual)(normalizedLeft, normalizedRight);
826
+ return !(0, node_util.isDeepStrictEqual)(normalize(left), normalize(right));
801
827
  }
802
-
803
828
  //#endregion
804
829
  //#region src/plugins/po/merge.ts
805
830
  function formatDate(date) {
@@ -810,10 +835,7 @@ function formatDate(date) {
810
835
  const hours = pad(date.getHours());
811
836
  const minutes = pad(date.getMinutes());
812
837
  const tzo = -date.getTimezoneOffset();
813
- const sign = tzo >= 0 ? "+" : "-";
814
- const offsetHours = pad(Math.floor(Math.abs(tzo) / 60));
815
- const offsetMinutes = pad(Math.abs(tzo) % 60);
816
- return `${year}-${month}-${day} ${hours}:${minutes}${sign}${offsetHours}${offsetMinutes}`;
838
+ return `${year}-${month}-${day} ${hours}:${minutes}${tzo >= 0 ? "+" : "-"}${pad(Math.floor(Math.abs(tzo) / 60))}${pad(Math.abs(tzo) % 60)}`;
817
839
  }
818
840
  function merge(sources, existing, obsolete, locale, generatedAt) {
819
841
  let headers = {};
@@ -830,22 +852,22 @@ function merge(sources, existing, obsolete, locale, generatedAt) {
830
852
  }
831
853
  }
832
854
  const collected = { "": {} };
833
- for (const { translations: translations$1 } of sources) for (const [ctx, msgs] of Object.entries(translations$1)) {
855
+ for (const { translations } of sources) for (const [ctx, msgs] of Object.entries(translations)) {
834
856
  if (!collected[ctx]) collected[ctx] = {};
835
857
  for (const [id, entry] of Object.entries(msgs)) {
836
- const existing$1 = collected[ctx][id];
858
+ const existing = collected[ctx][id];
837
859
  const refs = /* @__PURE__ */ new Set();
838
- if (existing$1?.comments?.reference) existing$1.comments.reference.split(/\r?\n|\r/).forEach((r) => {
860
+ if (existing?.comments?.reference) existing.comments.reference.split(/\r?\n|\r/).forEach((r) => {
839
861
  refs.add(r);
840
862
  });
841
863
  if (entry.comments?.reference) entry.comments.reference.split(/\r?\n|\r/).forEach((r) => {
842
864
  refs.add(r);
843
865
  });
844
866
  collected[ctx][id] = {
845
- ...existing$1,
867
+ ...existing,
846
868
  ...entry,
847
869
  comments: {
848
- ...existing$1?.comments,
870
+ ...existing?.comments,
849
871
  ...entry.comments,
850
872
  reference: refs.size ? Array.from(refs).join("\n") : void 0
851
873
  }
@@ -896,7 +918,6 @@ function merge(sources, existing, obsolete, locale, generatedAt) {
896
918
  ...obsolete === "mark" && Object.keys(obsoleteTranslations).length ? { obsolete: obsoleteTranslations } : {}
897
919
  };
898
920
  }
899
-
900
921
  //#endregion
901
922
  //#region src/plugins/po/po.ts
902
923
  const namespace = "translate";
@@ -910,13 +931,13 @@ function po() {
910
931
  build.onResolve({
911
932
  filter: /.*/,
912
933
  namespace
913
- }, async ({ entrypoint, path: path$1, data }) => {
934
+ }, async ({ entrypoint, path, data }) => {
914
935
  if (!data || !Array.isArray(data)) return;
915
936
  for (const locale of build.context.config.locales) {
916
937
  const destination = build.context.config.destination({
917
938
  entrypoint,
918
939
  locale,
919
- path: path$1
940
+ path
920
941
  });
921
942
  if (!collections.has(destination)) collections.set(destination, {
922
943
  locale,
@@ -927,9 +948,9 @@ function po() {
927
948
  Promise.all([build.defer("source"), build.defer(namespace)]).then(() => {
928
949
  if (dispatched) return;
929
950
  dispatched = true;
930
- for (const path$2 of collections.keys()) build.load({
951
+ for (const path of collections.keys()) build.load({
931
952
  entrypoint,
932
- path: path$2,
953
+ path,
933
954
  namespace
934
955
  });
935
956
  });
@@ -937,35 +958,33 @@ function po() {
937
958
  build.onLoad({
938
959
  filter: /.*\.po$/,
939
960
  namespace
940
- }, async ({ entrypoint, path: path$1 }) => {
941
- const contents = await node_fs_promises.default.readFile(path$1).catch(() => void 0);
942
- const data = contents ? gettext_parser.po.parse(contents) : void 0;
961
+ }, async ({ entrypoint, path }) => {
962
+ const contents = await node_fs_promises.default.readFile(path).catch(() => void 0);
943
963
  return {
944
964
  entrypoint,
945
- path: path$1,
965
+ path,
946
966
  namespace,
947
- data
967
+ data: contents ? gettext_parser.po.parse(contents) : void 0
948
968
  };
949
969
  });
950
970
  build.onProcess({
951
971
  filter: /.*\.po$/,
952
972
  namespace
953
- }, async ({ entrypoint, path: path$1, data }) => {
954
- const collected = collections.get(path$1);
973
+ }, async ({ entrypoint, path, data }) => {
974
+ const collected = collections.get(path);
955
975
  if (!collected) {
956
- build.context.logger?.warn({ path: path$1 }, "no translations collected for this path");
976
+ build.context.logger?.warn({ path }, "no translations collected for this path");
957
977
  return;
958
978
  }
959
979
  const { locale, translations } = collected;
960
- const record = collect(translations, locale);
961
- const out = merge([{ translations: record }], data, build.context.config.obsolete, locale, build.context.generatedAt);
980
+ const out = merge([{ translations: collect(translations, locale) }], data, build.context.config.obsolete, locale, build.context.generatedAt);
962
981
  if (hasChanges(out, data)) {
963
- await node_fs_promises.default.mkdir((0, node_path.dirname)(path$1), { recursive: true });
964
- await node_fs_promises.default.writeFile(path$1, gettext_parser.po.compile(out));
982
+ await node_fs_promises.default.mkdir((0, node_path.dirname)(path), { recursive: true });
983
+ await node_fs_promises.default.writeFile(path, gettext_parser.po.compile(out));
965
984
  }
966
985
  build.resolve({
967
986
  entrypoint,
968
- path: path$1,
987
+ path,
969
988
  namespace: "cleanup",
970
989
  data: translations
971
990
  });
@@ -973,7 +992,6 @@ function po() {
973
992
  }
974
993
  };
975
994
  }
976
-
977
995
  //#endregion
978
996
  //#region src/plugins/react/queries/utils.ts
979
997
  function buildTemplate(node) {
@@ -989,10 +1007,10 @@ function buildTemplate(node) {
989
1007
  segmentStart = Math.max(segmentStart, endIndex);
990
1008
  return;
991
1009
  }
992
- const text$1 = source.slice(segmentStart, endIndex);
993
- if (text$1) parts.push({
1010
+ const text = source.slice(segmentStart, endIndex);
1011
+ if (text) parts.push({
994
1012
  kind: "text",
995
- text: text$1,
1013
+ text,
996
1014
  raw: true
997
1015
  });
998
1016
  segmentStart = endIndex;
@@ -1100,7 +1118,6 @@ function buildAttrValue(node) {
1100
1118
  error: "Unsupported JSX child"
1101
1119
  };
1102
1120
  }
1103
-
1104
1121
  //#endregion
1105
1122
  //#region src/plugins/react/queries/message.ts
1106
1123
  const messageQuery = withComment({
@@ -1156,7 +1173,6 @@ const messageQuery = withComment({
1156
1173
  };
1157
1174
  }
1158
1175
  });
1159
-
1160
1176
  //#endregion
1161
1177
  //#region src/plugins/react/queries/plural.ts
1162
1178
  function parseForms(node) {
@@ -1182,7 +1198,9 @@ function parseForms(node) {
1182
1198
  }
1183
1199
  return { forms };
1184
1200
  }
1185
- const pluralQuery = withComment({
1201
+ //#endregion
1202
+ //#region src/plugins/react/queries/index.ts
1203
+ const queries = [messageQuery, withComment({
1186
1204
  pattern: `(
1187
1205
  [
1188
1206
  (jsx_element (jsx_opening_element name: (identifier) @name))
@@ -1225,17 +1243,12 @@ const pluralQuery = withComment({
1225
1243
  translation
1226
1244
  };
1227
1245
  }
1228
- });
1229
-
1230
- //#endregion
1231
- //#region src/plugins/react/queries/index.ts
1232
- const queries = [messageQuery, pluralQuery];
1233
-
1246
+ })];
1234
1247
  //#endregion
1235
1248
  //#region src/plugins/react/parse.ts
1236
- function parseSource(source, path$1) {
1237
- const context = { path: path$1 };
1238
- const { parser, language } = getParser(path$1);
1249
+ function parseSource(source, path) {
1250
+ const context = { path };
1251
+ const { parser, language } = getParser(path);
1239
1252
  const tree = parser.parse(source);
1240
1253
  const translations = [];
1241
1254
  const warnings = [];
@@ -1267,7 +1280,6 @@ function parseSource(source, path$1) {
1267
1280
  warnings
1268
1281
  };
1269
1282
  }
1270
-
1271
1283
  //#endregion
1272
1284
  //#region src/plugins/react/react.ts
1273
1285
  const filter = /\.[cm]?[jt]sx$/;
@@ -1279,12 +1291,12 @@ function react() {
1279
1291
  build.onProcess({
1280
1292
  filter,
1281
1293
  namespace: "source"
1282
- }, ({ entrypoint, path: path$1, data }) => {
1283
- const { translations, warnings } = parseSource(data, path$1);
1294
+ }, ({ entrypoint, path, data }) => {
1295
+ const { translations, warnings } = parseSource(data, path);
1284
1296
  for (const warning of warnings) build.context.logger?.warn(`${warning.error} at ${warning.reference}`);
1285
1297
  build.resolve({
1286
1298
  entrypoint,
1287
- path: path$1,
1299
+ path,
1288
1300
  namespace: "translate",
1289
1301
  data: translations
1290
1302
  });
@@ -1292,7 +1304,21 @@ function react() {
1292
1304
  }
1293
1305
  };
1294
1306
  }
1295
-
1307
+ //#endregion
1308
+ //#region src/defer.ts
1309
+ var Defer = class {
1310
+ pending = 0;
1311
+ promise = Promise.resolve();
1312
+ resolve;
1313
+ enqueue() {
1314
+ if (this.pending++ === 0) this.promise = new Promise((res) => {
1315
+ this.resolve = res;
1316
+ });
1317
+ }
1318
+ dequeue() {
1319
+ if (this.pending > 0 && --this.pending === 0) this.resolve?.();
1320
+ }
1321
+ };
1296
1322
  //#endregion
1297
1323
  //#region src/plugins/static.ts
1298
1324
  const original = {
@@ -1305,13 +1331,12 @@ function resolveStaticPlugin(item) {
1305
1331
  if ("static" in item) return original[item.static.name](...item.static.props);
1306
1332
  return item;
1307
1333
  }
1308
-
1309
1334
  //#endregion
1310
1335
  //#region src/run.ts
1311
1336
  async function getPaths(entrypoint) {
1312
1337
  const pattern = entrypoint.entrypoint.replace(/\\/g, "/");
1313
1338
  const paths = fast_glob.default.isDynamicPattern(pattern) ? await (0, fast_glob.default)(pattern, { onlyFiles: true }) : [entrypoint.entrypoint];
1314
- return new Set(paths.map((path$1) => (0, node_path.resolve)(path$1)));
1339
+ return new Set(paths.map((path) => (0, node_path.resolve)(path)));
1315
1340
  }
1316
1341
  async function run(entrypoint, { config, logger }) {
1317
1342
  const destination = entrypoint.destination ?? config.destination;
@@ -1343,100 +1368,106 @@ async function run(entrypoint, { config, logger }) {
1343
1368
  };
1344
1369
  const pending = /* @__PURE__ */ new Map();
1345
1370
  const queue = [];
1346
- function getDeferred(namespace$3) {
1347
- let defer$1 = pending.get(namespace$3);
1348
- if (defer$1 === void 0) {
1349
- defer$1 = new Defer();
1350
- pending.set(namespace$3, defer$1);
1371
+ function getDeferred(namespace) {
1372
+ let defer = pending.get(namespace);
1373
+ if (defer === void 0) {
1374
+ defer = new Defer();
1375
+ pending.set(namespace, defer);
1351
1376
  }
1352
- return defer$1;
1377
+ return defer;
1353
1378
  }
1354
- function defer(namespace$3) {
1355
- return getDeferred(namespace$3).promise;
1379
+ function defer(namespace) {
1380
+ return getDeferred(namespace).promise;
1356
1381
  }
1357
- function source(path$1) {
1358
- const resolvedPath = (0, node_path.resolve)(path$1);
1382
+ function source(path) {
1383
+ const abs = (0, node_path.resolve)(path);
1384
+ let resolvedPath;
1385
+ try {
1386
+ resolvedPath = (0, node_fs.realpathSync)(abs);
1387
+ } catch {
1388
+ resolvedPath = abs;
1389
+ }
1359
1390
  if (paths.has(resolvedPath)) return;
1360
1391
  logger?.debug({
1361
1392
  entrypoint: entrypoint.entrypoint,
1362
1393
  path: resolvedPath
1363
1394
  }, "resolved path");
1364
1395
  paths.add(resolvedPath);
1365
- resolve$3({
1396
+ resolve({
1366
1397
  entrypoint: resolvedPath,
1367
1398
  path: resolvedPath,
1368
1399
  namespace: "source"
1369
1400
  });
1370
1401
  }
1371
- function resolve$3(args) {
1372
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1373
- const key = `${entrypoint$1}:${namespace$3}:${path$1}`;
1402
+ function resolve(args) {
1403
+ const { entrypoint, path, namespace } = args;
1404
+ const key = `${entrypoint}:${namespace}:${path}`;
1374
1405
  const visited = resolved.has(key);
1375
- const skipped = context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path));
1406
+ const skipped = require_exclude.isExcluded(args, context.config.exclude);
1376
1407
  logger?.debug({
1377
- entrypoint: entrypoint$1,
1378
- path: path$1,
1379
- namespace: namespace$3,
1408
+ entrypoint,
1409
+ path,
1410
+ namespace,
1380
1411
  skipped,
1381
1412
  visited
1382
1413
  }, "resolve");
1383
- if (namespace$3 === "source" && visited) return;
1414
+ if (namespace === "source" && visited) return;
1384
1415
  resolved.add(key);
1385
1416
  if (skipped) return;
1386
1417
  queue.push({
1387
1418
  type: "resolve",
1388
1419
  args
1389
1420
  });
1390
- getDeferred(namespace$3).enqueue();
1421
+ getDeferred(namespace).enqueue();
1391
1422
  }
1392
1423
  function load(args) {
1393
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1424
+ const { entrypoint, path, namespace } = args;
1394
1425
  logger?.debug({
1395
- entrypoint: entrypoint$1,
1396
- path: path$1,
1397
- namespace: namespace$3
1426
+ entrypoint,
1427
+ path,
1428
+ namespace
1398
1429
  }, "load");
1399
1430
  queue.push({
1400
1431
  type: "load",
1401
1432
  args
1402
1433
  });
1403
- getDeferred(namespace$3).enqueue();
1434
+ getDeferred(namespace).enqueue();
1404
1435
  }
1405
- function process$1(args) {
1406
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1436
+ function process(args) {
1437
+ const { entrypoint, path, namespace } = args;
1407
1438
  logger?.debug({
1408
- entrypoint: entrypoint$1,
1409
- path: path$1,
1410
- namespace: namespace$3
1439
+ entrypoint,
1440
+ path,
1441
+ namespace
1411
1442
  }, "process");
1412
1443
  queue.push({
1413
1444
  type: "process",
1414
1445
  args
1415
1446
  });
1416
- getDeferred(namespace$3).enqueue();
1447
+ getDeferred(namespace).enqueue();
1417
1448
  }
1418
1449
  const build = {
1419
1450
  context,
1420
1451
  source,
1421
- resolve: resolve$3,
1452
+ resolve,
1422
1453
  load,
1423
- process: process$1,
1454
+ process,
1424
1455
  defer,
1425
- onResolve(filter$2, hook) {
1456
+ onResolve(filter, hook) {
1426
1457
  resolvers.push({
1427
- filter: filter$2,
1458
+ filter,
1428
1459
  hook
1429
1460
  });
1430
1461
  },
1431
- onLoad(filter$2, hook) {
1462
+ onLoad(filter, hook) {
1432
1463
  loaders.push({
1433
- filter: filter$2,
1464
+ filter,
1434
1465
  hook
1435
1466
  });
1436
1467
  },
1437
- onProcess(filter$2, hook) {
1468
+ onProcess(filter, hook) {
1438
1469
  processors.push({
1439
- filter: filter$2,
1470
+ filter,
1440
1471
  hook
1441
1472
  });
1442
1473
  }
@@ -1446,20 +1477,20 @@ async function run(entrypoint, { config, logger }) {
1446
1477
  logger?.debug({ plugin: plugin.name }, "setting up plugin");
1447
1478
  plugin.setup(build);
1448
1479
  }
1449
- for (const path$1 of await getPaths(entrypoint)) source(path$1);
1480
+ for (const path of await getPaths(entrypoint)) source(path);
1450
1481
  async function processTask(task) {
1451
1482
  const { type } = task;
1452
1483
  let args = task.args;
1453
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1484
+ const { entrypoint, path, namespace } = args;
1454
1485
  logger?.trace({
1455
1486
  type,
1456
- entrypoint: entrypoint$1,
1457
- path: path$1,
1458
- namespace: namespace$3
1487
+ entrypoint,
1488
+ path,
1489
+ namespace
1459
1490
  }, "processing task");
1460
- for (const { filter: filter$2, hook } of hooks[type]) {
1461
- if (filter$2.namespace !== namespace$3) continue;
1462
- if (filter$2.filter && !filter$2.filter.test(path$1)) continue;
1491
+ for (const { filter, hook } of hooks[type]) {
1492
+ if (filter.namespace !== namespace) continue;
1493
+ if (filter.filter && !filter.filter.test(path)) continue;
1463
1494
  const result = await hook(args);
1464
1495
  if (result !== void 0) {
1465
1496
  args = result;
@@ -1468,9 +1499,9 @@ async function run(entrypoint, { config, logger }) {
1468
1499
  }
1469
1500
  if (args !== void 0) {
1470
1501
  if (type === "resolve") load(args);
1471
- else if (type === "load") process$1(args);
1502
+ else if (type === "load") process(args);
1472
1503
  }
1473
- getDeferred(namespace$3).dequeue();
1504
+ getDeferred(namespace).dequeue();
1474
1505
  }
1475
1506
  while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
1476
1507
  while (queue.length) {
@@ -1483,35 +1514,40 @@ async function run(entrypoint, { config, logger }) {
1483
1514
  }
1484
1515
  logger?.info(entrypoint, "extraction completed");
1485
1516
  }
1486
-
1487
1517
  //#endregion
1488
- Object.defineProperty(exports, 'cleanup', {
1489
- enumerable: true,
1490
- get: function () {
1491
- return cleanup;
1492
- }
1518
+ Object.defineProperty(exports, "__toESM", {
1519
+ enumerable: true,
1520
+ get: function() {
1521
+ return __toESM;
1522
+ }
1523
+ });
1524
+ Object.defineProperty(exports, "cleanup", {
1525
+ enumerable: true,
1526
+ get: function() {
1527
+ return cleanup;
1528
+ }
1493
1529
  });
1494
- Object.defineProperty(exports, 'core', {
1495
- enumerable: true,
1496
- get: function () {
1497
- return core;
1498
- }
1530
+ Object.defineProperty(exports, "core", {
1531
+ enumerable: true,
1532
+ get: function() {
1533
+ return core;
1534
+ }
1499
1535
  });
1500
- Object.defineProperty(exports, 'po', {
1501
- enumerable: true,
1502
- get: function () {
1503
- return po;
1504
- }
1536
+ Object.defineProperty(exports, "po", {
1537
+ enumerable: true,
1538
+ get: function() {
1539
+ return po;
1540
+ }
1505
1541
  });
1506
- Object.defineProperty(exports, 'react', {
1507
- enumerable: true,
1508
- get: function () {
1509
- return react;
1510
- }
1542
+ Object.defineProperty(exports, "react", {
1543
+ enumerable: true,
1544
+ get: function() {
1545
+ return react;
1546
+ }
1547
+ });
1548
+ Object.defineProperty(exports, "run", {
1549
+ enumerable: true,
1550
+ get: function() {
1551
+ return run;
1552
+ }
1511
1553
  });
1512
- Object.defineProperty(exports, 'run', {
1513
- enumerable: true,
1514
- get: function () {
1515
- return run;
1516
- }
1517
- });