diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index b753256e3..a91909f2d 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -127,6 +127,23 @@ steps: - yarn turbo run --filter='./packages/consent/*' lint - echo "+++ Run Tests" - yarn turbo run --filter='./packages/consent/*' test + plugins: + - ssh://git@github.com/segmentio/cache-buildkite-plugin#v2.0.0: + key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" + + - label: '[Signals] Lint + Test' + agents: + queue: v1 + commands: + - npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN} + - echo "--- Install dependencies" + - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable + - echo "--- Build bundles" + - yarn turbo run --filter='./packages/signals/*' build + - echo "+++ Run Lint" + - yarn turbo run --filter='./packages/signals/*' lint + - echo "+++ Run Tests" + - yarn turbo run --filter='./packages/signals/*' test plugins: - ssh://git@github.com/segmentio/cache-buildkite-plugin#v2.0.0: key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}" diff --git a/jest.config.js b/jest.config.js index a5aa55afe..81dbd2451 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,5 +17,6 @@ module.exports = () => '/packages/consent/consent-tools', '/packages/consent/consent-wrapper-onetrust', '/scripts', + '/packages/signals/browser-signals', ], }) diff --git a/package.json b/package.json index 8cffce7bd..417cb53d2 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "playgrounds/*", "packages/*", "packages/consent/*", + "packages/signals/*", "scripts" ], "engines": { diff --git a/packages/signals/browser-signals/.eslintrc.js b/packages/signals/browser-signals/.eslintrc.js new file mode 100644 index 000000000..eedf2f3c3 --- /dev/null +++ b/packages/signals/browser-signals/.eslintrc.js @@ -0,0 +1,7 @@ +/** @type { import('eslint').Linter.Config } */ +module.exports = { + extends: ['../../../.eslintrc'], + env: { + browser: true, + }, +} diff --git a/packages/signals/browser-signals/.lintstagedrc.js b/packages/signals/browser-signals/.lintstagedrc.js new file mode 100644 index 000000000..bc1f1c780 --- /dev/null +++ b/packages/signals/browser-signals/.lintstagedrc.js @@ -0,0 +1 @@ +module.exports = require("@internal/config").lintStagedConfig diff --git a/packages/signals/browser-signals/LICENSE b/packages/signals/browser-signals/LICENSE new file mode 100644 index 000000000..a0378adfd --- /dev/null +++ b/packages/signals/browser-signals/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright © 2023 Segment + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/signals/browser-signals/README.md b/packages/signals/browser-signals/README.md new file mode 100644 index 000000000..7fb9241c2 --- /dev/null +++ b/packages/signals/browser-signals/README.md @@ -0,0 +1 @@ +# @segment/analytics-browser-signals diff --git a/packages/signals/browser-signals/jest.config.js b/packages/signals/browser-signals/jest.config.js new file mode 100644 index 000000000..06534cb19 --- /dev/null +++ b/packages/signals/browser-signals/jest.config.js @@ -0,0 +1,5 @@ +const { createJestTSConfig } = require('@internal/config') + +module.exports = createJestTSConfig(__dirname, { + testEnvironment: 'jsdom', +}) diff --git a/packages/signals/browser-signals/package.json b/packages/signals/browser-signals/package.json new file mode 100644 index 000000000..cf1cfe1e6 --- /dev/null +++ b/packages/signals/browser-signals/package.json @@ -0,0 +1,55 @@ +{ + "name": "@segment/analytics-browser-signals", + "version": "0.0.1", + "main": "./dist/cjs/index.js", + "private": true, + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "sideEffects": [ + "./dist/umd/analytics-browser-signals.umd.js" + ], + "jsdelivr": "./dist/umd/analytics-browser-signals.umd.js", + "unpkg": "./dist/umd/analytics-browser-signals.umd.js", + "files": [ + "LICENSE", + "dist/", + "src/", + "!**/__tests__/**", + "!**/test-helpers/**", + "!*.tsbuildinfo" + ], + "scripts": { + ".": "yarn run -T turbo run --filter=@segment/analytics-browser-signals...", + "test": "yarn jest", + "lint": "yarn concurrently 'yarn:eslint .' 'yarn:tsc --noEmit'", + "build": "rm -rf dist && yarn concurrently 'yarn:build:*'", + "build:esm": "yarn tsc -p tsconfig.build.json", + "build:cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs", + "build:bundle": "NODE_ENV=production yarn run webpack", + "build:bundle-dev": "NODE_ENV=development yarn run webpack", + "watch": "yarn concurrently 'yarn build:bundle-dev --watch' 'yarn build:esm --watch'", + "version": "sh scripts/version.sh", + "watch:test": "yarn test --watch", + "tsc": "yarn run -T tsc", + "eslint": "yarn run -T eslint", + "concurrently": "yarn run -T concurrently --raw", + "jest": "yarn run -T jest", + "webpack": "yarn run -T webpack" + }, + "dependencies": { + "tslib": "^2.4.1" + }, + "peerDependencies": { + "@segment/analytics-next": ">=1.70.0" + }, + "peerDependenciesMeta": { + "@segment/analytics-next": { + "optional": true + } + }, + "packageManager": "yarn@3.4.1", + "devDependencies": { + "@internal/config-webpack": "workspace:^", + "@internal/test-helpers": "workspace:^" + } +} diff --git a/packages/signals/browser-signals/scripts/version.sh b/packages/signals/browser-signals/scripts/version.sh new file mode 100644 index 000000000..9cc9c0766 --- /dev/null +++ b/packages/signals/browser-signals/scripts/version.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Generate a version.ts file from the version in the package.json + +PKG_VERSION=$(node --eval="process.stdout.write(require('./package.json').version)") + +cat <src/generated/version.ts +// This file is generated. +export const version = '$PKG_VERSION' +EOF + +git add src/generated/version.ts diff --git a/packages/signals/browser-signals/src/core/buffer/__tests__/buffer.test.ts b/packages/signals/browser-signals/src/core/buffer/__tests__/buffer.test.ts new file mode 100644 index 000000000..4da548ad2 --- /dev/null +++ b/packages/signals/browser-signals/src/core/buffer/__tests__/buffer.test.ts @@ -0,0 +1,13 @@ +import { SignalBuffer } from '../index' + +describe(SignalBuffer, () => { + let buffer: SignalBuffer + + beforeEach(() => { + buffer = new SignalBuffer() + }) + + it('should exits', () => { + expect(buffer).toBeTruthy() + }) +}) diff --git a/packages/signals/browser-signals/src/core/buffer/index.ts b/packages/signals/browser-signals/src/core/buffer/index.ts new file mode 100644 index 000000000..a331e519b --- /dev/null +++ b/packages/signals/browser-signals/src/core/buffer/index.ts @@ -0,0 +1 @@ +export class SignalBuffer {} diff --git a/packages/signals/browser-signals/src/core/signals/index.ts b/packages/signals/browser-signals/src/core/signals/index.ts new file mode 100644 index 000000000..0778b18b5 --- /dev/null +++ b/packages/signals/browser-signals/src/core/signals/index.ts @@ -0,0 +1,5 @@ +import { SignalBuffer } from '../buffer' + +export class Signals { + buffer = new SignalBuffer() +} diff --git a/packages/signals/browser-signals/src/generated/version.ts b/packages/signals/browser-signals/src/generated/version.ts new file mode 100644 index 000000000..4122e1779 --- /dev/null +++ b/packages/signals/browser-signals/src/generated/version.ts @@ -0,0 +1,2 @@ +// This file is generated. +export const version = '0.0.1' diff --git a/packages/signals/browser-signals/src/index.ts b/packages/signals/browser-signals/src/index.ts new file mode 100644 index 000000000..d4c59b185 --- /dev/null +++ b/packages/signals/browser-signals/src/index.ts @@ -0,0 +1,6 @@ +/** + * This is the public API for this package. + * We avoid using splat (*) exports so that we can control what is exposed. + */ +export { SignalsPlugin } from './plugin/signals-plugin' +export { Signals } from './core/signals' diff --git a/packages/signals/browser-signals/src/index.umd.ts b/packages/signals/browser-signals/src/index.umd.ts new file mode 100644 index 000000000..f8268483b --- /dev/null +++ b/packages/signals/browser-signals/src/index.umd.ts @@ -0,0 +1,9 @@ +/** + * This is the entry point to a webpack bundle that can be loaded via a