@naanlang/naan 1.2.0 → 1.2.1

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.
@@ -36,7 +36,7 @@
36
36
  *
37
37
  */
38
38
 
39
- var CurrentCacheName = "Naanlang-1.2.0+1";
39
+ var CurrentCacheName = "Naanlang-1.2.1+1";
40
40
 
41
41
 
42
42
  //
@@ -92,18 +92,18 @@ var terminated; // flag that this service worker
92
92
  var pubVersion = event.data.hereIsMyVersion;
93
93
  var sourceId = event.source.id; // client id of sender of message
94
94
  msgPorts[sourceId] = msgport;
95
- console.log("[1.2.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
- if (pubVersion != "1.2.0+1") {
95
+ console.log("[1.2.1+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
+ if (pubVersion != "1.2.1+1") {
97
97
  if (upgradeMsgPorts) { // if not activated
98
- console.log("[1.2.0+1] update pending for", sourceId);
98
+ console.log("[1.2.1+1] update pending for", sourceId);
99
99
  upgradeMsgPorts[sourceId] = msgport;
100
100
  }
101
101
  else {
102
102
  msgport.postMessage({ // notify new version available
103
103
  id: "upgrade",
104
- version: "1.2.0+1"
104
+ version: "1.2.1+1"
105
105
  });
106
- console.log("[1.2.0+1] update sent for:", sourceId);
106
+ console.log("[1.2.1+1] update sent for:", sourceId);
107
107
  }
108
108
  }
109
109
  Reaper(); // clean up obsolete info
@@ -134,10 +134,10 @@ var terminated; // flag that this service worker
134
134
  msgport.onmessage = function(msg) {
135
135
  msg = msg.data;
136
136
  if (msg.id == "skipWaiting") { // try to activate this SW now
137
- console.log("[1.2.0+1] attempting skipWaiting");
137
+ console.log("[1.2.1+1] attempting skipWaiting");
138
138
  self.skipWaiting();
139
139
  } else if (msg.id == "terminate") { // termiante this SW now
140
- console.log("[1.2.0+1] terminated");
140
+ console.log("[1.2.1+1] terminated");
141
141
  terminate();
142
142
  } else if (msg.id == "abortURL") { // abort an I/O transaction
143
143
  var href = new URL(msg.url).href;
@@ -150,7 +150,7 @@ var terminated; // flag that this service worker
150
150
  } else if (msg.id == "response") // response from fetch request
151
151
  processResponse(msg);
152
152
  else if (msg.id == "text") // just log some text
153
- console.log("[1.2.0+1] msg received:", msg.text);
153
+ console.log("[1.2.1+1] msg received:", msg.text);
154
154
  };
155
155
 
156
156
  // send text to IDE log
@@ -161,7 +161,7 @@ var terminated; // flag that this service worker
161
161
  // don't clutter the log
162
162
  msgport.postMessage({
163
163
  id: "text",
164
- text: "port received by 1.2.0+1",
164
+ text: "port received by 1.2.1+1",
165
165
  });
166
166
  */
167
167
  if (--pending === 0)
@@ -178,7 +178,7 @@ var terminated; // flag that this service worker
178
178
  includeUncontrolled: true
179
179
  }).then(function(clientList) {
180
180
  clientList.every(function(client) {
181
- console.log("[1.2.0+1] requesting new msgport for", client.id);
181
+ console.log("[1.2.1+1] requesting new msgport for", client.id);
182
182
  ++pending;
183
183
  client.postMessage({ // tell client(s) we need this fetch source
184
184
  msg: "Naan_need_fetch_port",
@@ -224,12 +224,12 @@ function Reaper() {
224
224
  clients[clientList[clidex].id] = clientList[clidex];
225
225
  for (var sourceId in msgPorts)
226
226
  if (!clients[sourceId]) {
227
- console.log("[1.2.0+1] source gone:", sourceId);
227
+ console.log("[1.2.1+1] source gone:", sourceId);
228
228
  delete msgPorts[sourceId]; // no longer a source
229
229
  }
230
230
  for (var clientId in fetchPorts)
231
231
  if (!clients[clientId]) {
232
- console.log("[1.2.0+1] client gone:", clientId);
232
+ console.log("[1.2.1+1] client gone:", clientId);
233
233
  delete fetchPorts[clientId]; // no longer a client
234
234
  }
235
235
  for (var fqdex = 0; fqdex < fetchQueue.length; ++fqdex) {
@@ -263,16 +263,16 @@ function ClearCaches() {
263
263
  return (Promise.all(
264
264
  cacheNames.map(function(cacheName) {
265
265
  if (cacheName != CurrentCacheName) {
266
- console.log('[1.2.0+1] deleting old cache:', cacheName);
266
+ console.log('[1.2.1+1] deleting old cache:', cacheName);
267
267
  return (caches.delete(cacheName));
268
268
  }
269
269
  })
270
270
  ));
271
271
  }).then(function() { // claim all clients
272
- console.log('[1.2.0+1] claiming clients');
272
+ console.log('[1.2.1+1] claiming clients');
273
273
  return (self.clients.claim());
274
274
  }).then(function() {
275
- console.log('[1.2.0+1] clients claimed');
275
+ console.log('[1.2.1+1] clients claimed');
276
276
  return (Promise.resolve(true));
277
277
  });
278
278
  return (promise);
@@ -315,7 +315,7 @@ function GetClientResponse(event, urlpath) {
315
315
  msgport.postMessage({
316
316
  id: "fetch",
317
317
  seq: seqno,
318
- version: "1.2.0+1",
318
+ version: "1.2.1+1",
319
319
  request: {
320
320
  method: event.request.method,
321
321
  url: event.request.url
@@ -363,7 +363,7 @@ function GetClientResponse(event, urlpath) {
363
363
  */
364
364
 
365
365
  self.addEventListener('install', function(event) {
366
- console.log("[1.2.0+1] install");
366
+ console.log("[1.2.1+1] install");
367
367
  self.skipWaiting();
368
368
  });
369
369
 
@@ -376,20 +376,20 @@ self.addEventListener('install', function(event) {
376
376
  */
377
377
 
378
378
  self.addEventListener('activate', function(event) {
379
- console.log("[1.2.0+1] activate");
379
+ console.log("[1.2.1+1] activate");
380
380
  self.clients.matchAll({ // for debugging, list controlled clients
381
381
  includeUncontrolled: true
382
382
  }).then(function(clientList) {
383
383
  var urls = clientList.map(function(client) {
384
384
  return (client.url);
385
385
  });
386
- console.log('[1.2.0+1] matching clients:', urls.join(', '));
386
+ console.log('[1.2.1+1] matching clients:', urls.join(', '));
387
387
  });
388
388
  var promise = ClearCaches().then(function() {
389
389
  for (var sourceId in upgradeMsgPorts) {
390
390
  upgradeMsgPorts[sourceId].postMessage({ // notify new version available
391
391
  id: "upgrade",
392
- version: "1.2.0+1"
392
+ version: "1.2.1+1"
393
393
  });
394
394
  }
395
395
  upgradeMsgPorts = false;
@@ -421,7 +421,7 @@ self.addEventListener('fetch', function(event) {
421
421
  var promise;
422
422
  var url = new URL(request.url);
423
423
  var nocache = request.method != "GET"
424
- || url.search.length !== 0 && url.searchParams.get("naanver") !== "d20959c47030d94a5b0694e7b9df2dc1"
424
+ || url.search.length !== 0 && url.searchParams.get("naanver") !== "ecffb6bced5a08a6d2fdd188410b1b50"
425
425
  || request.headers.get('range');
426
426
  if (url.pathname.startsWith("/run/")) {
427
427
  nocache = true;
@@ -455,7 +455,7 @@ self.addEventListener('fetch', function(event) {
455
455
  statusText: "Request Cancelled"
456
456
  }));
457
457
  }
458
- console.log("[1.2.0+1] fetch failed", request.url, e);
458
+ console.log("[1.2.1+1] fetch failed", request.url, e);
459
459
  return (new Response(undefined, {
460
460
  status: 404,
461
461
  statusText: "Fetch Failed"
@@ -55,13 +55,17 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
55
55
 
56
56
  // connect
57
57
  // Connect with the host if not already connected.
58
- closure connect(local host, pending) {
58
+ closure connect(local host, url, pending) {
59
59
  if target.ws
60
60
  return(list(false, { connected: true }))
61
61
  host = xnew(window.URL, api.url).host
62
62
  if !host || host == ""
63
63
  return(list(Error("invalid URL ${api.url}")))
64
- target.ws = xnew(window.WebSocket,"ws://${host}")
64
+ if window.location.protocol == "https:"
65
+ url = "wss://${host}"
66
+ else
67
+ url = "ws://${host}"
68
+ target.ws = xnew(window.WebSocket, url)
65
69
  pending = new(nonce)
66
70
 
67
71
  // onopen
@@ -98,8 +102,10 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
98
102
  if msg.id == "spawned" || msg.id == "workerlist" || msg.id == "termination"
99
103
  return (hostWorkerUpdate(msg))
100
104
  if msg.id != "targetout" {
101
- if msg.id == "status"
105
+ if msg.id == "status" {
102
106
  target.lastStatus = milliseconds()
107
+ target.execSetStatus(msg.status)
108
+ }
103
109
  if target.msgQueue {
104
110
  if msg.id != "status"
105
111
  target.msgQueue.push(msg)
@@ -455,8 +461,10 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
455
461
  destroy()
456
462
  return }
457
463
  else if msg.id != "targetout" && msg.id != "loaded" {
458
- if msg.id == "status"
464
+ if msg.id == "status" {
459
465
  target.lastStatus = milliseconds()
466
+ target.execSetStatus(msg.status)
467
+ }
460
468
  if target.msgQueue {
461
469
  if msg.id != "status"
462
470
  target.msgQueue.push(msg)
@@ -468,6 +476,7 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
468
476
  // The worker had an error.
469
477
 
470
478
  target.worker.addEventListener("error", function(e) {
479
+ debuglog("TermLocal worker error:", e.message)
471
480
  target.execClosed(Error("instance error", e.message))
472
481
  })
473
482
 
@@ -720,6 +729,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
720
729
  }
721
730
 
722
731
  function onstatus(status) {
732
+ target.execSetStatus(status)
723
733
  statusCB(target, status)
724
734
  }
725
735
 
@@ -37,10 +37,14 @@ closure WebSocket(options, local wsock) {
37
37
  //
38
38
  // Connect with the host if not already connected, returning a result tuple.
39
39
  //
40
- wsock.connect = closure connect(local pending) {
40
+ wsock.connect = closure connect(local url, pending) {
41
41
  if wsock.ws
42
42
  return (list(false, { open: true }))
43
- wsock.ws = xnew(window.WebSocket, "ws://${options.host}")
43
+ if window.location.protocol == "https:"
44
+ url = "wss://${options.host}"
45
+ else
46
+ url = "ws://${options.host}"
47
+ wsock.ws = xnew(window.WebSocket, url)
44
48
  pending = new(nonce)
45
49
 
46
50
  // onopen
@@ -667,13 +667,13 @@ closure psmcFsConnector(psm, api, local connClassID, connector, watch) {
667
667
 
668
668
 
669
669
  /*
670
- * psmcMakeClientPSM
670
+ * MakeClientPSM
671
671
  *
672
672
  * Return a new client PSM with our known connectors.
673
673
  *
674
674
  */
675
675
 
676
- function psmcMakeClientPSM(api, dbname, local importPSM) {
676
+ function MakeClientPSM(api, dbname, local importPSM) {
677
677
  global(App)
678
678
  importPSM = require("../storage/psm.nlg")
679
679
  App.psm = importPSM.MakePSM(dbname).1
@@ -694,12 +694,12 @@ function psmcMakeClientPSM(api, dbname, local importPSM) {
694
694
 
695
695
  function psmcInit(local manifest) {
696
696
 
697
- manifest = `(psmcFsView, psmcFsConnector, psmcMakeClientPSM, psmcInit)
697
+ manifest = `(psmcFsView, psmcFsConnector, MakeClientPSM, psmcInit)
698
698
 
699
699
  Naan.module.build(module.id, "psm_client", function(modobj, compobj) {
700
700
  require("./client.nlg")
701
701
  compobj.manifest = manifest
702
- modobj.exports.MakeClientPSM = psmcMakeClientPSM
702
+ modobj.exports.MakeClientPSM = MakeClientPSM
703
703
  })
704
704
 
705
705
  } ();
@@ -35,6 +35,7 @@ wsMod;; // websocket module
35
35
  * workerID: <string> // worker on server (server destinations only)
36
36
  * }
37
37
  * startup: <dictionary> // worker spawn init (server destinations only)
38
+ * wss: <boolean> // true to use secure connection
38
39
  * debug: <boolean> // debug logging
39
40
  * }
40
41
  *
@@ -74,6 +75,7 @@ closure RelayCon(host, secret, options, local relay, nlregex)
74
75
  relay.guid = secret
75
76
  relay.host = host // e.g. "localhost:8009"
76
77
  relay.wscon = wsMod.WebSocket(host, {
78
+ wss: options.wss || undefined
77
79
  onopen: onopen
78
80
  onmessage: onmessage
79
81
  onerror: onerror
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * column positioning: // // !
8
8
  *
9
- * Copyright (c) 2020-2023 by Richard C. Zulch
9
+ * Copyright (c) 2020-2024 by Richard C. Zulch
10
10
  *
11
11
  */
12
12
 
@@ -193,8 +193,14 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
193
193
  else
194
194
  fpath = "/".concat(libpath)
195
195
  if js.s.importScripts && tostring(js.s.importScripts) == "[Function importScripts]" {
196
- js.s.importScripts(fpath) // load in worker context
197
- jsScripts[libpath] = js.s[globalID]
196
+ fpath = JSpath.dirname(js.w.location.href).concat(fpath)
197
+ try {
198
+ js.s.importScripts(fpath) // load in worker context
199
+ jsScripts[libpath] = js.s[globalID]
200
+ } catch {
201
+ debuglog("JsLoadScript:", libpath, "failed", exception)
202
+ js.s.console.log("JsLoadScript:", libpath, "failed", exception) // ensure visibility in JS console
203
+ }
198
204
  } else if js.w { // load in browser context
199
205
  pending = new(nonce)
200
206
  scriptTag = js.w.document.createElement("script")
@@ -205,7 +211,7 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
205
211
  true
206
212
  }
207
213
  scriptTag.onerror = function (event) {
208
- debuglog("jsScriptLoader:", libpath, "not found")
214
+ debuglog("JsLoadScript:", libpath, "not found")
209
215
  pending.signal(false)
210
216
  true
211
217
  }
@@ -20,6 +20,7 @@
20
20
  *
21
21
  * Options:
22
22
  * {
23
+ * wss: <boolean> // true to use secure connection
23
24
  * onopen: <proc>(e) // connection has opened
24
25
  * onmessage: <proc>(e, message) // message received
25
26
  * onerror: <proc>(e) // error occurred
@@ -37,13 +38,17 @@ closure WebSocket(host, options, local wsock) {
37
38
  //
38
39
  // Connect with the host if not already connected, returning a result tuple.
39
40
  //
40
- wsock.connect = closure connect(local pending, error, ws) {
41
+ wsock.connect = closure connect(local error, ws, url, pending) {
41
42
  if wsock.ws
42
43
  return (list(false, { open: true }))
43
44
  `(error, ws) = await(js.i("ws"))
44
45
  if error
45
46
  return (list(error))
46
- wsock.ws = xnew(ws.default, "ws://${host}")
47
+ if options.wss
48
+ url = "wss://${host}"
49
+ else
50
+ url = "ws://${host}"
51
+ wsock.ws = xnew(ws.default, url)
47
52
  pending = new(nonce)
48
53
 
49
54
  // onopen
@@ -118,7 +118,7 @@
118
118
  * ]
119
119
  * }
120
120
  *
121
- * build = Builder(rulesDict, operation, fs, srcpath, destpath) // create a builder object
121
+ * build = Builder(rulesDict, operation, fs, srcpath, destpath, track) // create a builder object
122
122
  * build.increment() // increment the build counter
123
123
  * build.make() // run the build
124
124
  * build.clean() // clear all output folders
@@ -140,7 +140,7 @@
140
140
  *
141
141
  */
142
142
 
143
- closure Builder(rules, operation, fs, srcpath, destpath, local build, group, newgroup) {
143
+ closure Builder(rules, operation, fs, srcpath, destpath, track, local build, group, newgroup) {
144
144
  build = new(object, this)
145
145
  build.srcpath = srcpath
146
146
  build.destpath = destpath
@@ -393,7 +393,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
393
393
 
394
394
  closure zip(files, options, local result) {
395
395
  if !build.zipper
396
- build.zipper = ExecutorParallel({ // create worker for zipping
396
+ build.zipper = ExecutorParallel(track, { // create worker for zipping
397
397
  maxcount: 1 // stupid Zip lib can't do more than one
398
398
  basename: "zip"
399
399
  initeval: `(false, (zip1))
@@ -529,7 +529,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
529
529
 
530
530
  closure parseAndPack(text, fpath, options, local result) {
531
531
  if !build.parallel
532
- build.parallel = ExecutorParallel({ // create worker pool
532
+ build.parallel = ExecutorParallel(track, { // create worker pool
533
533
  basename: "build"
534
534
  initeval: `(false, (parseAndPack1))
535
535
  })
@@ -1190,7 +1190,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1190
1190
  //
1191
1191
  // Run the current build product by spawning a new worker.
1192
1192
  //
1193
- build.runSpawn = function runSpawn(track local error, maintext, executor, vpath, site) {
1193
+ build.runSpawn = function runSpawn(local error, maintext, executor, vpath, site) {
1194
1194
  `(error, maintext) = fs.readFile(JSpath.join(build.destpath, build.runway.main))
1195
1195
  if error
1196
1196
  error = Error("Builder: cannot read main file", error)
@@ -1228,7 +1228,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1228
1228
  //
1229
1229
  // Run the current build product by opening a new window.
1230
1230
  //
1231
- build.runWindow = function runWindow(track
1231
+ build.runWindow = function runWindow(
1232
1232
  local title, main, url, features, vpath, error, window, site) {
1233
1233
  if !js.w
1234
1234
  return (list(Error('Run method "window" requires browser host')))
@@ -1260,13 +1260,13 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1260
1260
  // Run the current build product, which would be after the make call. Returns a standard result
1261
1261
  // tuple.
1262
1262
  //
1263
- build.run = function run(track) {
1263
+ build.run = function run() {
1264
1264
  if build.runway.open
1265
1265
  fs.shellOpen(JSpath.join(build.destpath, build.runway.open), build.runway.args)
1266
1266
  else if build.runway.spawn
1267
- build.runSpawn(track)
1267
+ build.runSpawn()
1268
1268
  else if build.runway.window
1269
- build.runWindow(track)
1269
+ build.runWindow()
1270
1270
  else
1271
1271
  list(false, { ok: true })
1272
1272
  }
@@ -1276,7 +1276,7 @@ closure Builder(rules, operation, fs, srcpath, destpath, local build, group, new
1276
1276
  //
1277
1277
  // Refresh after updating the v-site, returning true iff an existing vsite was found.
1278
1278
  //
1279
- build.refresh = function refresh(track local url_origin, found) {
1279
+ build.refresh = function refresh(local url_origin, found) {
1280
1280
  if build.runway."v-site" {
1281
1281
  url_origin = js.w.location.origin.concat("/run", build.runway."v-site")
1282
1282
  for target in track.enumlist() {
@@ -296,7 +296,7 @@ closure projConnector(projman, projtype, local connector, watch) {
296
296
  *
297
297
  * Nide.proj/
298
298
  * nide_cliser.cfg - JSON definition of the project (see below)
299
- * NaanIDE_version.txt - [default] substitution file defining 1.2.0+1 etc.
299
+ * NaanIDE_version.txt - [default] substitution file defining 1.2.1+1 etc.
300
300
  * NaanIDE_version_builds.txt - [default] contains current build number as decimal string
301
301
  * build/ - [optional] default build output location
302
302
  * NaanIDE.lic - [optional] defines Zulch Laboratories, Inc. and other license info
@@ -614,7 +614,7 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
614
614
  rules.typeID = procon.where_typeID
615
615
  if !rules.operation
616
616
  rules.operation = "debug"
617
- `(error, builder) = Builder(rules, rules.operation, fs, "", buildpath)
617
+ `(error, builder) = Builder(rules, rules.operation, fs, "", buildpath, projman.track)
618
618
  if error
619
619
  return (list(error))
620
620
  procon.builder = builder
@@ -628,10 +628,10 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
628
628
  buildnum: buildnum
629
629
  })
630
630
  if !error {
631
- if builder.refresh(projman.track)
631
+ if builder.refresh()
632
632
  buildonly = !buildonly // reverse if refresh
633
633
  if !buildonly
634
- `(error) = builder.run(projman.track)
634
+ `(error) = builder.run()
635
635
  }
636
636
  builder.destroy()
637
637
  procon.builder = false
@@ -662,7 +662,9 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
662
662
  publish = rules.publish
663
663
  where = procon.localDict.publish[stage].where
664
664
  if !rules || !where
665
- return (list(Error("no project publish location configured")))
665
+ return (list(Error("no project publish location set")))
666
+ if !publish.input || !publish.sources || !publish.output
667
+ return (list(Error("project configuration has no publish instructions")))
666
668
  if publish.cacheControl
667
669
  outOptions = {
668
670
  cacheControl: publish.cacheControl