Skip to content
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

[now-client] Fix windows paths handling #2974

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/now-client/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DeploymentFile } from './hashes';
import { parse as parseUrl } from 'url';
import { fetch as fetch_ } from 'fetch-h2';
import { readFile } from 'fs-extra';
import { join } from 'path';
import { join, sep } from 'path';
import qs from 'querystring';
import pkg from '../../package.json';
import { Options } from '../deploy';
Expand All @@ -25,7 +25,7 @@ export const EVENTS = new Set([
'warning',
'error',
// Build events
'build-state-changed'
'build-state-changed',
]);

export function parseNowJSON(file?: DeploymentFile): NowJsonOptions {
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function getNowIgnore(
'node_modules',
'__pycache__/',
'venv/',
'CVS'
'CVS',
];

await Promise.all(
Expand Down Expand Up @@ -128,6 +128,8 @@ export interface PreparedFile {
size: number;
}

const isWin = process.platform.includes('win');

export const prepareFiles = (
files: Map<string, DeploymentFile>,
options: Options
Expand All @@ -143,17 +145,19 @@ export const prepareFiles = (

if (options.isDirectory) {
// Directory
fileName = options.path ? name.replace(`${options.path}/`, '') : name;
fileName = options.path
? name.substring(options.path.length + 1)
: name;
} else {
// Array of files or single file
const segments = name.split('/');
const segments = name.split(sep);
fileName = segments[segments.length - 1];
}

next.push({
file: fileName,
file: isWin ? fileName.replace(/\\/g, '/') : fileName,
size: file.data.byteLength || file.data.length,
sha
sha,
});
}

Expand Down