diff --git a/package-lock.json b/package-lock.json index 6d1ccf6bef7..3c186aa2bf2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34168,6 +34168,15 @@ "node": "*" } }, + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/mrmime": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-1.0.1.tgz", @@ -38650,6 +38659,108 @@ "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" }, + "node_modules/publint": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/publint/-/publint-0.2.2.tgz", + "integrity": "sha512-2t2IO6Y8Z+QBNLG89bpRhTQH7Ifn/83Kr0dVVdmOybq7GAT6+M4YGZd5AhtfMJbYPmbT7YD469pDKLCK94Q2+Q==", + "dev": true, + "dependencies": { + "npm-packlist": "^5.1.3", + "picocolors": "^1.0.0", + "sade": "^1.8.1" + }, + "bin": { + "publint": "lib/cli.js" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://bjornlu.com/sponsor" + } + }, + "node_modules/publint/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/publint/node_modules/ignore-walk": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-5.0.1.tgz", + "integrity": "sha512-yemi4pMf51WKT7khInJqAvsIGzoqYXblnsz0ql8tM+yi1EKYTY1evX4NAbJrLL/Aanr2HyZeluqU+Oi7MGHokw==", + "dev": true, + "dependencies": { + "minimatch": "^5.0.1" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/publint/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/publint/node_modules/npm-bundled": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-2.0.1.tgz", + "integrity": "sha512-gZLxXdjEzE/+mOstGDqR6b0EkhJ+kM6fxM6vUuckuctuVPh80Q6pw/rSZj9s4Gex9GxWtIicO1pc8DB9KZWudw==", + "dev": true, + "dependencies": { + "npm-normalize-package-bin": "^2.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/publint/node_modules/npm-normalize-package-bin": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-2.0.0.tgz", + "integrity": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==", + "dev": true, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/publint/node_modules/npm-packlist": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-5.1.3.tgz", + "integrity": "sha512-263/0NGrn32YFYi4J533qzrQ/krmmrWwhKkzwTuM4f/07ug51odoaNjUexxO4vxlzURHcmYMH1QjvHjsNDKLVg==", + "dev": true, + "dependencies": { + "glob": "^8.0.1", + "ignore-walk": "^5.0.1", + "npm-bundled": "^2.0.0", + "npm-normalize-package-bin": "^2.0.0" + }, + "bin": { + "npm-packlist": "bin/index.js" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -40661,6 +40772,18 @@ "tslib": "^2.1.0" } }, + "node_modules/sade": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/sade/-/sade-1.8.1.tgz", + "integrity": "sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==", + "dev": true, + "dependencies": { + "mri": "^1.1.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/safe-array-concat": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.0.1.tgz", @@ -81970,11 +82093,13 @@ "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" }, "engines": { - "node": ">=18" + "node": "^18 || ^20" }, "peerDependencies": { "react": "^18", diff --git a/packages/headless-react/.eslintrc.js b/packages/headless-react/.eslintrc.cjs similarity index 100% rename from packages/headless-react/.eslintrc.js rename to packages/headless-react/.eslintrc.cjs diff --git a/packages/headless-react/README.md b/packages/headless-react/README.md index e55db0df088..73ed0912e27 100644 --- a/packages/headless-react/README.md +++ b/packages/headless-react/README.md @@ -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. diff --git a/packages/headless-react/jest.config.js b/packages/headless-react/jest.config.mjs similarity index 71% rename from packages/headless-react/jest.config.js rename to packages/headless-react/jest.config.mjs index b661a8f196e..d4f35bc9f83 100644 --- a/packages/headless-react/jest.config.js +++ b/packages/headless-react/jest.config.mjs @@ -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', }, ], }, diff --git a/packages/headless-react/package.json b/packages/headless-react/package.json index 35e0bf09e59..8c765beec77 100644 --- a/packages/headless-react/package.json +++ b/packages/headless-react/package.json @@ -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" @@ -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" }, @@ -48,6 +57,6 @@ "react-dom": "^18" }, "engines": { - "node": ">=18" + "node": "^18 || ^20" } } diff --git a/packages/headless-react/project.json b/packages/headless-react/project.json index 24d65611936..58e0b7c55cf 100644 --- a/packages/headless-react/project.json +++ b/packages/headless-react/project.json @@ -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" } }, diff --git a/packages/headless-react/src/index.ts b/packages/headless-react/src/index.ts deleted file mode 100644 index 26f841622ed..00000000000 --- a/packages/headless-react/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {defineSearchEngine} from './search-engine'; diff --git a/packages/headless-react/src/client-utils.ts b/packages/headless-react/src/ssr/client-utils.ts similarity index 100% rename from packages/headless-react/src/client-utils.ts rename to packages/headless-react/src/ssr/client-utils.ts diff --git a/packages/headless-react/src/ssr/index.ts b/packages/headless-react/src/ssr/index.ts new file mode 100644 index 00000000000..32adff0d47d --- /dev/null +++ b/packages/headless-react/src/ssr/index.ts @@ -0,0 +1,2 @@ +export {defineSearchEngine} from './search-engine.js'; +export * from '@coveo/headless/ssr'; diff --git a/packages/headless-react/src/search-engine.test.tsx b/packages/headless-react/src/ssr/search-engine.test.tsx similarity index 98% rename from packages/headless-react/src/search-engine.test.tsx rename to packages/headless-react/src/ssr/search-engine.test.tsx index a5e1e291ad0..32e81b61aab 100644 --- a/packages/headless-react/src/search-engine.test.tsx +++ b/packages/headless-react/src/ssr/search-engine.test.tsx @@ -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; diff --git a/packages/headless-react/src/search-engine.tsx b/packages/headless-react/src/ssr/search-engine.tsx similarity index 97% rename from packages/headless-react/src/search-engine.tsx rename to packages/headless-react/src/ssr/search-engine.tsx index 8778601f397..c301697f7f8 100644 --- a/packages/headless-react/src/search-engine.tsx +++ b/packages/headless-react/src/ssr/search-engine.tsx @@ -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 = diff --git a/packages/headless-react/src/types.ts b/packages/headless-react/src/ssr/types.ts similarity index 100% rename from packages/headless-react/src/types.ts rename to packages/headless-react/src/ssr/types.ts diff --git a/packages/headless-react/src/utils.ts b/packages/headless-react/src/ssr/utils.ts similarity index 100% rename from packages/headless-react/src/utils.ts rename to packages/headless-react/src/ssr/utils.ts diff --git a/packages/headless-react/tsconfig.build.json b/packages/headless-react/tsconfig.build.json deleted file mode 100644 index e556d724c7c..00000000000 --- a/packages/headless-react/tsconfig.build.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "./tsconfig.json", - "exclude": ["node_modules", "**/*.test.tsx", "**/*.test.ts"] -} diff --git a/packages/headless-react/tsconfig.json b/packages/headless-react/tsconfig.json index 16b31b92836..d84f60d587a 100644 --- a/packages/headless-react/tsconfig.json +++ b/packages/headless-react/tsconfig.json @@ -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"] } diff --git a/packages/headless-react/tsconfig.test.json b/packages/headless-react/tsconfig.test.json index c9c2e1fea5e..7b6a65350b4 100644 --- a/packages/headless-react/tsconfig.test.json +++ b/packages/headless-react/tsconfig.test.json @@ -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"] - , + } } diff --git a/packages/samples/headless-ssr/README.md b/packages/samples/headless-ssr/README.md index a5797efd5ae..65873595914 100644 --- a/packages/samples/headless-ssr/README.md +++ b/packages/samples/headless-ssr/README.md @@ -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 diff --git a/packages/samples/headless-ssr/package.json b/packages/samples/headless-ssr/package.json index 7a88fd0830d..a2ad7981cca 100644 --- a/packages/samples/headless-ssr/package.json +++ b/packages/samples/headless-ssr/package.json @@ -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": { diff --git a/packages/samples/headless-ssr/src/app/layout.tsx b/packages/samples/headless-ssr/src/app/layout.tsx index 0469db42801..a85570e84cf 100644 --- a/packages/samples/headless-ssr/src/app/layout.tsx +++ b/packages/samples/headless-ssr/src/app/layout.tsx @@ -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}) { diff --git a/packages/samples/headless-ssr/src/app/react/common/engine.ts b/packages/samples/headless-ssr/src/app/react/common/engine.ts index acab8baa214..acdaeb57f75 100644 --- a/packages/samples/headless-ssr/src/app/react/common/engine.ts +++ b/packages/samples/headless-ssr/src/app/react/common/engine.ts @@ -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'; diff --git a/ui-kit.code-workspace b/ui-kit.code-workspace index 8e6cb2d4163..b3114736ffb 100644 --- a/ui-kit.code-workspace +++ b/ui-kit.code-workspace @@ -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" @@ -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"