@ms-cloudpack/bundle-server 0.6.95 → 0.6.96
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/handleWorker.d.ts.map +1 -1
- package/lib/handleWorker.js +11 -11
- package/lib/handleWorker.js.map +1 -1
- package/package.json +4 -4
|
@@ -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;AAY1E;;;;;;;;;;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,
|
|
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;AAY1E;;;;;;;;;;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,CAyEf"}
|
package/lib/handleWorker.js
CHANGED
|
@@ -5,7 +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
|
-
const
|
|
8
|
+
const filename = fileURLToPath(import.meta.url);
|
|
9
9
|
let esModuleShim;
|
|
10
10
|
/**
|
|
11
11
|
* The function handles a worker request by shimming import maps, a global object and process.browser
|
|
@@ -72,6 +72,7 @@ export async function handleWorker(options, context) {
|
|
|
72
72
|
|
|
73
73
|
registerDefineFlags(window, ${JSON.stringify(session.config.define ?? {})});
|
|
74
74
|
|
|
75
|
+
globalObject.esmsInitOptions = { shimMode: true };
|
|
75
76
|
${esModuleShim}
|
|
76
77
|
importShim.addImportMap(${JSON.stringify(session.importMap)});
|
|
77
78
|
importShim('${originalUrl.href}')
|
|
@@ -87,23 +88,22 @@ export async function handleWorker(options, context) {
|
|
|
87
88
|
.catch(e => setTimeout(() => { throw e; }));
|
|
88
89
|
`);
|
|
89
90
|
}
|
|
91
|
+
// esModuleShims must point to the non-CSP build of ES Module Shims,
|
|
92
|
+
// namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js
|
|
93
|
+
const esModuleShimsPackage = 'es-module-shims';
|
|
94
|
+
const esModuleShimsFile = 'dist/es-module-shims.wasm.js';
|
|
95
|
+
/** Get the `es-module-shims` WASM build file contents */
|
|
90
96
|
async function getShim() {
|
|
91
|
-
|
|
92
|
-
// namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js
|
|
93
|
-
const esModuleShimsPackage = 'es-module-shims';
|
|
94
|
-
const esModuleShimsFile = `./dist/es-module-shims.wasm.js`;
|
|
95
|
-
const esModuleShimsPath = await resolve(esModuleShimsPackage, parentDir);
|
|
97
|
+
const esModuleShimsPath = await resolve(esModuleShimsPackage, filename);
|
|
96
98
|
if (!esModuleShimsPath) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
99
101
|
const esModuleShimsWasm = path.join(esModuleShimsPath, esModuleShimsFile);
|
|
100
|
-
let esModuleShimString;
|
|
101
102
|
try {
|
|
102
|
-
|
|
103
|
+
return await fsPromises.readFile(esModuleShimsWasm, 'utf8');
|
|
103
104
|
}
|
|
104
|
-
catch
|
|
105
|
-
|
|
105
|
+
catch {
|
|
106
|
+
// ignore
|
|
106
107
|
}
|
|
107
|
-
return esModuleShimString;
|
|
108
108
|
}
|
|
109
109
|
//# sourceMappingURL=handleWorker.js.map
|
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;AAE/D,MAAM,
|
|
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;AAE/D,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,IAAI,YAAgC,CAAC;AAErC;;;;;;;;;;GAUG;AACH,M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8B,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';\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 console.debug(`Response (500): Failed to load import map shim for worker`);\n res.status(500).send(`Failed to load import map shim for worker`);\n return;\n }\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 // 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('${originalUrl.href}')\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.6.
|
|
3
|
+
"version": "0.6.96",
|
|
4
4
|
"description": "An implementation of the Bundle server for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/api-server": "^0.61.
|
|
17
|
+
"@ms-cloudpack/api-server": "^0.61.34",
|
|
18
18
|
"@ms-cloudpack/common-types": "^0.24.16",
|
|
19
19
|
"@ms-cloudpack/create-express-app": "^1.10.29",
|
|
20
20
|
"@ms-cloudpack/import-map": "^0.10.18",
|
|
21
|
-
"@ms-cloudpack/inline-scripts": "^0.1.
|
|
21
|
+
"@ms-cloudpack/inline-scripts": "^0.1.19",
|
|
22
22
|
"@ms-cloudpack/package-utilities": "^12.3.3",
|
|
23
23
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
24
24
|
"@ms-cloudpack/path-utilities": "^3.1.0",
|
|
25
|
-
"es-module-shims": "^
|
|
25
|
+
"es-module-shims": "^2.0.0",
|
|
26
26
|
"ts-dedent": "^2.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|