Skip to content

Commit 81d0886

Browse files
committed
wip
1 parent 12d73f5 commit 81d0886

File tree

5 files changed

+298
-225
lines changed

5 files changed

+298
-225
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const esbuild = require('esbuild')
22
const path = require('path')
33
const fs = require('fs')
44
const fsPromises = fs.promises
5-
const { execSync } = require('child_process')
5+
const babel = require('esbuild-plugin-babel-cjs')
66

77
const getBanner = (entryPoint) => {
88
const content = [
@@ -64,40 +64,44 @@ const buildRuntimeAsString = async (platform) => {
6464
console.log(`wrote: ${generatedTsFile}`)
6565
}
6666

67-
const compileToEs5WithBabel = (outFile) => {
68-
// While esbuild supports target: es5 natively, we use babel because esbuild chokes with errors. e.g.:
69-
// ✘ [ERROR] Transforming const to the configured target environment ("es5") is not supported yet
70-
return execSync(
71-
`npx babel ${outFile} --out-file ${outFile} --config-file ./babel.config.js`
72-
)
73-
}
74-
7567
const buildRuntime = async (platform) => {
7668
const entryPoint = getEntryPoint(platform)
7769
const { outfileUnminified, outfileMinified } = getOutFiles(platform)
7870

79-
// Build minified version
71+
// Transpile with Babel
72+
const transpiledFile = `./dist/runtime/index.${platform}.transpiled.js`
8073
await esbuild.build({
8174
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+
],
85+
})
86+
87+
// Bundle and minify with esbuild
88+
await esbuild.build({
89+
entryPoints: [transpiledFile],
8290
outfile: outfileMinified,
8391
bundle: true,
8492
minify: true,
8593
banner: { js: getBanner(entryPoint) },
8694
})
87-
compileToEs5WithBabel(outfileMinified)
8895
console.log(`wrote: ${outfileMinified}`)
8996

90-
// Build unminified version
97+
// Bundle without minification
9198
await esbuild.build({
92-
entryPoints: [entryPoint],
99+
entryPoints: [transpiledFile],
93100
outfile: outfileUnminified,
94101
bundle: true,
95102
minify: false,
96103
banner: { js: getBanner(entryPoint) },
97104
})
98-
99-
// Compile to ES5
100-
compileToEs5WithBabel(outfileUnminified)
101105
console.log(`wrote: ${outfileUnminified}`)
102106
}
103107

packages/signals/signals-runtime/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
"@babel/cli": "^7.22.10",
4848
"@babel/core": "^7.22.11",
4949
"@babel/preset-env": "^7.22.10",
50+
"@babel/preset-typescript": "^7.22.11",
5051
"@internal/test-helpers": "workspace:^",
51-
"@microsoft/api-extractor": "^7.47.9"
52+
"@microsoft/api-extractor": "^7.47.9",
53+
"babel-preset-minify": "^0.5.2",
54+
"esbuild-plugin-babel-cjs": "^1.0.0"
5255
}
5356
}

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

Lines changed: 1 addition & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,6 @@
22
// GENERATED, DO NOT EDIT
33
// Entry point: src/mobile/index.signals-runtime.ts
44
export const getRuntimeCode = (): string => `
5-
"use strict";
6-
7-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
9-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
10-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
12-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
13-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
14-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
16-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
19-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20-
(function () {
21-
var g = Object.defineProperty;
22-
var f = function f(r, n) {
23-
for (var e in n) g(r, e, {
24-
get: n[e],
25-
enumerable: !0
26-
});
27-
};
28-
var l = {};
29-
f(l, {
30-
EventType: function EventType() {
31-
return d;
32-
},
33-
LocalDataAction: function LocalDataAction() {
34-
return c;
35-
},
36-
NavigationAction: function NavigationAction() {
37-
return S;
38-
},
39-
NetworkAction: function NetworkAction() {
40-
return u;
41-
},
42-
SignalType: function SignalType() {
43-
return p;
44-
}
45-
});
46-
var p = Object.freeze({
47-
Interaction: "interaction",
48-
Navigation: "navigation",
49-
Network: "network",
50-
LocalData: "localData",
51-
Instrumentation: "instrumentation",
52-
UserDefined: "userDefined"
53-
}),
54-
d = Object.freeze({
55-
Track: "track",
56-
Page: "page",
57-
Screen: "screen",
58-
Identify: "identify",
59-
Group: "group",
60-
Alias: "alias"
61-
}),
62-
S = Object.freeze({
63-
Forward: "forward",
64-
Backward: "backward",
65-
Modal: "modal",
66-
Entering: "entering",
67-
Leaving: "leaving",
68-
Page: "page",
69-
Popup: "popup"
70-
}),
71-
u = Object.freeze({
72-
Request: "request",
73-
Response: "response"
74-
}),
75-
c = Object.freeze({
76-
Loaded: "loaded",
77-
Updated: "updated",
78-
Saved: "saved",
79-
Deleted: "deleted",
80-
Undefined: "undefined"
81-
});
82-
var a = /*#__PURE__*/_createClass(function a() {
83-
var _this = this;
84-
var n = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
85-
_classCallCheck(this, a);
86-
this.find = function (n, e, i) {
87-
return _this.filter(n, e, i)[0];
88-
};
89-
this.filter = function (n, e, i) {
90-
var o = function o(s) {
91-
return s.type === e;
92-
};
93-
return _this.signalBuffer.slice(_this.signalBuffer.indexOf(n) + 1).filter(o).filter(function (s) {
94-
return i ? i(s) : function () {
95-
return !0;
96-
};
97-
});
98-
};
99-
this.signalBuffer = n;
100-
});
101-
var t = /*#__PURE__*/function (_a) {
102-
_inherits(t, _a);
103-
var _super = _createSuper(t);
104-
function t() {
105-
var _this2;
106-
var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
107-
_classCallCheck(this, t);
108-
_this2 = _super.call(this, e);
109-
_this2.add = function (e) {
110-
_this2.signalCounter < 0 && (_this2.signalCounter = 0), "index" in e && e.index == -1 && (e.index = _this2.getNextIndex()), _this2.signalBuffer.unshift(e), _this2.signalBuffer.length > _this2.maxBufferSize && _this2.signalBuffer.pop();
111-
};
112-
_this2.getNextIndex = function () {
113-
var e = _this2.signalCounter;
114-
return _this2.signalCounter += 1, e;
115-
};
116-
_this2.signalCounter = 0, _this2.maxBufferSize = 1e3;
117-
return _this2;
118-
}
119-
return _createClass(t);
120-
}(a);
121-
Object.assign(globalThis, {
122-
signals: new t()
123-
}, l);
124-
})();
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)})();})();
1256
`
1267

0 commit comments

Comments
 (0)