core: add helpers for working with paths across OSes (#1102)

This commit is contained in:
Seth Vargo
2022-06-15 08:18:44 -07:00
committed by GitHub
parent b5f31bb5a2
commit 00282d6145
4 changed files with 226 additions and 1 deletions

View File

@@ -309,4 +309,27 @@ outputs:
runs:
using: 'node12'
main: 'dist/index.js'
```
```
#### Filesystem path helpers
You can use these methods to manipulate file paths across operating systems.
The `toPosixPath` function converts input paths to Posix-style (Linux) paths.
The `toWin32Path` function converts input paths to Windows-style paths. These
functions work independently of the underlying runner operating system.
```js
toPosixPath('\\foo\\bar') // => /foo/bar
toWin32Path('/foo/bar') // => \foo\bar
```
The `toPlatformPath` function converts input paths to the expected value on the runner's operating system.
```js
// On a Windows runner.
toPlatformPath('/foo/bar') // => \foo\bar
// On a Linux runner.
toPlatformPath('\\foo\\bar') // => /foo/bar
```