diff --git a/NOTICE.txt b/NOTICE.txt index 0f79b16b0b043..ed8b96176e920 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,6 +1,31 @@ Kibana source code with Kibana X-Pack source code Copyright 2012-2024 Elasticsearch B.V. +--- +Adapted from remote-web-worker, which was available under a "MIT" license. + +MIT License (MIT) + +Copyright (c) 2022 Jan Nicklas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + --- Pretty handling of logarithmic axes. Copyright (c) 2007-2014 IOLA and Ole Laursen. diff --git a/packages/kbn-test/src/jest/setup/polyfills.jsdom.js b/packages/kbn-test/src/jest/setup/polyfills.jsdom.js index 8016e0bd2b910..dbe4213ca83f7 100644 --- a/packages/kbn-test/src/jest/setup/polyfills.jsdom.js +++ b/packages/kbn-test/src/jest/setup/polyfills.jsdom.js @@ -32,3 +32,18 @@ global.Blob = require('blob-polyfill').Blob; if (!global.hasOwnProperty('ResizeObserver')) { global.ResizeObserver = require('resize-observer-polyfill'); } + +if (!global.hasOwnProperty('Worker')) { + class Worker { + constructor(stringUrl) { + this.url = stringUrl; + this.onmessage = () => {}; + } + + postMessage(msg) { + this.onmessage(msg); + } + } + + global.Worker = Worker; +} diff --git a/packages/kbn-ui-shared-deps-src/src/polyfills.js b/packages/kbn-ui-shared-deps-src/src/polyfills.js index cc8e1f9b75d5c..b942b5e92ff3c 100644 --- a/packages/kbn-ui-shared-deps-src/src/polyfills.js +++ b/packages/kbn-ui-shared-deps-src/src/polyfills.js @@ -17,3 +17,85 @@ if (typeof window.Event === 'object') { require('whatwg-fetch'); require('symbol-observable'); + +/* @notice + * + * Adapted from remote-web-worker, which was available under a "MIT" license. + * + * MIT License (MIT) + * + * Copyright (c) 2022 Jan Nicklas + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +typeof window !== 'undefined' && + // eslint-disable-next-line no-global-assign + (Worker = ((BaseWorker) => + class Worker extends BaseWorker { + constructor(url, options) { + let scriptUrl = String(url); + let objectURLRef; + + try { + const isCrossOrigin = (URLObject) => + URLObject.protocol === 'https:' && URLObject.origin !== window.location.origin; + + scriptUrl = isCrossOrigin(new URL(scriptUrl)) // to bootstrap the actual script to work around the same origin policy. + ? (objectURLRef = URL.createObjectURL( + new Blob( + [ + // Replace the `importScripts` function with + // a patched version that will resolve relative URLs + // to the remote script URL. + // + // Without a patched `importScripts` Webpack 5 generated worker chunks will fail with the following error: + // + // Uncaught (in promise) DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': + // The script at 'http://some.domain/worker.1e0e1e0e.js' failed to load. + // + // For minification, the inlined variable names are single letters: + // i = original importScripts + // a = arguments + // u = URL + `importScripts=((i)=>(...a)=>i(...a.map((u)=>''+new URL(u,"${scriptUrl}"))))(importScripts);importScripts("${scriptUrl}");`, + ], + { + type: 'text/javascript', + } + ) + )) + : scriptUrl; + } catch { + // provided url doesn't match the expectation for URL constructor, it will be used as is + } + + super(scriptUrl, options); + + this.addEventListener( + 'message', + function revokeURL() { + if (objectURLRef) { + URL.revokeObjectURL(objectURLRef); + objectURLRef = null; + } + }, + { once: true } + ); + } + })(Worker)); diff --git a/src/dev/build/tasks/create_cdn_assets_task.ts b/src/dev/build/tasks/create_cdn_assets_task.ts index 2555795d50d80..870fd05c4ae39 100644 --- a/src/dev/build/tasks/create_cdn_assets_task.ts +++ b/src/dev/build/tasks/create_cdn_assets_task.ts @@ -76,7 +76,10 @@ export const CreateCdnAssets: Task = { resolve(buildSource, 'node_modules/@kbn/core/target/public'), resolve(bundles, 'core') ); - await copyAll(resolve(buildSource, 'node_modules/@kbn/monaco'), resolve(bundles, 'kbn-monaco')); + await copyAll( + resolve(buildSource, 'node_modules/@kbn/monaco/target_workers'), + resolve(bundles, 'kbn-monaco') + ); // packages/core/apps/core-apps-server-internal/src/core_app.ts await copyAll(