@let-value/translate-extract 1.0.9 → 1.0.11

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,226 +0,0 @@
1
- //#region rolldown:runtime
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
-
23
- //#endregion
24
-
25
- //#region src/run.ts
26
- async function run(entrypoint, { config, logger }) {
27
- const entryConfig = config.entrypoints.find((e) => e.entrypoint === entrypoint);
28
- const destination = entryConfig?.destination ?? config.destination;
29
- const obsolete = entryConfig?.obsolete ?? config.obsolete;
30
- const exclude = entryConfig?.exclude ?? config.exclude;
31
- const queue = [{
32
- entrypoint,
33
- path: entrypoint
34
- }];
35
- const defaultLocale = config.defaultLocale;
36
- logger?.info({
37
- entrypoint,
38
- locale: defaultLocale
39
- }, "starting extraction");
40
- const context = {
41
- entrypoint,
42
- config: {
43
- ...config,
44
- destination,
45
- obsolete,
46
- exclude
47
- },
48
- generatedAt: /* @__PURE__ */ new Date(),
49
- locale: defaultLocale,
50
- logger
51
- };
52
- const resolves = [];
53
- const loads = [];
54
- const extracts = [];
55
- const collects = [];
56
- const generates = [];
57
- function resolvePath(args) {
58
- for (const ex of context.config.exclude) if (ex instanceof RegExp ? ex.test(args.path) : ex(args.path)) return;
59
- if (context.config.walk) queue.push(args);
60
- }
61
- const build = {
62
- onResolve({ filter }, hook) {
63
- resolves.push({
64
- filter,
65
- hook
66
- });
67
- },
68
- onLoad({ filter }, hook) {
69
- loads.push({
70
- filter,
71
- hook
72
- });
73
- },
74
- onExtract({ filter }, hook) {
75
- extracts.push({
76
- filter,
77
- hook
78
- });
79
- },
80
- onCollect({ filter }, hook) {
81
- collects.push({
82
- filter,
83
- hook
84
- });
85
- },
86
- onGenerate({ filter }, hook) {
87
- generates.push({
88
- filter,
89
- hook
90
- });
91
- },
92
- resolvePath,
93
- context
94
- };
95
- for (const plugin of config.plugins) {
96
- logger?.debug({ plugin: plugin.name }, "setting up plugin");
97
- plugin.setup(build);
98
- }
99
- const visited = /* @__PURE__ */ new Set();
100
- async function applyResolve({ entrypoint: entrypoint$1, path }) {
101
- for (const { filter, hook } of resolves) {
102
- if (!filter.test(path)) continue;
103
- const result = await hook({
104
- entrypoint: entrypoint$1,
105
- path
106
- }, context);
107
- if (result) logger?.debug(result, "resolved");
108
- if (result) return result;
109
- }
110
- return void 0;
111
- }
112
- async function applyLoad({ entrypoint: entrypoint$1, path }) {
113
- for (const { filter, hook } of loads) {
114
- if (!filter.test(path)) continue;
115
- const result = await hook({
116
- entrypoint: entrypoint$1,
117
- path
118
- }, context);
119
- if (result) logger?.debug({
120
- entrypoint: entrypoint$1,
121
- path
122
- }, "loaded");
123
- if (result) return result;
124
- }
125
- return void 0;
126
- }
127
- async function applyExtract({ entrypoint: entrypoint$1, path, contents }) {
128
- const results = [];
129
- for (const { filter, hook } of extracts) {
130
- if (!filter.test(path)) continue;
131
- const result = await hook({
132
- entrypoint: entrypoint$1,
133
- path,
134
- contents
135
- }, context);
136
- if (result) {
137
- logger?.debug({
138
- entrypoint: entrypoint$1,
139
- path
140
- }, "extracted");
141
- results.push(result);
142
- }
143
- }
144
- return results;
145
- }
146
- async function applyCollect({ entrypoint: entrypoint$1, path, translations, destination: destination$1 }) {
147
- for (const { filter, hook } of collects) {
148
- if (!filter.test(path)) continue;
149
- const result = await hook({
150
- entrypoint: entrypoint$1,
151
- path,
152
- translations,
153
- destination: destination$1
154
- }, context);
155
- if (result) logger?.debug({
156
- entrypoint: entrypoint$1,
157
- path,
158
- destination: destination$1,
159
- ...destination$1 !== result.destination && { redirected: result.destination }
160
- }, "collected");
161
- if (result) return result;
162
- }
163
- return void 0;
164
- }
165
- const extractedResults = [];
166
- while (queue.length) {
167
- const args = queue.shift();
168
- const resolved = await applyResolve(args);
169
- if (!resolved || visited.has(resolved.path)) continue;
170
- visited.add(resolved.path);
171
- const loaded = await applyLoad(resolved);
172
- if (!loaded) continue;
173
- const extracted = await applyExtract(loaded);
174
- if (!extracted.length) continue;
175
- extractedResults.push(...extracted);
176
- }
177
- for (const locale of config.locales) {
178
- context.locale = locale;
179
- const collectedByDest = {};
180
- for (const extracted of extractedResults) {
181
- const destination$1 = context.config.destination({
182
- entrypoint,
183
- locale,
184
- path: extracted.path
185
- });
186
- const collected = await applyCollect({
187
- ...extracted,
188
- destination: destination$1
189
- });
190
- if (!collected) continue;
191
- if (!collectedByDest[collected.destination]) collectedByDest[collected.destination] = [];
192
- collectedByDest[collected.destination].push(collected);
193
- }
194
- for (const [path, collected] of Object.entries(collectedByDest)) for (const { filter, hook } of generates) {
195
- if (!filter.test(path)) continue;
196
- logger?.info({
197
- path,
198
- locale
199
- }, "generating output");
200
- await hook({
201
- entrypoint,
202
- path,
203
- collected
204
- }, context);
205
- }
206
- }
207
- logger?.info({
208
- entrypoint,
209
- locale: defaultLocale
210
- }, "extraction completed");
211
- return extractedResults;
212
- }
213
-
214
- //#endregion
215
- Object.defineProperty(exports, '__toESM', {
216
- enumerable: true,
217
- get: function () {
218
- return __toESM;
219
- }
220
- });
221
- Object.defineProperty(exports, 'run', {
222
- enumerable: true,
223
- get: function () {
224
- return run;
225
- }
226
- });