-
Notifications
You must be signed in to change notification settings - Fork 18
feat(codegen): disallow src in fileName #87
Conversation
Todos:
|
@ricokahler let me know what you think about these new options! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement! I think this will make the DX of the lib a lot better.
I think i caught few smaller things and I'm not sure I understand the benefit of bundling via webpack. Let me know what you think!
@@ -6,7 +6,7 @@ import Layout from '../components/layout' | |||
import SEO from '../components/seo' | |||
import { rhythm } from '../utils/typography' | |||
|
|||
import { BlogIndexQuery } from '../../gen/graphql-types' | |||
import { BlogIndexQuery } from 'gatsby-ts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still valid? I didn't see anything that would enable importing like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoot, thanks for catching this 🤦♀️
!data || | ||
!data.site || | ||
!data.site.siteMetadata || | ||
!data.site.siteMetadata.title || | ||
!data.allMarkdownRemark | ||
) { | ||
throw new Error('no data') | ||
} | ||
const siteTitle = data.site.siteMetadata.title | ||
const posts = data.allMarkdownRemark.edges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old code but optional chaining would be nice here.
@@ -9,7 +9,7 @@ import * as React from 'react' | |||
import Helmet from 'react-helmet' | |||
import { useStaticQuery, graphql } from 'gatsby' | |||
import ensureKeys from '../helpers/ensure-keys' | |||
import { SeoQuery } from '../../graphql-types' | |||
import { SeoQuery } from 'gatsby-ts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
@@ -8,7 +8,7 @@ | |||
import * as React from 'react' | |||
import { useStaticQuery, graphql } from 'gatsby' | |||
import ensureKeys from '../helpers/ensure-keys' | |||
import { SiteTitleQuery } from '../../graphql-types' | |||
import { SiteTitleQuery } from 'gatsby-ts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
@@ -2,7 +2,7 @@ import * as React from 'react' | |||
import { useStaticQuery, graphql } from 'gatsby' | |||
import Img from 'gatsby-image' | |||
import ensureKeys from '../helpers/ensure-keys' | |||
import { ImageQuery } from '../../graphql-types' | |||
import { ImageQuery } from 'gatsby-ts' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
"typescript": "^3.7.5" | ||
"ts-loader": "^7.0.0", | ||
"typescript": "^3.7.5", | ||
"webpack": "^4.42.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: why did you decide to bundle this package webpack? Since these packages are meant for node, I don't see much value in bundling. And if you do decide to bundle, any reason why webpack over rollup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gatsby-node
has to be placed in the root, otherwise Gatsby can't find it. Because of this, all files inside src
is compiled to the root dir. I didn't want to ship unnecessary files, so I've been manually add/remove files to .npmignore
. This is quite cumbersome as the amount of files increase.
Rollup was no.1 choice, but for whatever reasons I couldn't make it work with various typescript plugins. I had little time, so I decided to go with webpack, which worked first try.
Now come to think about it, I've realized I don't really need to bundle, I can just npmignore the src dir 🤦♀️ Or just ship the whole thing.
}, | ||
externals: [ | ||
{ | ||
'fs-extra': 'commonjs2 fs-extra', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does putting commonjs
before the package here do? I've never seen this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's additional context so webpack understand that the module (fs-extra
) is a commonjs module, docs here. It's only useful for bundling node stuff. Without commonjs2
, webpack would look for fs-extra
in global space
type IsInSrc = (srcDir: string, fileDir: string) => boolean | ||
export const isInSrc: IsInSrc = (srcDir, fileDir) => { | ||
const relativePath = path.relative(srcDir, fileDir) | ||
return !relativePath.startsWith('..') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah this is smart!
graphql-codegen.config.d.ts | ||
utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this gitignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this is why having a second pair of eyes is so valuable, this is probably meant for .npmignore
but my 2am brain confused it with .gitignore
, which is wrong anyway 🤦♀️
expect(fs.writeFile).toMatchInlineSnapshot(` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
"example-directory/example-types.ts", | ||
undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm very curious on why this changed to undefined
. this seems unexpected. can you confirm this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right this isn't right, I'll run the test again
Thanks for reviewing @ricokahler, I shouldn't had tried to do more than one thing in one PR! I'll remove the bundle step & just use a normal |
Maybe it is easier to add a way to ignore certain files so avoid an infinite loop? |
Edit: Removed
useModule
, this PR now only add new improvements for the existingfileName
option.Update:
fileName
Outputing into src directory is now disallowed.
i.e
Dev stuff:
gatsby-plugin-graphql-codegen
now use webpack to bundle into a singlegatsby-node.js
.Related:
Close #85
Close #86