chore(repo): remove dead code
This commit is contained in:
parent
86acf4b5e7
commit
d47d2546b8
@ -3,7 +3,6 @@
|
||||
"bazel",
|
||||
"cypress",
|
||||
"express",
|
||||
"insights",
|
||||
"jest",
|
||||
"nest",
|
||||
"next",
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
"bazel",
|
||||
"cypress",
|
||||
"express",
|
||||
"insights",
|
||||
"jest",
|
||||
"nest",
|
||||
"next",
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
"bazel",
|
||||
"cypress",
|
||||
"express",
|
||||
"insights",
|
||||
"jest",
|
||||
"nest",
|
||||
"next",
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
# Nx Insights
|
||||
|
||||
An optional plugin integrating Nx with Nx Insights.
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
import insightsTaskRunner from './src/insights-task-runner';
|
||||
|
||||
export default insightsTaskRunner;
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
@ -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<boolean> {
|
||||
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<boolean> {
|
||||
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<InsightsTaskRunnerOptions> = (
|
||||
tasks: Task[],
|
||||
options: InsightsTaskRunnerOptions,
|
||||
context: Context
|
||||
): Observable<AffectedEvent> => {
|
||||
const res = new Subject<AffectedEvent>();
|
||||
|
||||
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<any>;
|
||||
|
||||
endCommand(result: string): Promise<any>;
|
||||
|
||||
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<any> {
|
||||
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<any, any>) {
|
||||
return this.axiosInstance.post(endpoint, post).catch(e => {
|
||||
this.errors.push(e.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default insightsTaskRunner;
|
||||
@ -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'
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
export interface Schema {}
|
||||
@ -1,7 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"id": "NxInsightsInit",
|
||||
"title": "Add Nx Insights Configuration to the workspace",
|
||||
"type": "object",
|
||||
"properties": {}
|
||||
}
|
||||
@ -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:"
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user