Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sm/core6
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 15, 2023
2 parents 7f865f0 + 6505c3d commit b26ef23
Show file tree
Hide file tree
Showing 11 changed files with 1,976 additions and 2,116 deletions.
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require": "ts-node/register,source-map-support/register",
"require": ["ts-node/register"],
"watch-extensions": "ts",
"watch-files": ["src/**/*.ts", "test/**/*.ts"],
"recursive": true,
"reporter": "spec",
"timeout": 5000
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.9
v18.18
213 changes: 42 additions & 171 deletions CHANGELOG.md

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/templates",
"version": "60.0.1",
"version": "60.0.0",
"salesforceApiVersion": "59",
"description": "Salesforce JS library for templates",
"bugs": "https://github.com/forcedotcom/salesforcedx-templates/issues",
Expand All @@ -14,57 +14,58 @@
],
"dependencies": {
"@salesforce/core": "^6.1.0",
"@salesforce/kit": "^3.0.9",
"@salesforce/kit": "^3.0.15",
"got": "^11.8.2",
"mime-types": "^2.1.27",
"proxy-agent": "^6.2.1",
"tar": "^6.1.13",
"tslib": "^1",
"hpagent": "^1.2.0",
"mime-types": "^2.1.35",
"proxy-from-env": "^1.1.0",
"tar": "^6.2.0",
"tslib": "^2.6.2",
"yeoman-environment": "^3.9.1",
"yeoman-generator": "^5.6.1"
},
"devDependencies": {
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-scripts": "^2.0.4",
"@salesforce/prettier-config": "^0.0.2",
"@types/chai-as-promised": "^7.1.4",
"@types/fs-extra": "^8.1.0",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/prettier-config": "^0.0.3",
"@types/chai-as-promised": "^7.1.8",
"@types/fs-extra": "^11.0.4",
"@types/got": "^9.6.12",
"@types/mime-types": "^2.1.0",
"@types/tar": "^4.0.5",
"@types/yeoman-assert": "^3.1.1",
"@types/yeoman-environment": "^2.10.6",
"@types/yeoman-generator": "^5.2.9",
"@types/mime-types": "^2.1.4",
"@types/proxy-from-env": "^1.0.4",
"@types/tar": "^6.1.8",
"@types/yeoman-assert": "^3.1.4",
"@types/yeoman-environment": "^2.10.11",
"@types/yeoman-generator": "^5.2.14",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"chai": "^4.2.0",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"commitizen": "^4.2.4",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-salesforce": "^0.1.6",
"eslint-config-salesforce-license": "^0.1.6",
"eslint-config-salesforce-typescript": "^0.2.7",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prettier": "^3.1.3",
"fs-extra": "^9.0.1",
"husky": "^8.0.0",
"mocha": "^9.1.3",
"husky": "^8.0.3",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"pretty-quick": "^3.1.0",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
"sinon": "10.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.4.4",
"sinon": "^17.0.1",
"ts-node": "^10.4.0",
"typescript": "^5.2.2",
"yeoman-assert": "^3.1.1"
},
"engines": {
"node": ">=18.0.0"
"node": ">=18.18.2"
},
"resolutions": {
"yeoman-generator": "^5.6.1",
Expand Down
25 changes: 21 additions & 4 deletions src/service/gitRepoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import { Stream } from 'stream';
import * as tar from 'tar';
import { promisify } from 'util';
import { nls } from '../i18n';
import { ProxyAgent } from 'proxy-agent';
import { HttpsProxyAgent } from 'hpagent';
import { getProxyForUrl } from 'proxy-from-env';

interface RepoInfo {
username: string;
name: string;
branch: string;
filePath: string;
}

/**
* extract repo info from uri
* @param repoUri uri to git repo
Expand All @@ -37,9 +39,24 @@ export async function getRepoInfo(repoUri: URL): Promise<RepoInfo> {
// For repos with no branch information, fetch default branch
if (t === undefined) {
const url = `https://api.github.com/repos/${username}/${name}`;
const infoResponse = await got(url, {
agent: { https: new ProxyAgent() },
}).catch((e) => e);
const proxy = getProxyForUrl(url);

// proxy will be empty string if no proxy is set
const infoResponse = await (proxy !== ''
? got(url, {
agent: {
https: new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy,
}),
},
})
: got(url)
).catch((e) => e);
if (infoResponse.statusCode !== 200) {
throw new Error(
nls.localize('customTemplatesCannotRetrieveDefaultBranch', repoUri.href)
Expand Down
2 changes: 1 addition & 1 deletion src/service/templateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class TemplateService {
};
resolve(result);
})
.catch((err) => {
.catch((err: Error | string) => {
reject(err);
});
});
Expand Down
3 changes: 0 additions & 3 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
'use strict';

import * as util from 'util';

Expand All @@ -22,8 +21,6 @@ const statuses = [
export class Log {
private output = '';
private cleanOutput: string[] = [];

// tslint:disable-next-line: no-any
[index: string]: any;

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion test/generators/sfdxGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import { assert, match, stub } from 'sinon';
import { TemplateOptions } from '../../';
import { SfdxGenerator } from '../../src/generators/sfdxGenerator';
import { TemplateService } from '../../src/service/templateService';
import { TemplateService } from '../../src';
import * as YeomanEnvironment from 'yeoman-environment';

describe('SfdxGenerator', () => {
Expand Down
5 changes: 0 additions & 5 deletions test/mocha.opts

This file was deleted.

13 changes: 12 additions & 1 deletion test/service/templateService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import * as fsOriginal from 'fs';
import * as fs from 'fs-extra';
import got from 'got';
import * as path from 'path';
import { assert as sinonAssert, spy, stub } from 'sinon';
import { assert as sinonAssert, spy, stub, createSandbox } from 'sinon';
import * as assert from 'yeoman-assert';
import * as yeoman from 'yeoman-environment';
import { TemplateService, TemplateType } from '../../src';
import { nls } from '../../src/i18n';
import { getStoragePathForCustomTemplates } from '../../src/service/gitRepoUtils';
import { getProxyForUrl } from 'proxy-from-env';

chai.use(chaiAsPromised);
chai.should();
Expand Down Expand Up @@ -79,6 +80,8 @@ describe('TemplateService', () => {
});

describe('create custom template', () => {
// add reference to a sinon sandbox
const sandbox = createSandbox();
const TEST_CUSTOM_TEMPLATES_REPO =
'https://github.com/forcedotcom/salesforcedx-templates/tree/main/test/custom-templates';
const TEST_CUSTOM_TEMPLATES_STORAGE_PATH = getStoragePathForCustomTemplates(
Expand All @@ -90,6 +93,9 @@ describe('TemplateService', () => {
path.join('testsoutput', 'customLibraryCreate', 'apexclass')
);
});
afterEach(() => {
sandbox.restore();
});

it('should create custom template from local folder', async () => {
const templateService = TemplateService.getInstance(process.cwd());
Expand Down Expand Up @@ -206,6 +212,11 @@ describe('TemplateService', () => {
});

it('should throw error if cannot retrieve default branch', async () => {
const mockIt = {
getProxyForUrl,
};
// @ts-ignore - function signature is not compatible with sinon stub
sandbox.stub(mockIt, 'getProxyForUrl').returns(undefined);
const templateService = TemplateService.getInstance(process.cwd());
const customTemplates =
'https://github.com/forcedotcom/this-repo-does-not-exist';
Expand Down
Loading

0 comments on commit b26ef23

Please sign in to comment.