@ms-cloudpack/cli 0.31.7 → 0.33.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/lib/commands/bundle/bundle.js +2 -1
- package/lib/commands/bundle/bundle.js.map +1 -1
- package/lib/commands/bundle/types.d.ts +4 -0
- package/lib/commands/bundle/types.js.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.d.ts +4 -1
- package/lib/commands/init/evaluateImportsForOverrides.js +8 -4
- package/lib/commands/init/evaluateImportsForOverrides.js.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.test.js +67 -0
- package/lib/commands/init/evaluateImportsForOverrides.test.js.map +1 -0
- package/lib/commands/init/index.js +1 -1
- package/lib/commands/init/index.js.map +1 -1
- package/lib/commands/init/init.js +10 -5
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/init/init.test.js +3 -3
- package/lib/commands/init/init.test.js.map +1 -1
- package/lib/commands/init/preparePackageOverride.d.ts +0 -1
- package/lib/commands/init/preparePackageOverride.js +2 -5
- package/lib/commands/init/preparePackageOverride.js.map +1 -1
- package/lib/commands/start/appServer/createRoutes.d.ts +3 -1
- package/lib/commands/start/appServer/createRoutes.js.map +1 -1
- package/lib/commands/start/appServer/handleSessionVersion.d.ts +1 -1
- package/lib/commands/start/appServer/handleSessionVersion.js.map +1 -1
- package/lib/commands/start/appServer/setHeaders.d.ts +1 -1
- package/lib/commands/start/appServer/setHeaders.js.map +1 -1
- package/lib/commands/start/appServer/startAppServer.d.ts +3 -1
- package/lib/commands/start/appServer/startAppServer.js.map +1 -1
- package/lib/commands/start/createBundleTask.d.ts +2 -1
- package/lib/commands/start/createBundleTask.js.map +1 -1
- package/lib/commands/start/createSession.d.ts +3 -1
- package/lib/commands/start/createSession.js +2 -1
- package/lib/commands/start/createSession.js.map +1 -1
- package/lib/commands/start/createSession.test.js +3 -3
- package/lib/commands/start/createSession.test.js.map +1 -1
- package/lib/commands/start/start.js +5 -5
- package/lib/commands/start/start.js.map +1 -1
- package/lib/commands/start/startBundleServer.d.ts +3 -1
- package/lib/commands/start/startBundleServer.js +1 -0
- package/lib/commands/start/startBundleServer.js.map +1 -1
- package/lib/commands/start/types.d.ts +1 -0
- package/lib/commands/start/types.js.map +1 -1
- package/lib/common/createPackageOverrideTransform.d.ts +1 -1
- package/lib/common/createPackageOverrideTransform.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js.map +1 -1
- package/lib/initTelemetry.js +1 -1
- package/lib/initTelemetry.js.map +1 -1
- package/lib/tasks/bundleTask.js +2 -1
- package/lib/tasks/bundleTask.js.map +1 -1
- package/lib/types.d.ts +6 -199
- package/lib/types.js.map +1 -1
- package/package.json +7 -5
- package/lib/commands/start/TaskRunner.d.ts +0 -40
- package/lib/commands/start/TaskRunner.js +0 -119
- package/lib/commands/start/TaskRunner.js.map +0 -1
- package/lib/commands/start/addOverride.d.ts +0 -7
- package/lib/commands/start/addOverride.js +0 -63
- package/lib/commands/start/addOverride.js.map +0 -1
- package/lib/commands/start/addOverride.test.js +0 -254
- package/lib/commands/start/addOverride.test.js.map +0 -1
- package/lib/commands/start/startApiServer.d.ts +0 -19
- package/lib/commands/start/startApiServer.js +0 -303
- package/lib/commands/start/startApiServer.js.map +0 -1
- package/lib/commands/start/startWatcher.d.ts +0 -7
- package/lib/commands/start/startWatcher.js +0 -51
- package/lib/commands/start/startWatcher.js.map +0 -1
- package/lib/commands/start/taskRunner.test.d.ts +0 -1
- package/lib/commands/start/taskRunner.test.js +0 -80
- package/lib/commands/start/taskRunner.test.js.map +0 -1
- package/lib/commands/start/validateOverride.d.ts +0 -7
- package/lib/commands/start/validateOverride.js +0 -28
- package/lib/commands/start/validateOverride.js.map +0 -1
- package/lib/commands/start/validateOverride.test.d.ts +0 -1
- package/lib/commands/start/validateOverride.test.js +0 -137
- package/lib/commands/start/validateOverride.test.js.map +0 -1
- package/lib/common/config.d.ts +0 -31
- package/lib/common/config.js +0 -54
- package/lib/common/config.js.map +0 -1
- package/lib/common/configTemplate.d.ts +0 -13
- package/lib/common/configTemplate.js +0 -16
- package/lib/common/configTemplate.js.map +0 -1
- /package/lib/commands/{start/addOverride.test.d.ts → init/evaluateImportsForOverrides.test.d.ts} +0 -0
package/lib/types.d.ts
CHANGED
|
@@ -1,69 +1,7 @@
|
|
|
1
|
-
import type { ImportMap
|
|
1
|
+
import type { ImportMap } from '@ms-cloudpack/package-utilities';
|
|
2
2
|
import type { BundleResult, PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The session id, used for identifying
|
|
7
|
-
*/
|
|
8
|
-
id: string;
|
|
9
|
-
/**
|
|
10
|
-
* The primary application path to monitor.
|
|
11
|
-
*/
|
|
12
|
-
appPath: string;
|
|
13
|
-
/**
|
|
14
|
-
* The type of session controls how the code is served via start.
|
|
15
|
-
* Web apps require app server and asset hosting, while libraries
|
|
16
|
-
* only need a bundle service.
|
|
17
|
-
*/
|
|
18
|
-
type: 'web-app' | 'library';
|
|
19
|
-
/**
|
|
20
|
-
* The mode of the session controls how the code is bundled. Library
|
|
21
|
-
* mode bundles each package in isolation, while development and
|
|
22
|
-
* production modes bundle the full app graph together. Library
|
|
23
|
-
* mode is fastest but packages must be complaint for loading in
|
|
24
|
-
* the browser.
|
|
25
|
-
*/
|
|
26
|
-
mode: 'library' | 'development' | 'production';
|
|
27
|
-
/**
|
|
28
|
-
* Used to resolve packages in the dependency graph.
|
|
29
|
-
*/
|
|
30
|
-
resolveMap: ResolveMap;
|
|
31
|
-
/**
|
|
32
|
-
* Reload sequence to ensure that the client is always
|
|
33
|
-
* up to date with the latest changes.
|
|
34
|
-
*/
|
|
35
|
-
sequence: number;
|
|
36
|
-
/**
|
|
37
|
-
* Get session version.
|
|
38
|
-
* Used to force a hard refresh on the client.
|
|
39
|
-
*/
|
|
40
|
-
getSessionVersion: () => number;
|
|
41
|
-
/**
|
|
42
|
-
* Used to increment the session version.
|
|
43
|
-
* If version is undefined, the version will be incremented by 1.
|
|
44
|
-
* If version is greater than the current version, the version will be set to the new value.
|
|
45
|
-
*/
|
|
46
|
-
incrementSessionVersion: (version?: number) => void;
|
|
47
|
-
/**
|
|
48
|
-
* The name of the project folder.
|
|
49
|
-
* Used to differentiate between multiple projects.
|
|
50
|
-
*/
|
|
51
|
-
projectName: string;
|
|
52
|
-
/**
|
|
53
|
-
* The version of each target.
|
|
54
|
-
* Used to force a client cache refresh on a single target.
|
|
55
|
-
*/
|
|
56
|
-
targetVersions: Record<string, number>;
|
|
57
|
-
/**
|
|
58
|
-
* Increments the version for the given target.
|
|
59
|
-
*/
|
|
60
|
-
incrementTargetVersion: (inputPath: string) => void;
|
|
61
|
-
/**
|
|
62
|
-
* The import map for the session.
|
|
63
|
-
*/
|
|
64
|
-
getImportMap: () => ImportMap | undefined;
|
|
65
|
-
setImportMap: (newImportMap: ImportMap) => ImportMap;
|
|
66
|
-
}
|
|
3
|
+
import type { Route } from '@ms-cloudpack/config';
|
|
4
|
+
import type { Session } from '@ms-cloudpack/api-server';
|
|
67
5
|
/**
|
|
68
6
|
* Tracks a given bundle request and its result.
|
|
69
7
|
*/
|
|
@@ -78,6 +16,7 @@ export interface BundleRequest {
|
|
|
78
16
|
result?: BundleResult;
|
|
79
17
|
resultFromCache?: boolean;
|
|
80
18
|
isRebuildRequired?: boolean;
|
|
19
|
+
disableSourceMaps?: boolean;
|
|
81
20
|
packages?: PackageDefinitionsCache;
|
|
82
21
|
}
|
|
83
22
|
export interface BundleTaskOptions {
|
|
@@ -88,146 +27,14 @@ export interface BundleServer {
|
|
|
88
27
|
port: number;
|
|
89
28
|
close: () => Promise<void>;
|
|
90
29
|
}
|
|
91
|
-
export interface SessionStats {
|
|
92
|
-
status: 'idle' | 'pending';
|
|
93
|
-
remainingTasks: number;
|
|
94
|
-
totalTasks: number;
|
|
95
|
-
totalErrors: number;
|
|
96
|
-
totalWarnings: number;
|
|
97
|
-
}
|
|
98
|
-
export interface ApiServer {
|
|
99
|
-
url: string;
|
|
100
|
-
port: number;
|
|
101
|
-
notifyReload: () => void;
|
|
102
|
-
addTask: <TReturn>(task: Task<TReturn>, options?: TaskOptions) => Promise<TReturn>;
|
|
103
|
-
close: () => Promise<void>;
|
|
104
|
-
}
|
|
105
|
-
export interface Watcher {
|
|
106
|
-
watch: (bundleRequest: BundleRequest) => void;
|
|
107
|
-
}
|
|
108
|
-
export interface TaskError {
|
|
109
|
-
message: string;
|
|
110
|
-
pluginName: string;
|
|
111
|
-
stack: string;
|
|
112
|
-
fileLocation: string;
|
|
113
|
-
lineNumber: number;
|
|
114
|
-
columnNumber: number;
|
|
115
|
-
}
|
|
116
|
-
export interface TaskStartDescription {
|
|
117
|
-
id: string;
|
|
118
|
-
name?: string;
|
|
119
|
-
inputPath?: string;
|
|
120
|
-
outputPath?: string;
|
|
121
|
-
}
|
|
122
|
-
export interface TaskEndDescription {
|
|
123
|
-
id: string;
|
|
124
|
-
errors?: TaskError[];
|
|
125
|
-
warnings?: TaskError[];
|
|
126
|
-
}
|
|
127
|
-
export interface TaskDescription extends TaskStartDescription, TaskEndDescription {
|
|
128
|
-
status: 'pending' | 'complete';
|
|
129
|
-
startTime: number;
|
|
130
|
-
durationMilliseconds?: number;
|
|
131
|
-
lastUpdated?: number;
|
|
132
|
-
}
|
|
133
|
-
export interface Task<TReturn> {
|
|
134
|
-
name: string;
|
|
135
|
-
id: string;
|
|
136
|
-
dir?: string;
|
|
137
|
-
execute: () => Promise<TReturn | undefined>;
|
|
138
|
-
clear?: () => void;
|
|
139
|
-
watch?: boolean;
|
|
140
|
-
dispose?: () => Promise<void>;
|
|
141
|
-
onDispose?: () => void;
|
|
142
|
-
getErrors?: () => TaskError[] | undefined;
|
|
143
|
-
getStartDescription?: () => TaskStartDescription;
|
|
144
|
-
getEndDescription?: (result: TReturn | undefined) => TaskEndDescription;
|
|
145
|
-
}
|
|
146
|
-
export interface TaskOptions {
|
|
147
|
-
rerun?: boolean;
|
|
148
|
-
watch?: () => void;
|
|
149
|
-
}
|
|
150
30
|
export interface PackageOverride {
|
|
151
31
|
name: string;
|
|
152
32
|
versionRequirement: string;
|
|
153
33
|
isInternal?: boolean;
|
|
154
34
|
overrides: PackageJson;
|
|
155
35
|
}
|
|
156
|
-
export interface
|
|
157
|
-
|
|
158
|
-
* The url path part to match. Start paths with a leading slash, e.g. `'/my-route'`. You can also
|
|
159
|
-
* use wildcards (`*`), e.g. `'/my-route/*'` to match all paths starting with `'/my-route'`.
|
|
160
|
-
*/
|
|
161
|
-
match: string;
|
|
162
|
-
/**
|
|
163
|
-
* The path relative to the app root to static assets. If this is provided, renderScript/exportEntry
|
|
164
|
-
* will be ignored.
|
|
165
|
-
*/
|
|
166
|
-
staticPath?: string;
|
|
167
|
-
/**
|
|
168
|
-
* Path to a .js or .html file used for rendering the route. If a script is provided, it must
|
|
169
|
-
* export a default function implementing `CreateHtmlFunction` defined in `@ms-cloudpack/cli`.
|
|
170
|
-
*/
|
|
171
|
-
renderScript?: string;
|
|
172
|
-
/**
|
|
173
|
-
* The key in the exports map which represents the entry point app script for this route.
|
|
174
|
-
* Default is '.', meaning the main package export key.
|
|
175
|
-
*/
|
|
176
|
-
exportEntry?: string;
|
|
177
|
-
}
|
|
178
|
-
export interface DevServer {
|
|
179
|
-
/**
|
|
180
|
-
* The domain name of the server.
|
|
181
|
-
*/
|
|
182
|
-
domain?: string;
|
|
183
|
-
/**
|
|
184
|
-
* The ports to be used by the server.
|
|
185
|
-
* It can be a number or an array of numbers.
|
|
186
|
-
* If ports are provided, an error will be thrown if none are available.
|
|
187
|
-
* If no ports are provided, the server will attempt to find an available port.
|
|
188
|
-
*/
|
|
189
|
-
port?: number | number[];
|
|
190
|
-
/**
|
|
191
|
-
* The config settings for the https server.
|
|
192
|
-
* Paths to files are accepted for 'ca', 'cert', 'key', and 'pfx' settings.
|
|
193
|
-
* Everything else is passed directly to the https.createServer() method.
|
|
194
|
-
* If not provided, the server will use http.
|
|
195
|
-
*/
|
|
196
|
-
https?: HttpsConfig;
|
|
197
|
-
/**
|
|
198
|
-
* If provided, will override where the publicDir is located, relative to the app package folder.
|
|
199
|
-
* Defaults to `./public`. The same thing can be achieved with `routes`, using route: '*' and
|
|
200
|
-
* staticPath: './public', so the `publicPath` setting may be removed in the future.
|
|
201
|
-
*/
|
|
202
|
-
publicPath?: string;
|
|
203
|
-
/**
|
|
204
|
-
* If provided, will register routes with the dev server to host various pages.
|
|
205
|
-
*/
|
|
206
|
-
routes?: Route[];
|
|
207
|
-
}
|
|
208
|
-
export interface TelemetryConfig {
|
|
209
|
-
/**
|
|
210
|
-
* Application Insights instrumentation key.
|
|
211
|
-
*/
|
|
212
|
-
instrumentationKey: string;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Per-application configuration for Cloudpack.
|
|
216
|
-
*/
|
|
217
|
-
export interface CloudpackConfig {
|
|
218
|
-
/**
|
|
219
|
-
* An array of PackageOverride objects, used to provide overrides for packages without modifying their
|
|
220
|
-
* definitions directly. This is primarily used for providing exports maps for packages that don't have them.
|
|
221
|
-
*/
|
|
222
|
-
packageOverrides?: PackageOverride[];
|
|
223
|
-
/**
|
|
224
|
-
* A set of options for configuring how the dev server works.
|
|
225
|
-
*/
|
|
226
|
-
devServer?: DevServer;
|
|
227
|
-
/**
|
|
228
|
-
* A set of options for configuring telemetry
|
|
229
|
-
*/
|
|
230
|
-
telemetry?: TelemetryConfig;
|
|
36
|
+
export interface Watcher {
|
|
37
|
+
watch: (bundleRequest: BundleRequest) => void;
|
|
231
38
|
}
|
|
232
39
|
/**
|
|
233
40
|
* The input options for a createHtml custom server render function.
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/package-utilities';\nimport type { BundleResult, PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { Route } from '@ms-cloudpack/config';\nimport type { Session } from '@ms-cloudpack/api-server';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n id: string;\n packageName: string;\n version: string;\n packagePath: string;\n outputPath: string;\n isExternal: boolean;\n bundlerType?: string;\n result?: BundleResult;\n resultFromCache?: boolean;\n isRebuildRequired?: boolean;\n disableSourceMaps?: boolean;\n packages?: PackageDefinitionsCache;\n}\n\nexport interface BundleTaskOptions {\n force?: boolean;\n}\n\nexport interface BundleServer {\n url: string;\n port: number;\n close: () => Promise<void>;\n}\n\nexport interface PackageOverride {\n name: string;\n versionRequirement: string;\n isInternal?: boolean;\n overrides: PackageJson;\n}\n\nexport interface Watcher {\n watch: (bundleRequest: BundleRequest) => void;\n}\n\n/**\n * The input options for a createHtml custom server render function.\n */\nexport type CreateHtmlOptions = {\n session: Session;\n route: Route;\n baseUrl: string;\n definition: PackageJson;\n importMap: ImportMap;\n overlayScript: string | undefined;\n entryScript: string | undefined;\n inlineScripts: string[];\n};\n\n/**\n * The expected result of the createHtml custom server render function.\n */\nexport type CreateHtmlResult =\n | string\n | {\n html: string;\n statusCode: number;\n };\n\n/**\n * A custom server render function that can be used to override the default HTML response.\n */\nexport type CreateHtmlFunction = (options: CreateHtmlOptions) => Promise<CreateHtmlResult> | CreateHtmlResult;\n\n/**\n * The expected shape of the createHtml custom server render function script.\n */\nexport type CreateHtmlScript = { default: CreateHtmlFunction };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.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,16 +16,18 @@
|
|
|
16
16
|
"cloudpack": "./bin/cloudpack.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ms-cloudpack/
|
|
19
|
+
"@ms-cloudpack/api-server": "^0.3.0",
|
|
20
|
+
"@ms-cloudpack/bundler": "^0.11.19",
|
|
21
|
+
"@ms-cloudpack/config": "^0.3.0",
|
|
20
22
|
"@ms-cloudpack/create-express-app": "^1.3.0",
|
|
21
23
|
"@ms-cloudpack/data-bus": "^0.1.1",
|
|
22
24
|
"@ms-cloudpack/json-utilities": "^0.0.5",
|
|
23
|
-
"@ms-cloudpack/overlay": "^0.
|
|
24
|
-
"@ms-cloudpack/package-utilities": "^2.3.
|
|
25
|
+
"@ms-cloudpack/overlay": "^0.13.0",
|
|
26
|
+
"@ms-cloudpack/package-utilities": "^2.3.11",
|
|
25
27
|
"@ms-cloudpack/path-utilities": "^2.1.1",
|
|
26
28
|
"@ms-cloudpack/path-string-parsing": "^1.0.1",
|
|
27
29
|
"@ms-cloudpack/task-reporter": "^0.3.0",
|
|
28
|
-
"@ms-cloudpack/telemetry": "^0.2.
|
|
30
|
+
"@ms-cloudpack/telemetry": "^0.2.2",
|
|
29
31
|
"chokidar": "^3.5.3",
|
|
30
32
|
"commander": "^10.0.0",
|
|
31
33
|
"es-module-lexer": "^1.0.3",
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Task, TaskOptions } from '../../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* TaskRunner class manages the state of Tasks.
|
|
4
|
-
* This class is to be called by the api server.
|
|
5
|
-
*/
|
|
6
|
-
export declare class TaskRunner {
|
|
7
|
-
private _queue;
|
|
8
|
-
private _pendingTasks;
|
|
9
|
-
private _completedTasks;
|
|
10
|
-
private _requiresRerun;
|
|
11
|
-
private _prevTasks;
|
|
12
|
-
constructor();
|
|
13
|
-
/**
|
|
14
|
-
* The add method enqueues a Task and returns its Promise.
|
|
15
|
-
* If a Task with the same id has already been processed,
|
|
16
|
-
* it returns either the result or the promise.
|
|
17
|
-
* Rerun flag forces the Task to be run again.
|
|
18
|
-
*/
|
|
19
|
-
add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn>;
|
|
20
|
-
/**
|
|
21
|
-
* The reset method removes a task from the TaskRunner
|
|
22
|
-
* and then adds it again through a previous execute function.
|
|
23
|
-
*
|
|
24
|
-
* This is useful for when a task needs to be forcibly rerun.
|
|
25
|
-
*
|
|
26
|
-
* It is intented to be used by the api server
|
|
27
|
-
* to rerun a task when it is stuck or it failed.
|
|
28
|
-
*/
|
|
29
|
-
reset<TReturn>(id: string): Promise<TReturn>;
|
|
30
|
-
/**
|
|
31
|
-
* The remove method disposes a task if available
|
|
32
|
-
* and then removes it from the TaskRunner.
|
|
33
|
-
*
|
|
34
|
-
* This is useful when the state of a task needs to be cleared.
|
|
35
|
-
*
|
|
36
|
-
* It is intented to be used by the api server
|
|
37
|
-
* to clear the TaskRunner's state before reloading the page.
|
|
38
|
-
*/
|
|
39
|
-
remove(id: string): void;
|
|
40
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import PQueue from 'p-queue';
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
-
const log = (...messages) => {
|
|
4
|
-
// console.log(`TaskRunner:`, ...messages);
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* TaskRunner class manages the state of Tasks.
|
|
8
|
-
* This class is to be called by the api server.
|
|
9
|
-
*/
|
|
10
|
-
export class TaskRunner {
|
|
11
|
-
constructor() {
|
|
12
|
-
this._queue = new PQueue({ concurrency: 10 });
|
|
13
|
-
this._pendingTasks = new Map();
|
|
14
|
-
this._completedTasks = new Map();
|
|
15
|
-
this._requiresRerun = new Set();
|
|
16
|
-
this._prevTasks = new Map();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The add method enqueues a Task and returns its Promise.
|
|
20
|
-
* If a Task with the same id has already been processed,
|
|
21
|
-
* it returns either the result or the promise.
|
|
22
|
-
* Rerun flag forces the Task to be run again.
|
|
23
|
-
*/
|
|
24
|
-
add(task, options) {
|
|
25
|
-
const { name, id, execute } = task;
|
|
26
|
-
const { rerun, watch } = options || {};
|
|
27
|
-
watch?.();
|
|
28
|
-
if (!this._prevTasks.get(id)) {
|
|
29
|
-
this._prevTasks.set(id, task);
|
|
30
|
-
}
|
|
31
|
-
// Check if we are already completed the task with that id.
|
|
32
|
-
const action = this._completedTasks.get(id);
|
|
33
|
-
if (action !== undefined && !rerun) {
|
|
34
|
-
log(`Previous action found, returning: "${name}:${id}"`);
|
|
35
|
-
return Promise.resolve(action);
|
|
36
|
-
}
|
|
37
|
-
// Check if we are already running the task with that id.
|
|
38
|
-
const pending = this._pendingTasks.get(id);
|
|
39
|
-
if (pending !== undefined) {
|
|
40
|
-
if (rerun) {
|
|
41
|
-
this._requiresRerun.add(id);
|
|
42
|
-
}
|
|
43
|
-
log(`Previous action found, waiting: "${name}:${id}"`);
|
|
44
|
-
return pending;
|
|
45
|
-
}
|
|
46
|
-
const resultPromise = (async () => {
|
|
47
|
-
let taskResult;
|
|
48
|
-
let taskError;
|
|
49
|
-
let completed = false;
|
|
50
|
-
do {
|
|
51
|
-
// Delete from rerun list (if present).
|
|
52
|
-
this._requiresRerun.delete(id);
|
|
53
|
-
try {
|
|
54
|
-
// TODO: possibly remove cast once this issue is resolved
|
|
55
|
-
// https://github.com/sindresorhus/p-queue/issues/175
|
|
56
|
-
taskResult = (await this._queue.add(execute));
|
|
57
|
-
completed = true;
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
// Save the error--it will be thrown later if a rerun was not requested.
|
|
61
|
-
taskError = err;
|
|
62
|
-
}
|
|
63
|
-
} while (this._requiresRerun.has(id));
|
|
64
|
-
log(`Task finished: "${name}:${id}"`);
|
|
65
|
-
// Delete from pending list.
|
|
66
|
-
this._pendingTasks.delete(id);
|
|
67
|
-
if (completed) {
|
|
68
|
-
// Update finished Tasks.
|
|
69
|
-
this._completedTasks.set(id, taskResult);
|
|
70
|
-
// Resolve the promise.
|
|
71
|
-
return taskResult;
|
|
72
|
-
}
|
|
73
|
-
// If the task never completed successfully, throw the error from earlier.
|
|
74
|
-
throw taskError;
|
|
75
|
-
})();
|
|
76
|
-
this._pendingTasks.set(id, resultPromise);
|
|
77
|
-
this._completedTasks.delete(id);
|
|
78
|
-
return resultPromise;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* The reset method removes a task from the TaskRunner
|
|
82
|
-
* and then adds it again through a previous execute function.
|
|
83
|
-
*
|
|
84
|
-
* This is useful for when a task needs to be forcibly rerun.
|
|
85
|
-
*
|
|
86
|
-
* It is intented to be used by the api server
|
|
87
|
-
* to rerun a task when it is stuck or it failed.
|
|
88
|
-
*/
|
|
89
|
-
reset(id) {
|
|
90
|
-
this.remove(id);
|
|
91
|
-
const prevTask = this._prevTasks.get(id);
|
|
92
|
-
if (prevTask === undefined) {
|
|
93
|
-
throw new Error(`Task not found: ${id}`);
|
|
94
|
-
}
|
|
95
|
-
return this.add(prevTask, { rerun: true });
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The remove method disposes a task if available
|
|
99
|
-
* and then removes it from the TaskRunner.
|
|
100
|
-
*
|
|
101
|
-
* This is useful when the state of a task needs to be cleared.
|
|
102
|
-
*
|
|
103
|
-
* It is intented to be used by the api server
|
|
104
|
-
* to clear the TaskRunner's state before reloading the page.
|
|
105
|
-
*/
|
|
106
|
-
remove(id) {
|
|
107
|
-
this._prevTasks
|
|
108
|
-
.get(id)
|
|
109
|
-
?.dispose?.()
|
|
110
|
-
.catch(() => {
|
|
111
|
-
log(`Error disposing task: ${id}`);
|
|
112
|
-
});
|
|
113
|
-
this._prevTasks.get(id)?.clear?.();
|
|
114
|
-
this._requiresRerun.delete(id);
|
|
115
|
-
this._pendingTasks.delete(id);
|
|
116
|
-
this._completedTasks.delete(id);
|
|
117
|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@typescript-eslint/no-unused-vars\nconst log = (...messages: unknown[]) => {\n // console.log(`TaskRunner:`, ...messages);\n};\n\n/**\n * TaskRunner class manages the state of Tasks.\n * This class is to be called by the api server.\n */\nexport class TaskRunner {\n private _queue: PQueue;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _pendingTasks: Map<string, Promise<any>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _completedTasks: Map<string, any>;\n private _requiresRerun: Set<string>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private _prevTasks: Map<string, Task<any>>;\n\n constructor() {\n this._queue = new PQueue({ concurrency: 10 });\n this._pendingTasks = new Map();\n this._completedTasks = new Map();\n this._requiresRerun = new Set();\n this._prevTasks = new Map();\n }\n\n /**\n * The add method enqueues a Task and returns its Promise.\n * If a Task with the same id has already been processed,\n * it returns either the result or the promise.\n * Rerun flag forces the Task to be run again.\n */\n add<TReturn>(task: Task<TReturn>, options?: TaskOptions): Promise<TReturn> {\n const { name, id, execute } = task;\n const { rerun, watch } = options || {};\n\n watch?.();\n\n if (!this._prevTasks.get(id)) {\n this._prevTasks.set(id, task);\n }\n\n // Check if we are already completed the task with that id.\n const action = this._completedTasks.get(id) as TReturn | undefined;\n if (action !== undefined && !rerun) {\n log(`Previous action found, returning: \"${name}:${id}\"`);\n return Promise.resolve(action);\n }\n\n // Check if we are already running the task with that id.\n const pending = this._pendingTasks.get(id) as Promise<TReturn> | undefined;\n if (pending !== undefined) {\n if (rerun) {\n this._requiresRerun.add(id);\n }\n log(`Previous action found, waiting: \"${name}:${id}\"`);\n return pending;\n }\n\n const resultPromise = (async () => {\n let taskResult: TReturn | undefined;\n let taskError: unknown;\n let completed = false;\n\n do {\n // Delete from rerun list (if present).\n this._requiresRerun.delete(id);\n try {\n // TODO: possibly remove cast once this issue is resolved\n // https://github.com/sindresorhus/p-queue/issues/175\n taskResult = (await this._queue.add(execute)) as TReturn | undefined;\n completed = true;\n } catch (err) {\n // Save the error--it will be thrown later if a rerun was not requested.\n taskError = err;\n }\n } while (this._requiresRerun.has(id));\n\n log(`Task finished: \"${name}:${id}\"`);\n\n // Delete from pending list.\n this._pendingTasks.delete(id);\n\n if (completed) {\n // Update finished Tasks.\n this._completedTasks.set(id, taskResult);\n // Resolve the promise.\n return taskResult as TReturn;\n }\n\n // If the task never completed successfully, throw the error from earlier.\n throw taskError;\n })();\n\n this._pendingTasks.set(id, resultPromise);\n this._completedTasks.delete(id);\n\n return resultPromise;\n }\n\n /**\n * The reset method removes a task from the TaskRunner\n * and then adds it again through a previous execute function.\n *\n * This is useful for when a task needs to be forcibly rerun.\n *\n * It is intented to be used by the api server\n * to rerun a task when it is stuck or it failed.\n */\n reset<TReturn>(id: string): Promise<TReturn> {\n this.remove(id);\n const prevTask = this._prevTasks.get(id);\n if (prevTask === undefined) {\n throw new Error(`Task not found: ${id}`);\n }\n return <Promise<TReturn>>this.add(prevTask, { rerun: true });\n }\n\n /**\n * The remove method disposes a task if available\n * and then removes it from the TaskRunner.\n *\n * This is useful when the state of a task needs to be cleared.\n *\n * It is intented to be used by the api server\n * to clear the TaskRunner's state before reloading the page.\n */\n remove(id: string): void {\n this._prevTasks\n .get(id)\n ?.dispose?.()\n .catch(() => {\n log(`Error disposing task: ${id}`);\n });\n this._prevTasks.get(id)?.clear?.();\n this._requiresRerun.delete(id);\n this._pendingTasks.delete(id);\n this._completedTasks.delete(id);\n }\n}\n"]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import semver from 'semver';
|
|
2
|
-
import { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';
|
|
3
|
-
import { addExportsMapEntry, findResolveMapEntry, getExportsMap, PackageDefinitions, } from '@ms-cloudpack/package-utilities';
|
|
4
|
-
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
5
|
-
import { parseRequestInfo } from './parseRequestInfo.js';
|
|
6
|
-
import { readConfig, writeConfig } from '../../common/config.js';
|
|
7
|
-
export async function addOverride({ session, packageName, importPath, filename, }) {
|
|
8
|
-
let definition = undefined;
|
|
9
|
-
if (filename) {
|
|
10
|
-
const requestPath = slash(new URL(filename).pathname);
|
|
11
|
-
const { packageName: name, version } = parseRequestInfo(requestPath);
|
|
12
|
-
definition = { name, version };
|
|
13
|
-
}
|
|
14
|
-
const entry = findResolveMapEntry({
|
|
15
|
-
packageName,
|
|
16
|
-
resolveMap: session.resolveMap,
|
|
17
|
-
definition,
|
|
18
|
-
});
|
|
19
|
-
if (entry === undefined) {
|
|
20
|
-
console.error(`Could not find entry of package ${packageName} in resolve map`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const exports = (await getExportsMap(entry.path));
|
|
24
|
-
await addExportsMapEntry({
|
|
25
|
-
exports,
|
|
26
|
-
packagePath: entry.path,
|
|
27
|
-
importPath,
|
|
28
|
-
});
|
|
29
|
-
const packageOverride = {
|
|
30
|
-
name: packageName,
|
|
31
|
-
versionRequirement: entry.version,
|
|
32
|
-
overrides: {
|
|
33
|
-
exports,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
// Parse config if it exists.
|
|
37
|
-
const cloudpackConfig = await readConfig(session.appPath);
|
|
38
|
-
// Add package override to config.
|
|
39
|
-
if (!cloudpackConfig.packageOverrides) {
|
|
40
|
-
cloudpackConfig.packageOverrides = [packageOverride];
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
// Check if override already exists.
|
|
44
|
-
const existingOverride = cloudpackConfig.packageOverrides.find((o) => o.name === packageOverride.name && semver.satisfies(packageOverride.versionRequirement, o.versionRequirement));
|
|
45
|
-
if (existingOverride) {
|
|
46
|
-
// Update existing override.
|
|
47
|
-
existingOverride.overrides = packageOverride.overrides;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Add new override.
|
|
51
|
-
cloudpackConfig.packageOverrides.push(packageOverride);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// Write config.
|
|
55
|
-
await writeConfig(cloudpackConfig, session.appPath);
|
|
56
|
-
console.debug(`Added override for ${packageName} to cloudpack config`);
|
|
57
|
-
const override = {
|
|
58
|
-
packageOverrides: [packageOverride],
|
|
59
|
-
};
|
|
60
|
-
// Initialize package overrides.
|
|
61
|
-
PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(override));
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=addOverride.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../../../src/commands/start/addOverride.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,gDAAgD,CAAC;AAChG,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,EAChC,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,GAMT;IACC,IAAI,UAAU,GAAG,SAAS,CAAC;IAE3B,IAAI,QAAQ,EAAE;QACZ,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC;QACtD,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACrE,UAAU,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;KAChC;IAED,MAAM,KAAK,GAAG,mBAAmB,CAAC;QAChC,WAAW;QACX,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,KAAK,KAAK,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,QAAQ,GAAoB;QAChC,gBAAgB,EAAE,CAAC,eAAe,CAAC;KACpC,CAAC;IAEF,gCAAgC;IAChC,kBAAkB,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC,8BAA8B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import semver from 'semver';\nimport { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n getExportsMap,\n PackageDefinitions,\n} from '@ms-cloudpack/package-utilities';\nimport type { CloudpackConfig, Session, PackageOverride } from '../../types.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { readConfig, writeConfig } from '../../common/config.js';\n\nexport async function addOverride({\n session,\n packageName,\n importPath,\n filename,\n}: {\n session: Session;\n packageName: string;\n importPath: string;\n filename?: string;\n}) {\n let definition = undefined;\n\n if (filename) {\n const requestPath = slash(new URL(filename).pathname);\n const { packageName: name, version } = parseRequestInfo(requestPath);\n definition = { name, version };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition,\n });\n\n if (entry === undefined) {\n console.error(`Could not find entry of package ${packageName} in resolve map`);\n return;\n }\n\n const exports = (await getExportsMap(entry.path)) as Record<string, Record<string, string>>;\n\n await addExportsMapEntry({\n exports,\n packagePath: entry.path,\n importPath,\n });\n\n const packageOverride: PackageOverride = {\n name: packageName,\n versionRequirement: entry.version,\n overrides: {\n exports,\n },\n };\n\n // Parse config if it exists.\n const cloudpackConfig = await readConfig(session.appPath);\n\n // Add package override to config.\n if (!cloudpackConfig.packageOverrides) {\n cloudpackConfig.packageOverrides = [packageOverride];\n } else {\n // Check if override already exists.\n const existingOverride = cloudpackConfig.packageOverrides.find(\n (o) =>\n o.name === packageOverride.name && semver.satisfies(packageOverride.versionRequirement, o.versionRequirement),\n );\n\n if (existingOverride) {\n // Update existing override.\n existingOverride.overrides = packageOverride.overrides;\n } else {\n // Add new override.\n cloudpackConfig.packageOverrides.push(packageOverride);\n }\n }\n\n // Write config.\n await writeConfig(cloudpackConfig, session.appPath);\n console.debug(`Added override for ${packageName} to cloudpack config`);\n\n const override: CloudpackConfig = {\n packageOverrides: [packageOverride],\n };\n\n // Initialize package overrides.\n PackageDefinitions.getInstance().registerTransform(createPackageOverrideTransform(override));\n}\n"]}
|