-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@osd/cross-platform] Adds cross-platform helpers #2681
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,3 @@ | ||||||
# `@osd/cross-platform` — OpenSearch Dashboards cross-platform helpers | ||||||
|
||||||
This package contains the helper functions to work around the differences of platforms | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can help disambiguate "platforms" in this context with an example.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@osd/cross-platform", | ||
"main": "./target/index.js", | ||
"version": "1.0.0", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"osd:bootstrap": "yarn build" | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.0.2", | ||
"tsd": "^0.21.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './path'; | ||
export * from './process'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { normalize } from 'path'; | ||
|
||
/** | ||
* Get a standardized reference to a path | ||
* @param {string} path - the path to standardize | ||
* @param {boolean} [usePosix=true] - produce a posix reference | ||
* @param {boolean} [escapedBackslashes=true] - on Windows, double-backslash the reference | ||
* @internal | ||
*/ | ||
export const standardize = ( | ||
path: string, | ||
usePosix: boolean = true, | ||
escapedBackslashes: boolean = true | ||
) => { | ||
/* Force os-dependant separators | ||
* path.posix.normalize doesn't convert backslashes to slashes on Windows so we manually force it afterwards | ||
*/ | ||
const normal = normalize(path); | ||
|
||
// Filter out in-browser executions as well as non-windows ones | ||
if (process?.platform !== 'win32') return normal; | ||
|
||
if (usePosix) return normal.replace(/\\/g, '/'); | ||
return escapedBackslashes ? normal.replace(/\\/g, '\\\\') : normal; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { execSync } from 'child_process'; | ||
|
||
let workingDir = process.cwd(); | ||
|
||
if (process.platform === 'win32') { | ||
try { | ||
const pathFullName = execSync('powershell "(Get-Item -LiteralPath $pwd).FullName"', { | ||
peterzhuamazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cwd: workingDir, | ||
encoding: 'utf8', | ||
})?.trim?.(); | ||
if (pathFullName?.length > 2) workingDir = pathFullName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the significance of |
||
} catch (ex) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
export const PROCESS_WORKING_DIR = workingDir; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target", | ||
"declaration": true, | ||
"declarationMap": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!