fix: fix push uploads to the wrong path on windows (#240)

This commit is contained in:
Roman Hotsiy
2021-01-09 20:03:02 +02:00
committed by GitHub
parent 1a30fbfab6
commit be707fab1c
3 changed files with 37 additions and 3 deletions

View 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);
});
});

View File

@@ -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,
}
}

View File

@@ -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, '/');
}