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

Platformatic 2 support and electron 30 [DON'T MERGE] #872

Draft
wants to merge 5 commits into
base: main
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
11,326 changes: 7,862 additions & 3,464 deletions package-lock.json

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.0.8",
"main": "./out/main/index.js",
"author": "Platformatic.dev",
"type": "module",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,53 +35,52 @@
"@electron-toolkit/preload": "^3.0.1",
"@electron-toolkit/utils": "^3.0.0",
"@fastify/error": "^4.0.0",
"@fastify/http-proxy": "^9.5.0",
"@platformatic/client": "^1.41.0",
"@platformatic/control": "^1.41.0",
"@platformatic/sql-mapper": "^1.41.0",
"@fastify/http-proxy": "^10.0.0",
"@platformatic/client": "^2.3.1",
"@platformatic/control": "^2.3.1",
"@platformatic/sql-mapper": "^2.3.1",
"@platformatic/ui-components": "^0.6.0",
"@scalar/api-reference-react": "^0.1.15",
"autoprefixer": "^10.4.19",
"autoprefixer": "^10.4.20",
"boring-name-generator": "^1.0.3",
"change-case-all": "^2.1.0",
"d3": "~7.9.0",
"electron-dl": "^3.5.2",
"electron-log": "^5.1.1",
"electron-updater": "^6.1.8",
"execa": "^5.1.1",
"electron-dl": "^4.0.0",
"electron-log": "^5.2.0",
"electron-updater": "^6.3.9",
"execa": "^9.4.0",
"mkdirp": "^3.0.1",
"npm-check-updates": "^17.0.0",
"pino": "^9.0.0",
"postgrator": "^7.2.0",
"npm-check-updates": "^17.1.3",
"pino": "^9.4.0",
"postgrator": "^7.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.0",
"react-router-dom": "^6.26.2",
"react-transition-group": "^4.4.5",
"split2": "^4.2.0",
"tailwindcss": "^3.3.6",
"undici": "^6.16.0",
"tailwindcss": "^3.4.13",
"undici": "^6.19.8",
"use-error-boundary": "^2.0.6",
"which": "^4.0.0",
"zustand": "^4.5.2"
"which": "^5.0.0",
"zustand": "^4.5.5"
},
"devDependencies": {
"@electron/rebuild": "^3.6.0",
"@testing-library/react": "^16.0.0",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.1",
"electron": "28.3.3",
"electron-builder": "^24.13.3",
"electron-vite": "^2.2.0",
"fastify": "^4.27.0",
"@electron/rebuild": "^3.6.2",
"@testing-library/react": "^16.0.1",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"electron": "30.5.0",
"electron-builder": "^25.1.7",
"electron-vite": "^2.3.0",
"fastify": "^5.0.0",
"glob": "^11.0.0",
"happy-dom": "^15.0.0",
"react": "^18.3.1",
"rimraf": "^6.0.0",
"rimraf": "^6.0.1",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"vite": "^5.0.0",
"vitest": "^1.6.0"
"standard": "^17.1.2",
"vite": "^5.4.8",
"vitest": "^2.1.2"
},
"optionalDependencies": {
"dmg-license": "^1.0.11"
Expand Down
5 changes: 3 additions & 2 deletions src/main/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getTemplates, getPlugins } from './client.mjs'
import { prepareFolder, createApp } from './generate.mjs'
import { autoCheckForUpdates } from './updater.mjs'
import log from 'electron-log'
import { download } from 'electron-dl'
import { getAppPath } from './lib/utils.mjs'
import Applications from './lib/applications.mjs'
import Logs from './lib/logs.mjs'
Expand Down Expand Up @@ -133,7 +132,7 @@ function createWindow () {
autoHideMenuBar: false,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/index.mjs'),
sandbox: false,
additionalArguments: [`--devMode=${devMode}`]
}
Expand Down Expand Up @@ -305,6 +304,8 @@ app.whenReady().then(async () => {
})

ipcMain.handle('get-all-logs', async (_, id) => {
// BEcause now it's a "PureESM package"
const { download } = await import('electron-dl')
if (!id) {
throw new Error('Application ID is required')
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/applications.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import execa from 'execa'
import { execa } from 'execa'
import { RuntimeApiClient } from '@platformatic/control'
import { access, rm } from 'node:fs/promises'
import { createRequire } from 'node:module'
Expand Down
6 changes: 6 additions & 0 deletions src/main/lib/inspect-app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ const loadServiceConfig = async (servicePath) => {
}

const getTemplate = (serviceConfig) => {
console.log('serviceConfig', serviceConfig.$schema)
// TODO: support both schemas
let template
if (serviceConfig?.$schema?.startsWith('https://platformatic.dev/schemas')) {
template = serviceConfig?.$schema?.split('/').slice(-1)
template = `@platformatic/${template}`
} else if (serviceConfig?.$schema?.startsWith('https://schemas.platformatic.dev')) {
template = serviceConfig?.$schema?.split('https://schemas.platformatic.dev/@platformatic/')[1]
template = template.split('/')[0]
template = `@platformatic/${template}`
} else {
template = serviceConfig?.module || serviceConfig?.extends
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/logs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Logs {
const fullLogStream = await this.#runtimeClient.getRuntimeAllLogsStream(pid)
return reply.send(fullLogStream)
})
await this.#logServer.listen(0) // TODO: We should use a unix socket for that
await this.#logServer.listen({ port: 0 }) // TODO: We should use a unix socket for that
}
const port = this.#logServer.server.address().port
return `http://localhost:${port}/logs/${id}`
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/run-npm.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import execa from 'execa'
import { execa } from 'execa'
import { app } from 'electron'
import split from 'split2'
import { dirname } from 'node:path'
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/runtime-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RuntimeProxy {
undici: client
})

await this.#runtimeProxy.listen(0)
await this.#runtimeProxy.listen({ port: 0 })
}
const port = this.#runtimeProxy.server.address().port
return `http://localhost:${port}`
Expand Down
2 changes: 1 addition & 1 deletion src/main/lib/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { access } from 'node:fs/promises'
import { request } from 'undici'
import { homedir } from 'node:os'
import log from 'electron-log'
import execa from 'execa'
import { execa } from 'execa'
import which from 'which'

const isMac = process.platform === 'darwin'
Expand Down
4 changes: 3 additions & 1 deletion src/main/updater.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { dialog } from 'electron'
import { autoUpdater } from 'electron-updater'
import pkg from 'electron-updater'
import log from 'electron-log'

const { autoUpdater } = pkg

let updater = null
autoUpdater.autoDownload = false
log.transports.console.level = 'info'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/main/applications.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolve, join } from 'node:path'
import { mkdirp } from 'mkdirp'
import Applications from '../../src/main/lib/applications.mjs'
import { startRuntimeInFolder } from './helper.mjs'
import execa from 'execa'
import { execa } from 'execa'

const { MockAgent, setGlobalDispatcher } = require('undici')

Expand Down
23 changes: 16 additions & 7 deletions test/main/client.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, onTestFinished } from 'vitest'
import { test, expect, onTestFinished, afterEach } from 'vitest'
import { startMarketplace, setUpEnvironment } from './helper.mjs'
import { mkdtemp, writeFile, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
Expand All @@ -7,6 +7,12 @@ import { mkdirp } from 'mkdirp'

setUpEnvironment()
const { getTemplates, getPlugins } = await import('../../src/main/client.mjs')
let marketplace
afterEach(async () => {
if (marketplace) {
await marketplace.close()
}
})

test('should invoke marketplace for stackables', async () => {
const platformaticDir = await mkdtemp(join(tmpdir(), 'plat-app-test-home'))
Expand All @@ -27,11 +33,12 @@ test('should invoke marketplace for stackables', async () => {
public: true
}
]
await startMarketplace({
getStackablesCallback: (request, reply) => {
const ret = await startMarketplace({
getStackablesCallback: (_request, reply) => {
reply.code(200).send(stacks)
}
})
marketplace = ret.marketplace
const stackables = await getTemplates()
expect(stackables).toEqual(stacks)
})
Expand Down Expand Up @@ -61,11 +68,12 @@ test('should invoke marketplace for stackables', async () => {
public: true
}
]
await startMarketplace({
getStackablesCallback: (request, reply) => {
const ret = await startMarketplace({
getStackablesCallback: (_request, reply) => {
reply.code(200).send(stacks)
}
})
marketplace = ret.marketplace
const stackables = await getTemplates()
expect(stackables).toEqual(stacks)
})
Expand Down Expand Up @@ -93,11 +101,12 @@ test('should invoke marketplace for stackables', async () => {
envVars: []
}
]
await startMarketplace({
getPluginsCallback: (request, reply) => {
const ret = await startMarketplace({
getPluginsCallback: (_, reply) => {
reply.code(200).send(plugs)
}
})
marketplace = ret.marketplace
const plugins = await getPlugins()
expect(plugins).toEqual(plugs)
})
5 changes: 3 additions & 2 deletions test/main/helper.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastify from 'fastify'
import execa from 'execa'
import { execa } from 'execa'
import { afterEach } from 'vitest'
import { access } from 'node:fs/promises'
import { createRequire } from 'node:module'
Expand Down Expand Up @@ -34,7 +34,8 @@ async function startMarketplace (options = {}) {
await marketplace.close()
})

return marketplace.listen({ port: 13042 })
const url = await marketplace.listen({ port: 13042 })
return { url, marketplace }
}

async function isFileAccessible (filename) {
Expand Down
15 changes: 12 additions & 3 deletions test/main/inspect-app.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, onTestFinished } from 'vitest'
import { test, expect, onTestFinished, afterEach } from 'vitest'
import { mkdtemp, cp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
Expand All @@ -10,6 +10,13 @@ const logger = {
info: console.log
}

let marketplace
afterEach(async () => {
if (marketplace) {
await marketplace.close()
}
})

// We need to setup env BEFORE importing the module
setUpEnvironment()
const { inspectApp } = await import('../../src/main/lib/inspect-app.mjs')
Expand Down Expand Up @@ -50,7 +57,7 @@ test('inspect runtime generated by meraki', async () => {
public: true
}
]
await startMarketplace({
const ret = await startMarketplace({
getPluginsCallback: (request, reply) => {
reply.code(200).send(plugs)
},
Expand All @@ -59,6 +66,7 @@ test('inspect runtime generated by meraki', async () => {
reply.code(200).send(stacks)
}
})
marketplace = ret.marketplace

const appDir = await mkdtemp(join(tmpdir(), 'plat-app-test'))
onTestFinished(() => rm(appDir, { recursive: true, force: true }))
Expand Down Expand Up @@ -281,7 +289,7 @@ test('inspect runtime generated by meraki', async () => {
}, 20000)

test('inspect runtime generated by meraki with stackable', async () => {
await startMarketplace({
const ret = await startMarketplace({
getPluginsCallback: (request, reply) => {
reply.code(200).send([])
},
Expand All @@ -290,6 +298,7 @@ test('inspect runtime generated by meraki with stackable', async () => {
reply.code(200).send([])
}
})
marketplace = ret.marketplace

const appDir = await mkdtemp(join(tmpdir(), 'plat-app-test'))
onTestFinished(() => rm(appDir, { recursive: true, force: true }))
Expand Down
2 changes: 1 addition & 1 deletion test/main/upgrade-plt.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mkdirp } from 'mkdirp'
import Applications from '../../src/main/lib/applications.mjs'
import { upgradePlt } from '../../src/main/lib/upgrade-plt.mjs'
import { cleanNpmVersion } from '../../src/main/lib/utils.mjs'
import execa from 'execa'
import { execa } from 'execa'

// Setup meraki app folder (for migrations) and config folder (for the DB)
const platformaticTestDir = await mkdtemp(join(tmpdir(), 'plat-app-test'))
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vite'
export default defineConfig({
test: {
globals: true,
environment: 'happy-dom',
environment: 'node',
exclude: ['node_modules']
}
})