Skip to content

Commit

Permalink
separate web and node exports
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Feb 17, 2025
1 parent 49a6480 commit 97baa1b
Show file tree
Hide file tree
Showing 29 changed files with 47 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/config/jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getModuleMapper() {
return {
'^@elbwalker/jest$1': getDirectory('config/jest$1', ''),
'^@elbwalker/types': getDirectory('types', 'src'),
'^@elbwalker/utils': getDirectory('utils'),
'^@elbwalker/utils$1': getDirectory('utils$1'),
'^@elbwalker/walker.js': getDirectory('sources/walkerjs'),
'^@elbwalker/destination-web-(.*)$': getDirectory('destinations/web/$1'),
'^@elbwalker/destination-node-(.*)$': getDirectory('destinations/node/$1'),
Expand Down
3 changes: 3 additions & 0 deletions packages/destinations/node/etag/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ describe('Destination node etag', () => {
jest.mock('@elbwalker/utils', () => ({
...jest.requireActual('@elbwalker/utils'),
getId: () => 1337,
}));
jest.mock('@elbwalker/utils/node', () => ({
...jest.requireActual('@elbwalker/utils/node'),
sendNode: mockSend,
}));

Expand Down
3 changes: 2 additions & 1 deletion packages/destinations/node/etag/src/push.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { WalkerOS } from '@elbwalker/types';
import type { Custom, PushFn } from './types';
import { requestToParameter, sendNode } from '@elbwalker/utils';
import { requestToParameter } from '@elbwalker/utils';
import { sendNode } from '@elbwalker/utils/node';
import { getParameters } from '@elbwalker/destination-core-etag';

export const push: PushFn = async function (pushEvent, config) {
Expand Down
4 changes: 2 additions & 2 deletions packages/destinations/web/api/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { DestinationWebAPI } from '.';

describe('Destination API', () => {
const mockSendWeb = jest.fn();
jest.mock('@elbwalker/utils', () => ({
...jest.requireActual('@elbwalker/utils'),
jest.mock('@elbwalker/utils/web', () => ({
...jest.requireActual('@elbwalker/utils/web'),
sendWeb: mockSendWeb,
}));

Expand Down
4 changes: 2 additions & 2 deletions packages/destinations/web/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Custom, Destination } from './types';
import { isArray, isDefined, sendWeb } from '@elbwalker/utils';

import { isArray, isDefined } from '@elbwalker/utils';
import { sendWeb } from '@elbwalker/utils/web';
// Types
export * as DestinationWebAPI from './types';

Expand Down
8 changes: 3 additions & 5 deletions packages/destinations/web/api/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { WalkerOS } from '@elbwalker/types';
import type {
SendDataValue,
SendHeaders,
SendWebTransport,
} from '@elbwalker/utils';
import type { SendDataValue, SendHeaders } from '@elbwalker/utils';
import type { SendWebTransport } from '@elbwalker/utils/web';

import type { DestinationWeb } from '@elbwalker/walker.js';

export interface Destination
Expand Down
4 changes: 4 additions & 0 deletions packages/destinations/web/etag/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ describe('Destination web etag', () => {
jest.mock('@elbwalker/utils', () => ({
...jest.requireActual('@elbwalker/utils'),
getId: () => 1337,
}));

jest.mock('@elbwalker/utils/web', () => ({
...jest.requireActual('@elbwalker/utils/web'),
sendWebAsFetch: mockSend,
}));

Expand Down
3 changes: 2 additions & 1 deletion packages/destinations/web/etag/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Custom, Destination } from './types';
import type { DestinationCoreEtag } from '@elbwalker/destination-core-etag';
import { getParameters } from '@elbwalker/destination-core-etag';
import { requestToParameter, sendWebAsFetch } from '@elbwalker/utils';
import { requestToParameter } from '@elbwalker/utils';
import { sendWebAsFetch } from '@elbwalker/utils/web';

// Types
export * as DestinationWebEtag from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/destinations/web/plausible/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { elb, Walkerjs } from '@elbwalker/walker.js';
import type { DestinationPlausible } from '.';
import { elb, Walkerjs } from '@elbwalker/walker.js';
import { getEvent } from '@elbwalker/utils';

describe('destination plausible', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/sources/walkerjs/src/__tests__/elblayer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { elb, Walkerjs } from '..';
import { mockDataLayer } from '@elbwalker/jest/web.setup';
import type { SourceWalkerjs, DestinationWeb, Elb } from '..';
import type { WalkerOS } from '@elbwalker/types';
import { mockDataLayer } from '@elbwalker/jest/web.setup';
import { elb, Walkerjs } from '..';

describe('elbLayer', () => {
const w = window;
Expand Down
6 changes: 3 additions & 3 deletions packages/sources/walkerjs/src/__tests__/on.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { SourceWalkerjs, DestinationWeb } from '..';
import { elb, Walkerjs } from '..';
import { mockDataLayer } from '@elbwalker/jest/web.setup';
import { sessionStart } from '@elbwalker/utils';
import { sessionStart } from '@elbwalker/utils/web';

jest.mock('@elbwalker/utils', () => {
const utilsOrg = jest.requireActual('@elbwalker/utils');
jest.mock('@elbwalker/utils/web', () => {
const utilsOrg = jest.requireActual('@elbwalker/utils/web');

return {
...utilsOrg,
Expand Down
6 changes: 3 additions & 3 deletions packages/sources/walkerjs/src/__tests__/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Walkerjs } from '..';
import { mockDataLayer } from '@elbwalker/jest/web.setup';
import { sessionStart } from '@elbwalker/utils';
import { sessionStart } from '@elbwalker/utils/web';
import type { SourceWalkerjs } from '..';

jest.mock('@elbwalker/utils', () => {
const utilsOrg = jest.requireActual('@elbwalker/utils');
jest.mock('@elbwalker/utils/web', () => {
const utilsOrg = jest.requireActual('@elbwalker/utils/web');

return {
...utilsOrg,
Expand Down
4 changes: 2 additions & 2 deletions packages/sources/walkerjs/src/__tests__/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ describe('Trigger', () => {
);

// mock isVisible to return true
jest.mock('@elbwalker/utils', () => ({
...jest.requireActual('@elbwalker/utils'),
jest.mock('@elbwalker/utils/web', () => ({
...jest.requireActual('@elbwalker/utils/web'),
isVisible: () => true,
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/sources/walkerjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Elb, SourceWalkerjs } from './types';
import { sessionStart } from '@elbwalker/utils';
import { sessionStart } from '@elbwalker/utils/web';
import { addDestination } from './lib/destination';
import { onApply } from './lib/on';
import { createPush, elbLayerInit } from './lib/push';
Expand Down
10 changes: 3 additions & 7 deletions packages/sources/walkerjs/src/lib/session.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { WalkerOS } from '@elbwalker/types';
import type { SessionCallback } from '@elbwalker/utils';
import {
assign,
isSameType,
sessionStart as sessionStartOrg,
useHooks,
} from '@elbwalker/utils';
import type { SessionCallback } from '@elbwalker/utils/web';
import { assign, isSameType, useHooks } from '@elbwalker/utils';
import { sessionStart as sessionStartOrg } from '@elbwalker/utils/web';
import { SourceWalkerjs } from '../types';
import { SessionStartOptions } from '../types/source';
import { onApply } from './on';
Expand Down
10 changes: 2 additions & 8 deletions packages/sources/walkerjs/src/lib/trigger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Const, throttle, tryCatch } from '@elbwalker/utils';
import { elb as elbOrg, getAttribute, isVisible } from '@elbwalker/utils/web';
import { Walker, SourceWalkerjs, Elb } from '../types';
import { onApply } from './on';
import {
Expand All @@ -6,14 +8,6 @@ import {
getPageViewData,
getTriggerActions,
} from './walker';
import {
elb as elbOrg,
Const,
getAttribute,
isVisible,
throttle,
tryCatch,
} from '@elbwalker/utils';

let visibleObserver: IntersectionObserver | undefined;
let scrollElements: Walker.ScrollElements = [];
Expand Down
11 changes: 2 additions & 9 deletions packages/sources/walkerjs/src/lib/walker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import type { Walker } from '../types';
import type { WalkerOS } from '@elbwalker/types';
import {
Const,
assign,
castValue,
getAttribute,
isArray,
trim,
} from '@elbwalker/utils';

import { Const, assign, castValue, isArray, trim } from '@elbwalker/utils';
import { getAttribute } from '@elbwalker/utils/web';
export function getElbAttributeName(
prefix: string,
name?: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/walkerjs/src/types/source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Hooks, WalkerOS } from '@elbwalker/types';
import type { SessionConfig } from '@elbwalker/utils';
import type { SessionConfig } from '@elbwalker/utils/web';
import type { Destination, Config as DestConfig } from './destination';
import type { Fn, Layer } from './elb';
import type { Config as OnConfig } from './on';
Expand Down
2 changes: 1 addition & 1 deletion packages/sources/walkerjs/src/walkerjs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// browser version
import { elb, Walkerjs } from './';
import { getAttribute } from '@elbwalker/utils';
import { getAttribute } from '@elbwalker/utils/web';

let defaultMode, tagging;

Expand Down
1 change: 0 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/web.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/node/sendNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sendNode } from '../../';
import { sendNode } from '../../node';
import * as http from 'http';
import * as https from 'https';

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/web/browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLanguage, getTimezone, getScreenSize } from '../..';
import { getLanguage, getTimezone, getScreenSize } from '../../web';

describe('Browser', () => {
const window = {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/web/isVisible.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isVisible } from '../..';
import { isVisible } from '../../web';

describe('isVisible', () => {
const w = window;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/web/sendWeb.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sendWeb } from '../../';
import { sendWeb } from '../../web';

describe('sendWeb', () => {
const data = { key: 'value' };
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/__tests__/web/sessionWindow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sessionWindow } from '../../';
import { sessionWindow } from '../../web';

describe('SessionStart', () => {
const w = window;
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/__tests__/web/storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Const, storageDelete, storageRead, storageWrite } from '../../';
import { Const } from '../..';
import { storageDelete, storageRead, storageWrite } from '../../web';

describe('Storage', () => {
const w = window;
Expand Down
2 changes: 0 additions & 2 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './core/index';
export * from './node/index';
export * from './web/index';
1 change: 0 additions & 1 deletion packages/utils/src/node.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './core/index';
export * from './node/index';
1 change: 0 additions & 1 deletion packages/utils/src/web.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './core/index';
export * from './web/index';

0 comments on commit 97baa1b

Please sign in to comment.