From d47d2546b87cfe105d6ad9797804b98a5893f32e Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Wed, 15 Jan 2020 15:09:18 -0500 Subject: [PATCH] chore(repo): remove dead code --- docs/angular/schematics.json | 1 - docs/react/schematics.json | 1 - docs/web/schematics.json | 1 - packages/insights/README.md | 3 - packages/insights/collection.json | 13 - packages/insights/index.ts | 3 - packages/insights/package.json | 30 -- packages/insights/src/insights-task-runner.ts | 298 ------------------ packages/insights/src/schematics/init/init.ts | 14 - .../insights/src/schematics/init/schema.d.ts | 1 - .../insights/src/schematics/init/schema.json | 7 - scripts/build.sh | 4 +- scripts/nx-release.js | 3 +- scripts/package.sh | 8 +- 14 files changed, 6 insertions(+), 381 deletions(-) delete mode 100644 packages/insights/README.md delete mode 100644 packages/insights/collection.json delete mode 100644 packages/insights/index.ts delete mode 100644 packages/insights/package.json delete mode 100644 packages/insights/src/insights-task-runner.ts delete mode 100644 packages/insights/src/schematics/init/init.ts delete mode 100644 packages/insights/src/schematics/init/schema.d.ts delete mode 100644 packages/insights/src/schematics/init/schema.json diff --git a/docs/angular/schematics.json b/docs/angular/schematics.json index 59004e9c10..ada5ef03fd 100644 --- a/docs/angular/schematics.json +++ b/docs/angular/schematics.json @@ -3,7 +3,6 @@ "bazel", "cypress", "express", - "insights", "jest", "nest", "next", diff --git a/docs/react/schematics.json b/docs/react/schematics.json index 59004e9c10..ada5ef03fd 100644 --- a/docs/react/schematics.json +++ b/docs/react/schematics.json @@ -3,7 +3,6 @@ "bazel", "cypress", "express", - "insights", "jest", "nest", "next", diff --git a/docs/web/schematics.json b/docs/web/schematics.json index 59004e9c10..ada5ef03fd 100644 --- a/docs/web/schematics.json +++ b/docs/web/schematics.json @@ -3,7 +3,6 @@ "bazel", "cypress", "express", - "insights", "jest", "nest", "next", diff --git a/packages/insights/README.md b/packages/insights/README.md deleted file mode 100644 index ab664aeb8f..0000000000 --- a/packages/insights/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Nx Insights - -An optional plugin integrating Nx with Nx Insights. diff --git a/packages/insights/collection.json b/packages/insights/collection.json deleted file mode 100644 index d767e2d906..0000000000 --- a/packages/insights/collection.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "Nx Insights", - "version": "0.1", - "schematics": { - "init": { - "factory": "./src/schematics/init/init", - "schema": "./src/schematics/init/schema.json", - "description": "Initialize the @nrwl/insights plugin", - "aliases": ["ng-add"], - "hidden": true - } - } -} diff --git a/packages/insights/index.ts b/packages/insights/index.ts deleted file mode 100644 index e5d0680946..0000000000 --- a/packages/insights/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import insightsTaskRunner from './src/insights-task-runner'; - -export default insightsTaskRunner; diff --git a/packages/insights/package.json b/packages/insights/package.json deleted file mode 100644 index b1bb8f75c9..0000000000 --- a/packages/insights/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@nrwl/insights", - "version": "0.0.1", - "description": "Nx Insights plugin for Nx", - "repository": { - "type": "git", - "url": "git+https://github.com/nrwl/nx.git" - }, - "keywords": [ - "Monorepo", - "Nx", - "Insights" - ], - "main": "index.js", - "types": "index.d.ts", - "author": "Victor Savkin", - "license": "MIT", - "bugs": { - "url": "https://github.com/nrwl/nx/issues" - }, - "homepage": "https://nx.dev", - "schematics": "./collection.json", - "peerDependencies": { - "@nrwl/workspace": "*" - }, - "dependencies": { - "axios": "^0.19.0", - "tar": "5.0.5" - } -} diff --git a/packages/insights/src/insights-task-runner.ts b/packages/insights/src/insights-task-runner.ts deleted file mode 100644 index ef55d4a6d1..0000000000 --- a/packages/insights/src/insights-task-runner.ts +++ /dev/null @@ -1,298 +0,0 @@ -import { - AffectedEvent, - Task, - TaskCompleteEvent, - TasksRunner -} from '@nrwl/workspace/src/tasks-runner/tasks-runner'; -import { Observable, Subject } from 'rxjs'; -import { - tasksRunnerV2, - DefaultTasksRunnerOptions, - RemoteCache -} from '@nrwl/workspace/src/tasks-runner/tasks-runner-v2'; -import * as fs from 'fs'; -import * as path from 'path'; -import { ProjectGraph } from '@nrwl/workspace/src/core/project-graph'; -import { NxJson } from '@nrwl/workspace/src/core/shared-interfaces'; -import { writeFileSync } from 'fs'; - -const axios = require('axios'); -const tar = require('tar'); - -interface InsightsTaskRunnerOptions extends DefaultTasksRunnerOptions { - insightsUrl?: string; -} - -type Context = { - projectGraph: ProjectGraph; - target: string; - nxJson: NxJson; -}; - -class InsightsRemoteCache implements RemoteCache { - constructor(private readonly axiosInstance: any) {} - - async retrieve(hash: string, cacheDirectory: string): Promise { - try { - const resp = await this.axiosInstance({ - method: 'get', - url: `/nx-cache/${hash}`, - maxContentLength: 1000 * 1000 * 100 - }); - const tg = path.join(cacheDirectory, `${hash}.tg`); - writeFileSync(tg, resp.data, { encoding: 'base64' }); - await tar.x({ - file: tg, - cwd: cacheDirectory - }); - writeFileSync(path.join(cacheDirectory, `${hash}.commit`), 'true'); - return true; - } catch (e) { - if (e.response && e.response.status === 404) { - // cache miss. print nothing - } else if (e.code === 'ECONNREFUSED') { - console.error(`Error: Cannot connect to remote cache.`); - } else { - console.error(e.message); - } - return false; - } - } - - async store(hash: string, cacheDirectory: string): Promise { - const tg = path.join(cacheDirectory, `${hash}.tg`); - try { - await tar.c( - { - gzip: false, - file: tg, - cwd: cacheDirectory - }, - [hash] - ); - await this.axiosInstance({ - method: 'post', - url: `/nx-cache/${hash}`, - data: { tgz: fs.readFileSync(tg).toString('base64') }, - maxContentLength: 1000 * 1000 * 50 - }); - return true; - } catch (e) { - if (e.code === 'ECONNREFUSED') { - console.error(`Error: Cannot connect to remote cache.`); - } else { - console.error(e.message); - } - return false; - } - } -} - -const insightsTaskRunner: TasksRunner = ( - tasks: Task[], - options: InsightsTaskRunnerOptions, - context: Context -): Observable => { - const res = new Subject(); - - const notifier = createNotifier(options, context); - const remoteCache = createRemoteCache(options); - - let commandResult = true; - notifier.startCommand(tasks).then(() => { - tasksRunnerV2(tasks, { ...options, remoteCache }, context).subscribe({ - next: (t: TaskCompleteEvent) => { - commandResult = commandResult && t.success; - res.next(t); - notifier.endTask(t.task.id, stringifyStatus(t.success), ''); - }, - complete: () => { - notifier.endCommand(stringifyStatus(commandResult)).then(() => { - printNxInsightsStatus(notifier, commandResult); - res.complete(); - }); - } - }); - }); - - return res; -}; - -function createRemoteCache(options: InsightsTaskRunnerOptions) { - // if (!process.env.NX_INSIGHTS_AUTH_TOKEN) { - // return undefined; - // } - return new InsightsRemoteCache(createAxios(options)); -} - -function createNotifier( - options: InsightsTaskRunnerOptions, - context: Context -): Notifier { - if (!process.env.NX_INSIGHTS_AUTH_TOKEN) { - reportSetupError(`NX_INSIGHTS_AUTH_TOKEN env variable is not set.`); - return new EmptyNotifier(); - } - if ( - process.env.NX_INSIGHTS_AUTH_TOKEN && - !process.env.NX_INSIGHTS_BRANCH_ID - ) { - reportSetupError(`NX_INSIGHTS_BRANCH_ID env variable is not set.`); - return new EmptyNotifier(); - } - if (process.env.NX_INSIGHTS_AUTH_TOKEN && !process.env.NX_INSIGHTS_RUN_ID) { - reportSetupError(`NX_INSIGHTS_RUN_ID env variable is not set.`); - return new EmptyNotifier(); - } - return new InsightsNotifier(createAxios(options), context); -} - -function createAxios(options: InsightsTaskRunnerOptions) { - return axios.create({ - baseURL: options.insightsUrl || 'https://nrwl.api.io', - timeout: 30000, - headers: { authorization: `auth ${process.env.NX_INSIGHTS_AUTH_TOKEN}` } - }); -} - -function reportSetupError(reason: string) { - console.error(`WARNING: Nx won't send data to Nx Insights.`); - console.error(`Reason: ${reason}`); -} - -function printNxInsightsStatus( - notifier: EmptyNotifier, - commandResult: boolean -) { - if (notifier.errors.length > 0) { - if (commandResult) { - console.error( - `The command succeeded, but we were unable to send the data to Nx Insights:` - ); - } else { - console.error(`We were unable to send the data to Nx Insights.`); - } - console.error(`Errors:`); - console.error(notifier.errors[0]); - } -} - -function stringifyStatus(s: boolean) { - return s ? 'success' : 'failure'; -} - -interface Notifier { - errors: string[]; - - startCommand(tasks: Task[]): Promise; - - endCommand(result: string): Promise; - - endTask(taskId: string, result: string, log: string): void; -} - -class EmptyNotifier implements Notifier { - errors = []; - - startCommand(tasks: Task[]) { - return Promise.resolve(); - } - - endCommand(result: string) { - return Promise.resolve(); - } - - endTask(taskId: string, result: string, log: string) {} -} - -class InsightsNotifier implements Notifier { - errors: string[] = []; - endTaskNotifications = []; - - commandId: string; - - constructor( - private readonly axiosInstance: any, - private readonly context: Context - ) { - this.commandId = this.generateCommandId(); - } - - startCommand(tasks: Task[]) { - const files = this.collectGlobalFiles(); - const p = this.makePostRequest('nx-insights-record-start-command', { - workspaceId: '---', // should remove it - runContext: '---', // should remove it - branchId: this.envOptions.branchId, - runId: this.envOptions.runId, - commandId: this.commandId, - target: this.context.target, - packageJson: files.packageJson, - workspaceJson: files.workspaceJson, - nxJson: files.nxJson, - projectGraph: JSON.stringify(this.context.projectGraph), - startTime: new Date().toISOString() - }); - return p.then(() => tasks.map(t => this.startTask(t))); - } - - endCommand(result: string): Promise { - return Promise.all(this.endTaskNotifications).then(() => { - return this.makePostRequest('nx-insights-record-end-command', { - commandId: this.commandId, - endTime: new Date().toISOString(), - result - }); - }); - } - - endTask(taskId: string, result: string, log: string) { - this.endTaskNotifications.push( - this.makePostRequest('nx-insights-record-end-task', { - taskId, - endTime: new Date().toISOString(), - result, - log - }) - ); - } - - private get envOptions() { - return { - branchId: process.env.NX_INSIGHTS_BRANCH_ID, - runId: process.env.NX_INSIGHTS_RUN_ID - }; - } - - private startTask(task: Task) { - return this.makePostRequest('nx-insights-record-start-task', { - commandId: this.commandId, - taskId: task.id, - startTime: new Date().toISOString(), - target: task.target.target, - projectName: task.target.project - }); - } - - private collectGlobalFiles() { - return { - nxJson: fs.readFileSync('nx.json').toString(), - workspaceJson: fs.readFileSync('workspace.json').toString(), - packageJson: fs.readFileSync('package.json').toString() - }; - } - - private generateCommandId() { - return `${this.envOptions.runId}-${this.context.target}-${Math.floor( - Math.random() * 100000 - )}`; - } - - private makePostRequest(endpoint: string, post: Record) { - return this.axiosInstance.post(endpoint, post).catch(e => { - this.errors.push(e.message); - }); - } -} - -export default insightsTaskRunner; diff --git a/packages/insights/src/schematics/init/init.ts b/packages/insights/src/schematics/init/init.ts deleted file mode 100644 index 566be1f7aa..0000000000 --- a/packages/insights/src/schematics/init/init.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { updateJsonInTree } from '@nrwl/workspace'; - -export default function init() { - return updateJsonInTree('nx.json', json => { - return { - ...json, - tasksRunnerOptions: { - default: { - runner: '@nrwl/insights' - } - } - }; - }); -} diff --git a/packages/insights/src/schematics/init/schema.d.ts b/packages/insights/src/schematics/init/schema.d.ts deleted file mode 100644 index e53f1202a2..0000000000 --- a/packages/insights/src/schematics/init/schema.d.ts +++ /dev/null @@ -1 +0,0 @@ -export interface Schema {} diff --git a/packages/insights/src/schematics/init/schema.json b/packages/insights/src/schematics/init/schema.json deleted file mode 100644 index bab4bc1129..0000000000 --- a/packages/insights/src/schematics/init/schema.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema", - "id": "NxInsightsInit", - "title": "Add Nx Insights Configuration to the workspace", - "type": "object", - "properties": {} -} diff --git a/scripts/build.sh b/scripts/build.sh index ceead08b7d..9083f0f497 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -35,8 +35,8 @@ chmod +x build/packages/tao/index.js # React-specifc typings cp packages/react/typings/* build/packages/react/typings -rm -rf build/packages/install rm -rf build/packages/nx/dist +rm -rf build/packages/install rm -rf build/packages/nx/spec cp README.md build/packages/builders cp README.md build/packages/schematics @@ -57,7 +57,6 @@ cp README.md build/packages/cli cp README.md build/packages/tao cp README.md build/packages/eslint-plugin-nx cp README.md build/packages/linter -cp README.md build/packages/insights cp README.md build/packages/bazel cp LICENSE build/packages/builders @@ -79,7 +78,6 @@ cp LICENSE build/packages/cli cp LICENSE build/packages/tao cp LICENSE build/packages/eslint-plugin-nx cp LICENSE build/packages/linter -cp LICENSE build/packages/insights cp LICENSE build/packages/bazel echo "Nx libraries available at build/packages:" diff --git a/scripts/nx-release.js b/scripts/nx-release.js index 5fe57343bf..226cf67be8 100755 --- a/scripts/nx-release.js +++ b/scripts/nx-release.js @@ -163,8 +163,7 @@ const options = { 'build/npm/cli/package.json', 'build/npm/tao/package.json', 'build/npm/eslint-plugin-nx/package.json', - 'build/npm/linter/package.json', - 'build/npm/insights/package.json' + 'build/npm/linter/package.json' ], increment: parsedVersion.version, requireUpstream: false, diff --git a/scripts/package.sh b/scripts/package.sh index 796d2d5820..7967b6762f 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -18,14 +18,14 @@ cd build/packages if [[ "$OSTYPE" == "darwin"* ]]; then sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js - sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,insights,tao,eslint-plugin-nx,create-nx-workspace}/package.json + sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace}/package.json sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js else sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js - sed -i "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,insights,tao,eslint-plugin-nx,create-nx-workspace}/package.json + sed -i "s|\*|$NX_VERSION|g" {schematics,react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace}/package.json sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js @@ -34,9 +34,9 @@ fi if [[ $NX_VERSION == "*" ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then - sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,insights,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace}/package.json + sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace}/package.json else echo $PWD - sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,insights,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace}/package.json + sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {schematics,jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace}/package.json fi fi