From e2a2e97ab4a85607a705f2deb30e25f4b15dad5d Mon Sep 17 00:00:00 2001 From: Caleb Shafer <31107829+calebmshafer@users.noreply.github.com> Date: Wed, 10 Feb 2021 17:57:32 -0500 Subject: [PATCH] Consolidate configuration setup across repository (#685) * Update use of configuration to consistently use .env file. Deprecate use of default.json. - Add new custom Rush command, 'copy:config', to copy a shared `.env` file to each directory necessary - Enhance the internal-tools copyConfig script to allow a custom path for `.env` file - Mark main IModelJsConfig class as deprecated --- clients/context-registry/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- clients/extension/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- clients/forms-data-management/package.json | 4 ++- .../src/test/TestConfig.ts | 35 ------------------- .../FormDataManagementClient.test.ts | 21 +++++------ .../src/test/utils/webpack.config.js | 10 +++--- clients/product-settings/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- clients/projectshare/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- clients/rbac/package.json | 4 ++- clients/rbac/src/test/utils/webpack.config.js | 10 +++--- clients/reality-data/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- clients/usage-logging/package.json | 4 ++- .../src/test/utils/webpack.config.js | 10 +++--- common/api/config-loader.api.md | 5 ++- .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../update-test-config_2021-01-30-02-30.json | 11 ++++++ .../rush/browser-approved-packages.json | 2 +- common/config/rush/command-line.json | 10 ++++++ core/backend-itwin-client/package.json | 6 ++-- .../src/test/AgentAuthorizationClient.test.ts | 9 ++--- .../DelegationAuthorizationClient.test.ts | 5 +-- .../src/test/TestConfig.ts | 7 ++-- core/backend/package.json | 4 ++- core/backend/src/test/IModelTestUtils.ts | 10 +++--- .../test/ios/config/mobile.webpack.config.js | 5 ++- core/imodel-bridge/package.json | 4 ++- .../imodel-bridge/src/test/BridgeTestUtils.ts | 10 +++--- example-code/app/package.json | 3 +- example-code/app/src/backend/test/Utils.ts | 4 --- example-code/snippets/package.json | 3 +- .../snippets/src/backend/IModelTestUtils.ts | 5 +-- full-stack-tests/core/package.json | 4 ++- full-stack-tests/core/src/backend/backend.ts | 12 +++---- full-stack-tests/core/webpack.config.js | 6 ++-- .../imodelhub-client/package.json | 4 ++- .../imodelhub-client/src/TestConfig.ts | 5 +-- full-stack-tests/native-app/package.json | 4 ++- .../native-app/src/backend/backend.ts | 16 ++++----- full-stack-tests/native-app/webpack.config.js | 12 +++---- full-stack-tests/presentation/package.json | 4 ++- .../presentation/src/IntegrationTests.ts | 4 +-- full-stack-tests/rpc-interface/package.json | 4 ++- .../rpc-interface/src/backend/BackendInit.ts | 9 ++--- .../rpc-interface/src/test/backend.ts | 8 ++--- full-stack-tests/rpc/package.json | 5 ++- .../rpc/src/backend/CommonBackendSetup.ts | 4 +-- full-stack-tests/rpc/webpack.config.js | 11 ------ .../src/backend/backend.ts | 6 ++-- test-apps/display-test-app/package.json | 2 +- .../display-test-app/src/backend/Backend.ts | 6 ++-- .../presentation-test-app/src/backend/main.ts | 6 ++-- test-apps/ui-test-app/package.json | 4 +-- test-apps/ui-test-app/src/backend/main.ts | 7 ++-- .../src/backend/mobile/MobileMain.ts | 10 +++--- tools/config-loader/package.json | 3 +- tools/config-loader/src/IModelJsConfig.ts | 24 +++++++++++-- tools/internal/scripts/copyConfig.js | 21 ++++++----- tools/oidc-signin-tool/package.json | 4 ++- .../src/certa/certaBackend.ts | 9 +++-- tools/oidc-signin-tool/src/test/basic.test.ts | 7 ++-- 78 files changed, 404 insertions(+), 242 deletions(-) delete mode 100644 clients/forms-data-management/src/test/TestConfig.ts create mode 100644 common/changes/@bentley/backend-itwin-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/config-loader/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/context-registry-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/extension-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/forms-data-management-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/imodel-bridge/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/imodelhub-client-tests/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/imodeljs-backend/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/oidc-signin-tool/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/product-settings-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/projectshare-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/rbac-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/reality-data-client/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/rpcinterface-full-stack-tests/update-test-config_2021-01-30-02-30.json create mode 100644 common/changes/@bentley/usage-logging-client/update-test-config_2021-01-30-02-30.json diff --git a/clients/context-registry/package.json b/clients/context-registry/package.json index fb206f375165..d933d7674ba1 100644 --- a/clients/context-registry/package.json +++ b/clients/context-registry/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "cover": "" }, "keywords": [ @@ -54,6 +55,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -70,4 +72,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/context-registry/src/test/utils/webpack.config.js b/clients/context-registry/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/context-registry/src/test/utils/webpack.config.js +++ b/clients/context-registry/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/extension/package.json b/clients/extension/package.json index f78c05260edd..7f57b2e734ae 100644 --- a/clients/extension/package.json +++ b/clients/extension/package.json @@ -22,6 +22,7 @@ "test:integration:chrome": "certa -r chrome", "test:integration:electron": "certa -r electron", "test:integration:node": "certa -r node", + "copy:config": "internal-tools copy-config", "webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2" }, "keywords": [ @@ -51,6 +52,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -67,4 +69,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/extension/src/test/utils/webpack.config.js b/clients/extension/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/extension/src/test/utils/webpack.config.js +++ b/clients/extension/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/forms-data-management/package.json b/clients/forms-data-management/package.json index 63901d25478d..ee04c0624796 100644 --- a/clients/forms-data-management/package.json +++ b/clients/forms-data-management/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "cover": "" }, "keywords": [ @@ -53,6 +54,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -69,4 +71,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/forms-data-management/src/test/TestConfig.ts b/clients/forms-data-management/src/test/TestConfig.ts deleted file mode 100644 index a55b37e8afaa..000000000000 --- a/clients/forms-data-management/src/test/TestConfig.ts +++ /dev/null @@ -1,35 +0,0 @@ -/*--------------------------------------------------------------------------------------------- -* Copyright (c) Bentley Systems, Incorporated. All rights reserved. -* See LICENSE.md in the project root for license terms and full copyright notice. -*--------------------------------------------------------------------------------------------*/ -import { Logger } from "@bentley/bentleyjs-core"; -import { AccessToken, AuthorizedClientRequestContext } from "@bentley/itwin-client"; -import { getAccessTokenFromBackend, TestUserCredentials, TestUsers } from "@bentley/oidc-signin-tool/lib/frontend"; - -// Note: Turn this off unless really necessary - it causes Error messages on the -// console with the existing suite of tests, and this is quite misleading, -// especially when diagnosing CI job failures. -const loggingConfigFile: string | undefined = process.env.imjs_test_logging_config; -if (!!loggingConfigFile) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - Logger.configureLevels(require(loggingConfigFile)); -} - -function isOfflineSet(): boolean { - const index = process.argv.indexOf("--offline"); - return process.argv[index + 1] === "mock"; -} - -/** Basic configuration used by all tests - */ -export class TestConfig { - /** Name of project used by most tests */ - public static readonly projectName: string = "iModelJsIntegrationTest"; - public static readonly enableMocks: boolean = isOfflineSet(); - - /** Login the specified user and return the AuthorizationToken */ - public static async getAuthorizedClientRequestContext(user: TestUserCredentials = TestUsers.regular): Promise { - const accessToken = await getAccessTokenFromBackend(user); - return new AuthorizedClientRequestContext((accessToken as any) as AccessToken); - } -} diff --git a/clients/forms-data-management/src/test/integration/FormDataManagementClient.test.ts b/clients/forms-data-management/src/test/integration/FormDataManagementClient.test.ts index ebe43a4110f8..f53d043492ed 100644 --- a/clients/forms-data-management/src/test/integration/FormDataManagementClient.test.ts +++ b/clients/forms-data-management/src/test/integration/FormDataManagementClient.test.ts @@ -2,33 +2,30 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import * as chai from "chai"; +import { assert } from "chai"; import { ContextRegistryClient, Project } from "@bentley/context-registry-client"; -import { AuthorizedClientRequestContext } from "@bentley/itwin-client"; +import { AccessToken, AuthorizedClientRequestContext } from "@bentley/itwin-client"; +import { getAccessTokenFromBackend, TestUsers } from "@bentley/oidc-signin-tool/lib/frontend"; import { FormDataManagementClient, FormDefinition } from "../../FormDataManagementClient"; -import { TestConfig } from "../TestConfig"; /* eslint-disable @typescript-eslint/naming-convention */ -chai.should(); - describe("FormDataManagementClient", () => { let requestContext: AuthorizedClientRequestContext; const formDataManagementClient: FormDataManagementClient = new FormDataManagementClient(); let projectId: string; before(async function () { - if (TestConfig.enableMocks) return; - this.enableTimeouts(false); - - requestContext = await TestConfig.getAuthorizedClientRequestContext(); + const accessToken = await getAccessTokenFromBackend(TestUsers.super); + requestContext = new AuthorizedClientRequestContext((accessToken as any) as AccessToken); const contextRegistry = new ContextRegistryClient(); + const projectName = "iModelJsIntegrationTest"; const project: Project | undefined = await contextRegistry.getProject(requestContext, { $select: "*", - $filter: `Name+eq+'${TestConfig.projectName}'`, + $filter: `Name+eq+'${projectName}'`, }); - chai.assert(project, `Project ${TestConfig.projectName} not found for user.`); + assert(project, `Project ${projectName} not found for user.`); projectId = project.wsgId; }); @@ -37,6 +34,6 @@ describe("FormDataManagementClient", () => { requestContext, projectId ); - chai.assert(formDefinitions); + assert(formDefinitions); }); }); diff --git a/clients/forms-data-management/src/test/utils/webpack.config.js b/clients/forms-data-management/src/test/utils/webpack.config.js index e3ec34d0689f..429166639cf6 100644 --- a/clients/forms-data-management/src/test/utils/webpack.config.js +++ b/clients/forms-data-management/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -48,16 +48,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/product-settings/package.json b/clients/product-settings/package.json index 6ccdfc624894..dfb09029082f 100644 --- a/clients/product-settings/package.json +++ b/clients/product-settings/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2" }, "keywords": [ @@ -52,6 +53,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -68,4 +70,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/product-settings/src/test/utils/webpack.config.js b/clients/product-settings/src/test/utils/webpack.config.js index 23e5e4453d1d..6a0ebd0716c1 100644 --- a/clients/product-settings/src/test/utils/webpack.config.js +++ b/clients/product-settings/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/projectshare/package.json b/clients/projectshare/package.json index 845ad8d0c11d..94029f14ac7a 100644 --- a/clients/projectshare/package.json +++ b/clients/projectshare/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2" }, "keywords": [ @@ -52,6 +53,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -68,4 +70,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/projectshare/src/test/utils/webpack.config.js b/clients/projectshare/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/projectshare/src/test/utils/webpack.config.js +++ b/clients/projectshare/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/rbac/package.json b/clients/rbac/package.json index 78cca906be2e..0bb9b0f8f281 100644 --- a/clients/rbac/package.json +++ b/clients/rbac/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2" }, "keywords": [ @@ -53,6 +54,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -69,4 +71,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/rbac/src/test/utils/webpack.config.js b/clients/rbac/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/rbac/src/test/utils/webpack.config.js +++ b/clients/rbac/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/reality-data/package.json b/clients/reality-data/package.json index 9ca0f59ee9ca..a8ec528fb50f 100644 --- a/clients/reality-data/package.json +++ b/clients/reality-data/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "cover": "" }, "keywords": [ @@ -54,6 +55,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -70,4 +72,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/reality-data/src/test/utils/webpack.config.js b/clients/reality-data/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/reality-data/src/test/utils/webpack.config.js +++ b/clients/reality-data/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/clients/usage-logging/package.json b/clients/usage-logging/package.json index 8231b5b462fa..bb0aaf8bb804 100644 --- a/clients/usage-logging/package.json +++ b/clients/usage-logging/package.json @@ -22,6 +22,7 @@ "test:integration": "npm run webpackTests && npm run test:integration:chrome", "test:integration:chrome": "certa -r chrome --grep \"#integration\"", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "webpackTests": "webpack --config ./src/test/utils/webpack.config.js 1>&2" }, "keywords": [ @@ -54,6 +55,7 @@ "@types/node": "10.14.1", "chai": "^4.1.2", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -70,4 +72,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/clients/usage-logging/src/test/utils/webpack.config.js b/clients/usage-logging/src/test/utils/webpack.config.js index 23e5e4453d1d..862117044e53 100644 --- a/clients/usage-logging/src/test/utils/webpack.config.js +++ b/clients/usage-logging/src/test/utils/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", "..", ".env")); const clientsLib = path.resolve(__dirname, "../../../lib"); @@ -51,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/common/api/config-loader.api.md b/common/api/config-loader.api.md index 7d0276783211..324b8cfc0798 100644 --- a/common/api/config-loader.api.md +++ b/common/api/config-loader.api.md @@ -4,11 +4,14 @@ ```ts -// @public +// @public @deprecated export class IModelJsConfig { static init(suppressException?: boolean, suppressErrorMessage?: boolean, config?: any): any; } +// @internal +export function loadEnv(envFile: string): void; + // (No @packageDocumentation comment for this package) diff --git a/common/changes/@bentley/backend-itwin-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/backend-itwin-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..fc928027c431 --- /dev/null +++ b/common/changes/@bentley/backend-itwin-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/backend-itwin-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/backend-itwin-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/config-loader/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/config-loader/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..a34438833aab --- /dev/null +++ b/common/changes/@bentley/config-loader/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/config-loader", + "comment": "Deprecate IModelJsConfig class in favor of `.env` loading. Add a simple `loadEnv()` function to use dotenv and dotenv-expand to load .env file.", + "type": "none" + } + ], + "packageName": "@bentley/config-loader", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/context-registry-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/context-registry-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..b8adbb03f357 --- /dev/null +++ b/common/changes/@bentley/context-registry-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/context-registry-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/context-registry-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/extension-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/extension-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..31eee8f43acd --- /dev/null +++ b/common/changes/@bentley/extension-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/extension-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/extension-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/forms-data-management-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/forms-data-management-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..3f8529f0f28c --- /dev/null +++ b/common/changes/@bentley/forms-data-management-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/forms-data-management-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/forms-data-management-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/imodel-bridge/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/imodel-bridge/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..0d315a9e7cc2 --- /dev/null +++ b/common/changes/@bentley/imodel-bridge/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/imodel-bridge", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/imodel-bridge", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/imodelhub-client-tests/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/imodelhub-client-tests/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..f0183d641e41 --- /dev/null +++ b/common/changes/@bentley/imodelhub-client-tests/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/imodelhub-client-tests", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/imodelhub-client-tests", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/imodeljs-backend/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/imodeljs-backend/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..3862fb39ed32 --- /dev/null +++ b/common/changes/@bentley/imodeljs-backend/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/imodeljs-backend", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/imodeljs-backend", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/oidc-signin-tool/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/oidc-signin-tool/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..428926fdaea0 --- /dev/null +++ b/common/changes/@bentley/oidc-signin-tool/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/oidc-signin-tool", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/oidc-signin-tool", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/product-settings-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/product-settings-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..c474d1576b35 --- /dev/null +++ b/common/changes/@bentley/product-settings-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/product-settings-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/product-settings-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/projectshare-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/projectshare-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..3ac13843c52c --- /dev/null +++ b/common/changes/@bentley/projectshare-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/projectshare-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/projectshare-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/rbac-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/rbac-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..49a453bbfdca --- /dev/null +++ b/common/changes/@bentley/rbac-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/rbac-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/rbac-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/reality-data-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/reality-data-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..066c18cee6ac --- /dev/null +++ b/common/changes/@bentley/reality-data-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/reality-data-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/reality-data-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/rpcinterface-full-stack-tests/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/rpcinterface-full-stack-tests/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..361b132dc016 --- /dev/null +++ b/common/changes/@bentley/rpcinterface-full-stack-tests/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/rpcinterface-full-stack-tests", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/rpcinterface-full-stack-tests", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/usage-logging-client/update-test-config_2021-01-30-02-30.json b/common/changes/@bentley/usage-logging-client/update-test-config_2021-01-30-02-30.json new file mode 100644 index 000000000000..240252d4a1b0 --- /dev/null +++ b/common/changes/@bentley/usage-logging-client/update-test-config_2021-01-30-02-30.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/usage-logging-client", + "comment": "", + "type": "none" + } + ], + "packageName": "@bentley/usage-logging-client", + "email": "31107829+calebmshafer@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/config/rush/browser-approved-packages.json b/common/config/rush/browser-approved-packages.json index 92721454eb9a..2cb6629b257d 100644 --- a/common/config/rush/browser-approved-packages.json +++ b/common/config/rush/browser-approved-packages.json @@ -576,7 +576,7 @@ }, { "name": "internal-tools", - "allowedCategories": [ "internal" ] + "allowedCategories": [ "backend", "common", "integration-testing", "internal", "tools" ] }, { "name": "istanbul-instrumenter-loader", diff --git a/common/config/rush/command-line.json b/common/config/rush/command-line.json index 03a448f079db..f88ed16dd0ac 100644 --- a/common/config/rush/command-line.json +++ b/common/config/rush/command-line.json @@ -94,6 +94,16 @@ "ignoreMissingScript": true, "ignoreDependencyOrder": true, "allowWarningsInSuccessfulBuild": true + }, + { + "name": "copy:config", + "commandKind": "bulk", + "summary": "Run copy:config script for each package", + "description": "Iterates through each package in the monorepo and runs the 'copy:config' script. Note: If the files to copy already exist, the copy script will not overwrite it.", + "enableParallelism": true, + "ignoreMissingScript": true, + "ignoreDependencyOrder": true, + "allowWarningsInSuccessfulBuild": true } ] } \ No newline at end of file diff --git a/core/backend-itwin-client/package.json b/core/backend-itwin-client/package.json index 0592ed75ba2b..0306b078af9a 100644 --- a/core/backend-itwin-client/package.json +++ b/core/backend-itwin-client/package.json @@ -23,7 +23,8 @@ "lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2", "pretest": "npm run copy:test-assets", "test": "betools test --grep=\"#integration\" --invert", - "test:integration": "npm run pretest && betools test --grep=\"#integration\"" + "test:integration": "npm run pretest && betools test --grep=\"#integration\"", + "copy:config": "internal-tools copy-config" }, "repository": { "type": "git", @@ -77,6 +78,7 @@ "chai": "^4.1.2", "cpx": "^1.5.0", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nock": "^9.2.3", "nyc": "^14.0.0", @@ -107,4 +109,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/core/backend-itwin-client/src/test/AgentAuthorizationClient.test.ts b/core/backend-itwin-client/src/test/AgentAuthorizationClient.test.ts index df2681e78c69..abf4ad8224d2 100644 --- a/core/backend-itwin-client/src/test/AgentAuthorizationClient.test.ts +++ b/core/backend-itwin-client/src/test/AgentAuthorizationClient.test.ts @@ -4,14 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import * as chai from "chai"; -import { Issuer, Client as OpenIdClient } from "openid-client"; +import { Client, Issuer } from "openid-client"; +import * as path from "path"; import { BeDuration, ClientRequestContext, Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { AccessToken, IncludePrefix } from "@bentley/itwin-client"; import { AgentAuthorizationClient, AgentAuthorizationClientConfiguration } from "../backend-itwin-client"; import { HubAccessTestValidator } from "./HubAccessTestValidator"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); +loadEnv(path.join(__dirname, "..", "..", ".env")); chai.should(); @@ -37,7 +38,7 @@ describe("AgentAuthorizationClient (#integration)", () => { const client = new AgentAuthorizationClient(agentConfiguration); const url: string = await client.getUrl(requestContext); - const issuer: Issuer = await client.discoverEndpoints(requestContext); + const issuer: Issuer = await client.discoverEndpoints(requestContext); chai.expect(issuer.token_endpoint).equals(`${url}/connect/token`); chai.expect(issuer.authorization_endpoint).equals(`${url}/connect/authorize`); chai.expect(issuer.introspection_endpoint).equals(`${url}/connect/introspect`); diff --git a/core/backend-itwin-client/src/test/DelegationAuthorizationClient.test.ts b/core/backend-itwin-client/src/test/DelegationAuthorizationClient.test.ts index 4cc6bad0a4c4..442403296952 100644 --- a/core/backend-itwin-client/src/test/DelegationAuthorizationClient.test.ts +++ b/core/backend-itwin-client/src/test/DelegationAuthorizationClient.test.ts @@ -4,15 +4,16 @@ *--------------------------------------------------------------------------------------------*/ import * as chai from "chai"; +import * as path from "path"; import { ClientRequestContext, Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { AccessToken, SamlAccessToken } from "@bentley/itwin-client"; import { AgentAuthorizationClient, AgentAuthorizationClientConfiguration, DelegationAuthorizationClient, DelegationAuthorizationClientConfiguration, } from "../backend-itwin-client"; import { HubAccessTestValidator } from "./HubAccessTestValidator"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); +loadEnv(path.join(__dirname, "..", "..", ".env")); chai.should(); diff --git a/core/backend-itwin-client/src/test/TestConfig.ts b/core/backend-itwin-client/src/test/TestConfig.ts index 1fd6e42c65db..704199f4c0b4 100644 --- a/core/backend-itwin-client/src/test/TestConfig.ts +++ b/core/backend-itwin-client/src/test/TestConfig.ts @@ -2,13 +2,14 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { Config, GuidString } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import * as path from "path"; +import { GuidString } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; import { ContextRegistryClient, Project } from "@bentley/context-registry-client"; import { HubIModel, IModelClient, IModelHubClient, IModelQuery } from "@bentley/imodelhub-client"; import { AuthorizedClientRequestContext } from "@bentley/itwin-client"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); +loadEnv(path.join(__dirname, "..", "..", ".env")); /** Basic configuration used by all tests */ diff --git a/core/backend/package.json b/core/backend/package.json index 161770e36c0d..9abc06335702 100644 --- a/core/backend/package.json +++ b/core/backend/package.json @@ -14,6 +14,7 @@ "clean": "rimraf lib .rush/temp/package-deps*.json", "docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/core/imodeljs-backend/file.json --tsIndexFile=./imodeljs-backend.ts --onlyJson", "copy:assets": "cpx \"./src/assets/**/*\" ./lib/assets", + "copy:config": "internal-tools copy-config", "copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/test/assets", "cover": "nyc npm test", "cover:integration": "nyc npm run test:integration", @@ -101,6 +102,7 @@ "cpx": "^1.5.0", "eslint": "^6.8.0", "event-stream": "~4.0.1", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "null-loader": "^0.1.1", "nyc": "^14.0.0", @@ -139,4 +141,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/core/backend/src/test/IModelTestUtils.ts b/core/backend/src/test/IModelTestUtils.ts index 1285462ed8cf..64f0c29e68a5 100644 --- a/core/backend/src/test/IModelTestUtils.ts +++ b/core/backend/src/test/IModelTestUtils.ts @@ -5,15 +5,13 @@ import { assert } from "chai"; import * as path from "path"; import { - BeEvent, BentleyLoggerCategory, ChangeSetStatus, Config, DbResult, GuidString, Id64, Id64String, IDisposable, IModelStatus, Logger, LogLevel, - OpenMode, + BeEvent, BentleyLoggerCategory, ChangeSetStatus, DbResult, GuidString, Id64, Id64String, IDisposable, IModelStatus, Logger, LogLevel, OpenMode, } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { ChangeSet, IModelHubClientLoggerCategory } from "@bentley/imodelhub-client"; import { Code, CodeProps, ElementProps, IModel, IModelError, IModelReadRpcInterface, IModelVersion, IModelVersionProps, PhysicalElementProps, RelatedElement, - RequestNewBriefcaseProps, - RpcConfiguration, RpcManager, RpcPendingResponse, SyncMode, + RequestNewBriefcaseProps, RpcConfiguration, RpcManager, RpcPendingResponse, SyncMode, } from "@bentley/imodeljs-common"; import { IModelJsNative, NativeLoggerCategory } from "@bentley/imodeljs-native"; import { AuthorizedClientRequestContext, ITwinClientLoggerCategory } from "@bentley/itwin-client"; @@ -429,7 +427,7 @@ export class IModelTestUtils { } public static async startBackend(): Promise { - IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); const config = new IModelHostConfiguration(); config.concurrentQuery.concurrent = 4; // for test restrict this to two threads. Making closing connection faster await IModelHost.startup(config); diff --git a/core/backend/src/test/ios/config/mobile.webpack.config.js b/core/backend/src/test/ios/config/mobile.webpack.config.js index d1f15e182dcc..330879d4ab86 100644 --- a/core/backend/src/test/ios/config/mobile.webpack.config.js +++ b/core/backend/src/test/ios/config/mobile.webpack.config.js @@ -6,10 +6,9 @@ const path = require("path"); const webpack = require("webpack"); const fs = require("fs"); -// 'is_ci_job' variable is set in ci job env. CI job already set all the envirnoment variable required to run integeration test +// 'is_ci_job' variable is set in ci job env. CI job already set all the environment variable required to run integration test if (!process.env.TF_BUILD) { - const config = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig; - config.init(); + require("@bentley/config-loader").loadEnv(path.join(__dirname, "..", "..", ".env")); } /** Find package root folder where package.json exist */ diff --git a/core/imodel-bridge/package.json b/core/imodel-bridge/package.json index 64657cccd524..43974caae92c 100644 --- a/core/imodel-bridge/package.json +++ b/core/imodel-bridge/package.json @@ -18,6 +18,7 @@ "clean": "rimraf lib .rush/temp/package-deps*.json", "docs": "betools docs --tsIndexFile=./imodel-bridge.ts --json=../../generated-docs/core/imodel-bridge/file.json --onlyJson", "copy:assets": "cpx \"./src/assets/**/*\" ./lib/assets", + "copy:config": "internal-tools copy-config", "copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/test/assets", "cover": "nyc npm test", "cover:integration": "nyc npm run test:integration", @@ -71,6 +72,7 @@ "chai": "^4.1.2", "cpx": "^1.5.0", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -88,4 +90,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/core/imodel-bridge/src/test/BridgeTestUtils.ts b/core/imodel-bridge/src/test/BridgeTestUtils.ts index 72c71b3c23b1..6577c15dc5c5 100644 --- a/core/imodel-bridge/src/test/BridgeTestUtils.ts +++ b/core/imodel-bridge/src/test/BridgeTestUtils.ts @@ -5,12 +5,12 @@ import { assert } from "chai"; import * as path from "path"; -import { BentleyLoggerCategory, Config, DbResult, Id64, Id64String, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { BentleyLoggerCategory, DbResult, Id64, Id64String, Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; import { ChangeSet, IModelHubClientLoggerCategory } from "@bentley/imodelhub-client"; import { - BackendLoggerCategory, ECSqlStatement, ExternalSourceAspect, IModelDb, IModelHost, IModelHostConfiguration, IModelJsFs, - NativeLoggerCategory, PhysicalPartition, Subject, + BackendLoggerCategory, ECSqlStatement, ExternalSourceAspect, IModelDb, IModelHost, IModelHostConfiguration, IModelJsFs, NativeLoggerCategory, + PhysicalPartition, Subject, } from "@bentley/imodeljs-backend"; import { IModel } from "@bentley/imodeljs-common"; import { AuthorizedClientRequestContext, ITwinClientLoggerCategory } from "@bentley/itwin-client"; @@ -111,7 +111,7 @@ export class BridgeTestUtils { } public static async startBackend(clientArgs?: IModelBankArgs): Promise { - IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); const config = new IModelHostConfiguration(); config.concurrentQuery.concurrent = 4; // for test restrict this to two threads. Making closing connection faster config.cacheDir = KnownTestLocations.outputDir; diff --git a/example-code/app/package.json b/example-code/app/package.json index 5b7e226d81d7..06a0b118a0e7 100644 --- a/example-code/app/package.json +++ b/example-code/app/package.json @@ -43,7 +43,6 @@ "webpack": "4.42.0" }, "devDependencies": { - "@bentley/config-loader": "2.13.0-dev.8", "@bentley/build-tools": "2.13.0-dev.8", "@bentley/eslint-plugin": "2.13.0-dev.8", "@bentley/oidc-signin-tool": "2.13.0-dev.8", @@ -70,4 +69,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/example-code/app/src/backend/test/Utils.ts b/example-code/app/src/backend/test/Utils.ts index 35ab7b9c37fb..c75493548293 100644 --- a/example-code/app/src/backend/test/Utils.ts +++ b/example-code/app/src/backend/test/Utils.ts @@ -4,12 +4,8 @@ *--------------------------------------------------------------------------------------------*/ import { assert } from "chai"; import * as path from "path"; -import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; import { IModelJsFs } from "@bentley/imodeljs-backend/lib/IModelJsFs"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); - export class KnownTestLocations { /** The directory where test assets are stored. Keep in mind that the test is playing the role of the app. */ public static get assetsDir(): string { diff --git a/example-code/snippets/package.json b/example-code/snippets/package.json index f11c1e4753e9..8fcb85b4afc2 100644 --- a/example-code/snippets/package.json +++ b/example-code/snippets/package.json @@ -41,7 +41,6 @@ "webpack": "4.42.0" }, "devDependencies": { - "@bentley/config-loader": "2.13.0-dev.8", "@bentley/build-tools": "2.13.0-dev.8", "@bentley/eslint-plugin": "2.13.0-dev.8", "@bentley/oidc-signin-tool": "2.13.0-dev.8", @@ -67,4 +66,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/example-code/snippets/src/backend/IModelTestUtils.ts b/example-code/snippets/src/backend/IModelTestUtils.ts index b3ebadd2db8c..cc4c617a5d49 100644 --- a/example-code/snippets/src/backend/IModelTestUtils.ts +++ b/example-code/snippets/src/backend/IModelTestUtils.ts @@ -4,15 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import { assert } from "chai"; import * as path from "path"; -import { Config, OpenMode } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { OpenMode } from "@bentley/bentleyjs-core"; import { ContextRegistryClient } from "@bentley/context-registry-client"; import { IModelHost, IModelHostConfiguration, KnownLocations, SnapshotDb, StandaloneDb } from "@bentley/imodeljs-backend"; import { IModelJsFs, IModelJsFsStats } from "@bentley/imodeljs-backend/lib/IModelJsFs"; import { IModelReadRpcInterface, RpcManager } from "@bentley/imodeljs-common"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); - RpcManager.initializeInterface(IModelReadRpcInterface); export interface IModelTestUtilsOpenOptions { diff --git a/full-stack-tests/core/package.json b/full-stack-tests/core/package.json index fdf76acfdb82..9bf57bd0fe31 100644 --- a/full-stack-tests/core/package.json +++ b/full-stack-tests/core/package.json @@ -5,6 +5,7 @@ "license": "MIT", "scripts": { "compile": "npm run build", + "copy:config": "internal-tools copy-config", "build": "tsc 1>&2 && npm run webpack:frontend && npm run build:extensions", "build:extensions": "npm run build:loadingTestExtension", "build:loadingTestExtension": "extension-webpack-tools build -s ./src/common/extensions/loadingTestExtension/loadingTestExtension.ts -o ./lib/imjs_extensions/loadingTestExtension --sourceMap", @@ -63,6 +64,7 @@ "chai": "^4.1.2", "glob": "^7.1.2", "istanbul-instrumenter-loader": "^3.0.1", + "internal-tools": "0.0.0", "null-loader": "^0.1.1", "rimraf": "^3.0.2", "source-map-loader": "^1.0.0", @@ -79,4 +81,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/core/src/backend/backend.ts b/full-stack-tests/core/src/backend/backend.ts index 89a96b610464..64c27bbd6a77 100644 --- a/full-stack-tests/core/src/backend/backend.ts +++ b/full-stack-tests/core/src/backend/backend.ts @@ -7,22 +7,22 @@ import "./RpcImpl"; import "@bentley/oidc-signin-tool/lib/certa/certaBackend"; import * as http from "http"; import * as path from "path"; -import serveHandler = require("serve-handler"); -import { Config, isElectronMain, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { isElectronMain, Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; +import { ElectronBackend } from "@bentley/electron-manager/lib/ElectronBackend"; import { IModelJsExpressServer } from "@bentley/express-server"; import { FileNameResolver, IModelHost, IModelHostConfiguration } from "@bentley/imodeljs-backend"; import { BentleyCloudRpcManager, RpcConfiguration } from "@bentley/imodeljs-common"; +import { EditCommandAdmin } from "@bentley/imodeljs-editor-backend"; import { rpcInterfaces } from "../common/RpcInterfaces"; import { CloudEnv } from "./cloudEnv"; -import { EditCommandAdmin } from "@bentley/imodeljs-editor-backend"; import * as testCommands from "./TestEditCommands"; -import { ElectronBackend } from "@bentley/electron-manager/lib/ElectronBackend"; +import serveHandler = require("serve-handler"); /* eslint-disable no-console */ async function init() { - IModelJsConfig.init(true, true, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); RpcConfiguration.developmentMode = true; // Bootstrap the cloud environment diff --git a/full-stack-tests/core/webpack.config.js b/full-stack-tests/core/webpack.config.js index 8acf4954e7b4..11df24651878 100644 --- a/full-stack-tests/core/webpack.config.js +++ b/full-stack-tests/core/webpack.config.js @@ -6,7 +6,7 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); +require("@bentley/config-loader").loadEnv(path.join(__dirname, ".env")); const { IModeljsLibraryExportsPlugin } = require('@bentley/webpack-tools-core'); @@ -56,12 +56,12 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; }, { IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), diff --git a/full-stack-tests/imodelhub-client/package.json b/full-stack-tests/imodelhub-client/package.json index 88ded64a7de5..71196eef7343 100644 --- a/full-stack-tests/imodelhub-client/package.json +++ b/full-stack-tests/imodelhub-client/package.json @@ -12,6 +12,7 @@ "compile": "npm run build", "build": "tsc 1>&2", "clean": "rimraf lib .rush/temp/package-deps*.json", + "copy:config": "internal-tools copy-config", "copy:test-assets": "cpx \"./src/assets/**/*\" ./lib/assets", "cover": "npm run cover:imodelhub-client && npm run cover:backend-itwin-client && npm run cover:itwin-client", "cover:imodelhub-client": "nyc --nycrc-path=imodelhub-client.nycrc npm test", @@ -63,6 +64,7 @@ "@types/nock": "^9.1.2", "cpx": "^1.5.0", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", "typescript": "~3.7.4" @@ -73,4 +75,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/imodelhub-client/src/TestConfig.ts b/full-stack-tests/imodelhub-client/src/TestConfig.ts index bdd4d8901ff6..48407d3a8080 100644 --- a/full-stack-tests/imodelhub-client/src/TestConfig.ts +++ b/full-stack-tests/imodelhub-client/src/TestConfig.ts @@ -2,11 +2,12 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ +import * as path from "path"; import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { RequestGlobalOptions } from "@bentley/itwin-client"; -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); +loadEnv(path.join(__dirname, "..", ".env")); // Increase the timeout since iModel creation is taking longer RequestGlobalOptions.timeout.response = 60 * 1000; // 60 seconds in ms diff --git a/full-stack-tests/native-app/package.json b/full-stack-tests/native-app/package.json index 8a848ce844a1..825b27f5aa23 100644 --- a/full-stack-tests/native-app/package.json +++ b/full-stack-tests/native-app/package.json @@ -15,6 +15,7 @@ "test:electron": "certa -r electron --grep \"#integration\" --invert", "test:integration": "npm run test:integration:electron", "test:integration:electron": "certa -r electron --grep \"#integration\"", + "copy:config": "internal-tools copy-config", "webpack:frontend": "webpack --config webpack.config.js 1>&2" }, "repository": {}, @@ -53,6 +54,7 @@ "eslint": "^6.8.0", "glob": "^7.1.2", "istanbul-instrumenter-loader": "^3.0.1", + "internal-tools": "0.0.0", "null-loader": "^0.1.1", "rimraf": "^3.0.2", "source-map-loader": "^1.0.0", @@ -67,4 +69,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/native-app/src/backend/backend.ts b/full-stack-tests/native-app/src/backend/backend.ts index 59097aae8130..65ace63668e1 100644 --- a/full-stack-tests/native-app/src/backend/backend.ts +++ b/full-stack-tests/native-app/src/backend/backend.ts @@ -3,20 +3,20 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { BentleyLoggerCategory, Config, isElectronMain, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +// Sets up certa to allow a method on the frontend to get an access token +import "@bentley/oidc-signin-tool/lib/certa/certaBackend"; +import "./RpcImpl"; +import * as path from "path"; +import { BentleyLoggerCategory, isElectronMain, Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; +import { ElectronBackend } from "@bentley/electron-manager/lib/ElectronBackend"; import { IModelJsExpressServer } from "@bentley/express-server"; import { IModelHubClientLoggerCategory } from "@bentley/imodelhub-client"; import { BackendLoggerCategory, IModelHostConfiguration, NativeAppBackend, NativeLoggerCategory } from "@bentley/imodeljs-backend"; import { BentleyCloudRpcManager, RpcConfiguration } from "@bentley/imodeljs-common"; -import { ElectronBackend } from "@bentley/electron-manager/lib/ElectronBackend"; import { ITwinClientLoggerCategory } from "@bentley/itwin-client"; -// Sets up certa to allow a method on the frontend to get an access token -import "@bentley/oidc-signin-tool/lib/certa/certaBackend"; -import * as path from "path"; import { rpcInterfaces } from "../common/RpcInterfaces"; import { CloudEnv } from "./cloudEnv"; -import "./RpcImpl"; /* eslint-disable no-console */ @@ -40,7 +40,7 @@ export function setupDebugLogLevels() { } async function init() { - IModelJsConfig.init(true, true, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); RpcConfiguration.developmentMode = true; diff --git a/full-stack-tests/native-app/webpack.config.js b/full-stack-tests/native-app/webpack.config.js index 0129056ef0c9..3e9bfd8a13a9 100644 --- a/full-stack-tests/native-app/webpack.config.js +++ b/full-stack-tests/native-app/webpack.config.js @@ -6,7 +6,9 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); + +// loads into the process.env +require("@bentley/config-loader").loadEnv(path.join(__dirname, ".env")); function createConfig(shouldInstrument) { const config = { @@ -49,16 +51,14 @@ function createConfig(shouldInstrument) { // Makes some environment variables available to the JS code, for example: // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ - "process.env": Object.keys(raw) + "process.env": Object.keys(process.env) .filter((key) => { return key.match(/^imjs_/i); }) .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); + env[key] = JSON.stringify(process.env[key]); return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), + }, {}), }) ] }; diff --git a/full-stack-tests/presentation/package.json b/full-stack-tests/presentation/package.json index f93faafc808a..d0cdc878840f 100644 --- a/full-stack-tests/presentation/package.json +++ b/full-stack-tests/presentation/package.json @@ -18,6 +18,7 @@ "lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2", "test": "cross-env NODE_ENV=development mocha --opts ./mocha.opts \"./lib/**/*.js\" --grep \"#with-services\" --invert", "test:integration": "mocha --opts ./mocha.opts \"./lib/**/*.js\" --grep \"#with-services\"", + "copy:config": "internal-tools copy-config", "cover": "npm run test" }, "dependencies": { @@ -80,6 +81,7 @@ "cross-env": "^5.1.4", "eslint": "^6.8.0", "ignore-styles": "^5.0.1", + "internal-tools": "0.0.0", "jsdom-global": "3.0.2", "ts-node": "^7.0.1", "typescript": "~3.7.4" @@ -90,4 +92,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/presentation/src/IntegrationTests.ts b/full-stack-tests/presentation/src/IntegrationTests.ts index 7589a2066fc3..79a15ee3c2fd 100644 --- a/full-stack-tests/presentation/src/IntegrationTests.ts +++ b/full-stack-tests/presentation/src/IntegrationTests.ts @@ -10,7 +10,7 @@ import * as fs from "fs"; import * as path from "path"; import sinonChai from "sinon-chai"; import { ClientRequestContext, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { IModelAppOptions, NoRenderApp } from "@bentley/imodeljs-frontend"; import { I18NOptions } from "@bentley/imodeljs-i18n"; import { TestUsers } from "@bentley/oidc-signin-tool/lib/TestUsers"; @@ -27,7 +27,7 @@ import { initialize as initializeTesting, PresentationTestingInitProps, terminat chai.use(sinonChai); chai.use(chaiSubset); -IModelJsConfig.init(true); +loadEnv(path.join(__dirname, "..", ".env")); const copyBentleyBackendAssets = (outputDir: string) => { const bentleyPackagesPath = "node_modules/@bentley"; diff --git a/full-stack-tests/rpc-interface/package.json b/full-stack-tests/rpc-interface/package.json index 4bf7ec9b26f8..450dbd7c4558 100644 --- a/full-stack-tests/rpc-interface/package.json +++ b/full-stack-tests/rpc-interface/package.json @@ -7,6 +7,7 @@ "compile": "npm run build", "build": "npm run copy:files && tsc 1>&2 && npm run webpack:frontend", "clean": "rimraf lib .rush/temp/package-deps*.json integration_test_results", + "copy:config": "internal-tools copy-config", "copy:files": "cpx \"./rulesets/**/*\" ./lib/rulesets/", "cover": "", "docs": "", @@ -70,6 +71,7 @@ "@types/puppeteer": "2.0.1", "cpx": "^1.5.0", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "npm-run-all": "^4.1.5", "null-loader": "^0.1.1", "rimraf": "^3.0.2", @@ -84,4 +86,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/rpc-interface/src/backend/BackendInit.ts b/full-stack-tests/rpc-interface/src/backend/BackendInit.ts index e79e47a6b4d6..2d1f872baa17 100644 --- a/full-stack-tests/rpc-interface/src/backend/BackendInit.ts +++ b/full-stack-tests/rpc-interface/src/backend/BackendInit.ts @@ -1,18 +1,19 @@ /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. -* Licensed under the MIT License. See LICENSE.md in the project root for license terms. +* See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -// Sets up certa to allow a method on the frontend to get an access token import "@bentley/oidc-signin-tool/lib/certa/certaBackend"; +// Sets up certa to allow a method on the frontend to get an access token +import * as path from "path"; import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { Settings } from "../common/Settings"; import { exposeBackendCallbacks } from "../common/SideChannels"; /* eslint-disable no-console */ module.exports = (async () => { - IModelJsConfig.init(true, true, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); // Need to create a new one on the backend to properly setup dotenv const settings = new Settings(process.env); diff --git a/full-stack-tests/rpc-interface/src/test/backend.ts b/full-stack-tests/rpc-interface/src/test/backend.ts index d805fd65d0cc..14cbf491c1aa 100644 --- a/full-stack-tests/rpc-interface/src/test/backend.ts +++ b/full-stack-tests/rpc-interface/src/test/backend.ts @@ -1,19 +1,19 @@ /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. -* Licensed under the MIT License. See LICENSE.md in the project root for license terms. +* See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ // Sets up a local backend to be used for testing within the iModel.js repo. -import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import * as path from "path"; +import { loadEnv } from "@bentley/config-loader"; import { IModelJsExpressServer } from "@bentley/express-server"; import { IModelHost, IModelHostConfiguration } from "@bentley/imodeljs-backend"; import { BentleyCloudRpcManager, RpcConfiguration } from "@bentley/imodeljs-common"; import { Presentation as PresentationBackend } from "@bentley/presentation-backend"; import { getRpcInterfaces, Settings } from "../common/Settings"; -IModelJsConfig.init(true, true, Config.App); +loadEnv(path.join(__dirname, "..", "..", ".env")); const settings = new Settings(process.env); // eslint-disable-next-line @typescript-eslint/no-floating-promises diff --git a/full-stack-tests/rpc/package.json b/full-stack-tests/rpc/package.json index 787a29c7f7c0..95671fbcf55d 100644 --- a/full-stack-tests/rpc/package.json +++ b/full-stack-tests/rpc/package.json @@ -32,9 +32,8 @@ "spdy": "^4.0.1" }, "devDependencies": { - "@bentley/certa": "2.13.0-dev.8", - "@bentley/config-loader": "2.13.0-dev.8", "@bentley/build-tools": "2.13.0-dev.8", + "@bentley/certa": "2.13.0-dev.8", "@bentley/eslint-plugin": "2.13.0-dev.8", "@types/chai": "^4.1.4", "@types/express": "^4.16.1", @@ -57,4 +56,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts index ab1e1ac38f1f..8e4b5976e668 100644 --- a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts +++ b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts @@ -2,16 +2,14 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { Config, Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { Logger, LogLevel } from "@bentley/bentleyjs-core"; import { registerBackendCallback } from "@bentley/certa/lib/utils/CallbackUtils"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; import { IModelHost } from "@bentley/imodeljs-backend"; import { IModelReadRpcInterface, RpcConfiguration } from "@bentley/imodeljs-common"; import { BackendTestCallbacks } from "../common/SideChannels"; import { resetOp8Initializer, TestRpcImpl2 } from "./TestRpcImpl"; export async function commonSetup(): Promise { - IModelJsConfig.init(true, true, Config.App); RpcConfiguration.developmentMode = true; // Start the backend diff --git a/full-stack-tests/rpc/webpack.config.js b/full-stack-tests/rpc/webpack.config.js index 0dc161b2c7d9..20b0d059b0bb 100644 --- a/full-stack-tests/rpc/webpack.config.js +++ b/full-stack-tests/rpc/webpack.config.js @@ -6,7 +6,6 @@ const path = require("path"); const glob = require("glob"); const webpack = require("webpack"); -const raw = require("@bentley/config-loader/lib/IModelJsConfig").IModelJsConfig.init(true /*suppress error*/, true); module.exports = { mode: "development", entry: glob.sync(path.resolve(__dirname, "lib/**/*.test.js")), @@ -63,16 +62,6 @@ module.exports = { // if (process.env.NODE_ENV === "development") { ... }. See `./env.js`. new webpack.DefinePlugin({ "global.GENTLY": false, - "process.env": Object.keys(raw) - .filter((key) => { - return key.match(/^imjs_/i); - }) - .reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); - return env; - }, { - IMODELJS_CORE_DIRNAME: JSON.stringify(path.join(__dirname, "../..")), - }), }) ] }; diff --git a/test-apps/display-performance-test-app/src/backend/backend.ts b/test-apps/display-performance-test-app/src/backend/backend.ts index 6e89c2b6ac85..eeaa0c414a58 100644 --- a/test-apps/display-performance-test-app/src/backend/backend.ts +++ b/test-apps/display-performance-test-app/src/backend/backend.ts @@ -3,8 +3,8 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import "./DisplayPerfRpcImpl"; // just to get the RPC implementation registered -import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import * as path from "path"; +import { loadEnv } from "@bentley/config-loader"; import { IModelHost, IModelHostConfiguration } from "@bentley/imodeljs-backend"; import { IModelReadRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; import DisplayPerfRpcInterface from "../common/DisplayPerfRpcInterface"; @@ -14,7 +14,7 @@ export function getRpcInterfaces() { } export async function initializeBackend() { - IModelJsConfig.init(true /* suppress exception */, true /* suppress error message */, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // (needed temporarily to use self-signed cert to communicate with iModelBank via https) const hostConfig = new IModelHostConfiguration(); diff --git a/test-apps/display-test-app/package.json b/test-apps/display-test-app/package.json index 184c5af940c6..a9f980b464e3 100644 --- a/test-apps/display-test-app/package.json +++ b/test-apps/display-test-app/package.json @@ -27,7 +27,7 @@ "start:servers": "run-p \"start:webserver\" \"start:backend\"", "test": "", "cover": "", - "copyConfig": "internal-tools copy-config", + "copy:config": "internal-tools copy-config", "build:ios-backend": "npm run build:backend && webpack --config ./ios/backend.config --env.outdir=./lib/ios --env.entry=./lib/backend/MobileMain.js --env.bundlename=main", "install-ios-lib": "node ./ios/scripts/installIosNativeLib.js", "copy:ios-frontend": "mkdir -p ./lib/ios && rm -rf ./lib/ios/www && cp -R ./build ./lib/ios/www", diff --git a/test-apps/display-test-app/src/backend/Backend.ts b/test-apps/display-test-app/src/backend/Backend.ts index 72e688f02d4a..db2140cc60d8 100644 --- a/test-apps/display-test-app/src/backend/Backend.ts +++ b/test-apps/display-test-app/src/backend/Backend.ts @@ -5,8 +5,8 @@ import * as fs from "fs"; import * as path from "path"; import { UrlFileHandler } from "@bentley/backend-itwin-client"; -import { Config, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; import { IModelBankClient } from "@bentley/imodelhub-client"; import { IModelHost, IModelHostConfiguration, NativeAppBackend } from "@bentley/imodeljs-backend"; import { @@ -100,7 +100,7 @@ export const getRpcInterfaces = (): RpcInterfaceDefinition[] => { const setupStandaloneConfiguration = () => { process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // (needed temporarily to use self-signed cert to communicate with iModelBank via https) - IModelJsConfig.init(true /* suppress exception */, true /* suppress error message */, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); const configuration: DtaConfiguration = {}; if (MobileRpcConfiguration.isMobileBackend) diff --git a/test-apps/presentation-test-app/src/backend/main.ts b/test-apps/presentation-test-app/src/backend/main.ts index 485dc03ada57..e711f5173eef 100644 --- a/test-apps/presentation-test-app/src/backend/main.ts +++ b/test-apps/presentation-test-app/src/backend/main.ts @@ -5,8 +5,8 @@ import "./SampleRpcImpl"; // just to get the RPC implementation registered import { app as electron } from "electron"; import * as path from "path"; -import { Config, Logger, LogLevel } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; import { IModelHost } from "@bentley/imodeljs-backend"; import { RpcConfiguration, RpcInterfaceDefinition } from "@bentley/imodeljs-common"; // __PUBLISH_EXTRACT_START__ Presentation.Backend.Initialization @@ -17,7 +17,7 @@ import rpcs from "../common/Rpcs"; import { PresentationBackendLoggerCategory, PresentationBackendNativeLoggerCategory } from "@bentley/presentation-backend"; // eslint-disable-line no-duplicate-imports (async () => { // eslint-disable-line @typescript-eslint/no-floating-promises - IModelJsConfig.init(true /* suppress error */, true /* suppress message */, Config.App); + loadEnv(path.join(__dirname, "..", "..", ".env")); // initialize logging Logger.initializeToConsole(); diff --git a/test-apps/ui-test-app/package.json b/test-apps/ui-test-app/package.json index c5a21114f0cf..5845daaf9b2c 100644 --- a/test-apps/ui-test-app/package.json +++ b/test-apps/ui-test-app/package.json @@ -23,7 +23,7 @@ "test": "", "cover": "", "docs": "", - "copyConfig": "internal-tools copy-config", + "copy:config": "internal-tools copy-config", "build:ios-backend": "npm run build:backend && webpack --config ./ios/backend.config --env.outdir=./lib/ios --env.entry=./lib/backend/mobile/MobileMain.js --env.bundlename=main", "install-ios-lib": "node ./ios/scripts/installIosNativeLib.js", "copy:ios-frontend": "mkdir -p ./lib/ios && rm -rf ./lib/ios/www && cp -R ./build ./lib/ios/www", @@ -157,4 +157,4 @@ "@typescript-eslint/unbound-method": "off" } } -} +} \ No newline at end of file diff --git a/test-apps/ui-test-app/src/backend/main.ts b/test-apps/ui-test-app/src/backend/main.ts index 5b6a39ce962f..7ecd74c0ceff 100644 --- a/test-apps/ui-test-app/src/backend/main.ts +++ b/test-apps/ui-test-app/src/backend/main.ts @@ -3,17 +3,16 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { app as electron } from "electron"; -import * as os from "os"; import * as fs from "fs"; +import * as os from "os"; import * as path from "path"; +import { BackendApplicationInsightsClient } from "@bentley/backend-application-insights-client"; import { Config, Logger } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; import { IModelHost } from "@bentley/imodeljs-backend"; import { RpcInterfaceDefinition } from "@bentley/imodeljs-common"; import { Presentation } from "@bentley/presentation-backend"; import getSupportedRpcs from "../common/rpcs"; import { initializeLogging } from "./web/BackendServer"; -import { BackendApplicationInsightsClient } from "@bentley/backend-application-insights-client"; (async () => { // eslint-disable-line @typescript-eslint/no-floating-promises try { @@ -24,8 +23,6 @@ import { BackendApplicationInsightsClient } from "@bentley/backend-application-i ); } - IModelJsConfig.init(true /* suppress error */, true /* suppress message */, Config.App); - if (!electron) { initializeLogging(); } diff --git a/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts b/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts index 9389186e74b2..85a4828d739c 100644 --- a/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts +++ b/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts @@ -3,13 +3,12 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { IModelReadRpcInterface, IModelTileRpcInterface, MobileRpcManager, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; -import { Presentation } from "@bentley/presentation-backend"; -import { NativeAppBackend } from "@bentley/imodeljs-backend"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; import * as fs from "fs"; import * as path from "path"; -import { Config, Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { Logger, LogLevel } from "@bentley/bentleyjs-core"; +import { NativeAppBackend } from "@bentley/imodeljs-backend"; +import { IModelReadRpcInterface, IModelTileRpcInterface, MobileRpcManager, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; +import { Presentation } from "@bentley/presentation-backend"; import { PresentationRpcInterface } from "@bentley/presentation-common"; (async () => { // eslint-disable-line @typescript-eslint/no-floating-promises @@ -22,7 +21,6 @@ import { PresentationRpcInterface } from "@bentley/presentation-common"; } Logger.initializeToConsole(); Logger.setLevelDefault(LogLevel.Trace); - IModelJsConfig.init(true /* suppress error */, true /* suppress message */, Config.App); // initialize imodeljs-backend await NativeAppBackend.startup(); diff --git a/tools/config-loader/package.json b/tools/config-loader/package.json index 6963eacf9afb..58ba68e9a667 100644 --- a/tools/config-loader/package.json +++ b/tools/config-loader/package.json @@ -7,6 +7,7 @@ "type": "git", "url": "/~https://github.com/imodeljs/imodeljs/tree/master/tools/config-loader" }, + "main": "lib/index.js", "typings": "lib/index", "scripts": { "compile": "npm run build", @@ -53,4 +54,4 @@ "no-eval": "off" } } -} +} \ No newline at end of file diff --git a/tools/config-loader/src/IModelJsConfig.ts b/tools/config-loader/src/IModelJsConfig.ts index 1c724645b827..2e581cbd9f07 100644 --- a/tools/config-loader/src/IModelJsConfig.ts +++ b/tools/config-loader/src/IModelJsConfig.ts @@ -2,10 +2,29 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import * as JSON5 from "json5"; +import * as chalk from "chalk"; import * as fs from "fs"; +import * as JSON5 from "json5"; import * as path from "path"; -import * as chalk from "chalk"; + +/** Loads the provided `.env` file into process.env + * @internal + */ +export function loadEnv(envFile: string) { + if (!fs.existsSync(envFile)) + return; + + const dotenv = require("dotenv"); // eslint-disable-line @typescript-eslint/no-var-requires + const dotenvExpand = require("dotenv-expand"); // eslint-disable-line @typescript-eslint/no-var-requires + const envResult = dotenv.config({ path: envFile }); + if (envResult.error) { + throw envResult.error; + } + + dotenvExpand(envResult); +} + +/* eslint-disable deprecation/deprecation */ /** Handles locating an iModel.js configuration JSON file and merging it with the existing configuration. * @@ -14,6 +33,7 @@ import * as chalk from "chalk"; * * For details on how the configuration is loaded, see the documentation on [[IModelJsConfig.init]]. * @public + * @deprecated Deprecated in favor of directly using the dotenv package or using the new `loadEnv()`. Will be removed in next major release (3.0). */ export class IModelJsConfig { private static _repositoryPath: string; diff --git a/tools/internal/scripts/copyConfig.js b/tools/internal/scripts/copyConfig.js index 2201f9d2eb7c..f4ed9a32ab98 100644 --- a/tools/internal/scripts/copyConfig.js +++ b/tools/internal/scripts/copyConfig.js @@ -20,18 +20,23 @@ exports.builder = (yargs) => exports.handler = async (argv) => { const rootDir = __dirname.split("tools")[0]; - let lastIndex = rootDir.lastIndexOf(path.sep + "imodeljs"); - let pathDir = rootDir.substring(0, lastIndex + 1); - const configDir = path.resolve(pathDir, "imodeljs-config"); - const envFile = path.resolve(configDir, ".env"); - if (!fs.existsSync(configDir) || !fs.existsSync(envFile)) { - console.log("Missing either imodeljs-config directory or .env file"); + let envFile = process.env.imjs_config_file ? process.env.imjs_config_file : ""; + + if (!envFile) { + const lastIndex = rootDir.lastIndexOf(path.sep + "imodeljs"); + const pathDir = rootDir.substring(0, lastIndex + 1); + const configDir = path.resolve(pathDir, "imodeljs-config"); + envFile = path.resolve(configDir, ".env"); + } + + if (!fs.existsSync(envFile)) { + console.log(`The ${envFile} path does not exist.`); return; } - for (let destination of argv.out) { - const destRoot = path.resolve(rootDir, "test-apps", destination) + for (const destination of argv.out) { + const destRoot = path.resolve(rootDir, destination) if (!fs.existsSync(destRoot)) { console.log(`Cannot find the root directory of the destination: ${destRoot}`) return; diff --git a/tools/oidc-signin-tool/package.json b/tools/oidc-signin-tool/package.json index e9a56c9af0b5..69a9c4789b05 100644 --- a/tools/oidc-signin-tool/package.json +++ b/tools/oidc-signin-tool/package.json @@ -16,6 +16,7 @@ "lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2", "test": "", "test:integration": "betools test", + "copy:config": "internal-tools copy-config", "docs": "", "cover": "" }, @@ -49,6 +50,7 @@ "chai": "^4.1.2", "chai-as-promised": "^7", "eslint": "^6.8.0", + "internal-tools": "0.0.0", "mocha": "^5.2.0", "nyc": "^14.0.0", "rimraf": "^3.0.2", @@ -63,4 +65,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/tools/oidc-signin-tool/src/certa/certaBackend.ts b/tools/oidc-signin-tool/src/certa/certaBackend.ts index c1110ebc4985..fcc758bfa58a 100644 --- a/tools/oidc-signin-tool/src/certa/certaBackend.ts +++ b/tools/oidc-signin-tool/src/certa/certaBackend.ts @@ -3,9 +3,9 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { Config } from "@bentley/bentleyjs-core"; +import * as path from "path"; import { registerBackendCallback } from "@bentley/certa/lib/utils/CallbackUtils"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; +import { loadEnv } from "@bentley/config-loader"; import { AccessToken } from "@bentley/itwin-client"; import { TestBrowserAuthorizationClientConfiguration, TestUserCredentials } from "../TestUsers"; import { TestUtility } from "../TestUtility"; @@ -15,7 +15,10 @@ import { getTokenCallbackName, serializeToken } from "./certaCommon"; /* eslint-disable no-console */ -IModelJsConfig.init(true, true, Config.App); +// The assumption is the certa.json file is a peer of the `package.json` file and +// when certa is invoked via a npm script (in the package.json) the `.env` will +// also be a peer of both files. +loadEnv(path.join(process.cwd(), ".env")); /** Signs in for the provided user. * diff --git a/tools/oidc-signin-tool/src/test/basic.test.ts b/tools/oidc-signin-tool/src/test/basic.test.ts index acc71b90306e..1eb27fa6c694 100644 --- a/tools/oidc-signin-tool/src/test/basic.test.ts +++ b/tools/oidc-signin-tool/src/test/basic.test.ts @@ -3,17 +3,18 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { Config } from "@bentley/bentleyjs-core"; -import { IModelJsConfig } from "@bentley/config-loader/lib/IModelJsConfig"; import * as chai from "chai"; import * as chaiAsPromised from "chai-as-promised"; +import * as path from "path"; +import { Config } from "@bentley/bentleyjs-core"; +import { loadEnv } from "@bentley/config-loader"; import { getTestAccessToken, TestBrowserAuthorizationClientConfiguration, TestUsers, TestUtility } from "../index"; const assert = chai.assert; const expect = chai.expect; chai.use(chaiAsPromised); -IModelJsConfig.init(true /* suppress exception */, false /* suppress error message */, Config.App); +loadEnv(path.join(__dirname, "..", "..", ".env")); describe("Sign in (#integration)", () => { let oidcConfig: TestBrowserAuthorizationClientConfiguration;