Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/headless-cajs-per-module-esm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@coveo/headless': patch
---

Import the `cookie`, `detector`, `storage` and `history-store` modules from `coveo.analytics` instead of keeping vendored copies of them, removing a source of drift between the two packages. No public API change.
Comment thread
Copilot marked this conversation as resolved.
Outdated
18 changes: 18 additions & 0 deletions packages/headless/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ function resolveEsm(moduleName) {
return resolve(dirname(packageJsonPath), packageJson.module || packageJson.main);
}

/**
* Absolute path for a package subpath. `packages: 'external'` does not externalize absolute
* paths, so aliasing to one keeps the module bundled. Required for the unbundled ESM modules of
* coveo.analytics: left as bare specifiers they would emit `require()` of an `.mjs` file, which
* throws `ERR_REQUIRE_ESM` on the older Node versions this package still supports.
*
* @param {string} subpath
*/
function resolveSubpath(subpath) {
return require.resolve(subpath);
}

function resolveBrowser(moduleName) {
const packageJsonPath = require.resolve(`${moduleName}/package.json`);
const packageJson = require(packageJsonPath);
Expand Down Expand Up @@ -245,6 +257,9 @@ async function buildBrowserConfig(options, outDir) {
plugins: [
alias({
'coveo.analytics': resolveEsm('coveo.analytics'),
'coveo.analytics/dist/esm/history.mjs': resolveSubpath(
Comment thread
alexprudhomme marked this conversation as resolved.
Outdated
'coveo.analytics/dist/esm/history.mjs'
),
pino: resolveBrowser('pino'),
}),
...(options.plugins || []),
Expand Down Expand Up @@ -282,6 +297,9 @@ async function buildNodeConfig(options, outDir) {
plugins: [
alias({
'coveo.analytics': resolveEsm('coveo.analytics'),
'coveo.analytics/dist/esm/history.mjs': resolveSubpath(
'coveo.analytics/dist/esm/history.mjs'
),
}),
],
...options,
Expand Down
210 changes: 0 additions & 210 deletions packages/headless/src/api/analytics/coveo.analytics/cookie.test.ts

This file was deleted.

64 changes: 0 additions & 64 deletions packages/headless/src/api/analytics/coveo.analytics/cookie.ts

This file was deleted.

Loading
Loading