Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable output directory #35

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

osdiab
Copy link
Collaborator

@osdiab osdiab commented Jan 28, 2022

Supercedes #33
Closes #32

  • Adds a configurable output directory to the plugin
  • Docs for that
  • Tightens up typings with strictness

Worked locally on my project.

@osdiab osdiab requested a review from ckastbjerg January 28, 2022 04:28
@osdiab
Copy link
Collaborator Author

osdiab commented Jan 28, 2022

@ckastbjerg not sure how we should make automated tests for this but it does work on my computer.

@@ -1,6 +1,9 @@
{
"compilerOptions": {
"declaration": true,
"strict": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tightened up the typings while i was at it

@@ -72,6 +72,30 @@ Now you just need to decide how you want to integrate `next-type-safe-routes` in

<img src="./example.gif" />

## Configuration
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

how are these docs @ckastbjerg ?

@osdiab
Copy link
Collaborator Author

osdiab commented Mar 11, 2022

@ckastbjerg would love a peek at this!

Copy link
Owner

@ckastbjerg ckastbjerg left a comment

Choose a reason for hiding this comment

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

@osdiab thanks so much for picking this up! Looks great. I left a few minor suggestions around naming but nothing blocking at all.

Also, I'm really sorry for letting you hang!!! 🙏 For personal reasons, I had to take a break from this project among other things. I should be more available in the future. But I want to make sure that I'm not a bottleneck here. So will prioritise getting releases more automated soon.

const withPlugins = require("next-compose-plugins");
const nextTypeSafePages = require("next-type-safe-routes/plugin");

module.exports = withPlugins([nextTypeSafePages], {
Copy link
Owner

Choose a reason for hiding this comment

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

I just tested this out in the example project, but it only worked for me with:

module.exports = withPlugins([nextTypeSafeRoutes], {
  nextTypeSafeRoutes: { outDir: "@types/custom-page-type-directory" },
});

Is this the intended interface? Or am I misunderstanding something?

Note, I haven't looked into the "correct" way of allowing options for plugins...


```js
const withPlugins = require("next-compose-plugins");
const nextTypeSafePages = require("next-type-safe-routes/plugin");
Copy link
Owner

Choose a reason for hiding this comment

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

I'm thinking this should be

Suggested change
const nextTypeSafePages = require("next-type-safe-routes/plugin");
const nextTypeSafeRoutes = require("next-type-safe-routes/plugin");

const withPlugins = require("next-compose-plugins");
const nextTypeSafePages = require("next-type-safe-routes/plugin");

module.exports = withPlugins([nextTypeSafePages], {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
module.exports = withPlugins([nextTypeSafePages], {
module.exports = withPlugins([nextTypeSafeRoutes], {

const writeTypesToDisc = ({ pagesDir, outDir: inputOutDir }: PathConfig) => {
const typeScriptFile = generateTypeScriptFile(pagesDir);
const srcDir = path.dirname(pagesDir);
const outDir = path.isAbsolute(inputOutDir)
Copy link
Owner

Choose a reason for hiding this comment

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

Nit pick! Just ignore if you disagree :)

I got a bit confused a bout the re-mapping of outDir to inputOutDir. Makes the code a bit hard to read IMO. How about naming this outDirAbsolute instead?

@ckastbjerg
Copy link
Owner

@ckastbjerg not sure how we should make automated tests for this but it does work on my computer.

Yeah, good question. Maybe we could look how some of the more mature Next.js plugins does it. But guessing it's not too common to test this aspect of it.

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.

configuration should allow custom destination for generated types.
3 participants