@pegasusheavy/nestjs-prisma-graphql 1.2.2 → 1.2.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.
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
+ import { existsSync, readdirSync, rmdirSync } from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { arch, platform } from 'os';
1
4
  import generatorHelper from '@prisma/generator-helper';
2
5
  import { ok } from 'assert';
3
- import { createRequire } from 'module';
4
6
  import { memoize, mapKeys, merge, trim, castArray, uniqWith, isEqual, countBy, startCase, camelCase, keyBy, remove, partition, kebabCase, isObject, omit, cloneDeep } from 'lodash-es';
5
7
  import { Project, QuoteKind, StructureKind } from 'ts-morph';
6
8
  import JSON52 from 'json5';
7
9
  import pupa from 'pupa';
8
10
  import getRelativePath from 'get-relative-path';
9
11
  import outmatch2 from 'outmatch';
10
- import { existsSync, rmdirSync } from 'fs';
11
12
  import { unflatten } from 'flat';
12
13
  import filenamify from 'filenamify';
13
14
  import pluralize from 'pluralize';
@@ -376,6 +377,15 @@ async function generateFiles(args) {
376
377
  statements: [...imports.toStatements(), ...enums, ...classes]
377
378
  });
378
379
  }
380
+ const sourceFileCount = project.getSourceFiles().length;
381
+ console.log(
382
+ `nestjs-prisma-graphql: saving ${String(sourceFileCount)} source files to ${output}`
383
+ );
384
+ if (sourceFileCount === 0) {
385
+ throw new Error(
386
+ "nestjs-prisma-graphql: project has 0 source files \u2014 nothing to write"
387
+ );
388
+ }
379
389
  if (config.emitCompiled) {
380
390
  project.compilerOptions.set({
381
391
  declaration: true,
@@ -2630,17 +2640,27 @@ async function generate(args) {
2630
2640
  }
2631
2641
 
2632
2642
  // src/index.ts
2643
+ var requireCjs2 = createRequire(import.meta.url);
2644
+ requireCjs2("graceful-fs").gracefulify(requireCjs2("fs"));
2645
+ process.on("unhandledRejection", (reason) => {
2646
+ console.log("nestjs-prisma-graphql: unhandled rejection:", reason);
2647
+ if (reason instanceof Error && typeof reason.stack === "string") {
2648
+ console.log(reason.stack);
2649
+ }
2650
+ });
2651
+ process.on("uncaughtException", (error) => {
2652
+ console.log("nestjs-prisma-graphql: uncaught exception:", error.message);
2653
+ if (typeof error.stack === "string") {
2654
+ console.log(error.stack);
2655
+ }
2656
+ });
2633
2657
  var { generatorHandler } = generatorHelper;
2634
2658
  function isGeneratorDisabled(options, env = process.env) {
2635
2659
  const envVarsToCheck = [
2636
2660
  "DISABLE_NESTJS_PRISMA_GRAPHQL",
2637
- // Most specific
2638
2661
  "CI_SKIP_PRISMA_GRAPHQL",
2639
- // CI-specific
2640
2662
  "PRISMA_GENERATOR_SKIP",
2641
- // Common convention
2642
2663
  "SKIP_PRISMA_GENERATE"
2643
- // Alternative
2644
2664
  ];
2645
2665
  for (const envVar of envVarsToCheck) {
2646
2666
  const value = env[envVar];
@@ -2654,15 +2674,65 @@ function isGeneratorDisabled(options, env = process.env) {
2654
2674
  }
2655
2675
  return false;
2656
2676
  }
2677
+ function countFilesRecursive(dir) {
2678
+ let count = 0;
2679
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
2680
+ if (entry.isDirectory()) {
2681
+ count += countFilesRecursive(`${dir}/${entry.name}`);
2682
+ } else {
2683
+ count++;
2684
+ }
2685
+ }
2686
+ return count;
2687
+ }
2657
2688
  generatorHandler({
2658
2689
  async onGenerate(options) {
2659
2690
  if (isGeneratorDisabled(options)) {
2660
2691
  console.log(
2661
- "\u23ED\uFE0F nestjs-prisma-graphql: Generation skipped (disabled via environment variable or config)"
2692
+ "nestjs-prisma-graphql: generation skipped (disabled via environment variable or config)"
2662
2693
  );
2663
2694
  return;
2664
2695
  }
2665
- await generate(options);
2696
+ const outputPath = options.generator.output?.value ?? "<unknown>";
2697
+ const startTime = Date.now();
2698
+ console.log(
2699
+ [
2700
+ "nestjs-prisma-graphql: starting generation",
2701
+ `(arch=${arch()}, platform=${platform()}, node=${process.version}, output=${outputPath})`
2702
+ ].join(" ")
2703
+ );
2704
+ try {
2705
+ await generate(options);
2706
+ } catch (error) {
2707
+ const elapsed2 = Date.now() - startTime;
2708
+ const message = error instanceof Error ? error.message : String(error);
2709
+ const stack = error instanceof Error ? error.stack : void 0;
2710
+ console.log(
2711
+ `nestjs-prisma-graphql: generation FAILED after ${String(elapsed2)}ms: ${message}`
2712
+ );
2713
+ if (typeof stack === "string") {
2714
+ console.log(stack);
2715
+ }
2716
+ throw error;
2717
+ }
2718
+ const elapsed = Date.now() - startTime;
2719
+ if (typeof outputPath === "string" && outputPath !== "<unknown>" && existsSync(outputPath)) {
2720
+ const fileCount = countFilesRecursive(outputPath);
2721
+ console.log(
2722
+ `nestjs-prisma-graphql: generated ${String(fileCount)} files in ${String(
2723
+ elapsed
2724
+ )}ms`
2725
+ );
2726
+ if (fileCount === 0) {
2727
+ const msg = "nestjs-prisma-graphql: generation produced 0 files \u2014 this likely indicates a silent failure";
2728
+ console.log(msg);
2729
+ throw new Error(msg);
2730
+ }
2731
+ } else {
2732
+ const msg = `nestjs-prisma-graphql: output directory not found after generation: ${outputPath}`;
2733
+ console.log(msg);
2734
+ throw new Error(msg);
2735
+ }
2666
2736
  },
2667
2737
  onManifest() {
2668
2738
  return {