本文整理匯總了TypeScript中npm-common/npmregistry.NpmRegistry類的典型用法代碼示例。如果您正苦於以下問題:TypeScript NpmRegistry類的具體用法?TypeScript NpmRegistry怎麽用?TypeScript NpmRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NpmRegistry類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('does Basic auth for onprem when service endpoint auth is Token and the TFS server and EP have the same IP', (done: MochaDone) => {
// Scenario: Onprem and user supplied an IP for the endpoint and the TeamFoundationCollectionUri is a _matching_ IP
let mockTask = {
getVariable: (v) => {
if (v === 'System.TeamFoundationCollectionUri') {
return 'http://mytfsserver.example.com';
}
},
getEndpointAuthorization: (id, optional) => {
return { scheme: 'UsernamePassword', parameters: { 'username': 'USERNAME', 'password': 'PASSWORD' } };
},
getEndpointUrl: (id, optional) => {
return 'http://somepublicrepo.contoso.com:8080/some/random/path';
}
};
mockery.registerMock('vsts-task-lib/task', mockTask);
const npmregistry = require("npm-common/npmregistry");
let registry = npmregistry.NpmRegistry.FromServiceEndpoint('endpointId');
const BASIC_AUTH_PASSWD_REGEX = /\/\/.*\/:_password=PASSWORD.*/g;
assert(registry.auth.match(BASIC_AUTH_PAT_PASSWD_REGEX), `Auth must contain a password. Auth is: (${registry.auth})`);
const BASIC_AUTH_PAT_EML_REGEX = /\/\/.*\/:email=USERNAME.*/g;
assert(registry.auth.match(BASIC_AUTH_PAT_EML_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
const BASIC_AUTH_PAT_USERNAME_REGEX = /\/\/.*\/:username=USERNAME.*/g;
assert(registry.auth.match(BASIC_AUTH_PAT_USERNAME_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
assert(registry.auth.match(AWLAYS_AUTH_REGEX), `Auth must contain always-auth. Auth is: (${registry.auth})`);
done();
});
示例2: require
(done: MochaDone) => {
// Scenario: Cross account on visualstudio.com
let mockTask = {
getVariable: (v) => {
if (v === 'System.TeamFoundationCollectionUri') {
return 'http://example.visualstudio.com';
}
},
getEndpointAuthorization: (id, optional) => {
return { scheme: 'Token', parameters: { 'apitoken': 'AUTHTOKEN' } };
},
getEndpointUrl: (id, optional) => {
return 'http://serviceendpoint.visualstudio.com';
}
};
mockery.registerMock('vsts-task-lib/task', mockTask);
const npmregistry = require("npm-common/npmregistry");
let registry = npmregistry.NpmRegistry.FromServiceEndpoint('endpointId');
assert(registry.auth.match(BASIC_AUTH_PAT_PASSWD_REGEX), `Auth must contain a password. Auth is: (${registry.auth})`);
assert(registry.auth.match(BASIC_AUTH_PAT_EML_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
assert(registry.auth.match(BASIC_AUTH_PAT_USERNAME_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
assert(registry.auth.match(AWLAYS_AUTH_REGEX), `Auth must contain always-auth. Auth is: (${registry.auth})`);
done();
});
示例3: getPublishRegistry
export async function getPublishRegistry(packagingLocation: PackagingLocation): Promise<INpmRegistry> {
let npmRegistry: INpmRegistry;
const registryLocation = tl.getInput(NpmTaskInput.PublishRegistry);
switch (registryLocation) {
case RegistryLocation.Feed:
tl.debug(tl.loc('PublishFeed'));
const feedId = tl.getInput(NpmTaskInput.PublishFeed, true);
npmRegistry = await NpmRegistry.FromFeedId(packagingLocation.DefaultPackagingUri, feedId);
break;
case RegistryLocation.External:
tl.debug(tl.loc('PublishExternal'));
const endpointId = tl.getInput(NpmTaskInput.PublishEndpoint, true);
npmRegistry = await NpmRegistry.FromServiceEndpoint(endpointId);
break;
}
return npmRegistry;
}
示例4: async
async (done: MochaDone) => {
// Scenario: Cross account on visualstudio.com
let mockTask = {
getVariable: (v) => {
if (v === 'System.TeamFoundationCollectionUri') {
return 'http://example.visualstudio.com';
}
},
getEndpointAuthorization: (id, optional) => {
return { scheme: 'Token', parameters: { 'apitoken': 'AUTHTOKEN' } };
},
getEndpointUrl: (id, optional) => {
return 'http://serviceendpoint.visualstudio.com';
},
loc: (key: string) => {
// no-op
},
getHttpProxyConfiguration: (endpoint) => {
return null;
}
};
mockery.registerMock('vsts-task-lib/task', mockTask);
mockery.registerMock('typed-rest-client/HttpClient', {
HttpClient: function() {
return {
get: function(url, headers) {
return {
then: function(handler) {
handler({
message: {
statusCode: 401,
rawHeaders: ['x-tfs-foo: abc', 'x-content-type-options: nosniff', 'X-Powered-By: ASP.NET']
}
});
}
};
}
};
}
});
const npmregistry = require("npm-common/npmregistry");
let registry = await npmregistry.NpmRegistry.FromServiceEndpoint('endpointId');
assert(registry.auth.match(BASIC_AUTH_PAT_PASSWD_REGEX), `Auth must contain a password. Auth is: (${registry.auth})`);
assert(registry.auth.match(BASIC_AUTH_PAT_EML_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
assert(registry.auth.match(BASIC_AUTH_PAT_USERNAME_REGEX), `Auth must contain a email. Auth is: (${registry.auth})`);
assert(registry.auth.match(AWLAYS_AUTH_REGEX), `Auth must contain always-auth. Auth is: (${registry.auth})`);
done();
});
示例5: it
it('does Bearer auth for hosted when service endpoint auth is Token and endpoint is 3rd party', async (done: MochaDone) => {
// Scenario: User is connecting to a non-visualstudio.com registry
let mockTask = {
getVariable: (v) => {
if (v === 'System.TeamFoundationCollectionUri') {
return 'http://example.visualstudio.com';
}
},
getEndpointAuthorization: (id, optional) => {
return { scheme: 'Token', parameters: { 'apitoken': 'AUTHTOKEN' } };
},
getEndpointUrl: (id, optional) => {
return 'http://somepublicrepo.contoso.com:8080/some/random/path';
},
getHttpProxyConfiguration: (endpoint) => {
return null;
}
};
mockery.registerMock('vsts-task-lib/task', mockTask);
mockery.registerMock('typed-rest-client/HttpClient', {
HttpClient: function() {
return {
get: function(url, headers) {
return {
then: function(handler) {
handler({
message: {
statusCode: 401,
rawHeaders: ['x-content-type-options: nosniff', 'X-Powered-By: ASP.NET']
}
});
}
};
}
};
}
});
const npmregistry = require("npm-common/npmregistry");
let registry = await npmregistry.NpmRegistry.FromServiceEndpoint('endpointId');
assert(registry.auth.match(BEARER_AUTH_REGEX), `Auth must contain _authToken. Auth is: (${registry.auth})`);
assert(registry.auth.match(AWLAYS_AUTH_REGEX), `Auth must contain always-auth. Auth is: (${registry.auth})`);
done();
});
示例6: getCustomRegistries
export async function getCustomRegistries(packagingLocation: PackagingLocation): Promise<NpmRegistry[]> {
const workingDir = tl.getInput(NpmTaskInput.WorkingDir) || process.cwd();
const npmRegistries: INpmRegistry[] = await util.getLocalNpmRegistries(workingDir, packagingLocation.PackagingUris);
const registryLocation = tl.getInput(NpmTaskInput.CustomRegistry);
switch (registryLocation) {
case RegistryLocation.Feed:
tl.debug(tl.loc('UseFeed'));
const feedId = tl.getInput(NpmTaskInput.CustomFeed, true);
npmRegistries.push(await NpmRegistry.FromFeedId(packagingLocation.DefaultPackagingUri, feedId));
break;
case RegistryLocation.Npmrc:
tl.debug(tl.loc('UseNpmrc'));
const endpointIds = tl.getDelimitedInput(NpmTaskInput.CustomEndpoint, ',');
if (endpointIds && endpointIds.length > 0) {
await Promise.all(endpointIds.map(async e => {
npmRegistries.push(await NpmRegistry.FromServiceEndpoint(e, true));
}));
}
break;
}
return npmRegistries;
}
示例7:
await Promise.all(endpointIds.map(async e => {
endpointRegistries.push(await npmregistry.NpmRegistry.FromServiceEndpoint(e, true));
}));