Skip to content

Commit

Permalink
fix: generated placeholder files not properly deleted + fake index.ts…
Browse files Browse the repository at this point in the history
… raising TS overwrite error
  • Loading branch information
LilaRest committed May 7, 2023
1 parent 113bfc8 commit 4834886
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/.generated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ _Example_: Accessing dynamically generated models specifications:
```ts
import { modelsSpecs } from "../.generated";
```

### Usage

Run `pnpm build` and `npx prisma generate` to make generated contents available from sources
18 changes: 13 additions & 5 deletions src/.generated/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// @ts-ignore
export * from "../../dist/.generated";
const _generated = require("../../dist/.generated");

declare module "." {
export const modelsSpecs: { [key: string]: any; };
}
type ModelsSpecs = {
[key: string]: {
fields: Set<string>,
relations: Record<string, string>;
};
};

interface Generated {
modelsSpecs: ModelsSpecs;
}

export const { modelsSpecs } = _generated as Generated;
15 changes: 14 additions & 1 deletion src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { version } from "../package.json";
import { generatorHandler, type EnvValue } from "@prisma/generator-helper";
import { parseEnvValue } from "@prisma/internals";
import { promises as fs } from "fs";
import { promises as fs, unlink } from "fs";
import { Project, SourceFile } from "ts-morph";
import { generate as generateSpecs } from "./generators/specs";
import { generate as generateSchemas } from "./generators/schemas";
Expand Down Expand Up @@ -58,6 +58,18 @@ generatorHandler({
// Save ts-morph project
ctx.project.saveSync();

// zzz
try {
await fs.unlink(path.join(ctx.outputDirPath, "index.d.ts"));
} catch (e) {}
try {
await fs.unlink(path.join(ctx.outputDirPath, "index.js"));
} catch (e) {}
try {
await fs.unlink(path.join(ctx.outputDirPath, "index.js.map"));
} catch (e) {}


// Build swc transpiler options
const swcOptions: Options = {
jsc: {
Expand All @@ -79,6 +91,7 @@ generatorHandler({
// Retrieve generated file paths
const generatedFilesPaths = fg.sync([`${ctx.outputDirPath}/**/*`]);


console.time("swc");
generatedFilesPaths.forEach((filePath) => {
try {
Expand Down
1 change: 1 addition & 0 deletions tests/clauses.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { clauses, parentClauses, extendClauses, ignoredClauses, notSupportedClauses } from "../src/clauses";
import { modelsSpecs } from "../src/.generated";

describe.skip("clauses.ts file", () => {
const implementedClauses = new Set([...parentClauses, ...extendClauses, ...ignoredClauses, ...notSupportedClauses]);
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"strict": true
},
"include": ["./src/**/*.ts"],
"exclude": ["**/*.template.ts", "./dist/**/*"]
"exclude": ["**/*.template.ts", "dist"]
}

0 comments on commit 4834886

Please sign in to comment.