本文整理汇总了TypeScript中pify.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: pify
import nodeResolve from 'resolve'
import pify from 'pify'
interface Options {
cwd: string
}
const resolve = pify(nodeResolve)
const cache = new Map()
export default async function(id: string, options: Options) {
const cacheId = `${id}::${options.cwd}`
if (cache.has(cacheId)) return cache.get(cacheId)
const res = await resolve(id, {
basedir: options.cwd,
extensions: ['.js', '.json', '.jsx', '.ts', '.tsx'],
packageFilter(pkg: any) {
if (pkg.module) {
pkg.main = pkg.module
}
return pkg
}
})
cache.set(cacheId, res)
return res
}
示例2: getPort
return getPort().then(port => {
const s = http.createServer((req, resp) => s.emit(req.url, req, resp));
s.host = host;
s.port = port;
s.url = `http://${host}:${port}`;
s.protocol = 'http';
s.listen = pify(s.listen, Promise);
s.close = pify(s.close, Promise);
return s;
});
示例3: it
it('should post progress for uploads', async () => {
const scope =
nock(Utils.baseUrl)
.post(
'/upload/youtube/v3/videos?part=id%2Csnippet¬ifySubscribers=false&uploadType=multipart')
.reply(200);
const fileName = path.join(__dirname, '../../test/fixtures/mediabody.txt');
const fileSize = (await pify(fs.stat)(fileName)).size;
const google = new GoogleApis();
const youtube = google.youtube('v3');
const progressEvents = new Array<number>();
await youtube.videos.insert(
{
part: 'id,snippet',
notifySubscribers: false,
requestBody: {
snippet: {
title: 'Node.js YouTube Upload Test',
description:
'Testing YouTube upload via Google APIs Node.js Client'
}
},
media: {body: fs.createReadStream(fileName)}
},
{
onUploadProgress: (evt: {bytesRead: number}) => {
progressEvents.push(evt.bytesRead);
}
});
assert(progressEvents.length > 0);
assert.equal(progressEvents[0], fileSize);
scope.done();
});
示例4: pify
return [async (...args: any[]) => {
const done = args[args.length - 1];
const passedArgs = args.splice(0, args.length - 1);
for (const hook of hooks) {
await pify(hook)(...passedArgs);
}
done();
}] as [(...args: any[]) => Promise<void>];
示例5: async
async (buildPath, electronVersion, pPlatform, pArch, done) => {
if (packagerSpinner) {
packagerSpinner.succeed();
prepareCounter += 1;
prepareSpinner = ora(`Preparing to Package Application for arch: ${(prepareCounter === 2 ? 'armv7l' : 'x64').cyan}`).start();
}
const bins = await pify(glob)(path.join(buildPath, '**/.bin/**/*'));
for (const bin of bins) {
await fs.remove(bin);
}
done();
}, async (buildPath, electronVersion, pPlatform, pArch, done) => {
示例6: moveApp
async moveApp(appPath: string, targetApplicationPath: string, spinner: OraImpl, copyInstead = false) {
let writeAccess = true;
try {
await fs.access('/Applications', fs.constants.W_OK);
} catch (err) {
writeAccess = false;
}
if (await fs.pathExists(targetApplicationPath)) {
spinner.fail();
throw `The application "${path.basename(targetApplicationPath)}" appears to already exist in /Applications.`;
}
const moveCommand = `${copyInstead ? 'cp -r' : 'mv'} "${appPath}" "${targetApplicationPath}"`;
if (writeAccess) {
await pify(exec)(moveCommand);
} else {
await pify(sudo.exec)(moveCommand, {
name: 'Electron Forge',
});
}
}
示例7: async
return async (): Promise<TestServer> => {
const port = await getPort();
const server = http.createServer(fn) as TestServer;
server.host = host;
server.port = port;
server.url = `http://${host}:${port}`;
server.protocol = 'http';
server.listen(port);
server.close = pify(server.close);
return server;
};
示例8: cookieTest
async function cookieTest(input, t): Promise<void> {
const server = await createCookieServer();
const screenshots = await new Pageres({cookies: [input]})
.src(server.url, ['320x480'])
.run();
server.close();
const png = new PNG(screenshots[0]);
const {pixels} = await pify(png.parse.bind(png))();
t.is(pixels[0], 0);
t.is(pixels[1], 0);
t.is(pixels[2], 0);
t.is(pixels[3], 255);
}
示例9: pify
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import assert from 'assert';
import * as fs from 'fs';
import nock from 'nock';
import * as path from 'path';
import pify from 'pify';
import {Utils} from './../utils';
const fsp = pify(fs);
nock.disableNetConnect();
const samples = {
jwt: require('../../../samples/jwt')
};
describe('Auth samples', () => {
afterEach(() => {
nock.cleanAll();
});
it('should support JWT', async () => {
const scope = nock(Utils.baseUrl)
.get('/drive/v2/files')
示例10: workerFarm
import workerFarm from 'worker-farm';
import pify from 'pify';
import path from 'path';
const exportNames = [
'copyFileWorker',
'compressImageWorker',
'writeFileWorker',
'tinyPngWorker',
'binPackerWorker',
];
const workerFarmWorkers = workerFarm(
path.join(__dirname, 'workers.js'),
exportNames,
) as any;
export const workers = pify(workerFarmWorkers);
export const workerFarmEnd = () => workerFarm.end(workerFarmWorkers);