Skip to content

Commit

Permalink
fix: Correctly generate import path
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge committed Jan 25, 2024
1 parent 5118651 commit 0ff1424
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 3 additions & 1 deletion example/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ generator client {
}

generator custom_generator {
provider = "prisma-generator-fake-data"
///in your project, you'll use it like this
///provider = "prisma-generator-fake-data"
provider = "ts-node ../src/bin.ts"
extraImport = "import {fakeSettings} from './fakeData.utils'"
extraExport = "export * from './fakeData.utils'"
}
Expand Down
17 changes: 11 additions & 6 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
dependencies:
"@prisma/engines-version" "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584"

"@prisma/client@^5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.8.1.tgz#7815ec51c0ca2a6de219c02e7846701ae3baf240"
integrity sha512-xQtMPfbIwLlbm0VVIVQY2yqQVOxPwRQhvIp7Z3m2900g1bu/zRHKhYZJQWELqmjl6d8YwBy0K2NvMqh47v1ubw==

"@prisma/[email protected]":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.8.1.tgz#704daa36919b0fc4d227260ecebfa1c94b155b07"
Expand Down Expand Up @@ -78,7 +83,7 @@
"@prisma/engines-version" "5.8.1-1.78caf6feeaed953168c64e15a249c3e9a033ebe2"
"@prisma/get-platform" "5.8.1"

"@prisma/[email protected]", "@prisma/generator-helper@^5.0.0":
"@prisma/[email protected]", "@prisma/generator-helper@^5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@prisma/generator-helper/-/generator-helper-5.8.1.tgz#11d226bf004839763375303a7a081913796df06b"
integrity sha512-2EDd0o+GHfbX1dtw5BnfOz3hQB7AtYrwe4YNiKfo2UDBvB/ne/ChZa3b/vBm/GKpjW2Xaymct8D9oIHev3juzQ==
Expand All @@ -92,7 +97,7 @@
dependencies:
"@prisma/debug" "5.8.1"

"@prisma/internals@^5.0.0":
"@prisma/internals@^5.8.1":
version "5.8.1"
resolved "https://registry.yarnpkg.com/@prisma/internals/-/internals-5.8.1.tgz#cb73784f64846a65efe74f5f563ec8908ac857e9"
integrity sha512-9okoCgLeMqql58IbEG3YmzgNLRUQdN+qZUYp2DojWC7VAmL9TSOKQ5Dcc0588cKAsCBBDUQ2jfdflorYkzeFKw==
Expand Down Expand Up @@ -182,12 +187,12 @@ make-error@^1.1.1:
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

"prisma-generator-fake-data@file:..":
version "0.13.0"
version "0.14.0"
dependencies:
"@faker-js/faker" "^8.0.2"
"@prisma/client" "^5.0.0"
"@prisma/generator-helper" "^5.0.0"
"@prisma/internals" "^5.0.0"
"@prisma/client" "^5.8.1"
"@prisma/generator-helper" "^5.8.1"
"@prisma/internals" "^5.8.1"
decimal.js "^10.4.3"
tiny-invariant "^1.3.1"

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"dependencies": {
"@faker-js/faker": "^8.0.2",
"@prisma/client": "^5.0.0",
"@prisma/generator-helper": "^5.0.0",
"@prisma/internals": "^5.0.0",
"@prisma/client": "^5.8.1",
"@prisma/generator-helper": "^5.8.1",
"@prisma/internals": "^5.8.1",
"decimal.js": "^10.4.3",
"tiny-invariant": "^1.3.1"
},
Expand All @@ -32,7 +32,7 @@
"generate-changelog": "^1.8.0",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"prisma": "^5.0.0",
"prisma": "^5.8.1",
"release-it": "^15.9.3",
"typescript": "^5.0.2",
"vitest": "^0.29.8"
Expand Down
20 changes: 15 additions & 5 deletions src/utils/generatorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { GeneratorOptions } from '@prisma/generator-helper';

export function extractClientPath(options: GeneratorOptions) {
return (
options.otherGenerators.find(
(g) => g?.provider?.value === 'prisma-client-js',
)?.output?.value || undefined
);
const clientPath = options.otherGenerators.find(
(g) => g?.provider?.value === 'prisma-client-js',
)?.output?.value;

/**
* not sure what changed, but this value was undefined before
* and now it's set to the full path of the client (including
* the user folder etc). If we detect that, we just return
* the @prisma/client string
*/
if (clientPath?.includes('node_modules/@prisma/client')) {
return '@prisma/client';
}

return clientPath || undefined;
}

0 comments on commit 0ff1424

Please sign in to comment.