Skip to content

Commit 1402a33

Browse files
authored
Simplify signals-runtime build for es5 (#1252)
1 parent a006b34 commit 1402a33

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

.changeset/perfect-actors-tease.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@segment/analytics-signals-runtime': minor
33
---
44

5-
Transpile to es5
5+
Transpile to ES5

packages/signals/signals-runtime/babel.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/signals/signals-runtime/build-signals-runtime-global.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,39 +68,40 @@ const buildRuntime = async (platform) => {
6868
const entryPoint = getEntryPoint(platform)
6969
const { outfileUnminified, outfileMinified } = getOutFiles(platform)
7070

71-
// Transpile with Babel
72-
const transpiledFile = `./dist/runtime/index.${platform}.transpiled.js`
73-
await esbuild.build({
74-
entryPoints: [entryPoint],
75-
outfile: transpiledFile,
76-
bundle: true,
77-
minify: false,
78-
plugins: [
79-
babel({
80-
config: {
81-
presets: ['@babel/preset-env', '@babel/preset-typescript'],
82-
},
83-
}),
84-
],
71+
const babelPlugin = babel({
72+
config: {
73+
presets: [
74+
[
75+
'@babel/preset-env',
76+
{
77+
targets: {
78+
ie: '11', // target es5 -- for example, react-native's QuickJS does not support class
79+
},
80+
},
81+
],
82+
'@babel/preset-typescript',
83+
],
84+
},
8585
})
86-
8786
// Bundle and minify with esbuild
8887
await esbuild.build({
89-
entryPoints: [transpiledFile],
88+
entryPoints: [entryPoint],
9089
outfile: outfileMinified,
9190
bundle: true,
9291
minify: true,
9392
banner: { js: getBanner(entryPoint) },
93+
plugins: [babelPlugin],
9494
})
9595
console.log(`wrote: ${outfileMinified}`)
9696

9797
// Bundle without minification
9898
await esbuild.build({
99-
entryPoints: [transpiledFile],
99+
entryPoints: [entryPoint],
100100
outfile: outfileUnminified,
101101
bundle: true,
102102
minify: false,
103103
banner: { js: getBanner(entryPoint) },
104+
plugins: [babelPlugin],
104105
})
105106
console.log(`wrote: ${outfileUnminified}`)
106107
}

packages/signals/signals-runtime/src/mobile/get-runtime-code.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// GENERATED, DO NOT EDIT
33
// Entry point: src/mobile/index.signals-runtime.ts
44
export const getRuntimeCode = (): string => `
5-
"use strict";(()=>{(()=>{var _=Object.defineProperty,h=(t,e)=>{for(var n in e)_(t,n,{get:e[n],enumerable:!0})},s={};h(s,{EventType:()=>S,LocalDataAction:()=>j,NavigationAction:()=>w,NetworkAction:()=>P,SignalType:()=>O});var O=Object.freeze({Interaction:"interaction",Navigation:"navigation",Network:"network",LocalData:"localData",Instrumentation:"instrumentation",UserDefined:"userDefined"}),S=Object.freeze({Track:"track",Page:"page",Screen:"screen",Identify:"identify",Group:"group",Alias:"alias"}),w=Object.freeze({Forward:"forward",Backward:"backward",Modal:"modal",Entering:"entering",Leaving:"leaving",Page:"page",Popup:"popup"}),P=Object.freeze({Request:"request",Response:"response"}),j=Object.freeze({Loaded:"loaded",Updated:"updated",Saved:"saved",Deleted:"deleted",Undefined:"undefined"});function a(t){"@babel/helpers - typeof";return a=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(t)}function y(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,p(r.key),r)}}function x(t,e,n){return e&&y(t.prototype,e),n&&y(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function R(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function b(t,e,n){return e=p(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t){var e=T(t,"string");return a(e)==="symbol"?e:String(e)}function T(t,e){if(a(t)!=="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(a(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var N=x(function t(){var e=this,n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];R(this,t),b(this,"find",function(r,o,i){return e.filter(r,o,i)[0]}),b(this,"filter",function(r,o,i){var M=function(U){return U.type===o};return e.signalBuffer.slice(e.signalBuffer.indexOf(r)+1).filter(M).filter(function(d){return i?i(d):function(){return!0}})}),this.signalBuffer=n});function f(t){"@babel/helpers - typeof";return f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(t)}function g(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,m(r.key),r)}}function B(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function E(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function z(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,o){return r.__proto__=o,r},l(t,e)}function D(t){var e=I();return function(){var r=u(t),o;if(e){var i=u(this).constructor;o=Reflect.construct(r,arguments,i)}else o=r.apply(this,arguments);return A(this,o)}}function A(t,e){if(e&&(f(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return c(t)}function c(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function I(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},u(t)}function v(t,e,n){return e=m(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function m(t){var e=k(t,"string");return f(e)==="symbol"?e:String(e)}function k(t,e){if(f(t)!=="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(f(r)!=="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var L=function(t){z(n,t);var e=D(n);function n(){var r,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return E(this,n),r=e.call(this,o),v(c(r),"add",function(i){r.signalCounter<0&&(r.signalCounter=0),"index"in i&&i.index==-1&&(i.index=r.getNextIndex()),r.signalBuffer.unshift(i),r.signalBuffer.length>r.maxBufferSize&&r.signalBuffer.pop()}),v(c(r),"getNextIndex",function(){var i=r.signalCounter;return r.signalCounter+=1,i}),r.signalCounter=0,r.maxBufferSize=1e3,r}return B(n)}(N);Object.assign(globalThis,{signals:new L},s)})();})();
5+
"use strict";(()=>{var w=Object.defineProperty;var P=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})};var l={};P(l,{EventType:()=>j,LocalDataAction:()=>B,NavigationAction:()=>R,NetworkAction:()=>T,SignalType:()=>x});var x=Object.freeze({Interaction:"interaction",Navigation:"navigation",Network:"network",LocalData:"localData",Instrumentation:"instrumentation",UserDefined:"userDefined"}),j=Object.freeze({Track:"track",Page:"page",Screen:"screen",Identify:"identify",Group:"group",Alias:"alias"}),R=Object.freeze({Forward:"forward",Backward:"backward",Modal:"modal",Entering:"entering",Leaving:"leaving",Page:"page",Popup:"popup"}),T=Object.freeze({Request:"request",Response:"response"}),B=Object.freeze({Loaded:"loaded",Updated:"updated",Saved:"saved",Deleted:"deleted",Undefined:"undefined"});function a(t){"@babel/helpers - typeof";return a=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(t)}function p(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,g(n.key),n)}}function N(t,e,r){return e&&p(t.prototype,e),r&&p(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function E(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function b(t,e,r){return e=g(e),e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function g(t){var e=z(t,"string");return a(e)==="symbol"?e:String(e)}function z(t,e){if(a(t)!=="object"||t===null)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e||"default");if(a(n)!=="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var m=N(function t(){var e=this,r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];E(this,t),b(this,"find",function(n,o,i){return e.filter(n,o,i)[0]}),b(this,"filter",function(n,o,i){var S=function(O){return O.type===o};return e.signalBuffer.slice(e.signalBuffer.indexOf(n)+1).filter(S).filter(function(y){return i?i(y):function(){return!0}})}),this.signalBuffer=r});function f(t){"@babel/helpers - typeof";return f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(t)}function d(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,h(n.key),n)}}function D(t,e,r){return e&&d(t.prototype,e),r&&d(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function I(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function k(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,o){return n.__proto__=o,n},c(t,e)}function A(t){var e=M();return function(){var n=u(t),o;if(e){var i=u(this).constructor;o=Reflect.construct(n,arguments,i)}else o=n.apply(this,arguments);return L(this,o)}}function L(t,e){if(e&&(f(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return s(t)}function s(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function M(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(r){return r.__proto__||Object.getPrototypeOf(r)},u(t)}function v(t,e,r){return e=h(e),e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function h(t){var e=C(t,"string");return f(e)==="symbol"?e:String(e)}function C(t,e){if(f(t)!=="object"||t===null)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e||"default");if(f(n)!=="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var _=function(t){k(r,t);var e=A(r);function r(){var n,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];return I(this,r),n=e.call(this,o),v(s(n),"add",function(i){n.signalCounter<0&&(n.signalCounter=0),"index"in i&&i.index==-1&&(i.index=n.getNextIndex()),n.signalBuffer.unshift(i),n.signalBuffer.length>n.maxBufferSize&&n.signalBuffer.pop()}),v(s(n),"getNextIndex",function(){var i=n.signalCounter;return n.signalCounter+=1,i}),n.signalCounter=0,n.maxBufferSize=1e3,n}return D(r)}(m);Object.assign(globalThis,{signals:new _},l);})();
66
`
77

0 commit comments

Comments
 (0)