Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(containers): remove @redwoodjs/api-server's @redwoodjs/internal requirement #8455

Merged
merged 4 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"chalk": "4.1.2",
"chokidar": "3.5.3",
"core-js": "3.30.2",
"fast-glob": "3.2.12",
"fast-json-parse": "1.0.3",
"fastify": "4.17.0",
"fastify-raw-body": "4.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/api-server/src/__tests__/withWebServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ const FIXTURE_PATH = path.resolve(

// Mock the dist folder from fixtures,
// because its gitignored
jest.mock('@redwoodjs/internal/dist/files', () => {
jest.mock('../plugins/findPrerenderedHtml', () => {
return {
...jest.requireActual('@redwoodjs/internal/dist/files'),
findPrerenderedHtml: () => {
return ['about.html', 'mocked.html', 'posts/new.html', 'index.html']
},
Expand Down
9 changes: 9 additions & 0 deletions packages/api-server/src/plugins/findPrerenderedHtml.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know how mock this function in a file that has a default export, so I just moved it to a different file

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fg from 'fast-glob'

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

// NOTE: This function was copied from @redwoodjs/internal/dist/files to avoid depending on @redwoodjs/internal.
// import { findPrerenderedHtml } from '@redwoodjs/internal/dist/files'
export function findPrerenderedHtml(cwd = getPaths().web.dist) {
return fg.sync('**/*.html', { cwd, ignore: ['200.html', '404.html'] })
}
13 changes: 12 additions & 1 deletion packages/api-server/src/plugins/lambdaLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import path from 'path'

import c from 'ansi-colors'
import type { Handler } from 'aws-lambda'
import fg from 'fast-glob'
import { FastifyReply, FastifyRequest, RequestGenericInterface } from 'fastify'
import escape from 'lodash.escape'

import { findApiDistFunctions } from '@redwoodjs/internal/dist/files'
import { getPaths } from '@redwoodjs/project-config'

import { requestHandler } from '../requestHandlers/awsLambdaFastify'

Expand Down Expand Up @@ -61,6 +62,16 @@ export const loadFunctionsFromDist = async () => {
await setLambdaFunctions(serverFunctions)
}

// NOTE: Copied from @redwoodjs/internal/dist/files to avoid depending on @redwoodjs/internal.
// import { findApiDistFunctions } from '@redwoodjs/internal/dist/files'
function findApiDistFunctions(cwd: string = getPaths().api.base) {
return fg.sync('dist/functions/**/*.{ts,js}', {
cwd,
deep: 2, // We don't support deeply nested api functions, to maximise compatibility with deployment providers
absolute: true,
})
}

interface LambdaHandlerRequest extends RequestGenericInterface {
Params: {
routeName: string
Expand Down
3 changes: 2 additions & 1 deletion packages/api-server/src/plugins/withWebServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import path from 'path'
import fastifyStatic from '@fastify/static'
import { FastifyInstance, FastifyReply } from 'fastify'

import { findPrerenderedHtml } from '@redwoodjs/internal/dist/files'
import { getPaths } from '@redwoodjs/project-config'

import { loadFastifyConfig } from '../fastify'
import { WebServerArgs } from '../types'

import { findPrerenderedHtml } from './findPrerenderedHtml'

export const getFallbackIndexPath = () => {
const prerenderIndexPath = path.join(getPaths().web.dist, '/200.html')

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6739,6 +6739,7 @@ __metadata:
chalk: 4.1.2
chokidar: 3.5.3
core-js: 3.30.2
fast-glob: 3.2.12
fast-json-parse: 1.0.3
fastify: 4.17.0
fastify-raw-body: 4.2.0
Expand Down