@let-value/translate-extract 1.1.2 → 1.1.6-beta.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.
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-C8z_uhxb.js → run-Bv3fv1N8.mjs} +233 -206
  12. package/dist/run-Bv3fv1N8.mjs.map +1 -0
  13. package/dist/{run-DtE6y27D.cjs → run-oGs6tkeL.cjs} +297 -247
  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 -57
  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-C8z_uhxb.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,17 +635,48 @@ function getResolver(dir) {
632
635
  }
633
636
  return resolver;
634
637
  }
635
- function resolveImports(file, imports) {
638
+ function normalizeImportReference(imp) {
639
+ if (typeof imp === "string") return {
640
+ spec: imp,
641
+ kind: "static",
642
+ typeOnly: false
643
+ };
644
+ return imp;
645
+ }
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
- for (const spec of imports) {
640
- const res = resolver.sync(dir, spec);
641
- if (res.path) resolved.push(res.path);
650
+ const unresolved = [];
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
+ }
642
674
  }
643
- return resolved;
675
+ return {
676
+ resolved,
677
+ unresolved
678
+ };
644
679
  }
645
-
646
680
  //#endregion
647
681
  //#region src/plugins/core/core.ts
648
682
  const filter$1 = /\.([cm]?tsx?|jsx?)$/;
@@ -655,55 +689,67 @@ function core() {
655
689
  build.onResolve({
656
690
  filter: filter$1,
657
691
  namespace: namespace$1
658
- }, ({ entrypoint, path: path$1 }) => {
692
+ }, ({ entrypoint, path, import: imp, data }) => {
659
693
  return {
660
694
  entrypoint,
661
695
  namespace: namespace$1,
662
- path: (0, node_path.resolve)(path$1)
696
+ path: (0, node_path.resolve)(path),
697
+ import: imp,
698
+ data
663
699
  };
664
700
  });
665
701
  build.onLoad({
666
702
  filter: filter$1,
667
703
  namespace: namespace$1
668
- }, async ({ entrypoint, path: path$1 }) => {
669
- const data = await (0, node_fs_promises.readFile)(path$1, "utf8");
704
+ }, async ({ entrypoint, path }) => {
670
705
  return {
671
706
  entrypoint,
672
- path: path$1,
707
+ path,
673
708
  namespace: namespace$1,
674
- data
709
+ data: await (0, node_fs_promises.readFile)(path, "utf8")
675
710
  };
676
711
  });
677
712
  build.onProcess({
678
713
  filter: filter$1,
679
714
  namespace: namespace$1
680
- }, ({ entrypoint, path: path$1, data }) => {
681
- const result = parseSource$1(data, path$1);
682
- if (result.entrypoint && entrypoint !== path$1) {
683
- 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);
684
719
  return {
685
720
  entrypoint,
686
- path: path$1,
721
+ path,
687
722
  namespace: namespace$1,
688
723
  data: []
689
724
  };
690
725
  }
691
726
  const { translations, imports, warnings } = result;
692
727
  if (build.context.config.walk) {
693
- const paths = resolveImports(path$1, imports);
694
- for (const path$2 of paths) {
695
- 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;
696
731
  build.resolve({
697
732
  entrypoint,
698
- path: path$2,
699
- namespace: namespace$1
733
+ path: result.path,
734
+ namespace: namespace$1,
735
+ import: result.import
700
736
  });
701
737
  }
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
+ }
702
748
  }
703
749
  for (const warning of warnings) build.context.logger?.warn(`${warning.error} at ${warning.reference}`);
704
750
  build.resolve({
705
751
  entrypoint,
706
- path: path$1,
752
+ path,
707
753
  namespace: "translate",
708
754
  data: translations
709
755
  });
@@ -711,7 +757,6 @@ function core() {
711
757
  }
712
758
  };
713
759
  }
714
-
715
760
  //#endregion
716
761
  //#region src/plugins/po/collect.ts
717
762
  function collect(source, locale) {
@@ -746,7 +791,6 @@ function collect(source, locale) {
746
791
  }
747
792
  return translations;
748
793
  }
749
-
750
794
  //#endregion
751
795
  //#region src/plugins/po/hasChanges.ts
752
796
  const IGNORED_HEADER_KEYS = new Set(["pot-creation-date", "po-revision-date"]);
@@ -760,9 +804,7 @@ function normalizeHeaderString(value) {
760
804
  }).map((line) => {
761
805
  const separatorIndex = line.indexOf(":");
762
806
  if (separatorIndex === -1) return line;
763
- const key = line.slice(0, separatorIndex).trim().toLowerCase();
764
- const value$1 = line.slice(separatorIndex + 1);
765
- return `${key}:${value$1}`;
807
+ return `${line.slice(0, separatorIndex).trim().toLowerCase()}:${line.slice(separatorIndex + 1)}`;
766
808
  });
767
809
  if (hadTrailingNewline && filtered[filtered.length - 1] !== "") filtered.push("");
768
810
  return filtered.join("\n");
@@ -781,11 +823,8 @@ function normalize(translations) {
781
823
  }
782
824
  function hasChanges(left, right) {
783
825
  if (!right) return true;
784
- const normalizedLeft = normalize(left);
785
- const normalizedRight = normalize(right);
786
- return !(0, node_util.isDeepStrictEqual)(normalizedLeft, normalizedRight);
826
+ return !(0, node_util.isDeepStrictEqual)(normalize(left), normalize(right));
787
827
  }
788
-
789
828
  //#endregion
790
829
  //#region src/plugins/po/merge.ts
791
830
  function formatDate(date) {
@@ -796,10 +835,7 @@ function formatDate(date) {
796
835
  const hours = pad(date.getHours());
797
836
  const minutes = pad(date.getMinutes());
798
837
  const tzo = -date.getTimezoneOffset();
799
- const sign = tzo >= 0 ? "+" : "-";
800
- const offsetHours = pad(Math.floor(Math.abs(tzo) / 60));
801
- const offsetMinutes = pad(Math.abs(tzo) % 60);
802
- 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)}`;
803
839
  }
804
840
  function merge(sources, existing, obsolete, locale, generatedAt) {
805
841
  let headers = {};
@@ -816,22 +852,22 @@ function merge(sources, existing, obsolete, locale, generatedAt) {
816
852
  }
817
853
  }
818
854
  const collected = { "": {} };
819
- 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)) {
820
856
  if (!collected[ctx]) collected[ctx] = {};
821
857
  for (const [id, entry] of Object.entries(msgs)) {
822
- const existing$1 = collected[ctx][id];
858
+ const existing = collected[ctx][id];
823
859
  const refs = /* @__PURE__ */ new Set();
824
- 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) => {
825
861
  refs.add(r);
826
862
  });
827
863
  if (entry.comments?.reference) entry.comments.reference.split(/\r?\n|\r/).forEach((r) => {
828
864
  refs.add(r);
829
865
  });
830
866
  collected[ctx][id] = {
831
- ...existing$1,
867
+ ...existing,
832
868
  ...entry,
833
869
  comments: {
834
- ...existing$1?.comments,
870
+ ...existing?.comments,
835
871
  ...entry.comments,
836
872
  reference: refs.size ? Array.from(refs).join("\n") : void 0
837
873
  }
@@ -882,7 +918,6 @@ function merge(sources, existing, obsolete, locale, generatedAt) {
882
918
  ...obsolete === "mark" && Object.keys(obsoleteTranslations).length ? { obsolete: obsoleteTranslations } : {}
883
919
  };
884
920
  }
885
-
886
921
  //#endregion
887
922
  //#region src/plugins/po/po.ts
888
923
  const namespace = "translate";
@@ -896,13 +931,13 @@ function po() {
896
931
  build.onResolve({
897
932
  filter: /.*/,
898
933
  namespace
899
- }, async ({ entrypoint, path: path$1, data }) => {
934
+ }, async ({ entrypoint, path, data }) => {
900
935
  if (!data || !Array.isArray(data)) return;
901
936
  for (const locale of build.context.config.locales) {
902
937
  const destination = build.context.config.destination({
903
938
  entrypoint,
904
939
  locale,
905
- path: path$1
940
+ path
906
941
  });
907
942
  if (!collections.has(destination)) collections.set(destination, {
908
943
  locale,
@@ -913,9 +948,9 @@ function po() {
913
948
  Promise.all([build.defer("source"), build.defer(namespace)]).then(() => {
914
949
  if (dispatched) return;
915
950
  dispatched = true;
916
- for (const path$2 of collections.keys()) build.load({
951
+ for (const path of collections.keys()) build.load({
917
952
  entrypoint,
918
- path: path$2,
953
+ path,
919
954
  namespace
920
955
  });
921
956
  });
@@ -923,35 +958,33 @@ function po() {
923
958
  build.onLoad({
924
959
  filter: /.*\.po$/,
925
960
  namespace
926
- }, async ({ entrypoint, path: path$1 }) => {
927
- const contents = await node_fs_promises.default.readFile(path$1).catch(() => void 0);
928
- 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);
929
963
  return {
930
964
  entrypoint,
931
- path: path$1,
965
+ path,
932
966
  namespace,
933
- data
967
+ data: contents ? gettext_parser.po.parse(contents) : void 0
934
968
  };
935
969
  });
936
970
  build.onProcess({
937
971
  filter: /.*\.po$/,
938
972
  namespace
939
- }, async ({ entrypoint, path: path$1, data }) => {
940
- const collected = collections.get(path$1);
973
+ }, async ({ entrypoint, path, data }) => {
974
+ const collected = collections.get(path);
941
975
  if (!collected) {
942
- 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");
943
977
  return;
944
978
  }
945
979
  const { locale, translations } = collected;
946
- const record = collect(translations, locale);
947
- 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);
948
981
  if (hasChanges(out, data)) {
949
- await node_fs_promises.default.mkdir((0, node_path.dirname)(path$1), { recursive: true });
950
- 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));
951
984
  }
952
985
  build.resolve({
953
986
  entrypoint,
954
- path: path$1,
987
+ path,
955
988
  namespace: "cleanup",
956
989
  data: translations
957
990
  });
@@ -959,7 +992,6 @@ function po() {
959
992
  }
960
993
  };
961
994
  }
962
-
963
995
  //#endregion
964
996
  //#region src/plugins/react/queries/utils.ts
965
997
  function buildTemplate(node) {
@@ -975,10 +1007,10 @@ function buildTemplate(node) {
975
1007
  segmentStart = Math.max(segmentStart, endIndex);
976
1008
  return;
977
1009
  }
978
- const text$1 = source.slice(segmentStart, endIndex);
979
- if (text$1) parts.push({
1010
+ const text = source.slice(segmentStart, endIndex);
1011
+ if (text) parts.push({
980
1012
  kind: "text",
981
- text: text$1,
1013
+ text,
982
1014
  raw: true
983
1015
  });
984
1016
  segmentStart = endIndex;
@@ -1086,7 +1118,6 @@ function buildAttrValue(node) {
1086
1118
  error: "Unsupported JSX child"
1087
1119
  };
1088
1120
  }
1089
-
1090
1121
  //#endregion
1091
1122
  //#region src/plugins/react/queries/message.ts
1092
1123
  const messageQuery = withComment({
@@ -1142,7 +1173,6 @@ const messageQuery = withComment({
1142
1173
  };
1143
1174
  }
1144
1175
  });
1145
-
1146
1176
  //#endregion
1147
1177
  //#region src/plugins/react/queries/plural.ts
1148
1178
  function parseForms(node) {
@@ -1168,7 +1198,9 @@ function parseForms(node) {
1168
1198
  }
1169
1199
  return { forms };
1170
1200
  }
1171
- const pluralQuery = withComment({
1201
+ //#endregion
1202
+ //#region src/plugins/react/queries/index.ts
1203
+ const queries = [messageQuery, withComment({
1172
1204
  pattern: `(
1173
1205
  [
1174
1206
  (jsx_element (jsx_opening_element name: (identifier) @name))
@@ -1211,17 +1243,12 @@ const pluralQuery = withComment({
1211
1243
  translation
1212
1244
  };
1213
1245
  }
1214
- });
1215
-
1216
- //#endregion
1217
- //#region src/plugins/react/queries/index.ts
1218
- const queries = [messageQuery, pluralQuery];
1219
-
1246
+ })];
1220
1247
  //#endregion
1221
1248
  //#region src/plugins/react/parse.ts
1222
- function parseSource(source, path$1) {
1223
- const context = { path: path$1 };
1224
- const { parser, language } = getParser(path$1);
1249
+ function parseSource(source, path) {
1250
+ const context = { path };
1251
+ const { parser, language } = getParser(path);
1225
1252
  const tree = parser.parse(source);
1226
1253
  const translations = [];
1227
1254
  const warnings = [];
@@ -1253,7 +1280,6 @@ function parseSource(source, path$1) {
1253
1280
  warnings
1254
1281
  };
1255
1282
  }
1256
-
1257
1283
  //#endregion
1258
1284
  //#region src/plugins/react/react.ts
1259
1285
  const filter = /\.[cm]?[jt]sx$/;
@@ -1265,12 +1291,12 @@ function react() {
1265
1291
  build.onProcess({
1266
1292
  filter,
1267
1293
  namespace: "source"
1268
- }, ({ entrypoint, path: path$1, data }) => {
1269
- const { translations, warnings } = parseSource(data, path$1);
1294
+ }, ({ entrypoint, path, data }) => {
1295
+ const { translations, warnings } = parseSource(data, path);
1270
1296
  for (const warning of warnings) build.context.logger?.warn(`${warning.error} at ${warning.reference}`);
1271
1297
  build.resolve({
1272
1298
  entrypoint,
1273
- path: path$1,
1299
+ path,
1274
1300
  namespace: "translate",
1275
1301
  data: translations
1276
1302
  });
@@ -1278,7 +1304,21 @@ function react() {
1278
1304
  }
1279
1305
  };
1280
1306
  }
1281
-
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
+ };
1282
1322
  //#endregion
1283
1323
  //#region src/plugins/static.ts
1284
1324
  const original = {
@@ -1291,13 +1331,12 @@ function resolveStaticPlugin(item) {
1291
1331
  if ("static" in item) return original[item.static.name](...item.static.props);
1292
1332
  return item;
1293
1333
  }
1294
-
1295
1334
  //#endregion
1296
1335
  //#region src/run.ts
1297
1336
  async function getPaths(entrypoint) {
1298
1337
  const pattern = entrypoint.entrypoint.replace(/\\/g, "/");
1299
1338
  const paths = fast_glob.default.isDynamicPattern(pattern) ? await (0, fast_glob.default)(pattern, { onlyFiles: true }) : [entrypoint.entrypoint];
1300
- 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)));
1301
1340
  }
1302
1341
  async function run(entrypoint, { config, logger }) {
1303
1342
  const destination = entrypoint.destination ?? config.destination;
@@ -1329,100 +1368,106 @@ async function run(entrypoint, { config, logger }) {
1329
1368
  };
1330
1369
  const pending = /* @__PURE__ */ new Map();
1331
1370
  const queue = [];
1332
- function getDeferred(namespace$3) {
1333
- let defer$1 = pending.get(namespace$3);
1334
- if (defer$1 === void 0) {
1335
- defer$1 = new Defer();
1336
- 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);
1337
1376
  }
1338
- return defer$1;
1377
+ return defer;
1339
1378
  }
1340
- function defer(namespace$3) {
1341
- return getDeferred(namespace$3).promise;
1379
+ function defer(namespace) {
1380
+ return getDeferred(namespace).promise;
1342
1381
  }
1343
- function source(path$1) {
1344
- 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
+ }
1345
1390
  if (paths.has(resolvedPath)) return;
1346
1391
  logger?.debug({
1347
1392
  entrypoint: entrypoint.entrypoint,
1348
1393
  path: resolvedPath
1349
1394
  }, "resolved path");
1350
1395
  paths.add(resolvedPath);
1351
- resolve$3({
1396
+ resolve({
1352
1397
  entrypoint: resolvedPath,
1353
1398
  path: resolvedPath,
1354
1399
  namespace: "source"
1355
1400
  });
1356
1401
  }
1357
- function resolve$3(args) {
1358
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1359
- const key = `${entrypoint$1}:${namespace$3}:${path$1}`;
1402
+ function resolve(args) {
1403
+ const { entrypoint, path, namespace } = args;
1404
+ const key = `${entrypoint}:${namespace}:${path}`;
1360
1405
  const visited = resolved.has(key);
1361
- 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);
1362
1407
  logger?.debug({
1363
- entrypoint: entrypoint$1,
1364
- path: path$1,
1365
- namespace: namespace$3,
1408
+ entrypoint,
1409
+ path,
1410
+ namespace,
1366
1411
  skipped,
1367
1412
  visited
1368
1413
  }, "resolve");
1369
- if (namespace$3 === "source" && visited) return;
1414
+ if (namespace === "source" && visited) return;
1370
1415
  resolved.add(key);
1371
1416
  if (skipped) return;
1372
1417
  queue.push({
1373
1418
  type: "resolve",
1374
1419
  args
1375
1420
  });
1376
- getDeferred(namespace$3).enqueue();
1421
+ getDeferred(namespace).enqueue();
1377
1422
  }
1378
1423
  function load(args) {
1379
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1424
+ const { entrypoint, path, namespace } = args;
1380
1425
  logger?.debug({
1381
- entrypoint: entrypoint$1,
1382
- path: path$1,
1383
- namespace: namespace$3
1426
+ entrypoint,
1427
+ path,
1428
+ namespace
1384
1429
  }, "load");
1385
1430
  queue.push({
1386
1431
  type: "load",
1387
1432
  args
1388
1433
  });
1389
- getDeferred(namespace$3).enqueue();
1434
+ getDeferred(namespace).enqueue();
1390
1435
  }
1391
- function process$1(args) {
1392
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1436
+ function process(args) {
1437
+ const { entrypoint, path, namespace } = args;
1393
1438
  logger?.debug({
1394
- entrypoint: entrypoint$1,
1395
- path: path$1,
1396
- namespace: namespace$3
1439
+ entrypoint,
1440
+ path,
1441
+ namespace
1397
1442
  }, "process");
1398
1443
  queue.push({
1399
1444
  type: "process",
1400
1445
  args
1401
1446
  });
1402
- getDeferred(namespace$3).enqueue();
1447
+ getDeferred(namespace).enqueue();
1403
1448
  }
1404
1449
  const build = {
1405
1450
  context,
1406
1451
  source,
1407
- resolve: resolve$3,
1452
+ resolve,
1408
1453
  load,
1409
- process: process$1,
1454
+ process,
1410
1455
  defer,
1411
- onResolve(filter$2, hook) {
1456
+ onResolve(filter, hook) {
1412
1457
  resolvers.push({
1413
- filter: filter$2,
1458
+ filter,
1414
1459
  hook
1415
1460
  });
1416
1461
  },
1417
- onLoad(filter$2, hook) {
1462
+ onLoad(filter, hook) {
1418
1463
  loaders.push({
1419
- filter: filter$2,
1464
+ filter,
1420
1465
  hook
1421
1466
  });
1422
1467
  },
1423
- onProcess(filter$2, hook) {
1468
+ onProcess(filter, hook) {
1424
1469
  processors.push({
1425
- filter: filter$2,
1470
+ filter,
1426
1471
  hook
1427
1472
  });
1428
1473
  }
@@ -1432,20 +1477,20 @@ async function run(entrypoint, { config, logger }) {
1432
1477
  logger?.debug({ plugin: plugin.name }, "setting up plugin");
1433
1478
  plugin.setup(build);
1434
1479
  }
1435
- for (const path$1 of await getPaths(entrypoint)) source(path$1);
1480
+ for (const path of await getPaths(entrypoint)) source(path);
1436
1481
  async function processTask(task) {
1437
1482
  const { type } = task;
1438
1483
  let args = task.args;
1439
- const { entrypoint: entrypoint$1, path: path$1, namespace: namespace$3 } = args;
1484
+ const { entrypoint, path, namespace } = args;
1440
1485
  logger?.trace({
1441
1486
  type,
1442
- entrypoint: entrypoint$1,
1443
- path: path$1,
1444
- namespace: namespace$3
1487
+ entrypoint,
1488
+ path,
1489
+ namespace
1445
1490
  }, "processing task");
1446
- for (const { filter: filter$2, hook } of hooks[type]) {
1447
- if (filter$2.namespace !== namespace$3) continue;
1448
- 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;
1449
1494
  const result = await hook(args);
1450
1495
  if (result !== void 0) {
1451
1496
  args = result;
@@ -1454,9 +1499,9 @@ async function run(entrypoint, { config, logger }) {
1454
1499
  }
1455
1500
  if (args !== void 0) {
1456
1501
  if (type === "resolve") load(args);
1457
- else if (type === "load") process$1(args);
1502
+ else if (type === "load") process(args);
1458
1503
  }
1459
- getDeferred(namespace$3).dequeue();
1504
+ getDeferred(namespace).dequeue();
1460
1505
  }
1461
1506
  while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
1462
1507
  while (queue.length) {
@@ -1469,35 +1514,40 @@ async function run(entrypoint, { config, logger }) {
1469
1514
  }
1470
1515
  logger?.info(entrypoint, "extraction completed");
1471
1516
  }
1472
-
1473
1517
  //#endregion
1474
- Object.defineProperty(exports, 'cleanup', {
1475
- enumerable: true,
1476
- get: function () {
1477
- return cleanup;
1478
- }
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
+ }
1479
1529
  });
1480
- Object.defineProperty(exports, 'core', {
1481
- enumerable: true,
1482
- get: function () {
1483
- return core;
1484
- }
1530
+ Object.defineProperty(exports, "core", {
1531
+ enumerable: true,
1532
+ get: function() {
1533
+ return core;
1534
+ }
1485
1535
  });
1486
- Object.defineProperty(exports, 'po', {
1487
- enumerable: true,
1488
- get: function () {
1489
- return po;
1490
- }
1536
+ Object.defineProperty(exports, "po", {
1537
+ enumerable: true,
1538
+ get: function() {
1539
+ return po;
1540
+ }
1491
1541
  });
1492
- Object.defineProperty(exports, 'react', {
1493
- enumerable: true,
1494
- get: function () {
1495
- return react;
1496
- }
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
+ }
1497
1553
  });
1498
- Object.defineProperty(exports, 'run', {
1499
- enumerable: true,
1500
- get: function () {
1501
- return run;
1502
- }
1503
- });