@pegasusheavy/nestjs-prisma-graphql 1.2.1 → 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,14 +1,14 @@
1
- #!/usr/bin/env node
1
+ import { existsSync, readdirSync, rmdirSync } from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { arch, platform } from 'os';
2
4
  import generatorHelper from '@prisma/generator-helper';
3
5
  import { ok } from 'assert';
4
- import { createRequire } from 'module';
5
6
  import { memoize, mapKeys, merge, trim, castArray, uniqWith, isEqual, countBy, startCase, camelCase, keyBy, remove, partition, kebabCase, isObject, omit, cloneDeep } from 'lodash-es';
6
7
  import { Project, QuoteKind, StructureKind } from 'ts-morph';
7
8
  import JSON52 from 'json5';
8
9
  import pupa from 'pupa';
9
10
  import getRelativePath from 'get-relative-path';
10
11
  import outmatch2 from 'outmatch';
11
- import { existsSync, rmdirSync } from 'fs';
12
12
  import { unflatten } from 'flat';
13
13
  import filenamify from 'filenamify';
14
14
  import pluralize from 'pluralize';
@@ -377,6 +377,15 @@ async function generateFiles(args) {
377
377
  statements: [...imports.toStatements(), ...enums, ...classes]
378
378
  });
379
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
+ }
380
389
  if (config.emitCompiled) {
381
390
  project.compilerOptions.set({
382
391
  declaration: true,
@@ -2631,17 +2640,27 @@ async function generate(args) {
2631
2640
  }
2632
2641
 
2633
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
+ });
2634
2657
  var { generatorHandler } = generatorHelper;
2635
2658
  function isGeneratorDisabled(options, env = process.env) {
2636
2659
  const envVarsToCheck = [
2637
2660
  "DISABLE_NESTJS_PRISMA_GRAPHQL",
2638
- // Most specific
2639
2661
  "CI_SKIP_PRISMA_GRAPHQL",
2640
- // CI-specific
2641
2662
  "PRISMA_GENERATOR_SKIP",
2642
- // Common convention
2643
2663
  "SKIP_PRISMA_GENERATE"
2644
- // Alternative
2645
2664
  ];
2646
2665
  for (const envVar of envVarsToCheck) {
2647
2666
  const value = env[envVar];
@@ -2655,15 +2674,65 @@ function isGeneratorDisabled(options, env = process.env) {
2655
2674
  }
2656
2675
  return false;
2657
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
+ }
2658
2688
  generatorHandler({
2659
2689
  async onGenerate(options) {
2660
2690
  if (isGeneratorDisabled(options)) {
2661
2691
  console.log(
2662
- "\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)"
2663
2693
  );
2664
2694
  return;
2665
2695
  }
2666
- 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
+ }
2667
2736
  },
2668
2737
  onManifest() {
2669
2738
  return {