Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into chore/vitepk…
Browse files Browse the repository at this point in the history
…g-dual

* 'main' of github.com:redwoodjs/redwood:
  chore(web): Use attw args instead of custom output parsing (redwoodjs#10944)
  chore(web): publint and attw (redwoodjs#10943)
  chore(auth): Fix esm cjs exports and add tooling to verify correctness (redwoodjs#10942)
  chore(middleware): Move middleware out of rwjs/vite -> rwjs/web/middleware (redwoodjs#10917)
  feat(colors): Add more chalk colors. And prepare for chalk upgrade (redwoodjs#10939)
  fix(g directive): Notes formatting (redwoodjs#10940)
  • Loading branch information
GitHub Actions committed Jul 15, 2024
2 parents 58febbd + 81769b9 commit 50a0db3
Show file tree
Hide file tree
Showing 55 changed files with 642 additions and 208 deletions.
6 changes: 6 additions & 0 deletions .changesets/10939.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion packages/api-server/src/logFormatter/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-providers/dbAuth/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 5 additions & 2 deletions packages/auth-providers/dbAuth/middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import dbAuthApi from '@redwoodjs/auth-dbauth-api'
// Have to import this way, not sure why.
const { dbAuthSession, cookieName: cookieNameCreator } = dbAuthApi
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.js'

Expand Down
2 changes: 1 addition & 1 deletion packages/auth-providers/supabase/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
},
"dependencies": {
"@redwoodjs/auth-supabase-api": "workspace:*",
"@redwoodjs/web": "workspace:*",
"@supabase/ssr": "0.3.0"
},
"devDependencies": {
"@redwoodjs/api": "workspace:*",
"@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions packages/auth-providers/supabase/middleware/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import type {
Middleware,
MiddlewareRequest,
MiddlewareResponse,
// @ts-expect-error next-line. @TODO FIX THIS WITH CJS TYPES
} from '@redwoodjs/vite/middleware'
} from '@redwoodjs/web/middleware'

import { clearAuthState } from './util'
import { clearAuthState } from './util.js'

export interface SupabaseAuthMiddlewareOptions {
getCurrentUser: GetCurrentUser
Expand Down
3 changes: 1 addition & 2 deletions packages/auth-providers/supabase/middleware/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { throwSupabaseSettingsError } from '@redwoodjs/auth-supabase-api'
import type {
MiddlewareRequest,
MiddlewareResponse,
// @ts-expect-error next-line. @TODO FIX THIS WITH CJS TYPES
} from '@redwoodjs/vite/middleware'
} from '@redwoodjs/web/middleware'
/**
* Creates Supabase Server Client used to get the session cookie (only)
* from a given collection of auth cookies
Expand Down
30 changes: 30 additions & 0 deletions packages/auth/attw.ts
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 30 additions & 4 deletions packages/auth/build.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -22,10 +25,33 @@ 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' }))

// 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`
75 changes: 56 additions & 19 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -48,20 +78,27 @@
"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": {
"core-js": "3.37.1",
"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"
Expand Down
8 changes: 1 addition & 7 deletions packages/auth/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
21 changes: 11 additions & 10 deletions packages/cli-helpers/src/lib/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
4 changes: 2 additions & 2 deletions packages/cli-packages/dataMigrate/src/commands/upHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions packages/cli-packages/dataMigrate/src/lib/colors.ts
Original file line number Diff line number Diff line change
@@ -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'),
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/deploy/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 50a0db3

Please sign in to comment.