-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(nextjs): Prework for wrapping data-fetching functions (#5508)
This is a number of boring structural changes pulled out of #5503 in order to make it easier to review. Included changes: - Create folders for loaders and templates, and move the existing loader and template into their respective new folders. - Convert the `LoaderThis` type into a generic, so that each loader can specify its own options but share everything specified by webpack. - Since we are only going to support wrapping for pages written in ESM, make sure that templates are ESM, even if the CJS version of the SDK is being used. This required creating a build script, which in turn required updating our ESLint config. - Add/clarify comments in existing loader files.
- Loading branch information
1 parent
6ea53ed
commit 57dee8e
Showing
8 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
); |
15 changes: 5 additions & 10 deletions
15
packages/nextjs/src/config/prefixLoader.ts → ...nextjs/src/config/loaders/prefixLoader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// TODO Use real webpack types | ||
export type LoaderThis<Options> = { | ||
// 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; | ||
}; |
3 changes: 2 additions & 1 deletion
3
...nextjs/src/config/prefixLoaderTemplate.ts → .../config/templates/prefixLoaderTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters