@voxgig/model 3.2.0 → 3.4.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/dist/lib/builder/local.js +1 -21
- package/dist/lib/builder/local.js.map +1 -1
- package/dist/lib/watch.d.ts +19 -2
- package/dist/lib/watch.js +69 -14
- package/dist/lib/watch.js.map +1 -1
- package/lib/builder/local.ts +6 -2
- package/lib/watch.ts +103 -15
- package/package.json +6 -6
|
@@ -23,7 +23,7 @@ const local_builder = async (build, ctx) => {
|
|
|
23
23
|
for (let name in builders) {
|
|
24
24
|
let builder = builders[name];
|
|
25
25
|
let action_path = path_1.default.join(root, builder.load);
|
|
26
|
-
clear(action_path)
|
|
26
|
+
// clear(action_path)
|
|
27
27
|
let action = require(action_path);
|
|
28
28
|
if (action instanceof Promise) {
|
|
29
29
|
action = await action;
|
|
@@ -73,24 +73,4 @@ const local_builder = async (build, ctx) => {
|
|
|
73
73
|
return { ok: false, why: 'bad-step', step: ctx.step, active: false };
|
|
74
74
|
};
|
|
75
75
|
exports.local_builder = local_builder;
|
|
76
|
-
// Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
|
|
77
|
-
function clear(path) {
|
|
78
|
-
let filePath = require.resolve(path);
|
|
79
|
-
if (require.cache[filePath]) {
|
|
80
|
-
const children = require.cache[filePath].children.map(child => child.id);
|
|
81
|
-
// Delete module from cache
|
|
82
|
-
delete require.cache[filePath];
|
|
83
|
-
for (const id of children) {
|
|
84
|
-
clear(id);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (require.cache[filePath] && require.cache[filePath].parent) {
|
|
88
|
-
let i = require.cache[filePath].parent.children.length;
|
|
89
|
-
while (i--) {
|
|
90
|
-
if (require.cache[filePath].parent.children[i].id === filePath) {
|
|
91
|
-
require.cache[filePath].parent.children.splice(i, 1);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
76
|
//# sourceMappingURL=local.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../lib/builder/local.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AAKvB,uCAAuC;AACvC,MAAM,aAAa,GAAY,KAAK,EAAE,KAAY,EAAE,GAAiB,EAAE,EAAE;IACvE,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IACzC,IAAI,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAA;IAE3C,IAAI,IAAI,IAAI,UAAU,EAAE,CAAC;QACvB,IAAI,CAAC;YACH,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAA;YAE5C,+CAA+C;YAC/C,IAAI,IAAI,GAAG,cAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;YAG/C,6BAA6B;YAC7B,IAAI,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAA;YAElC,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA;YAE/C,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAA;YAExC,kCAAkC;YAClC,gBAAgB;YAChB,KAAK,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC1B,IAAI,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;gBAC5B,IAAI,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../lib/builder/local.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AAKvB,uCAAuC;AACvC,MAAM,aAA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AK,CAAC,CAAA;oBACnD,EAAE,GAAG,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;oBAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAChB,CAAC;YACH,CAAC;YAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;QACnD,CAAC;QACD,OAAO,CAAM,EAAE,CAAC;YACd,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AACtE,CAAC,CAAA;AAkCC,sCAAa"}
|
package/dist/lib/watch.d.ts
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import type { Build, BuildResult } from './types';
|
|
2
2
|
import { FSWatcher } from 'chokidar';
|
|
3
|
+
type Run = {
|
|
4
|
+
canon: string;
|
|
5
|
+
path: string;
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
type Canon = {
|
|
10
|
+
path: string;
|
|
11
|
+
isFolder: boolean;
|
|
12
|
+
when: number;
|
|
13
|
+
};
|
|
3
14
|
declare class Watch {
|
|
4
15
|
fsw: FSWatcher;
|
|
5
16
|
spec: any;
|
|
6
17
|
last?: BuildResult;
|
|
7
18
|
last_change_time: number;
|
|
8
19
|
build: Build | undefined;
|
|
20
|
+
runq: Run[];
|
|
21
|
+
doneq: Run[];
|
|
22
|
+
canons: Canon[];
|
|
23
|
+
running: boolean;
|
|
9
24
|
constructor(spec: any);
|
|
10
|
-
|
|
11
|
-
|
|
25
|
+
drain(): Promise<void>;
|
|
26
|
+
add(path: string): Promise<void>;
|
|
27
|
+
canon(path: string): string;
|
|
28
|
+
update(br: BuildResult): Promise<void>;
|
|
12
29
|
start(): Promise<BuildResult>;
|
|
13
30
|
run(once?: boolean): Promise<BuildResult>;
|
|
14
31
|
stop(): Promise<void>;
|
package/dist/lib/watch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* Copyright © 2021-
|
|
2
|
+
/* Copyright © 2021-2024 Voxgig Ltd, MIT License. */
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
@@ -16,36 +16,90 @@ class Watch {
|
|
|
16
16
|
this.spec = spec;
|
|
17
17
|
this.fsw = new chokidar_1.FSWatcher();
|
|
18
18
|
this.last_change_time = 0;
|
|
19
|
-
|
|
20
|
-
this.
|
|
19
|
+
this.runq = [];
|
|
20
|
+
this.doneq = [];
|
|
21
|
+
this.canons = [];
|
|
22
|
+
this.running = false;
|
|
23
|
+
// const run = this.run.bind(this)
|
|
24
|
+
const drain = this.drain.bind(this);
|
|
25
|
+
this.fsw.on('change', async (path) => {
|
|
21
26
|
// TODO: needs a much more robust queue that checks for dups,
|
|
22
27
|
// otherwise BuildContext state will have concurrency corruptions
|
|
23
28
|
// Avoid rebuilding when, for example, TS rewrites all files in dist
|
|
24
|
-
const dorun = 1111 < Date.now() - this.last_change_time
|
|
29
|
+
// const dorun = 1111 < Date.now() - this.last_change_time
|
|
25
30
|
// console.log('CHANGE', dorun, this.last_change_time, args)
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
const canon = this.canon(path);
|
|
32
|
+
const running = this.runq.find((run) => run.canon === canon);
|
|
33
|
+
if (running) {
|
|
34
|
+
// console.log('RUNNING', canon, path)
|
|
35
|
+
return;
|
|
28
36
|
}
|
|
37
|
+
this.runq.push({
|
|
38
|
+
canon,
|
|
39
|
+
path,
|
|
40
|
+
start: Date.now(),
|
|
41
|
+
end: -1,
|
|
42
|
+
});
|
|
43
|
+
// console.log('RUNQ-ADD', this.runq)
|
|
44
|
+
setImmediate(drain);
|
|
29
45
|
});
|
|
30
46
|
}
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
47
|
+
async drain() {
|
|
48
|
+
if (this.running) {
|
|
49
|
+
return;
|
|
34
50
|
}
|
|
35
|
-
this.
|
|
51
|
+
this.running = true;
|
|
52
|
+
let r;
|
|
53
|
+
while (r = this.runq[0]) {
|
|
54
|
+
// console.log('DRAIN')
|
|
55
|
+
let br = await this.run(false);
|
|
56
|
+
// console.log('BR', br)
|
|
57
|
+
this.runq.shift();
|
|
58
|
+
r.end = Date.now();
|
|
59
|
+
this.doneq.push(r);
|
|
60
|
+
// console.log('DONEQ', this.doneq)
|
|
61
|
+
}
|
|
62
|
+
this.running = false;
|
|
63
|
+
}
|
|
64
|
+
async add(path) {
|
|
65
|
+
if (!node_path_1.default.isAbsolute(path)) {
|
|
66
|
+
path = node_path_1.default.join(this.spec.require, path);
|
|
67
|
+
}
|
|
68
|
+
// Ignore if aleady added
|
|
69
|
+
if (this.canons.find((c) => c.path === path)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const fileStat = await (0, promises_1.stat)(path);
|
|
73
|
+
const canon = {
|
|
74
|
+
path: path,
|
|
75
|
+
isFolder: fileStat.isDirectory(),
|
|
76
|
+
when: Date.now()
|
|
77
|
+
};
|
|
78
|
+
this.canons.push(canon);
|
|
79
|
+
this.fsw.add(path);
|
|
80
|
+
// console.log('ADD', canon)
|
|
81
|
+
}
|
|
82
|
+
// If path is inside a watched folder, return folder as canonical reference.
|
|
83
|
+
canon(path) {
|
|
84
|
+
for (const canon of this.canons) {
|
|
85
|
+
if (canon.isFolder && path.startsWith(canon.path)) {
|
|
86
|
+
return canon.path;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return path;
|
|
36
90
|
}
|
|
37
|
-
update(br) {
|
|
91
|
+
async update(br) {
|
|
38
92
|
let build = br.build;
|
|
39
93
|
let files = Object.keys(build.root.deps).reduce((files, target) => {
|
|
40
94
|
files = files.concat(Object.keys(build.root.deps[target]));
|
|
41
95
|
return files;
|
|
42
96
|
}, [build.path]);
|
|
43
97
|
// TODO: remove deleted files
|
|
44
|
-
files.forEach((file) => {
|
|
98
|
+
files.forEach(async (file) => {
|
|
45
99
|
if ('string' === typeof (file) &&
|
|
46
100
|
'' !== file &&
|
|
47
101
|
build.opts.base !== file) {
|
|
48
|
-
this.
|
|
102
|
+
await this.add(file);
|
|
49
103
|
}
|
|
50
104
|
});
|
|
51
105
|
}
|
|
@@ -54,6 +108,7 @@ class Watch {
|
|
|
54
108
|
return await this.run(false);
|
|
55
109
|
}
|
|
56
110
|
async run(once) {
|
|
111
|
+
// console.trace()
|
|
57
112
|
var _a, _b;
|
|
58
113
|
this.last_change_time = Date.now();
|
|
59
114
|
print('\n@voxgig/model', new Date(this.last_change_time));
|
|
@@ -69,7 +124,7 @@ class Watch {
|
|
|
69
124
|
print('TOP:', Object.keys((_a = br === null || br === void 0 ? void 0 : br.build) === null || _a === void 0 ? void 0 : _a.model).join(', '), '\n');
|
|
70
125
|
if (!once) {
|
|
71
126
|
// There may be new files.
|
|
72
|
-
this.update(br);
|
|
127
|
+
await this.update(br);
|
|
73
128
|
}
|
|
74
129
|
}
|
|
75
130
|
else {
|
package/dist/lib/watch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../lib/watch.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;AAEpD,0DAA4B;AAK5B,mCAAmC;AACnC,uCAAoC;AAEpC,
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../lib/watch.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;AAEpD,0DAA4B;AAK5B,mCAAmC;AACnC,uCAAoC;AAEpC,0CAA4C;AAG5C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAA;AACzB,MAAM,IAAI,GAAG,OAAO,CAAC,IAA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d,OAAO,EAAE,CAAA;IACX,CAAC;IAGD,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;IAGD,YAAY,CAAC,EAAe;QAC1B,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC;YACX,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC;gBACtB,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC;oBACX,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;gBACd,CAAC;qBACI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;oBACpB,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;gBAClB,CAAC;qBACI,CAAC;oBACJ,IAAI,CAAC,EAAE,CAAC,CAAA;gBACV,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAqD;QAC5D,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,OAAO,EAAE,CAAA;QACX,CAAC;QAED,IAAI,IAAI,GAAG,EAAE,CAAA;QACb,KAAK,IAAI,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAA;YAC3B,KAAK,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBACjD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,CAAA;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;CACF;AAIC,sBAAK"}
|
package/lib/builder/local.ts
CHANGED
|
@@ -30,7 +30,10 @@ const local_builder: Builder = async (build: Build, ctx: BuildContext) => {
|
|
|
30
30
|
let builder = builders[name]
|
|
31
31
|
let action_path = Path.join(root, builder.load)
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
// clear(action_path)
|
|
35
|
+
|
|
36
|
+
|
|
34
37
|
let action = require(action_path)
|
|
35
38
|
|
|
36
39
|
if (action instanceof Promise) {
|
|
@@ -91,7 +94,7 @@ const local_builder: Builder = async (build: Build, ctx: BuildContext) => {
|
|
|
91
94
|
return { ok: false, why: 'bad-step', step: ctx.step, active: false }
|
|
92
95
|
}
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
/*
|
|
95
98
|
// Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
|
|
96
99
|
function clear(path: string) {
|
|
97
100
|
let filePath = require.resolve(path)
|
|
@@ -119,6 +122,7 @@ function clear(path: string) {
|
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
}
|
|
125
|
+
*/
|
|
122
126
|
|
|
123
127
|
|
|
124
128
|
export {
|
package/lib/watch.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Copyright © 2021-
|
|
1
|
+
/* Copyright © 2021-2024 Voxgig Ltd, MIT License. */
|
|
2
2
|
|
|
3
3
|
import Path from 'node:path'
|
|
4
4
|
|
|
@@ -8,50 +8,136 @@ import type { Build, BuildResult } from './types'
|
|
|
8
8
|
import { makeBuild } from './build'
|
|
9
9
|
import { FSWatcher } from 'chokidar'
|
|
10
10
|
|
|
11
|
-
import { readFile } from 'fs/promises'
|
|
11
|
+
import { readFile, stat } from 'fs/promises'
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
const print = console.log
|
|
15
15
|
const warn = console.warn
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
type Run = {
|
|
19
|
+
canon: string
|
|
20
|
+
path: string
|
|
21
|
+
start: number
|
|
22
|
+
end: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type Canon = {
|
|
26
|
+
path: string
|
|
27
|
+
isFolder: boolean
|
|
28
|
+
when: number
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
class Watch {
|
|
19
32
|
fsw: FSWatcher
|
|
20
33
|
spec: any
|
|
21
34
|
last?: BuildResult
|
|
22
35
|
last_change_time: number
|
|
23
36
|
build: Build | undefined
|
|
37
|
+
runq: Run[]
|
|
38
|
+
doneq: Run[]
|
|
39
|
+
canons: Canon[]
|
|
40
|
+
running: boolean
|
|
24
41
|
|
|
25
42
|
constructor(spec: any) {
|
|
26
43
|
this.spec = spec
|
|
27
44
|
this.fsw = new FSWatcher()
|
|
28
45
|
this.last_change_time = 0
|
|
46
|
+
this.runq = []
|
|
47
|
+
this.doneq = []
|
|
48
|
+
this.canons = []
|
|
49
|
+
this.running = false
|
|
29
50
|
|
|
30
|
-
const run = this.run.bind(this)
|
|
51
|
+
// const run = this.run.bind(this)
|
|
52
|
+
const drain = this.drain.bind(this)
|
|
31
53
|
|
|
32
|
-
this.fsw.on('change', (
|
|
54
|
+
this.fsw.on('change', async (path: string) => {
|
|
33
55
|
// TODO: needs a much more robust queue that checks for dups,
|
|
34
56
|
// otherwise BuildContext state will have concurrency corruptions
|
|
35
57
|
// Avoid rebuilding when, for example, TS rewrites all files in dist
|
|
36
|
-
const dorun = 1111 < Date.now() - this.last_change_time
|
|
58
|
+
// const dorun = 1111 < Date.now() - this.last_change_time
|
|
37
59
|
// console.log('CHANGE', dorun, this.last_change_time, args)
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
61
|
+
const canon = this.canon(path)
|
|
62
|
+
|
|
63
|
+
const running = this.runq.find((run: Run) => run.canon === canon)
|
|
64
|
+
if (running) {
|
|
65
|
+
// console.log('RUNNING', canon, path)
|
|
66
|
+
return
|
|
41
67
|
}
|
|
68
|
+
|
|
69
|
+
this.runq.push({
|
|
70
|
+
canon,
|
|
71
|
+
path,
|
|
72
|
+
start: Date.now(),
|
|
73
|
+
end: -1,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// console.log('RUNQ-ADD', this.runq)
|
|
77
|
+
setImmediate(drain)
|
|
42
78
|
})
|
|
43
79
|
}
|
|
44
80
|
|
|
45
81
|
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
82
|
+
async drain() {
|
|
83
|
+
if (this.running) {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.running = true
|
|
88
|
+
let r
|
|
89
|
+
while (r = this.runq[0]) {
|
|
90
|
+
// console.log('DRAIN')
|
|
91
|
+
let br = await this.run(false)
|
|
92
|
+
// console.log('BR', br)
|
|
93
|
+
this.runq.shift()
|
|
94
|
+
r.end = Date.now()
|
|
95
|
+
|
|
96
|
+
this.doneq.push(r)
|
|
97
|
+
|
|
98
|
+
// console.log('DONEQ', this.doneq)
|
|
99
|
+
}
|
|
100
|
+
this.running = false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async add(path: string) {
|
|
105
|
+
if (!Path.isAbsolute(path)) {
|
|
106
|
+
path = Path.join(this.spec.require, path)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Ignore if aleady added
|
|
110
|
+
if (this.canons.find((c: Canon) => c.path === path)) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const fileStat = await stat(path)
|
|
115
|
+
const canon: Canon = {
|
|
116
|
+
path: path,
|
|
117
|
+
isFolder: fileStat.isDirectory(),
|
|
118
|
+
when: Date.now()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.canons.push(canon)
|
|
122
|
+
|
|
123
|
+
this.fsw.add(path)
|
|
124
|
+
|
|
125
|
+
// console.log('ADD', canon)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// If path is inside a watched folder, return folder as canonical reference.
|
|
130
|
+
canon(path: string) {
|
|
131
|
+
for (const canon of this.canons) {
|
|
132
|
+
if (canon.isFolder && path.startsWith(canon.path)) {
|
|
133
|
+
return canon.path
|
|
134
|
+
}
|
|
49
135
|
}
|
|
50
|
-
|
|
136
|
+
return path
|
|
51
137
|
}
|
|
52
138
|
|
|
53
139
|
|
|
54
|
-
update(br: BuildResult) {
|
|
140
|
+
async update(br: BuildResult) {
|
|
55
141
|
let build = (br.build as Build)
|
|
56
142
|
|
|
57
143
|
let files: string[] =
|
|
@@ -62,12 +148,12 @@ class Watch {
|
|
|
62
148
|
|
|
63
149
|
|
|
64
150
|
// TODO: remove deleted files
|
|
65
|
-
files.forEach((file: string) => {
|
|
151
|
+
files.forEach(async (file: string) => {
|
|
66
152
|
if ('string' === typeof (file) &&
|
|
67
153
|
'' !== file &&
|
|
68
154
|
build.opts.base !== file
|
|
69
155
|
) {
|
|
70
|
-
this.
|
|
156
|
+
await this.add(file)
|
|
71
157
|
}
|
|
72
158
|
})
|
|
73
159
|
|
|
@@ -81,6 +167,8 @@ class Watch {
|
|
|
81
167
|
|
|
82
168
|
|
|
83
169
|
async run(once?: boolean): Promise<BuildResult> {
|
|
170
|
+
// console.trace()
|
|
171
|
+
|
|
84
172
|
this.last_change_time = Date.now()
|
|
85
173
|
print('\n@voxgig/model', new Date(this.last_change_time))
|
|
86
174
|
|
|
@@ -102,7 +190,7 @@ class Watch {
|
|
|
102
190
|
|
|
103
191
|
if (!once) {
|
|
104
192
|
// There may be new files.
|
|
105
|
-
this.update(br)
|
|
193
|
+
await this.update(br)
|
|
106
194
|
}
|
|
107
195
|
}
|
|
108
196
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/model",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"main": "dist/model.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/model.d.ts",
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@voxgig/util": "^0.0.3",
|
|
48
48
|
"aontu": "0.22.0",
|
|
49
|
-
"chokidar": "
|
|
49
|
+
"chokidar": "4.0.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@types/jest": "^29.5.
|
|
53
|
-
"@types/node": "22.5.
|
|
52
|
+
"@types/jest": "^29.5.13",
|
|
53
|
+
"@types/node": "22.5.5",
|
|
54
54
|
"es-jest": "^2.1.0",
|
|
55
|
-
"esbuild": "^0.
|
|
55
|
+
"esbuild": "^0.24.0",
|
|
56
56
|
"esbuild-jest": "^0.5.0",
|
|
57
57
|
"jest": "^29.7.0",
|
|
58
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.6.2"
|
|
59
59
|
}
|
|
60
60
|
}
|