From b7a984b19769cd85e3016d82b75ad6d7ac66ec17 Mon Sep 17 00:00:00 2001 From: Filip Sobol Date: Fri, 25 Aug 2023 14:12:21 +0200 Subject: [PATCH] fix: load only specified typings for TypeScript (#14808) Fix: Don't rely on `global` object available only in Node. Fixes https://github.com/ckeditor/vite-plugin-ckeditor5/issues/17 and #14801. Internal: Load only specified typings for TypeScript. Closes #14173. --- .../src/view/observer/mutationobserver.ts | 2 +- .../src/dom/getelementsintersectionrect.ts | 1 + packages/ckeditor5-utils/src/version.ts | 9 ++------- tsconfig.json | 11 +++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/ckeditor5-engine/src/view/observer/mutationobserver.ts b/packages/ckeditor5-engine/src/view/observer/mutationobserver.ts index c4fb868a9b3..e8f021f9455 100644 --- a/packages/ckeditor5-engine/src/view/observer/mutationobserver.ts +++ b/packages/ckeditor5-engine/src/view/observer/mutationobserver.ts @@ -55,7 +55,7 @@ export default class MutationObserver extends Observer { /** * Native mutation observer. */ - private _mutationObserver: InstanceType; + private _mutationObserver: InstanceType; /** * @inheritDoc diff --git a/packages/ckeditor5-utils/src/dom/getelementsintersectionrect.ts b/packages/ckeditor5-utils/src/dom/getelementsintersectionrect.ts index 6d8e2049afa..ddbf509b9a3 100644 --- a/packages/ckeditor5-utils/src/dom/getelementsintersectionrect.ts +++ b/packages/ckeditor5-utils/src/dom/getelementsintersectionrect.ts @@ -7,6 +7,7 @@ * @module utils/dom/getelementsintersectionrect */ +import global from './global'; import Rect from './rect'; /** diff --git a/packages/ckeditor5-utils/src/version.ts b/packages/ckeditor5-utils/src/version.ts index f301e40b667..d766361ca39 100644 --- a/packages/ckeditor5-utils/src/version.ts +++ b/packages/ckeditor5-utils/src/version.ts @@ -7,8 +7,6 @@ * @module utils/version */ -/* globals window, global */ - import CKEditorError from './ckeditorerror'; const version = '39.0.1'; @@ -18,16 +16,13 @@ export default version; // The second argument is not a month. It is `monthIndex` and starts from `0`. export const releaseDate = new Date( 2023, 7, 10 ); -/* istanbul ignore next -- @preserve */ -const windowOrGlobal = typeof window === 'object' ? window : global; - declare global { // eslint-disable-next-line no-var var CKEDITOR_VERSION: string; } /* istanbul ignore next -- @preserve */ -if ( windowOrGlobal.CKEDITOR_VERSION ) { +if ( globalThis.CKEDITOR_VERSION ) { /** * This error is thrown when due to a mistake in how CKEditor 5 was installed or initialized, some * of its modules were duplicated (evaluated and executed twice). Module duplication leads to inevitable runtime @@ -167,5 +162,5 @@ if ( windowOrGlobal.CKEDITOR_VERSION ) { null ); } else { - windowOrGlobal.CKEDITOR_VERSION = version; + globalThis.CKEDITOR_VERSION = version; } diff --git a/tsconfig.json b/tsconfig.json index 66b532c5b54..7bf691ba413 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,18 @@ */ { "compilerOptions": { + /** + * TypeScript automagically loads typings from all "@types/*" packages if the "compilerOptions.types" array is not defined in + * this file. However, if some dependencies have "@types/*" packages as their dependencies, they'll also be loaded as well. + * As a result, TypeScript loaded "@types/node" which we don't want to use, because it allows using Node.js specific APIs that + * are not available in the browsers. + * + * To avoid such issues, we defined this empty "types" to disable automatic inclusion of the "@types/*" packages. + */ + "types": [], "lib": [ + "ES2019", // Must match the "target" + "ES2020.String", "DOM", "DOM.Iterable" ],