@naanlang/naan 1.0.9 → 1.0.11

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.0.9+1";
39
+ var CurrentCacheName = "Naanlang-1.0.11+1";
40
40
 
41
41
 
42
42
  //
@@ -89,11 +89,11 @@ var waitingForInit = []; // initialization functions, or
89
89
  var pubVersion = event.data.hereIsMyVersion;
90
90
  var sourceId = event.source.id; // client id of sender of message
91
91
  msgPorts[sourceId] = msgport;
92
- console.log("[1.0.9+1] received new msgport for", sourceId, pubID, "-", pubVersion);
93
- if (pubVersion != "1.0.9+1")
92
+ console.log("[1.0.11+1] received new msgport for", sourceId, pubID, "-", pubVersion);
93
+ if (pubVersion != "1.0.11+1")
94
94
  msgport.postMessage({ // notify new version available
95
95
  id: "upgrade",
96
- version: "1.0.9+1"
96
+ version: "1.0.11+1"
97
97
  });
98
98
  Reaper(); // clean up obsolete info
99
99
 
@@ -107,7 +107,7 @@ var waitingForInit = []; // initialization functions, or
107
107
  if (msg.id == "response")
108
108
  processResponse(msg);
109
109
  else if (msg.id == "text")
110
- console.log("[1.0.9+1] msg received:", msg.text);
110
+ console.log("[1.0.11+1] msg received:", msg.text);
111
111
  };
112
112
 
113
113
  // send text to IDE log
@@ -118,7 +118,7 @@ var waitingForInit = []; // initialization functions, or
118
118
  // don't clutter the log
119
119
  msgport.postMessage({
120
120
  id: "text",
121
- text: "port received by 1.0.9+1",
121
+ text: "port received by 1.0.11+1",
122
122
  });
123
123
  */
124
124
  if (--pending === 0)
@@ -135,7 +135,7 @@ var waitingForInit = []; // initialization functions, or
135
135
  includeUncontrolled: true
136
136
  }).then(function(clientList) {
137
137
  clientList.every(function(client) {
138
- console.log("[1.0.9+1] requesting new msgport for", client.id);
138
+ console.log("[1.0.11+1] requesting new msgport for", client.id);
139
139
  ++pending;
140
140
  client.postMessage({ // tell client(s) we need this fetch source
141
141
  msg: "Naan_need_fetch_port",
@@ -181,12 +181,12 @@ function Reaper() {
181
181
  clients[clientList[clidex].id] = clientList[clidex];
182
182
  for (var sourceId in msgPorts)
183
183
  if (!clients[sourceId]) {
184
- console.log("[1.0.9+1] source gone:", sourceId);
184
+ console.log("[1.0.11+1] source gone:", sourceId);
185
185
  delete msgPorts[sourceId]; // no longer a source
186
186
  }
187
187
  for (var clientId in fetchPorts)
188
188
  if (!clients[clientId]) {
189
- console.log("[1.0.9+1] client gone:", clientId);
189
+ console.log("[1.0.11+1] client gone:", clientId);
190
190
  delete fetchPorts[clientId]; // no longer a client
191
191
  }
192
192
  for (var fqdex = 0; fqdex < fetchQueue.length; ++fqdex) {
@@ -220,13 +220,13 @@ function ClearCaches() {
220
220
  return (Promise.all(
221
221
  cacheNames.map(function(cacheName) {
222
222
  if (cacheName != CurrentCacheName) {
223
- console.log('[1.0.9+1] deleting old cache:', cacheName);
223
+ console.log('[1.0.11+1] deleting old cache:', cacheName);
224
224
  return (caches.delete(cacheName));
225
225
  }
226
226
  })
227
227
  ));
228
228
  }).then(function() { // claim all clients
229
- console.log('[1.0.9+1] claiming clients');
229
+ console.log('[1.0.11+1] claiming clients');
230
230
  return (self.clients.claim());
231
231
  });
232
232
  return (promise);
@@ -269,7 +269,7 @@ function GetClientResponse(event, urlpath) {
269
269
  msgport.postMessage({
270
270
  id: "fetch",
271
271
  seq: seqno,
272
- version: "1.0.9+1",
272
+ version: "1.0.11+1",
273
273
  request: {
274
274
  method: event.request.method,
275
275
  url: event.request.url
@@ -317,7 +317,7 @@ function GetClientResponse(event, urlpath) {
317
317
  */
318
318
 
319
319
  self.addEventListener('install', function(event) {
320
- console.log("[1.0.9+1] install");
320
+ console.log("[1.0.11+1] install");
321
321
  self.skipWaiting();
322
322
  });
323
323
 
@@ -339,7 +339,7 @@ self.addEventListener('fetch', function(event) {
339
339
  var promise;
340
340
  var url = new URL(event.request.url);
341
341
  var nocache = event.request.method != "GET"
342
- || url.search.length !== 0 && url.searchParams.get("naanver") !== "47cb512242b15eae60df6f89500e5ca4"
342
+ || url.search.length !== 0 && url.searchParams.get("naanver") !== "edf3a32af5c323a44ef5f80ba836e163"
343
343
  || event.request.headers.get('range');
344
344
  if (url.pathname.startsWith("/run/")) {
345
345
  nocache = true;
@@ -356,7 +356,7 @@ self.addEventListener('fetch', function(event) {
356
356
  }
357
357
  else
358
358
  promise = fetch(event.request).catch(function (e) {
359
- console.log("[1.0.9+1] fetch failed", e);
359
+ console.log("[1.0.11+1] fetch failed", e);
360
360
  return (new Response(undefined, {
361
361
  status: 404,
362
362
  statusText: "Fetch Failed"
@@ -385,14 +385,14 @@ self.addEventListener('fetch', function(event) {
385
385
  */
386
386
 
387
387
  self.addEventListener('activate', function(event) {
388
- console.log("[1.0.9+1] activate");
388
+ console.log("[1.0.11+1] activate");
389
389
  self.clients.matchAll({ // for debugging, list controlled clients
390
390
  includeUncontrolled: true
391
391
  }).then(function(clientList) {
392
392
  var urls = clientList.map(function(client) {
393
393
  return (client.url);
394
394
  });
395
- console.log('[1.0.9+1] matching clients:', urls.join(', '));
395
+ console.log('[1.0.11+1] matching clients:', urls.join(', '));
396
396
  });
397
397
  var promise = ClearCaches();
398
398
  if (event.waitUntil)
@@ -176,7 +176,7 @@ function JsLoadScript(libpath, globalID, local scriptTag, fpath) {
176
176
  } else if js.w { // load in browser context
177
177
  pending = new(nonce)
178
178
  scriptTag = js.w.document.createElement("script")
179
- scriptTag.src = js.w.location.origin.concat(fpath, requireQuery())
179
+ scriptTag.src = JSpath.dirname(js.w.location.href).concat(fpath, requireQuery())
180
180
  scriptTag.onload = function (event) {
181
181
  jsScripts[libpath] = js.w[globalID]
182
182
  pending.signal(js.w[globalID])
@@ -0,0 +1,77 @@
1
+ /*
2
+ * utils.nlg
3
+ * naanlib/frameworks/common/utils
4
+ *
5
+ * Platform-independent utility functions.
6
+ *
7
+ * column positioning: // // !
8
+ *
9
+ * Copyright (c) 2023 by Richard C. Zulch
10
+ *
11
+ */
12
+
13
+
14
+ /*
15
+ * DictCompare
16
+ *
17
+ * Compare two dictionaries and report differences in a dictionary with the following structure of
18
+ * differences from aa to bb:
19
+ * {
20
+ * added: [<item>,<item>...<item>]
21
+ * changed: [<item>,<item>...<item>]
22
+ * deleted: [<item>,<item>...<item>]
23
+ * }
24
+ *
25
+ * > DictCompare({a:3,b:2,c:5,f:8},{g:0,a:3,b:4,e:7,f:9});
26
+ * $: {
27
+ * changed: ["b", "f"],
28
+ * deleted: ["c"],
29
+ * added : ["e", "g"] }
30
+ *
31
+ */
32
+
33
+ function DictCompare(aa, bb, local output, keysa, keysb, ka, kb, comp) {
34
+ function compare(ka, kb) { ka <=> kb }
35
+ function added(key) { output.added.push(key) || output.added = [key] }
36
+ function changed(key) { output.changed.push(key) || output.changed = [key] }
37
+ function deleted(key) { output.deleted.push(key) || output.deleted = [key] }
38
+
39
+ output = { }
40
+ keysa = aa.*.toarray.sort(compare).reverse()
41
+ keysb = bb.*.toarray.sort(compare).reverse()
42
+ ka = keysa.pop()
43
+ kb = keysb.pop()
44
+ while ka || kb {
45
+ comp = ka <=> kb
46
+ if comp < 0
47
+ deleted(ka)
48
+ else if comp > 0
49
+ added(kb)
50
+ else if aa[ka] != bb[ka]
51
+ changed(ka)
52
+ if comp <= 0
53
+ ka = keysa.pop()
54
+ if comp >= 0
55
+ kb = keysb.pop()
56
+ }
57
+ output
58
+ };
59
+
60
+
61
+ /*
62
+ * utilsInit
63
+ *
64
+ * Initialize the component.
65
+ *
66
+ */
67
+
68
+ function utilsInit(local manifest) {
69
+ manifest = `(DictCompare, utilsInit)
70
+
71
+ Naan.module.build(module.id, "utils", function(modobj, compobj) {
72
+ require("./common.nlg")
73
+ compobj.manifest = manifest
74
+ module.exports.DictCompare = DictCompare
75
+ updateExports()
76
+ })
77
+ } ();
@@ -767,7 +767,7 @@ closure Filesystem(rootpath, local files, badCreatePathRegEx) {
767
767
  }
768
768
  output = []
769
769
  debuglog("dirSearch begins", localpath)
770
- asyncArray(localpaths, 10, closure(localpath, index, elements, local error, direnum, node, lines, line) {
770
+ asyncArray(localpaths, 10, closure(localpath, local error, direnum, node, lines, line) {
771
771
  `(error, direnum) = dirList(localpath, { })
772
772
  if direnum.children
773
773
  for node in direnum.children
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * column positioning: // // !
7
7
  *
8
- * Copyright (c) 2021-2022 by Richard C. Zulch
8
+ * Copyright (c) 2021-2023 by Richard C. Zulch
9
9
  *
10
10
  */
11
11
 
@@ -23,12 +23,15 @@
23
23
  * contentType: <string> // sets Content-Type header, otherwise auto-determined
24
24
  * range: <string> // sets range header
25
25
  * headers: [`(key, value)] // add header(s) to the request, overriding defaults
26
+ * auth: <string> // username:password string
27
+ * cacert: <data> // ca for verifying peer
26
28
  * debug: <boolean> // log errors and status results
27
29
  * }
28
30
  *
29
31
  */
30
32
 
31
- closure HttpsApiRequest(url, options, local urlq, reqOptions, putdata, item, pending, chunks, request) {
33
+ closure HttpsApiRequest(url, options,
34
+ local urlq, reqOptions, putdata, item, xurl, pending, chunks, request) {
32
35
  if options.query
33
36
  urlq = url.concat(EncodeQuery("?", options.query))
34
37
  else
@@ -58,6 +61,20 @@ closure HttpsApiRequest(url, options, local urlq, reqOptions, putdata, item, pen
58
61
  if array(options.headers)
59
62
  for item in options.headers
60
63
  reqOptions.headers[item.0] = item.1
64
+ if options.auth
65
+ reqOptions.auth = options.auth
66
+ if options.cacert
67
+ reqOptions.ca = options.cacert
68
+ if options.allowSelfSigned {
69
+ xurl = nodeUrl.parse(url)
70
+ reqOptions.agent = xnew(nodeHttps.Agent({
71
+ host: xurl.hostname
72
+ port: xurl.port
73
+ path: xurl.path
74
+ rejectUnauthorized: false
75
+ ca: [ selfSignedRootCaPemCrtBuffer ]
76
+ }))
77
+ }
61
78
  pending = new(nonce)
62
79
  chunks = []
63
80
  request = nodeHttps.request(url, reqOptions, closure (response) {
@@ -76,6 +76,7 @@ function nodrInit(local manifest) {
76
76
  os = js.r("os")
77
77
  stream = js.r("stream")
78
78
  nodeHttps = js.r("https")
79
+ nodeUrl= js.r("url")
79
80
  }()
80
81
  module.reload = nodrReload
81
82
  })
@@ -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.0.9+1 etc.
299
+ * NaanIDE_version.txt - [default] substitution file defining 1.0.11+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
@@ -574,7 +574,9 @@ closure projConfig(projman, where, projID, local procon, fs, configpath) {
574
574
  if error
575
575
  return (list(error))
576
576
  rules = procon.configDict."build-rules"[stage]
577
- if !rules
577
+ if rules.inherit
578
+ rules = js.o.assign(procon.configDict."build-rules"[rules.inherit], rules)
579
+ else if !rules
578
580
  rules = procon.configDict.build // fallback to old config structure
579
581
  rules = new(rules)
580
582
  if !rules["no-common"]
@@ -19,15 +19,15 @@
19
19
  */
20
20
 
21
21
  closure DebugNub(local nub, debug, paused) {
22
+ if debugNub !== `debugNub { // multiple load attempt
23
+ debuglog("DebugNub: a debugNub already exsts; there can be only one")
24
+ return (false)
25
+ }
22
26
  debug = module.owner.list.Util.exports.DebugController()
23
27
  if !debug { // no debugger support in worker
24
28
  debuglog("DebugNub: no debugger support in this execution instance")
25
29
  return (false)
26
30
  }
27
- if debugNub !== `debugNub { // multiple load attempt
28
- debuglog("DebugNub: a debugNub already exsts; there can be only one")
29
- return (false)
30
- }
31
31
  nub = new(object, this)
32
32
  debugNub = nub // access from taskDispatcher
33
33
  nub.codemgr = CodeManager()
@@ -385,7 +385,7 @@ closure FileManager(fs, options, local files, watch, opqueue, willgit, hadgit) {
385
385
  else if files.fs.dirSearch
386
386
  processGrep(files.fs.dirSearch)
387
387
  else {
388
- asyncArray(files.nodes, 5, closure(node, index, elements, local error, lines) {
388
+ asyncArray(files.nodes, 5, closure(node, local error, lines) {
389
389
  ++fileCount
390
390
  `(error, lines) = files.fs.readLines(node, config)
391
391
  if error
@@ -276,7 +276,7 @@ closure MakePSMutil(fs, local util) {
276
276
  //
277
277
  // Pass 1 - Get info on all source files, and make destination directories
278
278
  //
279
- asyncArray(sources, 10, closure mklist(entry, index, elements,
279
+ asyncArray(sources, 10, closure mklist(entry,
280
280
  local srcpath, destpath, epath, error, stat, folder, node) {
281
281
  srcpath = fs.path.join(inpath, entry)
282
282
  destpath = outfs.path.join(outpath, entry)
@@ -308,7 +308,7 @@ closure MakePSMutil(fs, local util) {
308
308
  // Pass 2 - erase extraneous files and folders from destination
309
309
  //
310
310
  if options.erase {
311
- asyncArray(keys(folders).toarray, 10, closure eraser(destpath, index, elements
311
+ asyncArray(keys(folders).toarray, 10, closure eraser(destpath
312
312
  local error, outfolder, folder, namesin, removes, delopt) {
313
313
  `(error, outfolder) = outfs.dirList(destpath) // existing files in our destination
314
314
  if error
@@ -336,7 +336,7 @@ closure MakePSMutil(fs, local util) {
336
336
  //
337
337
  // Pass 3 - copy files and links
338
338
  //
339
- asyncArray(copies, 10, closure cpfiles(entry, index, elements,
339
+ asyncArray(copies, 10, closure cpfiles(entry,
340
340
  local error, data, dest, instat, outstat) {
341
341
  `(error, instat) = fs.info(entry.source, fsopt)
342
342
  if !error {
@@ -356,6 +356,12 @@ exports.NaanControllerWeb = function() {
356
356
  this.int = function int() {
357
357
  contSelf.Interrupt();
358
358
  };
359
+ //
360
+ // StateSave
361
+ //
362
+ this.StateSave = function StateSave() {
363
+ return (false);
364
+ };
359
365
  }
360
366
 
361
367
  //
@@ -520,7 +526,7 @@ exports.NaanControllerWeb = function() {
520
526
  statedoc.curversion = kStateCurrentVersion;
521
527
  statedoc.firstver = kStateFirstVersion;
522
528
  statedoc.licensee = "MIT-License";
523
- statedoc.verstring = "1.0.9+1";
529
+ statedoc.verstring = "1.0.11+1";
524
530
  statedoc.date = new Date().toISOString();
525
531
  statedoc.prefs = prefs;
526
532
  statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
@@ -538,7 +544,7 @@ exports.NaanControllerWeb = function() {
538
544
  || statedoc.firstver > kStateCurrentVersion
539
545
  || statedoc.curversion < kStateFirstVersion
540
546
  || statedoc.licensee != "MIT-License"
541
- || statedoc.verstring != "1.0.9+1")
547
+ || statedoc.verstring != "1.0.11+1")
542
548
  {
543
549
  localStorage.removeItem("NaanState_Hosted");
544
550
  return (false);
@@ -564,8 +570,8 @@ exports.NaanControllerWeb = function() {
564
570
  if ("localStorage" in window && window["localStorage"] !== null)
565
571
  {
566
572
  localStorage.removeItem("NaanState_Hosted");
567
- if (localStorage.setItem("NaanState_Hosted", statestr) !== undefined)
568
- return (true);
573
+ localStorage.setItem("NaanState_Hosted", statestr);
574
+ return (true);
569
575
  }
570
576
  } catch(e) {
571
577
  console.log("save state failed: " + "(" + e + ")");
@@ -597,7 +603,7 @@ exports.NaanControllerWeb = function() {
597
603
  op: "VsiteOpen",
598
604
  name: vsiteName,
599
605
  naancont: contSelf,
600
- title: vsiteName + " 1.0.9+1"
606
+ title: vsiteName + " 1.0.11+1"
601
607
  });
602
608
  }
603
609
  } catch (e) {
@@ -611,7 +617,7 @@ exports.NaanControllerWeb = function() {
611
617
  op: "VsiteClose",
612
618
  name: vsiteName,
613
619
  naancont: contSelf,
614
- title: vsiteName + " 1.0.9+1"
620
+ title: vsiteName + " 1.0.11+1"
615
621
  });
616
622
  termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
617
623
  }
@@ -626,8 +632,8 @@ exports.NaanControllerWeb = function() {
626
632
  naanlib.banner();
627
633
  var hostpath = naanlib.js.r("path").dirname(window.location.href);
628
634
  naanlib.start({
629
- cmd: 'App.version = "1.0.9+1";;\r\n'
630
- + 'App.cache = "56a3661c1caa5c6ed3781ffcad84acf4";;\r\n'
635
+ cmd: 'App.version = "1.0.11+1";;\r\n'
636
+ + 'App.cache = "8fdb7eef8a4a62fd4137803988319a3c";;\r\n'
631
637
  + 'Naan.module.requireQuery({ naanver: App.cache });;\r\n'
632
638
  + 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '", { naanver: App.cache });;\r\n'
633
639
  });