mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-10 16:19:24 -07:00
Expand Yomitan external profile tilde paths to home directory
- Normalize `yomitan.externalProfilePath` so `~` and `~/...` resolve to the current user home directory - Add coverage for tilde expansion in integration config tests - Update Yomitan config docs and tighten settings opener test assertion
This commit is contained in:
@@ -1,6 +1,19 @@
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ResolveContext } from './context';
|
||||
import { asBoolean, asNumber, asString, isObject } from './shared';
|
||||
|
||||
function normalizeExternalProfilePath(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed === '~') {
|
||||
return os.homedir();
|
||||
}
|
||||
if (trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
||||
return path.join(os.homedir(), trimmed.slice(2));
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function applyIntegrationConfig(context: ResolveContext): void {
|
||||
const { src, resolved, warn } = context;
|
||||
|
||||
@@ -202,7 +215,7 @@ export function applyIntegrationConfig(context: ResolveContext): void {
|
||||
if (isObject(src.yomitan)) {
|
||||
const externalProfilePath = asString(src.yomitan.externalProfilePath);
|
||||
if (externalProfilePath !== undefined) {
|
||||
resolved.yomitan.externalProfilePath = externalProfilePath.trim();
|
||||
resolved.yomitan.externalProfilePath = normalizeExternalProfilePath(externalProfilePath);
|
||||
} else if (src.yomitan.externalProfilePath !== undefined) {
|
||||
warn(
|
||||
'yomitan.externalProfilePath',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as os from 'node:os';
|
||||
import { createResolveContext } from './context';
|
||||
import { applyIntegrationConfig } from './integrations';
|
||||
|
||||
@@ -127,3 +128,16 @@ test('yomitan externalProfilePath is trimmed and invalid values warn', () => {
|
||||
assert.equal(invalid.context.resolved.yomitan.externalProfilePath, '');
|
||||
assert.ok(invalid.warnings.some((warning) => warning.path === 'yomitan.externalProfilePath'));
|
||||
});
|
||||
|
||||
test('yomitan externalProfilePath expands leading tilde to the current home directory', () => {
|
||||
const homeDir = os.homedir();
|
||||
const { context } = createResolveContext({
|
||||
yomitan: {
|
||||
externalProfilePath: '~/.config/gsm_overlay',
|
||||
},
|
||||
});
|
||||
|
||||
applyIntegrationConfig(context);
|
||||
|
||||
assert.equal(context.resolved.yomitan.externalProfilePath, `${homeDir}/.config/gsm_overlay`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user