@webqit/webflo 0.20.5 → 0.20.7-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "vanila-javascript"
13
13
  ],
14
14
  "homepage": "https://webqit.io/tooling/webflo",
15
- "version": "0.20.5",
15
+ "version": "0.20.7-next.0",
16
16
  "license": "MIT",
17
17
  "repository": {
18
18
  "type": "git",
@@ -48,6 +48,7 @@
48
48
  "@webqit/use-live": "^0.5.41",
49
49
  "@webqit/util": "^0.8.11",
50
50
  "dotenv": "^16.4.7",
51
+ "esbuild": "^0.14.38",
51
52
  "mime-types": "^2.1.33",
52
53
  "simple-git": "^2.20.1",
53
54
  "urlpattern-polyfill": "^4.0.3"
@@ -56,7 +57,6 @@
56
57
  "chai": "^4.3.6",
57
58
  "chokidar": "^4.0.3",
58
59
  "coveralls": "^3.1.1",
59
- "esbuild": "^0.14.38",
60
60
  "fast-glob": "^3.3.3",
61
61
  "jsdom": "^27.0.1",
62
62
  "markdown-it-mathjax3": "^4.3.2",
@@ -0,0 +1,42 @@
1
+ import Fs from 'fs/promises';
2
+ import { parse, compile, matchPrologDirective, serialize } from '@webqit/use-live';
3
+
4
+ export function UseLiveTransform() {
5
+ return {
6
+ name: 'uselive-transform',
7
+ setup(build) {
8
+ build.onLoad({ filter: /\.(js|mjs|ts|jsx|tsx)$/ }, async (args) => {
9
+ const code = await Fs.readFile(args.path, 'utf8');
10
+
11
+ // Super dirty detection
12
+ if (matchPrologDirective(code)) {
13
+ // Actual check...
14
+
15
+ let ast;
16
+ try { ast = parse(code, parserParams); } catch (e) { console.error(args.path, '\nUseLive transform error:', e); }
17
+
18
+ if (ast?.isLiveProgram || ast?.hasLiveFunctions) {
19
+ const result = await compile(parserParams.sourceType+'-file', ast, {
20
+ liveMode: ast.isLiveProgram, // Regarding top-level
21
+ fileName: args.path,
22
+ });
23
+ return { contents: serialize(result), loader: 'js' };
24
+ }
25
+ }
26
+
27
+ return { contents: code, loader: 'default' };
28
+ });
29
+ }
30
+ };
31
+ }
32
+
33
+ export const parserParams = {
34
+ ecmaVersion: 'latest',
35
+ sourceType: 'module',
36
+ executionMode: 'RegularProgram', // 'LiveProgram'
37
+ allowReturnOutsideFunction: true,
38
+ allowAwaitOutsideFunction: true,
39
+ allowSuperOutsideMethod: false,
40
+ preserveParens: false,
41
+ locations: true,
42
+ };
@@ -339,7 +339,7 @@ export class LiveResponse extends EventTarget {
339
339
  redirected: response.redirected,
340
340
  url: response.url,
341
341
  });
342
- if (this.test(response) === 'LiveResponse') {
342
+ if (this.constructor.test(response) === 'LiveResponse') {
343
343
  response.addEventListener('replace', () => execReplaceWith(response), { signal: this.#abortController.signal });
344
344
  return await response.whileLive(true);
345
345
  }
@@ -153,7 +153,14 @@ export const response = {
153
153
  }
154
154
  },
155
155
  prototype: {
156
- status: { get: function () { return _wq(this, 'meta').get('status') || responseOriginals.prototype.status.get.call(this); } },
156
+ status: {
157
+ get: function () {
158
+ return _wq(this, 'meta').get('status')
159
+ || this instanceof Response
160
+ ? responseOriginals.prototype.status.get.call(this)
161
+ : this.status;
162
+ }
163
+ },
157
164
  carry: { get: function () { return _wq(this, 'meta').get('carry'); } },
158
165
  parse: { value: async function () { return await parseHttpMessage(this); } },
159
166
  clone: {
@@ -22,7 +22,7 @@ export function dataType(value) {
22
22
  'Uint8Array', 'Uint16Array', 'Uint32Array', 'ArrayBuffer', 'Blob', 'File', 'FormData', 'Stream', 'ReadableStream'
23
23
  ].reduce((_toStringTag, type) => _toStringTag || (toStringTag === type ? type : null), null);
24
24
  if (type) return type;
25
- if ((_isObject(value) && _isPlainObject(value)) || (Array.isArray(value) && _isPlainArray(value)) || 'toString' in value) {
25
+ if ((_isObject(value)) || (Array.isArray(value) && _isPlainArray(value)) || 'toString' in value) {
26
26
  return 'json';
27
27
  }
28
28
  }
@@ -6,14 +6,12 @@ import { _wq } from '../../util.js';
6
6
 
7
7
  export class WQSockPort extends WQMessagePort {
8
8
 
9
- static WebSocket = typeof WebSocket !== 'undefined' ? WebSocket : null;
10
-
11
9
  #socket;
12
10
  #cleanups = [];
13
11
 
14
12
  constructor(instanceOrConnectionID) {
15
13
  super();
16
- this.#socket = typeof instanceOrConnectionID === 'string' ? new this.constructor.WebSocket(`/${instanceOrConnectionID}`) : instanceOrConnectionID;
14
+ this.#socket = typeof instanceOrConnectionID === 'string' ? new WebSocket(`/${instanceOrConnectionID}`) : instanceOrConnectionID;
17
15
  const meta = _wq(this, 'meta');
18
16
  Object.defineProperty(this, 'wqLifecycle', {
19
17
  value: {
@@ -294,6 +294,7 @@ export function postRequest(data, callback, options = {}) {
294
294
  const { signal, once } = eventOptions2;
295
295
  const messageChannel = new MessageChannel;
296
296
  messageChannel.port1.start();
297
+ toWQPort(messageChannel.port1);
297
298
  messageChannel.port1.addEventListener('message', (e) => callback(e), { signal, once });
298
299
  return this.postMessage(data, { ...$options, transfer: [messageChannel.port2].concat(transfer) });
299
300
  }
@@ -65,7 +65,6 @@ export class WebfloServer extends WebfloRuntime {
65
65
  await this.enterDevMode();
66
66
  } else {
67
67
  await this.buildRoutes({ server: true });
68
- await this.bundleAssetsIfPending(true);
69
68
  }
70
69
 
71
70
  // ----------
@@ -564,7 +563,7 @@ export class WebfloServer extends WebfloRuntime {
564
563
  const finalizeResponse = (response) => {
565
564
  // Qualify Service-Worker responses
566
565
  if (httpEvent.request.headers.get('Service-Worker') === 'script') {
567
- scopeObj.response.headers.set('Service-Worker-Allowed', this.config.WORKER.scope || '/');
566
+ response.headers.set('Service-Worker-Allowed', this.config.WORKER.scope || '/');
568
567
  }
569
568
  const responseMeta = _wq(response, 'meta');
570
569
  responseMeta.set('filename', scopeObj.filename);