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

feat: dont open urls when CLI is running in CI #6503

Merged
merged 4 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/amplify-category-analytics/lib/kinesis-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const open = require('open');
const { open } = require('amplify-cli-core');
const constants = require('./constants');

function console(context) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-analytics/lib/pinpoint-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const open = require('open');
const { open } = require('amplify-cli-core');
const constants = require('./constants');

function console(context) {
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-category-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"amplify-cli-core": "1.14.1",
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"open": "^7.0.0",
"uuid": "^3.4.0"
}
}
1 change: 0 additions & 1 deletion packages/amplify-category-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"graphql-relational-schema-transformer": "2.16.1",
"graphql-transformer-core": "6.25.1",
"inquirer": "^7.3.3",
"open": "^7.0.0",
"ora": "^4.0.3",
"uuid": "^3.4.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import path from 'path';
import fs from 'fs-extra';
import os from 'os';
import uuid from 'uuid';
import open from 'open';
import { rootAssetDir } from '../aws-constants';
import { checkForPathOverlap, validatePathName, formatCFNPathParamsForExpressJs } from '../utils/rest-api-path-utils';
import { ResourceDoesNotExistError, exitOnNextTick, $TSContext, stateManager } from 'amplify-cli-core';
import { ResourceDoesNotExistError, exitOnNextTick, $TSContext, stateManager, open } from 'amplify-cli-core';

// keep in sync with ServiceName in amplify-category-function, but probably it will not change
const FunctionServiceNameLambdaFunction = 'Lambda';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { dataStoreLearnMore } from '../sync-conflict-handler-assets/syncAssets';
import inquirer from 'inquirer';
import fs from 'fs-extra';
import path from 'path';
import open from 'open';
import { rootAssetDir } from '../aws-constants';
import { collectDirectivesByTypeNames, readProjectConfiguration, ConflictHandlerType } from 'graphql-transformer-core';
import { category } from '../../../category-constants';
Expand All @@ -19,6 +18,7 @@ import {
exitOnNextTick,
stateManager,
$TSContext,
open,
} from 'amplify-cli-core';

const serviceName = 'AppSync';
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-category-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"inquirer": "^7.3.3",
"lodash": "^4.17.19",
"mime-types": "^2.1.26",
"open": "^7.0.0",
"ora": "^4.0.3",
"promise-sequential": "^1.1.1",
"uuid": "^3.4.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const inquirer = require('inquirer');
const open = require('open');
const _ = require('lodash');
const { stateManager } = require('amplify-cli-core');
const { stateManager, open } = require('amplify-cli-core');
const { getAuthResourceName } = require('../../utils/getAuthResourceName');
const { copyCfnTemplate, saveResourceParameters } = require('./utils/synthesize-resources');
const { ENV_SPECIFIC_PARAMS, AmplifyAdmin, UserPool, IdentityPool, BothPools, privateKeys } = require('./constants');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { openConsole, isMockable } from '../../../provider-utils/awscloudformation';
import { ServiceName } from '../../../provider-utils/awscloudformation/utils/constants';
import open from 'open';
import { open } from 'amplify-cli-core';

jest.mock('open');
jest.mock('amplify-cli-core');

describe('awscloudformation function provider', () => {
it('opens the correct service console', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import _ from 'lodash';
import { merge, convertToComplete, isComplete } from './utils/funcParamsUtils';
import fs from 'fs-extra';
import path from 'path';
import open from 'open';
import { IsMockableResponse } from '../..';
import { JSONUtilities } from 'amplify-cli-core';
import { JSONUtilities, open } from 'amplify-cli-core';

/**
* Entry point for creating a new function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
jest.mock('fs-extra');
jest.mock('open');
jest.mock('amplify-cli-core');

jest.mock('../../../lib/S3AndCloudFront/configuration-manager');
jest.mock('../../../lib/S3AndCloudFront/helpers/file-uploader');
jest.mock('../../../lib/S3AndCloudFront/helpers/cloudfront-manager');

const fs = require('fs-extra');
const path = require('path');
const open = require('open');
const { open } = require('amplify-cli-core');
const inquirer = require('inquirer');
const mockirer = require('mockirer');

Expand All @@ -20,8 +21,6 @@ const internalParametersContents = require('../../../lib/S3AndCloudFront/paramet
const mockTemplate = require('../../../__mocks__/mockTemplate');
const mockParameters = require('../../../__mocks__/mockParameters');

const serviceName = 'S3AndCloudFront';
const providerPlugin = 'awscloudformation';
const templateFileName = 'template.json';
const parametersFileName = 'parameters.json';

Expand Down Expand Up @@ -101,6 +100,7 @@ describe('s3IndexModule', () => {
options: {},
},
};

beforeAll(() => {
mockirer(inquirer, mockAnswers);
fs.ensureDirSync = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require('fs-extra');
const inquirer = require('inquirer');
const path = require('path');
const open = require('open');
const chalk = require('chalk');
const { open } = require('amplify-cli-core');
const configManager = require('./configuration-manager');
const fileUPloader = require('./helpers/file-uploader');
const cloudFrontManager = require('./helpers/cloudfront-manager');
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"test": "jest --coverage"
},
"dependencies": {
"amplify-cli-core": "1.14.1",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"mime-types": "^2.1.26",
"minimatch": "^3.0.4",
"moment": "^2.24.0",
"open": "^7.0.0",
"ora": "^4.0.3",
"promise-sequential": "^1.1.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const open = require('open');
const ora = require('ora');
const inquirer = require('inquirer');
const { open } = require('amplify-cli-core');

const constants = require('./constants');
const authHelper = require('./auth-helper');
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-category-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"open": "^7.0.0",
"ora": "^4.0.3",
"promise-sequential": "^1.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-predictions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"aws"
],
"dependencies": {
"amplify-cli-core": "1.14.1",
"aws-sdk": "^2.765.0",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"open": "^7.0.0",
"uuid": "^3.4.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import open from 'open';

const path = require('path');
const chalk = require('chalk');
const { NotImplementedError, ResourceDoesNotExistError, exitOnNextTick } = require('amplify-cli-core');
const { NotImplementedError, ResourceDoesNotExistError, exitOnNextTick, open } = require('amplify-cli-core');
const parametersFileName = 'parameters.json';
const prefixForAdminTrigger = 'protected/predictions/index-faces/admin';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import open from 'open';
import inferAssets from '../assets/inferQuestions';
import getAllDefaults from '../default-values/infer-defaults';
import regionMapper from '../assets/regionMapping';
import { ResourceAlreadyExistsError, ResourceDoesNotExistError, exitOnNextTick } from 'amplify-cli-core';
import { ResourceAlreadyExistsError, ResourceDoesNotExistError, exitOnNextTick, open } from 'amplify-cli-core';
const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs-extra');
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-xr/lib/xr-manager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require('fs-extra');
const path = require('path');
const inquirer = require('inquirer');
const open = require('open');
const chalk = require('chalk');
const { URL } = require('url');

const constants = require('./constants');
const authHelper = require('./auth-helper');
const { open } = require('amplify-cli-core');

const SUMERIAN_CONSOLE_URL = 'https://console.aws.amazon.com/sumerian/home/start';

Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-xr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"test-watch": "jest --watch"
},
"dependencies": {
"amplify-cli-core": "1.14.1",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
"inquirer": "^7.3.3",
"open": "^7.0.0"
"inquirer": "^7.3.3"
},
"jest": {
"collectCoverage": true,
Expand Down
4 changes: 3 additions & 1 deletion packages/amplify-cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
"dependencies": {
"ajv": "^6.12.3",
"amplify-cli-logger": "1.1.0",
"ci-info":"^2.0.0",
"dotenv": "^8.2.0",
"fs-extra": "^8.1.0",
"hjson": "^3.2.1",
"lodash": "^4.17.19"
"lodash": "^4.17.19",
"open": "^7.3.1"
},
"devDependencies": {
"@types/fs-extra": "^8.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-cli-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './isPackaged';
export * from './cliConstants';
export * from './deploymentSecretsHelper';
export * from './deploymentState';
export * from './utils';

// Temporary types until we can finish full type definition across the whole CLI

Expand Down
1 change: 1 addition & 0 deletions packages/amplify-cli-core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './open';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit can get rid of this file and change the export in the main index.ts to export directly from open.ts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the single level export for clarity as we probably not exporting everything in an upper level directory.

16 changes: 16 additions & 0 deletions packages/amplify-cli-core/src/utils/open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import opn from 'open';
import ciInfo from 'ci-info';
import { ChildProcess } from 'child_process';

/**
* Helper function to Open stuff like URLs, files, executables. Cross-platform and opens only if its run in non-ci environmets
* This is wrapper for https://github.com/sindresorhus/open
* @param target The thing you want to open. Can be a URL, file, or executable.
* @param options
*/
export const open = (target: string, options: opn.Options): Promise<ChildProcess | void> => {
if (ciInfo.isCI) {
return Promise.resolve();
}
return opn(target, options);
};
12 changes: 6 additions & 6 deletions packages/amplify-cli/src/__tests__/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { preInitSetup } from '../../init-steps/preInitSetup';
import { analyzeProject } from '../../init-steps/s0-analyzeProject';
import { initFrontend } from '../../init-steps/s1-initFrontend';
import { scaffoldProjectHeadless } from '../../init-steps/s8-scaffoldHeadless';

jest.mock('child_process', () => ({ execSync: jest.fn() }));
import { getPackageManager, normalizePackageManagerForOS } from '../../packageManagerHelpers';
jest.mock('child_process');
jest.mock('fs-extra');

(readJSON as jest.Mock).mockReturnValue({});
Expand All @@ -17,10 +17,7 @@ jest.mock('fs-extra');
(existsSync as jest.Mock).mockReturnValue(true);
(readdirSync as jest.Mock).mockReturnValue([]);

jest.mock('../../packageManagerHelpers', () => ({
getPackageManager: () => 'yarn',
normalizePackageManagerForOS: () => 'yarn',
}));
jest.mock('../../packageManagerHelpers');

describe('amplify init: ', () => {
const mockGetProjectConfigFilePath = jest.spyOn(pathManager, 'getProjectConfigFilePath');
Expand All @@ -29,6 +26,9 @@ describe('amplify init: ', () => {
const mockGetBackendDirPath = jest.spyOn(pathManager, 'getBackendDirPath');
const mockGetGitIgnoreFilePath = jest.spyOn(pathManager, 'getGitIgnoreFilePath');

(getPackageManager as jest.Mock).mockReturnValue('yarn');
(normalizePackageManagerForOS as jest.Mock).mockReturnValue('yarn');

const mockGetProjectConfig = jest.fn(() => ({}));

const mockPathManager = {
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-cli/src/commands/console.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import open from 'open';
import { prompt } from 'enquirer';
import { stateManager } from 'amplify-cli-core';
import { stateManager, open } from 'amplify-cli-core';

const providerName = 'awscloudformation';

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-console-hosting/hosting/cicd/configure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const open = require('open');
const { open } = require('amplify-cli-core');
const utils = require('../../utils/amplify-context-utils');
const questions = require('../../modules/questions/question-generator');

Expand Down
10 changes: 6 additions & 4 deletions packages/amplify-console-hosting/hosting/cicd/enable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const open = require('open');
const utils = require('../../utils/amplify-context-utils');
const { open } = require('amplify-cli-core');
const questions = require('../../modules/questions/question-generator');
const configUtils = require('../../utils/config-utils');
const constants = require('../../constants/plugin-constants');
Expand Down Expand Up @@ -38,9 +38,11 @@ async function enable(context) {

async function validateCICDApp(context, appId) {
const amplifyClient = await clientFactory.getAmplifyClient(context);
const result = await amplifyClient.listBranches({
appId,
}).promise();
const result = await amplifyClient
.listBranches({
appId,
})
.promise();
if (result.branches.length === 0) {
throw new ValidationError("No hosting URL found. Run 'amplify add hosting' again to set up hosting with Amplify Console.");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-console-hosting/hosting/cicd/publish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const open = require('open');
const utils = require('../../utils/amplify-context-utils');
const { open } = require('amplify-cli-core');
const questions = require('../../modules/questions/question-generator');

async function publish(context) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-console-hosting/hosting/cicd/serve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const open = require('open');
const { open } = require('amplify-cli-core');
const utils = require('../../utils/amplify-context-utils');
const questions = require('../../modules/questions/question-generator');
const constants = require('../../constants/plugin-constants');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const open = require('open');
const utils = require('../../utils/amplify-context-utils');
const { open } = require('amplify-cli-core');
const questions = require('../../modules/questions/question-generator');

async function configure(context) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-console-hosting/hosting/manual/serve.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const open = require('open');
const utils = require('../../utils/amplify-context-utils');
const amplifyUtils = require('../../utils/amplify-console-utils');
const { open } = require('amplify-cli-core');

async function serve(context) {
const appId = utils.getAppIdForCurrEnv(context);
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-console-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"glob": "^7.1.6",
"inquirer": "^7.3.3",
"node-fetch": "^2.6.1",
"open": "^7.0.0",
"ora": "^4.0.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const { getS3Client, uploadFile } = require('./file-uploader');
const fs = require('fs-extra');
const inquirer = require('inquirer');
const path = require('path');
const open = require('open');

const constants = require('../constants');

const { EcsAlbStack, NETWORK_STACK_LOGICAL_ID, DEPLOYMENT_MECHANISM, processDockerConfig } = require('amplify-category-api');
const { open } = require('amplify-cli-core');

const serviceName = 'ElasticContainer';
const categoryName = 'hosting';
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-container-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"mime-types": "^2.1.26",
"minimatch": "^3.0.4",
"moment": "^2.24.0",
"open": "^7.0.0",
"ora": "^4.0.3",
"promise-sequential": "^1.1.1"
},
Expand Down
Loading