@ms-cloudpack/cli 0.47.6 → 0.47.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAO1D;;GAEG;AACH,wBAAsB,IAAI,CAAC,UAAU,EAAE;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAO1D;;GAEG;AACH,wBAAsB,IAAI,CAAC,UAAU,EAAE;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,EAAE,eAAe,CAAC;CAClC,GAAG,OAAO,CAAC,WAAW,CAAC,CA2GvB"}
|
|
@@ -30,7 +30,7 @@ export async function init(parameters) {
|
|
|
30
30
|
const generatedConfig = config.generated;
|
|
31
31
|
// Ensure generatedConfig.packageSettings is initialized.
|
|
32
32
|
generatedConfig.packageSettings ??= [];
|
|
33
|
-
|
|
33
|
+
const summary = await new Promise((resolve, reject) => {
|
|
34
34
|
let pending = 0;
|
|
35
35
|
const visitedSet = new Set();
|
|
36
36
|
// Create a function to enqueue more paths.
|
|
@@ -40,57 +40,57 @@ export async function init(parameters) {
|
|
|
40
40
|
}
|
|
41
41
|
// Iterate through the given paths.
|
|
42
42
|
for (const path of newPaths) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
visitedSet.add(path);
|
|
46
|
-
pending++;
|
|
47
|
-
// Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.
|
|
48
|
-
evaluatePath({
|
|
49
|
-
packagePath: path,
|
|
50
|
-
generatedConfig,
|
|
51
|
-
telemetryClient,
|
|
52
|
-
resolveMap,
|
|
53
|
-
shouldForce,
|
|
54
|
-
initOptions: options,
|
|
55
|
-
summaryData,
|
|
56
|
-
ctx,
|
|
57
|
-
})
|
|
58
|
-
.then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {
|
|
59
|
-
pending--;
|
|
60
|
-
if (shouldExit) {
|
|
61
|
-
isExitingPrematurely = true;
|
|
62
|
-
}
|
|
63
|
-
if (!isExitingPrematurely && pathsToEvaluate?.size) {
|
|
64
|
-
// If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing
|
|
65
|
-
// we pass the `shouldRerun` flag through
|
|
66
|
-
pathsToRefresh?.forEach((refreshPath) => {
|
|
67
|
-
refreshPaths.add(refreshPath);
|
|
68
|
-
visitedSet.delete(refreshPath);
|
|
69
|
-
});
|
|
70
|
-
// Try to enqueue the new paths.
|
|
71
|
-
enqueuePaths(Array.from(pathsToEvaluate));
|
|
72
|
-
}
|
|
73
|
-
// If nothing is pending after this call, we're complete.
|
|
74
|
-
if (!pending) {
|
|
75
|
-
resolve(summaryData.summarize());
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
.catch((error) => {
|
|
79
|
-
reject(error);
|
|
80
|
-
});
|
|
43
|
+
if (visitedSet.has(path)) {
|
|
44
|
+
continue;
|
|
81
45
|
}
|
|
46
|
+
const shouldForce = refreshPaths.delete(path);
|
|
47
|
+
visitedSet.add(path);
|
|
48
|
+
pending++;
|
|
49
|
+
// Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.
|
|
50
|
+
evaluatePath({
|
|
51
|
+
packagePath: path,
|
|
52
|
+
generatedConfig,
|
|
53
|
+
telemetryClient,
|
|
54
|
+
resolveMap,
|
|
55
|
+
shouldForce,
|
|
56
|
+
initOptions: options,
|
|
57
|
+
summaryData,
|
|
58
|
+
ctx,
|
|
59
|
+
})
|
|
60
|
+
.then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {
|
|
61
|
+
pending--;
|
|
62
|
+
if (shouldExit) {
|
|
63
|
+
isExitingPrematurely = true;
|
|
64
|
+
}
|
|
65
|
+
if (!isExitingPrematurely && pathsToEvaluate?.size) {
|
|
66
|
+
// If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing
|
|
67
|
+
// we pass the `shouldRerun` flag through
|
|
68
|
+
pathsToRefresh?.forEach((refreshPath) => {
|
|
69
|
+
refreshPaths.add(refreshPath);
|
|
70
|
+
visitedSet.delete(refreshPath);
|
|
71
|
+
});
|
|
72
|
+
// Try to enqueue the new paths.
|
|
73
|
+
enqueuePaths(Array.from(pathsToEvaluate));
|
|
74
|
+
}
|
|
75
|
+
// If nothing is pending after this call, we're complete.
|
|
76
|
+
if (!pending) {
|
|
77
|
+
resolve(summaryData.summarize());
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.catch((error) => {
|
|
81
|
+
reject(error);
|
|
82
|
+
});
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
// Start with the app path.
|
|
85
86
|
enqueuePaths([appPath]);
|
|
86
|
-
}).then(async (summary) => {
|
|
87
|
-
const { totalChanges } = summary;
|
|
88
|
-
if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {
|
|
89
|
-
sortExportKeys(generatedConfig);
|
|
90
|
-
await writeGeneratedConfig(generatedConfig, appPath);
|
|
91
|
-
}
|
|
92
|
-
return summary;
|
|
93
87
|
});
|
|
88
|
+
const { totalChanges } = summary;
|
|
89
|
+
if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {
|
|
90
|
+
sortExportKeys(generatedConfig);
|
|
91
|
+
await writeGeneratedConfig(generatedConfig, appPath);
|
|
92
|
+
}
|
|
93
|
+
return summary;
|
|
94
94
|
}
|
|
95
95
|
function sortExportKeys({ packageSettings = [] }) {
|
|
96
96
|
for (const settings of packageSettings) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,UAO1B;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EA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IAEH,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,YAAY,IAAI,eAAe,CAAC,eAAe,EAAE,MAAM,EAAE;QAC7E,cAAc,CAAC,eAAe,CAAC,CAAC;QAEhC,MAAM,oBAAoB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;KACtD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,EAAE,eAAe,GAAG,EAAE,EAAmB;IAC/D,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE;QACtC,IAAI,QAAQ,CAAC,OAAO,EAAE;YACpB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAkD,CAAC;YACpF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YAExD,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC5C,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;gBAC1B,OAAO,CAAC,CAAC;YACX,CAAC,EAAE,EAA8B,CAAC,CAAC;SACpC;KACF;AACH,CAAC","sourcesContent":["import type { PackageJsonExportsObject, PackageJsonExportsValue } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig, GeneratedConfig } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { AutoDispose } from '../../types/AutoDispose.js';\nimport type { InitOptions } from './types/InitOptions.js';\nimport type { InitSummary } from './types/InitSummary.js';\n\nimport { createPartialApiContext } from '@ms-cloudpack/api-server/apis';\nimport { writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { InitSummaryData } from './InitSummaryData.js';\nimport { evaluatePath } from './evaluatePath.js';\n\n/**\n * Init execution function.\n */\nexport async function init(parameters: {\n options: InitOptions;\n appPath: string;\n config: CloudpackConfig;\n autoDispose: AutoDispose;\n reporter: TaskReporter;\n telemetryClient: TelemetryClient;\n}): Promise<InitSummary> {\n const { options, appPath, config, reporter, autoDispose, telemetryClient } = parameters;\n let isExitingPrematurely = false;\n\n // Don't allow --check and --reset together.\n if (options.check && options.reset) {\n throw Error('Cannot use --check and --reset together.');\n }\n\n // If --reset is specified, reset the generated config.\n if (options.reset) {\n config.generated = {};\n }\n\n const summaryData = new InitSummaryData();\n const [ctx] = autoDispose(\n await createPartialApiContext({\n appPath,\n config,\n reporter,\n telemetryClient,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session'],\n }),\n );\n const { session } = ctx;\n const { resolveMap } = session;\n const refreshPaths = new Set<string>();\n const generatedConfig = config.generated;\n\n // Ensure generatedConfig.packageSettings is initialized.\n generatedConfig.packageSettings ??= [];\n\n const summary = await new Promise<InitSummary>((resolve, reject) => {\n let pending = 0;\n const visitedSet = new Set<string>();\n\n // Create a function to enqueue more paths.\n function enqueuePaths(newPaths: string[]) {\n if (isExitingPrematurely) {\n return;\n }\n\n // Iterate through the given paths.\n for (const path of newPaths) {\n if (visitedSet.has(path)) {\n continue;\n }\n\n const shouldForce = refreshPaths.delete(path);\n\n visitedSet.add(path);\n pending++;\n\n // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.\n evaluatePath({\n packagePath: path,\n generatedConfig,\n telemetryClient,\n resolveMap,\n shouldForce,\n initOptions: options,\n summaryData,\n ctx,\n })\n .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {\n pending--;\n\n if (shouldExit) {\n isExitingPrematurely = true;\n }\n\n if (!isExitingPrematurely && pathsToEvaluate?.size) {\n // If there are paths that need to be rebuilt, add them to the refresh set so that on re-enqueuing\n // we pass the `shouldRerun` flag through\n pathsToRefresh?.forEach((refreshPath) => {\n refreshPaths.add(refreshPath);\n visitedSet.delete(refreshPath);\n });\n\n // Try to enqueue the new paths.\n enqueuePaths(Array.from(pathsToEvaluate));\n }\n\n // If nothing is pending after this call, we're complete.\n if (!pending) {\n resolve(summaryData.summarize());\n }\n })\n .catch((error) => {\n reject(error);\n });\n }\n }\n\n // Start with the app path.\n enqueuePaths([appPath]);\n });\n\n const { totalChanges } = summary;\n\n if (!options.check && totalChanges && generatedConfig.packageSettings?.length) {\n sortExportKeys(generatedConfig);\n\n await writeGeneratedConfig(generatedConfig, appPath);\n }\n\n return summary;\n}\n\nfunction sortExportKeys({ packageSettings = [] }: GeneratedConfig) {\n for (const settings of packageSettings) {\n if (settings.exports) {\n const unsortedExports = settings.exports as Record<string, PackageJsonExportsValue>;\n const sortedKeys = Object.keys(settings.exports).sort();\n\n settings.exports = sortedKeys.reduce((p, n) => {\n p[n] = unsortedExports[n];\n return p;\n }, {} as PackageJsonExportsObject);\n }\n }\n}\n"]}
|
|
@@ -5,7 +5,7 @@ import { isFolder } from '@ms-cloudpack/path-utilities';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { createBundleTask, createBundleRequestForPackage, parseRequestInfo } from '@ms-cloudpack/api-server';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
-
const
|
|
8
|
+
const currentFolder = path.dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
/**
|
|
10
10
|
* The bundle server handles package requests and returns bundled resources.
|
|
11
11
|
* Resources are bundled on demand and cached locally to avoid re-bundling
|
|
@@ -67,46 +67,43 @@ async function handleRequest(options, context) {
|
|
|
67
67
|
if (fullPath.length < packageEntry.path.length) {
|
|
68
68
|
console.debug(`Response (400): "${packageName}@${version}${filePath}"`);
|
|
69
69
|
res.status(400).send(`Invalid file path.`);
|
|
70
|
-
return;
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
else {
|
|
72
|
+
console.debug(`Unbundled response returning: "${packageName}@${version}${filePath}"`);
|
|
73
|
+
// If the package is external, set cache headers.
|
|
74
|
+
if (isExternalPackage(packageEntry.path)) {
|
|
75
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
|
76
|
+
}
|
|
77
|
+
res.sendFile(path.join(packageEntry.path, filePath));
|
|
76
78
|
}
|
|
77
|
-
res.sendFile(path.join(packageEntry.path, filePath));
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
80
81
|
const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });
|
|
81
82
|
// Set up for bundling.
|
|
82
|
-
const rerun = !(await isFolder(bundleRequest.outputPath))
|
|
83
|
+
const rerun = force || !(await isFolder(bundleRequest.outputPath));
|
|
84
|
+
let hasError = false;
|
|
83
85
|
if (features.enableLage) {
|
|
84
86
|
console.debug(`Trying to bundle "${packageName}@${version}" with lage task scheduler`);
|
|
85
87
|
try {
|
|
86
88
|
await apiServer.scheduleTask(bundleRequest, {
|
|
87
|
-
// TODO: we may want to have
|
|
88
|
-
bundle: path.resolve(
|
|
89
|
+
// TODO: we may want to have a way to let users add more types of tasks here
|
|
90
|
+
bundle: path.resolve(currentFolder, '../../tasks/bundleTaskWorker.js'),
|
|
89
91
|
}, { rerun });
|
|
90
|
-
console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
91
|
-
// Try to return the result.
|
|
92
|
-
if (bundleRequest.isExternal) {
|
|
93
|
-
res.setHeader('Cache-Control', 'public, max-age=31536000');
|
|
94
|
-
}
|
|
95
|
-
return res.sendFile(path.join(bundleRequest.outputPath, filePath));
|
|
96
92
|
}
|
|
97
93
|
catch (err) {
|
|
98
|
-
|
|
94
|
+
console.error(`Error bundling "${packageName}@${version}": ${err}`);
|
|
95
|
+
hasError = true;
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
|
-
console.debug(`Trying to bundle "${packageName}@${version}"`);
|
|
102
|
-
const bundleTask = createBundleTask(bundleRequest, { force }, reporter);
|
|
103
|
-
await apiServer.addTask(bundleTask, { rerun });
|
|
104
|
-
// At this point we should have a Task completed.
|
|
105
|
-
if ((bundleRequest.result?.errors?.length || 0) > 0) {
|
|
106
|
-
res.status(500).type('json').send(bundleRequest);
|
|
107
|
-
}
|
|
108
98
|
else {
|
|
109
|
-
|
|
99
|
+
console.debug(`Trying to bundle "${packageName}@${version}"`);
|
|
100
|
+
const bundleTask = createBundleTask(bundleRequest, { force }, reporter);
|
|
101
|
+
await apiServer.addTask(bundleTask, { rerun });
|
|
102
|
+
// At this point we should have a Task completed.
|
|
103
|
+
if (bundleRequest.result?.errors?.length) {
|
|
104
|
+
hasError = true;
|
|
105
|
+
}
|
|
106
|
+
else if (features.enqueueDependencies && bundleRequest.result?.imports) {
|
|
110
107
|
// Enqueue all dependencies to be bundled.
|
|
111
108
|
for (const dependency of Object.keys(bundleRequest.result.imports)) {
|
|
112
109
|
const dependencyBundleRequest = await createBundleRequestForPackage({ packageEntry: resolveMap[dependency] }, { ...context, config });
|
|
@@ -114,6 +111,11 @@ async function handleRequest(options, context) {
|
|
|
114
111
|
void apiServer.addTask(createBundleTask(dependencyBundleRequest, { force }, reporter));
|
|
115
112
|
}
|
|
116
113
|
}
|
|
114
|
+
}
|
|
115
|
+
if (hasError) {
|
|
116
|
+
res.status(500).type('json').send(bundleRequest);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
117
119
|
console.debug(`Bundle returning: "${packageName}@${version}${filePath}"`);
|
|
118
120
|
// Try to return the result.
|
|
119
121
|
if (bundleRequest.isExternal) {
|
|
@@ -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,MAA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AAQ,CAAC,mBAAmB,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE;YACjE,0CAA0C;YAC1C,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;gBAClE,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,4EAA4E;QAC5E,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;QAE1C,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, parseRequestInfo } 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 } = 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 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 });\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?.imports) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of Object.keys(bundleRequest.result.imports)) {\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 // The below header is need to be able to track the browser cache hit ratio.\n res.setHeader('Timing-Allow-Origin', '*');\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":"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,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC7G,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAIpC,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAKvC;IACC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC;QAClD,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI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AC,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, parseRequestInfo } 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 currentFolder = path.dirname(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 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 } else {\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 }\n return;\n }\n\n const bundleRequest = await createBundleRequestForPackage({ packageEntry }, { config, packages });\n\n // Set up for bundling.\n const rerun = force || !(await isFolder(bundleRequest.outputPath));\n let hasError = false;\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 a way to let users add more types of tasks here\n bundle: path.resolve(currentFolder, '../../tasks/bundleTaskWorker.js'),\n },\n { rerun },\n );\n } catch (err) {\n console.error(`Error bundling \"${packageName}@${version}\": ${err}`);\n hasError = true;\n }\n } else {\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) {\n hasError = true;\n } else if (features.enqueueDependencies && bundleRequest.result?.imports) {\n // Enqueue all dependencies to be bundled.\n for (const dependency of Object.keys(bundleRequest.result.imports)) {\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\n if (hasError) {\n res.status(500).type('json').send(bundleRequest);\n } else {\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 // The below header is need to be able to track the browser cache hit ratio.\n res.setHeader('Timing-Allow-Origin', '*');\n\n res.sendFile(path.join(bundleRequest.outputPath, filePath));\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.7",
|
|
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",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@lage-run/target-graph": "^0.8.7",
|
|
14
|
-
"@ms-cloudpack/api-server": "^0.
|
|
15
|
-
"@ms-cloudpack/config": "^0.12.
|
|
16
|
-
"@ms-cloudpack/create-express-app": "^1.3.
|
|
14
|
+
"@ms-cloudpack/api-server": "^0.20.0",
|
|
15
|
+
"@ms-cloudpack/config": "^0.12.6",
|
|
16
|
+
"@ms-cloudpack/create-express-app": "^1.3.10",
|
|
17
17
|
"@ms-cloudpack/json-utilities": "^0.0.7",
|
|
18
|
-
"@ms-cloudpack/overlay": "^0.15.
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^5.1.
|
|
20
|
-
"@ms-cloudpack/path-string-parsing": "^1.0
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^2.3.
|
|
18
|
+
"@ms-cloudpack/overlay": "^0.15.1",
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^5.1.8",
|
|
20
|
+
"@ms-cloudpack/path-string-parsing": "^1.1.0",
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.3.3",
|
|
22
22
|
"@ms-cloudpack/task-reporter": "^0.8.0",
|
|
23
23
|
"@ms-cloudpack/telemetry": "^0.3.8",
|
|
24
24
|
"commander": "^11.0.0",
|