diff --git a/src/localImports/preprocessor.ts b/src/localImports/preprocessor.ts index d4f6464c1..40a1d7e9e 100644 --- a/src/localImports/preprocessor.ts +++ b/src/localImports/preprocessor.ts @@ -1,5 +1,5 @@ import es from 'estree' -import * as path from 'path' +import * as posixPath from 'path/posix' import { CannotFindModuleError, CircularImportError } from '../errors/localImportErrors' import { parse } from '../parser/parser' @@ -39,11 +39,11 @@ export const getImportedLocalModulePaths = ( program: es.Program, currentFilePath: string ): Set => { - if (!path.isAbsolute(currentFilePath)) { + if (!posixPath.isAbsolute(currentFilePath)) { throw new Error(`Current file path '${currentFilePath}' is not absolute.`) } - const baseFilePath = path.resolve(currentFilePath, '..') + const baseFilePath = posixPath.resolve(currentFilePath, '..') const importedLocalModuleNames: Set = new Set() const importDeclarations = program.body.filter(isImportDeclaration) importDeclarations.forEach((importDeclaration: es.ImportDeclaration): void => { @@ -52,7 +52,7 @@ export const getImportedLocalModulePaths = ( throw new Error('Module names must be strings.') } if (!isSourceModule(modulePath)) { - const absoluteModulePath = path.resolve(baseFilePath, modulePath) + const absoluteModulePath = posixPath.resolve(baseFilePath, modulePath) importedLocalModuleNames.add(absoluteModulePath) } }) @@ -192,7 +192,7 @@ const preprocessFileImports = ( // We want to operate on the entrypoint program to get the eventual // preprocessed program. const entrypointProgram = programs[entrypointFilePath] - const entrypointDirPath = path.resolve(entrypointFilePath, '..') + const entrypointDirPath = posixPath.resolve(entrypointFilePath, '..') // Create variables to hold the imported statements. const entrypointProgramModuleDeclarations = entrypointProgram.body.filter(isModuleDeclaration) diff --git a/src/localImports/transformers/transformProgramToFunctionDeclaration.ts b/src/localImports/transformers/transformProgramToFunctionDeclaration.ts index 98a179106..870d0aa98 100644 --- a/src/localImports/transformers/transformProgramToFunctionDeclaration.ts +++ b/src/localImports/transformers/transformProgramToFunctionDeclaration.ts @@ -1,5 +1,5 @@ import es from 'estree' -import * as path from 'path' +import * as posixPath from 'path/posix' import { defaultExportLookupName } from '../../stdlib/localImport.prelude' import { @@ -50,7 +50,7 @@ export const getInvokedFunctionResultVariableNameToImportSpecifiersMap = ( // current file path to get the absolute file path of the file to // be imported. Since the absolute file path is guaranteed to be // unique, it is also the canonical file path. - const importFilePath = path.resolve(currentDirPath, importSource) + const importFilePath = posixPath.resolve(currentDirPath, importSource) // Even though we limit the chars that can appear in Source file // paths, some chars in file paths (such as '/') cannot be used // in function names. As such, we substitute illegal chars with @@ -287,7 +287,7 @@ export const transformProgramToFunctionDeclaration = ( currentFilePath: string ): es.FunctionDeclaration => { const moduleDeclarations = program.body.filter(isModuleDeclaration) - const currentDirPath = path.resolve(currentFilePath, '..') + const currentDirPath = posixPath.resolve(currentFilePath, '..') // Create variables to hold the imported statements. const invokedFunctionResultVariableNameToImportSpecifiersMap =