diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 05cc6b9be..993722c91 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -140,8 +140,8 @@ steps: - HUSKY=0 yarn install --immutable - echo "--- Build bundles" - yarn turbo run --filter='./packages/signals/*' build - - echo "--- Assert Workerbox Up-to-Date" - - yarn workspace @segment/analytics-signals run assert-workerbox-built + - echo "+++ Assert Generated Files Up-to-Date" + - yarn turbo run --filter='./packages/signals/*' assert-generated - echo "+++ Run Lint" - yarn turbo run --filter='./packages/signals/*' lint - echo "+++ Run Tests" diff --git a/packages/signals/signals-runtime/build-signals-runtime-global.js b/packages/signals/signals-runtime/build-signals-runtime-global.js index 924b1aa6a..a13c9db7c 100644 --- a/packages/signals/signals-runtime/build-signals-runtime-global.js +++ b/packages/signals/signals-runtime/build-signals-runtime-global.js @@ -2,12 +2,10 @@ const esbuild = require('esbuild') const path = require('path') const fs = require('fs') const fsPromises = fs.promises -const pkgJSON = require('./package.json') const getBanner = (entryPoint) => { const content = [ `// GENERATED, DO NOT EDIT`, - `// ${pkgJSON.name}@${pkgJSON.version}`, `// Entry point: ${entryPoint}`, ].join('\n') return content diff --git a/packages/signals/signals-runtime/package.json b/packages/signals/signals-runtime/package.json index 3e636323c..4cabc1f4d 100644 --- a/packages/signals/signals-runtime/package.json +++ b/packages/signals/signals-runtime/package.json @@ -24,6 +24,7 @@ "build:esm": "yarn tsc -p tsconfig.build.json", "build:cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs", "build:global": "node build-signals-runtime-global.js", + "assert-generated": "bash scripts/assert-generated.sh", "watch": "yarn build:esm --watch", "watch:test": "yarn test --watch", "tsc": "yarn run -T tsc", diff --git a/packages/signals/signals-runtime/scripts/assert-generated.sh b/packages/signals/signals-runtime/scripts/assert-generated.sh new file mode 100644 index 000000000..66f9719ca --- /dev/null +++ b/packages/signals/signals-runtime/scripts/assert-generated.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# A CI script to ensure people remember to rebuild workerbox related files if workerbox changes + +yarn build:global + +# Check for changes in the workerbox directory +changed_files=$(git diff --name-only | grep 'generated') + +# Check for changes in the workerbox directory +if [ -n "$changed_files" ]; then + echo "Error: Changes detected. Please commit the changed files:" + echo "$changed_files" + exit 1 +else + echo "Files have not changed" + exit 0 +fi diff --git a/packages/signals/signals-runtime/src/mobile/get-runtime-code.generated.ts b/packages/signals/signals-runtime/src/mobile/get-runtime-code.generated.ts index 1269f6cce..35913d024 100644 --- a/packages/signals/signals-runtime/src/mobile/get-runtime-code.generated.ts +++ b/packages/signals/signals-runtime/src/mobile/get-runtime-code.generated.ts @@ -1,6 +1,5 @@ /* eslint-disable */ // GENERATED, DO NOT EDIT -// @segment/analytics-signals-runtime@0.0.0 // Entry point: src/mobile/index.signals-runtime.ts export const getRuntimeCode = (): string => ` "use strict";(()=>{var g=Object.defineProperty;var f=(r,n)=>{for(var e in n)g(r,e,{get:n[e],enumerable:!0})};var l={};f(l,{EventType:()=>d,LocalDataAction:()=>c,NavigationAction:()=>S,NetworkAction:()=>u,SignalType:()=>p});var p=Object.freeze({Interaction:"interaction",Navigation:"navigation",Network:"network",LocalData:"localData",Instrumentation:"instrumentation",UserDefined:"userDefined"}),d=Object.freeze({Track:"track",Page:"page",Screen:"screen",Identify:"identify",Group:"group",Alias:"alias"}),S=Object.freeze({Forward:"forward",Backward:"backward",Modal:"modal",Entering:"entering",Leaving:"leaving",Page:"page",Popup:"popup"}),u=Object.freeze({Request:"request",Response:"response"}),c=Object.freeze({Loaded:"loaded",Updated:"updated",Saved:"saved",Deleted:"deleted",Undefined:"undefined"});var a=class{constructor(n=[]){this.find=(n,e,i)=>this.filter(n,e,i)[0];this.filter=(n,e,i)=>{let o=s=>s.type===e;return this.signalBuffer.slice(this.signalBuffer.indexOf(n)+1).filter(o).filter(s=>i?i(s):()=>!0)};this.signalBuffer=n}};var t=class extends a{constructor(e=[]){super(e);this.add=e=>{this.signalCounter<0&&(this.signalCounter=0),"index"in e&&e.index==-1&&(e.index=this.getNextIndex()),this.signalBuffer.unshift(e),this.signalBuffer.length>this.maxBufferSize&&this.signalBuffer.pop()};this.getNextIndex=()=>{let e=this.signalCounter;return this.signalCounter+=1,e};this.signalCounter=0,this.maxBufferSize=1e3}};Object.assign(globalThis,{signals:new t},l);})(); diff --git a/packages/signals/signals-runtime/src/web/get-runtime-code.generated.ts b/packages/signals/signals-runtime/src/web/get-runtime-code.generated.ts index 4263262c9..5c9ba359e 100644 --- a/packages/signals/signals-runtime/src/web/get-runtime-code.generated.ts +++ b/packages/signals/signals-runtime/src/web/get-runtime-code.generated.ts @@ -1,6 +1,5 @@ /* eslint-disable */ // GENERATED, DO NOT EDIT -// @segment/analytics-signals-runtime@0.0.0 // Entry point: src/web/index.signals-runtime.ts export const getRuntimeCode = (): string => ` "use strict";(()=>{var o=Object.defineProperty;var S=(l,e)=>{for(var n in e)o(l,n,{get:e[n],enumerable:!0})};var i=class{constructor(e=[]){this.find=(e,n,a)=>this.filter(e,n,a)[0];this.filter=(e,n,a)=>{let s=g=>g.type===n;return this.signalBuffer.slice(this.signalBuffer.indexOf(e)+1).filter(s).filter(g=>a?a(g):()=>!0)};this.signalBuffer=e}};var t=class extends i{};var r={};S(r,{EventType:()=>f,NavigationAction:()=>p,SignalType:()=>y});var f=Object.freeze({Track:"track",Page:"page",Screen:"screen",Identify:"identify",Group:"group",Alias:"alias"}),p=Object.freeze({URLChange:"urlChange",PageLoad:"pageLoad"}),y=Object.freeze({Interaction:"interaction",Navigation:"navigation",Network:"network",LocalData:"localData",Instrumentation:"instrumentation",UserDefined:"userDefined"});Object.assign(globalThis,{signals:new t},r);})(); diff --git a/packages/signals/signals/package.json b/packages/signals/signals/package.json index d115e42e6..cca635115 100644 --- a/packages/signals/signals/package.json +++ b/packages/signals/signals/package.json @@ -32,7 +32,7 @@ "build:cjs": "yarn tsc -p tsconfig.build.json --outDir ./dist/cjs --module commonjs", "build:bundle": "NODE_ENV=production yarn run webpack", "workerbox": "node scripts/build-workerbox.js", - "assert-workerbox-built": "sh scripts/assert-workerbox-built.sh", + "assert-generated": "sh scripts/assert-workerbox-built.sh", "watch": "yarn concurrently 'yarn build:bundle --watch' 'yarn build:esm --watch'", "version": "sh scripts/version.sh", "watch:test": "yarn test --watch", diff --git a/turbo.json b/turbo.json index 04f823410..a4101e6e3 100644 --- a/turbo.json +++ b/turbo.json @@ -35,6 +35,9 @@ "tsc": { "cache": false }, + "assert-generated": { + "cache": false + }, "watch": { "cache": false, "outputs": ["dist/**"]