Skip to content

Commit

Permalink
Allow downloading projects on GUI dev server (#9851)
Browse files Browse the repository at this point in the history
- Fixes #9482
- Add URL rewriting logic to `npm run dev` in `app/gui2/` so that "download" actions work

# Important Notes
- ⚠️ `config.yaml` HAS BEEN REMOVED in favor of `config.json`.
- Most of the keys have been removed as they were only used by GUI1.
- This is a REQUIRED change, because the vite dev server does not seem to like importing yaml files when running `vite.config.ts`.
  • Loading branch information
somebody1234 authored May 3, 2024
1 parent 6d605a5 commit 25d1007
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 57 deletions.
30 changes: 0 additions & 30 deletions app/gui2/config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion app/ide-desktop/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const NAME = 'enso'
* `yargs` is a modules we explicitly want the default imports of.
* `node:process` is here because `process.on` does not exist on the namespace import. */
const DEFAULT_IMPORT_ONLY_MODULES =
'@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|enso-assets.*|@modyfi\\u002Fvite-plugin-yaml|is-network-error|validator.+'
'@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|enso-assets.*|@modyfi\\u002Fvite-plugin-yaml|is-network-error|validator.+|.*[.]json$'
const OUR_MODULES = 'enso-.*'
const RELATIVE_MODULES =
'bin\\u002Fproject-manager|bin\\u002Fserver|config\\u002Fparser|authentication|config|debug|detect|file-associations|index|ipc|log|naming|paths|preload|project-management|security|url-associations|#\\u002F.*'
Expand Down
4 changes: 1 addition & 3 deletions app/ide-desktop/lib/client/src/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import type * as vite from 'vite'
import createServer from 'create-servers'

import * as common from 'enso-common'
import GLOBAL_CONFIG from 'enso-common/src/config.json' assert { type: 'json' }
import * as contentConfig from 'enso-content-config'
import * as ydocServer from 'enso-gui2/ydoc-server'

import * as paths from '../paths'

// prettier-ignore
import GLOBAL_CONFIG from '../../../../../gui2/config.yaml' assert { type: 'yaml' }

const logger = contentConfig.logger

// =================
Expand Down
4 changes: 1 addition & 3 deletions app/ide-desktop/lib/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as portfinder from 'portfinder'

import * as common from 'enso-common'
import * as buildUtils from 'enso-common/src/buildUtils'
import GLOBAL_CONFIG from 'enso-common/src/config.json' assert { type: 'json' }
import * as contentConfig from 'enso-content-config'

import * as authentication from 'authentication'
Expand All @@ -34,9 +35,6 @@ import * as security from 'security'
import * as server from 'bin/server'
import * as urlAssociations from 'url-associations'

// prettier-ignore
import GLOBAL_CONFIG from '../../../../gui2/config.yaml' assert { type: 'yaml' }

const logger = contentConfig.logger

if (process.env.ELECTRON_DEV_MODE === 'true' && process.env.NODE_MODULES_PATH != null) {
Expand Down
1 change: 1 addition & 0 deletions app/ide-desktop/lib/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./src/index.js",
"exports": {
".": "./src/index.js",
"./src/config.json": "./src/config.json",
"./src/appConfig": "./src/appConfig.js",
"./src/buildUtils": "./src/buildUtils.js",
"./src/detect": "./src/detect.ts",
Expand Down
4 changes: 4 additions & 0 deletions app/ide-desktop/lib/common/src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"projectManagerEndpoint": "ws://127.0.0.1:30535",
"projectManagerHttpEndpoint": "http://127.0.0.1:30535"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import * as fs from 'node:fs/promises'
import * as fsSync from 'node:fs'
import type * as http from 'node:http'
import * as http from 'node:http'
import * as os from 'node:os'
import * as path from 'node:path'

import * as tar from 'tar'
import * as yaml from 'yaml'

import * as common from 'enso-common'
import GLOBAL_CONFIG from '../../common/src/config.json' assert { type: 'json' }

import * as projectManagement from './projectManagement'

// =================
Expand Down Expand Up @@ -97,7 +99,37 @@ export default function projectManagerShimMiddleware(
) {
const requestUrl = request.url
const requestPath = requestUrl?.split('?')[0]?.split('#')[0]
if (request.method === 'POST') {
if (requestUrl != null && requestUrl.startsWith('/api/project-manager/')) {
const actualUrl = new URL(
requestUrl.replace(/^\/api\/project-manager/, GLOBAL_CONFIG.projectManagerHttpEndpoint)
)
request.pipe(
http.request(
// `...actualUrl` does NOT work because `URL` properties are not enumerable.
{
headers: request.headers,
host: actualUrl.host,
hostname: actualUrl.hostname,
method: request.method,
path: actualUrl.pathname,
port: actualUrl.port,
protocol: actualUrl.protocol,
},
actualResponse => {
response.writeHead(
// This is SAFE. The documentation says:
// Only valid for response obtained from ClientRequest.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
actualResponse.statusCode!,
actualResponse.statusMessage,
actualResponse.headers
)
actualResponse.pipe(response, { end: true })
}
),
{ end: true }
)
} else if (request.method === 'POST') {
switch (requestPath) {
case '/api/upload-file': {
const url = new URL(`https://example.com/${requestUrl}`)
Expand Down
2 changes: 1 addition & 1 deletion app/ide-desktop/lib/project-manager-shim/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"checkJs": false,
"skipLibCheck": false
},
"include": ["./src/"]
"include": ["./src/", "../common/src/config.json"]
}
17 changes: 0 additions & 17 deletions app/ide-desktop/lib/types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ declare module '*/build.json' {
export default BUILD_INFO
}

declare module '*/gui2/config.yaml' {
/** Content of the GUI config file. */
interface Config {
readonly windowAppScopeName: string
readonly windowAppScopeConfigName: string
readonly windowAppScopeThemeName: string
readonly projectManagerEndpoint: string
readonly projectManagerHttpEndpoint: string
readonly minimumSupportedVersion: string
readonly engineVersionSupported: string
readonly languageEditionSupported: string
}

const DATA: Config
export default DATA
}

declare module '@eslint/js' {
/** A set of configurations. */
export interface Config {
Expand Down

0 comments on commit 25d1007

Please sign in to comment.