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: update Vite config for delivery function examples [EXT-6273] #9585

Merged
merged 4 commits into from
Mar 20, 2025

Conversation

whitelisab
Copy link
Contributor

Purpose

We updated the example apps to use Vite instead of CRA/react-scripts in this PR. However, a few things were missed, so this PR aims to clean those up.

Approach

Here's an overview of the changes:

Vite updates

  • Ensure Vite, Vitest, @vitejs/plugin-react and any other dependencies are up to date
  • Ensure that in the Vite config, the build directory is set to ./build instead of the default ./dist. This is because the build-functions script from the @contentful/app-scripts package expects this to be the name for the build directory
  • Add `"base": ''" to the Vite config to support relative paths, more info here
  • Ensure Vitest is configured properly; add /// <reference types="vitest/config" /> when using Vitest, adding the triple slash command as documented here
  • Rename the Vite config file to address this warning
  • Add start script in package.json in addition to to dev

tsconfig.json updates

  • Remove the CRA tsconfig and the associated react-app-env.d.ts file; add any necessary configuration after removing that
  • Ensure that the functions directory has its own tsconfig.json like our function templates

Contentful package dependency updates

  • Update @contentful/app-scripts and @contentful/node-apps-toolkit
  • In the functions code, use the FunctionTypeEnum instead of string values

Documentation updates

  • Remove references to Create React App
  • Remove references to the legacy GraphQL Playground app and instead link to the GraphiQL app

Example-specific changes

The function-mock-shop app had some mistakes copied from another app in the package.json file, so I've addressed those.

The native-external-references-tmdb example needed some additional updates in the test files to move from Jest to Vitest.

Testing steps

I tested these locally in the apps repo and also tested them using CCA according these instructions

Breaking Changes

Dependencies and/or References

Deployment

@whitelisab whitelisab requested a review from a team as a code owner March 20, 2025 13:37
@whitelisab whitelisab requested a review from a team March 20, 2025 13:37
Copy link

netlify bot commented Mar 20, 2025

Deploy Preview for ecommerce-app-base-components canceled.

Name Link
🔨 Latest commit 9e0a6d8
🔍 Latest deploy log https://app.netlify.com/sites/ecommerce-app-base-components/deploys/67dc1a02b0a6d00008959512


type InstallationParameters = {
apiEndpoint: string;
url: string;
};

type EventHandler = FunctionEventHandler<FunctionEventType, InstallationParameters>;
type QueryHandler = FunctionEventHandler<'graphql.query', InstallationParameters>;
type FieldMappingHandler = FunctionEventHandler<'graphql.field.mapping'>;
type QueryHandler = FunctionEventHandler<FunctionTypeEnum.GraphqlQuery, InstallationParameters>;
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

@@ -41,19 +39,19 @@
]
},
"devDependencies": {
"@contentful/app-scripts": "1.33.2",
"@contentful/app-scripts": "^2.3.0",
Copy link
Contributor

@BobHemphill76 BobHemphill76 Mar 20, 2025

Choose a reason for hiding this comment

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

Nice! I believe that's add-locations release!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this should bump all of these examples so they'll have that available!

"jsx": "react"
},
"include": ["./src/**/*.ts", "./setupTests.ts", "./functions/**/*.ts"]
"exclude": ["functions"]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is because build:functions uses a different tsc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly! I ended up updating this example to follow the convention we had in some examples where we have separate tsconfigs for the frontend app and then the functions directory

@whitelisab whitelisab merged commit a1cdca0 into master Mar 20, 2025
17 checks passed
@whitelisab whitelisab deleted the fix/ext-6273-cer-ner branch March 20, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants