From 9160b52d5b54d9f981c57e0c98bd8fb93893df33 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Thu, 14 Jan 2021 16:07:17 +0100 Subject: [PATCH] refactor: Remove toSystemFilePath --- src/init/CliRunner.ts | 6 +++--- src/util/PathUtil.ts | 13 +------------ test/integration/Config.ts | 4 ++-- test/unit/init/CliRunner.test.ts | 14 +++++++------- test/unit/util/PathUtil.test.ts | 8 -------- 5 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/init/CliRunner.ts b/src/init/CliRunner.ts index 89cb1b7d6..5a6ef6c1f 100644 --- a/src/init/CliRunner.ts +++ b/src/init/CliRunner.ts @@ -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 = { - 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 => initializer.handleSafe(), (error: Error): void => { diff --git a/src/util/PathUtil.ts b/src/util/PathUtil.ts index 57e8e7d39..41f182e19 100644 --- a/src/util/PathUtil.ts +++ b/src/util/PathUtil.ts @@ -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. diff --git a/test/integration/Config.ts b/test/integration/Config.ts index 3d967800f..ff9082b32 100644 --- a/test/integration/Config.ts +++ b/test/integration/Config.ts @@ -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 }); } diff --git a/test/unit/init/CliRunner.test.ts b/test/unit/init/CliRunner.test.ts index 121eb5acf..19cc805e0 100644 --- a/test/unit/init/CliRunner.test.ts +++ b/test/unit/init/CliRunner.test.ts @@ -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 = { 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', { diff --git a/test/unit/util/PathUtil.test.ts b/test/unit/util/PathUtil.test.ts index abd2f04fb..2e9b482fb 100644 --- a/test/unit/util/PathUtil.test.ts +++ b/test/unit/util/PathUtil.test.ts @@ -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 => { - 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 => { expect(ensureTrailingSlash('http://test.com')).toEqual('http://test.com/');