diff --git a/core/backend/package.json b/core/backend/package.json index 6aa926c55353..ec7919e0ae62 100644 --- a/core/backend/package.json +++ b/core/backend/package.json @@ -3,19 +3,21 @@ "version": "4.10.0-dev.33", "description": "iTwin.js backend components", "main": "lib/cjs/core-backend.js", + "module": "lib/esm/core-backend.js", "typings": "lib/cjs/core-backend", "license": "MIT", "engines": { "node": "^18.0.0 || ^20.0.0" }, "scripts": { - "build": "npm run -s build:cjs && npm run -s copy:assets && npm run -s copy:test-assets", + "build": "npm run -s build:cjs && npm run -s build:esm && npm run -s copy:assets && npm run -s copy:test-assets", "build:cjs": "tsc 1>&2 --outDir lib/cjs", + "build:esm": "tsc 1>&2 --module ES2020 --outDir lib/esm", "clean": "rimraf lib .rush/temp/package-deps*.json ../../tools/internal/ios/core-test-runner/build ../../tools/internal/lib", "docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/core/core-backend/file.json --tsIndexFile=./core-backend.ts --onlyJson --excludeGlob=**/*.d.ts", - "copy:assets": "cpx \"./src/assets/**/*\" ./lib/cjs/assets", + "copy:assets": "cpx \"./src/assets/**/*\" ./lib/cjs/assets && cpx \"./src/assets/**/*\" ./lib/esm/assets", "copy:config": "internal-tools copy-config", - "copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/cjs/test/assets", + "copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/cjs/test/assets && cpx \"./src/test/assets/**/*\" ./lib/esm/test/assets", "cover": "nyc npm -s test", "extract-api": "betools extract-api --entry=core-backend", "lint": "eslint \"./src/**/*.ts\" 1>&2", diff --git a/core/backend/src/test/schema/FunctionalDomain.test.ts b/core/backend/src/test/schema/FunctionalDomain.test.ts index 3ee6001dccb3..10b00903c568 100644 --- a/core/backend/src/test/schema/FunctionalDomain.test.ts +++ b/core/backend/src/test/schema/FunctionalDomain.test.ts @@ -5,7 +5,7 @@ import { assert, expect } from "chai"; import { join } from "path"; -import { restore as sinonRestore, spy as sinonSpy } from "sinon"; +import { restore as sinonRestore, SinonSpy, spy as sinonSpy } from "sinon"; import { Guid, Id64 } from "@itwin/core-bentley"; import { CodeScopeSpec, CodeSpec, ElementProps, IModel } from "@itwin/core-common"; import { ClassRegistry } from "../../ClassRegistry"; @@ -18,7 +18,6 @@ import { import { ElementOwnsChildElements, ElementOwnsUniqueAspect, SubjectOwnsPartitionElements } from "../../NavigationRelationship"; import { IModelTestUtils } from "../IModelTestUtils"; import { KnownTestLocations } from "../KnownTestLocations"; -import Sinon = require("sinon"); // eslint-disable-line @typescript-eslint/no-require-imports let iModelDb: StandaloneDb; const insertedLabel = "inserted label"; @@ -276,7 +275,7 @@ describe("Functional Domain", () => { const testChannelKey1 = "channel 1 for tests"; const testChannelKey2 = "channel 2 for tests"; - function testChannel(channelKey: ChannelKey, fn: () => T, spies: Sinon.SinonSpy[]) { + function testChannel(channelKey: ChannelKey, fn: () => T, spies: SinonSpy[]) { iModelDb.channels.removeAllowedChannel(channelKey); expect(fn).throws("not allowed"); iModelDb.channels.addAllowedChannel(channelKey); diff --git a/core/backend/src/test/standalone/ChangeConflictHandler.test.ts b/core/backend/src/test/standalone/ChangeConflictHandler.test.ts index 4e9ed26e4efc..3631cc5cf619 100644 --- a/core/backend/src/test/standalone/ChangeConflictHandler.test.ts +++ b/core/backend/src/test/standalone/ChangeConflictHandler.test.ts @@ -13,6 +13,7 @@ import { import * as chai from "chai"; import { assert, expect } from "chai"; import * as chaiAsPromised from "chai-as-promised"; +import { restore, SinonSpy, SinonStub, spy, stub } from "sinon"; import { HubWrappers, KnownTestLocations } from "../"; import { HubMock } from "../../HubMock"; import { @@ -25,7 +26,6 @@ import { import { IModelTestUtils, TestUserType } from "../IModelTestUtils"; import { ChangesetConflictArgs } from "../../internal/ChangesetConflictArgs"; chai.use(chaiAsPromised); -import sinon = require("sinon"); // eslint-disable-line @typescript-eslint/no-require-imports async function assertThrowsAsync(test: () => Promise, msg?: string) { try { @@ -139,7 +139,7 @@ describe("Changeset conflict handler", () => { }); afterEach(async () => { - sinon.restore(); + restore(); if (b1.isOpen) { b1.abandonChanges(); @@ -157,8 +157,8 @@ describe("Changeset conflict handler", () => { } }); - async function spyChangesetConflictHandler(b: BriefcaseDb, cb: () => Promise, test: (s: sinon.SinonSpy) => void) { - const s1 = sinon.spy(b, "onChangesetConflict" as any) as sinon.SinonSpy; + async function spyChangesetConflictHandler(b: BriefcaseDb, cb: () => Promise, test: (s: SinonSpy) => void) { + const s1 = spy(b, "onChangesetConflict" as any) as sinon.SinonSpy; try { await cb(); } finally { @@ -167,17 +167,17 @@ describe("Changeset conflict handler", () => { } } - async function stubChangesetConflictHandler(b: BriefcaseDb, cb: () => Promise, test: (s: sinon.SinonStub) => void) { - const s1 = sinon.stub(b as any, "onChangesetConflict" as any); + async function stubChangesetConflictHandler(b: BriefcaseDb, cb: () => Promise, test: (s: SinonStub) => void) { + const s1 = stub(b as any, "onChangesetConflict" as any); try { - test(s1 as sinon.SinonStub); + test(s1 as SinonStub); await cb(); } finally { s1.restore(); } } async function fakeChangesetConflictHandler(b: BriefcaseDb, cb: () => Promise, interceptMethod: (arg: ChangesetConflictArgs) => DbConflictResolution | undefined) { - const s1 = sinon.stub(b as any, "onChangesetConflict" as any); + const s1 = stub(b as any, "onChangesetConflict" as any); s1.callsFake(interceptMethod); try { await cb(); diff --git a/core/backend/src/test/standalone/MergeConflict.test.ts b/core/backend/src/test/standalone/MergeConflict.test.ts index 73f69e8cd5ab..68b40d2e736e 100644 --- a/core/backend/src/test/standalone/MergeConflict.test.ts +++ b/core/backend/src/test/standalone/MergeConflict.test.ts @@ -12,6 +12,7 @@ import { import * as chai from "chai"; import { assert, expect } from "chai"; import * as chaiAsPromised from "chai-as-promised"; +import { stub } from "sinon"; import { HubWrappers, KnownTestLocations } from "../"; import { HubMock } from "../../HubMock"; import { @@ -22,7 +23,6 @@ import { } from "../../core-backend"; import { IModelTestUtils, TestUserType } from "../IModelTestUtils"; chai.use(chaiAsPromised); -import sinon = require("sinon"); // eslint-disable-line @typescript-eslint/no-require-imports export async function createNewModelAndCategory(rwIModel: BriefcaseDb, parent?: Id64String) { // Create a new physical model. const [, modelId] = await IModelTestUtils.createAndInsertPhysicalPartitionAndModelAsync(rwIModel, IModelTestUtils.getUniqueModelCode(rwIModel, "newPhysicalModel"), true, parent); @@ -143,7 +143,7 @@ describe("Merge conflict & locking", () => { } as ElementAspectProps); b2.saveChanges(); - const onChangesetConflictStub = sinon.stub(BriefcaseDb.prototype, "onChangesetConflict" as any); + const onChangesetConflictStub = stub(BriefcaseDb.prototype, "onChangesetConflict" as any); await assertThrowsAsync( async () => b2.pushChanges({ accessToken: accessToken1, description: `modify aspect ${aspectId1} with no lock` }), "UPDATE/DELETE before value do not match with one in db or CASCADE action was triggered."); @@ -216,7 +216,7 @@ describe("Merge conflict & locking", () => { await b1.pushChanges({ accessToken: accessToken1, description: `deleted element ${el1}` }); b2.saveChanges(); - const onChangesetConflictStub = sinon.stub(BriefcaseDb.prototype, "onChangesetConflict" as any); + const onChangesetConflictStub = stub(BriefcaseDb.prototype, "onChangesetConflict" as any); await assertThrowsAsync( async () => b2.pushChanges({ accessToken: accessToken2, description: `add aspect to element ${el1}` }), "UPDATE/DELETE before value do not match with one in db or CASCADE action was triggered."); @@ -328,7 +328,7 @@ describe("Merge conflict & locking", () => { await b1.pushChanges({ accessToken: accessToken1, description: `deleted element ${el1}` }); - const onChangesetConflictStub = sinon.stub(BriefcaseDb.prototype, "onChangesetConflict" as any); + const onChangesetConflictStub = stub(BriefcaseDb.prototype, "onChangesetConflict" as any); /* we should be able to apply all changesets */ await b3.pullChanges(); expect(onChangesetConflictStub.callCount).greaterThanOrEqual(1, "native conflict handler must call BriefcaseDb.onChangesetConflict()"); diff --git a/core/electron/package.json b/core/electron/package.json index 744ef2b48d91..0174f4fee4cd 100644 --- a/core/electron/package.json +++ b/core/electron/package.json @@ -6,9 +6,23 @@ "engines": { "node": "^18.0.0 || ^20.0.0" }, + "type": "module", + "exports": { + "./ElectronBackend": { + "types": "./lib/esm/ElectronBackend.d.ts", + "import": "./lib/esm/ElectronBackend.js", + "require": "./lib/cjs/ElectronBackend.js" + }, + "./ElectronFrontend": { + "types": "./lib/esm/ElectronFrontend.d.ts", + "import": "./lib/esm/ElectronFrontend.js", + "require": "./lib/cjs/ElectronFrontend.js" + } + }, "scripts": { - "build": "npm run -s build:cjs && npm run -s webpack:test", + "build": "npm run -s build:cjs && npm run -s build:esm && npm run -s webpack:test", "build:cjs": "tsc 1>&2 --outDir lib/cjs", + "build:esm": "tsc 1>&2 --module esnext --outDir lib/esm", "clean": "rimraf lib .rush/temp/package-deps*.json", "docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/core/core-electron/file.json --tsIndexFile=./__DOC_ONLY__.ts --onlyJson", "extract-api": "betools extract-api --entry=__DOC_ONLY__", @@ -17,7 +31,7 @@ "test:integration": "npm run test:integration:backend && npm run test:integration:frontend", "test:integration:backend": "mocha --config src/test/backend/.mocharc.json", "test:integration:frontend": "certa -r electron --config src/test/frontend/utils/certa.json", - "webpack:test": "webpack --config ./src/test/frontend/utils/webpack.config.js 1>&2", + "webpack:test": "webpack --config ./src/test/frontend/utils/webpack.config.cjs 1>&2", "cover": "" }, "repository": { @@ -39,7 +53,7 @@ "@itwin/core-bentley": "workspace:^4.10.0-dev.33", "@itwin/core-common": "workspace:^4.10.0-dev.33", "@itwin/core-frontend": "workspace:^4.10.0-dev.33", - "electron": ">=23.0.0 <34.0.0" + "electron": ">=28.0.0 <34.0.0" }, "devDependencies": { "@itwin/build-tools": "workspace:*", diff --git a/core/electron/src/ElectronBackend.ts b/core/electron/src/ElectronBackend.ts index 8f27ee912cc5..43a4ff89420b 100644 --- a/core/electron/src/ElectronBackend.ts +++ b/core/electron/src/ElectronBackend.ts @@ -3,4 +3,4 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -export * from "./backend/ElectronHost"; +export * from "./backend/ElectronHost.js"; diff --git a/core/electron/src/ElectronFrontend.ts b/core/electron/src/ElectronFrontend.ts index 9f2d605d8ce2..c27b4297ac37 100644 --- a/core/electron/src/ElectronFrontend.ts +++ b/core/electron/src/ElectronFrontend.ts @@ -3,4 +3,4 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -export * from "./frontend/ElectronApp"; +export * from "./frontend/ElectronApp.js"; diff --git a/core/electron/src/backend/ElectronHost.ts b/core/electron/src/backend/ElectronHost.ts index 4c5199c4b579..ebde9a66fe12 100644 --- a/core/electron/src/backend/ElectronHost.ts +++ b/core/electron/src/backend/ElectronHost.ts @@ -16,8 +16,8 @@ import * as path from "path"; import { BeDuration, IModelStatus, ProcessDetector } from "@itwin/core-bentley"; import { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@itwin/core-backend"; import { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration, RpcInterfaceDefinition } from "@itwin/core-common"; -import { ElectronRpcConfiguration, ElectronRpcManager } from "../common/ElectronRpcManager"; -import { DialogModuleMethod, electronIpcStrings } from "../common/ElectronIpcInterface"; +import { ElectronRpcConfiguration, ElectronRpcManager } from "../common/ElectronRpcManager.js"; +import { DialogModuleMethod, electronIpcStrings } from "../common/ElectronIpcInterface.js"; // cSpell:ignore signin devserver webcontents copyfile unmaximize eopt @@ -135,8 +135,8 @@ export class ElectronHost { const webPreferences: WebPreferences = { ...options?.webPreferences, - // These web preference variables should not be overriden by the ElectronHostWindowOptions - preload: require.resolve(/* webpack: copyfile */"./ElectronPreload.js"), + // These web preference variables should not be overridden by the ElectronHostWindowOptions + preload: new URL("./ElectronPreload.mjs", import.meta.url).pathname, experimentalFeatures: false, nodeIntegration: false, contextIsolation: true, @@ -270,7 +270,7 @@ export class ElectronHost { throw new Error("Not running under Electron"); if (!this.isValid) { - this._electron = require("electron"); // eslint-disable-line @typescript-eslint/no-require-imports + this._electron = (await import("electron")); this._ipc = new ElectronIpc(); const app = this.app; if (!app.isReady()) diff --git a/core/electron/src/backend/ElectronPreload.ts b/core/electron/src/backend/ElectronPreload.ts index ffe172b81355..53b983281c81 100644 --- a/core/electron/src/backend/ElectronPreload.ts +++ b/core/electron/src/backend/ElectronPreload.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { contextBridge, ipcRenderer } from "electron"; -import type { ElectronListener, ITwinElectronApi } from "../common/ITwinElectronApi"; +import type { ElectronListener, ITwinElectronApi } from "../common/ITwinElectronApi.js"; /** * This file is loaded as an Electron preload script diff --git a/core/electron/src/common/ElectronIpcTransport.ts b/core/electron/src/common/ElectronIpcTransport.ts index d7af318c4aa0..e0cf320c9df4 100644 --- a/core/electron/src/common/ElectronIpcTransport.ts +++ b/core/electron/src/common/ElectronIpcTransport.ts @@ -7,10 +7,10 @@ import { BentleyError, BentleyStatus, ProcessDetector } from "@itwin/core-bentle import { IModelError, iTwinChannel, RpcPushChannel, RpcPushConnection, RpcRequestFulfillment, RpcSerializedValue, SerializedRpcRequest, } from "@itwin/core-common"; -import { ElectronPushConnection, ElectronPushTransport } from "./ElectronPush"; -import { ElectronRpcConfiguration } from "./ElectronRpcManager"; -import { ElectronRpcProtocol } from "./ElectronRpcProtocol"; -import { ElectronRpcRequest } from "./ElectronRpcRequest"; +import { ElectronPushConnection, ElectronPushTransport } from "./ElectronPush.js"; +import { ElectronRpcConfiguration } from "./ElectronRpcManager.js"; +import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js"; +import { ElectronRpcRequest } from "./ElectronRpcRequest.js"; const OBJECTS_CHANNEL = iTwinChannel("rpc.objects"); const DATA_CHANNEL = iTwinChannel("rpc.data"); diff --git a/core/electron/src/common/ElectronPush.ts b/core/electron/src/common/ElectronPush.ts index 77727ef418b4..0906202369b4 100644 --- a/core/electron/src/common/ElectronPush.ts +++ b/core/electron/src/common/ElectronPush.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from "@itwin/core-common"; -import { BackendIpcTransport, FrontendIpcTransport } from "./ElectronIpcTransport"; +import { BackendIpcTransport, FrontendIpcTransport } from "./ElectronIpcTransport.js"; const PUSH = "__push__"; diff --git a/core/electron/src/common/ElectronRpcManager.ts b/core/electron/src/common/ElectronRpcManager.ts index be63f861262d..e0f326f37c83 100644 --- a/core/electron/src/common/ElectronRpcManager.ts +++ b/core/electron/src/common/ElectronRpcManager.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager, RpcRegistry } from "@itwin/core-common"; -import { ElectronRpcProtocol } from "./ElectronRpcProtocol"; +import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js"; /** RPC interface configuration for an Electron-based application. * @internal diff --git a/core/electron/src/common/ElectronRpcProtocol.ts b/core/electron/src/common/ElectronRpcProtocol.ts index 19fd061c8527..666cf1dabf1a 100644 --- a/core/electron/src/common/ElectronRpcProtocol.ts +++ b/core/electron/src/common/ElectronRpcProtocol.ts @@ -8,9 +8,9 @@ import { BentleyStatus } from "@itwin/core-bentley"; import { IModelError, IpcSocket, RpcInterface, RpcInterfaceDefinition, RpcProtocol } from "@itwin/core-common"; -import { ElectronIpcTransport, initializeIpc, IpcTransportMessage } from "./ElectronIpcTransport"; -import { ElectronRpcConfiguration } from "./ElectronRpcManager"; -import { ElectronRpcRequest } from "./ElectronRpcRequest"; +import { ElectronIpcTransport, initializeIpc, IpcTransportMessage } from "./ElectronIpcTransport.js"; +import { ElectronRpcConfiguration } from "./ElectronRpcManager.js"; +import { ElectronRpcRequest } from "./ElectronRpcRequest.js"; /** RPC interface protocol for an Electron-based application. * @internal diff --git a/core/electron/src/common/ElectronRpcRequest.ts b/core/electron/src/common/ElectronRpcRequest.ts index 0b11a7ed075a..d1819a6e5e4e 100644 --- a/core/electron/src/common/ElectronRpcRequest.ts +++ b/core/electron/src/common/ElectronRpcRequest.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { RpcProtocolEvent, RpcRequest, RpcRequestFulfillment } from "@itwin/core-common"; -import { ElectronRpcProtocol } from "./ElectronRpcProtocol"; +import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js"; /** @internal */ export class ElectronRpcRequest extends RpcRequest { diff --git a/core/electron/src/frontend/ElectronApp.ts b/core/electron/src/frontend/ElectronApp.ts index 2f99b1791bc8..6f2661eca42b 100644 --- a/core/electron/src/frontend/ElectronApp.ts +++ b/core/electron/src/frontend/ElectronApp.ts @@ -11,9 +11,9 @@ import { ProcessDetector, PromiseReturnType } from "@itwin/core-bentley"; import { IpcListener, IpcSocketFrontend } from "@itwin/core-common"; import { _callIpcChannel, IpcApp, NativeApp, NativeAppOpts } from "@itwin/core-frontend"; import type { IpcRenderer } from "electron"; -import { DialogModuleMethod, electronIpcStrings } from "../common/ElectronIpcInterface"; -import { ElectronRpcManager } from "../common/ElectronRpcManager"; -import type { ITwinElectronApi } from "../common/ITwinElectronApi"; +import { DialogModuleMethod, electronIpcStrings } from "../common/ElectronIpcInterface.js"; +import { ElectronRpcManager } from "../common/ElectronRpcManager.js"; +import type { ITwinElectronApi } from "../common/ITwinElectronApi.js"; declare global { interface Window { diff --git a/core/electron/src/test/frontend/utils/webpack.config.js b/core/electron/src/test/frontend/utils/webpack.config.cjs similarity index 100% rename from core/electron/src/test/frontend/utils/webpack.config.js rename to core/electron/src/test/frontend/utils/webpack.config.cjs diff --git a/test-apps/display-test-app/package.json b/test-apps/display-test-app/package.json index 712e51522dcc..45a32dfd7ee4 100644 --- a/test-apps/display-test-app/package.json +++ b/test-apps/display-test-app/package.json @@ -2,6 +2,7 @@ "name": "display-test-app", "description": "Internal app for testing features of display system", "license": "UNLICENSED", + "type": "module", "author": { "name": "Bentley Systems, Inc.", "url": "http://www.bentley.com" diff --git a/test-apps/display-test-app/src/backend/Backend.ts b/test-apps/display-test-app/src/backend/Backend.ts index 508560533961..a9aa08384f17 100644 --- a/test-apps/display-test-app/src/backend/Backend.ts +++ b/test-apps/display-test-app/src/backend/Backend.ts @@ -6,26 +6,29 @@ import * as fs from "fs"; import * as path from "path"; import { Logger, LogLevel, ProcessDetector } from "@itwin/core-bentley"; import { ElectronMainAuthorization } from "@itwin/electron-authorization/Main"; -import { ElectronHost, ElectronHostOptions } from "@itwin/core-electron/lib/cjs/ElectronBackend"; +import { ElectronHost, ElectronHostOptions } from "@itwin/core-electron/ElectronBackend"; import { BackendIModelsAccess } from "@itwin/imodels-access-backend"; import { IModelsClient } from "@itwin/imodels-client-authoring"; import { IModelDb, IModelHost, IModelHostOptions, LocalhostIpcHost, produceTextAnnotationGeometry } from "@itwin/core-backend"; import { IModelReadRpcInterface, IModelRpcProps, IModelTileRpcInterface, RpcInterfaceDefinition, RpcManager, SnapshotIModelRpcInterface, TextAnnotation, TextAnnotationProps, TextBlockGeometryProps, } from "@itwin/core-common"; -import { MobileHost, MobileHostOpts } from "@itwin/core-mobile/lib/cjs/MobileBackend"; -import { DtaConfiguration, getConfig } from "../common/DtaConfiguration"; -import { DtaRpcInterface } from "../common/DtaRpcInterface"; +import { MobileHost, MobileHostOpts } from "@itwin/core-mobile/lib/cjs/MobileBackend.js"; +import { DtaConfiguration, getConfig } from "../common/DtaConfiguration.js"; +import { DtaRpcInterface } from "../common/DtaRpcInterface.js"; import { EditCommandAdmin } from "@itwin/editor-backend"; import * as editorBuiltInCommands from "@itwin/editor-backend"; +import dotenv from "dotenv"; +import dotenvExpand from "dotenv-expand"; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); /** Loads the provided `.env` file into process.env */ function loadEnv(envFile: string) { if (!fs.existsSync(envFile)) return; - - const dotenv = require("dotenv"); // eslint-disable-line @typescript-eslint/no-require-imports - const dotenvExpand = require("dotenv-expand"); // eslint-disable-line @typescript-eslint/no-require-imports const envResult = dotenv.config({ path: envFile }); if (envResult.error) { throw envResult.error; diff --git a/test-apps/display-test-app/src/backend/DtaElectronMain.ts b/test-apps/display-test-app/src/backend/DtaElectronMain.ts index 32af463a79bc..d5495c5537b7 100644 --- a/test-apps/display-test-app/src/backend/DtaElectronMain.ts +++ b/test-apps/display-test-app/src/backend/DtaElectronMain.ts @@ -4,12 +4,14 @@ *--------------------------------------------------------------------------------------------*/ import * as path from "path"; import { assert } from "@itwin/core-bentley"; -import { ElectronHost } from "@itwin/core-electron/lib/cjs/ElectronBackend"; -import { CreateSectionDrawingViewArgs, CreateSectionDrawingViewResult, dtaChannel, DtaIpcInterface } from "../common/DtaIpcInterface"; -import { getRpcInterfaces, initializeDtaBackend, loadBackendConfig } from "./Backend"; +import { ElectronHost } from "@itwin/core-electron/ElectronBackend"; +import { CreateSectionDrawingViewArgs, CreateSectionDrawingViewResult, dtaChannel, DtaIpcInterface } from "../common/DtaIpcInterface.js"; +import { getRpcInterfaces, initializeDtaBackend, loadBackendConfig } from "./Backend.js"; import { IpcHandler } from "@itwin/core-backend"; -import { getConfig } from "../common/DtaConfiguration"; -import { createSectionDrawing } from "./SectionDrawingImpl"; +import { getConfig } from "../common/DtaConfiguration.js"; +import { createSectionDrawing } from "./SectionDrawingImpl.js"; +import { fileURLToPath } from "node:url"; +import { dirname } from "node:path"; const mainWindowName = "mainWindow"; const getWindowSize = (winSize?: string) => { @@ -51,6 +53,8 @@ const dtaElectronMain = async () => { // Need to load the config first to get the electron options loadBackendConfig(); + const __filename = fileURLToPath(import.meta.url); + const __dirname = dirname(__filename); const opts = { webResourcesPath: path.join(__dirname, "..", "..", "lib"), iconName: "display-test-app.ico", diff --git a/test-apps/display-test-app/src/backend/MobileMain.ts b/test-apps/display-test-app/src/backend/MobileMain.ts index ce2339cb9bf6..9dce2518ac6f 100644 --- a/test-apps/display-test-app/src/backend/MobileMain.ts +++ b/test-apps/display-test-app/src/backend/MobileMain.ts @@ -3,8 +3,8 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { MobileHostOpts } from "@itwin/core-mobile/lib/cjs/MobileBackend"; -import { getRpcInterfaces, initializeDtaBackend } from "./Backend"; +import { MobileHostOpts } from "@itwin/core-mobile/lib/cjs/MobileBackend.js"; +import { getRpcInterfaces, initializeDtaBackend } from "./Backend.js"; const dtaMobileMain = (async () => { const opts: MobileHostOpts = { diff --git a/test-apps/display-test-app/src/backend/SectionDrawingImpl.ts b/test-apps/display-test-app/src/backend/SectionDrawingImpl.ts index a7f6ea08685f..ded1a54a5cfc 100644 --- a/test-apps/display-test-app/src/backend/SectionDrawingImpl.ts +++ b/test-apps/display-test-app/src/backend/SectionDrawingImpl.ts @@ -10,7 +10,7 @@ import { import { TransformProps } from "@itwin/core-geometry"; import { DbResult, DisplayStyle3dProps, GeometricModel2dProps, RelatedElementProps, SectionDrawingProps, SectionType, SpatialViewDefinitionProps } from "@itwin/core-common"; import { Id64, Id64String } from "@itwin/core-bentley"; -import { CreateSectionDrawingViewArgs, CreateSectionDrawingViewResult } from "../common/DtaIpcInterface"; +import { CreateSectionDrawingViewArgs, CreateSectionDrawingViewResult } from "../common/DtaIpcInterface.js"; /** Find or create a document partition named" DrawingProductionDrawing" to contain all our section drawings. */ async function getDrawingProductionListModel(db: BriefcaseDb): Promise { diff --git a/test-apps/display-test-app/src/backend/WebMain.ts b/test-apps/display-test-app/src/backend/WebMain.ts index 342b4f8fd256..b833580ae4e5 100644 --- a/test-apps/display-test-app/src/backend/WebMain.ts +++ b/test-apps/display-test-app/src/backend/WebMain.ts @@ -2,15 +2,15 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import * as express from "express"; +import express from "express"; import * as fs from "fs"; import * as https from "https"; -import * as enableWs from "express-ws"; +import enableWs from "express-ws"; import { Logger } from "@itwin/core-bentley"; import { BentleyCloudRpcConfiguration, BentleyCloudRpcManager } from "@itwin/core-common"; -import { getRpcInterfaces, initializeDtaBackend } from "./Backend"; +import { getRpcInterfaces, initializeDtaBackend } from "./Backend.js"; import { LocalhostIpcHost } from "@itwin/core-backend"; -import { DtaRpcInterface } from "../common/DtaRpcInterface"; +import { DtaRpcInterface } from "../common/DtaRpcInterface.js"; /* eslint-disable no-console */ diff --git a/test-apps/display-test-app/src/common/DtaRpcInterface.ts b/test-apps/display-test-app/src/common/DtaRpcInterface.ts index 5497645db84e..0a5bb7816c47 100644 --- a/test-apps/display-test-app/src/common/DtaRpcInterface.ts +++ b/test-apps/display-test-app/src/common/DtaRpcInterface.ts @@ -5,7 +5,7 @@ import { IModelRpcProps, RpcInterface, RpcManager, TextAnnotationProps, TextBlockGeometryProps } from "@itwin/core-common"; import * as http from "http"; import * as https from "https"; -import { DtaConfiguration } from "./DtaConfiguration"; +import { DtaConfiguration } from "./DtaConfiguration.js"; /** Display Test App RPC interface. */ export class DtaRpcInterface extends RpcInterface { diff --git a/test-apps/display-test-app/src/frontend/App.ts b/test-apps/display-test-app/src/frontend/App.ts index fa613e01bc72..0e897711349e 100644 --- a/test-apps/display-test-app/src/frontend/App.ts +++ b/test-apps/display-test-app/src/frontend/App.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import "@bentley/icons-generic-webfont/dist/bentley-icons-generic-webfont.css"; import { GuidString, ProcessDetector } from "@itwin/core-bentley"; -import { ElectronApp, ElectronAppOpts } from "@itwin/core-electron/lib/cjs/ElectronFrontend"; +import { ElectronApp, ElectronAppOpts } from "@itwin/core-electron/ElectronFrontend"; import { BrowserAuthorizationClient } from "@itwin/browser-authorization"; import { FrontendIModelsAccess } from "@itwin/imodels-access-frontend"; import { IModelsClient } from "@itwin/imodels-client-management"; diff --git a/test-apps/display-test-app/src/frontend/FileOpen.ts b/test-apps/display-test-app/src/frontend/FileOpen.ts index 1ea477caf24a..cbb808b21aa6 100644 --- a/test-apps/display-test-app/src/frontend/FileOpen.ts +++ b/test-apps/display-test-app/src/frontend/FileOpen.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ProcessDetector } from "@itwin/core-bentley"; -import { ElectronApp } from "@itwin/core-electron/lib/cjs/ElectronFrontend"; +import { ElectronApp } from "@itwin/core-electron/ElectronFrontend"; import { OpenDialogOptions } from "electron"; export interface BrowserFileSelector { diff --git a/test-apps/display-test-app/tsconfig.backend.json b/test-apps/display-test-app/tsconfig.backend.json index e4e59e2d8aff..2e562944b292 100644 --- a/test-apps/display-test-app/tsconfig.backend.json +++ b/test-apps/display-test-app/tsconfig.backend.json @@ -2,9 +2,12 @@ "extends": "./node_modules/@itwin/build-tools/tsconfig-base.json", "compilerOptions": { "outDir": "./lib", + "lib": ["ES2020"], "module": "NodeNext", "moduleResolution": "NodeNext", - "resolvePackageJsonExports": true + "resolveJsonModule": true, + "resolvePackageJsonExports": true, + "noImplicitAny": false }, "include": ["./src/backend/*.ts", "./src/common/*.ts"] } diff --git a/test-apps/display-test-app/vite.config.mts b/test-apps/display-test-app/vite.config.mts index 1510d1c5e570..4b83251832e7 100644 --- a/test-apps/display-test-app/vite.config.mts +++ b/test-apps/display-test-app/vite.config.mts @@ -76,10 +76,12 @@ export default defineConfig(() => { commonjsOptions: { // plugin to convert CommonJS modules to ESM, so they can be included in bundle include: [ - /core\/electron/, // prevent error in ElectronApp /core\/mobile/, // prevent error in MobileApp - /node_modules/, // prevent errors from dependencies + // /node_modules/, // prevent errors from dependencies ], + // exclude: [ + // /electron/ + // ], transformMixedEsModules: true, // transforms require statements }, rollupOptions: { @@ -135,8 +137,8 @@ export default defineConfig(() => { resolve: { alias: { ...packageAliases, - "@itwin/core-electron/lib/cjs/ElectronFrontend": - "@itwin/core-electron/src/ElectronFrontend.ts", + // "@itwin/core-electron/ElectronFrontend": + // "@itwin/core-electron/src/ElectronFrontend.ts", "@itwin/core-mobile/lib/cjs/MobileFrontend": "@itwin/core-mobile/src/MobileFrontend.ts", "../../package.json": "../package.json", // in core-frontend @@ -147,7 +149,7 @@ export default defineConfig(() => { force: true, // forces cache dumps on each rebuild. should be turned off once the issue in vite with monorepos not being correctly optimized is fixed. Issue link: https://github.com/vitejs/vite/issues/14099 // overoptimized dependencies in the same monorepo (vite converts all cjs to esm) include: [ - "@itwin/core-electron/lib/cjs/ElectronFrontend", // import from module error + // "@itwin/core-electron/ElectronFrontend", // import from module error "@itwin/core-mobile/lib/cjs/MobileFrontend", // import from module error ], exclude: [