From 1c538acd8057b5a61231da6ba87b7d349816a03c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 5 Dec 2023 10:21:33 +0100 Subject: [PATCH] script runner --- .../src/app/files/electronProvider.ts | 4 +- apps/remix-ide/src/app/panels/file-panel.js | 12 +++- apps/remix-ide/src/index.tsx | 16 ----- apps/remix-ide/src/remixAppManager.js | 1 - apps/remixdesktop/src/plugins/fsPlugin.ts | 4 +- .../remixdesktop/src/plugins/ripgrepPlugin.ts | 65 +++++++++---------- apps/remixdesktop/src/plugins/scriptRunner.ts | 3 +- .../workspace/src/lib/actions/events.ts | 12 ++++ .../workspace/src/lib/actions/workspace.ts | 7 +- .../src/lib/providers/FileSystemProvider.tsx | 4 ++ .../workspace/src/lib/reducers/workspace.ts | 8 --- .../remix-ui/workspace/src/lib/types/index.ts | 1 + 12 files changed, 70 insertions(+), 67 deletions(-) diff --git a/apps/remix-ide/src/app/files/electronProvider.ts b/apps/remix-ide/src/app/files/electronProvider.ts index 8d7ca10769..27d15d99a0 100644 --- a/apps/remix-ide/src/app/files/electronProvider.ts +++ b/apps/remix-ide/src/app/files/electronProvider.ts @@ -16,7 +16,8 @@ export class ElectronProvider extends FileProvider { } async init() { - this._appManager.on('fs', 'change', (event, path) => { + this._appManager.on('fs', 'change', async (event, path) => { + console.log('change', event, path) switch (event) { case 'add': this.event.emit('fileAdded', path) @@ -74,7 +75,6 @@ export class ElectronProvider extends FileProvider { * @param {*} path is the folder to be removed */ async remove(path: string) { - console.log('remove', path) try { await window.remixFileSystem.rmdir(path) return true diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 247a1ed57f..112847fe1c 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -43,7 +43,8 @@ const profile = { 'renameWorkspace', 'deleteWorkspace', 'loadTemplate', - 'clone' + 'clone', + 'isExpanded', ], events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'], icon: 'assets/img/fileManager.webp', @@ -72,6 +73,8 @@ module.exports = class Filepanel extends ViewPlugin { this.workspaces = [] this.appManager = appManager this.currentWorkspaceMetadata = null + + this.expandPath = [] } render() { @@ -229,5 +232,12 @@ module.exports = class Filepanel extends ViewPlugin { workspaceCreated(workspace) { this.emit('workspaceCreated', workspace) } + + isExpanded(path) { + console.log('isExpanded', path, this.expandPath) + if(path === '/') return true + return this.expandPath.includes(path) + } + /** end section */ } diff --git a/apps/remix-ide/src/index.tsx b/apps/remix-ide/src/index.tsx index 015b9a53f4..87289f144e 100644 --- a/apps/remix-ide/src/index.tsx +++ b/apps/remix-ide/src/index.tsx @@ -8,10 +8,6 @@ import Config from './config' import {Registry} from '@remix-project/remix-lib' import {Storage} from '@remix-project/remix-lib' -import * as esbuild from 'esbuild-wasm' - - - ;(async function () { try { @@ -21,18 +17,6 @@ import * as esbuild from 'esbuild-wasm' } catch (e) {} const theme = new ThemeModule() theme.initTheme() - - await esbuild.initialize({ - wasmURL: './assets/esbuild.wasm', - }) - - const code = `import { ethers } from 'ethers'` - - const result = await esbuild.transform(code, {}) - await esbuild.build({ - - }) - console.log(result) render( diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index b44b2c5800..6dd9e9428a 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -237,7 +237,6 @@ export class RemixAppManager extends PluginManager { const res = await fetch(this.pluginsDirectory) plugins = await res.json() plugins = plugins.filter((plugin) => { - if(plugin.name === 'scriptRunner') return false if (plugin.targets && Array.isArray(plugin.targets) && plugin.targets.length > 0) { return plugin.targets.includes('remix') } diff --git a/apps/remixdesktop/src/plugins/fsPlugin.ts b/apps/remixdesktop/src/plugins/fsPlugin.ts index 08c23153df..11695633d7 100644 --- a/apps/remixdesktop/src/plugins/fsPlugin.ts +++ b/apps/remixdesktop/src/plugins/fsPlugin.ts @@ -108,6 +108,7 @@ class FSPluginClient extends ElectronBasePluginClient { // best for non recursive async readdir(path: string): Promise { + if (this.workingDir === '') throw new Error('workingDir is not set') // call node fs.readdir if (!path) return [] const startTime = Date.now() @@ -203,7 +204,6 @@ class FSPluginClient extends ElectronBasePluginClient { ignorePermissionErrors: true, ignoreInitial: true, ignored: [ - '**/node_modules/**', '**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows ], }) @@ -211,7 +211,7 @@ class FSPluginClient extends ElectronBasePluginClient { let pathWithoutPrefix = path.replace(this.workingDir, '') pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1) - + console.log('eventName', eventName, pathWithoutPrefix) if (eventName === 'change') { // remove workingDir from path const newContent = await fs.readFile(path, 'utf-8') diff --git a/apps/remixdesktop/src/plugins/ripgrepPlugin.ts b/apps/remixdesktop/src/plugins/ripgrepPlugin.ts index 426f5a00f9..c017d08f67 100644 --- a/apps/remixdesktop/src/plugins/ripgrepPlugin.ts +++ b/apps/remixdesktop/src/plugins/ripgrepPlugin.ts @@ -1,9 +1,6 @@ import {PluginClient} from '@remixproject/plugin' import {Profile} from '@remixproject/plugin-utils' -import { - ElectronBasePlugin, - ElectronBasePluginClient, -} from '@remixproject/plugin-electron' +import {ElectronBasePlugin, ElectronBasePluginClient} from '@remixproject/plugin-electron' import path from 'path' import {rgPath} from '@vscode/ripgrep' import byline from 'byline' @@ -47,42 +44,42 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { } async glob(path: string, pattern: string, options?: any) { - path = convertPathToPosix(this.fixPath(path)) + try { + const fixedPath = this.fixPath(path) + path = convertPathToPosix(fixedPath) - return new Promise((c, e) => { - // replace packed app path with unpacked app path for release on windows + return new Promise((c, e) => { + // replace packed app path with unpacked app path for release on windows - const customRgPath = rgPath.includes('app.asar.unpacked') - ? rgPath - : rgPath.replace('app.asar', 'app.asar.unpacked') - const rg = spawn(customRgPath, ['.', '-l', path]) + const customRgPath = rgPath.includes('app.asar.unpacked') ? rgPath : rgPath.replace('app.asar', 'app.asar.unpacked') + const rg = spawn(customRgPath, ['.', '-l', path]) - const resultrg: any[] = [] + const resultrg: any[] = [] - const stream = byline(rg.stdout.setEncoding('utf8')) - stream.on('data', (rgresult: string) => { - let pathWithoutWorkingDir = rgresult.replace( - convertPathToPosix(this.workingDir), - '' - ) - if (pathWithoutWorkingDir.endsWith('/')) { - pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) - } - if (pathWithoutWorkingDir.startsWith('/')) { - pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) - } - if (pathWithoutWorkingDir.startsWith('\\')) { - pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) - } - resultrg.push({ - path: convertPathToPosix(pathWithoutWorkingDir), - isDirectory: false, + const stream = byline(rg.stdout.setEncoding('utf8')) + stream.on('data', (rgresult: string) => { + let pathWithoutWorkingDir = rgresult.replace(convertPathToPosix(this.workingDir), '') + if (pathWithoutWorkingDir.endsWith('/')) { + pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) + } + if (pathWithoutWorkingDir.startsWith('/')) { + pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) + } + if (pathWithoutWorkingDir.startsWith('\\')) { + pathWithoutWorkingDir = pathWithoutWorkingDir.slice(1) + } + resultrg.push({ + path: convertPathToPosix(pathWithoutWorkingDir), + isDirectory: false, + }) + }) + stream.on('end', () => { + c(resultrg) }) }) - stream.on('end', () => { - c(resultrg) - }) - }) + } catch (e) { + return [] + } } fixPath(path: string): string { diff --git a/apps/remixdesktop/src/plugins/scriptRunner.ts b/apps/remixdesktop/src/plugins/scriptRunner.ts index d4c71ee52f..e2c019a985 100644 --- a/apps/remixdesktop/src/plugins/scriptRunner.ts +++ b/apps/remixdesktop/src/plugins/scriptRunner.ts @@ -132,7 +132,8 @@ class ScriptRunnerClient extends ElectronBasePluginClient { bundle: true, outdir: out, plugins: [], - platform: 'node' + platform: 'node', + inject: ['/Volumes/bunsen/code/basic6/remix.ts'] }) console.log('build', build) if (build.errors.length > 0) { diff --git a/libs/remix-ui/workspace/src/lib/actions/events.ts b/libs/remix-ui/workspace/src/lib/actions/events.ts index e3b083403a..ec0a048e0a 100644 --- a/libs/remix-ui/workspace/src/lib/actions/events.ts +++ b/libs/remix-ui/workspace/src/lib/actions/events.ts @@ -175,6 +175,12 @@ const removePluginActions = (plugin, cb: (err: Error, result?: string | number | } const fileAdded = async (filePath: string) => { + const path = extractParentFromKey(filePath) || ROOT_PATH + console.log('fileAdded', filePath, path) + const isExpanded = await plugin.call('filePanel', 'isExpanded', path) + + if(!isExpanded) return + await dispatch(fileAddedSuccess(filePath)) if (filePath.includes('_test.sol')) { plugin.emit('newTestFileCreated', filePath) @@ -185,6 +191,12 @@ const folderAdded = async (folderPath: string) => { const provider = plugin.fileManager.currentFileProvider() const path = extractParentFromKey(folderPath) || ROOT_PATH + const isExpanded = await plugin.call('filePanel', 'isExpanded', path) + + console.log('folderAdded', folderPath, path, isExpanded) + + if(!isExpanded) return + const promise: Promise = new Promise((resolve) => { provider.resolveDirectory(path, (error, fileTree: FileTree) => { if (error) console.error(error) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 9b2baf385a..43a4cb0ab4 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -350,9 +350,12 @@ export const fetchWorkspaceDirectory = async (path: string) => { if (!path) return const provider = plugin.fileManager.currentFileProvider() - const promise: Promise = new Promise((resolve) => { + const promise: Promise = new Promise((resolve, reject) => { provider.resolveDirectory(path, (error, fileTree: FileTree) => { - if (error) console.error(error) + if (error) { + reject(error) + console.error(error) + } resolve(fileTree) }) }) diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 1af9292e13..50e74f26df 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -287,6 +287,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => { } }, [fs.popup]) + useEffect(() => { + plugin.expandPath = fs.browser.expandPath + },[fs.browser.expandPath]) + const handleHideModal = () => { setFocusModal((modal) => { return {...modal, hide: true, message: null} diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 8e4e6bad76..05583089f3 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -326,10 +326,6 @@ export const browserReducer = (state = browserInitialState, action: Actions) => state.mode === 'browser' ? fileAdded(state, payload) : state.browser.files, - expandPath: - state.mode === 'browser' - ? [...new Set([...state.browser.expandPath, payload])] - : state.browser.expandPath }, localhost: { ...state.localhost, @@ -356,10 +352,6 @@ export const browserReducer = (state = browserInitialState, action: Actions) => state.mode === 'browser' ? fetchDirectoryContent(state, payload) : state.browser.files, - expandPath: - state.mode === 'browser' - ? [...new Set([...state.browser.expandPath, payload.folderPath])] - : state.browser.expandPath }, localhost: { ...state.localhost, diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 4feb5c88e3..406af5dc15 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -74,6 +74,7 @@ export interface FilePanelType extends ViewPlugin { initialWorkspace: string resetNewFile: () => void getWorkspaces: () => string[] + expandPath: string[] } /* eslint-disable-next-line */