Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ module.exports = {
],
},
],

'no-restricted-globals': [
'error',
{
name: 'global',
message: "Use 'globalThis' instead.",
},
],
},

globals: {},
Expand Down
3 changes: 1 addition & 2 deletions app-shell-odd/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
// for security reasons
import { ipcRenderer } from 'electron'

// @ts-expect-error can't get TS to recognize global.d.ts
global.APP_SHELL_REMOTE = { ipcRenderer }
globalThis.APP_SHELL_REMOTE = { ipcRenderer }
11 changes: 3 additions & 8 deletions app-shell-odd/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
declare global {
namespace NodeJS {
export interface Global {
APP_SHELL_REMOTE: {
ipcRenderer: IpcRenderer
}
}
}
/* eslint-disable no-var */
declare var APP_SHELL_REMOTE: {
ipcRenderer: IpcRenderer
}

declare const _PKG_VERSION_: string
Expand Down
1 change: 0 additions & 1 deletion app-shell-odd/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default defineConfig(
NODE_ENV: process.env.NODE_ENV,
OPENTRONS_PROJECT: process.env.OPENTRONS_PROJECT,
},
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_PKG_PRODUCT_NAME_: JSON.stringify(pkg.productName),
_PKG_BUGS_URL_: JSON.stringify(pkg.bugs.url),
Expand Down
7 changes: 5 additions & 2 deletions app-shell/src/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ export const DEFAULTS_V0: ConfigV0 = {

// app update config
update: {
// @ts-expect-error can't get TS to recognize global.d.ts
channel: [].includes('beta') ? 'beta' : 'latest',
channel: 'latest',
// todo(mm, 2025-09-15): We used to set this more dynamically depending on _PKG_VERSION_,
// but that got dropped during the Vite migration, possibly because of type-checking problems
// that have since been resolved. Do we want to restore this?
// channel: _PKG_VERSION_.includes('beta') ? 'beta' : 'latest',
},

buildroot: {
Expand Down
3 changes: 1 addition & 2 deletions app-shell/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ const getFilePathFrom = (file: File): Promise<string> => {
return Promise.resolve(webUtils.getPathForFile(file))
}

// @ts-expect-error can't get TS to recognize global.d.ts
global.APP_SHELL_REMOTE = { ipcRenderer, getFilePathFrom }
globalThis.APP_SHELL_REMOTE = { ipcRenderer, getFilePathFrom }
4 changes: 1 addition & 3 deletions app-shell/typings/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable no-var */
declare global {
var APP_SHELL_REMOTE: { ipcRenderer: IpcRenderer; [key: string]: any }
}
declare var APP_SHELL_REMOTE: { ipcRenderer: IpcRenderer; [key: string]: any }

declare const _PKG_VERSION_: string
declare const _PKG_PRODUCT_NAME_: string
Expand Down
1 change: 0 additions & 1 deletion app-shell/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default defineConfig(
NODE_ENV: process.env.NODE_ENV,
OPENTRONS_PROJECT: process.env.OPENTRONS_PROJECT,
},
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_PKG_PRODUCT_NAME_: JSON.stringify(pkg.productName),
_PKG_BUGS_URL_: JSON.stringify(pkg.bugs.url),
Expand Down
10 changes: 8 additions & 2 deletions app/src/App/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { Box } from '@opentrons/components'
export const TOP_PORTAL_ID = '__otAppTopPortalRoot'
export const MODAL_PORTAL_ID = '__otAppModalPortalRoot'
export function getTopPortalEl(): HTMLElement {
return global.document.getElementById(TOP_PORTAL_ID) ?? global.document.body
return (
globalThis.document.getElementById(TOP_PORTAL_ID) ??
globalThis.document.body
)
}
export function getModalPortalEl(): HTMLElement {
return global.document.getElementById(MODAL_PORTAL_ID) ?? global.document.body
return (
globalThis.document.getElementById(MODAL_PORTAL_ID) ??
globalThis.document.body
)
}

export function PortalRoot(): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const mockIpAddress = '1.1.1.1'
const mockLink = `http://${mockIpAddress}:48888`
const trackEvent = vi.fn()

global.window = Object.create(window)
globalThis.window = Object.create(window)
Object.defineProperty(window, 'open', { writable: true, configurable: true })
window.open = vi.fn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ const render = () => {
}

describe('CalibrationDataDownload', () => {
const realBlob = global.Blob
const realBlob = globalThis.Blob

beforeAll(() => {
// @ts-expect-error(sa, 2021-6-28): not a valid blob interface
global.Blob = function (content: any, options: any) {
globalThis.Blob = function (content: any, options: any) {
return { content, options }
}
})

afterAll(() => {
global.Blob = realBlob
globalThis.Blob = realBlob
})

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/redux/analytics/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function hash(source: string): Promise<string> {
const data = encoder.encode(source)

// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
return global.crypto.subtle
return globalThis.crypto.subtle
.digest(ALGORITHM, data)
.then((digest: ArrayBuffer) => arrayBufferToHex(digest))
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/redux/robot-api/__tests__/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('robot-api http client', () => {
let robot: RobotHost

beforeAll(() => {
;(global as any).fetch = fetch
;(globalThis as any).fetch = fetch
testApp = express()
testApp.use((express as any).json())

Expand Down Expand Up @@ -55,7 +55,7 @@ describe('robot-api http client', () => {

afterAll(() => {
// @ts-expect-error(sa, 2021-6-28): can't delete non optional properties
delete global.fetch
delete globalThis.fetch

if (testServer) {
const close = promisify(testServer.close.bind(testServer))
Expand Down
6 changes: 3 additions & 3 deletions app/src/redux/shell/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
export const remote: Remote = new Proxy(emptyRemote, {
get(_target, propName: string): unknown {
console.assert(
(global as any).APP_SHELL_REMOTE,
globalThis.APP_SHELL_REMOTE,

Check failure on line 15 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

Check failure on line 15 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
'Expected APP_SHELL_REMOTE to be attached to global scope; is app-shell/src/preload.ts properly configured?'
)

console.assert(
propName in (global as any).APP_SHELL_REMOTE,
propName in globalThis.APP_SHELL_REMOTE,

Check failure on line 20 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

Check failure on line 20 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
`Expected APP_SHELL_REMOTE.${propName} to exist, is app-shell/src/preload.ts properly configured?`
)
return (global as any).APP_SHELL_REMOTE[propName] as Remote
return globalThis.APP_SHELL_REMOTE[propName] as Remote

Check failure on line 23 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ ipcRenderer: IpcRenderer; }'.

Check failure on line 23 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

Check failure on line 23 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ ipcRenderer: IpcRenderer; }'.

Check failure on line 23 in app/src/redux/shell/remote.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
},
})

Expand Down
1 change: 0 additions & 1 deletion app/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default defineConfig(
OT_APP_MIXPANEL_ID: process.env.OT_APP_MIXPANEL_ID,
OPENTRONS_PROJECT: process.env.OPENTRONS_PROJECT,
},
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_OPENTRONS_PROJECT_: JSON.stringify(project),
},
Expand Down
1 change: 0 additions & 1 deletion components/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default defineConfig({
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
Expand Down
1 change: 0 additions & 1 deletion discovery-client/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default defineConfig(
},
define: {
'process.env': process.env,
global: 'globalThis',
_PKG_VERSION_: JSON.stringify(version),
_PKG_BUGS_URL_: JSON.stringify(pkg.bugs.url),
_OPENTRONS_PROJECT_: JSON.stringify(project),
Expand Down
1 change: 0 additions & 1 deletion labware-designer/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default defineConfig({
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
Expand Down
4 changes: 2 additions & 2 deletions labware-library/src/analytics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const persistAnalyticsCookie = (cookies: AnalyticsState): void => {
const maxAge = 10 * 365 * 24 * 60 * 60 // 10 years
const options = { COOKIE_DOMAIN, maxAge }

;(global as any).document.cookie = cookie.serialize(
globalThis.document.cookie = cookie.serialize(
COOKIE_KEY_NAME,
JSON.stringify(cookies),
options
)
}

const getAnalyticsCookie = (): AnalyticsState => {
const cookies = cookie.parse((global as any).document.cookie as string)
const cookies = cookie.parse(globalThis.document.cookie)
const analyticsCookie =
cookies[COOKIE_KEY_NAME] != null ? JSON.parse(cookies[COOKIE_KEY_NAME]) : {}
return analyticsCookie
Expand Down
1 change: 0 additions & 1 deletion labware-library/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default defineConfig({
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
Expand Down
2 changes: 1 addition & 1 deletion opentrons-ai-client/src/OpentronsAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function OpentronsAIApp(): JSX.Element | null {
return null
}

global.enablePrereleaseMode = () => {
globalThis.enablePrereleaseMode = () => {
setFeatureFlags({ enablePrereleaseMode: true })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function LabwareModal({
</Flex>
</Flex>
</Modal>,
global.document.body
globalThis.document.body
)}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { UpdateProtocol } from '../index'

import type { NavigateFunction } from 'react-router-dom'

// global.Blob = BlobPolyfill as any
global.Blob = require('node:buffer').Blob
// globalThis.Blob = BlobPolyfill as any
globalThis.Blob = require('node:buffer').Blob

const mockNavigate = vi.fn()
const mockUseTrackEvent = vi.fn()
Expand Down
1 change: 0 additions & 1 deletion opentrons-ai-client/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default defineConfig({
},
define: {
'process.env': process.env,
global: 'globalThis',
},
resolve: {
alias: {
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/__tests__/persist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('persist', () => {
let setItemSpy: MockInstance<(key: string, value: string) => void>

beforeEach(() => {
const LocalStorageProto = Object.getPrototypeOf(global.localStorage)
const LocalStorageProto = Object.getPrototypeOf(globalThis.localStorage)
getItemSpy = vi.spyOn(LocalStorageProto, 'getItem') as MockInstance<
(key: string) => string | null
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function LiquidToolbox({

const handleClearSelectedWells: () => void = () => {
if (labwareId != null && selectedWells != null && selectionHasLiquids) {
if (global.confirm(t('application:are_you_sure') as string)) {
if (globalThis.confirm(t('application:are_you_sure') as string)) {
dispatch(
removeWellsContents({
labwareId,
Expand All @@ -164,7 +164,9 @@ export function LiquidToolbox({
const handleClearAllWells: () => void = () => {
if (labwareId != null && activeItemHasLiquids) {
if (
global.confirm(t('application:are_you_sure_clear_all_wells') as string)
globalThis.confirm(
t('application:are_you_sure_clear_all_wells') as string
)
) {
dispatch(
removeWellsContents({
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
store.dispatch(rehydratePersistedAction())
store.subscribe(makePersistSubscriber(store))

global.enablePrereleaseMode = () => {
globalThis.enablePrereleaseMode = () => {

Check failure on line 112 in protocol-designer/src/configureStore.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.

Check failure on line 112 in protocol-designer/src/configureStore.ts

View workflow job for this annotation

GitHub Actions / js checks

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
store.dispatch({
type: 'SET_FEATURE_FLAGS',
payload: {
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/labware-ingred/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const deleteLiquidGroup: (
const liquidIsOnDeck = allLiquidGroups.includes(liquidGroupId)

const okToDelete = liquidIsOnDeck
? global.confirm(
? globalThis.confirm(
'This liquid has been placed on the deck, are you sure you want to delete it?'
)
: true
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/networking/opentronsWebApi.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const getIsProduction = (): boolean =>
global.location.host === 'designer.opentrons.com'
globalThis.location.host === 'designer.opentrons.com'
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export function ConnectedStepContainer(
}

useEffect(() => {
global.addEventListener('click', handleClick)
globalThis.addEventListener('click', handleClick)
return () => {
global.removeEventListener('click', handleClick)
globalThis.removeEventListener('click', handleClick)
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export function TimelineToolbox({
handleKeyDown(e)
}

global.addEventListener('keydown', onKeyDown, false)
globalThis.addEventListener('keydown', onKeyDown, false)

return () => {
global.removeEventListener('keydown', onKeyDown, false)
globalThis.removeEventListener('keydown', onKeyDown, false)
}
}, [])

Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface RehydratePersistedAction {
}
export const getLocalStorageItem = (path: string): unknown => {
try {
const persisted = global.localStorage.getItem(_addStoragePrefix(path))
const persisted = globalThis.localStorage.getItem(_addStoragePrefix(path))
return persisted ? JSON.parse(persisted) : undefined
} catch (e) {
console.error('Could not rehydrate:', e)
Expand Down Expand Up @@ -80,7 +80,7 @@ function transformBeforePersist(

export const setLocalStorageItem = (path: string, value: any): void => {
try {
global.localStorage.setItem(
globalThis.localStorage.setItem(
_addStoragePrefix(path),
JSON.stringify(transformBeforePersist(path, value))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('steps actions', () => {
.calledWith(expect.anything())
.thenReturn(null)
const consoleWarnSpy = vi
.spyOn(global.console, 'warn')
.spyOn(globalThis.console, 'warn')
.mockImplementation(() => null)
const store: any = mockStore()
store.dispatch(deselectAllSteps())
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/ui/steps/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const MAIN_CONTENT_FORCED_SCROLL_CLASSNAME = 'main_content_forced_scroll'
// being positioned absolute until we can figure out something better
export const resetScrollElements = (): void => {
forEach(
global.document.getElementsByClassName(
globalThis.document.getElementsByClassName(
MAIN_CONTENT_FORCED_SCROLL_CLASSNAME
),
elem => {
Expand Down
1 change: 0 additions & 1 deletion protocol-designer/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export default defineConfig(
},
define: {
'process.env': { ...process.env, OT_PD_VERSION, OT_PD_BUILD_DATE },
global: 'globalThis',
},
resolve: {
alias: {
Expand Down
1 change: 0 additions & 1 deletion shared-data/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export default defineConfig({
},
define: {
'process.env': process.env,
global: 'globalThis',
},
})
Loading
Loading