Skip to content

Commit b0261ef

Browse files
authored
chore: update default repo-dir (#1335)
* chore: update default repo-dir * chore: engine multi different repo * chore: update changelog * feat: update default repo path
1 parent f12d7f2 commit b0261ef

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

.changeset/gentle-goats-poke.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@openfn/engine-multi': minor
3+
'@openfn/runtime': minor
4+
'@openfn/cli': minor
5+
---
6+
7+
Update default repo directory to be relative to homedir

packages/cli/src/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cli/src/options.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import nodePath from 'node:path';
22
import yargs from 'yargs';
33

44
import type { CommandList } from './commands';
5-
import { DEFAULT_REPO_DIR } from './constants';
65
import {
76
expandAdaptors as doExpandAdaptors,
87
ensureLogOpts,
98
LogLevel,
109
} from './util';
1110
import { existsSync } from 'node:fs';
11+
import { defaultRepoPath } from '@openfn/runtime';
1212

1313
// Central type definition for the main options
1414
// This represents the types coming out of yargs,
@@ -490,20 +490,8 @@ export const repoDir: CLIOption = {
490490
name: 'repo-dir',
491491
yargs: () => ({
492492
description: 'Provide a path to the repo root dir',
493-
default: process.env.OPENFN_REPO_DIR || DEFAULT_REPO_DIR,
493+
default: process.env.OPENFN_REPO_DIR || defaultRepoPath,
494494
}),
495-
ensure: (opts) => {
496-
if (opts.repoDir === DEFAULT_REPO_DIR) {
497-
// Note that we don't use the logger here - it's not been created yet
498-
console.warn(
499-
'WARNING: no repo module dir found! Using the default (/tmp/repo)'
500-
);
501-
console.warn(
502-
'You should set OPENFN_REPO_DIR or pass --repoDir=some/path in to the CLI'
503-
);
504-
console.log();
505-
}
506-
},
507495
};
508496

509497
export const start: CLIOption = {

packages/cli/test/options/repo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import yargs from 'yargs';
44
import { repo } from '../../src/repo/command';
55

66
import type { Opts } from '../../src/options';
7-
import { DEFAULT_REPO_DIR } from '../../src/constants';
7+
import { defaultRepoPath } from '@openfn/runtime';
88

99
// Build the repo command and test the options it returns
1010
// Note that this will re-parse the command each time, so env vars will be re-calculated
@@ -17,7 +17,7 @@ test('repoDir: use the built-in default if no env var', (t) => {
1717

1818
const options = parse('repo');
1919

20-
t.is(options.repoDir, DEFAULT_REPO_DIR);
20+
t.is(options.repoDir, defaultRepoPath);
2121
process.env.OPENFN_REPO_DIR = dir;
2222
});
2323

packages/engine-multi/src/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Creates the public/external API to the runtime
22
// Basically a thin wrapper, with validation, around the engine
33

4+
import path from 'node:path';
5+
import os from 'node:os';
46
import createLogger from '@openfn/logger';
57

68
import whitelist from './whitelist';
@@ -23,7 +25,7 @@ export type LazyResolvers = {
2325

2426
export type APIOptions = Partial<Omit<EngineOptions, 'whitelist'>>;
2527

26-
const DEFAULT_REPO_DIR = '/tmp/openfn/worker/repo';
28+
const DEFAULT_REPO_DIR = path.join(os.homedir(), '.openfn/worker/repo');
2729

2830
const DEFAULT_MEMORY_LIMIT = 500;
2931

@@ -38,7 +40,6 @@ const createAPI = async function (
3840

3941
if (!repoDir) {
4042
repoDir = DEFAULT_REPO_DIR;
41-
logger.warn('Using default repo directory: ', DEFAULT_REPO_DIR);
4243
}
4344
logger.info('repoDir set to ', repoDir);
4445

packages/runtime/src/modules/repo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from 'node:path';
22
import { readFile, writeFile, mkdir } from 'node:fs/promises';
33
import { defaultLogger, Logger } from '@openfn/logger';
44
import exec from '../util/exec';
5+
import * as os from 'node:os';
6+
const homeDir = os.homedir();
57

68
const defaultPkg = {
79
name: 'openfn-repo',
@@ -12,7 +14,7 @@ const defaultPkg = {
1214
dependencies: {},
1315
};
1416

15-
export const defaultRepoPath = '/tmp/openfn/repo';
17+
export const defaultRepoPath = path.join(homeDir, './openfn/repo/cli');
1618

1719
type InstallList = Array<{ name: string; version: string }>;
1820

0 commit comments

Comments
 (0)