mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Remove toSystemFilePath
This commit is contained in:
parent
5bb7822dc7
commit
9160b52d5b
@ -5,7 +5,7 @@ import type { IComponentsManagerBuilderOptions, LogLevel } from 'componentsjs';
|
||||
import { ComponentsManager } from 'componentsjs';
|
||||
import yargs from 'yargs';
|
||||
import { getLoggerFor } from '../logging/LogUtil';
|
||||
import { joinFilePath, toSystemFilePath, ensureTrailingSlash } from '../util/PathUtil';
|
||||
import { joinFilePath, ensureTrailingSlash } from '../util/PathUtil';
|
||||
import type { Initializer } from './Initializer';
|
||||
|
||||
export class CliRunner {
|
||||
@ -42,7 +42,7 @@ export class CliRunner {
|
||||
|
||||
// Gather settings for instantiating the server
|
||||
const loaderProperties: IComponentsManagerBuilderOptions<Initializer> = {
|
||||
mainModulePath: toSystemFilePath(this.resolveFilePath(params.mainModulePath)),
|
||||
mainModulePath: this.resolveFilePath(params.mainModulePath),
|
||||
dumpErrorState: true,
|
||||
logLevel: params.loggingLevel as LogLevel,
|
||||
};
|
||||
@ -50,7 +50,7 @@ export class CliRunner {
|
||||
const variables = this.createVariables(params);
|
||||
|
||||
// Create and execute the server initializer
|
||||
this.createInitializer(loaderProperties, toSystemFilePath(configFile), variables)
|
||||
this.createInitializer(loaderProperties, configFile, variables)
|
||||
.then(
|
||||
async(initializer): Promise<void> => initializer.handleSafe(),
|
||||
(error: Error): void => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import platform, { posix } from 'path';
|
||||
import { posix } from 'path';
|
||||
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
|
||||
/**
|
||||
@ -35,17 +35,6 @@ export function joinFilePath(basePath: string, ...paths: string[]): string {
|
||||
return posix.join(windowsToPosixPath(basePath), ...paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the path into an OS-dependent path.
|
||||
*
|
||||
* @param path - Path to check (POSIX).
|
||||
*
|
||||
* @returns The potentially changed path (OS-dependent).
|
||||
*/
|
||||
export function toSystemFilePath(path: string): string {
|
||||
return platform.normalize(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the input path has exactly 1 slash at the end.
|
||||
* Multiple slashes will get merged into one.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { mkdirSync } from 'fs';
|
||||
import { ComponentsManager } from 'componentsjs';
|
||||
import * as rimraf from 'rimraf';
|
||||
import { joinFilePath, toSystemFilePath } from '../../src/util/PathUtil';
|
||||
import { joinFilePath } from '../../src/util/PathUtil';
|
||||
|
||||
export const BASE = 'http://test.com';
|
||||
|
||||
@ -15,7 +15,7 @@ export async function instantiateFromConfig(componentUrl: string, configFile: st
|
||||
const manager = await ComponentsManager.build({ mainModulePath, logLevel: 'error' });
|
||||
|
||||
// Instantiate the component from the config
|
||||
const configPath = toSystemFilePath(joinFilePath(__dirname, 'config', configFile));
|
||||
const configPath = joinFilePath(__dirname, 'config', configFile);
|
||||
await manager.configRegistry.register(configPath);
|
||||
return await manager.instantiate(componentUrl, { variables });
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ComponentsManager } from 'componentsjs';
|
||||
import { CliRunner } from '../../../src/init/CliRunner';
|
||||
import type { Initializer } from '../../../src/init/Initializer';
|
||||
import { joinFilePath, toSystemFilePath } from '../../../src/util/PathUtil';
|
||||
import { joinFilePath } from '../../../src/util/PathUtil';
|
||||
|
||||
const initializer: jest.Mocked<Initializer> = {
|
||||
handleSafe: jest.fn(),
|
||||
@ -44,11 +44,11 @@ describe('CliRunner', (): void => {
|
||||
expect(ComponentsManager.build).toHaveBeenCalledWith({
|
||||
dumpErrorState: true,
|
||||
logLevel: 'info',
|
||||
mainModulePath: toSystemFilePath(joinFilePath(__dirname, '../../../')),
|
||||
mainModulePath: joinFilePath(__dirname, '../../../'),
|
||||
});
|
||||
expect(manager.configRegistry.register).toHaveBeenCalledTimes(1);
|
||||
expect(manager.configRegistry.register)
|
||||
.toHaveBeenCalledWith(toSystemFilePath(joinFilePath(__dirname, '/../../../config/config-default.json')));
|
||||
.toHaveBeenCalledWith(joinFilePath(__dirname, '/../../../config/config-default.json'));
|
||||
expect(manager.instantiate).toHaveBeenCalledTimes(1);
|
||||
expect(manager.instantiate).toHaveBeenCalledWith(
|
||||
'urn:solid-server:default:Initializer',
|
||||
@ -91,11 +91,11 @@ describe('CliRunner', (): void => {
|
||||
expect(ComponentsManager.build).toHaveBeenCalledWith({
|
||||
dumpErrorState: true,
|
||||
logLevel: 'debug',
|
||||
mainModulePath: toSystemFilePath('/var/cwd/module/path'),
|
||||
mainModulePath: '/var/cwd/module/path',
|
||||
});
|
||||
expect(manager.configRegistry.register).toHaveBeenCalledTimes(1);
|
||||
expect(manager.configRegistry.register)
|
||||
.toHaveBeenCalledWith(toSystemFilePath('/var/cwd/myconfig.json'));
|
||||
.toHaveBeenCalledWith('/var/cwd/myconfig.json');
|
||||
expect(manager.instantiate).toHaveBeenCalledWith(
|
||||
'urn:solid-server:default:Initializer',
|
||||
{
|
||||
@ -135,11 +135,11 @@ describe('CliRunner', (): void => {
|
||||
expect(ComponentsManager.build).toHaveBeenCalledWith({
|
||||
dumpErrorState: true,
|
||||
logLevel: 'debug',
|
||||
mainModulePath: toSystemFilePath('/var/cwd/module/path'),
|
||||
mainModulePath: '/var/cwd/module/path',
|
||||
});
|
||||
expect(manager.configRegistry.register).toHaveBeenCalledTimes(1);
|
||||
expect(manager.configRegistry.register)
|
||||
.toHaveBeenCalledWith(toSystemFilePath('/var/cwd/myconfig.json'));
|
||||
.toHaveBeenCalledWith('/var/cwd/myconfig.json');
|
||||
expect(manager.instantiate).toHaveBeenCalledWith(
|
||||
'urn:solid-server:default:Initializer',
|
||||
{
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { sep } from 'path';
|
||||
import {
|
||||
decodeUriPathComponents,
|
||||
encodeUriPathComponents,
|
||||
@ -6,7 +5,6 @@ import {
|
||||
joinFilePath,
|
||||
normalizeFilePath,
|
||||
toCanonicalUriPath,
|
||||
toSystemFilePath,
|
||||
} from '../../../src/util/PathUtil';
|
||||
|
||||
describe('PathUtil', (): void => {
|
||||
@ -30,12 +28,6 @@ describe('PathUtil', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('toSystemFilePath', (): void => {
|
||||
it('converts a POSIX path to an OS-specific path.', async(): Promise<void> => {
|
||||
expect(toSystemFilePath('c:/foo/bar/')).toEqual(`c:${sep}foo${sep}bar${sep}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ensureTrailingSlash', (): void => {
|
||||
it('makes sure there is always exactly 1 slash.', async(): Promise<void> => {
|
||||
expect(ensureTrailingSlash('http://test.com')).toEqual('http://test.com/');
|
||||
|
Loading…
x
Reference in New Issue
Block a user