Skip to content

Commit

Permalink
Manually backports Windows changes from opensearch-project#2601 (open…
Browse files Browse the repository at this point in the history
…search-project#2647)

* [Windows] Replaces `rm -rf` with `remove.js`
* [dev/build] Facilitates using zipped archives of node releases
* [div/build] Introduces Windows as a platform
* [dev/build] Corrects cleaning of platform specific build artifacts
* [dev/build] Enhances the cleanup of downloaded node binaries
* [opensearch-dashboards-plugin] Removes prohibition on installing plugins on Windows
* [@osd/utils] Adds a method to standardize path references across platforms
* [dev/build] Standardize paths in tests
* [@osd/telemetry-tools] Normalizes the collection paths
* [plugins/url-forwarding] Fixes the usage of `normalizePath` across node and browser
* [@osd/pm] Allows symlink created for tests without elevated privileges on Windows
* [@osd/opensearch] Allows usage of Windows snapshots in integration tests
* [@osd/opensearch] Employs absolute paths in tests
* [@osd/apm-config-loader] Employs absolute paths in tests
* [core/server] Employs absolute and posix references to paths
* [@osd/optimizer] Standardize paths in tests
* [@osd/tests] Employs absolute paths in tests
* [@osd/pm] Standardize paths in project trees
* [plugins/telemetry] Accommodates the inability of Windows to create unreadable files for testing
* [@osd/config-schema] Normalize paths in tests
* [@osd/plugin-helpers] Standardize paths in tests
* [@osd/plugin-generator] Standardize paths in tests
* [Windows] Update changelog

backport PR: opensearch-project#2601

Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki authored and Peter Fitzgibbons committed Dec 1, 2022
1 parent ff2cb92 commit cc0a0c9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/osd-utils/src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import { join } from 'path';
import { join, normalize } from 'path';
import { accessSync, constants } from 'fs';
import { TypeOf, schema } from '@osd/config-schema';
import { REPO_ROOT } from '@osd/cross-platform';
Expand Down Expand Up @@ -94,3 +94,27 @@ export const config = {
data: schema.string({ defaultValue: () => getDataPath() }),
}),
};

/**
* 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;
};

0 comments on commit cc0a0c9

Please sign in to comment.