@codua/codeoutline-win32-x64 0.1.5 → 0.1.9
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/DISTRIBUTION.md +60 -15
- package/README.md +7 -7
- package/README.zh-CN.md +7 -7
- package/bin/xnet.exe +0 -0
- package/build-info.json +1 -1
- package/codeoutline +3 -1
- package/codeoutline.cmd +5 -1
- package/package.json +1 -1
- package/scripts/codeoutline/command.lua +103 -7
- package/scripts/codeoutline/common.lua +10 -2
- package/scripts/codeoutline/daemon.lua +223 -0
- package/scripts/codeoutline/explore.lua +46 -42
- package/scripts/codeoutline/graph.lua +89 -54
- package/scripts/codeoutline/http.lua +5 -0
- package/scripts/codeoutline/index.lua +246 -66
- package/scripts/codeoutline/index_worker.lua +1 -0
- package/scripts/codeoutline/main.lua +71 -11
- package/scripts/codeoutline/service.lua +25 -4
- package/scripts/codeoutline/update_sequence.lua +1 -1
- package/scripts/codeoutline/update_worker.lua +17 -7
- package/scripts/codeoutline/updater.lua +8 -5
- package/scripts/codeoutline/version.lua +1 -1
- package/scripts/codeoutline/xscan.lua +41 -2
- package/scripts/xupgate/client.lua +85 -1
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
-- Background update thread: network, verification and installation stay off the
|
|
2
|
-
-- service thread.
|
|
2
|
+
-- service thread. Checks at startup and then hourly while the service runs.
|
|
3
3
|
local source = assert(xutils.realpath(debug.getinfo(1, 'S').source:sub(2))):gsub('\\', '/')
|
|
4
4
|
local scripts = assert(source:match('^(.*)/codeoutline/[^/]+$'))
|
|
5
5
|
package.path = scripts .. '/?.lua;' .. package.path
|
|
6
6
|
local updater = require('codeoutline.updater')
|
|
7
|
+
local INTERVAL_MS = 3600000
|
|
8
|
+
local checking = false
|
|
9
|
+
|
|
10
|
+
local function check()
|
|
11
|
+
if checking then return end
|
|
12
|
+
checking = true
|
|
13
|
+
local ok, err = pcall(function()
|
|
14
|
+
require('xupgate.client').open(updater.config()).update(function(update_error, result)
|
|
15
|
+
checking = false
|
|
16
|
+
xthread.post(1, 'update_result', update_error, result and result.version)
|
|
17
|
+
end)
|
|
18
|
+
end)
|
|
19
|
+
if not ok then checking = false; xthread.post(1, 'update_result', tostring(err)) end
|
|
20
|
+
end
|
|
7
21
|
|
|
8
22
|
return {
|
|
9
23
|
__init = function()
|
|
10
24
|
assert(xnet.init()); xtimer.init(16)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
xthread.post(1, 'update_result', update_error, result and result.version)
|
|
14
|
-
end)
|
|
15
|
-
end)
|
|
16
|
-
if not ok then xthread.post(1, 'update_result', tostring(err)) end
|
|
25
|
+
check()
|
|
26
|
+
xtimer.add(INTERVAL_MS, check, -1)
|
|
17
27
|
end,
|
|
18
28
|
__uninit = function() xnet.uninit() end,
|
|
19
29
|
__thread_handle = function() end,
|
|
@@ -20,6 +20,13 @@ function M.config(options)
|
|
|
20
20
|
minimumSequence=tonumber(os.getenv('CODEOUTLINE_UPDATE_MIN_SEQUENCE')) or build.updateSequence or 0,
|
|
21
21
|
http=require('xupgate.http_client'),
|
|
22
22
|
runtimeDirectory=install,
|
|
23
|
+
-- Keep only the active version; npm reinstalls are the way back.
|
|
24
|
+
keepPrevious=false,prune=true,
|
|
25
|
+
-- Versions before 0.1.7 run without leases.
|
|
26
|
+
leased=function(files)
|
|
27
|
+
local sdk=c.read(files .. '/scripts/xupgate/client.lua')
|
|
28
|
+
return sdk~=nil and sdk:find('function M.lease',1,true)~=nil
|
|
29
|
+
end,
|
|
23
30
|
}
|
|
24
31
|
cfg.validate=function(root,m)
|
|
25
32
|
local info=c.decode_json(c.read(root .. '/build-info.json'))
|
|
@@ -43,7 +50,7 @@ end
|
|
|
43
50
|
function M.run(action,options)
|
|
44
51
|
local api=require('xupgate.client').open(M.config(options))
|
|
45
52
|
local function selected()
|
|
46
|
-
local ok,current=pcall(api.
|
|
53
|
+
local ok,current=pcall(api.active)
|
|
47
54
|
if not ok then io.stderr:write('codeoutline: installed update invalid; using initial version\n')end
|
|
48
55
|
return ok and current and current.root or install
|
|
49
56
|
end
|
|
@@ -58,10 +65,6 @@ function M.run(action,options)
|
|
|
58
65
|
assert(xnet.init());xtimer.init(16)
|
|
59
66
|
-- Selection is local only; serve updates in its background thread.
|
|
60
67
|
if action=='select' then finish(nil)
|
|
61
|
-
elseif action=='rollback' then
|
|
62
|
-
local ok,result=pcall(api.rollback)
|
|
63
|
-
if not ok and tostring(result):find('no previous version',1,true)then ok,result=pcall(api.use_initial)end
|
|
64
|
-
finish(not ok and tostring(result) or nil,ok and result or nil)
|
|
65
68
|
elseif action=='current' then local ok,result=pcall(api.current);finish(not ok and tostring(result) or nil,ok and result or nil)
|
|
66
69
|
elseif action=='check' then api.check(finish)
|
|
67
70
|
else api.update(finish)end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
return '0.1.
|
|
1
|
+
return '0.1.9'
|
|
@@ -329,7 +329,11 @@ function Lang:tokenize(src)
|
|
|
329
329
|
|
|
330
330
|
while pos <= len do
|
|
331
331
|
local c = src:byte(pos)
|
|
332
|
-
if c == 10 then
|
|
332
|
+
if c == 10 then -- \n
|
|
333
|
+
-- Newlines outside tokens are counted here; strings and block
|
|
334
|
+
-- comments jump past theirs and add them with count_nl. Indent
|
|
335
|
+
-- mode ends a logical line, but not inside brackets, and blank or
|
|
336
|
+
-- comment-only lines collapse into the previous 'nl'.
|
|
333
337
|
if indent_mode and depth == 0 and n > 0 and K[n] ~= 'nl' and not skip then
|
|
334
338
|
push('nl', pos, pos, line)
|
|
335
339
|
end
|
|
@@ -337,21 +341,30 @@ function Lang:tokenize(src)
|
|
|
337
341
|
pos = pos + 1
|
|
338
342
|
bol = true
|
|
339
343
|
elseif c == 32 or c == 9 or c == 13 or c == 12 or c == 11 then
|
|
344
|
+
-- Space, tab, \r, \f, \v. bol stays set, so indentation and a
|
|
345
|
+
-- directive '#' are still judged at the first real token; the \r
|
|
346
|
+
-- of \r\n is skipped here and its \n counted above.
|
|
340
347
|
pos = pos + 1
|
|
341
348
|
elseif indent_mode and c == 92 and (src:byte(pos + 1) == 10
|
|
342
349
|
or (src:byte(pos + 1) == 13 and src:byte(pos + 2) == 10)) then
|
|
343
350
|
-- Python `\` continuation: the next line joins this logical line
|
|
351
|
+
-- (no 'nl', and bol stays clear so its indentation is ignored).
|
|
344
352
|
pos = pos + (src:byte(pos + 1) == 10 and 2 or 3)
|
|
345
353
|
line = line + 1
|
|
346
354
|
else
|
|
355
|
+
-- Anything else starts a token, comment or directive. Every token
|
|
356
|
+
-- except 'nl' is pushed below; each case advances pos past what it
|
|
357
|
+
-- consumed, and the operator case always consumes at least a byte.
|
|
358
|
+
|
|
347
359
|
-- Indentation (Python): measured at the first real token of a line.
|
|
348
360
|
if indent_mode and bol and depth == 0 then
|
|
349
361
|
local col_start = pos
|
|
350
362
|
while col_start > 1 and src:byte(col_start - 1) ~= 10 do col_start = col_start - 1 end
|
|
351
|
-
local width = 0
|
|
363
|
+
local width = 0 -- tabs advance to the next multiple of 8
|
|
352
364
|
for x = col_start, pos - 1 do
|
|
353
365
|
width = width + ((src:byte(x) == 9) and (8 - width % 8) or 1)
|
|
354
366
|
end
|
|
367
|
+
-- Comment-only lines do not open or close blocks.
|
|
355
368
|
local is_comment = false
|
|
356
369
|
for _, lc in ipairs(self.line_comment) do
|
|
357
370
|
if starts(src, pos, lc) then is_comment = true end
|
|
@@ -402,6 +415,9 @@ function Lang:tokenize(src)
|
|
|
402
415
|
end
|
|
403
416
|
bol = false
|
|
404
417
|
|
|
418
|
+
-- The cases below are tried in order; the first match wins.
|
|
419
|
+
-- Line comment: skipped up to (not including) the newline, which
|
|
420
|
+
-- the \n branch then handles.
|
|
405
421
|
if not handled then
|
|
406
422
|
for _, lc in ipairs(self.line_comment) do
|
|
407
423
|
if starts(src, pos, lc) then
|
|
@@ -419,6 +435,7 @@ function Lang:tokenize(src)
|
|
|
419
435
|
end
|
|
420
436
|
end
|
|
421
437
|
end
|
|
438
|
+
-- Lua long string [==[ ... ]==]: one 'str' token.
|
|
422
439
|
if not handled and long_brackets then
|
|
423
440
|
local lb = long_open(src, pos)
|
|
424
441
|
if lb then
|
|
@@ -430,11 +447,14 @@ function Lang:tokenize(src)
|
|
|
430
447
|
handled = true
|
|
431
448
|
end
|
|
432
449
|
end
|
|
450
|
+
-- Block comment: skipped, its newlines still counted. An unclosed
|
|
451
|
+
-- one runs to the end of the file.
|
|
433
452
|
if not handled then
|
|
434
453
|
for _, bc in ipairs(self.block_comment) do
|
|
435
454
|
if starts(src, pos, bc[1]) then
|
|
436
455
|
local stop
|
|
437
456
|
if nested_comments then
|
|
457
|
+
-- Rust: /* /* */ */ closes at the outer */
|
|
438
458
|
local nest, p = 1, pos + #bc[1]
|
|
439
459
|
while p + #bc[2] - 1 <= len do
|
|
440
460
|
if starts(src, p, bc[1]) then
|
|
@@ -460,6 +480,7 @@ function Lang:tokenize(src)
|
|
|
460
480
|
end
|
|
461
481
|
end
|
|
462
482
|
end
|
|
483
|
+
-- JS template literal `...${...}...`: one 'str' token, nesting included.
|
|
463
484
|
if not handled and template_literals and c == 96 then
|
|
464
485
|
local stop = skip_template(src, pos)
|
|
465
486
|
local l0 = line
|
|
@@ -468,6 +489,8 @@ function Lang:tokenize(src)
|
|
|
468
489
|
pos = stop + 1
|
|
469
490
|
handled = true
|
|
470
491
|
end
|
|
492
|
+
-- JS regex literal: only where an operand may start; when the line
|
|
493
|
+
-- ends before the closing '/', it falls through as a division.
|
|
471
494
|
if not handled and regex_literals and c == 47 and regex_allowed(src, K, S, E, n, ctrl_close) then
|
|
472
495
|
local stop = scan_regex(src, pos, id_char)
|
|
473
496
|
if stop then
|
|
@@ -476,6 +499,7 @@ function Lang:tokenize(src)
|
|
|
476
499
|
handled = true
|
|
477
500
|
end
|
|
478
501
|
end
|
|
502
|
+
-- Rust lifetime 'a: an 'id', so it is not read as an unclosed char.
|
|
479
503
|
if not handled and lifetimes and c == 39 then
|
|
480
504
|
local stop = scan_lifetime(src, pos, id_start, id_char)
|
|
481
505
|
if stop then
|
|
@@ -484,6 +508,8 @@ function Lang:tokenize(src)
|
|
|
484
508
|
handled = true
|
|
485
509
|
end
|
|
486
510
|
end
|
|
511
|
+
-- Rust raw string r"..", r#".."#, br"..", cr"..": one 'str' token.
|
|
512
|
+
-- Otherwise r/b/c fall through to an identifier.
|
|
487
513
|
if not handled and raw_strings and (c == 114 or c == 98 or c == 99) then
|
|
488
514
|
local stop = scan_raw_string(src, pos, id_char)
|
|
489
515
|
if stop then
|
|
@@ -496,6 +522,9 @@ function Lang:tokenize(src)
|
|
|
496
522
|
end
|
|
497
523
|
if not handled then
|
|
498
524
|
-- String, optionally after a prefix (r"", b'', f"""...""").
|
|
525
|
+
-- A prefix counts only at the start of a word (not the end of
|
|
526
|
+
-- `abc"`). A single-line string stops at the newline, so a
|
|
527
|
+
-- stray quote cannot swallow the rest of the file.
|
|
499
528
|
local q = pos
|
|
500
529
|
while self.prefixes[src:byte(q)] and q - pos < 2 do q = q + 1 end
|
|
501
530
|
for _, st in ipairs(self.strings) do
|
|
@@ -529,12 +558,16 @@ function Lang:tokenize(src)
|
|
|
529
558
|
end
|
|
530
559
|
end
|
|
531
560
|
if not handled then
|
|
561
|
+
-- Identifier or keyword: the longest run of identifier bytes
|
|
562
|
+
-- (bytes >= 0x80 included, so UTF-8/GBK names stay whole).
|
|
532
563
|
if id_start[c] then
|
|
533
564
|
local p = pos + 1
|
|
534
565
|
while p <= len and id_char[src:byte(p)] do p = p + 1 end
|
|
535
566
|
local word = src:sub(pos, p - 1)
|
|
536
567
|
push(keywords[word] and 'kw' or 'id', pos, p - 1, line)
|
|
537
568
|
pos = p
|
|
569
|
+
-- Number: a digit, or '.' then a digit. Takes identifier
|
|
570
|
+
-- bytes, '.' and the C++14 separator ' (0x1F, 1.5f, 1'000).
|
|
538
571
|
elseif (c >= 48 and c <= 57) or (c == 46 and (src:byte(pos + 1) or 0) >= 48 and (src:byte(pos + 1) or 0) <= 57) then
|
|
539
572
|
local p = pos + 1
|
|
540
573
|
while p <= len do
|
|
@@ -551,6 +584,8 @@ function Lang:tokenize(src)
|
|
|
551
584
|
push('num', pos, p - 1, line)
|
|
552
585
|
pos = p
|
|
553
586
|
else
|
|
587
|
+
-- Operator or punctuation: the longest configured operator
|
|
588
|
+
-- starting with this byte, else the single byte itself.
|
|
554
589
|
local w = 1
|
|
555
590
|
local list = ops[c]
|
|
556
591
|
if list then
|
|
@@ -558,11 +593,15 @@ function Lang:tokenize(src)
|
|
|
558
593
|
if starts(src, pos, op) then w = #op; break end
|
|
559
594
|
end
|
|
560
595
|
end
|
|
596
|
+
-- Bracket depth: indent mode ignores newlines inside brackets,
|
|
597
|
+
-- and directives use it to choose which #if arms to keep.
|
|
561
598
|
if w == 1 and not skip then
|
|
562
599
|
if OPEN[c] then depth = depth + 1
|
|
563
600
|
elseif CLOSE[c] and depth > 0 then depth = depth - 1 end
|
|
564
601
|
end
|
|
565
602
|
push('op', pos, pos + w - 1, line)
|
|
603
|
+
-- Track which ')' closes an if/while/for/with condition:
|
|
604
|
+
-- a '/' right after one starts a regex, not a division.
|
|
566
605
|
if regex_literals and w == 1 and not skip then
|
|
567
606
|
if c == 40 then
|
|
568
607
|
local prev = n - 1
|
|
@@ -11,6 +11,47 @@ end
|
|
|
11
11
|
local function command_ok(command)
|
|
12
12
|
local ok=os.execute(command);return ok==true or ok==0
|
|
13
13
|
end
|
|
14
|
+
-- A lease marks an installed version as used by a live process; pruning keeps
|
|
15
|
+
-- leased versions. Windows holds the lease file open, so it cannot be deleted
|
|
16
|
+
-- until the process exits; elsewhere the file names a PID checked with kill -0.
|
|
17
|
+
local windows=package.config:sub(1,1)=='\\'
|
|
18
|
+
local LEGACY_GRACE=7*86400
|
|
19
|
+
local function token()
|
|
20
|
+
return u.sha256_hex(tostring(os.time()) .. tostring(os.clock()) .. tostring({}) .. tostring(math.random())):sub(1,16)
|
|
21
|
+
end
|
|
22
|
+
local function process_id()
|
|
23
|
+
local pipe=io.popen('echo $PPID');if not pipe then return nil end
|
|
24
|
+
local pid=pipe:read('a');pipe:close()
|
|
25
|
+
return tonumber(pid:match('^%s*(%d+)%s*$'))
|
|
26
|
+
end
|
|
27
|
+
-- A lease whose owner has exited is removed and reported free.
|
|
28
|
+
local function lease_alive(path)
|
|
29
|
+
if windows then return not os.remove(path)end
|
|
30
|
+
local pid=tonumber((c.read(path,64) or ''):match('^(%d+)'))
|
|
31
|
+
if pid and pid>1 and command_ok('kill -0 ' .. pid .. ' 2>/dev/null')then return true end
|
|
32
|
+
os.remove(path);return false
|
|
33
|
+
end
|
|
34
|
+
local leases={}
|
|
35
|
+
-- Returns nil outside an update directory (the initial installation is never pruned).
|
|
36
|
+
function M.lease(files_root)
|
|
37
|
+
local root,identity=files_root:gsub('\\','/'):match('^(.*)/versions/(%x+)/files/?$')
|
|
38
|
+
if not root or #identity~=64 or not u.mkdir_p(root .. '/leases') then return nil end
|
|
39
|
+
local path=root .. '/leases/' .. identity .. '-' .. token()
|
|
40
|
+
local handle
|
|
41
|
+
if windows then
|
|
42
|
+
handle=io.open(path,'wb');if not handle then return nil end
|
|
43
|
+
else
|
|
44
|
+
local pid=process_id();if not pid or not pcall(c.write,path,pid .. '\n')then return nil end
|
|
45
|
+
end
|
|
46
|
+
local lease={}
|
|
47
|
+
function lease.release()
|
|
48
|
+
if handle then handle:close();handle=nil end
|
|
49
|
+
os.remove(path);leases[lease]=nil
|
|
50
|
+
end
|
|
51
|
+
-- Referenced here so garbage collection never closes the held handle.
|
|
52
|
+
leases[lease]=true
|
|
53
|
+
return lease
|
|
54
|
+
end
|
|
14
55
|
function M.open(config)
|
|
15
56
|
assert(c.id(config.project) and c.id(config.platform),'invalid project/platform')
|
|
16
57
|
assert(type(config.publicKey)=='string','pinned publicKey required')
|
|
@@ -46,6 +87,38 @@ function M.open(config)
|
|
|
46
87
|
if not ok then error(result) end
|
|
47
88
|
return result
|
|
48
89
|
end
|
|
90
|
+
-- Remove versions other than keep that no live process leases, then the
|
|
91
|
+
-- runtime cache, which only feeds installation.
|
|
92
|
+
local function prune(keep)
|
|
93
|
+
local now,busy=os.time(),{}
|
|
94
|
+
for _,entry in ipairs(u.list_dir(root .. '/leases') or {})do
|
|
95
|
+
local path=root .. '/leases/' .. entry.name
|
|
96
|
+
local identity=entry.name:match('^(%x+)%-%x+$')
|
|
97
|
+
if not identity then os.remove(path)
|
|
98
|
+
elseif lease_alive(path)then busy[identity]=true end
|
|
99
|
+
end
|
|
100
|
+
for _,entry in ipairs(u.list_dir(root .. '/versions') or {})do
|
|
101
|
+
local removable=entry.dir and not keep[entry.name] and not busy[entry.name]
|
|
102
|
+
-- Versions predating leases may still run unseen: delete them only
|
|
103
|
+
-- after a grace period counted from the first prune that saw them.
|
|
104
|
+
if removable and config.leased and not config.leased(root .. '/versions/' .. entry.name .. '/files') then
|
|
105
|
+
local marker=root .. '/retired/' .. entry.name
|
|
106
|
+
local info=u.stat(marker)
|
|
107
|
+
if not (info and info.exists) then c.write(marker,now .. '\n');removable=false
|
|
108
|
+
else removable=now-(info.mtime or now)>=(config.legacyGrace or LEGACY_GRACE) end
|
|
109
|
+
end
|
|
110
|
+
if removable then
|
|
111
|
+
-- Moving first keeps a half-deleted tree out of versions/.
|
|
112
|
+
assert(u.mkdir_p(root .. '/trash'))
|
|
113
|
+
os.rename(root .. '/versions/' .. entry.name,root .. '/trash/' .. entry.name .. '-' .. token())
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
for _,entry in ipairs(u.list_dir(root .. '/trash') or {})do u.rmtree(root .. '/trash/' .. entry.name)end
|
|
117
|
+
for _,entry in ipairs(u.list_dir(root .. '/retired') or {})do
|
|
118
|
+
if not u.stat(root .. '/versions/' .. entry.name).exists then os.remove(root .. '/retired/' .. entry.name)end
|
|
119
|
+
end
|
|
120
|
+
if u.stat(root .. '/runtime-cache').exists then u.rmtree(root .. '/runtime-cache')end
|
|
121
|
+
end
|
|
49
122
|
local function verified(envelope)
|
|
50
123
|
local m=c.manifest(envelope,config.publicKey)
|
|
51
124
|
assert(m.project==config.project and m.platform==config.platform,'manifest target mismatch')
|
|
@@ -81,6 +154,14 @@ function M.open(config)
|
|
|
81
154
|
end
|
|
82
155
|
return {version=m.version,sequence=m.sequence,root=dir .. '/files',entry=m.entry,runtime=m.runtime,sha256=m.sha256,kind=m.kind or 'full'}
|
|
83
156
|
end
|
|
157
|
+
-- The installed update to run, or nil when the initial installation is
|
|
158
|
+
-- at least as new: reinstalling a newer initial version (an npm upgrade)
|
|
159
|
+
-- raises minimumSequence, and check() will not fetch anything below it.
|
|
160
|
+
function api.active()
|
|
161
|
+
local current=api.current()
|
|
162
|
+
if current and current.sequence<(config.minimumSequence or 0) then return nil end
|
|
163
|
+
return current
|
|
164
|
+
end
|
|
84
165
|
function api.install(envelope,data)
|
|
85
166
|
local m=verified(envelope);local files=c.bundle(data,m)
|
|
86
167
|
local identity=u.sha256_hex(envelope.payload)
|
|
@@ -125,9 +206,12 @@ function M.open(config)
|
|
|
125
206
|
c.atomic(dir .. '/complete','1\n')
|
|
126
207
|
end
|
|
127
208
|
if config.validate then assert(config.validate(dir .. '/files',m),'project health validation failed')end
|
|
128
|
-
|
|
209
|
+
local previous=config.keepPrevious~=false and s.current or nil
|
|
210
|
+
save({schema=1,highSequence=math.max(s.highSequence,m.sequence),previous=previous,current=identity})
|
|
129
211
|
local ok,result=pcall(api.current)
|
|
130
212
|
if not ok then save(s);error(result)end
|
|
213
|
+
-- Cleanup never fails an installation that is already active.
|
|
214
|
+
if config.prune then pcall(prune,{[identity]=true,[previous or identity]=true})end
|
|
131
215
|
return result
|
|
132
216
|
end)
|
|
133
217
|
end
|