From 15376bb1df0ea1bd748d49c1029fe051bfebaeae Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 12 Jul 2024 12:58:28 +0200 Subject: [PATCH 1/6] fix(g directive): Notes formatting (#10940) --- .../commands/generate/directive/directive.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/generate/directive/directive.js b/packages/cli/src/commands/generate/directive/directive.js index 5b7aadf3a028..2141f48d40ab 100644 --- a/packages/cli/src/commands/generate/directive/directive.js +++ b/packages/cli/src/commands/generate/directive/directive.js @@ -114,9 +114,10 @@ export const handler = async (args) => { rollback: args.rollback, }) - const POST_RUN_INSTRUCTIONS = `Next steps...\n\n ${c.warning( - 'After modifying your directive, you can add it to your SDLs e.g.:', - )} + let notes = '' + const POST_RUN_INSTRUCTIONS = ` + ${c.warning('After modifying your directive, you can add it to your SDLs e.g.:')} + ${c.info('// example todo.sdl.js')} ${c.info('# Option A: Add it to a field')} type Todo { @@ -187,8 +188,11 @@ export const handler = async (args) => { }, { title: 'Next steps...', - task: (_ctx, task) => { - task.title = POST_RUN_INSTRUCTIONS + task: () => { + // Can't do this, since it strips formatting + // task.title = POST_RUN_INSTRUCTIONS + // Instead we just console.log the instructions at the end + notes = POST_RUN_INSTRUCTIONS }, }, ].filter(Boolean), @@ -200,6 +204,9 @@ export const handler = async (args) => { prepareForRollback(tasks) } await tasks.run() + if (notes) { + console.log(notes) + } } catch (e) { console.log(c.error(e.message)) process.exit(1) From 01d4f168402b39a7fe0666b32350165e3b5d3ff5 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Fri, 12 Jul 2024 14:27:52 +0200 Subject: [PATCH 2/6] feat(colors): Add more chalk colors. And prepare for chalk upgrade (#10939) --- .changesets/10939.md | 6 ++++++ .../api-server/src/logFormatter/formatters.ts | 3 ++- packages/cli-helpers/src/lib/colors.ts | 21 ++++++++++--------- .../dataMigrate/src/commands/upHandler.ts | 4 ++-- .../dataMigrate/src/lib/colors.ts | 13 +++++++++--- .../src/commands/deploy/helpers/helpers.js | 2 +- .../commands/generate/directive/directive.js | 6 +++--- packages/cli/src/commands/prismaHandler.js | 2 +- .../src/commands/setup/cache/cacheHandler.js | 5 ++--- .../custom-web-index-handler.js | 5 ++--- .../src/commands/setup/i18n/i18nHandler.js | 7 ++----- .../setup/monitoring/sentry/sentryHandler.ts | 2 +- .../setup/tsconfig/tsconfigHandler.js | 5 ++--- .../commands/setup/webpack/webpackHandler.js | 5 ++--- packages/cli/src/commands/test.js | 2 +- packages/cli/src/lib/colors.js | 9 ++++++-- .../cli/src/middleware/checkNodeVersion.js | 2 +- 17 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 .changesets/10939.md diff --git a/.changesets/10939.md b/.changesets/10939.md new file mode 100644 index 000000000000..571972ef9be6 --- /dev/null +++ b/.changesets/10939.md @@ -0,0 +1,6 @@ +- feat(colors): Add more chalk colors. And prepare for chalk upgrade (#10939) by @Tobbe + +Add more colors to `@redwoodjs/cli-helpers`. + +Breaking: No longer exporting `green` as a color. Use `tip` or `success` +instead depending on what you want to convey. diff --git a/packages/api-server/src/logFormatter/formatters.ts b/packages/api-server/src/logFormatter/formatters.ts index 8e36ba5d4373..63ac9d44d7ea 100644 --- a/packages/api-server/src/logFormatter/formatters.ts +++ b/packages/api-server/src/logFormatter/formatters.ts @@ -125,7 +125,8 @@ export const formatMessage = (logData: any) => { pretty = chalk.white(msg) } if (level === 'warn') { - pretty = chalk.magenta(msg) + const orange = '#ffa500' + pretty = chalk.hex(orange)(msg) } if (level === 'debug') { pretty = chalk.yellow(msg) diff --git a/packages/cli-helpers/src/lib/colors.ts b/packages/cli-helpers/src/lib/colors.ts index fe876011e14a..b584b75baca1 100644 --- a/packages/cli-helpers/src/lib/colors.ts +++ b/packages/cli-helpers/src/lib/colors.ts @@ -2,20 +2,21 @@ import chalk from 'chalk' /** * To keep a consistent color/style palette between cli packages, such as - * @redwood/cli and @redwood/create-redwood-app, please keep them compatible - * with one and another. We'll might split up and refactor these into a - * separate package when there is a strong motivation behind it. - * - * Current files: - * - * - packages/cli/src/lib/colors.js (this file) - * - packages/create-redwood-app/src/create-redwood-app.js + * @redwood/cli and @redwood/create-redwood-app, please only use the colors + * defined here. If you *really* can't find a color that fits your needs, + * it's better to add it here than to introduce a new one-off color in whatever + * package you're going to use it in. */ export const colors = { error: chalk.bold.red, - warning: chalk.keyword('orange'), - green: chalk.green, + warning: chalk.hex('#ffa500'), + success: chalk.green, info: chalk.grey, bold: chalk.bold, underline: chalk.underline, + note: chalk.blue, + tip: chalk.green, + important: chalk.magenta, + caution: chalk.red, + link: chalk.hex('#e8e8e8'), } diff --git a/packages/cli-packages/dataMigrate/src/commands/upHandler.ts b/packages/cli-packages/dataMigrate/src/commands/upHandler.ts index 35e3498a59cd..d2255aea61e4 100644 --- a/packages/cli-packages/dataMigrate/src/commands/upHandler.ts +++ b/packages/cli-packages/dataMigrate/src/commands/upHandler.ts @@ -50,7 +50,7 @@ export async function handler({ const pendingDataMigrations = await getPendingDataMigrations(db) if (!pendingDataMigrations.length) { - console.info(c.green(`\n${NO_PENDING_MIGRATIONS_MESSAGE}\n`)) + console.info(c.success(`\n${NO_PENDING_MIGRATIONS_MESSAGE}\n`)) process.exitCode = 0 return } @@ -221,7 +221,7 @@ function reportDataMigrations(counters: { }) { if (counters.run) { console.info( - c.green(`${counters.run} data migration(s) completed successfully.`), + c.success(`${counters.run} data migration(s) completed successfully.`), ) } if (counters.error) { diff --git a/packages/cli-packages/dataMigrate/src/lib/colors.ts b/packages/cli-packages/dataMigrate/src/lib/colors.ts index b32f9980d5c3..c5311265f44e 100644 --- a/packages/cli-packages/dataMigrate/src/lib/colors.ts +++ b/packages/cli-packages/dataMigrate/src/lib/colors.ts @@ -1,11 +1,18 @@ -// This file will eventually be deduplicated across the framework +// TODO: This file should be deduplicated across the framework // when we take the time to make architectural changes. import chalk from 'chalk' export default { error: chalk.bold.red, - warning: chalk.keyword('orange'), - green: chalk.green, + warning: chalk.hex('#ffa500'), + success: chalk.green, + info: chalk.grey, bold: chalk.bold, + underline: chalk.underline, + note: chalk.blue, + tip: chalk.green, + important: chalk.magenta, + caution: chalk.red, + link: chalk.hex('#e8e8e8'), } diff --git a/packages/cli/src/commands/deploy/helpers/helpers.js b/packages/cli/src/commands/deploy/helpers/helpers.js index 234dba6fb325..2c6ac51ec157 100644 --- a/packages/cli/src/commands/deploy/helpers/helpers.js +++ b/packages/cli/src/commands/deploy/helpers/helpers.js @@ -47,7 +47,7 @@ export const deployHandler = async ({ build, prisma, dm: dataMigrate }) => { const joinedCommands = commandSet.join(' && ') - console.log(c.green(`\nRunning:\n`) + `${joinedCommands} \n`) + console.log(c.note(`\nRunning:\n`) + `${joinedCommands} \n`) return execa(joinedCommands, { shell: true, diff --git a/packages/cli/src/commands/generate/directive/directive.js b/packages/cli/src/commands/generate/directive/directive.js index 2141f48d40ab..e03e9281dc92 100644 --- a/packages/cli/src/commands/generate/directive/directive.js +++ b/packages/cli/src/commands/generate/directive/directive.js @@ -116,18 +116,18 @@ export const handler = async (args) => { let notes = '' const POST_RUN_INSTRUCTIONS = ` - ${c.warning('After modifying your directive, you can add it to your SDLs e.g.:')} + ${c.note('After modifying your directive, you can add it to your SDLs e.g.:')} ${c.info('// example todo.sdl.js')} ${c.info('# Option A: Add it to a field')} type Todo { id: Int! - body: String! ${c.green(`@${args.name}`)} + body: String! ${c.tip(`@${args.name}`)} } ${c.info('# Option B: Add it to query/mutation')} type Query { - todos: [Todo] ${c.green(`@${args.name}`)} + todos: [Todo] ${c.tip(`@${args.name}`)} } ` diff --git a/packages/cli/src/commands/prismaHandler.js b/packages/cli/src/commands/prismaHandler.js index f513c91e3412..4e6e697d6249 100644 --- a/packages/cli/src/commands/prismaHandler.js +++ b/packages/cli/src/commands/prismaHandler.js @@ -61,7 +61,7 @@ export const handler = async ({ _, $0, commands = [], ...options }) => { } console.log() - console.log(c.green('Running Prisma CLI...')) + console.log(c.note('Running Prisma CLI...')) console.log(c.underline('$ yarn prisma ' + args.join(' '))) console.log() diff --git a/packages/cli/src/commands/setup/cache/cacheHandler.js b/packages/cli/src/commands/setup/cache/cacheHandler.js index 81f9305e7bb3..aa3d9c09ee61 100644 --- a/packages/cli/src/commands/setup/cache/cacheHandler.js +++ b/packages/cli/src/commands/setup/cache/cacheHandler.js @@ -1,6 +1,5 @@ import path from 'path' -import chalk from 'chalk' import fs from 'fs-extra' import { Listr } from 'listr2' @@ -56,8 +55,8 @@ export const handler = async ({ client, force }) => { title: 'One more thing...', task: (_ctx, task) => { task.title = `One more thing...\n - ${c.green('Check out the Service Cache docs for config and usage:')} - ${chalk.hex('#e8e8e8')('https://redwoodjs.com/docs/services#caching')} + ${c.tip('Check out the Service Cache docs for config and usage:')} + ${c.link('https://redwoodjs.com/docs/services#caching')} ` }, }, diff --git a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js index 0314375e9ebf..1da59693a20e 100644 --- a/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js +++ b/packages/cli/src/commands/setup/custom-web-index/custom-web-index-handler.js @@ -1,6 +1,5 @@ import path from 'path' -import chalk from 'chalk' import fs from 'fs-extra' import { Listr } from 'listr2' @@ -48,10 +47,10 @@ export const handler = async ({ force }) => { title: 'One more thing...', task: (_ctx, task) => { task.title = `One more thing...\n - ${c.green( + ${c.tip( 'Quick link to the docs on configuring a custom entry point for your RW app', )} - ${chalk.hex('#e8e8e8')('https://redwoodjs.com/docs/custom-web-index')} + ${c.link('https://redwoodjs.com/docs/custom-web-index')} ` }, }, diff --git a/packages/cli/src/commands/setup/i18n/i18nHandler.js b/packages/cli/src/commands/setup/i18n/i18nHandler.js index 737ff65d5963..240c666d4e31 100644 --- a/packages/cli/src/commands/setup/i18n/i18nHandler.js +++ b/packages/cli/src/commands/setup/i18n/i18nHandler.js @@ -1,6 +1,5 @@ import path from 'path' -import chalk from 'chalk' import execa from 'execa' import fs from 'fs-extra' import { Listr } from 'listr2' @@ -178,10 +177,8 @@ export const handler = async ({ force }) => { title: 'One more thing...', task: (_ctx, task) => { task.title = `One more thing...\n - ${c.green('Quick link to the docs:')}\n - ${chalk.hex('#e8e8e8')( - 'https://react.i18next.com/guides/quick-start/', - )} + ${c.tip('Quick link to the docs:')}\n + ${c.link('https://react.i18next.com/guides/quick-start/')} ` }, }, diff --git a/packages/cli/src/commands/setup/monitoring/sentry/sentryHandler.ts b/packages/cli/src/commands/setup/monitoring/sentry/sentryHandler.ts index f36e62c4cb1f..e2f654644c3e 100644 --- a/packages/cli/src/commands/setup/monitoring/sentry/sentryHandler.ts +++ b/packages/cli/src/commands/setup/monitoring/sentry/sentryHandler.ts @@ -144,7 +144,7 @@ export const handler = async ({ force }: Args) => { title: 'One more thing...', task: (ctx) => { notes.push( - colors.green( + colors.important( 'You will need to add `SENTRY_DSN` to `includeEnvironmentVariables` in redwood.toml.', ), ) diff --git a/packages/cli/src/commands/setup/tsconfig/tsconfigHandler.js b/packages/cli/src/commands/setup/tsconfig/tsconfigHandler.js index 29ec2c5b4f29..2ff12c3e745c 100644 --- a/packages/cli/src/commands/setup/tsconfig/tsconfigHandler.js +++ b/packages/cli/src/commands/setup/tsconfig/tsconfigHandler.js @@ -1,6 +1,5 @@ import path from 'path' -import chalk from 'chalk' import { Listr } from 'listr2' import { errorTelemetry } from '@redwoodjs/telemetry' @@ -50,8 +49,8 @@ export const handler = async ({ force }) => { title: 'One more thing...', task: (_ctx, task) => { task.title = `One more thing...\n - ${c.green('Quick link to the docs on configuring TypeScript')} - ${chalk.hex('#e8e8e8')('https://redwoodjs.com/docs/typescript')} + ${c.tip('Quick link to the docs on configuring TypeScript')} + ${c.link('https://redwoodjs.com/docs/typescript')} ` }, }, diff --git a/packages/cli/src/commands/setup/webpack/webpackHandler.js b/packages/cli/src/commands/setup/webpack/webpackHandler.js index 85d8e09e5c0e..d0acc643aaf1 100644 --- a/packages/cli/src/commands/setup/webpack/webpackHandler.js +++ b/packages/cli/src/commands/setup/webpack/webpackHandler.js @@ -1,6 +1,5 @@ import path from 'path' -import chalk from 'chalk' import fs from 'fs-extra' import { Listr } from 'listr2' @@ -36,10 +35,10 @@ export const handler = async ({ force }) => { title: 'One more thing...', task: (_ctx, task) => { task.title = `One more thing...\n - ${c.green( + ${c.tip( 'Quick link to the docs on configuring custom webpack config:', )} - ${chalk.hex('#e8e8e8')( + ${c.link( 'https://redwoodjs.com/docs/webpack-configuration#configuring-webpack', )} ` diff --git a/packages/cli/src/commands/test.js b/packages/cli/src/commands/test.js index c7efba2ea862..6c8bfc0fbba1 100644 --- a/packages/cli/src/commands/test.js +++ b/packages/cli/src/commands/test.js @@ -33,7 +33,7 @@ export const builder = (yargs) => { default: true, }) .epilogue( - `For all available flags, run jest cli directly ${c.green( + `For all available flags, run jest cli directly ${c.tip( 'yarn jest --help', )}\n\nAlso see the ${terminalLink( 'Redwood CLI Reference', diff --git a/packages/cli/src/lib/colors.js b/packages/cli/src/lib/colors.js index 5ce6635485a9..0bbed5ee01bb 100644 --- a/packages/cli/src/lib/colors.js +++ b/packages/cli/src/lib/colors.js @@ -13,9 +13,14 @@ import chalk from 'chalk' */ export default { error: chalk.bold.red, - warning: chalk.keyword('orange'), - green: chalk.green, + warning: chalk.hex('#ffa500'), + success: chalk.green, info: chalk.grey, bold: chalk.bold, underline: chalk.underline, + note: chalk.blue, + tip: chalk.green, + important: chalk.magenta, + caution: chalk.red, + link: chalk.hex('#e8e8e8'), } diff --git a/packages/cli/src/middleware/checkNodeVersion.js b/packages/cli/src/middleware/checkNodeVersion.js index db41cf5144ab..42eca0cd4b17 100644 --- a/packages/cli/src/middleware/checkNodeVersion.js +++ b/packages/cli/src/middleware/checkNodeVersion.js @@ -18,7 +18,7 @@ export function checkNodeVersion() { checks.message = [ `Your Node.js version is ${c.warning( pVersion, - )}, but Redwood requires ${c.green(`>=${LOWER_BOUND}`)}.`, + )}, but Redwood requires ${c.important(`>=${LOWER_BOUND}`)}.`, 'Upgrade your Node.js version using `nvm` or a similar tool. See https://redwoodjs.com/docs/how-to/using-nvm.', ].join('\n') From 3659ff71687884a8d2e78035c72b31d4482c0e9d Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Sat, 13 Jul 2024 19:40:22 +0700 Subject: [PATCH 3/6] chore(middleware): Move middleware out of rwjs/vite -> rwjs/web/middleware (#10917) Co-authored-by: GitHub Actions <> Co-authored-by: Tobbe Lundberg --- .../web/src/middleware/self.mts | 2 +- .../dbAuth/middleware/package.json | 4 +- .../__tests__/initDbAuthMiddleware.test.ts | 2 +- .../dbAuth/middleware/src/index.ts | 7 +++- .../supabase/middleware/package.json | 2 +- .../initSupabaseAuthMiddleware.test.ts | 2 +- .../supabase/middleware/src/index.ts | 2 +- .../supabase/middleware/src/util.ts | 2 +- packages/ogimage-gen/package.json | 2 +- .../ogimage-gen/src/OgImageMiddleware.test.ts | 2 +- packages/ogimage-gen/src/OgImageMiddleware.ts | 2 +- packages/vite/package.json | 10 ++--- packages/vite/src/devFeServer.ts | 2 +- packages/vite/src/middleware/index.ts | 2 - .../src/middleware/invokeMiddleware.test.ts | 7 ++-- .../vite/src/middleware/invokeMiddleware.ts | 10 +++-- packages/vite/src/middleware/register.test.ts | 10 +++-- packages/vite/src/middleware/register.ts | 16 ++++---- packages/vite/src/middleware/types.ts | 27 ++----------- packages/vite/src/rsc/rscRequestHandler.ts | 2 +- packages/vite/src/runFeServer.ts | 2 +- .../streaming/createReactStreamingHandler.ts | 4 +- packages/vite/src/streaming/streamHelpers.ts | 4 +- packages/web/package.json | 40 +++++++++++-------- .../src/server}/MiddlewareRequest.test.ts | 0 .../src/server}/MiddlewareRequest.ts | 0 .../src/server}/MiddlewareResponse.test.ts | 0 .../src/server}/MiddlewareResponse.ts | 0 packages/web/src/server/middleware.ts | 28 +++++++++++++ packages/web/tsconfig.json | 15 ++++++- yarn.lock | 24 ++++++----- 31 files changed, 131 insertions(+), 101 deletions(-) rename packages/{vite/src/middleware => web/src/server}/MiddlewareRequest.test.ts (100%) rename packages/{vite/src/middleware => web/src/server}/MiddlewareRequest.ts (100%) rename packages/{vite/src/middleware => web/src/server}/MiddlewareResponse.test.ts (100%) rename packages/{vite/src/middleware => web/src/server}/MiddlewareResponse.ts (100%) create mode 100644 packages/web/src/server/middleware.ts diff --git a/__fixtures__/test-project-rsc-kitchen-sink/web/src/middleware/self.mts b/__fixtures__/test-project-rsc-kitchen-sink/web/src/middleware/self.mts index 43361c72e168..57c94bb1c243 100644 --- a/__fixtures__/test-project-rsc-kitchen-sink/web/src/middleware/self.mts +++ b/__fixtures__/test-project-rsc-kitchen-sink/web/src/middleware/self.mts @@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url' import type { MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/middleware' +} from '@redwoodjs/web/middleware' const __filename = fileURLToPath(import.meta.url) diff --git a/packages/auth-providers/dbAuth/middleware/package.json b/packages/auth-providers/dbAuth/middleware/package.json index 2eecd7cb148a..560854a53f48 100644 --- a/packages/auth-providers/dbAuth/middleware/package.json +++ b/packages/auth-providers/dbAuth/middleware/package.json @@ -31,13 +31,13 @@ "test:watch": "vitest watch" }, "dependencies": { - "@redwoodjs/auth-dbauth-api": "workspace:*" + "@redwoodjs/auth-dbauth-api": "workspace:*", + "@redwoodjs/web": "workspace:*" }, "devDependencies": { "@redwoodjs/api": "workspace:*", "@redwoodjs/framework-tools": "workspace:*", "@redwoodjs/graphql-server": "workspace:*", - "@redwoodjs/vite": "workspace:*", "@types/aws-lambda": "8.10.138", "ts-toolbelt": "9.6.0", "tsx": "4.15.6", diff --git a/packages/auth-providers/dbAuth/middleware/src/__tests__/initDbAuthMiddleware.test.ts b/packages/auth-providers/dbAuth/middleware/src/__tests__/initDbAuthMiddleware.test.ts index 4a92ad8bf52b..67d0b34ab0f7 100644 --- a/packages/auth-providers/dbAuth/middleware/src/__tests__/initDbAuthMiddleware.test.ts +++ b/packages/auth-providers/dbAuth/middleware/src/__tests__/initDbAuthMiddleware.test.ts @@ -6,7 +6,7 @@ import { MiddlewareRequest as MWRequest, MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/middleware' +} from '@redwoodjs/web/middleware' import { middlewareDefaultAuthProviderState } from '../../../../../auth/dist/AuthProvider/AuthProviderState' import type { DbAuthMiddlewareOptions } from '../index' diff --git a/packages/auth-providers/dbAuth/middleware/src/index.ts b/packages/auth-providers/dbAuth/middleware/src/index.ts index b655b7071766..84f5528ba879 100644 --- a/packages/auth-providers/dbAuth/middleware/src/index.ts +++ b/packages/auth-providers/dbAuth/middleware/src/index.ts @@ -6,8 +6,11 @@ import { dbAuthSession, } from '@redwoodjs/auth-dbauth-api' import type { GetCurrentUser } from '@redwoodjs/graphql-server' -import type { Middleware, MiddlewareRequest } from '@redwoodjs/vite/middleware' -import { MiddlewareResponse } from '@redwoodjs/vite/middleware' +import { MiddlewareResponse } from '@redwoodjs/web/dist/server/middleware' +import type { + Middleware, + MiddlewareRequest, +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } import { defaultGetRoles } from './defaultGetRoles' diff --git a/packages/auth-providers/supabase/middleware/package.json b/packages/auth-providers/supabase/middleware/package.json index 468d7231ac94..1bc2b59bff26 100644 --- a/packages/auth-providers/supabase/middleware/package.json +++ b/packages/auth-providers/supabase/middleware/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "@redwoodjs/auth-supabase-api": "workspace:*", + "@redwoodjs/web": "workspace:*", "@supabase/ssr": "0.3.0" }, "devDependencies": { @@ -39,7 +40,6 @@ "@redwoodjs/auth": "workspace:*", "@redwoodjs/framework-tools": "workspace:*", "@redwoodjs/graphql-server": "workspace:*", - "@redwoodjs/vite": "workspace:*", "@types/aws-lambda": "8.10.138", "ts-toolbelt": "9.6.0", "tsx": "4.15.6", diff --git a/packages/auth-providers/supabase/middleware/src/__tests__/initSupabaseAuthMiddleware.test.ts b/packages/auth-providers/supabase/middleware/src/__tests__/initSupabaseAuthMiddleware.test.ts index 08adf13a5cbe..b4d5027ce586 100644 --- a/packages/auth-providers/supabase/middleware/src/__tests__/initSupabaseAuthMiddleware.test.ts +++ b/packages/auth-providers/supabase/middleware/src/__tests__/initSupabaseAuthMiddleware.test.ts @@ -8,7 +8,7 @@ import { authDecoder } from '@redwoodjs/auth-supabase-api' import { MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/middleware' +} from '@redwoodjs/web/middleware' import initSupabaseAuthMiddleware from '../index' import type { SupabaseAuthMiddlewareOptions } from '../index' diff --git a/packages/auth-providers/supabase/middleware/src/index.ts b/packages/auth-providers/supabase/middleware/src/index.ts index 49c5c4360ee2..f411d9dad57c 100644 --- a/packages/auth-providers/supabase/middleware/src/index.ts +++ b/packages/auth-providers/supabase/middleware/src/index.ts @@ -5,7 +5,7 @@ import type { Middleware, MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/middleware' +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } import { clearAuthState } from './util' diff --git a/packages/auth-providers/supabase/middleware/src/util.ts b/packages/auth-providers/supabase/middleware/src/util.ts index b67d5b47850c..550be4bb12b1 100644 --- a/packages/auth-providers/supabase/middleware/src/util.ts +++ b/packages/auth-providers/supabase/middleware/src/util.ts @@ -7,7 +7,7 @@ import { throwSupabaseSettingsError } from '@redwoodjs/auth-supabase-api' import type { MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/middleware' +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } /** * Creates Supabase Server Client used to get the session cookie (only) * from a given collection of auth cookies diff --git a/packages/ogimage-gen/package.json b/packages/ogimage-gen/package.json index de9e41e504e2..a195020d1d74 100644 --- a/packages/ogimage-gen/package.json +++ b/packages/ogimage-gen/package.json @@ -41,7 +41,7 @@ "@redwoodjs/internal": "workspace:*", "@redwoodjs/project-config": "workspace:*", "@redwoodjs/router": "workspace:*", - "@redwoodjs/vite": "workspace:*", + "@redwoodjs/web": "workspace:*", "fast-glob": "3.3.2", "lodash": "4.17.21", "react": "19.0.0-beta-04b058868c-20240508", diff --git a/packages/ogimage-gen/src/OgImageMiddleware.test.ts b/packages/ogimage-gen/src/OgImageMiddleware.test.ts index 5a87d067775b..7d3106827578 100644 --- a/packages/ogimage-gen/src/OgImageMiddleware.test.ts +++ b/packages/ogimage-gen/src/OgImageMiddleware.test.ts @@ -7,7 +7,7 @@ import { vi, describe, beforeEach, afterEach, test, expect } from 'vitest' import type { RWRouteManifestItem } from '@redwoodjs/internal' import { ensurePosixPath } from '@redwoodjs/project-config' -import { MiddlewareResponse } from '@redwoodjs/vite/middleware' +import { MiddlewareResponse } from '@redwoodjs/web/middleware' import OgImageMiddleware from './OgImageMiddleware' diff --git a/packages/ogimage-gen/src/OgImageMiddleware.ts b/packages/ogimage-gen/src/OgImageMiddleware.ts index 92f10882189c..0b418ab579e6 100644 --- a/packages/ogimage-gen/src/OgImageMiddleware.ts +++ b/packages/ogimage-gen/src/OgImageMiddleware.ts @@ -14,7 +14,7 @@ import type { MiddlewareInvokeOptions, MiddlewareRequest, MiddlewareResponse, -} from '@redwoodjs/vite/dist/middleware' +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } import { getRoutesList } from './getRoutesList.js' import { OGIMAGE_DEFAULTS } from './hooks.js' diff --git a/packages/vite/package.json b/packages/vite/package.json index 53d8fa9d503f..041392eb4c73 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -40,11 +40,7 @@ "types": "./dist/react-server-dom-webpack/node-loader.d.ts", "default": "./dist/react-server-dom-webpack/node-loader.js" }, - "./bins/rw-vite-build.mjs": "./bins/rw-vite-build.mjs", - "./middleware": { - "types": "./dist/middleware/index.d.ts", - "default": "./dist/middleware/index.js" - } + "./bins/rw-vite-build.mjs": "./bins/rw-vite-build.mjs" }, "bin": { "rw-dev-fe": "./dist/devFeServer.js", @@ -79,7 +75,7 @@ "@swc/core": "1.5.27", "@vitejs/plugin-react": "4.2.1", "@whatwg-node/fetch": "0.9.17", - "@whatwg-node/server": "0.9.34", + "@whatwg-node/server": "0.9.36", "acorn-loose": "8.4.0", "buffer": "6.0.3", "busboy": "^1.6.0", @@ -94,7 +90,7 @@ "react-server-dom-webpack": "19.0.0-beta-04b058868c-20240508", "vite": "5.3.1", "vite-plugin-cjs-interop": "2.1.1", - "vite-plugin-node-polyfills": "^0.22.0", + "vite-plugin-node-polyfills": "0.22.0", "yargs-parser": "21.1.1" }, "devDependencies": { diff --git a/packages/vite/src/devFeServer.ts b/packages/vite/src/devFeServer.ts index 30644f3e9f8e..b18b12da0b66 100644 --- a/packages/vite/src/devFeServer.ts +++ b/packages/vite/src/devFeServer.ts @@ -13,11 +13,11 @@ import { createPerRequestMap, createServerStorage, } from '@redwoodjs/server-store' +import type { Middleware } from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } import { registerFwGlobalsAndShims } from './lib/registerFwGlobalsAndShims.js' import { invoke } from './middleware/invokeMiddleware.js' import { createMiddlewareRouter } from './middleware/register.js' -import type { Middleware } from './middleware/types.js' import { rscRoutesAutoLoader } from './plugins/vite-plugin-rsc-routes-auto-loader.js' import { createRscRequestHandler } from './rsc/rscRequestHandler.js' import { collectCssPaths, componentsModules } from './streaming/collectCss.js' diff --git a/packages/vite/src/middleware/index.ts b/packages/vite/src/middleware/index.ts index e5857b0fc17a..fdc633235f7d 100644 --- a/packages/vite/src/middleware/index.ts +++ b/packages/vite/src/middleware/index.ts @@ -1,3 +1 @@ -export * from './MiddlewareRequest.js' -export * from './MiddlewareResponse.js' export * from './types.js' diff --git a/packages/vite/src/middleware/invokeMiddleware.test.ts b/packages/vite/src/middleware/invokeMiddleware.test.ts index 28a4ca38e6db..fdf667bfc04c 100644 --- a/packages/vite/src/middleware/invokeMiddleware.test.ts +++ b/packages/vite/src/middleware/invokeMiddleware.test.ts @@ -1,14 +1,13 @@ import type { MockInstance } from 'vitest' import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest' -import type { ServerAuthState } from '@redwoodjs/auth' import { middlewareDefaultAuthProviderState } from '@redwoodjs/auth' +import type { ServerAuthState } from '@redwoodjs/auth/ServerAuthProvider' import { createServerStorage } from '@redwoodjs/server-store' +import type { Middleware, MiddlewareRequest } from '@redwoodjs/web/middleware' +import { MiddlewareResponse } from '@redwoodjs/web/middleware' import { invoke } from './invokeMiddleware' -import type { MiddlewareRequest } from './MiddlewareRequest' -import { MiddlewareResponse } from './MiddlewareResponse' -import type { Middleware } from './types' describe('Invoke middleware', () => { beforeAll(() => { diff --git a/packages/vite/src/middleware/invokeMiddleware.ts b/packages/vite/src/middleware/invokeMiddleware.ts index 5a188246d69b..f9a8be301d6e 100644 --- a/packages/vite/src/middleware/invokeMiddleware.ts +++ b/packages/vite/src/middleware/invokeMiddleware.ts @@ -1,12 +1,14 @@ import type { ServerAuthState } from '@redwoodjs/auth/dist/AuthProvider/ServerAuthProvider.js' import { setServerAuthState } from '@redwoodjs/server-store' - -import { MiddlewareRequest } from './MiddlewareRequest.js' import { MiddlewareResponse, + MiddlewareRequest, MiddlewareShortCircuit, -} from './MiddlewareResponse.js' -import type { Middleware, MiddlewareInvokeOptions } from './types.js' +} from '@redwoodjs/web/dist/server/middleware' +import type { + Middleware, + MiddlewareInvokeOptions, +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } /** * Invokes the middleware function, and guarantees a MiddlewareResponse object diff --git a/packages/vite/src/middleware/register.test.ts b/packages/vite/src/middleware/register.test.ts index 7cc000bd8259..3f7a4031dbd4 100644 --- a/packages/vite/src/middleware/register.test.ts +++ b/packages/vite/src/middleware/register.test.ts @@ -1,9 +1,13 @@ import { describe, expect, it, vitest } from 'vitest' -import { MiddlewareRequest } from './MiddlewareRequest' -import { MiddlewareResponse } from './MiddlewareResponse' +import type { Middleware, MiddlewareClass } from '@redwoodjs/web/middleware' +import { + MiddlewareRequest, + MiddlewareResponse, +} from '@redwoodjs/web/middleware' + import { addMiddlewareHandlers, chain, groupByRoutePatterns } from './register' -import type { Middleware, MiddlewareClass, MiddlewareReg } from './types' +import type { MiddlewareReg } from './types' const fakeMiddleware: Middleware = vitest.fn() diff --git a/packages/vite/src/middleware/register.ts b/packages/vite/src/middleware/register.ts index 0381eb3ddd85..9e005147e060 100644 --- a/packages/vite/src/middleware/register.ts +++ b/packages/vite/src/middleware/register.ts @@ -3,18 +3,18 @@ import type Router from 'find-my-way' import type { ViteDevServer } from 'vite' import { getPaths } from '@redwoodjs/project-config' - -import type { EntryServer } from '../types' -import { makeFilePath, ssrLoadEntryServer } from '../utils' - -import type { MiddlewareRequest } from './MiddlewareRequest' -import { MiddlewareResponse } from './MiddlewareResponse' +import { MiddlewareResponse } from '@redwoodjs/web/dist/server/middleware' import type { Middleware, MiddlewareClass, MiddlewareInvokeOptions, - MiddlewareReg, -} from './types' + MiddlewareRequest, +} from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } + +import type { EntryServer } from '../types' +import { makeFilePath, ssrLoadEntryServer } from '../utils' + +import type { MiddlewareReg } from './types' type GroupedMw = Record diff --git a/packages/vite/src/middleware/types.ts b/packages/vite/src/middleware/types.ts index d718110cdc5c..b36c507f9057 100644 --- a/packages/vite/src/middleware/types.ts +++ b/packages/vite/src/middleware/types.ts @@ -1,26 +1,7 @@ -import type { ViteDevServer } from 'vite' - -import type { RWRouteManifestItem } from '@redwoodjs/internal/dist/routes' - -import type { MiddlewareRequest } from './MiddlewareRequest.js' -import type { MiddlewareResponse } from './MiddlewareResponse.js' - -export type Middleware = ( - req: MiddlewareRequest, - res: MiddlewareResponse, - options?: MiddlewareInvokeOptions, -) => Promise | MiddlewareResponse | void - -export interface MiddlewareClass { - invoke: Middleware -} - -export type MiddlewareInvokeOptions = { - route?: RWRouteManifestItem - cssPaths?: Array - params?: Record - viteDevServer?: ViteDevServer -} +import type { + Middleware, + MiddlewareClass, +} from '@redwoodjs/web/dist/server/middleware' // Tuple of [mw, '*.{extension}'] export type MiddlewareReg = Array< diff --git a/packages/vite/src/rsc/rscRequestHandler.ts b/packages/vite/src/rsc/rscRequestHandler.ts index a3f016bd5123..6f6d83eaf839 100644 --- a/packages/vite/src/rsc/rscRequestHandler.ts +++ b/packages/vite/src/rsc/rscRequestHandler.ts @@ -10,13 +10,13 @@ import type { HTTPMethod } from 'find-my-way' import type { ViteDevServer } from 'vite' import { getAuthState, getRequestHeaders } from '@redwoodjs/server-store' +import type { Middleware } from '@redwoodjs/web/dist/server/middleware' import { decodeReply, decodeReplyFromBusboy, } from '../bundled/react-server-dom-webpack.server' import { hasStatusCode } from '../lib/StatusError.js' -import type { Middleware } from '../middleware' import { invoke } from '../middleware/invokeMiddleware' import { getFullUrlForFlightRequest } from '../utils' diff --git a/packages/vite/src/runFeServer.ts b/packages/vite/src/runFeServer.ts index 7ce33e1acbc1..b9798c5f6049 100644 --- a/packages/vite/src/runFeServer.ts +++ b/packages/vite/src/runFeServer.ts @@ -20,11 +20,11 @@ import { createPerRequestMap, createServerStorage, } from '@redwoodjs/server-store' +import type { Middleware } from '@redwoodjs/web/dist/server/middleware' import { registerFwGlobalsAndShims } from './lib/registerFwGlobalsAndShims.js' import { invoke } from './middleware/invokeMiddleware.js' import { createMiddlewareRouter } from './middleware/register.js' -import type { Middleware } from './middleware/types.js' import { getRscStylesheetLinkGenerator } from './rsc/rscCss.js' import { createRscRequestHandler } from './rsc/rscRequestHandler.js' import { setClientEntries } from './rsc/rscWorkerCommunication.js' diff --git a/packages/vite/src/streaming/createReactStreamingHandler.ts b/packages/vite/src/streaming/createReactStreamingHandler.ts index a7c6de57a410..c36cbc09b5c7 100644 --- a/packages/vite/src/streaming/createReactStreamingHandler.ts +++ b/packages/vite/src/streaming/createReactStreamingHandler.ts @@ -12,10 +12,10 @@ import type { RouteSpec, RWRouteManifestItem } from '@redwoodjs/internal' import { getAppRouteHook, getConfig, getPaths } from '@redwoodjs/project-config' import { matchPath } from '@redwoodjs/router/dist/util.js' import type { TagDescriptor } from '@redwoodjs/web' +import { MiddlewareResponse } from '@redwoodjs/web/dist/server/middleware' +import type { Middleware } from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } import { invoke } from '../middleware/invokeMiddleware.js' -import { MiddlewareResponse } from '../middleware/MiddlewareResponse.js' -import type { Middleware } from '../middleware/types.js' import type { EntryServer } from '../types.js' import { makeFilePath, ssrLoadEntryServer } from '../utils.js' diff --git a/packages/vite/src/streaming/streamHelpers.ts b/packages/vite/src/streaming/streamHelpers.ts index 68b18f8ad141..593115819cf6 100644 --- a/packages/vite/src/streaming/streamHelpers.ts +++ b/packages/vite/src/streaming/streamHelpers.ts @@ -14,9 +14,9 @@ import { getConfig, getPaths } from '@redwoodjs/project-config' import type * as LocationModule from '@redwoodjs/router/dist/location.js' import type { TagDescriptor } from '@redwoodjs/web' // @TODO (ESM), use exports field. Cannot import from web because of index exports -import type * as ServerInjectModule from '@redwoodjs/web/dist/components/ServerInject' +import type * as ServerInjectModule from '@redwoodjs/web/dist/components/ServerInject.js' +import type { MiddlewareResponse } from '@redwoodjs/web/middleware' with { 'resolution-mode': 'import' } -import type { MiddlewareResponse } from '../middleware/MiddlewareResponse.js' import type { ServerEntryType } from '../types.js' import { makeFilePath } from '../utils.js' diff --git a/packages/web/package.json b/packages/web/package.json index 01b916da6839..a8a7554a4022 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -22,25 +22,30 @@ }, "exports": { ".": { - "import": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, - "require": { - "types": "./dist/cjs/index.d.ts", - "default": "./dist/cjs/index.js" - } + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/cjs/index.js" }, "./serverInject": { - "require": "./dist/cjs/components/ServerInject.js", - "import": "./dist/components/ServerInject.js", "types": "./dist/components/ServerInject.d.ts", - "default": "./dist/components/ServerInject.js" + "import": "./dist/components/ServerInject.js", + "default": "./dist/cjs/components/ServerInject.js" }, "./request": { - "require": "./dist/cjs/server/request.js", + "types": "./dist/server/request.d.ts", "import": "./dist/server/request.js", - "types": "./dist/server/request.d.ts" + "default": "./dist/cjs/server/request.js" + }, + "./middleware": { + "types": "./dist/server/middleware.d.ts", + "import": "./dist/server/middleware.js", + "default": "./dist/cjs/server/middleware.js" + }, + "./dist/server/middleware": { + "require": "./dist/cjs/server/middleware.js", + "types": "./dist/server/middleware.d.ts", + "import": "./dist/server/middleware.js", + "default": "./dist/cjs/server/middleware.js" }, "./dist/components/*": { "require": "./dist/cjs/components/*.js", @@ -66,14 +71,13 @@ "default": "./dist/entry/index.js" }, "./toast": { - "require": "./dist/cjs/toast/index.js", + "types": "./dist/toast/index.d.ts", "import": "./dist/toast/index.js", - "types": "./dist/toast/index.d.ts" + "default": "./dist/cjs/toast/index.js" }, "./apollo": { - "require": "./dist/cjs/apollo/index.js", - "import": "./dist/apollo/index.js", "types": "./dist/apollo/index.d.ts", + "import": "./dist/apollo/index.js", "default": "./dist/cjs/apollo/index.js" }, "./forceEsmApollo": { @@ -102,6 +106,7 @@ "@babel/runtime-corejs3": "7.24.5", "@redwoodjs/auth": "workspace:*", "@redwoodjs/server-store": "workspace:*", + "@whatwg-node/fetch": "0.9.17", "core-js": "3.37.1", "graphql": "16.8.1", "graphql-sse": "2.5.3", @@ -118,6 +123,7 @@ "@babel/plugin-transform-runtime": "7.24.3", "@babel/runtime": "7.24.5", "@redwoodjs/framework-tools": "workspace:*", + "@redwoodjs/internal": "workspace:*", "@rollup/plugin-babel": "6.0.4", "@testing-library/jest-dom": "6.4.6", "@testing-library/react": "14.3.1", diff --git a/packages/vite/src/middleware/MiddlewareRequest.test.ts b/packages/web/src/server/MiddlewareRequest.test.ts similarity index 100% rename from packages/vite/src/middleware/MiddlewareRequest.test.ts rename to packages/web/src/server/MiddlewareRequest.test.ts diff --git a/packages/vite/src/middleware/MiddlewareRequest.ts b/packages/web/src/server/MiddlewareRequest.ts similarity index 100% rename from packages/vite/src/middleware/MiddlewareRequest.ts rename to packages/web/src/server/MiddlewareRequest.ts diff --git a/packages/vite/src/middleware/MiddlewareResponse.test.ts b/packages/web/src/server/MiddlewareResponse.test.ts similarity index 100% rename from packages/vite/src/middleware/MiddlewareResponse.test.ts rename to packages/web/src/server/MiddlewareResponse.test.ts diff --git a/packages/vite/src/middleware/MiddlewareResponse.ts b/packages/web/src/server/MiddlewareResponse.ts similarity index 100% rename from packages/vite/src/middleware/MiddlewareResponse.ts rename to packages/web/src/server/MiddlewareResponse.ts diff --git a/packages/web/src/server/middleware.ts b/packages/web/src/server/middleware.ts new file mode 100644 index 000000000000..5f2302d3e39c --- /dev/null +++ b/packages/web/src/server/middleware.ts @@ -0,0 +1,28 @@ +import type { ViteDevServer } from 'vite' + +// We are just importing the type here, it's OK! +// eslint-disable-next-line no-restricted-imports +import type { RWRouteManifestItem } from '@redwoodjs/internal/dist/routes.js' + +import type { MiddlewareRequest } from './MiddlewareRequest.js' +import type { MiddlewareResponse } from './MiddlewareResponse.js' + +export * from './MiddlewareRequest.js' +export * from './MiddlewareResponse.js' + +export type MiddlewareInvokeOptions = { + route?: RWRouteManifestItem + cssPaths?: Array + params?: Record + viteDevServer?: ViteDevServer +} + +export type Middleware = ( + req: MiddlewareRequest, + res: MiddlewareResponse, + options?: MiddlewareInvokeOptions, +) => Promise | MiddlewareResponse | void + +export interface MiddlewareClass { + invoke: Middleware +} diff --git a/packages/web/tsconfig.json b/packages/web/tsconfig.json index 57fcd541165b..e1e11dacc0f5 100644 --- a/packages/web/tsconfig.json +++ b/packages/web/tsconfig.json @@ -7,6 +7,17 @@ "moduleResolution": "NodeNext", "module": "NodeNext", }, - "include": ["./src/**/*", "ambient.d.ts", "testing-library.d.ts"], - "references": [{ "path": "../auth/tsconfig.build.json" }] + "include": [ + "./src/**/*", + "ambient.d.ts", + "testing-library.d.ts" + ], + "references": [ + { + "path": "../auth/tsconfig.build.json" + }, + { + "path": "../internal" + } + ] } diff --git a/yarn.lock b/yarn.lock index 1a085a695e51..3f8cbb73027f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7497,7 +7497,7 @@ __metadata: "@redwoodjs/auth-dbauth-api": "workspace:*" "@redwoodjs/framework-tools": "workspace:*" "@redwoodjs/graphql-server": "workspace:*" - "@redwoodjs/vite": "workspace:*" + "@redwoodjs/web": "workspace:*" "@types/aws-lambda": "npm:8.10.138" ts-toolbelt: "npm:9.6.0" tsx: "npm:4.15.6" @@ -7675,7 +7675,7 @@ __metadata: "@redwoodjs/auth-supabase-api": "workspace:*" "@redwoodjs/framework-tools": "workspace:*" "@redwoodjs/graphql-server": "workspace:*" - "@redwoodjs/vite": "workspace:*" + "@redwoodjs/web": "workspace:*" "@supabase/ssr": "npm:0.3.0" "@types/aws-lambda": "npm:8.10.138" ts-toolbelt: "npm:9.6.0" @@ -8414,7 +8414,7 @@ __metadata: "@redwoodjs/internal": "workspace:*" "@redwoodjs/project-config": "workspace:*" "@redwoodjs/router": "workspace:*" - "@redwoodjs/vite": "workspace:*" + "@redwoodjs/web": "workspace:*" fast-glob: "npm:3.3.2" lodash: "npm:4.17.21" react: "npm:19.0.0-beta-04b058868c-20240508" @@ -8669,7 +8669,7 @@ __metadata: languageName: unknown linkType: soft -"@redwoodjs/vite@workspace:*, @redwoodjs/vite@workspace:packages/vite": +"@redwoodjs/vite@workspace:packages/vite": version: 0.0.0-use.local resolution: "@redwoodjs/vite@workspace:packages/vite" dependencies: @@ -8691,7 +8691,7 @@ __metadata: "@types/yargs-parser": "npm:21.0.3" "@vitejs/plugin-react": "npm:4.2.1" "@whatwg-node/fetch": "npm:0.9.17" - "@whatwg-node/server": "npm:0.9.34" + "@whatwg-node/server": "npm:0.9.36" acorn-loose: "npm:8.4.0" buffer: "npm:6.0.3" busboy: "npm:^1.6.0" @@ -8710,7 +8710,7 @@ __metadata: typescript: "npm:5.4.5" vite: "npm:5.3.1" vite-plugin-cjs-interop: "npm:2.1.1" - vite-plugin-node-polyfills: "npm:^0.22.0" + vite-plugin-node-polyfills: "npm:0.22.0" vitest: "npm:1.6.0" yargs-parser: "npm:21.1.1" bin: @@ -8754,12 +8754,14 @@ __metadata: "@babel/runtime-corejs3": "npm:7.24.5" "@redwoodjs/auth": "workspace:*" "@redwoodjs/framework-tools": "workspace:*" + "@redwoodjs/internal": "workspace:*" "@redwoodjs/server-store": "workspace:*" "@rollup/plugin-babel": "npm:6.0.4" "@testing-library/jest-dom": "npm:6.4.6" "@testing-library/react": "npm:14.3.1" "@types/react": "npm:^18.2.55" "@types/react-dom": "npm:^18.2.19" + "@whatwg-node/fetch": "npm:0.9.17" core-js: "npm:3.37.1" graphql: "npm:16.8.1" graphql-sse: "npm:2.5.3" @@ -12052,13 +12054,13 @@ __metadata: languageName: node linkType: hard -"@whatwg-node/server@npm:0.9.34, @whatwg-node/server@npm:^0.9.33": - version: 0.9.34 - resolution: "@whatwg-node/server@npm:0.9.34" +"@whatwg-node/server@npm:0.9.36, @whatwg-node/server@npm:^0.9.33": + version: 0.9.36 + resolution: "@whatwg-node/server@npm:0.9.36" dependencies: "@whatwg-node/fetch": "npm:^0.9.17" tslib: "npm:^2.3.1" - checksum: 10c0/6f2f651d8b1a95c81244b5b61d19f8eedccb66dcc50c7a9fc7c3ef8baa47ce756e07e3ca50f8c61e729f1dbde9e3282f7eedf3357aa75aa132f458138484cc4d + checksum: 10c0/62d50ac4a1f41fddee4ff370f9b565a9a384c897c079595faba7ee1a62d8b30f4b6497c37b0d1d07d806cad38117fef8b77bf144ecd1d0cb6578ded47328ee49 languageName: node linkType: hard @@ -31584,7 +31586,7 @@ __metadata: languageName: node linkType: hard -"vite-plugin-node-polyfills@npm:^0.22.0": +"vite-plugin-node-polyfills@npm:0.22.0": version: 0.22.0 resolution: "vite-plugin-node-polyfills@npm:0.22.0" dependencies: From d39d278dd47697f2b065888f595d9b0e459a64c7 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sat, 13 Jul 2024 22:37:00 +0200 Subject: [PATCH 4/6] chore(auth): Fix esm cjs exports and add tooling to verify correctness (#10942) --- packages/auth/attw.ts | 30 +++ packages/auth/build.ts | 28 ++- packages/auth/package.json | 75 +++++-- packages/auth/tsconfig.json | 8 +- packages/router/src/router-context.tsx | 2 +- yarn.lock | 267 +++++++++++++++++++++++-- 6 files changed, 360 insertions(+), 50 deletions(-) create mode 100644 packages/auth/attw.ts diff --git a/packages/auth/attw.ts b/packages/auth/attw.ts new file mode 100644 index 000000000000..396c519ea0b6 --- /dev/null +++ b/packages/auth/attw.ts @@ -0,0 +1,30 @@ +import { $ } from 'zx' + +interface Problem { + kind: string + resolutionKind?: string +} + +await $({ nothrow: true })`yarn attw -P -f json > .attw.json` +const output = await $`cat .attw.json` +await $`rm .attw.json` + +const json = JSON.parse(output.stdout) + +if (!json.analysis.problems || json.analysis.problems.length === 0) { + console.log('No errors found') + process.exit(0) +} + +if ( + json.analysis.problems.every( + (problem: Problem) => problem.resolutionKind === 'node10', + ) +) { + console.log("Only found node10 problems, which we don't care about") + process.exit(0) +} + +console.log('Errors found') +console.log(json.analysis.problems) +process.exit(1) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index e5e0b1780591..f0265b9b48ae 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -1,4 +1,7 @@ -import { writeFileSync } from 'node:fs' +import { readFileSync, writeFileSync } from 'node:fs' + +import type { PackageJson } from 'type-fest' +import { $ } from 'zx' import { build, defaultBuildOptions } from '@redwoodjs/framework-tools' @@ -29,3 +32,26 @@ writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) // Place a package.json file with `type: module` in the dist/esm folder so that // all .js files are treated as ES Module files. writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) + +// Finally we need to also produce CJS type definitions +// +// The best way[1] to do this is to (temporarily) change the "type" in +// package.json to "commonjs" and run tsc with our tsconfig.build-cjs.json +// config file. +// It's possible to run TSC programmatically[2] but it's much easier to just +// shell out to the CLI. +// +// [1]: https://github.com/arethetypeswrong/arethetypeswrong.github.io/issues/21#issuecomment-1494618930 +// [2]: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API + +await $`cp package.json package.json.bak` + +const packageJson: PackageJson = JSON.parse( + readFileSync('./package.json', 'utf-8'), +) +packageJson.type = 'commonjs' +writeFileSync('./package.json', JSON.stringify(packageJson, null, 2)) + +await $`yarn build:types-cjs` + +await $`mv package.json.bak package.json` diff --git a/packages/auth/package.json b/packages/auth/package.json index 705f86b9ddf5..6b85c04ea6f9 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -10,34 +10,64 @@ "type": "module", "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "default": "./dist/cjs/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + } }, "./AuthProviderState": { - "types": "./dist/AuthProvider/AuthProviderState.d.ts", - "import": "./dist/AuthProvider/AuthProviderState.js", - "default": "./dist/cjs/AuthProvider/AuthProviderState.js" + "import": { + "types": "./dist/AuthProvider/AuthProviderState.d.ts", + "default": "./dist/AuthProvider/AuthProviderState.js" + }, + "require": { + "types": "./dist/cjs/AuthProvider/AuthProviderState.d.ts", + "default": "./dist/cjs/AuthProvider/AuthProviderState.js" + } }, "./dist/AuthProvider/AuthProviderState.js": { - "types": "./dist/AuthProvider/AuthProviderState.d.ts", - "import": "./dist/AuthProvider/AuthProviderState.js", - "default": "./dist/cjs/AuthProvider/AuthProviderState.js" + "import": { + "types": "./dist/AuthProvider/AuthProviderState.d.ts", + "default": "./dist/AuthProvider/AuthProviderState.js" + }, + "require": { + "types": "./dist/cjs/AuthProvider/AuthProviderState.d.ts", + "default": "./dist/cjs/AuthProvider/AuthProviderState.js" + } }, "./ServerAuthProvider": { - "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", - "import": "./dist/AuthProvider/ServerAuthProvider.js", - "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + "import": { + "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/AuthProvider/ServerAuthProvider.js" + }, + "require": { + "types": "./dist/cjs/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + } }, "./dist/AuthProvider/ServerAuthProvider": { - "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", - "import": "./dist/AuthProvider/ServerAuthProvider.js", - "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + "import": { + "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/AuthProvider/ServerAuthProvider.js" + }, + "require": { + "types": "./dist/cjs/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + } }, "./dist/AuthProvider/ServerAuthProvider.js": { - "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", - "import": "./dist/AuthProvider/ServerAuthProvider.js", - "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + "import": { + "types": "./dist/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/AuthProvider/ServerAuthProvider.js" + }, + "require": { + "types": "./dist/cjs/AuthProvider/ServerAuthProvider.d.ts", + "default": "./dist/cjs/AuthProvider/ServerAuthProvider.js" + } } }, "types": "./dist/index.d.ts", @@ -48,9 +78,13 @@ "build": "tsx ./build.ts && yarn build:types", "build:pack": "yarn pack -o redwoodjs-auth.tgz", "build:types": "tsc --build --verbose tsconfig.build.json", + "build:types-cjs": "tsc --build --verbose tsconfig.build-cjs.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "vitest run", + "test": "concurrently \"npm:test:publint\" \"npm:test:vitest\" npm:test:attw", + "test:publint": "yarn publint", + "test:vitest": "vitest run", + "test:attw": "tsx ./attw.ts", "test:watch": "vitest watch" }, "dependencies": { @@ -58,10 +92,13 @@ "react": "19.0.0-beta-04b058868c-20240508" }, "devDependencies": { + "@arethetypeswrong/cli": "0.15.3", "@redwoodjs/framework-tools": "workspace:*", "@testing-library/jest-dom": "6.4.6", "@testing-library/react": "14.3.1", + "concurrently": "8.2.2", "msw": "1.3.3", + "publint": "0.2.8", "tsx": "4.15.6", "typescript": "5.4.5", "vitest": "1.6.0" diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index d435973639c6..6bf2eb548af4 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -6,13 +6,7 @@ "module": "NodeNext", "outDir": "dist" }, - "include": [ - "src", - "ambient.d.ts", - "modules.d.ts", - "./vitest.setup.ts", - "__tests__" - ], + "inclue": ["."], "exclude": ["dist", "node_modules", "**/__mocks__", "**/__fixtures__"], "references": [ { "path": "../framework-tools" } diff --git a/packages/router/src/router-context.tsx b/packages/router/src/router-context.tsx index f2462294c1a4..4abbb736b0a2 100644 --- a/packages/router/src/router-context.tsx +++ b/packages/router/src/router-context.tsx @@ -1,6 +1,6 @@ import React, { createContext, useContext, useMemo } from 'react' -import type { AuthContextInterface } from '@redwoodjs/auth' +import type { AuthContextInterface } from '@redwoodjs/auth' with { 'resolution-mode': 'import' } import { useNoAuth } from '@redwoodjs/auth' import type { analyzeRoutes } from './analyzeRoutes' diff --git a/yarn.lock b/yarn.lock index 3f8cbb73027f..85fc878f61b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -103,6 +103,13 @@ __metadata: languageName: node linkType: hard +"@andrewbranch/untar.js@npm:^1.0.3": + version: 1.0.3 + resolution: "@andrewbranch/untar.js@npm:1.0.3" + checksum: 10c0/16774208cd5bc2cace3c8c6ca608b2b9ab07719a44501e5553f72bffb63c5fbac0b715a4b1065a65d09e010d940ac3cd148ade44dd7d49682765fe09e2c3b2a8 + languageName: node + linkType: hard + "@antfu/utils@npm:^0.7.7": version: 0.7.7 resolution: "@antfu/utils@npm:0.7.7" @@ -198,6 +205,37 @@ __metadata: languageName: node linkType: hard +"@arethetypeswrong/cli@npm:0.15.3": + version: 0.15.3 + resolution: "@arethetypeswrong/cli@npm:0.15.3" + dependencies: + "@arethetypeswrong/core": "npm:0.15.1" + chalk: "npm:^4.1.2" + cli-table3: "npm:^0.6.3" + commander: "npm:^10.0.1" + marked: "npm:^9.1.2" + marked-terminal: "npm:^6.0.0" + semver: "npm:^7.5.4" + bin: + attw: dist/index.js + checksum: 10c0/5998ab4a2195f9036a5c1988f73912a0a82cceeaa6a4e647b04414ad956a62163d8286b2a936941f23065b0c872f2bbdf9196fe3cac19c40b8b62a643d91c3c2 + languageName: node + linkType: hard + +"@arethetypeswrong/core@npm:0.15.1": + version: 0.15.1 + resolution: "@arethetypeswrong/core@npm:0.15.1" + dependencies: + "@andrewbranch/untar.js": "npm:^1.0.3" + fflate: "npm:^0.8.2" + semver: "npm:^7.5.4" + ts-expose-internals-conditionally: "npm:1.0.0-empty.0" + typescript: "npm:5.3.3" + validate-npm-package-name: "npm:^5.0.0" + checksum: 10c0/85385378a62be4d6b6e445d7f32e1e20452db0f4cfe337eead747fead9f20cccdf8ee69e3ce8c74736cab9effd6800d8bf6047c35a54474d3e1c5d5f168cf39f + languageName: node + linkType: hard + "@auth0/auth0-spa-js@npm:2.1.3": version: 2.1.3 resolution: "@auth0/auth0-spa-js@npm:2.1.3" @@ -7777,11 +7815,14 @@ __metadata: version: 0.0.0-use.local resolution: "@redwoodjs/auth@workspace:packages/auth" dependencies: + "@arethetypeswrong/cli": "npm:0.15.3" "@redwoodjs/framework-tools": "workspace:*" "@testing-library/jest-dom": "npm:6.4.6" "@testing-library/react": "npm:14.3.1" + concurrently: "npm:8.2.2" core-js: "npm:3.37.1" msw: "npm:1.3.3" + publint: "npm:0.2.8" react: "npm:19.0.0-beta-04b058868c-20240508" tsx: "npm:4.15.6" typescript: "npm:5.4.5" @@ -9133,6 +9174,13 @@ __metadata: languageName: node linkType: hard +"@sindresorhus/is@npm:^4.6.0": + version: 4.6.0 + resolution: "@sindresorhus/is@npm:4.6.0" + checksum: 10c0/33b6fb1d0834ec8dd7689ddc0e2781c2bfd8b9c4e4bacbcb14111e0ae00621f2c264b8a7d36541799d74888b5dccdf422a891a5cb5a709ace26325eedc81e22e + languageName: node + linkType: hard + "@sinonjs/commons@npm:^3.0.0": version: 3.0.0 resolution: "@sinonjs/commons@npm:3.0.0" @@ -12526,12 +12574,10 @@ __metadata: languageName: node linkType: hard -"ansi-escapes@npm:^6.0.0": - version: 6.2.0 - resolution: "ansi-escapes@npm:6.2.0" - dependencies: - type-fest: "npm:^3.0.0" - checksum: 10c0/3eec75deedd8b10192c5f98e4cd9715cc3ff268d33fc463c24b7d22446668bfcd4ad1803993ea89c0f51f88b5a3399572bacb7c8cb1a067fc86e189c5f3b0c7e +"ansi-escapes@npm:^6.0.0, ansi-escapes@npm:^6.2.0": + version: 6.2.1 + resolution: "ansi-escapes@npm:6.2.1" + checksum: 10c0/a2c6f58b044be5f69662ee17073229b492daa2425a7fd99a665db6c22eab6e4ab42752807def7281c1c7acfed48f87f2362dda892f08c2c437f1b39c6b033103 languageName: node linkType: hard @@ -12590,6 +12636,13 @@ __metadata: languageName: node linkType: hard +"ansicolors@npm:~0.3.2": + version: 0.3.2 + resolution: "ansicolors@npm:0.3.2" + checksum: 10c0/e202182895e959c5357db6c60791b2abaade99fcc02221da11a581b26a7f83dc084392bc74e4d3875c22f37b3c9ef48842e896e3bfed394ec278194b8003e0ac + languageName: node + linkType: hard + "anymatch@npm:^3.0.3, anymatch@npm:~3.1.2": version: 3.1.3 resolution: "anymatch@npm:3.1.3" @@ -14058,6 +14111,18 @@ __metadata: languageName: node linkType: hard +"cardinal@npm:^2.1.1": + version: 2.1.1 + resolution: "cardinal@npm:2.1.1" + dependencies: + ansicolors: "npm:~0.3.2" + redeyed: "npm:~2.1.0" + bin: + cdl: ./bin/cdl.js + checksum: 10c0/0051d0e64c0e1dff480c1aace4c018c48ecca44030533257af3f023107ccdeb061925603af6d73710f0345b0ae0eb57e5241d181d9b5fdb595d45c5418161675 + languageName: node + linkType: hard + "case-sensitive-paths-webpack-plugin@npm:^2.4.0": version: 2.4.0 resolution: "case-sensitive-paths-webpack-plugin@npm:2.4.0" @@ -14472,16 +14537,16 @@ __metadata: languageName: node linkType: hard -"cli-table3@npm:^0.6.1, cli-table3@npm:~0.6.1": - version: 0.6.3 - resolution: "cli-table3@npm:0.6.3" +"cli-table3@npm:^0.6.1, cli-table3@npm:^0.6.3, cli-table3@npm:~0.6.1": + version: 0.6.5 + resolution: "cli-table3@npm:0.6.5" dependencies: "@colors/colors": "npm:1.5.0" string-width: "npm:^4.2.0" dependenciesMeta: "@colors/colors": optional: true - checksum: 10c0/39e580cb346c2eaf1bd8f4ff055ae644e902b8303c164a1b8894c0dc95941f92e001db51f49649011be987e708d9fa3183ccc2289a4d376a057769664048cc0c + checksum: 10c0/d7cc9ed12212ae68241cc7a3133c52b844113b17856e11f4f81308acc3febcea7cc9fd298e70933e294dd642866b29fd5d113c2c098948701d0c35f09455de78 languageName: node linkType: hard @@ -16701,6 +16766,13 @@ __metadata: languageName: node linkType: hard +"emojilib@npm:^2.4.0": + version: 2.4.0 + resolution: "emojilib@npm:2.4.0" + checksum: 10c0/6e66ba8921175842193f974e18af448bb6adb0cf7aeea75e08b9d4ea8e9baba0e4a5347b46ed901491dcaba277485891c33a8d70b0560ca5cc9672a94c21ab8f + languageName: node + linkType: hard + "emojis-list@npm:^3.0.0": version: 3.0.0 resolution: "emojis-list@npm:3.0.0" @@ -18219,6 +18291,13 @@ __metadata: languageName: node linkType: hard +"fflate@npm:^0.8.2": + version: 0.8.2 + resolution: "fflate@npm:0.8.2" + checksum: 10c0/03448d630c0a583abea594835a9fdb2aaf7d67787055a761515bf4ed862913cfd693b4c4ffd5c3f3b355a70cf1e19033e9ae5aedcca103188aaff91b8bd6e293 + languageName: node + linkType: hard + "figures@npm:3.2.0, figures@npm:^3.0.0, figures@npm:^3.2.0": version: 3.2.0 resolution: "figures@npm:3.2.0" @@ -23214,6 +23293,31 @@ __metadata: languageName: node linkType: hard +"marked-terminal@npm:^6.0.0": + version: 6.2.0 + resolution: "marked-terminal@npm:6.2.0" + dependencies: + ansi-escapes: "npm:^6.2.0" + cardinal: "npm:^2.1.1" + chalk: "npm:^5.3.0" + cli-table3: "npm:^0.6.3" + node-emoji: "npm:^2.1.3" + supports-hyperlinks: "npm:^3.0.0" + peerDependencies: + marked: ">=1 <12" + checksum: 10c0/72d4093cbb1ee864ced1f88fdb6fb8dbfea56d6aa3d8a1ec401ac51866ff3c32382c3f4642b19f2d808c798efde23b10300b99e3b6475b3f79e41e7741581d54 + languageName: node + linkType: hard + +"marked@npm:^9.1.2": + version: 9.1.6 + resolution: "marked@npm:9.1.6" + bin: + marked: bin/marked.js + checksum: 10c0/010bbd33c0f38300259c5d3bf0063deb36bab098d37ac0a3be5a35a65674a4c693427fc6704f486a89f638e9b36c36b8e220a93d47163f4e70e45a1fa8ca7b60 + languageName: node + linkType: hard + "md5.js@npm:^1.3.4": version: 1.3.5 resolution: "md5.js@npm:1.3.5" @@ -24212,7 +24316,7 @@ __metadata: languageName: node linkType: hard -"mri@npm:^1.2.0": +"mri@npm:^1.1.0, mri@npm:^1.2.0": version: 1.2.0 resolution: "mri@npm:1.2.0" checksum: 10c0/a3d32379c2554cf7351db6237ddc18dc9e54e4214953f3da105b97dc3babe0deb3ffe99cf409b38ea47cc29f9430561ba6b53b24ab8f9ce97a4b50409e4a50e7 @@ -24428,6 +24532,18 @@ __metadata: languageName: node linkType: hard +"node-emoji@npm:^2.1.3": + version: 2.1.3 + resolution: "node-emoji@npm:2.1.3" + dependencies: + "@sindresorhus/is": "npm:^4.6.0" + char-regex: "npm:^1.0.2" + emojilib: "npm:^2.4.0" + skin-tone: "npm:^2.0.0" + checksum: 10c0/e688333373563aa8308df16111eee2b5837b53a51fb63bf8b7fbea2896327c5d24c9984eb0c8ca6ac155d4d9c194dcf1840d271033c1b588c7c45a3b65339ef7 + languageName: node + linkType: hard + "node-environment-flags@npm:^1.0.5": version: 1.0.6 resolution: "node-environment-flags@npm:1.0.6" @@ -24735,6 +24851,15 @@ __metadata: languageName: node linkType: hard +"npm-bundled@npm:^2.0.0": + version: 2.0.1 + resolution: "npm-bundled@npm:2.0.1" + dependencies: + npm-normalize-package-bin: "npm:^2.0.0" + checksum: 10c0/5b2dc1de455d38200e49c6205dee185ce919ea6b608672c693bec8907116bc5686dabcc150347630d351c1c533315fd60a1910ce00bdad6bb204cef016b90b7d + languageName: node + linkType: hard + "npm-bundled@npm:^3.0.0": version: 3.0.0 resolution: "npm-bundled@npm:3.0.0" @@ -24760,6 +24885,13 @@ __metadata: languageName: node linkType: hard +"npm-normalize-package-bin@npm:^2.0.0": + version: 2.0.0 + resolution: "npm-normalize-package-bin@npm:2.0.0" + checksum: 10c0/9b5283a2e423124c60fbc14244d36686b59e517d29156eacf9df8d3dc5d5bf4d9444b7669c607567ed2e089bbdbef5a2b3678cbf567284eeff3612da6939514b + languageName: node + linkType: hard + "npm-normalize-package-bin@npm:^3.0.0": version: 3.0.1 resolution: "npm-normalize-package-bin@npm:3.0.1" @@ -24825,6 +24957,20 @@ __metadata: languageName: node linkType: hard +"npm-packlist@npm:^5.1.3": + version: 5.1.3 + resolution: "npm-packlist@npm:5.1.3" + dependencies: + glob: "npm:^8.0.1" + ignore-walk: "npm:^5.0.1" + npm-bundled: "npm:^2.0.0" + npm-normalize-package-bin: "npm:^2.0.0" + bin: + npm-packlist: bin/index.js + checksum: 10c0/a8bea97661b2a7132bc8832d5560da24f823ee5324429bd16eb82b7873557de14641bc3fed8a7611b0d88b9771e59e99e01a9e551a53adb164327ded6128aada + languageName: node + linkType: hard + "npm-pick-manifest@npm:^9.0.0, npm-pick-manifest@npm:^9.0.1": version: 9.0.1 resolution: "npm-pick-manifest@npm:9.0.1" @@ -25992,10 +26138,10 @@ __metadata: languageName: node linkType: hard -"picocolors@npm:^1.0.0": - version: 1.0.0 - resolution: "picocolors@npm:1.0.0" - checksum: 10c0/20a5b249e331c14479d94ec6817a182fd7a5680debae82705747b2db7ec50009a5f6648d0621c561b0572703f84dbef0858abcbd5856d3c5511426afcb1961f7 +"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1": + version: 1.0.1 + resolution: "picocolors@npm:1.0.1" + checksum: 10c0/c63cdad2bf812ef0d66c8db29583802355d4ca67b9285d846f390cc15c2f6ccb94e8cb7eb6a6e97fc5990a6d3ad4ae42d86c84d3146e667c739a4234ed50d400 languageName: node linkType: hard @@ -27010,6 +27156,19 @@ __metadata: languageName: node linkType: hard +"publint@npm:0.2.8": + version: 0.2.8 + resolution: "publint@npm:0.2.8" + dependencies: + npm-packlist: "npm:^5.1.3" + picocolors: "npm:^1.0.1" + sade: "npm:^1.8.1" + bin: + publint: lib/cli.js + checksum: 10c0/da4157b3039004d42b8f7df048236bbbf598919d8ddb2c9387b5c4ddaf1564d81e7ab3370ed039f00b784a0c6915d0dbb523fcd1817aa3738f77aac0b955153a + languageName: node + linkType: hard + "pump@npm:^2.0.0": version: 2.0.1 resolution: "pump@npm:2.0.1" @@ -27749,6 +27908,15 @@ __metadata: languageName: node linkType: hard +"redeyed@npm:~2.1.0": + version: 2.1.1 + resolution: "redeyed@npm:2.1.1" + dependencies: + esprima: "npm:~4.0.0" + checksum: 10c0/350f5e39aebab3886713a170235c38155ee64a74f0f7e629ecc0144ba33905efea30c2c3befe1fcbf0b0366e344e7bfa34e6b2502b423c9a467d32f1306ef166 + languageName: node + linkType: hard + "redis-errors@npm:^1.0.0, redis-errors@npm:^1.2.0": version: 1.2.0 resolution: "redis-errors@npm:1.2.0" @@ -28502,6 +28670,15 @@ __metadata: languageName: node linkType: hard +"sade@npm:^1.8.1": + version: 1.8.1 + resolution: "sade@npm:1.8.1" + dependencies: + mri: "npm:^1.1.0" + checksum: 10c0/da8a3a5d667ad5ce3bf6d4f054bbb9f711103e5df21003c5a5c1a8a77ce12b640ed4017dd423b13c2307ea7e645adee7c2ae3afe8051b9db16a6f6d3da3f90b1 + languageName: node + linkType: hard + "safe-array-concat@npm:^1.0.0, safe-array-concat@npm:^1.1.2": version: 1.1.2 resolution: "safe-array-concat@npm:1.1.2" @@ -29016,6 +29193,15 @@ __metadata: languageName: node linkType: hard +"skin-tone@npm:^2.0.0": + version: 2.0.0 + resolution: "skin-tone@npm:2.0.0" + dependencies: + unicode-emoji-modifier-base: "npm:^1.0.0" + checksum: 10c0/82d4c2527864f9cbd6cb7f3c4abb31e2224752234d5013b881d3e34e9ab543545b05206df5a17d14b515459fcb265ce409f9cfe443903176b0360cd20e4e4ba5 + languageName: node + linkType: hard + "slash@npm:3.0.0, slash@npm:^3.0.0": version: 3.0.0 resolution: "slash@npm:3.0.0" @@ -29964,6 +30150,16 @@ __metadata: languageName: node linkType: hard +"supports-hyperlinks@npm:^3.0.0": + version: 3.0.0 + resolution: "supports-hyperlinks@npm:3.0.0" + dependencies: + has-flag: "npm:^4.0.0" + supports-color: "npm:^7.0.0" + checksum: 10c0/36aaa55e67645dded8e0f846fd81d7dd05ce82ea81e62347f58d86213577eb627b2b45298656ce7a70e7155e39f071d0d3f83be91e112aed801ebaa8db1ef1d0 + languageName: node + linkType: hard + "supports-preserve-symlinks-flag@npm:^1.0.0": version: 1.0.0 resolution: "supports-preserve-symlinks-flag@npm:1.0.0" @@ -30575,6 +30771,13 @@ __metadata: languageName: node linkType: hard +"ts-expose-internals-conditionally@npm:1.0.0-empty.0": + version: 1.0.0-empty.0 + resolution: "ts-expose-internals-conditionally@npm:1.0.0-empty.0" + checksum: 10c0/47c68497ec75b75a903db518b146d3599b71f62382368af4dd70c1fc2de777791620beac4afb4a2eaf7cf08efa68d7389bc5ea007c3c2d07cae2f3d482111db8 + languageName: node + linkType: hard + "ts-invariant@npm:^0.10.3": version: 0.10.3 resolution: "ts-invariant@npm:0.10.3" @@ -30886,13 +31089,6 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^3.0.0": - version: 3.13.1 - resolution: "type-fest@npm:3.13.1" - checksum: 10c0/547d22186f73a8c04590b70dcf63baff390078c75ea8acd366bbd510fd0646e348bd1970e47ecf795b7cff0b41d26e9c475c1fedd6ef5c45c82075fbf916b629 - languageName: node - linkType: hard - "type-is@npm:~1.6.18": version: 1.6.18 resolution: "type-is@npm:1.6.18" @@ -30962,6 +31158,16 @@ __metadata: languageName: node linkType: hard +"typescript@npm:5.3.3": + version: 5.3.3 + resolution: "typescript@npm:5.3.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10c0/e33cef99d82573624fc0f854a2980322714986bc35b9cb4d1ce736ed182aeab78e2cb32b385efa493b2a976ef52c53e20d6c6918312353a91850e2b76f1ea44f + languageName: node + linkType: hard + "typescript@npm:5.4.5, typescript@npm:>=3 < 6": version: 5.4.5 resolution: "typescript@npm:5.4.5" @@ -30972,6 +31178,16 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@npm%3A5.3.3#optional!builtin": + version: 5.3.3 + resolution: "typescript@patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 10c0/1d0a5f4ce496c42caa9a30e659c467c5686eae15d54b027ee7866744952547f1be1262f2d40de911618c242b510029d51d43ff605dba8fb740ec85ca2d3f9500 + languageName: node + linkType: hard + "typescript@patch:typescript@npm%3A5.4.5#optional!builtin, typescript@patch:typescript@npm%3A>=3 < 6#optional!builtin": version: 5.4.5 resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin::version=5.4.5&hash=5adc0c" @@ -31054,6 +31270,13 @@ __metadata: languageName: node linkType: hard +"unicode-emoji-modifier-base@npm:^1.0.0": + version: 1.0.0 + resolution: "unicode-emoji-modifier-base@npm:1.0.0" + checksum: 10c0/b37623fcf0162186debd20f116483e035a2d5b905b932a2c472459d9143d446ebcbefb2a494e2fe4fa7434355396e2a95ec3fc1f0c29a3bc8f2c827220e79c66 + languageName: node + linkType: hard + "unicode-match-property-ecmascript@npm:^2.0.0": version: 2.0.0 resolution: "unicode-match-property-ecmascript@npm:2.0.0" From d7a0a6a51abce95465c81f71550a69d91a02c76a Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 14 Jul 2024 01:11:59 +0200 Subject: [PATCH 5/6] chore(web): publint and attw (#10943) --- packages/auth/build.ts | 6 +- packages/web/attw.ts | 34 +++++++++++ packages/web/{build.mts => build.ts} | 16 +++-- packages/web/package.json | 88 ++++++++++++++++++++-------- packages/web/tsconfig.json | 7 +-- yarn.lock | 3 + 6 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 packages/web/attw.ts rename packages/web/{build.mts => build.ts} (71%) diff --git a/packages/auth/build.ts b/packages/auth/build.ts index f0265b9b48ae..cee4016df6f2 100644 --- a/packages/auth/build.ts +++ b/packages/auth/build.ts @@ -25,11 +25,11 @@ await build({ }, }) -// Place a package.json file with `type: commonjs` in the dist folder so that -// all .js files are treated as CommonJS files. +// Place a package.json file with `type: commonjs` in the dist/cjs folder so +// that all .js files are treated as CommonJS files. writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) -// Place a package.json file with `type: module` in the dist/esm folder so that +// Place a package.json file with `type: module` in the dist folder so that // all .js files are treated as ES Module files. writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) diff --git a/packages/web/attw.ts b/packages/web/attw.ts new file mode 100644 index 000000000000..30cc6559892e --- /dev/null +++ b/packages/web/attw.ts @@ -0,0 +1,34 @@ +import { $ } from 'zx' + +interface Problem { + kind: string + entrypoint?: string + resolutionKind?: string +} + +await $({ nothrow: true })`yarn attw -P -f json > .attw.json` +const output = await $`cat .attw.json` +await $`rm .attw.json` + +const json = JSON.parse(output.stdout) + +if (!json.analysis.problems || json.analysis.problems.length === 0) { + console.log('No errors found') + process.exit(0) +} + +if ( + json.analysis.problems.every( + (problem: Problem) => + problem.resolutionKind === 'node10' || + problem.entrypoint === './webpackEntry' || + problem.entrypoint === './forceEsmApollo', + ) +) { + console.log("Only found problems we don't care about") + process.exit(0) +} + +console.log('Errors found') +console.log(json.analysis.problems) +process.exit(1) diff --git a/packages/web/build.mts b/packages/web/build.ts similarity index 71% rename from packages/web/build.mts rename to packages/web/build.ts index ad8cc749bae7..c481b2ec205e 100644 --- a/packages/web/build.mts +++ b/packages/web/build.ts @@ -1,9 +1,10 @@ +import { writeFileSync } from 'node:fs' + import { build, defaultBuildOptions, defaultIgnorePatterns, } from '@redwoodjs/framework-tools' -import { writeFileSync } from 'node:fs' // CJS build /** @@ -16,7 +17,7 @@ import { writeFileSync } from 'node:fs' */ await build({ entryPointOptions: { - ignore: [...defaultIgnorePatterns, 'src/__typetests__/**', 'src/entry/**'], + ignore: [...defaultIgnorePatterns, 'src/__typetests__/**'], //, 'src/entry/**'], }, buildOptions: { ...defaultBuildOptions, @@ -41,10 +42,15 @@ await build({ }, }) -// Place a package.json file with `type: commonjs` in the dist folder so that -// all .js files are treated as CommonJS files. +// Place a package.json file with `type: commonjs` in the dist/cjs folder so +// that all .js files are treated as CommonJS files. writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) -// Place a package.json file with `type: module` in the dist/esm folder so that +// Place a package.json file with `type: module` in the dist folder so that // all .js files are treated as ES Module files. writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) + +// tsc doesn't generate any types here, because the source file is a javascript +// file. But it's really simple. It doesn't have any exports. So we can just +// write the type definitions ourselves +writeFileSync('dist/entry/index.d.ts', 'export {}\n') diff --git a/packages/web/package.json b/packages/web/package.json index a8a7554a4022..6a5b85b89202 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -22,30 +22,54 @@ }, "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.js", - "require": "./dist/cjs/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/cjs/index.d.ts", + "default": "./dist/cjs/index.js" + } }, "./serverInject": { - "types": "./dist/components/ServerInject.d.ts", - "import": "./dist/components/ServerInject.js", - "default": "./dist/cjs/components/ServerInject.js" + "import": { + "types": "./dist/components/ServerInject.d.ts", + "default": "./dist/components/ServerInject.js" + }, + "require": { + "types": "./dist/cjs/components/ServerInject.d.ts", + "default": "./dist/cjs/components/ServerInject.js" + } }, "./request": { - "types": "./dist/server/request.d.ts", - "import": "./dist/server/request.js", - "default": "./dist/cjs/server/request.js" + "import": { + "types": "./dist/server/request.d.ts", + "default": "./dist/server/request.js" + }, + "require": { + "types": "./dist/cjs/server/request.d.ts", + "default": "./dist/cjs/server/request.js" + } }, "./middleware": { - "types": "./dist/server/middleware.d.ts", - "import": "./dist/server/middleware.js", - "default": "./dist/cjs/server/middleware.js" + "import": { + "types": "./dist/server/middleware.d.ts", + "default": "./dist/server/middleware.js" + }, + "require": { + "types": "./dist/cjs/server/middleware.d.ts", + "default": "./dist/cjs/server/middleware.js" + } }, "./dist/server/middleware": { - "require": "./dist/cjs/server/middleware.js", - "types": "./dist/server/middleware.d.ts", - "import": "./dist/server/middleware.js", - "default": "./dist/cjs/server/middleware.js" + "import": { + "types": "./dist/server/middleware.d.ts", + "default": "./dist/server/middleware.js" + }, + "require": { + "types": "./dist/cjs/server/middleware.d.ts", + "default": "./dist/cjs/server/middleware.js" + } }, "./dist/components/*": { "require": "./dist/cjs/components/*.js", @@ -71,14 +95,24 @@ "default": "./dist/entry/index.js" }, "./toast": { - "types": "./dist/toast/index.d.ts", - "import": "./dist/toast/index.js", - "default": "./dist/cjs/toast/index.js" + "import": { + "types": "./dist/toast/index.d.ts", + "default": "./dist/toast/index.js" + }, + "require": { + "types": "./dist/cjs/toast/index.d.ts", + "default": "./dist/cjs/toast/index.js" + } }, "./apollo": { - "types": "./dist/apollo/index.d.ts", - "import": "./dist/apollo/index.js", - "default": "./dist/cjs/apollo/index.js" + "import": { + "types": "./dist/apollo/index.d.ts", + "default": "./dist/apollo/index.js" + }, + "require": { + "types": "./dist/cjs/apollo/index.d.ts", + "default": "./dist/cjs/apollo/index.js" + } }, "./forceEsmApollo": { "require": "./dist/apollo/index.js", @@ -92,12 +126,15 @@ "src/entry" ], "scripts": { - "build": "tsx ./build.mts && yarn build:types", + "build": "tsx ./build.ts && yarn build:types", "build:pack": "yarn pack -o redwoodjs-web.tgz", "build:types": "tsc --build --verbose ./tsconfig.json ./tsconfig.types-cjs.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "vitest run", + "test": "concurrently npm:test:vitest npm:test:attw npm:test:publint", + "test:vitest": "vitest run", + "test:attw": "tsx ./attw.ts", + "test:publint": "yarn publint", "test:types": "tstyche", "test:watch": "vitest watch" }, @@ -118,6 +155,7 @@ }, "devDependencies": { "@apollo/client-react-streaming": "0.10.0", + "@arethetypeswrong/cli": "0.15.3", "@babel/cli": "7.24.5", "@babel/core": "^7.22.20", "@babel/plugin-transform-runtime": "7.24.3", @@ -129,7 +167,9 @@ "@testing-library/react": "14.3.1", "@types/react": "^18.2.55", "@types/react-dom": "^18.2.19", + "concurrently": "8.2.2", "nodemon": "3.1.3", + "publint": "0.2.8", "react": "19.0.0-beta-04b058868c-20240508", "react-dom": "19.0.0-beta-04b058868c-20240508", "tstyche": "2.0.0", diff --git a/packages/web/tsconfig.json b/packages/web/tsconfig.json index e1e11dacc0f5..6f5da81e0a26 100644 --- a/packages/web/tsconfig.json +++ b/packages/web/tsconfig.json @@ -13,11 +13,6 @@ "testing-library.d.ts" ], "references": [ - { - "path": "../auth/tsconfig.build.json" - }, - { - "path": "../internal" - } + { "path": "../internal" } ] } diff --git a/yarn.lock b/yarn.lock index 85fc878f61b3..6ad3aec90288 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8788,6 +8788,7 @@ __metadata: dependencies: "@apollo/client": "npm:3.9.9" "@apollo/client-react-streaming": "npm:0.10.0" + "@arethetypeswrong/cli": "npm:0.15.3" "@babel/cli": "npm:7.24.5" "@babel/core": "npm:^7.22.20" "@babel/plugin-transform-runtime": "npm:7.24.3" @@ -8803,11 +8804,13 @@ __metadata: "@types/react": "npm:^18.2.55" "@types/react-dom": "npm:^18.2.19" "@whatwg-node/fetch": "npm:0.9.17" + concurrently: "npm:8.2.2" core-js: "npm:3.37.1" graphql: "npm:16.8.1" graphql-sse: "npm:2.5.3" graphql-tag: "npm:2.12.6" nodemon: "npm:3.1.3" + publint: "npm:0.2.8" react: "npm:19.0.0-beta-04b058868c-20240508" react-dom: "npm:19.0.0-beta-04b058868c-20240508" react-helmet-async: "npm:2.0.5" From 81769b94fe5b26b7c550331e50effb07ee23c615 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Sun, 14 Jul 2024 15:41:34 +0200 Subject: [PATCH 6/6] chore(web): Use attw args instead of custom output parsing (#10944) --- packages/web/attw.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/web/attw.ts b/packages/web/attw.ts index 30cc6559892e..b088b0e2af82 100644 --- a/packages/web/attw.ts +++ b/packages/web/attw.ts @@ -6,7 +6,9 @@ interface Problem { resolutionKind?: string } -await $({ nothrow: true })`yarn attw -P -f json > .attw.json` +await $({ + nothrow: true, +})`yarn attw -P --exclude-entrypoints webpackEntry forceEsmApollo -f json > .attw.json` const output = await $`cat .attw.json` await $`rm .attw.json` @@ -19,13 +21,10 @@ if (!json.analysis.problems || json.analysis.problems.length === 0) { if ( json.analysis.problems.every( - (problem: Problem) => - problem.resolutionKind === 'node10' || - problem.entrypoint === './webpackEntry' || - problem.entrypoint === './forceEsmApollo', + (problem: Problem) => problem.resolutionKind === 'node10', ) ) { - console.log("Only found problems we don't care about") + console.log("Only found node10 problems, which we don't care about") process.exit(0) }