Skip to content

Commit

Permalink
build(headless-react): move to esm (#3194)
Browse files Browse the repository at this point in the history
* config node support to 18 or 20

https://coveord.atlassian.net/browse/KIT-2661

* vsc workspace: remove obs ref to headless-next, reorder

https://coveord.atlassian.net/browse/KIT-2661

* removed redundant build tsconfig

https://coveord.atlassian.net/browse/KIT-2661

* move to esm module

https://coveord.atlassian.net/browse/KIT-2661

* add esm config for jest

https://coveord.atlassian.net/browse/KIT-2661

* reuse base tsconfig for test

https://coveord.atlassian.net/browse/KIT-2661

* add release scripts, bump version

https://coveord.atlassian.net/browse/KIT-2661

* revert version bump to fix build issues

https://coveord.atlassian.net/browse/KIT-2661

* add rimraf dev dep

https://coveord.atlassian.net/browse/KIT-2661

* add esm package config linter

https://coveord.atlassian.net/browse/KIT-2661

* convert jest config to mjs

https://coveord.atlassian.net/browse/KIT-2661

* reexport headless/ssr

https://coveord.atlassian.net/browse/KIT-2661

* add ref to ts-jest bug

https://coveord.atlassian.net/browse/KIT-2661

* add ssr subpackage

https://coveord.atlassian.net/browse/KIT-2661

* change refs in headless-ssr samples to reflect new ssr subpath

https://coveord.atlassian.net/browse/KIT-2661
  • Loading branch information
mrrajamanickam-coveo authored Sep 20, 2023
1 parent 3cad7b2 commit df0ad6b
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 61 deletions.
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.

File renamed without changes.
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",
"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.

File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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",
"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"
},
{
"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

0 comments on commit df0ad6b

Please sign in to comment.