@ms-cloudpack/cli 0.8.1 → 0.10.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/CHANGELOG.json +70 -1
- package/CHANGELOG.md +26 -2
- package/lib/commands/start/TaskRunner.d.ts +4 -19
- package/lib/commands/start/TaskRunner.js +38 -35
- package/lib/commands/start/TaskRunner.js.map +1 -1
- package/lib/commands/start/createBundleTask.d.ts +3 -0
- package/lib/commands/start/createBundleTask.js +65 -0
- package/lib/commands/start/createBundleTask.js.map +1 -0
- package/lib/commands/start/startApiServer.d.ts +1 -49
- package/lib/commands/start/startApiServer.js +63 -52
- package/lib/commands/start/startApiServer.js.map +1 -1
- package/lib/commands/start/startAppServer.d.ts +1 -3
- package/lib/commands/start/startAppServer.js.map +1 -1
- package/lib/commands/start/startBundleServer.d.ts +1 -7
- package/lib/commands/start/startBundleServer.js +22 -137
- package/lib/commands/start/startBundleServer.js.map +1 -1
- package/lib/commands/start/startWatcher.d.ts +4 -0
- package/lib/commands/start/startWatcher.js +52 -0
- package/lib/commands/start/startWatcher.js.map +1 -0
- package/lib/commands/start/taskRunner.test.js +28 -8
- package/lib/commands/start/taskRunner.test.js.map +1 -1
- package/lib/commands/start/types.d.ts +76 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +3 -4
- package/lib/commands/start/bundleTask.d.ts +0 -16
- package/lib/commands/start/bundleTask.js +0 -32
- package/lib/commands/start/bundleTask.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,76 @@
|
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Tue, 20 Sep 2022 08:13:37 GMT",
|
|
6
|
+
"tag": "@ms-cloudpack/cli_v0.10.0",
|
|
7
|
+
"version": "0.10.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "dake.3601@gmail.com",
|
|
12
|
+
"package": "@ms-cloudpack/cli",
|
|
13
|
+
"commit": "d5ebdee5d00d56b153b4de0851665cb02189694a",
|
|
14
|
+
"comment": "Only one watcher per bundle task"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"minor": [
|
|
18
|
+
{
|
|
19
|
+
"author": "dake.3601@gmail.com",
|
|
20
|
+
"package": "@ms-cloudpack/cli",
|
|
21
|
+
"commit": "bc64187802ecacd4098c99cdf308aa6bd2fc6f7f",
|
|
22
|
+
"comment": "Improved task watcher and data flow"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"none": [
|
|
26
|
+
{
|
|
27
|
+
"author": "elcraig@microsoft.com",
|
|
28
|
+
"package": "@ms-cloudpack/cli",
|
|
29
|
+
"commit": "52b4314b694af37388821ff5b8a3b16f61b8dc8f",
|
|
30
|
+
"comment": "Hoist commonly used devDependencies to the repo root"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"date": "Tue, 13 Sep 2022 08:15:44 GMT",
|
|
37
|
+
"tag": "@ms-cloudpack/cli_v0.9.0",
|
|
38
|
+
"version": "0.9.0",
|
|
39
|
+
"comments": {
|
|
40
|
+
"minor": [
|
|
41
|
+
{
|
|
42
|
+
"author": "dake.3601@gmail.com",
|
|
43
|
+
"package": "@ms-cloudpack/cli",
|
|
44
|
+
"commit": "895b402c3959e689ae8d7fb9c1ee8a56711b8958",
|
|
45
|
+
"comment": "Rerun flag on add method of Task Runner"
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
"patch": [
|
|
49
|
+
{
|
|
50
|
+
"author": "renovate@whitesourcesoftware.com",
|
|
51
|
+
"package": "@ms-cloudpack/cli",
|
|
52
|
+
"commit": "42d8d8353be2893774225fbe2130dd934188c70f",
|
|
53
|
+
"comment": "Update dependency uuid to v9"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"date": "Mon, 12 Sep 2022 08:13:33 GMT",
|
|
60
|
+
"tag": "@ms-cloudpack/cli_v0.8.1",
|
|
61
|
+
"version": "0.8.1",
|
|
62
|
+
"comments": {
|
|
63
|
+
"none": [
|
|
64
|
+
{
|
|
65
|
+
"author": "renovate@whitesourcesoftware.com",
|
|
66
|
+
"package": "@ms-cloudpack/cli",
|
|
67
|
+
"commit": "1ec5df995e0c7e2b037d329293c2da25e2be6527",
|
|
68
|
+
"comment": "Update devDependency @types/glob to v8"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"date": "Fri, 09 Sep 2022 08:15:19 GMT",
|
|
6
75
|
"tag": "@ms-cloudpack/cli_v0.8.1",
|
|
7
76
|
"version": "0.8.1",
|
|
8
77
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
# Change Log - @ms-cloudpack/cli
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 20 Sep 2022 08:13:37 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.10.0
|
|
8
|
+
|
|
9
|
+
Tue, 20 Sep 2022 08:13:37 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Improved task watcher and data flow (dake.3601@gmail.com)
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Only one watcher per bundle task (dake.3601@gmail.com)
|
|
18
|
+
|
|
19
|
+
## 0.9.0
|
|
20
|
+
|
|
21
|
+
Tue, 13 Sep 2022 08:15:44 GMT
|
|
22
|
+
|
|
23
|
+
### Minor changes
|
|
24
|
+
|
|
25
|
+
- Rerun flag on add method of Task Runner (dake.3601@gmail.com)
|
|
26
|
+
|
|
27
|
+
### Patches
|
|
28
|
+
|
|
29
|
+
- Update dependency uuid to v9 (renovate@whitesourcesoftware.com)
|
|
30
|
+
|
|
7
31
|
## 0.8.1
|
|
8
32
|
|
|
9
|
-
Fri, 09 Sep 2022 08:15:
|
|
33
|
+
Fri, 09 Sep 2022 08:15:19 GMT
|
|
10
34
|
|
|
11
35
|
### Patches
|
|
12
36
|
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
name: string;
|
|
3
|
-
id: string;
|
|
4
|
-
execute: () => Promise<TReturn>;
|
|
5
|
-
}
|
|
1
|
+
import type { Task, TaskOptions } from './types.js';
|
|
6
2
|
/**
|
|
7
3
|
* TaskRunner class manages the state of Tasks.
|
|
8
4
|
* This class is to be called by the api server.
|
|
@@ -11,24 +7,13 @@ export declare class TaskRunner {
|
|
|
11
7
|
private _queue;
|
|
12
8
|
private _pendingTasks;
|
|
13
9
|
private _completedTasks;
|
|
10
|
+
private _requiresRerun;
|
|
14
11
|
constructor();
|
|
15
12
|
/**
|
|
16
13
|
* The add method enqueues a Task and returns its Promise.
|
|
17
14
|
* If a Task with the same id has already been processed,
|
|
18
15
|
* it returns either the result or the promise.
|
|
16
|
+
* Rerun flag forces the Task to be run again.
|
|
19
17
|
*/
|
|
20
|
-
add<TReturn>(task: Task<TReturn
|
|
21
|
-
/**
|
|
22
|
-
* Returns result from completed Task with id.
|
|
23
|
-
* TODO: rename to getResult?
|
|
24
|
-
*/
|
|
25
|
-
get<TReturn>(id: string): TReturn | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Returns if Task with id is pending.
|
|
28
|
-
*/
|
|
29
|
-
pending<TReturn>(id: string): Promise<TReturn> | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* Deletes Task with id.
|
|
32
|
-
*/
|
|
33
|
-
delete(id: string): void;
|
|
18
|
+
add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn>;
|
|
34
19
|
}
|
|
@@ -11,62 +11,65 @@ export class TaskRunner {
|
|
|
11
11
|
this._queue = new PQueue({ concurrency: 10 });
|
|
12
12
|
this._pendingTasks = new Map();
|
|
13
13
|
this._completedTasks = new Map();
|
|
14
|
+
this._requiresRerun = new Set();
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* The add method enqueues a Task and returns its Promise.
|
|
17
18
|
* If a Task with the same id has already been processed,
|
|
18
19
|
* it returns either the result or the promise.
|
|
20
|
+
* Rerun flag forces the Task to be run again.
|
|
19
21
|
*/
|
|
20
|
-
add(task) {
|
|
22
|
+
add(task, options) {
|
|
21
23
|
const { name, id, execute } = task;
|
|
24
|
+
const { rerun } = options || {};
|
|
22
25
|
// Check if we are already completed the task with that id.
|
|
23
26
|
const action = this._completedTasks.get(id);
|
|
24
|
-
if (action !== undefined) {
|
|
27
|
+
if (action !== undefined && !rerun) {
|
|
25
28
|
log(`Previous action found, returning: "${name}:${id}"`);
|
|
26
29
|
return Promise.resolve(action);
|
|
27
30
|
}
|
|
28
31
|
// Check if we are already running the task with that id.
|
|
29
32
|
const pending = this._pendingTasks.get(id);
|
|
30
33
|
if (pending !== undefined) {
|
|
34
|
+
if (rerun) {
|
|
35
|
+
this._requiresRerun.add(id);
|
|
36
|
+
}
|
|
31
37
|
log(`Previous action found, waiting: "${name}:${id}"`);
|
|
32
38
|
return pending;
|
|
33
39
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const resultPromise = (async () => {
|
|
41
|
+
let taskResult;
|
|
42
|
+
let taskError;
|
|
43
|
+
let completed = false;
|
|
44
|
+
do {
|
|
45
|
+
// Delete from rerun list (if present).
|
|
46
|
+
this._requiresRerun.delete(id);
|
|
47
|
+
try {
|
|
48
|
+
taskResult = await this._queue.add(execute);
|
|
49
|
+
completed = true;
|
|
50
|
+
// If an existing bundle was created, dispose.
|
|
51
|
+
// this._createdTasks.get(id)?.dispose?.();
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
// Save the error--it will be thrown later if a rerun was not requested.
|
|
55
|
+
taskError = err;
|
|
56
|
+
}
|
|
57
|
+
} while (this._requiresRerun.has(id));
|
|
58
|
+
log(`Task finished: "${name}:${id}"`);
|
|
59
|
+
// Delete from pending list.
|
|
47
60
|
this._pendingTasks.delete(id);
|
|
48
|
-
|
|
61
|
+
if (completed) {
|
|
62
|
+
// Update finished Tasks.
|
|
63
|
+
this._completedTasks.set(id, taskResult);
|
|
64
|
+
// Resolve the promise.
|
|
65
|
+
return taskResult;
|
|
66
|
+
}
|
|
67
|
+
// If the task never completed successfully, throw the error from earlier.
|
|
68
|
+
throw taskError;
|
|
69
|
+
})();
|
|
49
70
|
this._pendingTasks.set(id, resultPromise);
|
|
50
|
-
return resultPromise;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Returns result from completed Task with id.
|
|
54
|
-
* TODO: rename to getResult?
|
|
55
|
-
*/
|
|
56
|
-
get(id) {
|
|
57
|
-
return this._completedTasks.get(id);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Returns if Task with id is pending.
|
|
61
|
-
*/
|
|
62
|
-
pending(id) {
|
|
63
|
-
return this._pendingTasks.get(id);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Deletes Task with id.
|
|
67
|
-
*/
|
|
68
|
-
delete(id) {
|
|
69
71
|
this._completedTasks.delete(id);
|
|
72
|
+
return resultPromise;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
//# sourceMappingURL=TaskRunner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../../src/commands/start/TaskRunner.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":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equest, BundleTaskOptions, Task } from './types.js';
|
|
2
|
+
export declare function bundle(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest>;
|
|
3
|
+
export declare function createBundleTask(bundleRequest: BundleRequest, options?: BundleTaskOptions): Task<BundleRequest>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { bundlePackage } from '@ms-cloudpack/bundler';
|
|
2
|
+
import { readJson, writeJson } from '@ms-cloudpack/json-utilities';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fsExtra from 'fs-extra';
|
|
5
|
+
const { ensureDir } = fsExtra;
|
|
6
|
+
const log = (...messages) => {
|
|
7
|
+
console.log(`BundleTask:`, ...messages);
|
|
8
|
+
};
|
|
9
|
+
export async function bundle(bundleRequest, force) {
|
|
10
|
+
const { packagePath, outputPath, isExternal } = bundleRequest;
|
|
11
|
+
// Rehydrate the result if not incremental.
|
|
12
|
+
if (isExternal && !force) {
|
|
13
|
+
bundleRequest.result = await readJson(path.join(outputPath, 'result.json'));
|
|
14
|
+
}
|
|
15
|
+
const isCacheUsable = bundleRequest.result?.errors?.length === 0;
|
|
16
|
+
// Only use cached result if it's successful.
|
|
17
|
+
if (!isCacheUsable) {
|
|
18
|
+
bundleRequest.result = await bundlePackage({
|
|
19
|
+
packagePath,
|
|
20
|
+
outputPath,
|
|
21
|
+
outputType: 'library',
|
|
22
|
+
incremental: !isExternal,
|
|
23
|
+
});
|
|
24
|
+
// Write the result to disk.
|
|
25
|
+
if (isExternal) {
|
|
26
|
+
await writeJson(path.join(outputPath, 'result.json'), bundleRequest.result);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
log(`Bundle cached, returning: "${bundleRequest.packageName}@${bundleRequest.version}"`);
|
|
31
|
+
}
|
|
32
|
+
return bundleRequest;
|
|
33
|
+
}
|
|
34
|
+
export function createBundleTask(bundleRequest, options) {
|
|
35
|
+
const { id, packageName, version, outputPath, packagePath } = bundleRequest;
|
|
36
|
+
const { force, rebuild } = options || {};
|
|
37
|
+
return {
|
|
38
|
+
name: `Bundle ${packageName}@${version}`,
|
|
39
|
+
id,
|
|
40
|
+
async execute() {
|
|
41
|
+
let bundleResult = bundleRequest;
|
|
42
|
+
await ensureDir(outputPath);
|
|
43
|
+
log(`Finished ensureDir: "${packageName}@${version}"`);
|
|
44
|
+
if (rebuild && bundleRequest.result?.rebuild) {
|
|
45
|
+
bundleResult.result = await bundleRequest.result.rebuild();
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
bundleResult = await bundle(bundleRequest, force);
|
|
49
|
+
}
|
|
50
|
+
return bundleResult;
|
|
51
|
+
},
|
|
52
|
+
getStartDescription: () => ({
|
|
53
|
+
id,
|
|
54
|
+
name: `Bundle ${packageName}@${version}`,
|
|
55
|
+
inputPath: packagePath || '',
|
|
56
|
+
outputPath,
|
|
57
|
+
}),
|
|
58
|
+
getEndDescription: (taskResult) => ({
|
|
59
|
+
id,
|
|
60
|
+
errors: taskResult?.result?.errors,
|
|
61
|
+
warnings: taskResult?.result?.warnings,
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=createBundleTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../../src/commands/start/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,UAAU,CAAC;AAE/B,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;AAE9B,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;AAE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M,SAAS,CAAC,UAAU,CAAC,CAAC;YAE5B,GAAG,CAAC,wBAAwB,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC;YAEvD,IAAI,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE;gBAC5C,YAAY,CAAC,MAAM,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;aAC5D;iBAAM;gBACL,YAAY,GAAG,MAAM,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;aACnD;YAED,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1B,EAAE;YACF,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,EAAE;YACxC,SAAS,EAAE,WAAW,IAAI,EAAE;YAC5B,UAAU;SACX,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAChC,CAAC;YACC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;SAChB,CAAA;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import type { Session } from './types.js';
|
|
2
|
-
import { type Task } from './TaskRunner.js';
|
|
3
|
-
export interface SessionStats {
|
|
4
|
-
status: 'idle' | 'pending';
|
|
5
|
-
remainingTasks: number;
|
|
6
|
-
totalTasks: number;
|
|
7
|
-
totalErrors: number;
|
|
8
|
-
totalWarnings: number;
|
|
9
|
-
}
|
|
10
|
-
export interface ApiServer {
|
|
11
|
-
url: string;
|
|
12
|
-
port: number;
|
|
13
|
-
notifyReload: () => void;
|
|
14
|
-
reportStart: (options: TaskStartDescription) => void;
|
|
15
|
-
reportEnd: (options: TaskEndDescription) => void;
|
|
16
|
-
addTask: <TReturn>(task: Task<TReturn>) => Promise<TReturn>;
|
|
17
|
-
/**
|
|
18
|
-
* Gets the result of a completed task.
|
|
19
|
-
*/
|
|
20
|
-
getTask: <TReturn>(id: string) => TReturn | undefined;
|
|
21
|
-
pendingTask: <TReturn>(id: string) => Promise<TReturn> | undefined;
|
|
22
|
-
deleteTask: (id: string) => void;
|
|
23
|
-
close: () => Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
export interface TaskError {
|
|
26
|
-
message: string;
|
|
27
|
-
pluginName: string;
|
|
28
|
-
stack: string;
|
|
29
|
-
fileLocation: string;
|
|
30
|
-
lineNumber: number;
|
|
31
|
-
columnNumber: number;
|
|
32
|
-
}
|
|
33
|
-
export interface TaskStartDescription {
|
|
34
|
-
id: string;
|
|
35
|
-
name: string;
|
|
36
|
-
inputPath: string;
|
|
37
|
-
outputPath: string;
|
|
38
|
-
}
|
|
39
|
-
export interface TaskEndDescription {
|
|
40
|
-
id: string;
|
|
41
|
-
errors?: TaskError[];
|
|
42
|
-
warnings?: TaskError[];
|
|
43
|
-
}
|
|
44
|
-
export interface TaskDescription extends TaskStartDescription, TaskEndDescription {
|
|
45
|
-
status: 'pending' | 'complete';
|
|
46
|
-
startTime: number;
|
|
47
|
-
durationMilliseconds?: number;
|
|
48
|
-
lastUpdated?: number;
|
|
49
|
-
}
|
|
1
|
+
import type { ApiServer, Session } from './types.js';
|
|
50
2
|
/**
|
|
51
3
|
* The api server handles the data pub/sub (for things like reporting build status)
|
|
52
4
|
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
@@ -31,6 +31,47 @@ export async function startApiServer({ session }) {
|
|
|
31
31
|
};
|
|
32
32
|
const allTasks = new Map();
|
|
33
33
|
const taskRunner = new TaskRunner();
|
|
34
|
+
function reportStart(taskStart) {
|
|
35
|
+
const previousResult = allTasks.get(taskStart.id);
|
|
36
|
+
const now = new Date().getTime();
|
|
37
|
+
if (!previousResult) {
|
|
38
|
+
sessionStats.totalTasks++;
|
|
39
|
+
}
|
|
40
|
+
if (previousResult?.status === 'complete') {
|
|
41
|
+
sessionStats.totalErrors -= previousResult.errors?.length || 0;
|
|
42
|
+
sessionStats.totalWarnings -= previousResult.warnings?.length || 0;
|
|
43
|
+
}
|
|
44
|
+
sessionStats.remainingTasks++;
|
|
45
|
+
sessionStats.status = 'pending';
|
|
46
|
+
allTasks.set(taskStart.id, {
|
|
47
|
+
...taskStart,
|
|
48
|
+
status: 'pending',
|
|
49
|
+
startTime: now,
|
|
50
|
+
});
|
|
51
|
+
bus.publish([session.id, 'status'], sessionStats);
|
|
52
|
+
bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });
|
|
53
|
+
}
|
|
54
|
+
function reportEnd(taskEnd) {
|
|
55
|
+
const previousResult = allTasks.get(taskEnd.id);
|
|
56
|
+
const now = new Date().getTime();
|
|
57
|
+
if (previousResult) {
|
|
58
|
+
sessionStats.remainingTasks--;
|
|
59
|
+
sessionStats.totalErrors += taskEnd.errors?.length || 0;
|
|
60
|
+
sessionStats.totalWarnings += taskEnd.warnings?.length || 0;
|
|
61
|
+
allTasks.set(taskEnd.id, {
|
|
62
|
+
...previousResult,
|
|
63
|
+
...taskEnd,
|
|
64
|
+
status: 'complete',
|
|
65
|
+
durationMilliseconds: now - previousResult.startTime,
|
|
66
|
+
lastUpdated: now,
|
|
67
|
+
});
|
|
68
|
+
if (sessionStats.remainingTasks === 0) {
|
|
69
|
+
sessionStats.status = 'idle';
|
|
70
|
+
}
|
|
71
|
+
bus.publish([session.id, 'status'], sessionStats);
|
|
72
|
+
bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
34
75
|
bus.publish([session.id, 'status'], sessionStats);
|
|
35
76
|
// Create a websocket server which listens for subscriptions and verb requests,
|
|
36
77
|
// and broadcasts the data to all connected clients.
|
|
@@ -109,58 +150,28 @@ export async function startApiServer({ session }) {
|
|
|
109
150
|
}
|
|
110
151
|
});
|
|
111
152
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const now = new Date().getTime();
|
|
135
|
-
if (previousResult) {
|
|
136
|
-
sessionStats.remainingTasks--;
|
|
137
|
-
sessionStats.totalErrors += end.errors?.length || 0;
|
|
138
|
-
sessionStats.totalWarnings += end.warnings?.length || 0;
|
|
139
|
-
allTasks.set(end.id, {
|
|
140
|
-
...previousResult,
|
|
141
|
-
...end,
|
|
142
|
-
status: 'complete',
|
|
143
|
-
durationMilliseconds: now - previousResult.startTime,
|
|
144
|
-
lastUpdated: now,
|
|
145
|
-
});
|
|
146
|
-
if (sessionStats.remainingTasks === 0) {
|
|
147
|
-
sessionStats.status = 'idle';
|
|
148
|
-
}
|
|
149
|
-
bus.publish([session.id, 'status'], sessionStats);
|
|
150
|
-
bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
addTask: (task) => {
|
|
154
|
-
return taskRunner.add(task);
|
|
155
|
-
},
|
|
156
|
-
getTask: (id) => {
|
|
157
|
-
return taskRunner.get(id);
|
|
158
|
-
},
|
|
159
|
-
pendingTask: (id) => {
|
|
160
|
-
return taskRunner.pending(id);
|
|
161
|
-
},
|
|
162
|
-
deleteTask: (id) => {
|
|
163
|
-
taskRunner.delete(id);
|
|
153
|
+
addTask: (task, options) => {
|
|
154
|
+
return taskRunner.add({
|
|
155
|
+
...task,
|
|
156
|
+
execute: async () => {
|
|
157
|
+
reportStart({
|
|
158
|
+
...task.getStartDescription?.(),
|
|
159
|
+
id: task.id,
|
|
160
|
+
});
|
|
161
|
+
let taskResult;
|
|
162
|
+
try {
|
|
163
|
+
taskResult = await task.execute();
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
// no-op
|
|
167
|
+
}
|
|
168
|
+
reportEnd({
|
|
169
|
+
...task.getEndDescription?.(taskResult),
|
|
170
|
+
id: task.id,
|
|
171
|
+
});
|
|
172
|
+
return taskResult;
|
|
173
|
+
},
|
|
174
|
+
}, options);
|
|
164
175
|
},
|
|
165
176
|
close: () => new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
|
|
166
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../../../src/commands/start/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"startApiServer.js","sourceRoot":"","sources":["../../../src/commands/start/startApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,OAAO,MAAM,UAAU,CAAC;AAC/B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAU7C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EAAE,OAAO,EAAwB;IACpE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,aAAa,EAAE,CAAC;IAC5B,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AE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;KAC5G,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Session } from './types.js';
|
|
2
|
-
import type { ApiServer } from './startApiServer.js';
|
|
3
|
-
import type { BundleServer } from './startBundleServer.js';
|
|
1
|
+
import type { ApiServer, BundleServer, Session } from './types.js';
|
|
4
2
|
/**
|
|
5
3
|
* The app server hosts the appropriate routes for the web app, primarily returning html content
|
|
6
4
|
* which loads resources from the bundle server.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startAppServer.js","sourceRoot":"","sources":["../../../src/commands/start/startAppServer.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAkB,MAAM,iCAAiC,CAAC;AACtG,OAAO,EAAE,gBAAgB,EAA+B,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"startAppServer.js","sourceRoot":"","sources":["../../../src/commands/start/startAppServer.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAkB,MAAM,iCAAiC,CAAC;AACtG,OAAO,EAAE,gBAAgB,EAA+B,MAAM,kCAAkC,CAAC;AAGjG,6DAA6D;AAC7D,MAAM,GAAG,GAAG,CAAC,QAAiB,EAAE,EAAE;IAChC,6CAA6C;AAC/C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CA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AAiB;QACjB,QAAQ;QACR,QAAQ;QACR,UAAU,KAAK,UAAU;QACzB,4BAA4B,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,WAAW;QACzE,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,8BAA8B,SAAS,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QACtG,SAAS;QACT,QAAQ;QACR,uBAAuB;QACvB,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,8BAA8B,SAAS,mBAAmB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;QAC5G,SAAS;QACT,SAAS;KACV,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import type { Session } from './types.js';
|
|
2
|
-
import type { ApiServer } from './startApiServer.js';
|
|
3
|
-
export interface BundleServer {
|
|
4
|
-
url: string;
|
|
5
|
-
port: number;
|
|
6
|
-
close: () => Promise<void>;
|
|
7
|
-
}
|
|
1
|
+
import type { ApiServer, BundleServer, Session } from './types.js';
|
|
8
2
|
/**
|
|
9
3
|
* The bundle server handles package requests and returns bundled resources.
|
|
10
4
|
* Resources are bundled on demand and cached locally to avoid re-bundling
|
|
@@ -2,14 +2,12 @@ import { createExpressApp } from '@ms-cloudpack/create-express-app';
|
|
|
2
2
|
import { isExternalPackage } from '@ms-cloudpack/package-utilities';
|
|
3
3
|
import { isFolder, slash } from '@ms-cloudpack/path-utilities';
|
|
4
4
|
import filenamify from 'filenamify';
|
|
5
|
-
import fsExtra from 'fs-extra';
|
|
6
5
|
import hash from 'object-hash';
|
|
7
6
|
import os from 'os';
|
|
8
7
|
import path from 'path';
|
|
9
8
|
import { parseRequestInfo } from './parseRequestInfo.js';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
const { ensureDir } = fsExtra;
|
|
9
|
+
import { createBundleTask } from './createBundleTask.js';
|
|
10
|
+
import { startWatcher } from './startWatcher.js';
|
|
13
11
|
// const bundleLookupPath = path.join(os.tmpdir(), 'cloudpack-output', 'all-bundles.json');
|
|
14
12
|
const log = (...messages) => {
|
|
15
13
|
console.log(`BundleServer:`, ...messages);
|
|
@@ -23,10 +21,11 @@ const error = (...messages) => {
|
|
|
23
21
|
* on each request.
|
|
24
22
|
*/
|
|
25
23
|
export async function startBundleServer({ session, apiServer, }) {
|
|
24
|
+
const watcher = startWatcher(apiServer);
|
|
26
25
|
const { server, port } = await createExpressApp([5500, 5501, 5502, 5503], (app) => {
|
|
27
26
|
// Set up the express app routes.
|
|
28
27
|
app.get('*', (req, res) => {
|
|
29
|
-
handleRequest(req, res, session, apiServer).catch((err) => {
|
|
28
|
+
handleRequest(req, res, session, apiServer, watcher).catch((err) => {
|
|
30
29
|
error(err?.stack || err);
|
|
31
30
|
res.status(500).send(`Error bundling: ${err}`);
|
|
32
31
|
});
|
|
@@ -40,7 +39,7 @@ export async function startBundleServer({ session, apiServer, }) {
|
|
|
40
39
|
url,
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
|
-
async function handleRequest(req, res, session, apiServer) {
|
|
42
|
+
async function handleRequest(req, res, session, apiServer, watcher) {
|
|
44
43
|
const { resolveMap } = session;
|
|
45
44
|
const requestPath = slash(req.path.substring(1));
|
|
46
45
|
const { packageName, version, filePath } = parseRequestInfo(requestPath);
|
|
@@ -83,74 +82,23 @@ async function handleRequest(req, res, session, apiServer) {
|
|
|
83
82
|
// Derive where the output should be.
|
|
84
83
|
const outputPath = path.join(os.tmpdir(), 'cloudpack-output', `${filenamify(packageName)}-${version}-${bundleId}`);
|
|
85
84
|
// Set up for bundling.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
apiServer.reportStart({
|
|
104
|
-
id: bundleId,
|
|
105
|
-
name: `Bundle ${packageName}@${version}`,
|
|
106
|
-
inputPath: packagePath || '',
|
|
107
|
-
outputPath,
|
|
108
|
-
});
|
|
109
|
-
try {
|
|
110
|
-
log(`No previous action found, bundling: "${packageName}@${version}"`);
|
|
111
|
-
await ensureDir(outputPath);
|
|
112
|
-
log(`Finished ensureDir: "${packageName}@${version}"`);
|
|
113
|
-
log(`Trying to bundle "${packageName}@${version}"`);
|
|
114
|
-
if (restart) {
|
|
115
|
-
// TODO: Implement apiServer.restart
|
|
116
|
-
apiServer.deleteTask(bundleId);
|
|
117
|
-
}
|
|
118
|
-
await apiServer.addTask({
|
|
119
|
-
name: `Bundle ${packageName}@${version}`,
|
|
120
|
-
id: bundleId,
|
|
121
|
-
execute: () => bundleTask(bundleRequest, force),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
catch (_) {
|
|
125
|
-
/* no-op */
|
|
126
|
-
}
|
|
127
|
-
// TODO: if moved to a function, this would be the return value
|
|
128
|
-
action = bundleRequest;
|
|
129
|
-
// TODO: errors and warnings typings don't match up. We need to reconcile.
|
|
130
|
-
apiServer.reportEnd({
|
|
131
|
-
id: bundleId,
|
|
132
|
-
errors: bundleRequest.result?.errors,
|
|
133
|
-
warnings: bundleRequest.result?.warnings,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else if (pendingBundle) {
|
|
137
|
-
log(`Previous action found, waiting: "${packageName}@${version}${filePath}"`);
|
|
138
|
-
action = await pendingBundle;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
log(`Bundle cached, returning: "${packageName}@${version}${filePath}"`);
|
|
142
|
-
}
|
|
143
|
-
if (!action) {
|
|
144
|
-
res.status(500).send(`Result not found for "${bundleId}". This is likely a bug with cloudpack.`);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
// If this is a pre-built local package we haven't set up for incremental builds, set it up.
|
|
148
|
-
if (!isExternal && !action.dispose) {
|
|
149
|
-
initializeFileWatcher(bundleId, outputPath, action, apiServer);
|
|
150
|
-
}
|
|
151
|
-
// At this point we should have an action completed.
|
|
152
|
-
if ((action.result?.errors?.length || 0) > 0) {
|
|
153
|
-
res.status(500).type('json').send(action);
|
|
85
|
+
const rerun = !isFolder(outputPath) || force;
|
|
86
|
+
const taskResult = {
|
|
87
|
+
id: bundleId,
|
|
88
|
+
packageName,
|
|
89
|
+
version,
|
|
90
|
+
packagePath,
|
|
91
|
+
outputPath,
|
|
92
|
+
isExternal,
|
|
93
|
+
};
|
|
94
|
+
log(`Trying to bundle "${packageName}@${version}"`);
|
|
95
|
+
const bundleTask = createBundleTask(taskResult, { force });
|
|
96
|
+
await apiServer.addTask(bundleTask, { rerun });
|
|
97
|
+
// Set up the task's watcher
|
|
98
|
+
watcher.watch(taskResult);
|
|
99
|
+
// At this point we should have a Task completed.
|
|
100
|
+
if ((taskResult.result?.errors?.length || 0) > 0) {
|
|
101
|
+
res.status(500).type('json').send(taskResult);
|
|
154
102
|
}
|
|
155
103
|
else {
|
|
156
104
|
log(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
@@ -161,67 +109,4 @@ async function handleRequest(req, res, session, apiServer) {
|
|
|
161
109
|
res.sendFile(path.join(outputPath, filePath));
|
|
162
110
|
}
|
|
163
111
|
}
|
|
164
|
-
function initializeFileWatcher(bundleId, outputPath, bundleRequest, apiServer) {
|
|
165
|
-
const { id, packageName, packagePath, version } = bundleRequest;
|
|
166
|
-
let bundleOutput = bundleRequest.result;
|
|
167
|
-
log(`Initializing file watcher for ${packageName}@${version}`);
|
|
168
|
-
// TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.
|
|
169
|
-
const watcher = chokidar.watch(path.join(packagePath, 'src')).on('change', (event) => {
|
|
170
|
-
if (!apiServer.pendingTask(id)) {
|
|
171
|
-
bundleRequest.isRebuildRequired = true;
|
|
172
|
-
log(`Detected change "${event}", rebuilding "${packageName}@${version}"`);
|
|
173
|
-
(async () => {
|
|
174
|
-
do {
|
|
175
|
-
bundleRequest.isRebuildRequired = false;
|
|
176
|
-
log(`[Start] >> Bundling "${packageName}@${version}" to "${outputPath}"`);
|
|
177
|
-
// Start tracking work.
|
|
178
|
-
apiServer.reportStart({
|
|
179
|
-
id: bundleId,
|
|
180
|
-
name: `Rebundle ${packageName}@${version}`,
|
|
181
|
-
inputPath: packagePath,
|
|
182
|
-
outputPath,
|
|
183
|
-
});
|
|
184
|
-
if (!bundleOutput?.rebuild) {
|
|
185
|
-
bundleOutput = (await apiServer.addTask({
|
|
186
|
-
name: `Bundle ${packageName}@${version}`,
|
|
187
|
-
id: bundleId,
|
|
188
|
-
execute: () => bundleTask(bundleRequest),
|
|
189
|
-
})).result;
|
|
190
|
-
}
|
|
191
|
-
else if (bundleOutput?.rebuild) {
|
|
192
|
-
bundleOutput = await bundleOutput.rebuild();
|
|
193
|
-
}
|
|
194
|
-
// TODO: Fix typings
|
|
195
|
-
apiServer.reportEnd({
|
|
196
|
-
id: bundleId,
|
|
197
|
-
errors: bundleOutput?.errors,
|
|
198
|
-
warnings: bundleOutput?.warnings,
|
|
199
|
-
});
|
|
200
|
-
log(`[ End ] << Bundled "${packageName}@${version}" (${bundleOutput?.outputFiles?.length || 0} file(s), ${bundleOutput?.errors?.length || 0} errors)`);
|
|
201
|
-
} while (bundleRequest.isRebuildRequired);
|
|
202
|
-
if (!bundleOutput?.errors?.length) {
|
|
203
|
-
log(`Notifying rebuild: ${packageName}@${version}`);
|
|
204
|
-
apiServer.notifyReload();
|
|
205
|
-
}
|
|
206
|
-
})().catch((err) => {
|
|
207
|
-
error(`Error rebuilding "${packageName}@${version}":`, err?.stack || err);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
// A change was made while we were bundling. We need to wait for the current
|
|
212
|
-
// bundle to finish before we can rebuild.
|
|
213
|
-
bundleRequest.isRebuildRequired = true;
|
|
214
|
-
log(`Detected change "${event}", already waiting for "${packageName}@${version}"`);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
bundleRequest.dispose = async () => {
|
|
218
|
-
try {
|
|
219
|
-
await watcher.close();
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
// ignore
|
|
223
|
-
}
|
|
224
|
-
bundleOutput?.dispose?.();
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
112
|
//# sourceMappingURL=startBundleServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAm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KACX,CAAC;IAEF,GAAG,CAAC,qBAAqB,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC;IACpD,MAAM,UAAU,GAAwB,gBAAgB,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAChF,MAAM,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/C,4BAA4B;IAC5B,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE1B,iDAAiD;IACjD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE;QAChD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KAC/C;SAAM;QACL,GAAG,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAChE,4BAA4B;QAC5B,IAAI,UAAU,EAAE;YACd,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC/C;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import chokidar from 'chokidar';
|
|
3
|
+
import { createBundleTask } from './createBundleTask.js';
|
|
4
|
+
const log = (...messages) => {
|
|
5
|
+
console.log(`BundleWatcher:`, ...messages);
|
|
6
|
+
};
|
|
7
|
+
const error = (...messages) => {
|
|
8
|
+
console.error(`BundleWatcher:`, ...messages);
|
|
9
|
+
};
|
|
10
|
+
export function startWatcher(apiServer) {
|
|
11
|
+
const watched = new Set();
|
|
12
|
+
return {
|
|
13
|
+
watch: (bundleRequest) => {
|
|
14
|
+
// Have a single watcher per bundle request.
|
|
15
|
+
if (watched.has(bundleRequest.id)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
watched.add(bundleRequest.id);
|
|
19
|
+
const { packageName, version, packagePath, outputPath } = bundleRequest;
|
|
20
|
+
log(`Initializing file watcher for ${packageName}@${version}`);
|
|
21
|
+
// TODO: This is a bit of a hack. We should be able to use the watch API, but it doesn't seem to work.
|
|
22
|
+
const watcher = chokidar.watch(path.join(packagePath, 'src')).on('change', async (event) => {
|
|
23
|
+
log(`Detected change "${event}", rebuilding "${packageName}@${version}"`);
|
|
24
|
+
log(`[Start] >> Bundling "${packageName}@${version}" to "${outputPath}"`);
|
|
25
|
+
// Start tracking work.
|
|
26
|
+
try {
|
|
27
|
+
bundleRequest.result = (await apiServer.addTask(createBundleTask(bundleRequest, { rebuild: true }), { rerun: true })).result;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// TODO: Handle errors.
|
|
31
|
+
error(`Error rebuilding "${packageName}@${version}":`, err?.stack || err);
|
|
32
|
+
}
|
|
33
|
+
log(`[ End ] << Bundled "${packageName}@${version}" (${bundleRequest.result?.outputFiles?.length || 0} file(s), ${bundleRequest.result?.errors?.length || 0} errors)`);
|
|
34
|
+
if (!bundleRequest.result?.errors?.length) {
|
|
35
|
+
log(`Notifying rebuild: ${packageName}@${version}`);
|
|
36
|
+
apiServer.notifyReload();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
bundleRequest.dispose = async () => {
|
|
40
|
+
try {
|
|
41
|
+
await watcher.close();
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// ignore
|
|
45
|
+
}
|
|
46
|
+
watched.delete(bundleRequest.id);
|
|
47
|
+
bundleRequest.result?.dispose?.();
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=startWatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startWatcher.js","sourceRoot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
execute: () => new Promise((r) => r('first test value')),
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
name: 'Task 2',
|
|
11
11
|
id: '1',
|
|
12
|
-
execute: () => new Promise((r) => r('
|
|
12
|
+
execute: () => new Promise((r) => r('second test value')),
|
|
13
13
|
},
|
|
14
14
|
];
|
|
15
15
|
describe('addTask', () => {
|
|
16
|
-
it('
|
|
16
|
+
it('resolves the promise', async () => {
|
|
17
17
|
const taskRunner = new TaskRunner();
|
|
18
|
-
expect(await taskRunner.add(tasks[0])).toEqual('test value');
|
|
18
|
+
expect(await taskRunner.add(tasks[0])).toEqual('first test value');
|
|
19
19
|
});
|
|
20
|
-
it('
|
|
20
|
+
it('returns previous completed task with same id', async () => {
|
|
21
21
|
const taskRunner = new TaskRunner();
|
|
22
22
|
await taskRunner.add(tasks[0]);
|
|
23
23
|
// Task Runner should return task with same id
|
|
24
24
|
// since previous task is already completed.
|
|
25
|
-
expect(await taskRunner.add(tasks[1])).toEqual('test value');
|
|
25
|
+
expect(await taskRunner.add(tasks[1])).toEqual('first test value');
|
|
26
26
|
});
|
|
27
|
-
it('
|
|
27
|
+
it('returns previous pending task with same id', async () => {
|
|
28
28
|
const taskRunner = new TaskRunner();
|
|
29
29
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
30
30
|
taskRunner.add(tasks[0]);
|
|
31
31
|
// Even though task[0].excute() and task[1].execute() return different strings,
|
|
32
32
|
// since their tasks share id, the task runner will return the promise of the first.
|
|
33
|
-
expect(await taskRunner.add(tasks[1])).toEqual('test value');
|
|
33
|
+
expect(await taskRunner.add(tasks[1])).toEqual('first test value');
|
|
34
|
+
});
|
|
35
|
+
it('reruns completed tasks when rerun is set', async () => {
|
|
36
|
+
const taskRunner = new TaskRunner();
|
|
37
|
+
await taskRunner.add(tasks[0]);
|
|
38
|
+
// Returns task[1].execute() string as the Task is flagged for rerun.
|
|
39
|
+
expect(await taskRunner.add(tasks[1], { rerun: true })).toEqual('second test value');
|
|
40
|
+
});
|
|
41
|
+
it('reruns pending tasks when rerun is set', async () => {
|
|
42
|
+
const taskRunner = new TaskRunner();
|
|
43
|
+
taskRunner.add(tasks[0]);
|
|
44
|
+
const ret = await taskRunner.add(tasks[1], { rerun: true });
|
|
45
|
+
// Returns task[0].execute() string as the Task reuses the promise.
|
|
46
|
+
expect(ret).toEqual('first test value');
|
|
47
|
+
});
|
|
48
|
+
it('reuses pending promise when rerun is set', async () => {
|
|
49
|
+
const taskRunner = new TaskRunner();
|
|
50
|
+
const firstTask = taskRunner.add(tasks[0]);
|
|
51
|
+
const secondTask = taskRunner.add(tasks[1], { rerun: true });
|
|
52
|
+
expect(firstTask).toEqual(secondTask);
|
|
53
|
+
expect(await firstTask).toEqual(await secondTask);
|
|
34
54
|
});
|
|
35
55
|
});
|
|
36
56
|
//# sourceMappingURL=taskRunner.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taskRunner.test.js","sourceRoot":"","sources":["../../../src/commands/start/taskRunner.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"taskRunner.test.js","sourceRoot":"","sources":["../../../src/commands/start/taskRunner.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,MAAM,KAAK,GAAwB;IACjC;QACE,IAAI,EAAE,QAAQ;QACd,EAAE,EAAE,GAAG;QACP,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;KACjE;IACD;QACE,IAAI,EAAE,QAAQ;QACd,EAAE,EAAE,GAAG;QACP,OAAO,EAAE,GA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
|
2
|
+
import type { BundlerResult } from '@ms-cloudpack/bundler-types';
|
|
2
3
|
export interface Session {
|
|
3
4
|
/**
|
|
4
5
|
* The session id, used for identifying
|
|
@@ -27,3 +28,78 @@ export interface Session {
|
|
|
27
28
|
*/
|
|
28
29
|
resolveMap: ResolveMap;
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Tracks a given bundle request and its result.
|
|
33
|
+
*/
|
|
34
|
+
export interface BundleRequest {
|
|
35
|
+
id: string;
|
|
36
|
+
packageName: string;
|
|
37
|
+
version: string;
|
|
38
|
+
packagePath: string;
|
|
39
|
+
outputPath: string;
|
|
40
|
+
isExternal: boolean;
|
|
41
|
+
result?: BundlerResult;
|
|
42
|
+
isRebuildRequired?: boolean;
|
|
43
|
+
dispose?: () => Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export interface BundleTaskOptions {
|
|
46
|
+
force?: boolean;
|
|
47
|
+
rebuild?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface BundleServer {
|
|
50
|
+
url: string;
|
|
51
|
+
port: number;
|
|
52
|
+
close: () => Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface SessionStats {
|
|
55
|
+
status: 'idle' | 'pending';
|
|
56
|
+
remainingTasks: number;
|
|
57
|
+
totalTasks: number;
|
|
58
|
+
totalErrors: number;
|
|
59
|
+
totalWarnings: number;
|
|
60
|
+
}
|
|
61
|
+
export interface ApiServer {
|
|
62
|
+
url: string;
|
|
63
|
+
port: number;
|
|
64
|
+
notifyReload: () => void;
|
|
65
|
+
addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => Promise<TReturn>;
|
|
66
|
+
close: () => Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export interface Watcher {
|
|
69
|
+
watch: (bundleRequest: BundleRequest) => void;
|
|
70
|
+
}
|
|
71
|
+
export interface TaskError {
|
|
72
|
+
message: string;
|
|
73
|
+
pluginName: string;
|
|
74
|
+
stack: string;
|
|
75
|
+
fileLocation: string;
|
|
76
|
+
lineNumber: number;
|
|
77
|
+
columnNumber: number;
|
|
78
|
+
}
|
|
79
|
+
export interface TaskStartDescription {
|
|
80
|
+
id: string;
|
|
81
|
+
name?: string;
|
|
82
|
+
inputPath?: string;
|
|
83
|
+
outputPath?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface TaskEndDescription {
|
|
86
|
+
id: string;
|
|
87
|
+
errors?: TaskError[];
|
|
88
|
+
warnings?: TaskError[];
|
|
89
|
+
}
|
|
90
|
+
export interface TaskDescription extends TaskStartDescription, TaskEndDescription {
|
|
91
|
+
status: 'pending' | 'complete';
|
|
92
|
+
startTime: number;
|
|
93
|
+
durationMilliseconds?: number;
|
|
94
|
+
lastUpdated?: number;
|
|
95
|
+
}
|
|
96
|
+
export interface Task<TReturn> {
|
|
97
|
+
name: string;
|
|
98
|
+
id: string;
|
|
99
|
+
execute: () => Promise<TReturn | undefined>;
|
|
100
|
+
getStartDescription?: () => TaskStartDescription;
|
|
101
|
+
getEndDescription?: (result: TReturn | undefined) => TaskEndDescription;
|
|
102
|
+
}
|
|
103
|
+
export interface TaskOptions {
|
|
104
|
+
rerun?: boolean;
|
|
105
|
+
}
|
package/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The Cloudpack command line interface - a tool for managing fast inner and outer looping in web apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -31,15 +31,14 @@
|
|
|
31
31
|
"object-hash": "^3.0.0",
|
|
32
32
|
"open": "^8.4.0",
|
|
33
33
|
"p-queue": "^7.3.0",
|
|
34
|
-
"uuid": "^
|
|
34
|
+
"uuid": "^9.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@ms-cloudpack/bundler-types": "*",
|
|
38
38
|
"@ms-cloudpack/eslint-config-base": "*",
|
|
39
39
|
"@ms-cloudpack/scripts": "*",
|
|
40
40
|
"@types/chokidar": "2.1.3",
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/glob": "7.2.0",
|
|
41
|
+
"@types/glob": "8.0.0",
|
|
43
42
|
"@types/object-hash": "2.2.1",
|
|
44
43
|
"@types/uuid": "8.3.4"
|
|
45
44
|
},
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { BundlerResult } from '@ms-cloudpack/bundler-types';
|
|
2
|
-
/**
|
|
3
|
-
* Tracks a given bundle request and its result.
|
|
4
|
-
*/
|
|
5
|
-
export interface BundleRequest {
|
|
6
|
-
id: string;
|
|
7
|
-
packageName: string;
|
|
8
|
-
version: string;
|
|
9
|
-
packagePath: string;
|
|
10
|
-
outputPath: string;
|
|
11
|
-
isExternal: boolean;
|
|
12
|
-
result?: BundlerResult;
|
|
13
|
-
isRebuildRequired?: boolean;
|
|
14
|
-
dispose?: () => Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export declare function bundleTask(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest>;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { bundlePackage } from '@ms-cloudpack/bundler';
|
|
2
|
-
import { readJson, writeJson } from '@ms-cloudpack/json-utilities';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
const log = (...messages) => {
|
|
5
|
-
console.log(`BundleTask:`, ...messages);
|
|
6
|
-
};
|
|
7
|
-
export async function bundleTask(bundleRequest, force) {
|
|
8
|
-
const { packagePath, outputPath, isExternal } = bundleRequest;
|
|
9
|
-
// Rehydrate the result if not incremental.
|
|
10
|
-
if (isExternal && !force) {
|
|
11
|
-
bundleRequest.result = await readJson(path.join(outputPath, 'result.json'));
|
|
12
|
-
}
|
|
13
|
-
const isCacheUsable = bundleRequest.result?.errors?.length === 0;
|
|
14
|
-
// Only use cached result if it's successful.
|
|
15
|
-
if (!isCacheUsable) {
|
|
16
|
-
bundleRequest.result = await bundlePackage({
|
|
17
|
-
packagePath,
|
|
18
|
-
outputPath,
|
|
19
|
-
outputType: 'library',
|
|
20
|
-
incremental: !isExternal,
|
|
21
|
-
});
|
|
22
|
-
// Write the result to disk.
|
|
23
|
-
if (isExternal) {
|
|
24
|
-
await writeJson(path.join(outputPath, 'result.json'), bundleRequest.result);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
log(`Bundle cached, returning: "${bundleRequest.packageName}@${bundleRequest.version}"`);
|
|
29
|
-
}
|
|
30
|
-
return bundleRequest;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=bundleTask.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../../src/commands/start/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;AAkBF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,aAA4B,EAAE,KAAe;IAC5E,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAE9D,2CAA2C;IAC3C,IAAI,UAAU,IAAI,CAAC,KAAK,EAAE;QACxB,aAAa,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;KAC7E;IAED,MAAM,aAAa,GAAG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC;IAEjE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