Skip to content

Commit

Permalink
[core] chore: isolate dom4 import to its own module (#3868)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Nov 27, 2019
1 parent cb11010 commit 8ee0900
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.2.4",
"version": "3.5.3",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"unpkg": "dist/core.bundle.js",
"sideEffects": [
"*.css",
"lib/esm/components/index.js",
"lib/esnext/components/index.js",
"lib/cjs/components/index.js"
"lib/esm/common/configureDom4.js",
"lib/esnext/common/configureDom4.js",
"lib/cjs/common/configureDom4.js"
],
"bin": {
"upgrade-blueprint-2.0.0-rename": "./scripts/upgrade-blueprint-2.0.0-rename.sh",
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/common/configureDom4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2019 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

if (typeof require !== "undefined" && typeof window !== "undefined" && typeof document !== "undefined") {
// we're in browser
// tslint:disable-next-line:no-var-requires
require("dom4"); // only import actual dom4 if we're in the browser (not server-compatible)
// we'll still need dom4 types for the TypeScript to compile, these are included in package.json
}
2 changes: 2 additions & 0 deletions packages/core/src/common/utils/isDarkTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import "../configureDom4";

import { Classes } from "../";

export function isDarkTheme(element: Element | Text | null): boolean {
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
* limitations under the License.
*/

declare function require(moduleName: string): any; // declare node.js "require" so that we can conditionally import
if (typeof window !== "undefined" && typeof document !== "undefined") {
// we're in browser
// tslint:disable-next-line:no-var-requires
require("dom4"); // only import actual dom4 if we're in the browser (not server-compatible)
// we'll still need dom4 types for the TypeScript to compile, these are included in package.json
}
import "../common/configureDom4";

import * as contextMenu from "./context-menu/contextMenu";
export const ContextMenu = contextMenu;
Expand Down

1 comment on commit 8ee0900

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core] chore: isolate dom4 import to its own module (#3868)

Previews: documentation | landing | table

Please sign in to comment.