From 478de90d45911fef490637f381032822ae70f796 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Mon, 25 Jul 2022 15:13:54 +0200 Subject: [PATCH] Cleanup `src` folder for web and move ts code into `src/app` per angular convention (#3127) --- apps/web/src/abstractions/state.service.ts | 9 ----- apps/web/src/app/accounts/login.component.ts | 2 +- apps/web/src/{ => app}/models/account.ts | 0 apps/web/src/{ => app}/models/globalState.ts | 0 .../services/broadcasterMessaging.service.ts | 0 .../{ => app}/services/htmlStorage.service.ts | 0 .../src/{ => app}/services/i18n.service.ts | 0 apps/web/src/app/services/init.service.ts | 2 +- .../services/passwordReprompt.service.ts | 2 +- apps/web/src/app/services/services.module.ts | 36 ++++++----------- .../src/{ => app}/services/state.service.ts | 39 ++++++++++++++++--- .../services/stateMigration.service.ts | 0 .../services/webPlatformUtils.service.ts | 0 .../src/app/settings/settings.component.ts | 2 +- apps/web/src/{app => }/main.ts | 6 +-- apps/web/src/{app => }/polyfills.ts | 0 apps/web/tsconfig.json | 14 +------ apps/web/webpack.config.js | 4 +- .../bit-web/src/{app => }/main.ts | 2 +- bitwarden_license/bit-web/webpack.config.js | 2 +- package.json | 2 +- 21 files changed, 59 insertions(+), 63 deletions(-) delete mode 100644 apps/web/src/abstractions/state.service.ts rename apps/web/src/{ => app}/models/account.ts (100%) rename apps/web/src/{ => app}/models/globalState.ts (100%) rename apps/web/src/{ => app}/services/broadcasterMessaging.service.ts (100%) rename apps/web/src/{ => app}/services/htmlStorage.service.ts (100%) rename apps/web/src/{ => app}/services/i18n.service.ts (100%) rename apps/web/src/{ => app}/services/passwordReprompt.service.ts (77%) rename apps/web/src/{ => app}/services/state.service.ts (75%) rename apps/web/src/{ => app}/services/stateMigration.service.ts (100%) rename apps/web/src/{ => app}/services/webPlatformUtils.service.ts (100%) rename apps/web/src/{app => }/main.ts (75%) rename apps/web/src/{app => }/polyfills.ts (100%) rename bitwarden_license/bit-web/src/{app => }/main.ts (89%) diff --git a/apps/web/src/abstractions/state.service.ts b/apps/web/src/abstractions/state.service.ts deleted file mode 100644 index c6b237a84d..0000000000 --- a/apps/web/src/abstractions/state.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { StateService as BaseStateService } from "@bitwarden/common/abstractions/state.service"; -import { StorageOptions } from "@bitwarden/common/models/domain/storageOptions"; - -import { Account } from "src/models/account"; - -export abstract class StateService extends BaseStateService { - getRememberEmail: (options?: StorageOptions) => Promise; - setRememberEmail: (value: boolean, options?: StorageOptions) => Promise; -} diff --git a/apps/web/src/app/accounts/login.component.ts b/apps/web/src/app/accounts/login.component.ts index 180d3d2739..4410311e4f 100644 --- a/apps/web/src/app/accounts/login.component.ts +++ b/apps/web/src/app/accounts/login.component.ts @@ -19,8 +19,8 @@ import { Policy } from "@bitwarden/common/models/domain/policy"; import { ListResponse } from "@bitwarden/common/models/response/listResponse"; import { PolicyResponse } from "@bitwarden/common/models/response/policyResponse"; -import { StateService } from "../../abstractions/state.service"; import { RouterService } from "../services/router.service"; +import { StateService } from "../services/state.service"; @Component({ selector: "app-login", diff --git a/apps/web/src/models/account.ts b/apps/web/src/app/models/account.ts similarity index 100% rename from apps/web/src/models/account.ts rename to apps/web/src/app/models/account.ts diff --git a/apps/web/src/models/globalState.ts b/apps/web/src/app/models/globalState.ts similarity index 100% rename from apps/web/src/models/globalState.ts rename to apps/web/src/app/models/globalState.ts diff --git a/apps/web/src/services/broadcasterMessaging.service.ts b/apps/web/src/app/services/broadcasterMessaging.service.ts similarity index 100% rename from apps/web/src/services/broadcasterMessaging.service.ts rename to apps/web/src/app/services/broadcasterMessaging.service.ts diff --git a/apps/web/src/services/htmlStorage.service.ts b/apps/web/src/app/services/htmlStorage.service.ts similarity index 100% rename from apps/web/src/services/htmlStorage.service.ts rename to apps/web/src/app/services/htmlStorage.service.ts diff --git a/apps/web/src/services/i18n.service.ts b/apps/web/src/app/services/i18n.service.ts similarity index 100% rename from apps/web/src/services/i18n.service.ts rename to apps/web/src/app/services/i18n.service.ts diff --git a/apps/web/src/app/services/init.service.ts b/apps/web/src/app/services/init.service.ts index 0ab752c8f7..940ee50168 100644 --- a/apps/web/src/app/services/init.service.ts +++ b/apps/web/src/app/services/init.service.ts @@ -17,7 +17,7 @@ import { ContainerService } from "@bitwarden/common/services/container.service"; import { EventService as EventLoggingService } from "@bitwarden/common/services/event.service"; import { VaultTimeoutService as VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service"; -import { I18nService as I18nService } from "../../services/i18n.service"; +import { I18nService } from "./i18n.service"; @Injectable() export class InitService { diff --git a/apps/web/src/services/passwordReprompt.service.ts b/apps/web/src/app/services/passwordReprompt.service.ts similarity index 77% rename from apps/web/src/services/passwordReprompt.service.ts rename to apps/web/src/app/services/passwordReprompt.service.ts index fc0ed81585..fdd176e42d 100644 --- a/apps/web/src/services/passwordReprompt.service.ts +++ b/apps/web/src/app/services/passwordReprompt.service.ts @@ -2,7 +2,7 @@ import { Injectable } from "@angular/core"; import { PasswordRepromptService as BasePasswordRepromptService } from "@bitwarden/angular/services/passwordReprompt.service"; -import { PasswordRepromptComponent } from "../app/components/password-reprompt.component"; +import { PasswordRepromptComponent } from "../components/password-reprompt.component"; @Injectable() export class PasswordRepromptService extends BasePasswordRepromptService { diff --git a/apps/web/src/app/services/services.module.ts b/apps/web/src/app/services/services.module.ts index b5677f7871..efb5d991c0 100644 --- a/apps/web/src/app/services/services.module.ts +++ b/apps/web/src/app/services/services.module.ts @@ -13,7 +13,6 @@ import { import { ModalService as ModalServiceAbstraction } from "@bitwarden/angular/services/modal.service"; import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service"; import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/abstractions/log.service"; import { MessagingService as MessagingServiceAbstraction } from "@bitwarden/common/abstractions/messaging.service"; import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "@bitwarden/common/abstractions/passwordReprompt.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/abstractions/platformUtils.service"; @@ -23,26 +22,25 @@ import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.s import { StateFactory } from "@bitwarden/common/factories/stateFactory"; import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service"; -import { StateService as StateServiceAbstraction } from "../../abstractions/state.service"; -import { Account } from "../../models/account"; -import { GlobalState } from "../../models/globalState"; -import { BroadcasterMessagingService } from "../../services/broadcasterMessaging.service"; -import { HtmlStorageService } from "../../services/htmlStorage.service"; -import { I18nService } from "../../services/i18n.service"; -import { PasswordRepromptService } from "../../services/passwordReprompt.service"; -import { StateService } from "../../services/state.service"; -import { StateMigrationService } from "../../services/stateMigration.service"; -import { WebPlatformUtilsService } from "../../services/webPlatformUtils.service"; import { HomeGuard } from "../guards/home.guard"; +import { Account } from "../models/account"; +import { GlobalState } from "../models/globalState"; import { PermissionsGuard as OrgPermissionsGuard } from "../organizations/guards/permissions.guard"; import { NavigationPermissionsService as OrgPermissionsService } from "../organizations/services/navigation-permissions.service"; +import { BroadcasterMessagingService } from "./broadcasterMessaging.service"; import { EventService } from "./event.service"; +import { HtmlStorageService } from "./htmlStorage.service"; +import { I18nService } from "./i18n.service"; import { InitService } from "./init.service"; import { ModalService } from "./modal.service"; +import { PasswordRepromptService } from "./passwordReprompt.service"; import { PolicyListService } from "./policy-list.service"; import { RouterService } from "./router.service"; +import { StateService } from "./state.service"; +import { StateMigrationService } from "./stateMigration.service"; import { WebFileDownloadService } from "./webFileDownload.service"; +import { WebPlatformUtilsService } from "./webPlatformUtils.service"; @NgModule({ imports: [ToastrModule, JslibServicesModule], @@ -95,22 +93,10 @@ import { WebFileDownloadService } from "./webFileDownload.service"; useClass: StateMigrationService, deps: [AbstractStorageService, SECURE_STORAGE, STATE_FACTORY], }, - { - provide: StateServiceAbstraction, - useClass: StateService, - deps: [ - AbstractStorageService, - SECURE_STORAGE, - MEMORY_STORAGE, - LogService, - StateMigrationServiceAbstraction, - STATE_FACTORY, - STATE_SERVICE_USE_CACHE, - ], - }, + StateService, { provide: BaseStateServiceAbstraction, - useExisting: StateServiceAbstraction, + useExisting: StateService, }, { provide: PasswordRepromptServiceAbstraction, diff --git a/apps/web/src/services/state.service.ts b/apps/web/src/app/services/state.service.ts similarity index 75% rename from apps/web/src/services/state.service.ts rename to apps/web/src/app/services/state.service.ts index a2e6679b83..12b180991e 100644 --- a/apps/web/src/services/state.service.ts +++ b/apps/web/src/app/services/state.service.ts @@ -1,3 +1,15 @@ +import { Inject, Injectable } from "@angular/core"; + +import { + MEMORY_STORAGE, + SECURE_STORAGE, + STATE_FACTORY, + STATE_SERVICE_USE_CACHE, +} from "@bitwarden/angular/services/jslib-services.module"; +import { LogService } from "@bitwarden/common/abstractions/log.service"; +import { StateMigrationService } from "@bitwarden/common/abstractions/stateMigration.service"; +import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; +import { StateFactory } from "@bitwarden/common/factories/stateFactory"; import { CipherData } from "@bitwarden/common/models/data/cipherData"; import { CollectionData } from "@bitwarden/common/models/data/collectionData"; import { FolderData } from "@bitwarden/common/models/data/folderData"; @@ -5,14 +17,31 @@ import { SendData } from "@bitwarden/common/models/data/sendData"; import { StorageOptions } from "@bitwarden/common/models/domain/storageOptions"; import { StateService as BaseStateService } from "@bitwarden/common/services/state.service"; -import { StateService as StateServiceAbstraction } from "../abstractions/state.service"; import { Account } from "../models/account"; import { GlobalState } from "../models/globalState"; -export class StateService - extends BaseStateService - implements StateServiceAbstraction -{ +@Injectable() +export class StateService extends BaseStateService { + constructor( + storageService: AbstractStorageService, + @Inject(SECURE_STORAGE) secureStorageService: AbstractStorageService, + @Inject(MEMORY_STORAGE) memoryStorageService: AbstractStorageService, + logService: LogService, + stateMigrationService: StateMigrationService, + @Inject(STATE_FACTORY) stateFactory: StateFactory, + @Inject(STATE_SERVICE_USE_CACHE) useAccountCache = true + ) { + super( + storageService, + secureStorageService, + memoryStorageService, + logService, + stateMigrationService, + stateFactory, + useAccountCache + ); + } + async addAccount(account: Account) { // Apply web overides to default account values account = new Account(account); diff --git a/apps/web/src/services/stateMigration.service.ts b/apps/web/src/app/services/stateMigration.service.ts similarity index 100% rename from apps/web/src/services/stateMigration.service.ts rename to apps/web/src/app/services/stateMigration.service.ts diff --git a/apps/web/src/services/webPlatformUtils.service.ts b/apps/web/src/app/services/webPlatformUtils.service.ts similarity index 100% rename from apps/web/src/services/webPlatformUtils.service.ts rename to apps/web/src/app/services/webPlatformUtils.service.ts diff --git a/apps/web/src/app/settings/settings.component.ts b/apps/web/src/app/settings/settings.component.ts index 0fae6a7dc0..c8840a1298 100644 --- a/apps/web/src/app/settings/settings.component.ts +++ b/apps/web/src/app/settings/settings.component.ts @@ -6,7 +6,7 @@ import { OrganizationService } from "@bitwarden/common/abstractions/organization import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { TokenService } from "@bitwarden/common/abstractions/token.service"; -import { StateService } from "../../abstractions/state.service"; +import { StateService } from "../services/state.service"; const BroadcasterSubscriptionId = "SettingsComponent"; diff --git a/apps/web/src/app/main.ts b/apps/web/src/main.ts similarity index 75% rename from apps/web/src/app/main.ts rename to apps/web/src/main.ts index 8749ffce34..01b054780a 100644 --- a/apps/web/src/app/main.ts +++ b/apps/web/src/main.ts @@ -5,10 +5,10 @@ import "bootstrap"; import "jquery"; import "popper.js"; -require("../scss/styles.scss"); -require("../scss/tailwind.css"); +require("./scss/styles.scss"); +require("./scss/tailwind.css"); -import { AppModule } from "./app.module"; +import { AppModule } from "./app/app.module"; if (process.env.NODE_ENV === "production") { enableProdMode(); diff --git a/apps/web/src/app/polyfills.ts b/apps/web/src/polyfills.ts similarity index 100% rename from apps/web/src/app/polyfills.ts rename to apps/web/src/polyfills.ts diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 2741b1c71e..35c81e9784 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -14,16 +14,6 @@ "angularCompilerOptions": { "preserveWhitespaces": true }, - "files": [ - "src/app/polyfills.ts", - "src/app/main.ts", - "../../bitwarden_license/bit-web/src/app/main.ts" - ], - "include": [ - "src/connectors/*.ts", - "src/models/*.ts", - "src/services/*.ts", - "src/abstractions/*.ts", - "src/**/*.stories.ts" - ] + "files": ["src/polyfills.ts", "src/main.ts", "../../bitwarden_license/bit-web/src/main.ts"], + "include": ["src/connectors/*.ts", "src/**/*.stories.ts"] } diff --git a/apps/web/webpack.config.js b/apps/web/webpack.config.js index 65caccc1cb..5be39eb1eb 100644 --- a/apps/web/webpack.config.js +++ b/apps/web/webpack.config.js @@ -282,8 +282,8 @@ const webpackConfig = { devtool: "source-map", devServer: devServer, entry: { - "app/polyfills": "./src/app/polyfills.ts", - "app/main": "./src/app/main.ts", + "app/polyfills": "./src/polyfills.ts", + "app/main": "./src/main.ts", "connectors/webauthn": "./src/connectors/webauthn.ts", "connectors/webauthn-fallback": "./src/connectors/webauthn-fallback.ts", "connectors/duo": "./src/connectors/duo.ts", diff --git a/bitwarden_license/bit-web/src/app/main.ts b/bitwarden_license/bit-web/src/main.ts similarity index 89% rename from bitwarden_license/bit-web/src/app/main.ts rename to bitwarden_license/bit-web/src/main.ts index 5d15ec7460..aa0e9d4697 100644 --- a/bitwarden_license/bit-web/src/app/main.ts +++ b/bitwarden_license/bit-web/src/main.ts @@ -8,7 +8,7 @@ import "popper.js"; require("src/scss/styles.scss"); require("src/scss/tailwind.css"); -import { AppModule } from "./app.module"; +import { AppModule } from "./app/app.module"; if (process.env.NODE_ENV === "production") { enableProdMode(); diff --git a/bitwarden_license/bit-web/webpack.config.js b/bitwarden_license/bit-web/webpack.config.js index 2d60d20bb6..155b572b42 100644 --- a/bitwarden_license/bit-web/webpack.config.js +++ b/bitwarden_license/bit-web/webpack.config.js @@ -2,7 +2,7 @@ const { AngularWebpackPlugin } = require("@ngtools/webpack"); const webpackConfig = require("../../apps/web/webpack.config"); -webpackConfig.entry["app/main"] = "../../bitwarden_license/bit-web/src/app/main.ts"; +webpackConfig.entry["app/main"] = "../../bitwarden_license/bit-web/src/main.ts"; webpackConfig.plugins[webpackConfig.plugins.length - 1] = new AngularWebpackPlugin({ tsConfigPath: "tsconfig.json", entryModule: "bitwarden_license/src/app/app.module#AppModule", diff --git a/package.json b/package.json index 4684a506f2..779021bbc9 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "homepage": "https://bitwarden.com", "scripts": { "prepare": "husky install", - "lint": "eslint . || prettier --check .", + "lint": "eslint . && prettier --check .", "lint:fix": "eslint . --fix", "prettier": "prettier --write .", "test": "jest",