Skip to content

Commit 130a030

Browse files
authored
Use POSIX paths on Windows systems (#1470)
1 parent 1d99116 commit 130a030

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/localImports/preprocessor.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import es from 'estree'
2-
import * as path from 'path'
2+
import * as posixPath from 'path/posix'
33

44
import { CannotFindModuleError, CircularImportError } from '../errors/localImportErrors'
55
import { parse } from '../parser/parser'
@@ -39,11 +39,11 @@ export const getImportedLocalModulePaths = (
3939
program: es.Program,
4040
currentFilePath: string
4141
): Set<string> => {
42-
if (!path.isAbsolute(currentFilePath)) {
42+
if (!posixPath.isAbsolute(currentFilePath)) {
4343
throw new Error(`Current file path '${currentFilePath}' is not absolute.`)
4444
}
4545

46-
const baseFilePath = path.resolve(currentFilePath, '..')
46+
const baseFilePath = posixPath.resolve(currentFilePath, '..')
4747
const importedLocalModuleNames: Set<string> = new Set()
4848
const importDeclarations = program.body.filter(isImportDeclaration)
4949
importDeclarations.forEach((importDeclaration: es.ImportDeclaration): void => {
@@ -52,7 +52,7 @@ export const getImportedLocalModulePaths = (
5252
throw new Error('Module names must be strings.')
5353
}
5454
if (!isSourceModule(modulePath)) {
55-
const absoluteModulePath = path.resolve(baseFilePath, modulePath)
55+
const absoluteModulePath = posixPath.resolve(baseFilePath, modulePath)
5656
importedLocalModuleNames.add(absoluteModulePath)
5757
}
5858
})
@@ -192,7 +192,7 @@ const preprocessFileImports = (
192192
// We want to operate on the entrypoint program to get the eventual
193193
// preprocessed program.
194194
const entrypointProgram = programs[entrypointFilePath]
195-
const entrypointDirPath = path.resolve(entrypointFilePath, '..')
195+
const entrypointDirPath = posixPath.resolve(entrypointFilePath, '..')
196196

197197
// Create variables to hold the imported statements.
198198
const entrypointProgramModuleDeclarations = entrypointProgram.body.filter(isModuleDeclaration)

src/localImports/transformers/transformProgramToFunctionDeclaration.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import es from 'estree'
2-
import * as path from 'path'
2+
import * as posixPath from 'path/posix'
33

44
import { defaultExportLookupName } from '../../stdlib/localImport.prelude'
55
import {
@@ -50,7 +50,7 @@ export const getInvokedFunctionResultVariableNameToImportSpecifiersMap = (
5050
// current file path to get the absolute file path of the file to
5151
// be imported. Since the absolute file path is guaranteed to be
5252
// unique, it is also the canonical file path.
53-
const importFilePath = path.resolve(currentDirPath, importSource)
53+
const importFilePath = posixPath.resolve(currentDirPath, importSource)
5454
// Even though we limit the chars that can appear in Source file
5555
// paths, some chars in file paths (such as '/') cannot be used
5656
// in function names. As such, we substitute illegal chars with
@@ -287,7 +287,7 @@ export const transformProgramToFunctionDeclaration = (
287287
currentFilePath: string
288288
): es.FunctionDeclaration => {
289289
const moduleDeclarations = program.body.filter(isModuleDeclaration)
290-
const currentDirPath = path.resolve(currentFilePath, '..')
290+
const currentDirPath = posixPath.resolve(currentFilePath, '..')
291291

292292
// Create variables to hold the imported statements.
293293
const invokedFunctionResultVariableNameToImportSpecifiersMap =

0 commit comments

Comments
 (0)