mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 20:57:44 +00:00
fix: fix push uploads to the wrong path on windows (#240)
This commit is contained in:
19
packages/cli/src/__tests__/utils.test.ts
Normal file
19
packages/cli/src/__tests__/utils.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { slash } from '../utils';
|
||||
|
||||
describe('slash path', () => {
|
||||
it('can correctly slash path', () => {
|
||||
[
|
||||
['foo\\bar', 'foo/bar'],
|
||||
['foo/bar', 'foo/bar'],
|
||||
['foo\\中文', 'foo/中文'],
|
||||
['foo/中文', 'foo/中文'],
|
||||
].forEach(([path, expectRes]) => {
|
||||
expect(slash(path)).toBe(expectRes);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not modify extended length paths', () => {
|
||||
const extended = '\\\\?\\some\\path';
|
||||
expect(slash(extended)).toBe(extended);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import fetch from 'node-fetch';
|
||||
import { performance } from 'perf_hooks';
|
||||
import { yellow, green, blue } from 'colorette';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
import { bundle, Config, loadConfig, RedoclyClient, IGNORE_FILE, BundleOutputFormat } from '@redocly/openapi-core';
|
||||
import {
|
||||
promptUser,
|
||||
@@ -13,6 +14,7 @@ import {
|
||||
getTotals,
|
||||
pluralize,
|
||||
dumpBundle,
|
||||
slash
|
||||
} from '../utils';
|
||||
|
||||
type Source = {
|
||||
@@ -186,8 +188,8 @@ async function collectFilesToUpload(entrypoint: string) {
|
||||
return {
|
||||
filePath: path.resolve(filename),
|
||||
keyOnS3: config.configFile
|
||||
? path.relative(path.dirname(config.configFile), filename)
|
||||
: path.basename(filename),
|
||||
? slash(path.relative(path.dirname(config.configFile), filename))
|
||||
: slash(path.basename(filename)),
|
||||
contents: contents && Buffer.from(contents, 'utf-8') || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,3 +281,16 @@ export function exitWithError(message: string) {
|
||||
process.stderr.write(red(message)+ '\n\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
|
||||
*/
|
||||
export function slash(path: string): string {
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
|
||||
if (isExtendedLengthPath) {
|
||||
return path
|
||||
}
|
||||
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
Reference in New Issue
Block a user