@naanlang/naan 1.3.0 → 1.3.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.3.0+1";
39
+ var CurrentCacheName = "Naanlang-1.3.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.3.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
- if (pubVersion != "1.3.0+1") {
95
+ console.log("[1.3.1+1] received new msgport for", sourceId, pubID, "-", pubVersion);
96
+ if (pubVersion != "1.3.1+1") {
97
97
  if (upgradeMsgPorts) { // if not activated
98
- console.log("[1.3.0+1] update pending for", sourceId);
98
+ console.log("[1.3.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.3.0+1"
104
+ version: "1.3.1+1"
105
105
  });
106
- console.log("[1.3.0+1] update sent for:", sourceId);
106
+ console.log("[1.3.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.3.0+1] attempting skipWaiting");
137
+ console.log("[1.3.1+1] attempting skipWaiting");
138
138
  self.skipWaiting();
139
139
  } else if (msg.id == "terminate") { // termiante this SW now
140
- console.log("[1.3.0+1] terminated");
140
+ console.log("[1.3.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.3.0+1] msg received:", msg.text);
153
+ console.log("[1.3.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.3.0+1",
164
+ text: "port received by 1.3.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.3.0+1] requesting new msgport for", client.id);
181
+ console.log("[1.3.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.3.0+1] source gone:", sourceId);
227
+ console.log("[1.3.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.3.0+1] client gone:", clientId);
232
+ console.log("[1.3.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.3.0+1] deleting old cache:', cacheName);
266
+ console.log('[1.3.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.3.0+1] claiming clients');
272
+ console.log('[1.3.1+1] claiming clients');
273
273
  return (self.clients.claim());
274
274
  }).then(function() {
275
- console.log('[1.3.0+1] clients claimed');
275
+ console.log('[1.3.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.3.0+1",
318
+ version: "1.3.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.3.0+1] install");
366
+ console.log("[1.3.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.3.0+1] activate");
379
+ console.log("[1.3.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.3.0+1] matching clients:', urls.join(', '));
386
+ console.log('[1.3.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.3.0+1"
392
+ version: "1.3.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") !== "73538d9da7b765535859c873f6955312"
424
+ || url.search.length !== 0 && url.searchParams.get("naanver") !== "ecae8a62f4a0ae0408f1cbd16082d4ea"
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.3.0+1] fetch failed", request.url, e);
458
+ console.log("[1.3.1+1] fetch failed", request.url, e);
459
459
  return (new Response(undefined, {
460
460
  status: 404,
461
461
  statusText: "Fetch Failed"
@@ -19,6 +19,7 @@
19
19
  */
20
20
 
21
21
  function EncodeQuery(prefix, items, local result, item) {
22
+ global()
22
23
  result = []
23
24
  for item in items
24
25
  result.push(EncodeURIComponent(item).concat("=", EncodeURIComponent(items[item])))
@@ -38,6 +39,7 @@ function EncodeQuery(prefix, items, local result, item) {
38
39
  */
39
40
 
40
41
  function DecodeQuery(text, local output, rpreg, qarr, item, pair) {
42
+ global()
41
43
  output = {}
42
44
  rpreg = RegExp("\\+", "g")
43
45
  qarr = text.split("&")
@@ -62,6 +64,7 @@ function DecodeQuery(text, local output, rpreg, qarr, item, pair) {
62
64
  */
63
65
 
64
66
  function ContentTypeFromFileExt(filepath, local mimeType, encoding) {
67
+ global(JSpath)
65
68
  mimeType = {
66
69
  "css": "text/css",
67
70
  "csv": "text/csv",
@@ -103,6 +106,7 @@ function ContentTypeFromFileExt(filepath, local mimeType, encoding) {
103
106
  */
104
107
 
105
108
  function UUID(local rando) {
109
+ global(RandomBytes)
106
110
  if !RandomBytes
107
111
  return (false)
108
112
  rando = RandomBytes(36) // length of UUID
@@ -128,6 +132,7 @@ function UUID(local rando) {
128
132
  */
129
133
 
130
134
  function VersionCheck(testv, refv, local rxver, test, ref) {
135
+ global()
131
136
  rxver = RegExp("([0-9]+)[.]([0-9]+)[.]([0-9]+)-?[A-Za-z_]*[+]?([0-9]+)")
132
137
  function numerify(x){ Number.parseInt(x) }
133
138
  test = testv.match(rxver).map(numerify.proc)
@@ -147,6 +152,7 @@ function VersionCheck(testv, refv, local rxver, test, ref) {
147
152
  */
148
153
 
149
154
  function JsonParse(data) {
155
+ global(exception)
150
156
  try {
151
157
  data = JSONparse(data)
152
158
  list(false, data)
@@ -165,6 +171,7 @@ function JsonParse(data) {
165
171
  */
166
172
 
167
173
  function JsonStringify(data) {
174
+ global(exception)
168
175
  try {
169
176
  data = JSONstringify(data)
170
177
  list(false, data)
@@ -185,15 +192,18 @@ function JsonStringify(data) {
185
192
 
186
193
  jsScripts = { }; // script values become false on reload
187
194
 
188
- closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
195
+ closure JsLoadScript(libpath, globalID, local savens, fpath, hostpath, pending, scriptTag) {
196
+ global(jsScripts, js, JSpath)
189
197
  if jsScripts[libpath]
190
198
  return // already loaded
199
+ savens = nsactive()
191
200
  if libpath.startsWith("/")
192
201
  fpath = libpath
193
202
  else
194
203
  fpath = "/".concat(libpath)
204
+ hostpath = js.w.location.origin.concat(JSpath.dirname(js.w.location.pathname))
195
205
  if js.s.importScripts && tostring(js.s.importScripts) == "[Function importScripts]" {
196
- fpath = JSpath.dirname(js.w.location.href).concat(fpath)
206
+ fpath = hostpath.concat(fpath)
197
207
  try {
198
208
  js.s.importScripts(fpath) // load in worker context
199
209
  jsScripts[libpath] = js.s[globalID]
@@ -204,7 +214,7 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
204
214
  } else if js.w { // load in browser context
205
215
  pending = new(nonce)
206
216
  scriptTag = js.w.document.createElement("script")
207
- scriptTag.src = JSpath.dirname(js.w.location.href).concat(fpath, requireQuery())
217
+ scriptTag.src = hostpath.concat(fpath, requireQuery())
208
218
  scriptTag.onload = function (event) {
209
219
  jsScripts[libpath] = js.w[globalID]
210
220
  pending.signal(js.w[globalID])
@@ -219,6 +229,7 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
219
229
  pending.wait()
220
230
  } else if js.g
221
231
  jsScripts[libpath] = js.r(libpath) // load in NodeJS context
232
+ nsactive(savens)
222
233
  jsScripts[libpath]
223
234
  };
224
235
 
@@ -234,6 +245,7 @@ closure JsLoadScript(libpath, globalID, local scriptTag, fpath) {
234
245
  */
235
246
 
236
247
  macro LoadComponentOnDemand(functionKeys, componentPath, local modobj, key) {
248
+ global()
237
249
  modobj = car(nsrights().lookup("module"))
238
250
  functionKeys = eval(functionKeys)
239
251
  componentPath = eval(componentPath)
@@ -281,6 +293,7 @@ macro LoadComponentOnDemand(functionKeys, componentPath, local modobj, key) {
281
293
  */
282
294
 
283
295
  macro LiveExport() {
296
+ global()
284
297
  closure (exporterMod, local importList) {
285
298
  importList = []
286
299
  //
@@ -16,6 +16,17 @@
16
16
  *
17
17
  * Make an API server object.
18
18
  *
19
+ * Options:
20
+ * {
21
+ * name: <string> // server name (default "NaanServer")
22
+ * abspath: <string> // absolute pathname for web root
23
+ * relpath: <string> // web root pth relative to js.d
24
+ * fixedPort: <number> // fixed
25
+ * basePort: <number> // starting point for search
26
+ * gateway: <string> // websocket gateway URL
27
+ * statics: [<string>, ...] // search paths for static content
28
+ * }
29
+ *
19
30
  */
20
31
 
21
32
  closure APIServer(options, local server, chroot) {
@@ -30,7 +41,10 @@ closure APIServer(options, local server, chroot) {
30
41
  relpath: ""
31
42
  name: "NaanServer"
32
43
  }, options)
33
- chroot = JSpath.join(js.d, options.relpath)
44
+ if options.abspath
45
+ chroot = options.abspath
46
+ else
47
+ chroot = JSpath.join(js.d, options.relpath)
34
48
  server.root = chroot
35
49
 
36
50
  // updatePort
@@ -1298,6 +1298,8 @@ closure Builder(rules, operation, fs, srcpath, destpath, track, local build, gro
1298
1298
  //
1299
1299
  build.increment = closure increment(newnum, local error, filecon, buildnum) {
1300
1300
  build.buildnum = undefined
1301
+ if !build.buildnopath
1302
+ return (list(false, { version: false }))
1301
1303
  `(error, filecon) = fs.readFile(build.buildnopath)
1302
1304
  if !error
1303
1305
  buildnum = toint(filecon.trim())
@@ -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.3.0+1 etc.
299
+ * NaanIDE_version.txt - [default] substitution file defining 1.3.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
@@ -536,7 +536,7 @@ exports.NaanControllerWeb = function() {
536
536
  statedoc.curversion = kStateCurrentVersion;
537
537
  statedoc.firstver = kStateFirstVersion;
538
538
  statedoc.licensee = "MIT-License";
539
- statedoc.verstring = "1.3.0+1";
539
+ statedoc.verstring = "1.3.1+1";
540
540
  statedoc.date = new Date().toISOString();
541
541
  statedoc.prefs = prefs;
542
542
  statedoc.naan = naanlib.saveState(false); // true to optimize, which is a bit slower
@@ -554,7 +554,7 @@ exports.NaanControllerWeb = function() {
554
554
  || statedoc.firstver > kStateCurrentVersion
555
555
  || statedoc.curversion < kStateFirstVersion
556
556
  || statedoc.licensee != "MIT-License"
557
- || statedoc.verstring != "1.3.0+1")
557
+ || statedoc.verstring != "1.3.1+1")
558
558
  {
559
559
  localStorage.removeItem("NaanState_Hosted");
560
560
  return (false);
@@ -613,7 +613,7 @@ exports.NaanControllerWeb = function() {
613
613
  op: "VsiteOpen",
614
614
  name: vsiteName,
615
615
  naancont: contSelf,
616
- title: vsiteName + " 1.3.0+1"
616
+ title: vsiteName + " 1.3.1+1"
617
617
  });
618
618
  }
619
619
  } catch (e) {
@@ -627,7 +627,7 @@ exports.NaanControllerWeb = function() {
627
627
  op: "VsiteClose",
628
628
  name: vsiteName,
629
629
  naancont: contSelf,
630
- title: vsiteName + " 1.3.0+1"
630
+ title: vsiteName + " 1.3.1+1"
631
631
  });
632
632
  termTextOut("\x1b[90m\x1b[3m".concat("\nwindow closed", "\x1b[0m\n"));
633
633
  }
@@ -640,10 +640,10 @@ exports.NaanControllerWeb = function() {
640
640
  if (querystrings["restart"] || !loadLocal())
641
641
  { // don't load state or can't load state
642
642
  naanlib.banner();
643
- var hostpath = naanlib.js.r("path").dirname(window.location.href);
643
+ var hostpath = window.location.origin.concat(naanlib.js.r("path").dirname(window.location.pathname));
644
644
  naanlib.start({
645
- cmd: 'App.version = "1.3.0+1";;\r\n'
646
- + 'App.cache = "49a9b89fb804111a36026df163e15009";;\r\n'
645
+ cmd: 'App.version = "1.3.1+1";;\r\n'
646
+ + 'App.cache = "1f0eccb08fd1a57ede0bd91dc0e934cc";;\r\n'
647
647
  + 'Naan.module.requireQuery({ naanver: App.cache });;\r\n'
648
648
  + 'Naan.module.webparse("naan_init.nlg", "' + hostpath + '", { naanver: App.cache });;\r\n'
649
649
  });