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

build(headless-react): move to esm #3194

Merged
merged 19 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3256cf0
config node support to 18 or 20
mrrajamanickam-coveo Sep 15, 2023
8a57740
vsc workspace: remove obs ref to headless-next, reorder
mrrajamanickam-coveo Sep 15, 2023
ef7afab
Merge branch 'master' into KIT-2661_add_bundler_headless_react
mrrajamanickam-coveo Sep 18, 2023
34197df
removed redundant build tsconfig
mrrajamanickam-coveo Sep 18, 2023
a5912de
move to esm module
mrrajamanickam-coveo Sep 18, 2023
2202b29
add esm config for jest
mrrajamanickam-coveo Sep 18, 2023
d8b5b5c
reuse base tsconfig for test
mrrajamanickam-coveo Sep 18, 2023
829c44c
add release scripts, bump version
mrrajamanickam-coveo Sep 19, 2023
26f9edf
revert version bump to fix build issues
mrrajamanickam-coveo Sep 19, 2023
320d1c5
Merge branch 'master' into KIT-2661_add_bundler_headless_react
mrrajamanickam-coveo Sep 19, 2023
682f4f5
Merge branch 'master' into KIT-2661_add_bundler_headless_react
mrrajamanickam-coveo Sep 19, 2023
55f37cc
add rimraf dev dep
mrrajamanickam-coveo Sep 19, 2023
05746e2
add esm package config linter
mrrajamanickam-coveo Sep 19, 2023
bcf0b96
convert jest config to mjs
mrrajamanickam-coveo Sep 19, 2023
2da7b80
reexport headless/ssr
mrrajamanickam-coveo Sep 19, 2023
3b24efa
add ref to ts-jest bug
mrrajamanickam-coveo Sep 19, 2023
1bb71c4
add ssr subpackage
mrrajamanickam-coveo Sep 20, 2023
2d8b514
change refs in headless-ssr samples to reflect new ssr subpath
mrrajamanickam-coveo Sep 20, 2023
8d3ab8f
Merge branch 'master' into KIT-2661_add_bundler_headless_react
mrrajamanickam-coveo Sep 20, 2023
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
127 changes: 126 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/headless-react/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Headless React Utils for SSR

`@coveo/headless-react/ssr` provides react utilities for Server side rendering with headless controllers.
Refer to [samples/headless-ssr](https://github.com/coveo/ui-kit/tree/master/packages/samples/headless-ssr/src/app/react) for examples.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
export default {
testEnvironment: 'jsdom',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.test.json'
tsconfig: 'tsconfig.test.json',
},
],
},
Expand Down
15 changes: 12 additions & 3 deletions packages/headless-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
"ssr"
],
"license": "Apache-2.0",
"main": "dist/index.js",
"type": "module",
"exports": {
"./ssr": "./dist/ssr/index.js"
},
"files": [
"dist"
],
"scripts": {
"build": "nx build",
"clean": "rimraf dist",
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
"test": "jest",
"test:watch": "jest --watch --colors --no-cache",
"lint": "eslint ."
"lint": "eslint .; publint",
"release:phase1": "npx -p=@coveo/release bump",
"release:phase2": "npx -p=@coveo/release npm-publish",
"promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs latest"
},
"dependencies": {
"@coveo/headless": "2.32.0"
Expand All @@ -40,6 +47,8 @@
"gts": "5.0.1",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"publint": "0.2.2",
"rimraf": "5.0.1",
"ts-jest": "29.1.1",
"typescript": "5.2.2"
},
Expand All @@ -48,6 +57,6 @@
"react-dom": "^18"
},
"engines": {
"node": ">=18"
"node": "^18 || ^20"
}
}
2 changes: 1 addition & 1 deletion packages/headless-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cached:build": {
"executor": "nx:run-commands",
"options": {
"command": "tsc --project ./tsconfig.build.json",
"command": "tsc --project ./tsconfig.json",
"cwd": "packages/headless-react"
}
},
Expand Down
1 change: 0 additions & 1 deletion packages/headless-react/src/index.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/headless-react/src/ssr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export {defineSearchEngine} from './search-engine.js';
export * from '@coveo/headless/ssr';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
} from '@coveo/headless/ssr';
import {render, renderHook, screen} from '@testing-library/react';
import {PropsWithChildren} from 'react';
import {MissingEngineProviderError, defineSearchEngine} from './search-engine';
import {
MissingEngineProviderError,
defineSearchEngine,
} from './search-engine.js';

describe('Headless react SSR utils', () => {
let errorSpy: jest.SpyInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
import {useContext, useCallback, useMemo, Context} from 'react';
// Workaround to prevent Next.js erroring about importing CSR only hooks
import React from 'react';
import {useSyncMemoizedStore} from './client-utils';
import {useSyncMemoizedStore} from './client-utils.js';
import {
ContextHydratedState,
ContextState,
ControllerHook,
InferControllerHooksMapFromDefinition,
ReactSearchEngineDefinition,
} from './types';
import {SingletonGetter, capitalize, singleton, mapObject} from './utils';
} from './types.js';
import {SingletonGetter, capitalize, singleton, mapObject} from './utils.js';

export class MissingEngineProviderError extends Error {
static message =
Expand Down
4 changes: 0 additions & 4 deletions packages/headless-react/tsconfig.build.json

This file was deleted.

7 changes: 4 additions & 3 deletions packages/headless-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"sourceMap": true,
"declaration": true,
"jsx": "react-jsx",
"rootDir": "src/",
"outDir": "dist/",
"moduleResolution": "Node",
"module": "ES2022",
"moduleResolution": "NodeNext",
"module": "NodeNext",
"target": "ES2022",
"lib": ["dom", "ES2022"]
},
"exclude": ["**/*.test.ts", "**/*.test.tsx" ],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"],
"include": ["src/**/*.ts", "src/**/*.tsx"]
}
25 changes: 3 additions & 22 deletions packages/headless-react/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
{
"extends": "../../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"allowUnreachableCode": false,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": false,
"sourceMap": true,
"declaration": true,
"jsx": "react-jsx",
"outDir": "dist/",
// TODO: Remove override after bug is fixed https://github.com/kulshekhar/ts-jest/issues/4198
"moduleResolution": "Node",
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
"module": "ES2022",
"target": "ES2022",
"lib": ["dom", "ES2022"],
"types": ["jest", "react", "react-dom"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"]
,
}
}
2 changes: 1 addition & 1 deletion packages/samples/headless-ssr/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## About

- This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
- It demonstrates usage of the framework agnostic `@coveo/headless/ssr` and `@coveo/headless-react` utils for Server-Side Rendering with headless.
- It demonstrates usage of the framework agnostic `@coveo/headless/ssr` and `@coveo/headless-react/ssr` utils for Server-Side Rendering with headless.
- Although NextJS is used to demonstrate SSR usage for convenience, the utils are not specific to NextJS.

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion packages/samples/headless-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coveo/headless-ssr-samples",
"description": "Examples using framework agnostic @coveo/headless/ssr utils and @coveo/headless-react",
"description": "Examples using framework agnostic @coveo/headless/ssr utils and @coveo/headless-react/ssr",
"version": "0.0.0",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/samples/headless-ssr/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const metadata = {
title: 'Headless SSR examples',
description:
'Examples of using framework agnostic @coveo/headless/ssr utils and @coveo/headless-react',
'Examples of using framework agnostic @coveo/headless/ssr utils and @coveo/headless-react/ssr',
};

export default function RootLayout({children}: {children: React.ReactNode}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {defineSearchEngine} from '@coveo/headless-react';
import {defineSearchEngine} from '@coveo/headless-react/ssr';
import {InferStaticState, InferHydratedState} from '@coveo/headless/ssr';
import {config} from '../../common/search-engine-config';

Expand Down
28 changes: 12 additions & 16 deletions ui-kit.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,10 @@
"name": "📦 Atomic Hosted Page",
"path": "./packages/atomic-hosted-page"
},
{
"name": "📄 Atomic Storybook documentation",
"path": "./utils/atomic-storybook"
},
{
"name": "🚀 IIFE samples",
"path": "./packages/samples/iife"
},
{
"name": "🚀 Stencil samples",
"path": "./packages/samples/stencil"
},
{
"name": "🚀 React samples (Headless)",
"path": "./packages/samples/headless-react"
},
{
mrrajamanickam-coveo marked this conversation as resolved.
Show resolved Hide resolved
"name": "🚀 Next.js samples (Headless)",
"path": "./packages/samples/headless-next"
},
{
"name": "🚀 React samples (Atomic)",
"path": "./packages/samples/atomic-react"
Expand All @@ -80,6 +64,18 @@
"name": "🚀 Vue.js samples",
"path": "./packages/samples/vuejs"
},
{
"name": "🚀 IIFE samples",
"path": "./packages/samples/iife"
},
{
"name": "🚀 Stencil samples",
"path": "./packages/samples/stencil"
},
{
"name": "📄 Atomic Storybook documentation",
"path": "./utils/atomic-storybook"
},
{
"name": "⚙️ Release utilities",
"path": "./utils/release"
Expand Down