Skip to content

feat(sdk): read schema path from package.json - #3566

Merged
timsuchanek merged 8 commits into
masterfrom
feat/package-json-schema-path
Sep 14, 2020
Merged

timsuchanek merged 8 commits into
masterfrom
feat/package-json-schema-path

Conversation

@flaviaan

@flaviaan flaviaan commented Sep 9, 2020 •

Copy link
Copy Markdown
Contributor

Closes #3144

  • Schema path can now be configured in the nearest package.json file in a prisma.schema property
  • CLI will also try to read a .env file next to the path provided in the nearest package.json, if there's one
  • Better support for yarn workspaces (works even when running cli from a child package)
  • Added testing for getSchemaPath and getSchemaPathSync

@CLAassistant

CLAassistant commented Sep 9, 2020 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@flaviaan flaviaan changed the title feat(sdk): read schema path from package.json [WIP] feat(sdk): read schema path from package.json Sep 9, 2020
@janpio
janpio marked this pull request as draft September 9, 2020 15:19
@flaviaan flaviaan changed the title [WIP] feat(sdk): read schema path from package.json feat(sdk): read schema path from package.json Sep 9, 2020
@flaviaan
flaviaan marked this pull request as ready for review September 11, 2020 09:22
Comment thread src/packages/cli/src/bin.ts Resolved
Comment on lines +63 to +64
getSchemaPathFromPackageJson,
getSchemaPathFromPackageJsonSync,

@flaviaan flaviaan Sep 11, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know whether we want to expose these helpers on the SDK. Let me know

Comment on lines +229 to +234
export function getSchemaPathSyncInternal(
schemaPathFromArgs?: string,
opts: { cwd: string } = {
cwd: process.cwd(),
},
): string | null {

@flaviaan flaviaan Sep 11, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we actually want to make this signature the exported one on the SDK. While it was made to ease testing, it could be useful for SDK tinkerers as well. The goal here was to minimize changes of the surface API (although it wouldn't be a breaking change anyway), but I'm happy to expose that one instead. Same goes for the getSchemaPathInternal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not clear on the highlighted code, but the exported getSchemaPathSync function now just calls that "internal" one)

Comment on lines +1 to +5
{
"name": "yarn-workspaces",
"workspaces": ["packages/*"],
"private": true
} No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a bunch of fixtures to match the current style of testing. I can as well come up with some utilities to dynamically write these fixtures in tmp and clean them up for each tests. That's what we used to do in Nexus.

Comment thread src/packages/cli/src/bin.ts Resolved
@Jolg42
Jolg42 self-requested a review September 11, 2020 10:01
Comment thread src/packages/sdk/src/cli/getSchema.ts Outdated
}

// in case the normal schema path doesn't exist, try the npm base dir
// 4. In case no schema can't be found there, try the npm-based INIT_CWD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 4. In case no schema can't be found there, try the npm-based INIT_CWD
// 4. In case no schema can be found there, try the npm-based INIT_CWD

Comment on lines -37 to -40
if (process.env.INIT_CWD) {
return (
(await getRelativeSchemaPath(process.env.INIT_CWD)) ||
(await resolveYarnSchema())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the INIT_CWD logic. As seen with Tim, it looks like INIT_CWD is always process.cwd() anyway.

If you want your script to use different behavior based on what subdirectory you’re in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run

See the documentation full doc here: https://docs.npmjs.com/cli/run-script

@timsuchanek timsuchanek added this to the Release 2.7.0 milestone Sep 14, 2020
@timsuchanek
timsuchanek merged commit f870b2c into master Sep 14, 2020
@timsuchanek
timsuchanek deleted the feat/package-json-schema-path branch September 14, 2020 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to configure custom schema location instead of requiring --schema arg

4 participants