@ms-cloudpack/cli 0.45.3 → 0.46.1
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/execute.d.ts +4 -0
- package/lib/commands/bundle/execute.d.ts.map +1 -0
- package/lib/commands/bundle/{bundle.js → execute.js} +14 -15
- package/lib/commands/bundle/execute.js.map +1 -0
- package/lib/commands/bundle/index.d.ts.map +1 -1
- package/lib/commands/bundle/index.js +4 -2
- package/lib/commands/bundle/index.js.map +1 -1
- package/lib/commands/init/bundleAndGetImports.d.ts.map +1 -1
- package/lib/commands/init/bundleAndGetImports.js +3 -1
- package/lib/commands/init/bundleAndGetImports.js.map +1 -1
- package/lib/commands/init/execute.d.ts +5 -0
- package/lib/commands/init/execute.d.ts.map +1 -0
- package/lib/commands/init/execute.js +14 -0
- package/lib/commands/init/execute.js.map +1 -0
- package/lib/commands/init/index.d.ts.map +1 -1
- package/lib/commands/init/index.js +4 -2
- package/lib/commands/init/index.js.map +1 -1
- package/lib/commands/init/init.d.ts +11 -5
- package/lib/commands/init/init.d.ts.map +1 -1
- package/lib/commands/init/init.js +79 -102
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/start/{start.d.ts → execute.d.ts} +3 -3
- package/lib/commands/start/execute.d.ts.map +1 -0
- package/lib/commands/start/execute.js +127 -0
- package/lib/commands/start/execute.js.map +1 -0
- package/lib/commands/start/index.d.ts.map +1 -1
- package/lib/commands/start/index.js +4 -2
- package/lib/commands/start/index.js.map +1 -1
- package/lib/commands/start/startBundleServer.d.ts +1 -1
- package/lib/commands/start/startBundleServer.d.ts.map +1 -1
- package/lib/commands/start/startBundleServer.js +6 -19
- package/lib/commands/start/startBundleServer.js.map +1 -1
- package/lib/commands/sync/execute.d.ts +4 -0
- package/lib/commands/sync/execute.d.ts.map +1 -0
- package/lib/commands/sync/execute.js +31 -0
- package/lib/commands/sync/execute.js.map +1 -0
- package/lib/commands/sync/index.d.ts.map +1 -1
- package/lib/commands/sync/index.js +4 -5
- package/lib/commands/sync/index.js.map +1 -1
- package/lib/common/AutoDisposableList.d.ts +7 -0
- package/lib/common/AutoDisposableList.d.ts.map +1 -0
- package/lib/common/AutoDisposableList.js +17 -0
- package/lib/common/AutoDisposableList.js.map +1 -0
- package/lib/common/createCommandActionFunction.d.ts +14 -0
- package/lib/common/createCommandActionFunction.d.ts.map +1 -0
- package/lib/common/createCommandActionFunction.js +66 -0
- package/lib/common/createCommandActionFunction.js.map +1 -0
- package/lib/common/createExitFunction.d.ts +12 -0
- package/lib/common/createExitFunction.d.ts.map +1 -0
- package/lib/common/createExitFunction.js +17 -0
- package/lib/common/createExitFunction.js.map +1 -0
- package/lib/common/createInitializeFunction.d.ts +10 -0
- package/lib/common/createInitializeFunction.d.ts.map +1 -0
- package/lib/common/createInitializeFunction.js +21 -0
- package/lib/common/createInitializeFunction.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -5
- package/lib/index.js.map +1 -1
- package/lib/initTelemetry.js +1 -1
- package/lib/initTelemetry.js.map +1 -1
- package/lib/performance/markers.d.ts +0 -16
- package/lib/performance/markers.d.ts.map +1 -1
- package/lib/performance/markers.js +0 -16
- package/lib/performance/markers.js.map +1 -1
- package/lib/performance/registerPerformanceObservers.d.ts +2 -2
- package/lib/performance/registerPerformanceObservers.d.ts.map +1 -1
- package/lib/performance/registerPerformanceObservers.js +5 -8
- package/lib/performance/registerPerformanceObservers.js.map +1 -1
- package/lib/setupReporting.d.ts +7 -2
- package/lib/setupReporting.d.ts.map +1 -1
- package/lib/setupReporting.js +3 -2
- package/lib/setupReporting.js.map +1 -1
- package/lib/tasks/bundleTaskWorker.d.ts.map +1 -1
- package/lib/tasks/bundleTaskWorker.js +6 -2
- package/lib/tasks/bundleTaskWorker.js.map +1 -1
- package/lib/types/AutoDispose.d.ts +3 -0
- package/lib/types/AutoDispose.d.ts.map +1 -0
- package/lib/types/AutoDispose.js +2 -0
- package/lib/types/AutoDispose.js.map +1 -0
- package/lib/types/CommandAction.d.ts +21 -0
- package/lib/types/CommandAction.d.ts.map +1 -0
- package/lib/types/CommandAction.js +2 -0
- package/lib/types/CommandAction.js.map +1 -0
- package/lib/types/CommandContext.d.ts +10 -0
- package/lib/types/CommandContext.d.ts.map +1 -0
- package/lib/types/CommandContext.js +2 -0
- package/lib/types/CommandContext.js.map +1 -0
- package/lib/types/CommandFunction.d.ts +2 -2
- package/lib/types/CommandFunction.d.ts.map +1 -1
- package/lib/types/CommandFunction.js.map +1 -1
- package/lib/types/CreateCommandActionOptions.d.ts +7 -0
- package/lib/types/CreateCommandActionOptions.d.ts.map +1 -0
- package/lib/types/CreateCommandActionOptions.js +2 -0
- package/lib/types/CreateCommandActionOptions.js.map +1 -0
- package/lib/types/Disposable.d.ts +4 -0
- package/lib/types/Disposable.d.ts.map +1 -0
- package/lib/types/Disposable.js +2 -0
- package/lib/types/Disposable.js.map +1 -0
- package/package.json +8 -11
- package/lib/commands/bundle/bundle.d.ts +0 -4
- package/lib/commands/bundle/bundle.d.ts.map +0 -1
- package/lib/commands/bundle/bundle.js.map +0 -1
- package/lib/commands/start/parseRequestInfo.d.ts +0 -7
- package/lib/commands/start/parseRequestInfo.d.ts.map +0 -1
- package/lib/commands/start/parseRequestInfo.js +0 -14
- package/lib/commands/start/parseRequestInfo.js.map +0 -1
- package/lib/commands/start/start.d.ts.map +0 -1
- package/lib/commands/start/start.js +0 -149
- package/lib/commands/start/start.js.map +0 -1
- package/lib/commands/sync/sync.d.ts +0 -4
- package/lib/commands/sync/sync.d.ts.map +0 -1
- package/lib/commands/sync/sync.js +0 -53
- package/lib/commands/sync/sync.js.map +0 -1
- package/lib/common/createPartialApiContext.d.ts +0 -14
- package/lib/common/createPartialApiContext.d.ts.map +0 -1
- package/lib/common/createPartialApiContext.js +0 -101
- package/lib/common/createPartialApiContext.js.map +0 -1
- package/lib/common/createSession.d.ts +0 -13
- package/lib/common/createSession.d.ts.map +0 -1
- package/lib/common/createSession.js +0 -62
- package/lib/common/createSession.js.map +0 -1
- package/lib/common/prepareOutputPath.d.ts +0 -5
- package/lib/common/prepareOutputPath.d.ts.map +0 -1
- package/lib/common/prepareOutputPath.js +0 -14
- package/lib/common/prepareOutputPath.js.map +0 -1
- package/lib/tasks/resolveDependenciesTask.d.ts +0 -16
- package/lib/tasks/resolveDependenciesTask.d.ts.map +0 -1
- package/lib/tasks/resolveDependenciesTask.js +0 -69
- package/lib/tasks/resolveDependenciesTask.js.map +0 -1
- package/lib/types/TaskContext.d.ts +0 -8
- package/lib/types/TaskContext.d.ts.map +0 -1
- package/lib/types/TaskContext.js +0 -2
- package/lib/types/TaskContext.js.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createPackageDefinitions } from '@ms-cloudpack/config';
|
|
2
|
+
import { writeJson } from '@ms-cloudpack/json-utilities';
|
|
3
|
+
import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { openBrowser } from './openBrowser.js';
|
|
6
|
+
import { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';
|
|
7
|
+
import { createBundleRequestForPackage, createBundleTask, createSession } from '@ms-cloudpack/api-server';
|
|
8
|
+
import { mergeFeatures } from './mergeFeatures.js';
|
|
9
|
+
import { yellow } from '@ms-cloudpack/task-reporter';
|
|
10
|
+
import { runPrereqs } from './runPrereqs.js';
|
|
11
|
+
import { getStartingAppPath } from './getStartingAppPath.js';
|
|
12
|
+
let cleanupFunctions = [];
|
|
13
|
+
/** Stop all started cloudpack instances, for testing */
|
|
14
|
+
export async function stopServers() {
|
|
15
|
+
for (const func of cleanupFunctions) {
|
|
16
|
+
await func();
|
|
17
|
+
}
|
|
18
|
+
cleanupFunctions = [];
|
|
19
|
+
}
|
|
20
|
+
async function createAppBundleTask(options, context) {
|
|
21
|
+
const { packageName } = options;
|
|
22
|
+
const { session, config, packages } = context;
|
|
23
|
+
const { resolveMap } = session;
|
|
24
|
+
const packageEntry = findResolveMapEntry({
|
|
25
|
+
packageName,
|
|
26
|
+
resolveMap,
|
|
27
|
+
});
|
|
28
|
+
if (!packageEntry) {
|
|
29
|
+
throw new Error(`Could not find package ${packageName} in the resolve map.`);
|
|
30
|
+
}
|
|
31
|
+
const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages, resolveMap });
|
|
32
|
+
return createBundleTask({ bundleRequest, resolveMap });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Defines the "start" verb entry point.
|
|
36
|
+
*/
|
|
37
|
+
export const execute = async ({ options, cwd, initialize, reporter, autoDispose }) => {
|
|
38
|
+
const appPath = await getStartingAppPath(cwd, options.app);
|
|
39
|
+
const { config, telemetryClient } = await initialize(appPath);
|
|
40
|
+
console.log('App path:', yellow(appPath));
|
|
41
|
+
process.chdir(appPath);
|
|
42
|
+
runPrereqs(config, appPath);
|
|
43
|
+
// Merge in any additional features from the command line.
|
|
44
|
+
config.features = mergeFeatures({
|
|
45
|
+
configFeatures: config.features,
|
|
46
|
+
commandLineFeatures: options.features,
|
|
47
|
+
});
|
|
48
|
+
const enabledFeatureNames = Object.entries(config.features)
|
|
49
|
+
.filter(([, value]) => value)
|
|
50
|
+
.map(([key]) => key);
|
|
51
|
+
if (enabledFeatureNames.length) {
|
|
52
|
+
console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
// Initialize package overrides.
|
|
55
|
+
const packages = createPackageDefinitions({ config });
|
|
56
|
+
// Make sure the package has a valid definition.
|
|
57
|
+
const definition = await packages.get(appPath);
|
|
58
|
+
if (!definition) {
|
|
59
|
+
throw new Error(`There was no package.json located at "${appPath}".`);
|
|
60
|
+
}
|
|
61
|
+
if (!definition.name || !definition.version) {
|
|
62
|
+
throw new Error(`The package.json at "${appPath}" did not have a name and/or version.`);
|
|
63
|
+
}
|
|
64
|
+
// Initialize session definition.
|
|
65
|
+
const session = await createSession({ appPath, config, includeOverlay: true }, { reporter, packages });
|
|
66
|
+
// Set shared telemetry attributes which will be sent with all telemetry events.
|
|
67
|
+
telemetryClient.setSharedSpanAttribute('sessionId', session.id);
|
|
68
|
+
if (options.logResolveMap) {
|
|
69
|
+
// Write the resolve map to disk.
|
|
70
|
+
await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);
|
|
71
|
+
}
|
|
72
|
+
const { startApiServer } = await import('@ms-cloudpack/api-server');
|
|
73
|
+
// Start api server for tracking status and handling remote requests.
|
|
74
|
+
const apiServer = await startApiServer({
|
|
75
|
+
session,
|
|
76
|
+
telemetryClient,
|
|
77
|
+
reporter,
|
|
78
|
+
packages,
|
|
79
|
+
});
|
|
80
|
+
// Kick off bundling app package as soon as api server is ready.
|
|
81
|
+
void apiServer.addTask(await createAppBundleTask({ packageName: definition.name }, { session, config, packages }));
|
|
82
|
+
// Then start bundle and app servers for hosting the app.
|
|
83
|
+
const { startBundleServer } = await import('./startBundleServer.js');
|
|
84
|
+
const bundleServer = await startBundleServer({ apiServer, session, reporter, packages });
|
|
85
|
+
// Finally start the app server.
|
|
86
|
+
const { startAppServer } = await import('./appServer/startAppServer.js');
|
|
87
|
+
const appServer = await startAppServer({
|
|
88
|
+
session,
|
|
89
|
+
definition,
|
|
90
|
+
bundleServer,
|
|
91
|
+
apiServer,
|
|
92
|
+
config,
|
|
93
|
+
reporter,
|
|
94
|
+
packages,
|
|
95
|
+
});
|
|
96
|
+
const cleanup = async () => {
|
|
97
|
+
const servers = [
|
|
98
|
+
['appServer', appServer],
|
|
99
|
+
['apiServer', apiServer],
|
|
100
|
+
['bundleServer', bundleServer],
|
|
101
|
+
];
|
|
102
|
+
await Promise.all(servers.map(async ([name, server]) => {
|
|
103
|
+
console.info(`Closing ${name}: ${server.url}`);
|
|
104
|
+
try {
|
|
105
|
+
await server.close();
|
|
106
|
+
console.info(`Closed ${name}: ${server.url}`);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
console.warn('Error closing server:', err);
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
};
|
|
113
|
+
autoDispose({
|
|
114
|
+
dispose: cleanup,
|
|
115
|
+
});
|
|
116
|
+
cleanupFunctions.push(cleanup);
|
|
117
|
+
// Open the browser.
|
|
118
|
+
const url = appServer.url;
|
|
119
|
+
performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);
|
|
120
|
+
openBrowser(url).catch((err) => {
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
122
|
+
console.warn('Error opening browser:', err?.stack || err);
|
|
123
|
+
console.warn('Please open the browser manually to:', url);
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
// cspell:ignore Prereqs
|
|
127
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC9F,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D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S,CAAU;YACjC,CAAC,cAAc,EAAE,YAAY,CAAU;SACxC,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACnC,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YAC/C,IAAI;gBACF,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;gBACrB,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;aAC/C;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;aAC5C;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,WAAW,CAAC;QACV,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE/B,oBAAoB;IACpB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC;IAE1B,WAAW,CAAC,OAAO,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;IACpE,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QAC7B,sEAAsE;QACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,wBAAwB","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { StartOptions } from './types/StartOptions.js';\nimport type { CloudpackConfig } from '@ms-cloudpack/config';\nimport type { CommandAction } from '../../types/CommandAction.js';\n\nimport { createPackageDefinitions } from '@ms-cloudpack/config';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { openBrowser } from './openBrowser.js';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport { createBundleRequestForPackage, createBundleTask, createSession } from '@ms-cloudpack/api-server';\nimport { mergeFeatures } from './mergeFeatures.js';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport { runPrereqs } from './runPrereqs.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\n\nlet cleanupFunctions: Array<() => Promise<void>> = [];\n\n/** Stop all started cloudpack instances, for testing */\nexport async function stopServers() {\n for (const func of cleanupFunctions) {\n await func();\n }\n cleanupFunctions = [];\n}\n\nasync function createAppBundleTask(\n options: { packageName: string },\n context: { session: Session; config: CloudpackConfig; packages: PackageDefinitionsCache },\n) {\n const { packageName } = options;\n const { session, config, packages } = context;\n const { resolveMap } = session;\n const packageEntry = findResolveMapEntry({\n packageName,\n resolveMap,\n });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${packageName} in the resolve map.`);\n }\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages, resolveMap });\n\n return createBundleTask({ bundleRequest, resolveMap });\n}\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async ({ options, cwd, initialize, reporter, autoDispose }) => {\n const appPath = await getStartingAppPath(cwd, options.app);\n const { config, telemetryClient } = await initialize(appPath);\n\n console.log('App path:', yellow(appPath));\n\n process.chdir(appPath);\n\n runPrereqs(config, appPath);\n\n // Merge in any additional features from the command line.\n config.features = mergeFeatures({\n configFeatures: config.features,\n commandLineFeatures: options.features,\n });\n\n const enabledFeatureNames = Object.entries(config.features)\n .filter(([, value]) => value)\n .map(([key]) => key);\n\n if (enabledFeatureNames.length) {\n console.log(`Enabled features: ${enabledFeatureNames.map((f) => yellow(f)).join(', ')}`);\n }\n\n // Initialize package overrides.\n const packages = createPackageDefinitions({ config });\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (!definition) {\n throw new Error(`There was no package.json located at \"${appPath}\".`);\n }\n\n if (!definition.name || !definition.version) {\n throw new Error(`The package.json at \"${appPath}\" did not have a name and/or version.`);\n }\n\n // Initialize session definition.\n const session = await createSession({ appPath, config, includeOverlay: true }, { reporter, packages });\n\n // Set shared telemetry attributes which will be sent with all telemetry events.\n telemetryClient.setSharedSpanAttribute('sessionId', session.id);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n const { startApiServer } = await import('@ms-cloudpack/api-server');\n\n // Start api server for tracking status and handling remote requests.\n const apiServer = await startApiServer({\n session,\n telemetryClient,\n reporter,\n packages,\n });\n\n // Kick off bundling app package as soon as api server is ready.\n void apiServer.addTask(await createAppBundleTask({ packageName: definition.name }, { session, config, packages }));\n\n // Then start bundle and app servers for hosting the app.\n const { startBundleServer } = await import('./startBundleServer.js');\n const bundleServer = await startBundleServer({ apiServer, session, reporter, packages });\n\n // Finally start the app server.\n const { startAppServer } = await import('./appServer/startAppServer.js');\n const appServer = await startAppServer({\n session,\n definition,\n bundleServer,\n apiServer,\n config,\n reporter,\n packages,\n });\n\n const cleanup = async () => {\n const servers = [\n ['appServer', appServer] as const,\n ['apiServer', apiServer] as const,\n ['bundleServer', bundleServer] as const,\n ];\n\n await Promise.all(\n servers.map(async ([name, server]) => {\n console.info(`Closing ${name}: ${server.url}`);\n try {\n await server.close();\n console.info(`Closed ${name}: ${server.url}`);\n } catch (err) {\n console.warn('Error closing server:', err);\n }\n }),\n );\n };\n\n autoDispose({\n dispose: cleanup,\n });\n\n cleanupFunctions.push(cleanup);\n\n // Open the browser.\n const url = appServer.url;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n openBrowser(url).catch((err) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n console.warn('Error opening browser:', err?.stack || err);\n console.warn('Please open the browser manually to:', url);\n });\n};\n\n// cspell:ignore Prereqs\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,eAAO,MAAM,IAAI,EAAE,eAYlB,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* Defines the "start" verb. */
|
|
2
|
-
export const init = (command,
|
|
2
|
+
export const init = (command, createAction) => {
|
|
3
3
|
command
|
|
4
4
|
.command('start')
|
|
5
5
|
.description('Starts a web inner-loop from the current package folder.')
|
|
6
6
|
.option('--log-resolve-map', 'Logs the resolve map to "resolve-map.json" for diagnostics.')
|
|
7
7
|
.option('--features <featureName> [featureNames...]', 'Enable experimental features.')
|
|
8
8
|
.option('--app <appPackageName>', 'Run Cloudpack targeting a specific app.')
|
|
9
|
-
.action(
|
|
9
|
+
.action(createAction(() => ({
|
|
10
|
+
execute: import('./execute.js'),
|
|
11
|
+
})));
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/start/index.ts"],"names":[],"mappings":"AAEA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;IAC7D,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,mBAAmB,EAAE,6DAA6D,CAAC;SAC1F,MAAM,CAAC,4CAA4C,EAAE,+BAA+B,CAAC;SACrF,MAAM,CAAC,wBAAwB,EAAE,yCAAyC,CAAC;SAC3E,MAAM,CACL,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;KAChC,CAAC,CAAC,CACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { CommandFunction } from '../../types/CommandFunction.js';\n\n/* Defines the \"start\" verb. */\nexport const init: CommandFunction = (command, createAction) => {\n command\n .command('start')\n .description('Starts a web inner-loop from the current package folder.')\n .option('--log-resolve-map', 'Logs the resolve map to \"resolve-map.json\" for diagnostics.')\n .option('--features <featureName> [featureNames...]', 'Enable experimental features.')\n .option('--app <appPackageName>', 'Run Cloudpack targeting a specific app.')\n .action(\n createAction(() => ({\n execute: import('./execute.js'),\n })),\n );\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ApiServer, type Session } from '@ms-cloudpack/api-server';
|
|
2
2
|
import type { BundleServer } from '../../types/BundleServer.js';
|
|
3
3
|
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
4
4
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.d.ts","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"startBundleServer.d.ts","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAMzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI3E;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBxB"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { parseRequestUrl } from '@ms-cloudpack/api-server';
|
|
1
2
|
import { createExpressApp } from '@ms-cloudpack/create-express-app';
|
|
2
3
|
import { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';
|
|
3
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
4
5
|
import { isFolder } from '@ms-cloudpack/path-utilities';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import { createBundleTask, createBundleRequestForPackage } from '@ms-cloudpack/api-server';
|
|
7
|
-
import { parseRequestInfo } from './parseRequestInfo.js';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
const currentPath = fileURLToPath(import.meta.url);
|
|
10
10
|
/**
|
|
@@ -42,7 +42,7 @@ async function handleRequest(options, context) {
|
|
|
42
42
|
const { features = {} } = config;
|
|
43
43
|
const requestPath = slash(req.path.substring(1));
|
|
44
44
|
const force = req.query.force !== undefined;
|
|
45
|
-
const { packageName, version, bundled, filePath } =
|
|
45
|
+
const { packageName, version, bundled, filePath } = parseRequestUrl(requestPath);
|
|
46
46
|
const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });
|
|
47
47
|
if (!packageEntry) {
|
|
48
48
|
// If the package is missing, invalid arguments.
|
|
@@ -59,22 +59,9 @@ async function handleRequest(options, context) {
|
|
|
59
59
|
}
|
|
60
60
|
// If the version is missing, redirect to the primary version.
|
|
61
61
|
if (!version) {
|
|
62
|
-
if (!packageEntry) {
|
|
63
|
-
console.debug(`Response (404): Unrecognized package "${packageName}"`);
|
|
64
|
-
res.status(404).send(`Unrecognized package "${packageName}".`);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
62
|
res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);
|
|
68
63
|
return;
|
|
69
64
|
}
|
|
70
|
-
// If it's an unrecognized package, 404.
|
|
71
|
-
if (!packageEntry) {
|
|
72
|
-
console.debug(`Response (404): "${packageName}@${version}${filePath}"`);
|
|
73
|
-
res
|
|
74
|
-
.status(404)
|
|
75
|
-
.send(`The requested package "${packageName}@${version}${filePath}" was not found in the resolve map.`);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
65
|
// If we are accessing a non-bundled asset, return the file directly.
|
|
79
66
|
if (!bundled) {
|
|
80
67
|
const fullPath = path.join(packageEntry.path, filePath);
|
|
@@ -91,7 +78,7 @@ async function handleRequest(options, context) {
|
|
|
91
78
|
res.sendFile(path.join(packageEntry.path, filePath));
|
|
92
79
|
return;
|
|
93
80
|
}
|
|
94
|
-
const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });
|
|
81
|
+
const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages, resolveMap });
|
|
95
82
|
// Set up for bundling.
|
|
96
83
|
const rerun = !(await isFolder(bundleRequest.outputPath)) || force;
|
|
97
84
|
if (features.enableLage) {
|
|
@@ -113,7 +100,7 @@ async function handleRequest(options, context) {
|
|
|
113
100
|
}
|
|
114
101
|
}
|
|
115
102
|
console.debug(`Trying to bundle "${packageName}@${version}"`);
|
|
116
|
-
const bundleTask = createBundleTask(bundleRequest, { force }, reporter);
|
|
103
|
+
const bundleTask = createBundleTask({ bundleRequest, resolveMap, options: { force }, reporter });
|
|
117
104
|
await apiServer.addTask(bundleTask, { rerun });
|
|
118
105
|
// At this point we should have a Task completed.
|
|
119
106
|
if ((bundleRequest.result?.errors?.length || 0) > 0) {
|
|
@@ -123,9 +110,9 @@ async function handleRequest(options, context) {
|
|
|
123
110
|
if (features.enqueueDependencies && bundleRequest.result?.dependencies) {
|
|
124
111
|
// Enqueue all dependencies to be bundled.
|
|
125
112
|
for (const dependency of bundleRequest.result.dependencies) {
|
|
126
|
-
const dependencyBundleRequest = await createBundleRequestForPackage({ packageEntry: resolveMap[dependency] }, { ...context, config });
|
|
113
|
+
const dependencyBundleRequest = await createBundleRequestForPackage({ packageEntry: resolveMap[dependency] }, { ...context, config, resolveMap });
|
|
127
114
|
// No need to await, we don't want to wait until the bundle is completed.
|
|
128
|
-
void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));
|
|
115
|
+
void apiServer.addTask(createBundleTask({ bundleRequest: dependencyBundleRequest, resolveMap, options: { force }, reporter }));
|
|
129
116
|
}
|
|
130
117
|
}
|
|
131
118
|
console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEnD;;;;GAIG;AACH,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,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE;QACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAClD;SAAM;QACL,IAAI,QAAQ,CAAC,mBAAmB,IAAI,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE;YACtE,0CAA0C;YAC1C,KAAK,MAAM,UAAU,IAAI,aAAa,CAAC,MAAM,CAAC,YAAY,EAAE;gBAC1D,MAAM,uBAAuB,GAAG,MAAM,6BAA6B,CACjE,EAAE,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EACxC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CACvB,CAAC;gBAEF,yEAAyE;gBACzE,KAAK,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;aACxF;SACF;QAED,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,aAAa,CAAC,UAAU,EAAE;YAC5B,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC7D;AACH,CAAC","sourcesContent":["import type { ApiServer, Session } from '@ms-cloudpack/api-server';\nimport { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport type { BundleServer } from '../../types/BundleServer.js';\nimport { createBundleTask, createBundleRequestForPackage } from '@ms-cloudpack/api-server';\nimport { parseRequestInfo } from './parseRequestInfo.js';\nimport { fileURLToPath } from 'url';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nconst currentPath = fileURLToPath(import.meta.url);\n\n/**\n * The bundle server handles package requests and returns bundled resources.\n * Resources are bundled on demand and cached locally to avoid re-bundling\n * on each request.\n */\nexport async function startBundleServer(options: {\n apiServer: ApiServer;\n session: Session;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}): Promise<BundleServer> {\n const { apiServer, session, reporter, packages } = options;\n const { config } = session;\n const { port, close, url } = await createExpressApp({\n portRange: [5500, 5501, 5502, 5503],\n hostname: config.devServer?.domain,\n sslOptions: config.devServer?.https,\n setupCallback: (app: Express) => {\n // Set up the express app routes.\n app.get('*', (req, res) => {\n handleRequest({ req, res }, { session, apiServer, reporter, packages }).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n },\n });\n\n return {\n close,\n port,\n url,\n };\n}\n\nasync function handleRequest(\n options: {\n req: Request;\n res: Response;\n },\n context: {\n session: Session;\n apiServer: ApiServer;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n },\n) {\n const { req, res } = options;\n const { session, apiServer, reporter, packages } = context;\n const { resolveMap, config } = session;\n const { features = {} } = config;\n const requestPath = slash(req.path.substring(1));\n const force = req.query.force !== undefined;\n const { packageName, version, bundled, filePath } = parseRequestInfo(requestPath);\n const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });\n\n if (!packageEntry) {\n // If the package is missing, invalid arguments.\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n console.debug(`Request: \"${packageName}@${version}${filePath}\"`);\n\n // If the package is missing, invalid arguments.\n if (!requestPath || !packageName) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Requests must be in the format \"/{packageName}@{version}/{type}/path/file.ext\".`);\n return;\n }\n\n // If the version is missing, redirect to the primary version.\n if (!version) {\n if (!packageEntry) {\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);\n return;\n }\n\n // If it's an unrecognized package, 404.\n if (!packageEntry) {\n console.debug(`Response (404): \"${packageName}@${version}${filePath}\"`);\n\n res\n .status(404)\n .send(`The requested package \"${packageName}@${version}${filePath}\" was not found in the resolve map.`);\n\n return;\n }\n\n // If we are accessing a non-bundled asset, return the file directly.\n if (!bundled) {\n const fullPath = path.join(packageEntry.path, filePath);\n\n if (fullPath.length < packageEntry.path.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n return;\n }\n\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packageEntry.path)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packageEntry.path, filePath));\n return;\n }\n\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });\n\n // Set up for bundling.\n const rerun = !(await isFolder(bundleRequest.outputPath)) || force;\n\n if (features.enableLage) {\n console.debug(`Trying to bundle \"${packageName}@${version}\" with lage task scheduler`);\n\n try {\n await apiServer.scheduleTask(\n bundleRequest,\n {\n // TODO: we may want to have away to let users add more types of tasks here\n bundle: path.resolve(currentPath, '../../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n return res.sendFile(path.join(bundleRequest.outputPath, filePath));\n } catch (err) {\n return res.status(500).type('json').send(bundleRequest);\n }\n }\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask(bundleRequest, { force }, reporter);\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if ((bundleRequest.result?.errors?.length || 0) > 0) {\n res.status(500).type('json').send(bundleRequest);\n } else {\n if (features.enqueueDependencies && bundleRequest.result?.dependencies) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of bundleRequest.result.dependencies) {\n const dependencyBundleRequest = await createBundleRequestForPackage(\n { packageEntry: resolveMap[dependency] },\n { ...context, config },\n );\n\n // No need to await, we don't want to wait until the bundle is completed.\n void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));\n }\n }\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(bundleRequest.outputPath, filePath));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"startBundleServer.js","sourceRoot":"","sources":["../../../src/commands/start/startBundleServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgC,MAAM,0BAA0B,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAA6C,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC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G,MAAM,6BAA6B,CACjE,EAAE,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EACxC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CACnC,CAAC;gBAEF,yEAAyE;gBACzE,KAAK,SAAS,CAAC,OAAO,CACpB,gBAAgB,CAAC,EAAE,aAAa,EAAE,uBAAuB,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,CACvG,CAAC;aACH;SACF;QAED,OAAO,CAAC,KAAK,CAAC,sBAAsB,WAAW,IAAI,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC1E,4BAA4B;QAC5B,IAAI,aAAa,CAAC,UAAU,EAAE;YAC5B,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;SAC5D;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;KAC7D;AACH,CAAC","sourcesContent":["import { parseRequestUrl, type ApiServer, type Session } from '@ms-cloudpack/api-server';\nimport { createExpressApp, type Express, type Request, type Response } from '@ms-cloudpack/create-express-app';\nimport { isExternalPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport type { BundleServer } from '../../types/BundleServer.js';\nimport { createBundleTask, createBundleRequestForPackage } from '@ms-cloudpack/api-server';\nimport { fileURLToPath } from 'url';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nconst currentPath = fileURLToPath(import.meta.url);\n\n/**\n * The bundle server handles package requests and returns bundled resources.\n * Resources are bundled on demand and cached locally to avoid re-bundling\n * on each request.\n */\nexport async function startBundleServer(options: {\n apiServer: ApiServer;\n session: Session;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n}): Promise<BundleServer> {\n const { apiServer, session, reporter, packages } = options;\n const { config } = session;\n const { port, close, url } = await createExpressApp({\n portRange: [5500, 5501, 5502, 5503],\n hostname: config.devServer?.domain,\n sslOptions: config.devServer?.https,\n setupCallback: (app: Express) => {\n // Set up the express app routes.\n app.get('*', (req, res) => {\n handleRequest({ req, res }, { session, apiServer, reporter, packages }).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error bundling: ${err}`);\n });\n });\n },\n });\n\n return {\n close,\n port,\n url,\n };\n}\n\nasync function handleRequest(\n options: {\n req: Request;\n res: Response;\n },\n context: {\n session: Session;\n apiServer: ApiServer;\n reporter: TaskReporter;\n packages: PackageDefinitionsCache;\n },\n) {\n const { req, res } = options;\n const { session, apiServer, reporter, packages } = context;\n const { resolveMap, config } = session;\n const { features = {} } = config;\n const requestPath = slash(req.path.substring(1));\n const force = req.query.force !== undefined;\n const { packageName, version, bundled, filePath } = parseRequestUrl(requestPath);\n const packageEntry = findResolveMapEntry({ packageName, version, resolveMap });\n\n if (!packageEntry) {\n // If the package is missing, invalid arguments.\n console.debug(`Response (404): Unrecognized package \"${packageName}\"`);\n res.status(404).send(`Unrecognized package \"${packageName}\".`);\n return;\n }\n\n console.debug(`Request: \"${packageName}@${version}${filePath}\"`);\n\n // If the package is missing, invalid arguments.\n if (!requestPath || !packageName) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Requests must be in the format \"/{packageName}@{version}/{type}/path/file.ext\".`);\n return;\n }\n\n // If the version is missing, redirect to the primary version.\n if (!version) {\n res.redirect(`/${packageName}@${packageEntry.version}${filePath}`);\n return;\n }\n\n // If we are accessing a non-bundled asset, return the file directly.\n if (!bundled) {\n const fullPath = path.join(packageEntry.path, filePath);\n\n if (fullPath.length < packageEntry.path.length) {\n console.debug(`Response (400): \"${packageName}@${version}${filePath}\"`);\n\n res.status(400).send(`Invalid file path.`);\n return;\n }\n\n console.debug(`Unbundled response returning: \"${packageName}@${version}${filePath}\"`);\n // If the package is external, set cache headers.\n if (isExternalPackage(packageEntry.path)) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(packageEntry.path, filePath));\n return;\n }\n\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages, resolveMap });\n\n // Set up for bundling.\n const rerun = !(await isFolder(bundleRequest.outputPath)) || force;\n\n if (features.enableLage) {\n console.debug(`Trying to bundle \"${packageName}@${version}\" with lage task scheduler`);\n\n try {\n await apiServer.scheduleTask(\n bundleRequest,\n {\n // TODO: we may want to have away to let users add more types of tasks here\n bundle: path.resolve(currentPath, '../../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n return res.sendFile(path.join(bundleRequest.outputPath, filePath));\n } catch (err) {\n return res.status(500).type('json').send(bundleRequest);\n }\n }\n\n console.debug(`Trying to bundle \"${packageName}@${version}\"`);\n\n const bundleTask = createBundleTask({ bundleRequest, resolveMap, options: { force }, reporter });\n await apiServer.addTask(bundleTask, { rerun });\n\n // At this point we should have a Task completed.\n if ((bundleRequest.result?.errors?.length || 0) > 0) {\n res.status(500).type('json').send(bundleRequest);\n } else {\n if (features.enqueueDependencies && bundleRequest.result?.dependencies) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of bundleRequest.result.dependencies) {\n const dependencyBundleRequest = await createBundleRequestForPackage(\n { packageEntry: resolveMap[dependency] },\n { ...context, config, resolveMap },\n );\n\n // No need to await, we don't want to wait until the bundle is completed.\n void apiServer.addTask(\n createBundleTask({ bundleRequest: dependencyBundleRequest, resolveMap, options: { force }, reporter }),\n );\n }\n }\n\n console.debug(`Bundle returning: \"${packageName}@${version}${filePath}\"`);\n // Try to return the result.\n if (bundleRequest.isExternal) {\n res.setHeader('Cache-Control', 'public, max-age=31536000');\n }\n\n res.sendFile(path.join(bundleRequest.outputPath, filePath));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAIlE,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,WAAW,CA0C9C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isCIBuild } from '../../utilities/isCIBuild.js';
|
|
2
|
+
import { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server/apis';
|
|
3
|
+
export const execute = async ({ options, cwd, reporter, initialize, exit, autoDispose, }) => {
|
|
4
|
+
const { config, telemetryClient } = await initialize(cwd);
|
|
5
|
+
const { nonInteractiveLogin, upload } = options;
|
|
6
|
+
const remoteCacheConfig = config.remoteCache;
|
|
7
|
+
if (!remoteCacheConfig) {
|
|
8
|
+
console.warn('Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const input = {
|
|
12
|
+
isInteractiveLogin: !(isCIBuild() || nonInteractiveLogin),
|
|
13
|
+
};
|
|
14
|
+
const apiContextOptions = { appPath: cwd, config, reporter, telemetryClient };
|
|
15
|
+
if (upload) {
|
|
16
|
+
const [ctx] = autoDispose(await createPartialApiContext({
|
|
17
|
+
...apiContextOptions,
|
|
18
|
+
items: ['bus', 'taskRunner', 'watcher', 'packages', 'session'],
|
|
19
|
+
}));
|
|
20
|
+
await syncUpload({ input, ctx });
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const [ctx] = autoDispose(await createPartialApiContext({
|
|
24
|
+
...apiContextOptions,
|
|
25
|
+
items: ['packages', 'session'],
|
|
26
|
+
}));
|
|
27
|
+
await syncDownload({ input, ctx });
|
|
28
|
+
}
|
|
29
|
+
await exit({ exitCode: 0 });
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAElG,MAAM,CAAC,MAAM,OAAO,GAA+B,KAAK,EAAE,EACxD,OAAO,EACP,GAAG,EACH,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,WAAW,GACZ,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,CAAC;IAC1D,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,iBAAiB,GAAG,MAAM,CAAC,WAAW,CAAC;IAC7C,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,CAAC,IAAI,CACV,gHAAgH,CACjH,CAAC;QACF,OAAO;KACR;IAED,MAAM,KAAK,GAAG;QACZ,kBAAkB,EAAE,CAAC,CAAC,SAAS,EAAE,IAAI,mBAAmB,CAAC;KAC1D,CAAC;IAEF,MAAM,iBAAiB,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC9E,IAAI,MAAM,EAAE;QACV,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CACvB,MAAM,uBAAuB,CAAC;YAC5B,GAAG,iBAAiB;YACpB,KAAK,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;SAC/D,CAAC,CACH,CAAC;QACF,MAAM,UAAU,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;KAClC;SAAM;QACL,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CACvB,MAAM,uBAAuB,CAAC;YAC5B,GAAG,iBAAiB;YACpB,KAAK,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC;SAC/B,CAAC,CACH,CAAC;QACF,MAAM,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;KACpC;IAED,MAAM,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import type { SyncOptions } from './types/SyncOptions.js';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { isCIBuild } from '../../utilities/isCIBuild.js';\nimport { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server/apis';\n\nexport const execute: CommandAction<SyncOptions> = async ({\n options,\n cwd,\n reporter,\n initialize,\n exit,\n autoDispose,\n}) => {\n const { config, telemetryClient } = await initialize(cwd);\n const { nonInteractiveLogin, upload } = options;\n const remoteCacheConfig = config.remoteCache;\n if (!remoteCacheConfig) {\n console.warn(\n 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',\n );\n return;\n }\n\n const input = {\n isInteractiveLogin: !(isCIBuild() || nonInteractiveLogin),\n };\n\n const apiContextOptions = { appPath: cwd, config, reporter, telemetryClient };\n if (upload) {\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session'],\n }),\n );\n await syncUpload({ input, ctx });\n } else {\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['packages', 'session'],\n }),\n );\n await syncDownload({ input, ctx });\n }\n\n await exit({ exitCode: 0 });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,+BAA+B;AAC/B,eAAO,MAAM,IAAI,EAAE,eAalB,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/** Defines the "sync" verb. */
|
|
2
|
-
export const init = (command,
|
|
2
|
+
export const init = (command, createAction) => {
|
|
3
3
|
command
|
|
4
4
|
.command('sync')
|
|
5
5
|
.description('Syncs the packages from/to the remote cache. If the package is not in the local cache, it will be downloaded.')
|
|
6
6
|
.option('--upload', 'Uploads the packages to the remote cache.')
|
|
7
7
|
.option('--non-interactive-login', 'Disables interactive login prompts for authentication.')
|
|
8
|
-
.action(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
});
|
|
8
|
+
.action(createAction(() => ({
|
|
9
|
+
execute: import('./execute.js'),
|
|
10
|
+
})));
|
|
12
11
|
};
|
|
13
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/sync/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/sync/index.ts"],"names":[],"mappings":"AAEA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;IAC7D,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CACV,+GAA+G,CAChH;SACA,MAAM,CAAC,UAAU,EAAE,2CAA2C,CAAC;SAC/D,MAAM,CAAC,yBAAyB,EAAE,wDAAwD,CAAC;SAC3F,MAAM,CACL,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;KAChC,CAAC,CAAC,CACJ,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { CommandFunction } from '../../types/CommandFunction.js';\n\n/** Defines the \"sync\" verb. */\nexport const init: CommandFunction = (command, createAction) => {\n command\n .command('sync')\n .description(\n 'Syncs the packages from/to the remote cache. If the package is not in the local cache, it will be downloaded.',\n )\n .option('--upload', 'Uploads the packages to the remote cache.')\n .option('--non-interactive-login', 'Disables interactive login prompts for authentication.')\n .action(\n createAction(() => ({\n execute: import('./execute.js'),\n })),\n );\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoDisposableList.d.ts","sourceRoot":"","sources":["../../src/common/AutoDisposableList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEzC,GAAG,CAAC,CAAC,SAAS,UAAU,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE;IAKjC,OAAO;CAOrB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class AutoDisposableList {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.disposables = [];
|
|
4
|
+
}
|
|
5
|
+
add(...items) {
|
|
6
|
+
this.disposables.push(...items);
|
|
7
|
+
return items;
|
|
8
|
+
}
|
|
9
|
+
async dispose() {
|
|
10
|
+
const results = await Promise.allSettled(this.disposables.map((d) => d.dispose()));
|
|
11
|
+
const failedPromisesCount = results.filter((p) => p.status === 'rejected').length;
|
|
12
|
+
if (failedPromisesCount) {
|
|
13
|
+
throw new Error(`Failed to dispose ${failedPromisesCount} disposable(s)`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=AutoDisposableList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoDisposableList.js","sourceRoot":"","sources":["../../src/common/AutoDisposableList.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IAA/B;QACmB,gBAAW,GAAiB,EAAE,CAAC;IAclD,CAAC;IAZQ,GAAG,CAAuB,GAAG,KAAU;QAC5C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACnF,MAAM,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,MAAM,CAAC;QAClF,IAAI,mBAAmB,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,mBAAmB,gBAAgB,CAAC,CAAC;SAC3E;IACH,CAAC;CACF","sourcesContent":["import type { Disposable } from '../types/Disposable.js';\n\nexport class AutoDisposableList {\n private readonly disposables: Disposable[] = [];\n\n public add<T extends Disposable>(...items: T[]) {\n this.disposables.push(...items);\n return items;\n }\n\n public async dispose() {\n const results = await Promise.allSettled(this.disposables.map((d) => d.dispose()));\n const failedPromisesCount = results.filter((p) => p.status === 'rejected').length;\n if (failedPromisesCount) {\n throw new Error(`Failed to dispose ${failedPromisesCount} disposable(s)`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import type { CreateCommandActionOptions } from '../types/CreateCommandActionOptions.js';
|
|
3
|
+
/**
|
|
4
|
+
* It creates a function that creates a command action.
|
|
5
|
+
* @param createCommandActionFactoryOptions - Options for creating the command action factory.
|
|
6
|
+
* @returns A function that creates a command action.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createCommandActionFunction(createCommandActionFactoryOptions: {
|
|
9
|
+
cwd: string;
|
|
10
|
+
abortController: AbortController;
|
|
11
|
+
reporter: TaskReporter;
|
|
12
|
+
}): <TActionOptions>(getCreateActionOptions: () => CreateCommandActionOptions<TActionOptions>) => (options: TActionOptions) => Promise<void>;
|
|
13
|
+
export type CreateCommandAction = ReturnType<typeof createCommandActionFunction>;
|
|
14
|
+
//# sourceMappingURL=createCommandActionFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCommandActionFunction.d.ts","sourceRoot":"","sources":["../../src/common/createCommandActionFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAKzF;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,iCAAiC,EAAE;IAC7E,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC;CACxB,4IAoEA;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {} from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import { AutoDisposableList } from './AutoDisposableList.js';
|
|
3
|
+
import { createExitFunction } from './createExitFunction.js';
|
|
4
|
+
import { createInitializeFunction } from './createInitializeFunction.js';
|
|
5
|
+
/**
|
|
6
|
+
* It creates a function that creates a command action.
|
|
7
|
+
* @param createCommandActionFactoryOptions - Options for creating the command action factory.
|
|
8
|
+
* @returns A function that creates a command action.
|
|
9
|
+
*/
|
|
10
|
+
export function createCommandActionFunction(createCommandActionFactoryOptions) {
|
|
11
|
+
const { abortController, reporter, cwd } = createCommandActionFactoryOptions;
|
|
12
|
+
/**
|
|
13
|
+
* This function will be called to create a command action.
|
|
14
|
+
*/
|
|
15
|
+
return function createAction(getCreateActionOptions) {
|
|
16
|
+
return async (options) => {
|
|
17
|
+
const createActionOptions = getCreateActionOptions();
|
|
18
|
+
// Dynamically import the execute function
|
|
19
|
+
const execute = await createActionOptions.execute.then((m) => m.execute);
|
|
20
|
+
// This list will be used to dispose all registered disposables.
|
|
21
|
+
const autoDisposableList = new AutoDisposableList();
|
|
22
|
+
// This function will be used to register a disposable.
|
|
23
|
+
const autoDispose = autoDisposableList.add.bind(autoDisposableList);
|
|
24
|
+
// This function will be called instead of process.exit. It provides a way to cleanup and exit the process gracefully.
|
|
25
|
+
const exit = createExitFunction({ abortController, reporter, autoDisposableList });
|
|
26
|
+
// This function will be called to initialize the command.
|
|
27
|
+
const initialize = createInitializeFunction({ reporter, autoDispose });
|
|
28
|
+
try {
|
|
29
|
+
// Setup cleanup and close things on completion.
|
|
30
|
+
let sigintCount = 0;
|
|
31
|
+
// Handle SIGINT (Ctrl+C) gracefully.
|
|
32
|
+
process.on('SIGINT', () => {
|
|
33
|
+
sigintCount++;
|
|
34
|
+
if (sigintCount > 1) {
|
|
35
|
+
console.debug('Forcing exit');
|
|
36
|
+
// We are forcing the process to exit.
|
|
37
|
+
// No clean-up is needed because user pressed Ctrl+C twice.
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// We are trying to exit gracefully.
|
|
41
|
+
void exit();
|
|
42
|
+
});
|
|
43
|
+
// This is the abort signal that will be passed to the execute function.
|
|
44
|
+
const abortSignal = abortController.signal;
|
|
45
|
+
// Call the execute function which is the real command logic (ie: real init command logic, real start command logic, etc.)
|
|
46
|
+
await execute({
|
|
47
|
+
cwd,
|
|
48
|
+
options,
|
|
49
|
+
reporter,
|
|
50
|
+
initialize,
|
|
51
|
+
abortSignal,
|
|
52
|
+
autoDispose,
|
|
53
|
+
exit,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
// If an error occurs, exit the process with a non-zero exit code.
|
|
58
|
+
await exit({
|
|
59
|
+
hasErrors: true,
|
|
60
|
+
message: error instanceof Error ? error.message : '<Unknown error>',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=createCommandActionFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createCommandActionFunction.js","sourceRoot":"","sources":["../../src/common/createCommandActionFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,iCAI3C;IACC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,iCAAiC,CAAC;IAE7E;;OAEG;IACH,OAAO,SAAS,YAAY,CAC1B,sBAAwE;QAExE,OAAO,KAAK,EAAE,OAAuB,EAAE,EAAE;YACvC,MAAM,mBAAmB,GAAG,sBAAsB,EAAE,CAAC;YAErD,0CAA0C;YAC1C,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAEzE,gEAAgE;YAChE,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC;YAEpD,uDAAuD;YACvD,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAEpE,sHAAsH;YACtH,MAAM,IAAI,GAAG,kBAAkB,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,CAAC;YAEnF,0DAA0D;YAC1D,MAAM,UAAU,GAAG,wBAAwB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;YAEvE,IAAI;gBACF,gDAAgD;gBAChD,IAAI,WAAW,GAAG,CAAC,CAAC;gBAEpB,qCAAqC;gBACrC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;oBACxB,WAAW,EAAE,CAAC;oBACd,IAAI,WAAW,GAAG,CAAC,EAAE;wBACnB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;wBAE9B,sCAAsC;wBACtC,2DAA2D;wBAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;qBACjB;oBAED,oCAAoC;oBACpC,KAAK,IAAI,EAAE,CAAC;gBACd,CAAC,CAAC,CAAC;gBAEH,wEAAwE;gBACxE,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC;gBAE3C,0HAA0H;gBAC1H,MAAM,OAAO,CAAC;oBACZ,GAAG;oBACH,OAAO;oBACP,QAAQ;oBACR,UAAU;oBACV,WAAW;oBACX,WAAW;oBACX,IAAI;iBACL,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,kEAAkE;gBAClE,MAAM,IAAI,CAAC;oBACT,SAAS,EAAE,IAAI;oBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,iBAAiB;iBACpE,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { CreateCommandActionOptions } from '../types/CreateCommandActionOptions.js';\nimport { AutoDisposableList } from './AutoDisposableList.js';\nimport { createExitFunction } from './createExitFunction.js';\nimport { createInitializeFunction } from './createInitializeFunction.js';\n\n/**\n * It creates a function that creates a command action.\n * @param createCommandActionFactoryOptions - Options for creating the command action factory.\n * @returns A function that creates a command action.\n */\nexport function createCommandActionFunction(createCommandActionFactoryOptions: {\n cwd: string;\n abortController: AbortController;\n reporter: TaskReporter;\n}) {\n const { abortController, reporter, cwd } = createCommandActionFactoryOptions;\n\n /**\n * This function will be called to create a command action.\n */\n return function createAction<TActionOptions>(\n getCreateActionOptions: () => CreateCommandActionOptions<TActionOptions>,\n ) {\n return async (options: TActionOptions) => {\n const createActionOptions = getCreateActionOptions();\n\n // Dynamically import the execute function\n const execute = await createActionOptions.execute.then((m) => m.execute);\n\n // This list will be used to dispose all registered disposables.\n const autoDisposableList = new AutoDisposableList();\n\n // This function will be used to register a disposable.\n const autoDispose = autoDisposableList.add.bind(autoDisposableList);\n\n // This function will be called instead of process.exit. It provides a way to cleanup and exit the process gracefully.\n const exit = createExitFunction({ abortController, reporter, autoDisposableList });\n\n // This function will be called to initialize the command.\n const initialize = createInitializeFunction({ reporter, autoDispose });\n\n try {\n // Setup cleanup and close things on completion.\n let sigintCount = 0;\n\n // Handle SIGINT (Ctrl+C) gracefully.\n process.on('SIGINT', () => {\n sigintCount++;\n if (sigintCount > 1) {\n console.debug('Forcing exit');\n\n // We are forcing the process to exit.\n // No clean-up is needed because user pressed Ctrl+C twice.\n process.exit(1);\n }\n\n // We are trying to exit gracefully.\n void exit();\n });\n\n // This is the abort signal that will be passed to the execute function.\n const abortSignal = abortController.signal;\n\n // Call the execute function which is the real command logic (ie: real init command logic, real start command logic, etc.)\n await execute({\n cwd,\n options,\n reporter,\n initialize,\n abortSignal,\n autoDispose,\n exit,\n });\n } catch (error) {\n // If an error occurs, exit the process with a non-zero exit code.\n await exit({\n hasErrors: true,\n message: error instanceof Error ? error.message : '<Unknown error>',\n });\n }\n };\n };\n}\n\nexport type CreateCommandAction = ReturnType<typeof createCommandActionFunction>;\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import type { AutoDisposableList } from './AutoDisposableList.js';
|
|
3
|
+
export declare function createExitFunction(options: {
|
|
4
|
+
reporter: TaskReporter;
|
|
5
|
+
abortController: AbortController;
|
|
6
|
+
autoDisposableList: AutoDisposableList;
|
|
7
|
+
}): (exitOptions?: {
|
|
8
|
+
hasErrors?: boolean;
|
|
9
|
+
message?: string;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
}) => Promise<never>;
|
|
12
|
+
//# sourceMappingURL=createExitFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExitFunction.d.ts","sourceRoot":"","sources":["../../src/common/createExitFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAO,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAC1C,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,kBAIgB;IACX,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,oBAiBJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { red } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
export function createExitFunction(options) {
|
|
3
|
+
const { abortController, reporter, autoDisposableList } = options;
|
|
4
|
+
return async function exit(exitOptions = {}) {
|
|
5
|
+
const { message } = exitOptions;
|
|
6
|
+
const hasErrors = exitOptions.hasErrors ?? reporter.hasErrors();
|
|
7
|
+
// Let the execute function know that we are exiting.
|
|
8
|
+
abortController.abort();
|
|
9
|
+
// Dispose all registered disposables.
|
|
10
|
+
await autoDisposableList.dispose();
|
|
11
|
+
reporter.complete(hasErrors ? red(message) : message);
|
|
12
|
+
// Exit the process with the appropriate exit code.
|
|
13
|
+
const exitCode = exitOptions.exitCode ?? (hasErrors ? 1 : 0);
|
|
14
|
+
process.exit(exitCode);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=createExitFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createExitFunction.js","sourceRoot":"","sources":["../../src/common/createExitFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAGrE,MAAM,UAAU,kBAAkB,CAAC,OAIlC;IACC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;IAElE,OAAO,KAAK,UAAU,IAAI,CACxB,cAII,EAAE;QAEN,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC;QAChC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QAEhE,qDAAqD;QACrD,eAAe,CAAC,KAAK,EAAE,CAAC;QAExB,sCAAsC;QACtC,MAAM,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAEnC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAEtD,mDAAmD;QACnD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type TaskReporter, red } from '@ms-cloudpack/task-reporter';\nimport type { AutoDisposableList } from './AutoDisposableList.js';\n\nexport function createExitFunction(options: {\n reporter: TaskReporter;\n abortController: AbortController;\n autoDisposableList: AutoDisposableList;\n}) {\n const { abortController, reporter, autoDisposableList } = options;\n\n return async function exit(\n exitOptions: {\n hasErrors?: boolean;\n message?: string;\n exitCode?: number;\n } = {},\n ) {\n const { message } = exitOptions;\n const hasErrors = exitOptions.hasErrors ?? reporter.hasErrors();\n\n // Let the execute function know that we are exiting.\n abortController.abort();\n\n // Dispose all registered disposables.\n await autoDisposableList.dispose();\n\n reporter.complete(hasErrors ? red(message) : message);\n\n // Exit the process with the appropriate exit code.\n const exitCode = exitOptions.exitCode ?? (hasErrors ? 1 : 0);\n process.exit(exitCode);\n };\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import type { AutoDispose } from '../types/AutoDispose.js';
|
|
3
|
+
export declare function createInitializeFunction(options: {
|
|
4
|
+
reporter: TaskReporter;
|
|
5
|
+
autoDispose: AutoDispose;
|
|
6
|
+
}): (appPath: string) => Promise<{
|
|
7
|
+
telemetryClient: import("@ms-cloudpack/telemetry").TelemetryClient;
|
|
8
|
+
config: import("@ms-cloudpack/config").CloudpackConfig;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=createInitializeFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createInitializeFunction.d.ts","sourceRoot":"","sources":["../../src/common/createInitializeFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAAE,QAAQ,EAAE,YAAY,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,aAE1D,MAAM;;;GAgBjD"}
|