Skip to content

Commit

Permalink
Merge branch 'main' of github.com:redwoodjs/redwood into rc-og-image-…
Browse files Browse the repository at this point in the history
…support

* 'main' of github.com:redwoodjs/redwood: (30 commits)
  fix(scenario): Make sure to cleanup even if test fails (#10112)
  Update babel monorepo to v7.24.0 (#10090)
  Update storybook monorepo to v7.6.17 (#10089)
  Update dependency @apollo/client to v3.9.5 (#10087)
  fix(serve): Allow periods in most paths (#10114)
  feat(rsc-streaming): Integrating RSC builds with Streaming and Client side hydration (#10031)
  chore(style): getDefaultViteConfig source format (#10111)
  chore(refactor): vite - extract default vite config (#10110)
  chore(comment): cli index FIXME comment about ugly big red box
  RSC: rscBuildAnalyze: Start at web/src/ (#10109)
  RSC: ensureProcessDirWeb() (#10108)
  RSC: Extract webpack shims into their own file (#10107)
  RSC: Remove completed TODO comment
  RSC: Babel react plugin not needed for analyze phase (#10106)
  RSC: runFeServer: wrap RSC code with `if (rscEnabled)` (#10105)
  RSC: Update comments, naming etc based on Danny's input (#10104)
  RSC: Rename to buildRscClientAndServer (#10103)
  RSC: Rename to rscBuildForServer, and tweak some comments (#10102)
  SSR: Extract buildForStreamingServer function (#10099)
  chore(unit-tests): Silence middleware error logging (#10097)
  ...
  • Loading branch information
dac09 committed Mar 6, 2024
2 parents cc8ad07 + e9ecbb0 commit 409357b
Show file tree
Hide file tree
Showing 126 changed files with 1,538 additions and 7,640 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ jobs:
working-directory: ./tasks/e2e
spec: |
cypress/e2e/01-tutorial/*.cy.js
cypress/e2e/04-logger/*.cy.js
- uses: actions/upload-artifact@v4
if: always()
Expand Down
52 changes: 37 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

## Unreleased

- fix(scenario): Make sure to clean up scenarios even if tests fail (#10112)
Fixes an issue where a unit test failure would cause the scenario cleanup to be skipped. Thanks @peraltafederico and @cjreimer for highlighting this!

- fix(serve): Allow periods in most paths (#10114)

Partial fix for route paths with periods in them.

It's only "partial" because it doesn't fix it for `yarn rw dev`, as that's a
Vite bug
([vitejs/vite#2415 (comment)](https://github.com/vitejs/vite/issues/2415#issuecomment-1720814355)).
And there's also an edge case for yarn rw serve where this doesn't fully
handle client-side routes that start with /assets/ and that also have a
last-segment that accepts a period, like /assets/client-route-image.jpg

Fixes #9969

- fix(deps): update prisma monorepo to v5.10.2 (#10088)

This release updates Prisma to v5.10.2. Here are quick links to all the release notes since the last version (v5.9.1):

- https://github.com/prisma/prisma/releases/tag/5.10.0
- https://github.com/prisma/prisma/releases/tag/5.10.1
- https://github.com/prisma/prisma/releases/tag/5.10.2

- fix(deps): update opentelemetry-js monorepo (#10065)

Updates our opentelemetry packages. This is a breaking change for users of
Expand Down Expand Up @@ -29,28 +53,26 @@
DataDog/import-in-the-middle#57
* This version does not support Node.js 18.19 or later

- Add support for additional env var files (#9961)
- Add support for loading more env var files (#9961, #10093, and #10094)

Fixes #9877. This PR adds a new middleware step to the CLI that looks for an `--include-env-files` flag and includes `.env.[file]` to the list of dotfiles to load. This PR also introduces functionality so that `.env.[file]` files are loaded based on `NODE_ENV`.

Using the `--include-env-files` flag:

```bash
yarn rw exec myScript --include-env-files prod stripe-prod
# Alternatively you can specify the flag twice:
yarn rw exec myScript --include-env-files prod --include-env-files stripe-prod
```

Using `NODE_ENV`:
Fixes #9877. This PR adds CLI functionality to load more `.env` files via `NODE_ENV` and an `--add-env-files` flag.
Env vars loaded via either of these methods override the values in `.env`:

```
# loads .env.production
# Loads '.env.production', which overrides values in '.env'
NODE_ENV=production yarn rw exec myScript
# Load '.env.stripe' and '.env.nakama', which overrides values
yarn rw exec myScript --add-env-files stripe --add-env-files nakama
# Or you can specify the flag once:
yarn rw exec myScript --add-env-files stripe nakama
```

These files are loaded in addition to `.env` and `.env.defaults` and more generally are additive. Subsequent dotfiles won't overwrite environment variables defined previous ones. As such, files loaded via NODE_ENV have lower priority than those loaded specifically via `--include-env-files`.
Note that this feature is mainly for local scripting. Most deploy providers don't let you upload `.env` files (unless you're using baremetal) and usually have their own way of determining environments.

## v7.0.6

Note that this feature is mainly for local scripting. Most deploy providers don't let you upload dotfiles and usually have their own way of determining environments.
- See https://github.com/redwoodjs/redwood/releases/tag/v7.0.6

## v7.0.5

Expand Down
35 changes: 1 addition & 34 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,37 +343,4 @@ yarn rw upgrade --tag rc

## Publishing New Versions: `@latest`

> **New `yarn release` Publishing Command**
>
> As of February 2022, there's a new command `yarn release` that covers all the necessary steps:
>
> 1. starting with creating a release branch
> 2. to creating a milestone and assigning it to PRs
> 3. to preparing and publishing packages
> 4. to creating release notes
>
> 🚀
To publish a new version of Redwood to NPM, run the following commands:

> NOTE: `<version>` should be formatted like `v0.24.0` (for example)
```bash
git clean -dfx
yarn install
./tasks/update-package-versions <version>
git commit -am "<version>"
git tag -am <version> "<version>"
git push && git push --tags
yarn build
yarn lerna publish from-package
```

This...

1) changes the version of **all the packages** (even those that haven't changed),
2) changes the version of the packages within the CRWA Template
3) commits, tags, and pushes to GitHub
4) and finally publishes all packages to NPM.

If something went wrong you can use `yarn lerna publish from-package` to publish the packages that aren't already in the registry.
See https://github.com/redwoodjs/release-tooling.
2 changes: 1 addition & 1 deletion __fixtures__/test-project/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@redwoodjs/vite": "7.0.0",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"autoprefixer": "^10.4.17",
"autoprefixer": "^10.4.18",
"postcss": "^8.4.35",
"postcss-loader": "^8.1.1",
"prettier-plugin-tailwindcss": "0.4.1",
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
"project:tarsync": "node ./tasks/framework-tools/tarsync.mjs",
"rebuild-test-project-fixture": "tsx ./tasks/test-project/rebuild-test-project-fixture.ts",
"rebuild-fragments-test-project-fixture": "tsx ./tasks/test-project/rebuild-fragments-test-project-fixture.ts",
"release": "node ./tasks/release/release.mjs",
"release:compare": "node ./tasks/release/compare/compare.mjs",
"release:notes": "node ./tasks/release/generateReleaseNotes.mjs",
"release:triage": "node ./tasks/release/triage/triage.mjs",
"smoke-tests": "node ./tasks/smoke-tests/smoke-tests.mjs",
"test": "nx run-many -t test -- --minWorkers=1 --maxWorkers=4",
"test-ci": "nx run-many -t test",
Expand All @@ -55,17 +51,17 @@
"@babel/core": "^7.22.20",
"@babel/generator": "7.23.6",
"@babel/node": "7.23.9",
"@babel/plugin-proposal-decorators": "7.23.9",
"@babel/plugin-proposal-decorators": "7.24.0",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/plugin-transform-nullish-coalescing-operator": "7.23.4",
"@babel/plugin-transform-private-methods": "^7.22.5",
"@babel/plugin-transform-private-property-in-object": "^7.22.11",
"@babel/plugin-transform-react-jsx": "^7.22.15",
"@babel/plugin-transform-runtime": "7.23.9",
"@babel/plugin-transform-runtime": "7.24.0",
"@babel/preset-env": "^7.22.20",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.22.15",
"@babel/runtime-corejs3": "7.23.9",
"@babel/runtime-corejs3": "7.24.0",
"@faker-js/faker": "8.0.2",
"@npmcli/arborist": "7.2.2",
"@playwright/test": "1.41.2",
Expand Down
55 changes: 48 additions & 7 deletions packages/adapters/fastify/web/src/web.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import fs from 'fs'
import path from 'path'
import * as fs from 'fs'
import * as path from 'path'

import type { FastifyInstance } from 'fastify'
import Fastify from 'fastify'
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'

import { getPaths } from '@redwoodjs/project-config'

import { redwoodFastifyWeb } from './web'

let original_RWJS_CWD
let original_RWJS_CWD: string

beforeAll(() => {
original_RWJS_CWD = process.env.RWJS_CWD
Expand All @@ -24,7 +25,7 @@ describe('redwoodFastifyWeb', () => {
console.log = vi.fn()

// Set up and teardown the fastify instance with options.
let fastifyInstance
let fastifyInstance: FastifyInstance

const port = 8910

Expand Down Expand Up @@ -248,16 +249,56 @@ describe('redwoodFastifyWeb', () => {
})

describe("returns a 404 for assets that can't be found", () => {
it("returns a 404 for non-html assets that can't be found", async () => {
it("returns a 404 for assets that can't be found", async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/kittens.png',
url: '/assets/kittens.png',
})

expect(res.statusCode).toBe(404)
})

it('handles "."s in routes', async () => {
// This is testing current behavior - not ideal behavior. Feel free to
// update this test if you change the behavior.
// It's for the (hopefully rare) case where someone has a client-side
// route for /assets
it('returns a 200 for plain files, even in /assets/', async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/assets/kittens',
})

expect(res.statusCode).toBe(200)
})

it('handles "."s in route segments', async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/my.page/foo',
})

expect(res.statusCode).toBe(200)
})

it('handles "."s in last route segment', async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/foo/my.page',
})

expect(res.statusCode).toBe(200)
})

it('handles filenames in route segments', async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/file-route/fake.js',
})

expect(res.statusCode).toBe(200)
})

it('handles "."s in query params', async () => {
const res = await fastifyInstance.inject({
method: 'GET',
url: '/my-page?loading=spinner.blue',
Expand Down
41 changes: 29 additions & 12 deletions packages/adapters/fastify/web/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,36 @@ export async function redwoodFastifyWeb(
// For SPA routing, fallback on unmatched routes and let client-side routing take over
fastify.setNotFoundHandler({}, (req, reply) => {
const urlData = req.urlData()
const requestedExtension = path.extname(urlData.path ?? '')

// Paths with no extension (`/about`) or an .html extension (`/about.html`)
// should be handled by the client side router.
// See the discussion in https://github.com/redwoodjs/redwood/pull/9272.
if (requestedExtension === '' || requestedExtension === '.html') {
reply.header('Content-Type', 'text/html; charset=UTF-8')
return reply.sendFile(fallbackIndexPath)
const requestHasExtension = !!path.extname(urlData.path ?? '')

// Further up in this file we use `fastifyStatic` to serve files from the
// /web/dist folder. Most often for files like AboutPage-12ab34cd.js or
// some css file.
// Requests for other paths should most often be handled by client side
// routing. Like requests /about or /about.html.
// One exception for this is requests for assets that don't exist anymore.
// Like AboutPage-old_hash.js. These requests should return 404.
// The problem is we don't know what those assets are. So the best we can
// do is to return 404 for all requests for files in /assets that have an
// extension.
//
// See the discussions in https://github.com/redwoodjs/redwood/pull/9272
// and https://github.com/redwoodjs/redwood/issues/9969

if (requestHasExtension && urlData.path?.startsWith('/assets/')) {
// If we got here, the user is most likely requesting an asset with an
// extension (like `assets/AboutPage-xyz789.js`) that doesn't exist
//
// NOTE: This is a best guess, and could be wrong. The user could have
// a client-side route setup for /assets/client-side/{...} and in that
// case we really should pass this on to the client-side router instead
// of returning 404.
reply.code(404)
return reply.send('Not Found')
}

// If we got here, the user is requesting an asset with an extension
// (like `profile.png`) that doesn't exist
reply.code(404)
return reply.send('Not Found')
// Let client-side routing take over
reply.header('Content-Type', 'text/html; charset=UTF-8')
return reply.sendFile(fallbackIndexPath)
})
}

This file was deleted.

49 changes: 22 additions & 27 deletions packages/api-server/src/plugins/lambdaLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,32 @@ export const setLambdaFunctions = async (foundFunctions: string[]) => {
const tsImport = Date.now()
console.log(chalk.dim.italic('Importing Server Functions... '))

const imports = foundFunctions.map((fnPath) => {
return new Promise((resolve) => {
const ts = Date.now()
const routeName = path.basename(fnPath).replace('.js', '')

const { handler } = require(fnPath)
LAMBDA_FUNCTIONS[routeName] = handler
if (!handler) {
console.warn(
routeName,
'at',
fnPath,
'does not have a function called handler defined.'
)
}
// TODO: Use terminal link.
console.log(
chalk.magenta('/' + routeName),
chalk.dim.italic(Date.now() - ts + ' ms')
const imports = foundFunctions.map(async (fnPath) => {
const ts = Date.now()
const routeName = path.basename(fnPath).replace('.js', '')

const { handler } = await import(`file://${fnPath}`)
LAMBDA_FUNCTIONS[routeName] = handler
if (!handler) {
console.warn(
routeName,
'at',
fnPath,
'does not have a function called handler defined.'
)
return resolve(true)
})
})

Promise.all(imports).then((_results) => {
}
// TODO: Use terminal link.
console.log(
chalk.dim.italic(
'...Done importing in ' + (Date.now() - tsImport) + ' ms'
)
chalk.magenta('/' + routeName),
chalk.dim.italic(Date.now() - ts + ' ms')
)
})

await Promise.all(imports)

console.log(
chalk.dim.italic('...Done importing in ' + (Date.now() - tsImport) + ' ms')
)
}

type LoadFunctionsFromDistOptions = {
Expand Down
Loading

0 comments on commit 409357b

Please sign in to comment.