Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move utility files to common package #11863

Draft
wants to merge 18 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions app/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,19 @@
"./src/config.json": "./src/config.json",
"./src/accessToken": "./src/accessToken.ts",
"./src/appConfig": "./src/appConfig.js",
"./src/iter": "./src/iter.ts",
"./src/buildUtils": "./src/buildUtils.js",
"./src/detect": "./src/detect.ts",
"./src/gtag": "./src/gtag.ts",
"./src/load": "./src/load.ts",
"./src/backendQuery": "./src/backendQuery.ts",
"./src/queryClient": "./src/queryClient.ts",
"./src/utilities/data/array": "./src/utilities/data/array.ts",
"./src/utilities/data/dateTime": "./src/utilities/data/dateTime.ts",
"./src/utilities/data/newtype": "./src/utilities/data/newtype.ts",
"./src/utilities/data/object": "./src/utilities/data/object.ts",
"./src/utilities/data/string": "./src/utilities/data/string.ts",
"./src/utilities/data/iter": "./src/utilities/data/iter.ts",
"./src/utilities/style/tabBar": "./src/utilities/style/tabBar.ts",
"./src/utilities/uniqueString": "./src/utilities/uniqueString.ts",
"./src/string": "./src/string.ts",
"./src/text": "./src/text/index.ts",
"./src/utilities/permissions": "./src/utilities/permissions.ts",
"./src/services/Backend": "./src/services/Backend.ts",
"./src/types": "./src/types.d.ts"
},
"scripts": {
"test": "vitest run",
"lint": "eslint ./src --cache --max-warnings=0"
},
"peerDependencies": {
"@tanstack/query-core": "5.54.1",
"@tanstack/vue-query": ">= 5.54.0 < 5.56.0"
},
"dependencies": {
"@tanstack/query-persist-client-core": "^5.54.0",
"@tanstack/vue-query": ">= 5.54.0 < 5.56.0",
"lib0": "^0.2.85",
"react": "^18.3.1",
"vitest": "^1.3.1",
"vue": "^3.5.2"
"lib0": "^0.2.85"
},
"devDependencies": {
"@types/node": "^22.9.0"
}
}
4 changes: 0 additions & 4 deletions app/common/src/accessToken.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/** @file Types for IPC events sent between Electron's main process and its renderer process. */

// ===================
// === AccessToken ===
// ===================

/** Credentials to be saved to a credentials file. */
export interface AccessToken {
/** The user's JWT token. */
Expand Down
8 changes: 0 additions & 8 deletions app/common/src/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import * as path from 'node:path'
import * as process from 'node:process'
import * as url from 'node:url'

// ===============================
// === readEnvironmentFromFile ===
// ===============================

/** Read environment variables from a file based on the `ENSO_CLOUD_ENV_FILE_NAME`
* environment variable. Reads from `.env` if the variable is `production`, blank or absent.
* DOES NOT override existing environment variables if the variable is absent. */
Expand Down Expand Up @@ -74,10 +70,6 @@ function discardUndefinedEnv(name) {
}
}

// ===============
// === globals ===
// ===============

/** The value as JSON if it is not nullish, else `'undefined'`.
* @param {unknown} value - the value to `JSON.stringify()`. */
function stringify(value) {
Expand Down
12 changes: 0 additions & 12 deletions app/common/src/buildUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ import * as fs from 'node:fs'
import * as path from 'node:path'
import process from 'node:process'

// =================
// === Constants ===
// =================

/** Indent size for outputting JSON. */
export const INDENT_SIZE = 4

// ===================
// === Environment ===
// ===================

/** Get the environment variable value.
* @param {string} name - The name of the environment variable.
* @returns {string} The value of the environment variable.
Expand Down Expand Up @@ -50,10 +42,6 @@ export function requireEnvPathExist(name) {
}
}

// ======================
// === String Helpers ===
// ======================

/** Get the common prefix of the two strings.
* @param {string} a - the first string.
* @param {string} b - the second string.
Expand Down
4 changes: 0 additions & 4 deletions app/common/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* circular dependency in our packages.
*/

// ========================
// === Product metadata ===
// ========================

/**
* URL protocol scheme for deep links to authentication flow pages, without the `:` suffix.
*
Expand Down
4 changes: 0 additions & 4 deletions app/common/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* here when it is not possible for a sibling package to own that code without introducing a
* circular dependency in our packages. */

// ========================
// === Product metadata ===
// ========================

/** URL protocol scheme for deep links to authentication flow pages, without the `:` suffix.
*
* For example: the deep link URL
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions app/common/src/text/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/** @file Functions related to displaying text. */

import ENGLISH from './english.json' with { type: 'json' }

// =============
// === Types ===
// =============

/** Possible languages in which to display text. */
export enum Language {
english = 'english',
Expand Down Expand Up @@ -152,10 +147,6 @@ export interface Replacements
extends PlaceholderOverrides,
Record<Exclude<TextId, keyof PlaceholderOverrides>, []> {}

// =================
// === Constants ===
// =================

export const TEXTS: Readonly<Record<Language, Texts>> = {
[Language.english]: ENGLISH,
}
31 changes: 0 additions & 31 deletions app/common/src/utilities/data/__tests__/array.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"checkJs": true,
"skipLibCheck": false
},
"include": ["./src/", "./src/text/english.json", "../types/"]
"include": ["./src/"]
}
2 changes: 1 addition & 1 deletion app/gui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { StrictMode, useLayoutEffect, useState } from 'react'
import invariant from 'tiny-invariant'
import UIProviders from '../src/dashboard/components/UIProviders'

import { createQueryClient } from '@common/services/tanstackQuery/client'
import { QueryClientProvider } from '@tanstack/react-query'
import { createQueryClient } from 'enso-common/src/queryClient'
import { MotionGlobalConfig } from 'framer-motion'
import z from 'zod'
import '../src/dashboard/tailwind.css'
Expand Down
42 changes: 1 addition & 41 deletions app/gui/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
import type * as saveAccessToken from 'enso-common/src/accessToken'

// prettier-ignore
import * as buildJson from '../../build.json' with { type: 'json' };

// =============
// === Types ===
// =============
import * as buildJson from '../../build.json' with { type: 'json' }

/** Nested configuration options with `string` values. */
interface StringConfig {
Expand All @@ -23,10 +19,6 @@ interface Enso {
readonly main: (inputConfig?: StringConfig) => Promise<void>
}

// ===================
// === Backend API ===
// ===================

/**
* `window.backendApi` is a context bridge to the main process, when we're running in an
* Electron context. It contains non-authentication-related functionality.
Expand All @@ -40,10 +32,6 @@ interface BackendApi {
) => Promise<ProjectInfo>
}

// ==========================
// === Authentication API ===
// ==========================

/**
* `window.authenticationApi` is a context bridge to the main process, when we're running in an
* Electron context.
Expand All @@ -67,10 +55,6 @@ interface AuthenticationApi {
readonly saveAccessToken: (accessToken: saveAccessToken.AccessToken | null) => void
}

// ======================
// === Navigation API ===
// ======================

/**
* `window.navigationApi` is a context bridge to the main process, when we're running in an
* Electron context. It contains navigation-related functionality.
Expand All @@ -82,30 +66,18 @@ interface NavigationApi {
readonly goForward: () => void
}

// ================
// === Menu API ===
// ================

/** `window.menuApi` exposes functionality related to the system menu. */
interface MenuApi {
/** Set the callback to be called when the "about" entry is clicked in the "help" menu. */
readonly setShowAboutModalHandler: (callback: () => void) => void
}

// ==================
// === System API ===
// ==================

/** `window.systemApi` exposes functionality related to the operating system. */
interface SystemApi {
readonly downloadURL: (url: string, headers?: Record<string, string>) => void
readonly showItemInFolder: (fullPath: string) => void
}

// ==============================
// === Project Management API ===
// ==============================

/** Metadata for a newly imported project. */
interface ProjectInfo {
readonly id: string
Expand All @@ -121,10 +93,6 @@ interface ProjectManagementApi {
readonly setOpenProjectHandler: (handler: (projectInfo: ProjectInfo) => void) => void
}

// ========================
// === File Browser API ===
// ========================

/**
* `window.fileBrowserApi` is a context bridge to the main process, when we're running in an
* Electron context.
Expand All @@ -146,10 +114,6 @@ interface FileBrowserApi {
) => Promise<string[] | undefined>
}

// ====================
// === Version Info ===
// ====================

/** Versions of the app, and selected software bundled with Electron. */
interface VersionInfo {
readonly version: string
Expand All @@ -158,10 +122,6 @@ interface VersionInfo {
readonly chrome: string
}

// =====================================
// === Global namespace augmentation ===
// =====================================

// JSDocs here are intentionally empty as these interfaces originate from elsewhere.
declare global {
// Documentation is already inherited.
Expand Down
2 changes: 1 addition & 1 deletion app/gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<title>Enso %ENSO_IDE_VERSION%</title>

<script type="module">
import { platform } from '../common/src/detect.ts'
import { platform } from '/src/common/utilities/detect'

const currentPlatform = platform()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @file Actions for the second step of the "setup" page. */
import { PLAN_TO_UPGRADE_LABEL_ID } from '#/modules/payments/constants'
import { Plan } from 'enso-common/src/services/Backend'
import { Plan } from '@common/services/Backend'
import { TEXT } from '.'
import BaseActions from './BaseActions'
import SetupDonePageActions from './SetupDonePageActions'
Expand Down
12 changes: 6 additions & 6 deletions app/gui/integration-test/dashboard/actions/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/** @file The mock API. */
import * as test from '@playwright/test'

import * as backend from '#/services/Backend'
import * as backend from '@common/services/Backend'
import * as dateTime from '@common/utilities/data/dateTime'
import * as object from '@common/utilities/data/object'
import * as permissions from '@common/utilities/permissions'
import * as uniqueString from '@common/utilities/uniqueString'

import type * as remoteBackend from '#/services/RemoteBackend'
import * as remoteBackendPaths from '#/services/remoteBackendPaths'

import * as dateTime from '#/utilities/dateTime'
import * as object from '#/utilities/object'
import * as permissions from '#/utilities/permissions'
import * as uniqueString from 'enso-common/src/utilities/uniqueString'

import * as actions from '.'

import { readFileSync } from 'node:fs'
Expand Down
5 changes: 2 additions & 3 deletions app/gui/integration-test/dashboard/assetPanel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** @file Tests for the asset panel. */
import { expect, test, type Page } from '@playwright/test'

import { EmailAddress, UserId } from '#/services/Backend'

import { PermissionAction } from '#/utilities/permissions'
import { EmailAddress, UserId } from '@common/services/Backend'
import { PermissionAction } from '@common/utilities/permissions'

import { mockAllAndLogin } from './actions'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Test the search bar and its suggestions. */
import { expect, test, type Page } from '@playwright/test'

import { COLORS } from '#/services/Backend'
import { COLORS } from '@common/services/Backend'

import { mockAllAndLogin } from './actions'

Expand Down
2 changes: 1 addition & 1 deletion app/gui/integration-test/dashboard/contextMenus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Test the drive view. */
import { expect, test, type Page } from '@playwright/test'

import { COLORS } from 'enso-common/src/services/Backend'
import { COLORS } from '@common/services/Backend'
import { mockAllAndLogin } from './actions'

const LABEL_NAME = 'aaaa'
Expand Down
2 changes: 1 addition & 1 deletion app/gui/integration-test/dashboard/labels.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Test dragging of labels. */
import { expect, test, type Locator, type Page } from '@playwright/test'

import { COLORS } from '#/services/Backend'
import { COLORS } from '@common/services/Backend'

import { mockAllAndLogin } from './actions'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file Test the organization settings tab. */
import { expect, test } from '@playwright/test'

import { Plan } from 'enso-common/src/services/Backend'
import { Plan } from '@common/services/Backend'
import { mockAllAndLogin } from './actions'

const NEW_NAME = 'another organization-name'
Expand Down
Loading
Loading