-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(nextjs): Prework for wrapping data-fetching functions #5508
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as childProcess from 'child_process'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current | ||
* process. Returns contents of `stdout`. | ||
*/ | ||
function run(cmd: string, options?: childProcess.ExecSyncOptions): string | Buffer { | ||
return childProcess.execSync(cmd, { stdio: 'inherit', ...options }); | ||
} | ||
|
||
run('yarn rollup -c rollup.npm.config.js'); | ||
|
||
// Regardless of whether nextjs is using the CJS or ESM version of our SDK, we want the code from our templates to be in | ||
// ESM (since we'll be adding it onto page files which are themselves written in ESM), so copy the ESM versions of the | ||
// templates over into the CJS build directory. (Building only the ESM version and sticking it in both locations is | ||
// something which in theory Rollup could do, but it would mean refactoring our Rollup helper functions, which isn't | ||
// worth it just for this.) | ||
const cjsTemplateDir = 'build/cjs/config/templates/'; | ||
const esmTemplateDir = 'build/esm/config/templates/'; | ||
fs.readdirSync(esmTemplateDir).forEach(templateFile => | ||
fs.copyFileSync(path.join(esmTemplateDir, templateFile), path.join(cjsTemplateDir, templateFile)), | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// TODO Use real webpack types | ||
export type LoaderThis<Options> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally optional but we could type this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Will do. UPDATE: Turns out TS can't handle it, at least not gracefully. Doing that make lines like const { distDir } = this.getOptions ? this.getOptions() : this.query error out with
Annoying that it won't let you even check to see if something is there, but not sure it's worth trying to convince it otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah right should have tried it out - my bad. I think you need to do the check something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, but then you run into microsoft/TypeScript#21732. (Specifically - switching to TS - can't live with it, can't live without it. |
||
// Loader options in Webpack 4 | ||
query?: Options; | ||
// Loader options in Webpack 5 | ||
getOptions?: () => Options; | ||
|
||
// Function to add outside file used by loader to `watch` process | ||
addDependency: (filepath: string) => void; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any | ||
(global as any).__rewriteFramesDistDir__ = '__DIST_DIR__'; | ||
|
||
// We need this to make this file an ESM module, which TS requires when using `isolatedModules`. | ||
// We need this to make this file an ESM module, which TS requires when using `isolatedModules`, but it doesn't affect | ||
// the end result - Rollup recognizes that it's a no-op and doesn't include it when building our code. | ||
export {}; |
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 think this is the kind of technical debt we will never get rid of. Let's leave it but take the learning that DRY has it's downsides in regards to rollup configs.
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.
Interesting - not sure I'd call this tech debt. This is a weird one-off, and I feel like quite often in those cases the answer isn't "make your thing (whatever it is) support the uncommon edge case" it's "find a workaround," which to me is exactly what this is, no?