Skip to content

Commit

Permalink
fix: load only specified typings for TypeScript (#14808)
Browse files Browse the repository at this point in the history
Fix: Don't rely on `global` object available only in Node. Fixes ckeditor/vite-plugin-ckeditor5#17 and #14801.

Internal: Load only specified typings for TypeScript. Closes #14173.
  • Loading branch information
filipsobol committed Aug 25, 2023
1 parent b244b66 commit b7a984b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class MutationObserver extends Observer {
/**
* Native mutation observer.
*/
private _mutationObserver: InstanceType<typeof global.MutationObserver>;
private _mutationObserver: InstanceType<typeof window.MutationObserver>;

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @module utils/dom/getelementsintersectionrect
*/

import global from './global';
import Rect from './rect';

/**
Expand Down
9 changes: 2 additions & 7 deletions packages/ckeditor5-utils/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* @module utils/version
*/

/* globals window, global */

import CKEditorError from './ckeditorerror';

const version = '39.0.1';
Expand All @@ -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
Expand Down Expand Up @@ -167,5 +162,5 @@ if ( windowOrGlobal.CKEDITOR_VERSION ) {
null
);
} else {
windowOrGlobal.CKEDITOR_VERSION = version;
globalThis.CKEDITOR_VERSION = version;
}
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit b7a984b

Please sign in to comment.