From dbcd6ba575449eaa50bdf4487304de2bd26a024e Mon Sep 17 00:00:00 2001 From: Andy Brenneke Date: Wed, 18 Oct 2023 10:31:57 -0700 Subject: [PATCH] Fix node executor loading plugins on windows & linux --- packages/app-executor/bin/executor.mts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/app-executor/bin/executor.mts b/packages/app-executor/bin/executor.mts index 331df5c74..cec9889cd 100644 --- a/packages/app-executor/bin/executor.mts +++ b/packages/app-executor/bin/executor.mts @@ -12,12 +12,28 @@ import { type RivetPluginInitializer } from '@ironclad/rivet-core'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { P, match } from 'ts-pattern'; -import { getAppDataPath } from 'appdata-path'; import { join } from 'node:path'; import { access, readFile } from 'node:fs/promises'; +import { platform, homedir } from 'node:os'; const datasetProvider = new DebuggerDatasetProvider(); +// Roughly https://github.com/demurgos/appdata-path/blob/master/lib/index.js but appdata local and .local/share, try to match `dirs` from rust +function getAppDataLocalPath() { + const identifier = 'com.ironcladapp.rivet'; + return match(platform()) + .with('win32', () => join(homedir(), 'AppData', 'Local', identifier)) + .with('darwin', () => join(homedir(), 'Library', 'Application Support', identifier)) + .with('linux', () => join(homedir(), '.local', 'share', identifier)) + .otherwise(() => { + if (platform().startsWith('win')) { + return join(homedir(), 'AppData', 'Local', identifier); + } else { + return join(homedir(), '.local', 'share', identifier); + } + }); +} + const { port } = yargs(hideBin(process.argv)) .option('port', { alias: 'p', @@ -70,7 +86,7 @@ const rivetDebugger = startDebuggerServer({ registry.registerPlugin(initializedPlugin); }) .with({ type: 'package' }, async (spec) => { - const localDataDir = getAppDataPath('com.ironcladapp.rivet'); + const localDataDir = getAppDataLocalPath(); const pluginDir = join(localDataDir, `plugins/${spec.package}-${spec.tag}/package`); const packageJsonPath = join(pluginDir, 'package.json');