@ms-cloudpack/bundle-server 0.8.49 → 0.8.51
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":"handleWorker.d.ts","sourceRoot":"","sources":["../src/handleWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"handleWorker.d.ts","sourceRoot":"","sources":["../src/handleWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAc1E;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE;IACP,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACf,EACD,OAAO,EAAE,cAAc,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC,GAClE,OAAO,CAAC,IAAI,CAAC,CAsFf"}
|
package/lib/handleWorker.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import fsPromises from 'fs/promises';
|
|
7
7
|
import { getInlineScript } from '@ms-cloudpack/inline-scripts';
|
|
8
|
+
import { reduceResourceUrl } from '@ms-cloudpack/import-map';
|
|
8
9
|
import { logResponse, sendErrorResponse } from './responseHelpers.js';
|
|
9
10
|
const filename = fileURLToPath(import.meta.url);
|
|
10
11
|
let esModuleShim;
|
|
@@ -32,9 +33,14 @@ export async function handleWorker(options, context) {
|
|
|
32
33
|
message: 'Failed to load import map shim for worker',
|
|
33
34
|
});
|
|
34
35
|
}
|
|
36
|
+
const { relativeImportMapPaths } = session.config.features ?? {};
|
|
37
|
+
const appUrl = relativeImportMapPaths ? session.urls.appServer : undefined;
|
|
35
38
|
const originalUrl = makeUrl(req.url, session.urls.bundleServer);
|
|
36
39
|
// Add the worker query parameter so the bundle server knows it has ben shimmed
|
|
37
40
|
originalUrl.searchParams.set('worker', 'shim');
|
|
41
|
+
// Convert to relative path if relativeImportMapPaths is enabled
|
|
42
|
+
const workerUrl = reduceResourceUrl(originalUrl, appUrl);
|
|
43
|
+
console.debug(`Handling worker request for ${req.path}, shimmed url: ${workerUrl}`);
|
|
38
44
|
logResponse({ status: 200, requestPath: req.path, message: 'Returning worker shim' });
|
|
39
45
|
// The following code is based on https://github.com/guybedford/es-module-shims?tab=readme-ov-file#module-workers
|
|
40
46
|
// but it uses the bundle server to avoid sending a blob and to preserve url parameters
|
|
@@ -80,7 +86,7 @@ export async function handleWorker(options, context) {
|
|
|
80
86
|
globalObject.esmsInitOptions = { shimMode: true };
|
|
81
87
|
${esModuleShim}
|
|
82
88
|
importShim.addImportMap(${JSON.stringify(session.importMap)});
|
|
83
|
-
importShim('${
|
|
89
|
+
importShim('${workerUrl}')
|
|
84
90
|
.then(() => {
|
|
85
91
|
pending = false;
|
|
86
92
|
// Process the message queue
|
package/lib/handleWorker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleWorker.js","sourceRoot":"","sources":["../src/handleWorker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;A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M,oBAAoB,GAAG,iBAAiB,CAAC;AAC/C,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEzD,yDAAyD;AACzD,KAAK,UAAU,OAAO;IACpB,MAAM,iBAAiB,GAAG,MAAM,OAAO,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC;IACxE,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO;IACT,CAAC;IACD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAC1E,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;AACH,CAAC","sourcesContent":["import type { PartialContext } from '@ms-cloudpack/api-server';\nimport type { Request, Response } from '@ms-cloudpack/create-express-app';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { dedent } from 'ts-dedent';\nimport { resolve } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport fsPromises from 'fs/promises';\nimport { getInlineScript } from '@ms-cloudpack/inline-scripts';\nimport { reduceResourceUrl } from '@ms-cloudpack/import-map';\nimport { logResponse, sendErrorResponse } from './responseHelpers.js';\n\nconst filename = fileURLToPath(import.meta.url);\nlet esModuleShim: string | undefined;\n\n/**\n * The function handles a worker request by shimming import maps, a global object and process.browser\n * It also adds the worker query parameter so the bundle server knows it has been shimmed,\n * while preserving other query parameters\n *\n * It is called when the feature `enableModuleWorkers` is enabled, the worker has not been handled yet,\n * and the output file is a worker.\n *\n * This works even for workers that are not in the import map, as long as they are in the bundle. It also works\n * when the worker is requested through a blob as the the request goes through the bundle server.\n */\nexport async function handleWorker(\n options: {\n req: Request;\n res: Response;\n },\n context: PartialContext<'session', 'importMap' | 'urls' | 'config'>,\n): Promise<void> {\n const { req, res } = options;\n const { session } = context;\n\n esModuleShim ??= await getShim();\n\n if (!esModuleShim) {\n // If we can't get the shim, we can't handle the worker request\n return sendErrorResponse({\n res,\n status: 500,\n requestPath: req.path,\n message: 'Failed to load import map shim for worker',\n });\n }\n\n const { relativeImportMapPaths } = session.config.features ?? {};\n const appUrl = relativeImportMapPaths ? session.urls.appServer : undefined;\n\n const originalUrl = makeUrl(req.url, session.urls.bundleServer);\n // Add the worker query parameter so the bundle server knows it has ben shimmed\n originalUrl.searchParams.set('worker', 'shim');\n\n // Convert to relative path if relativeImportMapPaths is enabled\n const workerUrl = reduceResourceUrl(originalUrl, appUrl);\n\n console.debug(`Handling worker request for ${req.path}, shimmed url: ${workerUrl}`);\n\n logResponse({ status: 200, requestPath: req.path, message: 'Returning worker shim' });\n\n // The following code is based on https://github.com/guybedford/es-module-shims?tab=readme-ov-file#module-workers\n // but it uses the bundle server to avoid sending a blob and to preserve url parameters\n // it also shims the global object and process.browser for compatibility with some packages\n // We also need to set up web worker and shared worker temporary handlers right away\n // to receive messages from the main thread\n // This is necessary as there is a bug in the browser that when the handlers are\n // set up inside an async function the messages are not received.\n // In this case importShim is an async function.\n res.type('text/javascript').send(dedent`\n var pending = true;\n var messageQueue = [];\n self.onmessage = function (event) {\n if (pending) {\n messageQueue.push(event);\n }\n };\n self.onconnect = function (event) {\n if (pending) {\n messageQueue.push(event);\n }\n };\n\n // Shim the global object in workers\n var globalObject =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n var window = globalObject;\n\n ${await getInlineScript('defineProcess')}\n\n ${await getInlineScript('registerDefineFlags')}\n\n registerDefineFlags(window, ${JSON.stringify(session.config.define ?? {})});\n\n globalObject.esmsInitOptions = { shimMode: true };\n ${esModuleShim}\n importShim.addImportMap(${JSON.stringify(session.importMap)});\n importShim('${workerUrl}')\n .then(() => {\n pending = false;\n // Process the message queue\n while (messageQueue.length) {\n const message = messageQueue.shift();\n self.onmessage(message);\n self.onconnect(message);\n }\n })\n .catch(e => setTimeout(() => { throw e; }));\n `);\n}\n\n// esModuleShims must point to the non-CSP build of ES Module Shims,\n// namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js\nconst esModuleShimsPackage = 'es-module-shims';\nconst esModuleShimsFile = 'dist/es-module-shims.wasm.js';\n\n/** Get the `es-module-shims` WASM build file contents */\nasync function getShim(): Promise<string | undefined> {\n const esModuleShimsPath = await resolve(esModuleShimsPackage, filename);\n if (!esModuleShimsPath) {\n return;\n }\n const esModuleShimsWasm = path.join(esModuleShimsPath, esModuleShimsFile);\n try {\n return await fsPromises.readFile(esModuleShimsWasm, 'utf8');\n } catch {\n // ignore\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundle-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.51",
|
|
4
4
|
"description": "Internal bundle server for Cloudpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"lint": "cloudpack-scripts lint"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ms-cloudpack/api-server": "^0.66.
|
|
24
|
+
"@ms-cloudpack/api-server": "^0.66.12",
|
|
25
25
|
"@ms-cloudpack/common-types": "^0.33.2",
|
|
26
26
|
"@ms-cloudpack/create-express-app": "^1.10.69",
|
|
27
|
-
"@ms-cloudpack/import-map": "^0.
|
|
28
|
-
"@ms-cloudpack/inline-scripts": "^0.2.
|
|
29
|
-
"@ms-cloudpack/package-utilities": "^13.3.
|
|
27
|
+
"@ms-cloudpack/import-map": "^0.12.0",
|
|
28
|
+
"@ms-cloudpack/inline-scripts": "^0.2.73",
|
|
29
|
+
"@ms-cloudpack/package-utilities": "^13.3.6",
|
|
30
30
|
"@ms-cloudpack/path-string-parsing": "^1.3.0",
|
|
31
31
|
"@ms-cloudpack/path-utilities": "^3.2.5",
|
|
32
32
|
"es-module-shims": "^2.6.1",
|