Compare commits

..

2 Commits

Author SHA1 Message Date
Max Rovensky
3f5f71f8ab Publish
- now-client@5.1.3
2019-09-09 23:32:19 +08:00
Max
2a44179898 [now-client] Fix windows paths handling (#2974)
* Fix windows paths handling in now-client

* Tweak windows paths  handling
2019-09-09 23:31:16 +08:00
2 changed files with 55 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "now-client",
"version": "5.1.2",
"version": "5.1.3",
"main": "lib/index.js",
"license": "MIT",
"scripts": {

View File

@@ -1,17 +1,16 @@
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 qs from 'querystring'
import pkg from '../../package.json'
import { Options } from '../deploy'
import { DeploymentFile } from './hashes';
import { parse as parseUrl } from 'url';
import { fetch as fetch_ } from 'fetch-h2';
import { readFile } from 'fs-extra';
import { join, sep } from 'path';
import qs from 'querystring';
import pkg from '../../package.json';
import { Options } from '../deploy';
export const API_FILES = 'https://api.zeit.co/v2/now/files'
export const API_DEPLOYMENTS = 'https://api.zeit.co/v9/now/deployments'
export const API_DEPLOYMENTS_LEGACY = 'https://api.zeit.co/v3/now/deployments'
export const API_DELETE_DEPLOYMENTS_LEGACY =
'https://api.zeit.co/v2/now/deployments'
export const API_FILES = 'https://api.zeit.co/v2/now/files';
export const API_DEPLOYMENTS = 'https://api.zeit.co/v9/now/deployments';
export const API_DEPLOYMENTS_LEGACY = 'https://api.zeit.co/v3/now/deployments';
export const API_DELETE_DEPLOYMENTS_LEGACY = 'https://api.zeit.co/v2/now/deployments';
export const EVENTS = new Set([
// File events
@@ -23,23 +22,23 @@ export const EVENTS = new Set([
'ready',
'error',
// Build events
'build-state-changed'
])
'build-state-changed',
]);
export function parseNowJSON(file?: DeploymentFile): NowJsonOptions {
if (!file) {
return {}
return {};
}
try {
const jsonString = file.data.toString()
const jsonString = file.data.toString();
return JSON.parse(jsonString)
return JSON.parse(jsonString);
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
console.error(e);
return {}
return {};
}
}
@@ -70,8 +69,8 @@ export async function getNowIgnore(
'node_modules',
'__pycache__/',
'venv/',
'CVS'
]
'CVS',
];
await Promise.all(
files.map(
@@ -80,21 +79,21 @@ export async function getNowIgnore(
const filePath = Array.isArray(path)
? file
: file.includes(path)
? file
: join(path, file)
const nowIgnore = await readFile(filePath)
? file
: join(path, file);
const nowIgnore = await readFile(filePath);
nowIgnore
.toString()
.split('\n')
.filter((s: string): boolean => s.length > 0)
.forEach((entry: string): number => ignores.push(entry))
.forEach((entry: string): number => ignores.push(entry));
}
}
)
)
);
return ignores
return ignores;
}
export const fetch = (
@@ -103,22 +102,22 @@ export const fetch = (
opts: any = {}
): Promise<any> => {
if (opts.teamId) {
const parsedUrl = parseUrl(url, true)
const query = parsedUrl.query
const parsedUrl = parseUrl(url, true);
const query = parsedUrl.query;
query.teamId = opts.teamId
url = `${parsedUrl.href}?${qs.encode(query)}`
delete opts.teamId
query.teamId = opts.teamId;
url = `${parsedUrl.href}?${qs.encode(query)}`;
delete opts.teamId;
}
opts.headers = opts.headers || {}
opts.headers = opts.headers || {};
// @ts-ignore
opts.headers.authorization = `Bearer ${token}`
opts.headers.authorization = `Bearer ${token}`;
// @ts-ignore
opts.headers['user-agent'] = `now-client-v${pkg.version}`
opts.headers['user-agent'] = `now-client-v${pkg.version}`;
return fetch_(url, opts)
}
return fetch_(url, opts);
};
export interface PreparedFile {
file: string;
@@ -126,39 +125,43 @@ export interface PreparedFile {
size: number;
}
const isWin = process.platform.includes('win');
export const prepareFiles = (
files: Map<string, DeploymentFile>,
options: Options
): PreparedFile[] => {
const preparedFiles = [...files.keys()].reduce(
(acc: PreparedFile[], sha: string): PreparedFile[] => {
const next = [...acc]
const next = [...acc];
const file = files.get(sha) as DeploymentFile
const file = files.get(sha) as DeploymentFile;
for (const name of file.names) {
let fileName
let fileName;
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('/')
fileName = segments[segments.length - 1]
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,
});
}
return next
return next;
},
[]
)
);
return preparedFiles
}
return preparedFiles;
};