@ms-cloudpack/cli 0.7.0 → 0.9.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 +75 -1
- package/CHANGELOG.md +31 -2
- package/lib/cloudpack.js +4 -1
- package/lib/cloudpack.js.map +1 -1
- package/lib/commands/start/TaskRunner.d.ts +10 -8
- package/lib/commands/start/TaskRunner.js +41 -26
- package/lib/commands/start/TaskRunner.js.map +1 -1
- package/lib/commands/start/bundleTask.d.ts +2 -2
- package/lib/commands/start/start.js +20 -6
- package/lib/commands/start/start.js.map +1 -1
- package/lib/commands/start/startApiServer.d.ts +17 -10
- package/lib/commands/start/startApiServer.js +44 -40
- package/lib/commands/start/startApiServer.js.map +1 -1
- package/lib/commands/start/startAppServer.d.ts +1 -2
- package/lib/commands/start/startAppServer.js +2 -2
- package/lib/commands/start/startAppServer.js.map +1 -1
- package/lib/commands/start/startBundleServer.d.ts +1 -1
- package/lib/commands/start/startBundleServer.js +131 -143
- package/lib/commands/start/startBundleServer.js.map +1 -1
- package/lib/commands/start/taskRunner.test.js +29 -8
- package/lib/commands/start/taskRunner.test.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +4 -4
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,81 @@
|
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Tue,
|
|
5
|
+
"date": "Tue, 13 Sep 2022 08:15:36 GMT",
|
|
6
|
+
"tag": "@ms-cloudpack/cli_v0.9.0",
|
|
7
|
+
"version": "0.9.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "dake.3601@gmail.com",
|
|
12
|
+
"package": "@ms-cloudpack/cli",
|
|
13
|
+
"commit": "895b402c3959e689ae8d7fb9c1ee8a56711b8958",
|
|
14
|
+
"comment": "Rerun flag on add method of Task Runner"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"patch": [
|
|
18
|
+
{
|
|
19
|
+
"author": "renovate@whitesourcesoftware.com",
|
|
20
|
+
"package": "@ms-cloudpack/cli",
|
|
21
|
+
"commit": "42d8d8353be2893774225fbe2130dd934188c70f",
|
|
22
|
+
"comment": "Update dependency uuid to v9"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"date": "Mon, 12 Sep 2022 08:13:33 GMT",
|
|
29
|
+
"tag": "@ms-cloudpack/cli_v0.8.1",
|
|
30
|
+
"version": "0.8.1",
|
|
31
|
+
"comments": {
|
|
32
|
+
"none": [
|
|
33
|
+
{
|
|
34
|
+
"author": "renovate@whitesourcesoftware.com",
|
|
35
|
+
"package": "@ms-cloudpack/cli",
|
|
36
|
+
"commit": "1ec5df995e0c7e2b037d329293c2da25e2be6527",
|
|
37
|
+
"comment": "Update devDependency @types/glob to v8"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"date": "Fri, 09 Sep 2022 08:15:19 GMT",
|
|
44
|
+
"tag": "@ms-cloudpack/cli_v0.8.1",
|
|
45
|
+
"version": "0.8.1",
|
|
46
|
+
"comments": {
|
|
47
|
+
"patch": [
|
|
48
|
+
{
|
|
49
|
+
"author": "elcraig@microsoft.com",
|
|
50
|
+
"package": "@ms-cloudpack/cli",
|
|
51
|
+
"commit": "a94425304322aa40cd6837969d8c3a3f25d21ca2",
|
|
52
|
+
"message": "Improve async error handling"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"date": "Wed, 07 Sep 2022 08:14:20 GMT",
|
|
59
|
+
"tag": "@ms-cloudpack/cli_v0.8.0",
|
|
60
|
+
"version": "0.8.0",
|
|
61
|
+
"comments": {
|
|
62
|
+
"minor": [
|
|
63
|
+
{
|
|
64
|
+
"author": "dake.3601@gmail.com",
|
|
65
|
+
"package": "@ms-cloudpack/cli",
|
|
66
|
+
"commit": "40594c97b5b9eb23dbcd763a6ea23cca9f6452f6",
|
|
67
|
+
"comment": "Fixing action undefined"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"author": "beachball",
|
|
71
|
+
"package": "@ms-cloudpack/cli",
|
|
72
|
+
"comment": "Bump @ms-cloudpack/bundler to v0.4.1",
|
|
73
|
+
"commit": "40594c97b5b9eb23dbcd763a6ea23cca9f6452f6"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"date": "Tue, 06 Sep 2022 08:17:50 GMT",
|
|
6
80
|
"tag": "@ms-cloudpack/cli_v0.7.0",
|
|
7
81
|
"version": "0.7.0",
|
|
8
82
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
# Change Log - @ms-cloudpack/cli
|
|
2
2
|
|
|
3
|
-
This log was last generated on Tue,
|
|
3
|
+
This log was last generated on Tue, 13 Sep 2022 08:15:36 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.9.0
|
|
8
|
+
|
|
9
|
+
Tue, 13 Sep 2022 08:15:36 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Rerun flag on add method of Task Runner (dake.3601@gmail.com)
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Update dependency uuid to v9 (renovate@whitesourcesoftware.com)
|
|
18
|
+
|
|
19
|
+
## 0.8.1
|
|
20
|
+
|
|
21
|
+
Fri, 09 Sep 2022 08:15:19 GMT
|
|
22
|
+
|
|
23
|
+
### Patches
|
|
24
|
+
|
|
25
|
+
- undefined (elcraig@microsoft.com)
|
|
26
|
+
|
|
27
|
+
## 0.8.0
|
|
28
|
+
|
|
29
|
+
Wed, 07 Sep 2022 08:14:20 GMT
|
|
30
|
+
|
|
31
|
+
### Minor changes
|
|
32
|
+
|
|
33
|
+
- Fixing action undefined (dake.3601@gmail.com)
|
|
34
|
+
- Bump @ms-cloudpack/bundler to v0.4.1
|
|
35
|
+
|
|
7
36
|
## 0.7.0
|
|
8
37
|
|
|
9
|
-
Tue, 06 Sep 2022 08:17:
|
|
38
|
+
Tue, 06 Sep 2022 08:17:50 GMT
|
|
10
39
|
|
|
11
40
|
### Minor changes
|
|
12
41
|
|
package/lib/cloudpack.js
CHANGED
package/lib/cloudpack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudpack.js","sourceRoot":"","sources":["../src/cloudpack.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,KAAK,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"cloudpack.js","sourceRoot":"","sources":["../src/cloudpack.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACpB,OAAO,CAAC,KAAK,CAAE,GAAa,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -3,6 +3,9 @@ export interface Task<TReturn> {
|
|
|
3
3
|
id: string;
|
|
4
4
|
execute: () => Promise<TReturn>;
|
|
5
5
|
}
|
|
6
|
+
export interface TaskOptions {
|
|
7
|
+
rerun?: boolean;
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
10
|
* TaskRunner class manages the state of Tasks.
|
|
8
11
|
* This class is to be called by the api server.
|
|
@@ -11,23 +14,22 @@ export declare class TaskRunner {
|
|
|
11
14
|
private _queue;
|
|
12
15
|
private _pendingTasks;
|
|
13
16
|
private _completedTasks;
|
|
17
|
+
private _requiresRerun;
|
|
14
18
|
constructor();
|
|
15
19
|
/**
|
|
16
20
|
* The add method enqueues a Task and returns its Promise.
|
|
17
21
|
* If a Task with the same id has already been processed,
|
|
18
22
|
* it returns either the result or the promise.
|
|
23
|
+
* Rerun flag forces the Task to be run again.
|
|
19
24
|
*/
|
|
20
|
-
add<TReturn>(task: Task<TReturn
|
|
25
|
+
add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn>;
|
|
21
26
|
/**
|
|
22
|
-
* Returns Task with id.
|
|
27
|
+
* Returns result from completed Task with id.
|
|
28
|
+
* TODO: rename to getResult?
|
|
23
29
|
*/
|
|
24
|
-
get(id: string):
|
|
30
|
+
get<TReturn>(id: string): TReturn | undefined;
|
|
25
31
|
/**
|
|
26
32
|
* Returns if Task with id is pending.
|
|
27
33
|
*/
|
|
28
|
-
pending(id: string): Promise<
|
|
29
|
-
/**
|
|
30
|
-
* Deletes Task with id.
|
|
31
|
-
*/
|
|
32
|
-
delete(id: string): void;
|
|
34
|
+
pending<TReturn>(id: string): Promise<TReturn> | undefined;
|
|
33
35
|
}
|
|
@@ -11,63 +11,78 @@ 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
|
-
return action;
|
|
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);
|
|
71
|
+
this._completedTasks.delete(id);
|
|
50
72
|
return resultPromise;
|
|
51
73
|
}
|
|
52
74
|
/**
|
|
53
|
-
* Returns Task with id.
|
|
75
|
+
* Returns result from completed Task with id.
|
|
76
|
+
* TODO: rename to getResult?
|
|
54
77
|
*/
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
78
|
get(id) {
|
|
57
79
|
return this._completedTasks.get(id);
|
|
58
80
|
}
|
|
59
81
|
/**
|
|
60
82
|
* Returns if Task with id is pending.
|
|
61
83
|
*/
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
84
|
pending(id) {
|
|
64
85
|
return this._pendingTasks.get(id);
|
|
65
86
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Deletes Task with id.
|
|
68
|
-
*/
|
|
69
|
-
delete(id) {
|
|
70
|
-
this._completedTasks.delete(id);
|
|
71
|
-
}
|
|
72
87
|
}
|
|
73
88
|
//# 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;AAG7B,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../../src/commands/start/TaskRunner.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAG7B,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,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AAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BundlerResult } from '@ms-cloudpack/bundler-types';
|
|
2
2
|
/**
|
|
3
|
-
* Tracks a given bundle result.
|
|
3
|
+
* Tracks a given bundle request and its result.
|
|
4
4
|
*/
|
|
5
5
|
export interface BundleRequest {
|
|
6
6
|
id: string;
|
|
@@ -11,6 +11,6 @@ export interface BundleRequest {
|
|
|
11
11
|
isExternal: boolean;
|
|
12
12
|
result?: BundlerResult;
|
|
13
13
|
isRebuildRequired?: boolean;
|
|
14
|
-
dispose?: () => void
|
|
14
|
+
dispose?: () => Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
export declare function bundleTask(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest>;
|
|
@@ -19,14 +19,28 @@ export async function start() {
|
|
|
19
19
|
bundleServer,
|
|
20
20
|
apiServer,
|
|
21
21
|
});
|
|
22
|
+
const cleanup = async () => {
|
|
23
|
+
for (const server of [bundleServer, appServer, apiServer]) {
|
|
24
|
+
try {
|
|
25
|
+
await server.close();
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.warn('Error closing server:', err);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
22
32
|
// Setup cleanup and close things on completion.
|
|
23
|
-
process.on('SIGINT',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
process.exit(0);
|
|
33
|
+
process.on('SIGINT', () => {
|
|
34
|
+
cleanup().finally(() => {
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
28
37
|
});
|
|
29
38
|
// Open the browser.
|
|
30
|
-
|
|
39
|
+
const url = `http://localhost:${appServer.port}`;
|
|
40
|
+
openBrowser(url).catch((err) => {
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
42
|
+
console.warn('Error opening browser:', err?.stack || err);
|
|
43
|
+
console.warn('Please open the browser manually to:', url);
|
|
44
|
+
});
|
|
31
45
|
}
|
|
32
46
|
//# sourceMappingURL=start.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE9B,iCAAiC;IACjC,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAEjD,qEAAqE;IACrE,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAEpD,yDAAyD;IACzD,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC;QACrC,OAAO;QACP,YAAY;QACZ,SAAS;KACV,CAAC,CAAC;IAEH,
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../src/commands/start/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;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AC;QAC1D,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Session } from './types.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { Task, TaskOptions } from './TaskRunner.js';
|
|
3
3
|
export interface SessionStats {
|
|
4
4
|
status: 'idle' | 'pending';
|
|
5
5
|
remainingTasks: number;
|
|
@@ -13,13 +13,15 @@ export interface ApiServer {
|
|
|
13
13
|
notifyReload: () => void;
|
|
14
14
|
reportStart: (options: TaskStartDescription) => void;
|
|
15
15
|
reportEnd: (options: TaskEndDescription) => void;
|
|
16
|
-
addTask: <TReturn>(task: Task<TReturn
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => 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
|
+
close: () => Promise<void>;
|
|
21
23
|
}
|
|
22
|
-
interface TaskError {
|
|
24
|
+
export interface TaskError {
|
|
23
25
|
message: string;
|
|
24
26
|
pluginName: string;
|
|
25
27
|
stack: string;
|
|
@@ -27,17 +29,23 @@ interface TaskError {
|
|
|
27
29
|
lineNumber: number;
|
|
28
30
|
columnNumber: number;
|
|
29
31
|
}
|
|
30
|
-
interface TaskStartDescription {
|
|
32
|
+
export interface TaskStartDescription {
|
|
31
33
|
id: string;
|
|
32
34
|
name: string;
|
|
33
35
|
inputPath: string;
|
|
34
36
|
outputPath: string;
|
|
35
37
|
}
|
|
36
|
-
interface TaskEndDescription {
|
|
38
|
+
export interface TaskEndDescription {
|
|
37
39
|
id: string;
|
|
38
40
|
errors?: TaskError[];
|
|
39
41
|
warnings?: TaskError[];
|
|
40
42
|
}
|
|
43
|
+
export interface TaskDescription extends TaskStartDescription, TaskEndDescription {
|
|
44
|
+
status: 'pending' | 'complete';
|
|
45
|
+
startTime: number;
|
|
46
|
+
durationMilliseconds?: number;
|
|
47
|
+
lastUpdated?: number;
|
|
48
|
+
}
|
|
41
49
|
/**
|
|
42
50
|
* The api server handles the data pub/sub (for things like reporting build status)
|
|
43
51
|
* and hosting the dashboard verb backend (for executing actions like loading vscode,
|
|
@@ -55,4 +63,3 @@ interface TaskEndDescription {
|
|
|
55
63
|
export declare function startApiServer({ session }: {
|
|
56
64
|
session: Session;
|
|
57
65
|
}): Promise<ApiServer>;
|
|
58
|
-
export {};
|
|
@@ -44,44 +44,51 @@ export async function startApiServer({ session }) {
|
|
|
44
44
|
socket.send(JSON.stringify(message, null, 2));
|
|
45
45
|
}
|
|
46
46
|
socket
|
|
47
|
-
.on('message',
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
dispose
|
|
64
|
-
|
|
47
|
+
.on('message', (rawData) => {
|
|
48
|
+
try {
|
|
49
|
+
const request = JSON.parse(rawData.toString());
|
|
50
|
+
// console.log(`ApiServer: Received message: ${JSON.stringify(request, null, 2)}`);
|
|
51
|
+
switch (request.type) {
|
|
52
|
+
case 'subscribe': {
|
|
53
|
+
const { path: subscriptionPath, id } = request.data;
|
|
54
|
+
disposables.set(id, bus.subscribe(subscriptionPath,
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
|
|
56
|
+
(data) => sendMessage({ type: 'notify', id, path: subscriptionPath, data })));
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'unsubscribe': {
|
|
60
|
+
const id = request.data.id;
|
|
61
|
+
if (id) {
|
|
62
|
+
const dispose = disposables.get(id);
|
|
63
|
+
if (dispose) {
|
|
64
|
+
dispose();
|
|
65
|
+
disposables.delete(id);
|
|
66
|
+
}
|
|
65
67
|
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'openSource': {
|
|
71
|
+
const { rootPath, relativePath = '', line, column } = request.data;
|
|
72
|
+
const fullPath = path.join(rootPath, relativePath);
|
|
73
|
+
console.log(`Opening VSCode with path: ${fullPath}`);
|
|
74
|
+
execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'open': {
|
|
78
|
+
const { rootPath, relativePath = '' } = request.data;
|
|
79
|
+
const fullPath = path.join(rootPath, relativePath);
|
|
80
|
+
console.log(`Opening path: ${fullPath}`);
|
|
81
|
+
const openCommand = os.platform() == 'win32' ? 'start' : 'open';
|
|
82
|
+
execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });
|
|
83
|
+
break;
|
|
66
84
|
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case 'openSource': {
|
|
70
|
-
const { rootPath, relativePath = '', line, column } = request.data;
|
|
71
|
-
const fullPath = path.join(rootPath, relativePath);
|
|
72
|
-
console.log(`Opening VSCode with path: ${fullPath}`);
|
|
73
|
-
execSync(`code --goto ${fullPath}:${line}:${column}`, { cwd: process.cwd() });
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case 'open': {
|
|
77
|
-
const { rootPath, relativePath = '' } = request.data;
|
|
78
|
-
const fullPath = path.join(rootPath, relativePath);
|
|
79
|
-
console.log(`Opening path: ${fullPath}`);
|
|
80
|
-
const openCommand = os.platform() == 'win32' ? 'start' : 'open';
|
|
81
|
-
execSync(`${openCommand} ${fullPath}`, { cwd: process.cwd() });
|
|
82
|
-
break;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.error('ApiServer: error handling message');
|
|
89
|
+
console.error('Error:', err);
|
|
90
|
+
console.error('Message:', rawData.toString());
|
|
91
|
+
}
|
|
85
92
|
})
|
|
86
93
|
.on('close', () => {
|
|
87
94
|
for (const d of disposables.values()) {
|
|
@@ -143,8 +150,8 @@ export async function startApiServer({ session }) {
|
|
|
143
150
|
bus.publish([session.id, 'status-details'], { tasks: Array.from(allTasks.values()) });
|
|
144
151
|
}
|
|
145
152
|
},
|
|
146
|
-
addTask: (task) => {
|
|
147
|
-
return taskRunner.add(task);
|
|
153
|
+
addTask: (task, options) => {
|
|
154
|
+
return taskRunner.add(task, options);
|
|
148
155
|
},
|
|
149
156
|
getTask: (id) => {
|
|
150
157
|
return taskRunner.get(id);
|
|
@@ -152,10 +159,7 @@ export async function startApiServer({ session }) {
|
|
|
152
159
|
pendingTask: (id) => {
|
|
153
160
|
return taskRunner.pending(id);
|
|
154
161
|
},
|
|
155
|
-
|
|
156
|
-
taskRunner.delete(id);
|
|
157
|
-
},
|
|
158
|
-
close: () => server.close(),
|
|
162
|
+
close: () => new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
|
|
159
163
|
};
|
|
160
164
|
}
|
|
161
165
|
//# sourceMappingURL=startApiServer.js.map
|
|
@@ -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;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"startApiServer.js","sourceRoot":"","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,EAAE,EAAE;YACzB,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE;YACd,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE;YAClB,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAChC,CAAC;QAED,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,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,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import type { Session } from './types.js';
|
|
3
2
|
import type { ApiServer } from './startApiServer.js';
|
|
4
3
|
import type { BundleServer } from './startBundleServer.js';
|
|
@@ -15,6 +14,6 @@ export declare function startAppServer({ session, bundleServer, apiServer, }: {
|
|
|
15
14
|
bundleServer: BundleServer;
|
|
16
15
|
apiServer: ApiServer;
|
|
17
16
|
}): Promise<{
|
|
18
|
-
close: () =>
|
|
17
|
+
close: () => Promise<void>;
|
|
19
18
|
port: number;
|
|
20
19
|
}>;
|
|
@@ -33,7 +33,7 @@ export async function startAppServer({ session, bundleServer, apiServer, }) {
|
|
|
33
33
|
res,
|
|
34
34
|
});
|
|
35
35
|
})
|
|
36
|
-
.get('*',
|
|
36
|
+
.get('*', (req, res) => {
|
|
37
37
|
if (!definition) {
|
|
38
38
|
res.status(500).send(`There was no package.json located at "${session.appPath}".`);
|
|
39
39
|
return;
|
|
@@ -53,7 +53,7 @@ export async function startAppServer({ session, bundleServer, apiServer, }) {
|
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
return {
|
|
56
|
-
close: () => server.close(),
|
|
56
|
+
close: () => new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
|
|
57
57
|
port,
|
|
58
58
|
};
|
|
59
59
|
}
|
|
@@ -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;AAKjG,6DAA6D;AAC7D,MAAM,GAAG,GAAG,CAAC,QAAiB,EAAE,EAAE;IAChC,6CAA6C;AAC/C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,YAAY,EACZ,SAAS,GAKV;IACC,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IAC9E,MAAM,UAAU,GAAG,MAAM,kBAAkB,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/E,MAAM,qBAAqB,GAAG,SAAS,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACzE,MAAM,eAAe,GAAG,SAAS,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAEnE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,gBAAgB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;QA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AC,CACb,CAAC;AACJ,CAAC"}
|
|
@@ -14,158 +14,144 @@ const { ensureDir } = fsExtra;
|
|
|
14
14
|
const log = (...messages) => {
|
|
15
15
|
console.log(`BundleServer:`, ...messages);
|
|
16
16
|
};
|
|
17
|
+
const error = (...messages) => {
|
|
18
|
+
console.error(`BundleServer:`, ...messages);
|
|
19
|
+
};
|
|
17
20
|
/**
|
|
18
21
|
* The bundle server handles package requests and returns bundled resources.
|
|
19
22
|
* Resources are bundled on demand and cached locally to avoid re-bundling
|
|
20
23
|
* on each request.
|
|
21
24
|
*/
|
|
22
25
|
export async function startBundleServer({ session, apiServer, }) {
|
|
23
|
-
const { resolveMap } = session;
|
|
24
26
|
const { server, port } = await createExpressApp([5500, 5501, 5502, 5503], (app) => {
|
|
25
27
|
// Set up the express app routes.
|
|
26
|
-
app.get('*',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const packagePath = !!version && packageEntry?.version === version
|
|
31
|
-
? packageEntry?.path
|
|
32
|
-
: packageEntry?.scopedVersions?.[version]?.path;
|
|
33
|
-
const force = req.query.force !== undefined;
|
|
34
|
-
log(`Request: "${packageName}@${version}${filePath}"`);
|
|
35
|
-
// If the package is missing, invalid arguments.
|
|
36
|
-
if (!requestPath || !packageName) {
|
|
37
|
-
log(`Response (400): "${packageName}@${version}${filePath}"`);
|
|
38
|
-
res.status(400).send(`Requests must be in the format "/{packageName}@{version}/path/file.ext".`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// If the version is missing, redirect to the primary version.
|
|
42
|
-
if (!version) {
|
|
43
|
-
const resolvedPackage = resolveMap[packageName];
|
|
44
|
-
if (!resolvedPackage) {
|
|
45
|
-
log(`Response (404): Unrecognized package "${packageName}"`);
|
|
46
|
-
res.status(404).send(`Unrecognized package "${packageName}".`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
res.redirect(`/${packageName}@${resolvedPackage.version}${filePath}`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// If it's an unrecognized package, 404.
|
|
53
|
-
if (!packagePath) {
|
|
54
|
-
log(`Response (404): "${packageName}@${version}${filePath}"`);
|
|
55
|
-
res
|
|
56
|
-
.status(404)
|
|
57
|
-
.send(`The requested package "${packageName}@${version}${filePath}" was not found in the resolve map.`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Create an identifier for the bundle.
|
|
61
|
-
const isExternal = isExternalPackage(packagePath);
|
|
62
|
-
const bundleId = hash({
|
|
63
|
-
name: packageName,
|
|
64
|
-
version: isExternal ? version : packagePath,
|
|
65
|
-
mode: session.mode,
|
|
28
|
+
app.get('*', (req, res) => {
|
|
29
|
+
handleRequest(req, res, session, apiServer).catch((err) => {
|
|
30
|
+
error(err?.stack || err);
|
|
31
|
+
res.status(500).send(`Error bundling: ${err}`);
|
|
66
32
|
});
|
|
67
|
-
// Derive where the output should be.
|
|
68
|
-
const outputPath = path.join(os.tmpdir(), 'cloudpack-output', `${filenamify(packageName)}-${version}-${bundleId}`);
|
|
69
|
-
// Set up for bundling.
|
|
70
|
-
let action = apiServer.getTask(bundleId);
|
|
71
|
-
const pendingBundle = apiServer.pendingTask(bundleId);
|
|
72
|
-
const restart = action && !isFolder;
|
|
73
|
-
let bundling;
|
|
74
|
-
// Does it need to bundle?
|
|
75
|
-
if (!pendingBundle && (!action || restart)) {
|
|
76
|
-
// Bundling promise wrapper.
|
|
77
|
-
bundling = new Promise((resolve) => {
|
|
78
|
-
const bundleRequest = {
|
|
79
|
-
id: bundleId,
|
|
80
|
-
packageName,
|
|
81
|
-
version: version,
|
|
82
|
-
packagePath,
|
|
83
|
-
outputPath,
|
|
84
|
-
isExternal,
|
|
85
|
-
};
|
|
86
|
-
// Call to async helper so that we can await and call resolve.
|
|
87
|
-
(async () => {
|
|
88
|
-
// Start tracking work.
|
|
89
|
-
apiServer.reportStart({
|
|
90
|
-
id: bundleId,
|
|
91
|
-
name: `Bundle ${packageName}@${version}`,
|
|
92
|
-
inputPath: packagePath || '',
|
|
93
|
-
outputPath,
|
|
94
|
-
});
|
|
95
|
-
try {
|
|
96
|
-
log(`No previous action found, bundling: "${packageName}@${version}"`);
|
|
97
|
-
await ensureDir(outputPath);
|
|
98
|
-
log(`Finished ensureDir: "${packageName}@${version}"`);
|
|
99
|
-
log(`Trying to bundle "${packageName}@${version}"`);
|
|
100
|
-
if (restart) {
|
|
101
|
-
// TODO: Implement apiServer.restart
|
|
102
|
-
apiServer.deleteTask(bundleId);
|
|
103
|
-
}
|
|
104
|
-
await apiServer.addTask({
|
|
105
|
-
name: `Bundle ${packageName}@${version}`,
|
|
106
|
-
id: bundleId,
|
|
107
|
-
execute: () => bundleTask(bundleRequest, force),
|
|
108
|
-
});
|
|
109
|
-
// If this is going to be incremental, start a watcher to re-bundle when source
|
|
110
|
-
// changes.
|
|
111
|
-
if (!isExternal) {
|
|
112
|
-
initializeFileWatcher(session, bundleId, outputPath, bundleRequest, apiServer);
|
|
113
|
-
log(`Bundle complete: ${outputPath}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (_) {
|
|
117
|
-
/* no-op */
|
|
118
|
-
}
|
|
119
|
-
resolve(bundleRequest);
|
|
120
|
-
// TODO: errors and warnings typings don't match up. We need to reconcile.
|
|
121
|
-
apiServer.reportEnd({
|
|
122
|
-
id: bundleId,
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
-
errors: bundleRequest.result?.errors,
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
-
warnings: bundleRequest.result?.warnings,
|
|
127
|
-
});
|
|
128
|
-
})();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else if (pendingBundle) {
|
|
132
|
-
log(`Previous action found, waiting: "${packageName}@${version}${filePath}"`);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
log(`Bundle cached, returning: "${packageName}@${version}${filePath}"`);
|
|
136
|
-
}
|
|
137
|
-
await apiServer.pendingTask(bundleId);
|
|
138
|
-
await bundling;
|
|
139
|
-
action = apiServer.getTask(bundleId);
|
|
140
|
-
// If this is a pre-built local package we haven't set up for incremental builds, set it up.
|
|
141
|
-
if (!isExternal && !action.dispose) {
|
|
142
|
-
initializeFileWatcher(session, bundleId, outputPath, action, apiServer);
|
|
143
|
-
}
|
|
144
|
-
// At this point we should have an action completed.
|
|
145
|
-
if ((action.result?.errors?.length || 0) > 0) {
|
|
146
|
-
res.status(500).type('json').send(action);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
log(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
150
|
-
// Try to return the result.
|
|
151
|
-
if (isExternal) {
|
|
152
|
-
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
|
153
|
-
}
|
|
154
|
-
res.sendFile(path.join(outputPath, filePath));
|
|
155
|
-
}
|
|
156
33
|
});
|
|
157
34
|
});
|
|
158
35
|
const url = `http://localhost:${port}`;
|
|
159
36
|
log(`started (${url})`);
|
|
160
37
|
return {
|
|
161
|
-
close:
|
|
162
|
-
server.close();
|
|
163
|
-
},
|
|
38
|
+
close: () => new Promise((resolve, reject) => server.close((err) => (err ? reject(err) : resolve()))),
|
|
164
39
|
port,
|
|
165
40
|
url,
|
|
166
41
|
};
|
|
167
42
|
}
|
|
168
|
-
function
|
|
43
|
+
async function handleRequest(req, res, session, apiServer) {
|
|
44
|
+
const { resolveMap } = session;
|
|
45
|
+
const requestPath = slash(req.path.substring(1));
|
|
46
|
+
const { packageName, version, filePath } = parseRequestInfo(requestPath);
|
|
47
|
+
const packageEntry = resolveMap[packageName];
|
|
48
|
+
const packagePath = version && packageEntry?.version === version ? packageEntry?.path : packageEntry?.scopedVersions?.[version]?.path;
|
|
49
|
+
const force = req.query.force !== undefined;
|
|
50
|
+
log(`Request: "${packageName}@${version}${filePath}"`);
|
|
51
|
+
// If the package is missing, invalid arguments.
|
|
52
|
+
if (!requestPath || !packageName) {
|
|
53
|
+
log(`Response (400): "${packageName}@${version}${filePath}"`);
|
|
54
|
+
res.status(400).send(`Requests must be in the format "/{packageName}@{version}/path/file.ext".`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// If the version is missing, redirect to the primary version.
|
|
58
|
+
if (!version) {
|
|
59
|
+
const resolvedPackage = resolveMap[packageName];
|
|
60
|
+
if (!resolvedPackage) {
|
|
61
|
+
log(`Response (404): Unrecognized package "${packageName}"`);
|
|
62
|
+
res.status(404).send(`Unrecognized package "${packageName}".`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
res.redirect(`/${packageName}@${resolvedPackage.version}${filePath}`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// If it's an unrecognized package, 404.
|
|
69
|
+
if (!packagePath) {
|
|
70
|
+
log(`Response (404): "${packageName}@${version}${filePath}"`);
|
|
71
|
+
res
|
|
72
|
+
.status(404)
|
|
73
|
+
.send(`The requested package "${packageName}@${version}${filePath}" was not found in the resolve map.`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Create an identifier for the bundle.
|
|
77
|
+
const isExternal = isExternalPackage(packagePath);
|
|
78
|
+
const bundleId = hash({
|
|
79
|
+
name: packageName,
|
|
80
|
+
version: isExternal ? version : packagePath,
|
|
81
|
+
mode: session.mode,
|
|
82
|
+
});
|
|
83
|
+
// Derive where the output should be.
|
|
84
|
+
const outputPath = path.join(os.tmpdir(), 'cloudpack-output', `${filenamify(packageName)}-${version}-${bundleId}`);
|
|
85
|
+
// Set up for bundling.
|
|
86
|
+
let taskResult = apiServer.getTask(bundleId);
|
|
87
|
+
const rerun = force || (taskResult && !isFolder(outputPath));
|
|
88
|
+
// Does it need to bundle?
|
|
89
|
+
if (!taskResult || rerun) {
|
|
90
|
+
// TODO extract to function
|
|
91
|
+
// also `bundleRequest` appears to be the same thing as `taskResult`
|
|
92
|
+
const bundleRequest = {
|
|
93
|
+
id: bundleId,
|
|
94
|
+
packageName,
|
|
95
|
+
version: version,
|
|
96
|
+
packagePath,
|
|
97
|
+
outputPath,
|
|
98
|
+
isExternal,
|
|
99
|
+
};
|
|
100
|
+
// Start tracking work.
|
|
101
|
+
apiServer.reportStart({
|
|
102
|
+
id: bundleId,
|
|
103
|
+
name: `Bundle ${packageName}@${version}`,
|
|
104
|
+
inputPath: packagePath || '',
|
|
105
|
+
outputPath,
|
|
106
|
+
});
|
|
107
|
+
try {
|
|
108
|
+
log(`No previous task result found, bundling: "${packageName}@${version}"`);
|
|
109
|
+
await ensureDir(outputPath);
|
|
110
|
+
log(`Finished ensureDir: "${packageName}@${version}"`);
|
|
111
|
+
log(`Trying to bundle "${packageName}@${version}"`);
|
|
112
|
+
await apiServer.addTask({
|
|
113
|
+
name: `Bundle ${packageName}@${version}`,
|
|
114
|
+
id: bundleId,
|
|
115
|
+
execute: () => bundleTask(bundleRequest, force),
|
|
116
|
+
}, { rerun });
|
|
117
|
+
}
|
|
118
|
+
catch (_) {
|
|
119
|
+
/* no-op */
|
|
120
|
+
}
|
|
121
|
+
// TODO: if moved to a function, this would be the return value
|
|
122
|
+
taskResult = bundleRequest;
|
|
123
|
+
// TODO: errors and warnings typings don't match up. We need to reconcile.
|
|
124
|
+
apiServer.reportEnd({
|
|
125
|
+
id: bundleId,
|
|
126
|
+
errors: bundleRequest.result?.errors,
|
|
127
|
+
warnings: bundleRequest.result?.warnings,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
log(`Bundle cached, returning: "${packageName}@${version}${filePath}"`);
|
|
132
|
+
}
|
|
133
|
+
if (!taskResult) {
|
|
134
|
+
res.status(500).send(`Result not found for "${bundleId}". This is likely a bug with cloudpack.`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// If this is a pre-built local package we haven't set up for incremental builds, set it up.
|
|
138
|
+
if (!isExternal && !taskResult.dispose) {
|
|
139
|
+
initializeFileWatcher(bundleId, outputPath, taskResult, apiServer);
|
|
140
|
+
}
|
|
141
|
+
// At this point we should have a Task completed.
|
|
142
|
+
if ((taskResult.result?.errors?.length || 0) > 0) {
|
|
143
|
+
res.status(500).type('json').send(taskResult);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
log(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
147
|
+
// Try to return the result.
|
|
148
|
+
if (isExternal) {
|
|
149
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
|
150
|
+
}
|
|
151
|
+
res.sendFile(path.join(outputPath, filePath));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function initializeFileWatcher(bundleId, outputPath, bundleRequest, apiServer) {
|
|
169
155
|
const { id, packageName, packagePath, version } = bundleRequest;
|
|
170
156
|
let bundleOutput = bundleRequest.result;
|
|
171
157
|
log(`Initializing file watcher for ${packageName}@${version}`);
|
|
@@ -174,8 +160,7 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
174
160
|
if (!apiServer.pendingTask(id)) {
|
|
175
161
|
bundleRequest.isRebuildRequired = true;
|
|
176
162
|
log(`Detected change "${event}", rebuilding "${packageName}@${version}"`);
|
|
177
|
-
|
|
178
|
-
new Promise(async (resolveIncremental) => {
|
|
163
|
+
(async () => {
|
|
179
164
|
do {
|
|
180
165
|
bundleRequest.isRebuildRequired = false;
|
|
181
166
|
log(`[Start] >> Bundling "${packageName}@${version}" to "${outputPath}"`);
|
|
@@ -183,7 +168,6 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
183
168
|
apiServer.reportStart({
|
|
184
169
|
id: bundleId,
|
|
185
170
|
name: `Rebundle ${packageName}@${version}`,
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
187
171
|
inputPath: packagePath,
|
|
188
172
|
outputPath,
|
|
189
173
|
});
|
|
@@ -192,7 +176,7 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
192
176
|
name: `Bundle ${packageName}@${version}`,
|
|
193
177
|
id: bundleId,
|
|
194
178
|
execute: () => bundleTask(bundleRequest),
|
|
195
|
-
}))
|
|
179
|
+
}))?.result;
|
|
196
180
|
}
|
|
197
181
|
else if (bundleOutput?.rebuild) {
|
|
198
182
|
bundleOutput = await bundleOutput.rebuild();
|
|
@@ -200,9 +184,7 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
200
184
|
// TODO: Fix typings
|
|
201
185
|
apiServer.reportEnd({
|
|
202
186
|
id: bundleId,
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
187
|
errors: bundleOutput?.errors,
|
|
205
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
188
|
warnings: bundleOutput?.warnings,
|
|
207
189
|
});
|
|
208
190
|
log(`[ End ] << Bundled "${packageName}@${version}" (${bundleOutput?.outputFiles?.length || 0} file(s), ${bundleOutput?.errors?.length || 0} errors)`);
|
|
@@ -211,7 +193,8 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
211
193
|
log(`Notifying rebuild: ${packageName}@${version}`);
|
|
212
194
|
apiServer.notifyReload();
|
|
213
195
|
}
|
|
214
|
-
|
|
196
|
+
})().catch((err) => {
|
|
197
|
+
error(`Error rebuilding "${packageName}@${version}":`, err?.stack || err);
|
|
215
198
|
});
|
|
216
199
|
}
|
|
217
200
|
else {
|
|
@@ -221,8 +204,13 @@ function initializeFileWatcher(session, bundleId, outputPath, bundleRequest, api
|
|
|
221
204
|
log(`Detected change "${event}", already waiting for "${packageName}@${version}"`);
|
|
222
205
|
}
|
|
223
206
|
});
|
|
224
|
-
bundleRequest.dispose = () => {
|
|
225
|
-
|
|
207
|
+
bundleRequest.dispose = async () => {
|
|
208
|
+
try {
|
|
209
|
+
await watcher.close();
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// ignore
|
|
213
|
+
}
|
|
226
214
|
bundleOutput?.dispose?.();
|
|
227
215
|
};
|
|
228
216
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,
|
|
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,OAAO,MAAM,UAAU,CAAC;AAC/B,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;AAGzD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;AAE9B,2FAA2F;AAE3F,MAAM,GAAG,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACrC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE;IACvC,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,QAAQ,CAAC,CAAC;AAC9C,CAAC,CAAC;AAQF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EACtC,OAAO,EACP,SAAS,GAIV;IACC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MA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GAAG,CAAC,oBAAoB,KAAK,2BAA2B,WAAW,IAAI,OAAO,GAAG,CAAC,CAAC;SACpF;IACH,CAAC,CAAC,CAAC;IAEH,aAAa,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE;QACjC,IAAI;YACF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;SACvB;QAAC,MAAM;YACN,SAAS;SACV;QAED,YAAY,EAAE,OAAO,EAAE,EAAE,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,32 +4,53 @@ const tasks = [
|
|
|
4
4
|
{
|
|
5
5
|
name: 'Task 1',
|
|
6
6
|
id: '1',
|
|
7
|
-
execute: () => new Promise((r) => r('test value')),
|
|
7
|
+
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
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
29
30
|
taskRunner.add(tasks[0]);
|
|
30
31
|
// Even though task[0].excute() and task[1].execute() return different strings,
|
|
31
32
|
// since their tasks share id, the task runner will return the promise of the first.
|
|
32
|
-
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);
|
|
33
54
|
});
|
|
34
55
|
});
|
|
35
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,EAAa,MAAM,iBAAiB,CAAC;AAExD,MAAM,K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G,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;QAEpC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAE3C,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAE7D,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,MAAM,UAAU,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export async function start() {
|
|
|
13
13
|
program.name('cloudpack').version(getVersion()).usage('<command> [options]');
|
|
14
14
|
const commands = glob.sync('commands/*/index.js', { cwd: currentPath });
|
|
15
15
|
for (const commandPath of commands) {
|
|
16
|
-
const command = await import(pathToFileURL(path.resolve(currentPath, commandPath)).toString());
|
|
16
|
+
const command = (await import(pathToFileURL(path.resolve(currentPath, commandPath)).toString()));
|
|
17
17
|
command.init(program);
|
|
18
18
|
}
|
|
19
19
|
program.parse(process.argv);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,UAA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,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAE7E,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAExE,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE;QAClC,MAAM,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAE9F,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;KACvB;IAED,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,IAAI,EAAE,CAAC;KAChB;AACH,CAAC"}
|
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.9.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",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"cloudpack": "./lib/cloudpack.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ms-cloudpack/bundler": "^0.4.
|
|
19
|
+
"@ms-cloudpack/bundler": "^0.4.1",
|
|
20
20
|
"@ms-cloudpack/create-express-app": "^0.1.0",
|
|
21
21
|
"@ms-cloudpack/data-bus": "^0.1.0",
|
|
22
22
|
"@ms-cloudpack/json-utilities": "^0.0.3",
|
|
@@ -31,7 +31,7 @@
|
|
|
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": "*",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@ms-cloudpack/scripts": "*",
|
|
40
40
|
"@types/chokidar": "2.1.3",
|
|
41
41
|
"@types/fs-extra": "9.0.13",
|
|
42
|
-
"@types/glob": "
|
|
42
|
+
"@types/glob": "8.0.0",
|
|
43
43
|
"@types/object-hash": "2.2.1",
|
|
44
44
|
"@types/uuid": "8.3.4"
|
|
45
45
|
},
|