@514labs/moose-lib 0.6.325 → 0.6.326

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.
@@ -363,7 +363,8 @@ __export(commons_exports, {
363
363
  getKafkaClient: () => getKafkaClient,
364
364
  getKafkaProducer: () => getKafkaProducer,
365
365
  logError: () => logError,
366
- mapTstoJs: () => mapTstoJs
366
+ mapTstoJs: () => mapTstoJs,
367
+ rewriteImportExtensions: () => rewriteImportExtensions
367
368
  });
368
369
  function isTruthy(value) {
369
370
  if (!value) return false;
@@ -380,6 +381,94 @@ function isTruthy(value) {
380
381
  function mapTstoJs(filePath) {
381
382
  return filePath.replace(/\.ts$/, ".js").replace(/\.cts$/, ".cjs").replace(/\.mts$/, ".mjs");
382
383
  }
384
+ function walkDirectory(dir, extensions) {
385
+ const results = [];
386
+ if (!(0, import_fs.existsSync)(dir)) {
387
+ return results;
388
+ }
389
+ try {
390
+ const entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
391
+ for (const entry of entries) {
392
+ const fullPath = import_path.default.join(dir, entry.name);
393
+ if (entry.isDirectory()) {
394
+ if (entry.name !== "node_modules") {
395
+ results.push(...walkDirectory(fullPath, extensions));
396
+ }
397
+ } else if (entry.isFile()) {
398
+ const ext = import_path.default.extname(entry.name);
399
+ if (extensions.includes(ext)) {
400
+ results.push(fullPath);
401
+ }
402
+ }
403
+ }
404
+ } catch (e) {
405
+ console.debug(`[moose] Failed to read directory ${dir}:`, e);
406
+ }
407
+ return results;
408
+ }
409
+ function addJsExtensionToImports(content, fileDir) {
410
+ const fromPattern = /(from\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
411
+ const bareImportPattern = /(import\s+['"])(\.\.?\/[^'"]*?)(['"])/g;
412
+ const dynamicPattern = /(import\s*\(\s*['"])(\.\.?\/[^'"]*?)(['"])/g;
413
+ let result = content;
414
+ result = result.replace(fromPattern, (match, prefix, importPath, quote) => {
415
+ return rewriteImportPath(match, prefix, importPath, quote, fileDir);
416
+ });
417
+ result = result.replace(
418
+ bareImportPattern,
419
+ (match, prefix, importPath, quote) => {
420
+ return rewriteImportPath(match, prefix, importPath, quote, fileDir);
421
+ }
422
+ );
423
+ result = result.replace(
424
+ dynamicPattern,
425
+ (match, prefix, importPath, quote) => {
426
+ return rewriteImportPath(match, prefix, importPath, quote, fileDir);
427
+ }
428
+ );
429
+ return result;
430
+ }
431
+ function rewriteImportPath(match, prefix, importPath, quote, fileDir) {
432
+ if (/\.[cm]?js$/.test(importPath)) {
433
+ return match;
434
+ }
435
+ if (/\.json$/.test(importPath)) {
436
+ return match;
437
+ }
438
+ if (fileDir) {
439
+ const resolvedPath = import_path.default.resolve(fileDir, importPath);
440
+ if ((0, import_fs.existsSync)(`${resolvedPath}.js`)) {
441
+ return `${prefix}${importPath}.js${quote}`;
442
+ }
443
+ if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.js"))) {
444
+ return `${prefix}${importPath}/index.js${quote}`;
445
+ }
446
+ if ((0, import_fs.existsSync)(`${resolvedPath}.mjs`)) {
447
+ return `${prefix}${importPath}.mjs${quote}`;
448
+ }
449
+ if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.mjs"))) {
450
+ return `${prefix}${importPath}/index.mjs${quote}`;
451
+ }
452
+ if ((0, import_fs.existsSync)(`${resolvedPath}.cjs`)) {
453
+ return `${prefix}${importPath}.cjs${quote}`;
454
+ }
455
+ if ((0, import_fs.existsSync)(import_path.default.join(resolvedPath, "index.cjs"))) {
456
+ return `${prefix}${importPath}/index.cjs${quote}`;
457
+ }
458
+ }
459
+ return `${prefix}${importPath}.js${quote}`;
460
+ }
461
+ function rewriteImportExtensions(outDir) {
462
+ const files = walkDirectory(outDir, [".js", ".mjs"]);
463
+ for (const filePath of files) {
464
+ const content = (0, import_fs.readFileSync)(filePath, "utf-8");
465
+ const fileDir = import_path.default.dirname(filePath);
466
+ const rewritten = addJsExtensionToImports(content, fileDir);
467
+ if (content !== rewritten) {
468
+ (0, import_fs.writeFileSync)(filePath, rewritten, "utf-8");
469
+ }
470
+ }
471
+ }
383
472
  function createProducerConfig(maxMessageBytes) {
384
473
  return {
385
474
  kafkaJS: {
@@ -402,11 +491,13 @@ async function getKafkaProducer(cfg, logger, maxMessageBytes) {
402
491
  await producer.connect();
403
492
  return producer;
404
493
  }
405
- var import_http, import_client, import_kafka_javascript, Kafka, compilerLog, antiCachePath, getFileName, getClickhouseClient, cliLog, MAX_RETRIES, MAX_RETRY_TIME_MS, RETRY_INITIAL_TIME_MS, MAX_RETRIES_PRODUCER, RETRY_FACTOR_PRODUCER, ACKs, parseBrokerString, logError, buildSaslConfig, getKafkaClient;
494
+ var import_http, import_fs, import_path, import_client, import_kafka_javascript, Kafka, compilerLog, antiCachePath, getFileName, getClickhouseClient, cliLog, MAX_RETRIES, MAX_RETRY_TIME_MS, RETRY_INITIAL_TIME_MS, MAX_RETRIES_PRODUCER, RETRY_FACTOR_PRODUCER, ACKs, parseBrokerString, logError, buildSaslConfig, getKafkaClient;
406
495
  var init_commons = __esm({
407
496
  "src/commons.ts"() {
408
497
  "use strict";
409
498
  import_http = __toESM(require("http"));
499
+ import_fs = require("fs");
500
+ import_path = __toESM(require("path"));
410
501
  import_client = require("@clickhouse/client");
411
502
  import_kafka_javascript = require("@514labs/kafka-javascript");
412
503
  ({ Kafka } = import_kafka_javascript.KafkaJS);
@@ -556,6 +647,13 @@ var init_cluster_utils = __esm({
556
647
  }
557
648
  });
558
649
 
650
+ // src/compiler-config.ts
651
+ var init_compiler_config = __esm({
652
+ "src/compiler-config.ts"() {
653
+ "use strict";
654
+ }
655
+ });
656
+
559
657
  // src/consumption-apis/runner.ts
560
658
  var jose;
561
659
  var init_runner = __esm({
@@ -567,6 +665,7 @@ var init_runner = __esm({
567
665
  init_cluster_utils();
568
666
  init_sqlHelpers();
569
667
  init_internal();
668
+ init_compiler_config();
570
669
  }
571
670
  });
572
671
 
@@ -670,6 +769,7 @@ var init_internal = __esm({
670
769
  import_process = __toESM(require("process"));
671
770
  init_index();
672
771
  init_commons();
772
+ init_compiler_config();
673
773
  isClientOnlyMode = () => import_process.default.env.MOOSE_CLIENT_ONLY === "true";
674
774
  moose_internal = {
675
775
  tables: /* @__PURE__ */ new Map(),