@let-value/translate-extract 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_run = require('../run-XkKxn8kJ.cjs');
2
+ const require_run = require('../run-BFehT9l8.cjs');
3
3
  let node_util = require("node:util");
4
4
  node_util = require_run.__toESM(node_util);
5
5
  let cosmiconfig = require("cosmiconfig");
@@ -13,7 +13,10 @@ function createLogger(level = "info") {
13
13
  level,
14
14
  transport: {
15
15
  target: "pino-pretty",
16
- options: { colorize: true }
16
+ options: {
17
+ colorize: true,
18
+ ignore: "time,pid,hostname"
19
+ }
17
20
  }
18
21
  });
19
22
  }
@@ -30,7 +33,7 @@ async function main() {
30
33
  } }
31
34
  });
32
35
  const logger = createLogger(logLevel);
33
- const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, { searchPlaces: [
36
+ const result = await (0, cosmiconfig.cosmiconfig)(moduleName, { searchPlaces: [
34
37
  `.${moduleName}rc.js`,
35
38
  `.${moduleName}rc.ts`,
36
39
  `.${moduleName}rc.mjs`,
@@ -43,8 +46,7 @@ async function main() {
43
46
  `${moduleName}.config.ts`,
44
47
  `${moduleName}.config.mjs`,
45
48
  `${moduleName}.config.cjs`
46
- ] });
47
- const result = await explorer.search();
49
+ ] }).search();
48
50
  if (!result || !result.config) {
49
51
  logger.error("No configuration file found");
50
52
  process.exit(1);
@@ -60,8 +62,7 @@ async function main() {
60
62
  await Promise.all(tasks);
61
63
  }
62
64
  main().catch((err) => {
63
- const logger = createLogger();
64
- logger.error(err);
65
+ createLogger().error(err);
65
66
  process.exit(1);
66
67
  });
67
68
 
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ export { };
package/dist/bin/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ export { };
package/dist/bin/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { run } from "../run-Dl-tr2kf.js";
2
+ import { run } from "../run-CQoAsNNE.js";
3
3
  import { parseArgs } from "node:util";
4
4
  import { cosmiconfig } from "cosmiconfig";
5
5
  import pino from "pino";
@@ -10,7 +10,10 @@ function createLogger(level = "info") {
10
10
  level,
11
11
  transport: {
12
12
  target: "pino-pretty",
13
- options: { colorize: true }
13
+ options: {
14
+ colorize: true,
15
+ ignore: "time,pid,hostname"
16
+ }
14
17
  }
15
18
  });
16
19
  }
@@ -27,7 +30,7 @@ async function main() {
27
30
  } }
28
31
  });
29
32
  const logger = createLogger(logLevel);
30
- const explorer = cosmiconfig(moduleName, { searchPlaces: [
33
+ const result = await cosmiconfig(moduleName, { searchPlaces: [
31
34
  `.${moduleName}rc.js`,
32
35
  `.${moduleName}rc.ts`,
33
36
  `.${moduleName}rc.mjs`,
@@ -40,8 +43,7 @@ async function main() {
40
43
  `${moduleName}.config.ts`,
41
44
  `${moduleName}.config.mjs`,
42
45
  `${moduleName}.config.cjs`
43
- ] });
44
- const result = await explorer.search();
46
+ ] }).search();
45
47
  if (!result || !result.config) {
46
48
  logger.error("No configuration file found");
47
49
  process.exit(1);
@@ -57,8 +59,7 @@ async function main() {
57
59
  await Promise.all(tasks);
58
60
  }
59
61
  main().catch((err) => {
60
- const logger = createLogger();
61
- logger.error(err);
62
+ createLogger().error(err);
62
63
  process.exit(1);
63
64
  });
64
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":["tasks: Promise<unknown>[]"],"sources":["../../src/logger.ts","../../bin/cli.ts"],"sourcesContent":["import pino, { type LevelWithSilent, type Logger } from \"pino\";\n\nexport function createLogger(level: LevelWithSilent = \"info\"): Logger {\n return pino({\n level,\n transport: {\n target: \"pino-pretty\",\n options: {\n colorize: true,\n },\n },\n });\n}\n\nexport type { Logger, LevelWithSilent };\n","#!/usr/bin/env node\nimport { parseArgs } from \"node:util\";\nimport { cosmiconfig } from \"cosmiconfig\";\nimport type { ResolvedConfig } from \"../src/configuration.ts\";\nimport { createLogger, type LevelWithSilent } from \"../src/logger.ts\";\nimport { run } from \"../src/run.ts\";\n\nconst moduleName = \"translate\";\n\nasync function main() {\n const {\n values: { logLevel },\n } = parseArgs({\n args: process.argv.slice(2),\n options: {\n logLevel: { type: \"string\", short: \"l\" },\n },\n });\n\n const logger = createLogger(logLevel as LevelWithSilent | undefined);\n\n const explorer = cosmiconfig(moduleName, {\n searchPlaces: [\n `.${moduleName}rc.js`,\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n `.config/${moduleName}rc.js`,\n `.config/${moduleName}rc.ts`,\n `.config/${moduleName}rc.mjs`,\n `.config/${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.ts`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ],\n });\n\n const result = await explorer.search();\n if (!result || !result.config) {\n logger.error(\"No configuration file found\");\n process.exit(1);\n }\n\n const config = result.config as ResolvedConfig;\n config.logLevel = (logLevel as LevelWithSilent) ?? config.logLevel;\n logger.level = config.logLevel;\n\n const tasks: Promise<unknown>[] = [];\n for (const entrypoint of config.entrypoints) {\n tasks.push(run(entrypoint, { config, logger }));\n }\n\n await Promise.all(tasks);\n}\n\nvoid main().catch((err) => {\n const logger = createLogger();\n logger.error(err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAEA,SAAgB,aAAa,QAAyB,QAAgB;AAClE,QAAO,KAAK;EACR;EACA,WAAW;GACP,QAAQ;GACR,SAAS,EACL,UAAU;;;;;;;ACD1B,MAAM,aAAa;AAEnB,eAAe,OAAO;CAClB,MAAM,EACF,QAAQ,EAAE,eACV,UAAU;EACV,MAAM,QAAQ,KAAK,MAAM;EACzB,SAAS,EACL,UAAU;GAAE,MAAM;GAAU,OAAO;;;CAI3C,MAAM,SAAS,aAAa;CAE5B,MAAM,WAAW,YAAY,YAAY,EACrC,cAAc;EACV,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;;CAItB,MAAM,SAAS,MAAM,SAAS;AAC9B,KAAI,CAAC,UAAU,CAAC,OAAO,QAAQ;AAC3B,SAAO,MAAM;AACb,UAAQ,KAAK;;CAGjB,MAAM,SAAS,OAAO;AACtB,QAAO,WAAY,YAAgC,OAAO;AAC1D,QAAO,QAAQ,OAAO;CAEtB,MAAMA,QAA4B;AAClC,MAAK,MAAM,cAAc,OAAO,YAC5B,OAAM,KAAK,IAAI,YAAY;EAAE;EAAQ;;AAGzC,OAAM,QAAQ,IAAI;;AAGjB,OAAO,OAAO,QAAQ;CACvB,MAAM,SAAS;AACf,QAAO,MAAM;AACb,SAAQ,KAAK"}
1
+ {"version":3,"file":"cli.js","names":["tasks: Promise<unknown>[]"],"sources":["../../src/logger.ts","../../bin/cli.ts"],"sourcesContent":["import pino, { type LevelWithSilent, type Logger } from \"pino\";\n\nexport function createLogger(level: LevelWithSilent = \"info\"): Logger {\n return pino({\n level,\n transport: {\n target: \"pino-pretty\",\n options: {\n colorize: true,\n ignore: \"time,pid,hostname\",\n },\n },\n });\n}\n\nexport type { Logger, LevelWithSilent };\n","#!/usr/bin/env node\nimport { parseArgs } from \"node:util\";\nimport { cosmiconfig } from \"cosmiconfig\";\nimport type { ResolvedConfig } from \"../src/configuration.ts\";\nimport { createLogger, type LevelWithSilent } from \"../src/logger.ts\";\nimport { run } from \"../src/run.ts\";\n\nconst moduleName = \"translate\";\n\nasync function main() {\n const {\n values: { logLevel },\n } = parseArgs({\n args: process.argv.slice(2),\n options: {\n logLevel: { type: \"string\", short: \"l\" },\n },\n });\n\n const logger = createLogger(logLevel as LevelWithSilent | undefined);\n\n const explorer = cosmiconfig(moduleName, {\n searchPlaces: [\n `.${moduleName}rc.js`,\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n `.config/${moduleName}rc.js`,\n `.config/${moduleName}rc.ts`,\n `.config/${moduleName}rc.mjs`,\n `.config/${moduleName}rc.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.ts`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ],\n });\n\n const result = await explorer.search();\n if (!result || !result.config) {\n logger.error(\"No configuration file found\");\n process.exit(1);\n }\n\n const config = result.config as ResolvedConfig;\n config.logLevel = (logLevel as LevelWithSilent) ?? config.logLevel;\n logger.level = config.logLevel;\n\n const tasks: Promise<unknown>[] = [];\n for (const entrypoint of config.entrypoints) {\n tasks.push(run(entrypoint, { config, logger }));\n }\n\n await Promise.all(tasks);\n}\n\nvoid main().catch((err) => {\n const logger = createLogger();\n logger.error(err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAEA,SAAgB,aAAa,QAAyB,QAAgB;AAClE,QAAO,KAAK;EACR;EACA,WAAW;GACP,QAAQ;GACR,SAAS;IACL,UAAU;IACV,QAAQ;IACX;GACJ;EACJ,CAAC;;;;;ACLN,MAAM,aAAa;AAEnB,eAAe,OAAO;CAClB,MAAM,EACF,QAAQ,EAAE,eACV,UAAU;EACV,MAAM,QAAQ,KAAK,MAAM,EAAE;EAC3B,SAAS,EACL,UAAU;GAAE,MAAM;GAAU,OAAO;GAAK,EAC3C;EACJ,CAAC;CAEF,MAAM,SAAS,aAAa,SAAwC;CAmBpE,MAAM,SAAS,MAjBE,YAAY,YAAY,EACrC,cAAc;EACV,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,IAAI,WAAW;EACf,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,WAAW,WAAW;EACtB,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACjB,EACJ,CAAC,CAE4B,QAAQ;AACtC,KAAI,CAAC,UAAU,CAAC,OAAO,QAAQ;AAC3B,SAAO,MAAM,8BAA8B;AAC3C,UAAQ,KAAK,EAAE;;CAGnB,MAAM,SAAS,OAAO;AACtB,QAAO,WAAY,YAAgC,OAAO;AAC1D,QAAO,QAAQ,OAAO;CAEtB,MAAMA,QAA4B,EAAE;AACpC,MAAK,MAAM,cAAc,OAAO,YAC5B,OAAM,KAAK,IAAI,YAAY;EAAE;EAAQ;EAAQ,CAAC,CAAC;AAGnD,OAAM,QAAQ,IAAI,MAAM;;AAGvB,MAAM,CAAC,OAAO,QAAQ;AAEvB,CADe,cAAc,CACtB,MAAM,IAAI;AACjB,SAAQ,KAAK,EAAE;EACjB"}
@@ -57,7 +57,7 @@ async function run(entrypoint, { config, logger }) {
57
57
  generatedAt: /* @__PURE__ */ new Date(),
58
58
  logger
59
59
  };
60
- logger?.info({ entrypoint }, "starting extraction");
60
+ logger?.info(entrypoint, "starting extraction");
61
61
  const resolvers = [];
62
62
  const loaders = [];
63
63
  const processors = [];
@@ -77,30 +77,49 @@ async function run(entrypoint, { config, logger }) {
77
77
  return defer$1;
78
78
  }
79
79
  function defer(namespace) {
80
- const defer$1 = getDeferred(namespace);
81
- return defer$1.promise;
80
+ return getDeferred(namespace).promise;
82
81
  }
83
82
  function resolve(args) {
84
- if (args.path !== args.entrypoint && (!context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path)))) return;
83
+ const { entrypoint: entrypoint$1, path, namespace } = args;
84
+ const skipped = args.path !== args.entrypoint && !context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path));
85
+ logger?.debug({
86
+ entrypoint: entrypoint$1,
87
+ path,
88
+ namespace,
89
+ skipped
90
+ }, "resolve");
91
+ if (skipped) return;
85
92
  queue.push({
86
93
  type: "resolve",
87
94
  args
88
95
  });
89
- getDeferred(args.namespace).enqueue();
96
+ getDeferred(namespace).enqueue();
90
97
  }
91
98
  function load(args) {
99
+ const { entrypoint: entrypoint$1, path, namespace } = args;
100
+ logger?.debug({
101
+ entrypoint: entrypoint$1,
102
+ path,
103
+ namespace
104
+ }, "load");
92
105
  queue.push({
93
106
  type: "load",
94
107
  args
95
108
  });
96
- getDeferred(args.namespace).enqueue();
109
+ getDeferred(namespace).enqueue();
97
110
  }
98
111
  function process(args) {
112
+ const { entrypoint: entrypoint$1, path, namespace } = args;
113
+ logger?.debug({
114
+ entrypoint: entrypoint$1,
115
+ path,
116
+ namespace
117
+ }, "process");
99
118
  queue.push({
100
119
  type: "process",
101
120
  args
102
121
  });
103
- getDeferred(args.namespace).enqueue();
122
+ getDeferred(namespace).enqueue();
104
123
  }
105
124
  const build = {
106
125
  context,
@@ -131,13 +150,12 @@ async function run(entrypoint, { config, logger }) {
131
150
  logger?.debug({ plugin: plugin.name }, "setting up plugin");
132
151
  plugin.setup(build);
133
152
  }
134
- const paths = (0, glob.globSync)(entrypoint.entrypoint, { nodir: true });
135
- if (paths.length === 0) resolve({
153
+ const paths = (0, glob.hasMagic)(entrypoint.entrypoint) ? await (0, glob.glob)(entrypoint.entrypoint, { nodir: true }) : [entrypoint.entrypoint];
154
+ logger?.debug({
136
155
  entrypoint: entrypoint.entrypoint,
137
- path: entrypoint.entrypoint,
138
- namespace: "source"
139
- });
140
- else for (const path of paths) resolve({
156
+ paths
157
+ }, "resolved paths");
158
+ for (const path of paths) resolve({
141
159
  entrypoint: path,
142
160
  path,
143
161
  namespace: "source"
@@ -145,9 +163,16 @@ async function run(entrypoint, { config, logger }) {
145
163
  async function processTask(task) {
146
164
  const { type } = task;
147
165
  let args = task.args;
148
- for (const { filter: { filter, namespace }, hook } of hooks[type]) {
149
- if (namespace !== args.namespace) continue;
150
- if (filter && !filter.test(args.path)) continue;
166
+ const { entrypoint: entrypoint$1, path, namespace } = args;
167
+ logger?.trace({
168
+ type,
169
+ entrypoint: entrypoint$1,
170
+ path,
171
+ namespace
172
+ }, "processing task");
173
+ for (const { filter, hook } of hooks[type]) {
174
+ if (filter.namespace !== namespace) continue;
175
+ if (filter.filter && !filter.filter.test(path)) continue;
151
176
  const result = await hook(args);
152
177
  if (result !== void 0) args = result;
153
178
  }
@@ -155,7 +180,7 @@ async function run(entrypoint, { config, logger }) {
155
180
  if (type === "resolve") load(args);
156
181
  else if (type === "load") process(args);
157
182
  }
158
- getDeferred(task.args.namespace).dequeue();
183
+ getDeferred(namespace).dequeue();
159
184
  }
160
185
  while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
161
186
  while (queue.length) {
@@ -166,7 +191,7 @@ async function run(entrypoint, { config, logger }) {
166
191
  await Promise.all(Array.from(pending.values()).map((d) => d.promise));
167
192
  await Promise.resolve();
168
193
  }
169
- logger?.info({ entrypoint }, "extraction completed");
194
+ logger?.info(entrypoint, "extraction completed");
170
195
  }
171
196
 
172
197
  //#endregion
@@ -1,4 +1,4 @@
1
- import { globSync } from "glob";
1
+ import { glob, hasMagic } from "glob";
2
2
 
3
3
  //#region src/defer.ts
4
4
  var Defer = class {
@@ -33,7 +33,7 @@ async function run(entrypoint, { config, logger }) {
33
33
  generatedAt: /* @__PURE__ */ new Date(),
34
34
  logger
35
35
  };
36
- logger?.info({ entrypoint }, "starting extraction");
36
+ logger?.info(entrypoint, "starting extraction");
37
37
  const resolvers = [];
38
38
  const loaders = [];
39
39
  const processors = [];
@@ -53,30 +53,49 @@ async function run(entrypoint, { config, logger }) {
53
53
  return defer$1;
54
54
  }
55
55
  function defer(namespace) {
56
- const defer$1 = getDeferred(namespace);
57
- return defer$1.promise;
56
+ return getDeferred(namespace).promise;
58
57
  }
59
58
  function resolve(args) {
60
- if (args.path !== args.entrypoint && (!context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path)))) return;
59
+ const { entrypoint: entrypoint$1, path, namespace } = args;
60
+ const skipped = args.path !== args.entrypoint && !context.config.walk || context.config.exclude.some((ex) => typeof ex === "function" ? ex(args) : ex.test(args.path));
61
+ logger?.debug({
62
+ entrypoint: entrypoint$1,
63
+ path,
64
+ namespace,
65
+ skipped
66
+ }, "resolve");
67
+ if (skipped) return;
61
68
  queue.push({
62
69
  type: "resolve",
63
70
  args
64
71
  });
65
- getDeferred(args.namespace).enqueue();
72
+ getDeferred(namespace).enqueue();
66
73
  }
67
74
  function load(args) {
75
+ const { entrypoint: entrypoint$1, path, namespace } = args;
76
+ logger?.debug({
77
+ entrypoint: entrypoint$1,
78
+ path,
79
+ namespace
80
+ }, "load");
68
81
  queue.push({
69
82
  type: "load",
70
83
  args
71
84
  });
72
- getDeferred(args.namespace).enqueue();
85
+ getDeferred(namespace).enqueue();
73
86
  }
74
87
  function process(args) {
88
+ const { entrypoint: entrypoint$1, path, namespace } = args;
89
+ logger?.debug({
90
+ entrypoint: entrypoint$1,
91
+ path,
92
+ namespace
93
+ }, "process");
75
94
  queue.push({
76
95
  type: "process",
77
96
  args
78
97
  });
79
- getDeferred(args.namespace).enqueue();
98
+ getDeferred(namespace).enqueue();
80
99
  }
81
100
  const build = {
82
101
  context,
@@ -107,13 +126,12 @@ async function run(entrypoint, { config, logger }) {
107
126
  logger?.debug({ plugin: plugin.name }, "setting up plugin");
108
127
  plugin.setup(build);
109
128
  }
110
- const paths = globSync(entrypoint.entrypoint, { nodir: true });
111
- if (paths.length === 0) resolve({
129
+ const paths = hasMagic(entrypoint.entrypoint) ? await glob(entrypoint.entrypoint, { nodir: true }) : [entrypoint.entrypoint];
130
+ logger?.debug({
112
131
  entrypoint: entrypoint.entrypoint,
113
- path: entrypoint.entrypoint,
114
- namespace: "source"
115
- });
116
- else for (const path of paths) resolve({
132
+ paths
133
+ }, "resolved paths");
134
+ for (const path of paths) resolve({
117
135
  entrypoint: path,
118
136
  path,
119
137
  namespace: "source"
@@ -121,9 +139,16 @@ async function run(entrypoint, { config, logger }) {
121
139
  async function processTask(task) {
122
140
  const { type } = task;
123
141
  let args = task.args;
124
- for (const { filter: { filter, namespace }, hook } of hooks[type]) {
125
- if (namespace !== args.namespace) continue;
126
- if (filter && !filter.test(args.path)) continue;
142
+ const { entrypoint: entrypoint$1, path, namespace } = args;
143
+ logger?.trace({
144
+ type,
145
+ entrypoint: entrypoint$1,
146
+ path,
147
+ namespace
148
+ }, "processing task");
149
+ for (const { filter, hook } of hooks[type]) {
150
+ if (filter.namespace !== namespace) continue;
151
+ if (filter.filter && !filter.filter.test(path)) continue;
127
152
  const result = await hook(args);
128
153
  if (result !== void 0) args = result;
129
154
  }
@@ -131,7 +156,7 @@ async function run(entrypoint, { config, logger }) {
131
156
  if (type === "resolve") load(args);
132
157
  else if (type === "load") process(args);
133
158
  }
134
- getDeferred(task.args.namespace).dequeue();
159
+ getDeferred(namespace).dequeue();
135
160
  }
136
161
  while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {
137
162
  while (queue.length) {
@@ -142,9 +167,9 @@ async function run(entrypoint, { config, logger }) {
142
167
  await Promise.all(Array.from(pending.values()).map((d) => d.promise));
143
168
  await Promise.resolve();
144
169
  }
145
- logger?.info({ entrypoint }, "extraction completed");
170
+ logger?.info(entrypoint, "extraction completed");
146
171
  }
147
172
 
148
173
  //#endregion
149
174
  export { run };
150
- //# sourceMappingURL=run-Dl-tr2kf.js.map
175
+ //# sourceMappingURL=run-CQoAsNNE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-CQoAsNNE.js","names":["context: Context","resolvers: { filter: Filter; hook: ResolveHook }[]","loaders: { filter: Filter; hook: LoadHook }[]","processors: { filter: Filter; hook: ProcessHook }[]","queue: Task[]","defer","build: Build"],"sources":["../src/defer.ts","../src/run.ts"],"sourcesContent":["export class Defer {\n pending = 0;\n promise: Promise<void> = Promise.resolve();\n resolve?: () => void;\n\n enqueue() {\n if (this.pending++ === 0) {\n this.promise = new Promise<void>((res) => {\n this.resolve = res;\n });\n }\n }\n dequeue() {\n if (this.pending > 0 && --this.pending === 0) {\n this.resolve?.();\n }\n }\n}\n","import { glob, hasMagic } from \"glob\";\nimport type { ResolvedConfig, ResolvedEntrypoint } from \"./configuration.ts\";\nimport { Defer } from \"./defer.ts\";\nimport type { Logger } from \"./logger.ts\";\nimport type {\n Build,\n Context,\n Filter,\n LoadArgs,\n LoadHook,\n ProcessArgs,\n ProcessHook,\n ResolveArgs,\n ResolveHook,\n} from \"./plugin.ts\";\n\nexport type Task =\n | {\n type: \"resolve\";\n args: ResolveArgs;\n }\n | {\n type: \"load\";\n args: LoadArgs;\n }\n | {\n type: \"process\";\n args: ProcessArgs;\n };\n\nexport async function run(\n entrypoint: ResolvedEntrypoint,\n { config, logger }: { config: ResolvedConfig; logger?: Logger },\n) {\n const destination = entrypoint?.destination ?? config.destination;\n const obsolete = entrypoint?.obsolete ?? config.obsolete;\n const exclude = entrypoint?.exclude ?? config.exclude;\n const walk = entrypoint?.walk ?? config.walk;\n\n const context: Context = {\n config: { ...config, destination, obsolete, exclude, walk },\n generatedAt: new Date(),\n logger,\n };\n\n logger?.info(entrypoint, \"starting extraction\");\n\n const resolvers: { filter: Filter; hook: ResolveHook }[] = [];\n const loaders: { filter: Filter; hook: LoadHook }[] = [];\n const processors: { filter: Filter; hook: ProcessHook }[] = [];\n const hooks = {\n resolve: resolvers,\n load: loaders,\n process: processors,\n };\n\n const pending = new Map<string, Defer>();\n const queue: Task[] = [];\n\n function getDeferred(namespace: string) {\n let defer = pending.get(namespace);\n if (defer === undefined) {\n defer = new Defer();\n pending.set(namespace, defer);\n }\n return defer;\n }\n\n function defer(namespace: string) {\n const defer = getDeferred(namespace);\n return defer.promise;\n }\n\n function resolve(args: ResolveArgs) {\n const { entrypoint, path, namespace } = args;\n const skipped =\n (args.path !== args.entrypoint && !context.config.walk) ||\n context.config.exclude.some((ex) => (typeof ex === \"function\" ? ex(args) : ex.test(args.path)));\n logger?.debug({ entrypoint, path, namespace, skipped }, \"resolve\");\n\n if (skipped) {\n return;\n }\n\n queue.push({ type: \"resolve\", args });\n getDeferred(namespace).enqueue();\n }\n\n function load(args: LoadArgs) {\n const { entrypoint, path, namespace } = args;\n logger?.debug({ entrypoint, path, namespace }, \"load\");\n\n queue.push({ type: \"load\", args });\n getDeferred(namespace).enqueue();\n }\n\n function process(args: ProcessArgs) {\n const { entrypoint, path, namespace } = args;\n logger?.debug({ entrypoint, path, namespace }, \"process\");\n\n queue.push({ type: \"process\", args });\n getDeferred(namespace).enqueue();\n }\n\n const build: Build = {\n context,\n resolve,\n load,\n process,\n defer,\n onResolve(filter, hook) {\n resolvers.push({ filter, hook });\n },\n onLoad(filter, hook) {\n loaders.push({ filter, hook });\n },\n onProcess(filter, hook) {\n processors.push({ filter, hook });\n },\n };\n\n for (const plugin of config.plugins) {\n logger?.debug({ plugin: plugin.name }, \"setting up plugin\");\n plugin.setup(build);\n }\n\n const paths = hasMagic(entrypoint.entrypoint)\n ? await glob(entrypoint.entrypoint, { nodir: true })\n : [entrypoint.entrypoint];\n logger?.debug({ entrypoint: entrypoint.entrypoint, paths }, \"resolved paths\");\n\n for (const path of paths) {\n resolve({ entrypoint: path, path, namespace: \"source\" });\n }\n\n async function processTask(task: Task) {\n const { type } = task;\n let args = task.args;\n const { entrypoint, path, namespace } = args;\n logger?.trace({ type, entrypoint, path, namespace }, \"processing task\");\n\n for (const { filter, hook } of hooks[type]) {\n if (filter.namespace !== namespace) continue;\n if (filter.filter && !filter.filter.test(path)) continue;\n\n const result = await hook(args as never);\n if (result !== undefined) {\n args = result as never;\n }\n }\n\n if (args !== undefined) {\n if (type === \"resolve\") {\n load(args as never);\n } else if (type === \"load\") {\n process(args as never);\n }\n }\n\n getDeferred(namespace).dequeue();\n }\n\n while (queue.length || Array.from(pending.values()).some((d) => d.pending > 0)) {\n while (queue.length) {\n const task = queue.shift();\n if (!task) {\n break;\n }\n\n await processTask(task);\n }\n\n await Promise.all(Array.from(pending.values()).map((d) => d.promise));\n await Promise.resolve();\n }\n\n logger?.info(entrypoint, \"extraction completed\");\n}\n"],"mappings":";;;AAAA,IAAa,QAAb,MAAmB;CACf,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