Socket
Socket
Sign inDemoInstall

@nrwl/nx-cloud

Package Overview
Dependencies
Maintainers
1
Versions
343
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nrwl/nx-cloud - npm Package Compare versions

Comparing version 8.12.5 to 9.0.0

239

lib/nx-cloud-task-runner.js

@@ -1,238 +0,1 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const tasks_runner_v2_1 = require("@nrwl/workspace/src/tasks-runner/tasks-runner-v2");
const fs = require("fs");
const fs_1 = require("fs");
const path = require("path");
const uuid_1 = require("uuid");
const operators_1 = require("rxjs/operators");
const axios = require('axios');
const tar = require('tar');
class CloudApi {
constructor(baseUrl, authToken) {
this.uniqRunId = uuid_1.v4();
const [_, access] = new Buffer(authToken, 'base64').toString().split('|');
this.isReadWrite = access === 'read-write';
this.axiosInstance = axios.create({
baseURL: baseUrl,
timeout: 30000,
headers: { authorization: authToken }
});
}
startTask(task) {
return this.axiosInstance.post('/nx-cloud/tasks/start', {
taskId: `${task.id}-${this.uniqRunId}`,
startTime: new Date().toISOString(),
target: task.target.target,
projectName: task.target.project,
hash: task.hash
});
}
endTask(task) {
return this.axiosInstance.post('/nx-cloud/tasks/end', {
taskId: `${task.id}-${this.uniqRunId}`,
endTime: new Date().toISOString()
});
}
storeCache(hash) {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield this.axiosInstance({
method: 'get',
url: `/nx-cloud/cache/store/${hash}`
});
if (!resp.data || !resp.data.url || !(typeof resp.data.url === 'string')) {
throw new Error(`Invalid remote cache response: ${JSON.stringify(resp.data)}`);
}
return resp.data.url;
});
}
retrieveCache(hash) {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield this.axiosInstance({
method: 'get',
url: `/nx-cloud/cache/${hash}`
});
if (!resp.data || !resp.data.url || !(typeof resp.data.url === 'string')) {
throw new Error(`Invalid remote cache response: ${JSON.stringify(resp.data)}`);
}
return resp.data.url;
});
}
}
class CloudRemoteCache {
constructor(errors, api) {
this.errors = errors;
this.api = api;
}
retrieve(hash, cacheDirectory) {
return __awaiter(this, void 0, void 0, function* () {
try {
const url = yield this.api.retrieveCache(hash);
const tgz = this.createFileName(hash, cacheDirectory);
yield this.downloadFile(url, tgz);
this.createCommitFile(hash, cacheDirectory);
return true;
}
catch (e) {
if (e.response && e.response.status === 404) {
// cache miss. print nothing
}
else {
this.addErrorMessage(e);
}
return false;
}
});
}
store(hash, cacheDirectory) {
return __awaiter(this, void 0, void 0, function* () {
if (this.api.isReadWrite) {
try {
const url = yield this.api.storeCache(hash);
const tgz = yield this.createFile(hash, cacheDirectory);
yield this.uploadFile(url, tgz);
return true;
}
catch (e) {
this.addErrorMessage(e);
return false;
}
}
else {
return true;
}
});
}
addErrorMessage(e) {
if (e.code === 'ECONNREFUSED' ||
e.code === 'EAI_AGAIN' ||
e.code === 'ENOTFOUND') {
this.errors.cacheError = `Cannot connect to remote cache.`;
}
else if (e.response.status === 401) {
this.errors.cacheError = `Invalid Nx Cloud access token.`;
}
else {
this.errors.cacheError = e.message;
}
}
createFileName(hash, cacheDirectory) {
return path.join(cacheDirectory, `${hash}.tar.gz`);
}
downloadFile(url, tgz) {
return __awaiter(this, void 0, void 0, function* () {
const resp = yield axios(url, {
method: 'GET',
responseType: 'stream',
maxContentLength: 1000 * 1000 * 200
});
const q = resp.data.pipe(tar.x({
cwd: path.dirname(tgz)
}));
return new Promise(res => {
q.on('close', () => {
res();
});
});
});
}
createCommitFile(hash, cacheDirectory) {
fs_1.writeFileSync(path.join(cacheDirectory, `${hash}.commit`), 'true');
}
createFile(hash, cacheDirectory) {
return __awaiter(this, void 0, void 0, function* () {
const tgz = this.createFileName(hash, cacheDirectory);
yield tar.c({
gzip: true,
file: tgz,
cwd: cacheDirectory
}, [hash]);
return tgz;
});
}
uploadFile(url, tgz) {
return __awaiter(this, void 0, void 0, function* () {
yield axios(url, {
method: 'PUT',
data: fs.readFileSync(tgz),
headers: { 'Content-Type': 'application/octet-stream' },
maxContentLength: 1000 * 1000 * 200
});
});
}
}
const nxCloudTaskRunner = (tasks, options, context) => {
if (process.env.NX_CLOUD_AUTH_TOKEN || options.accessToken) {
const api = createApi(options);
const errors = new ErrorReporter();
const lifeCycle = new TaskRunnerLifeCycle(errors, api);
const remoteCache = new CloudRemoteCache(errors, api);
const res = tasks_runner_v2_1.tasksRunnerV2(tasks, Object.assign({}, options, { remoteCache, lifeCycle }), context);
return lifeCycle.complete().pipe(operators_1.tap(() => errors.printErrors()), operators_1.concatMap(() => res));
}
else {
return tasks_runner_v2_1.tasksRunnerV2(tasks, options, context);
}
};
class TaskRunnerLifeCycle {
constructor(errors, api) {
this.errors = errors;
this.api = api;
this.promises = {};
}
startTask(task) {
if (this.api.isReadWrite) {
this.promises[`${task.id}-start`] = this.api.startTask(task).catch(e => {
this.errors.lifeCycleError = e.message;
});
}
}
endTask(task, code) {
if (this.api.isReadWrite) {
const endPromise = this.promises[`${task.id}-start`]
.then(() => {
return this.api.endTask(task);
})
.catch((e) => {
this.errors.lifeCycleError = e.message;
});
this.promises[`${task.id}-end`] = endPromise;
}
}
complete() {
return rxjs_1.from(Promise.all(Object.values(this.promises)));
}
}
class ErrorReporter {
constructor() {
this.cacheError = null;
this.lifeCycleError = null;
}
printErrors() {
if (this.cacheError || this.lifeCycleError) {
console.warn(`Nx Cloud Errors:`);
console.error(`- ${this.cacheError}`);
console.error(`- ${this.lifeCycleError}`);
}
}
}
function createApi(options) {
const baseUrl = options.url || 'https://api.nrwl.io';
if (process.env.NX_CLOUD_AUTH_TOKEN) {
return new CloudApi(baseUrl, process.env.NX_CLOUD_AUTH_TOKEN);
}
else {
return new CloudApi(baseUrl, options.accessToken);
}
}
exports.default = nxCloudTaskRunner;
//# sourceMappingURL=nx-cloud-task-runner.js.map
const a0_0x4df7=['https://api.nrwl.io','endTask','axios','base64','post','path','uuid','from','toString','all','GET','value','createFileName','code','split','NX_CLOUD_AUTH_TOKEN','defineProperty','toISOString','rxjs/operators','uploadFile','createFile','tar','message','throw','api','downloadFile','stream','true','response','Nx\x20Cloud\x20Errors:','startTask','Invalid\x20remote\x20cache\x20response:\x20','read-write','lifeCycleError','assign','isReadWrite','env','.tar.gz','store','error','-start','done','stringify','/nx-cloud/tasks/end','readFileSync','complete','target','writeFileSync','rxjs','url','values','create','storeCache','cacheError','/nx-cloud/cache/store/','errors','createCommitFile','/nx-cloud/cache/','pipe','.commit','-end','@nrwl/workspace/src/tasks-runner/tasks-runner-v2','data','string','axiosInstance','printErrors','default','uniqRunId','join','get','retrieve','hash','__awaiter','PUT','retrieveCache','addErrorMessage','__esModule','then','concatMap','catch','promises','application/octet-stream','Invalid\x20Nx\x20Cloud\x20access\x20token.','status','next'];(function(_0x574cb0,_0x4df72a){const _0x296b3c=function(_0x2e4dd2){while(--_0x2e4dd2){_0x574cb0['push'](_0x574cb0['shift']());}};_0x296b3c(++_0x4df72a);}(a0_0x4df7,0x7a));const a0_0x296b=function(_0x574cb0,_0x4df72a){_0x574cb0=_0x574cb0-0x0;let _0x296b3c=a0_0x4df7[_0x574cb0];return _0x296b3c;};'use strict';var __awaiter=this&&this[a0_0x296b('0x23')]||function(_0x24b513,_0xa0297,_0x41ec66,_0x447181){function _0x7e2a1d(_0x391eb4){return _0x391eb4 instanceof _0x41ec66?_0x391eb4:new _0x41ec66(function(_0x3f0bf2){_0x3f0bf2(_0x391eb4);});}return new(_0x41ec66||(_0x41ec66=Promise))(function(_0x816a79,_0x476d6e){function _0xfeed11(_0x311c95){try{_0x1dae8a(_0x447181['next'](_0x311c95));}catch(_0x474eff){_0x476d6e(_0x474eff);}}function _0x228143(_0x497467){try{_0x1dae8a(_0x447181[a0_0x296b('0x47')](_0x497467));}catch(_0x464df4){_0x476d6e(_0x464df4);}}function _0x1dae8a(_0x5c185d){_0x5c185d[a0_0x296b('0x4')]?_0x816a79(_0x5c185d[a0_0x296b('0x3b')]):_0x7e2a1d(_0x5c185d['value'])[a0_0x296b('0x28')](_0xfeed11,_0x228143);}_0x1dae8a((_0x447181=_0x447181['apply'](_0x24b513,_0xa0297||[]))[a0_0x296b('0x2f')]());});};Object[a0_0x296b('0x40')](exports,a0_0x296b('0x27'),{'value':!![]});const rxjs_1=require(a0_0x296b('0xb'));const tasks_runner_v2_1=require(a0_0x296b('0x18'));const fs=require('fs');const fs_1=require('fs');const path=require(a0_0x296b('0x35'));const uuid_1=require(a0_0x296b('0x36'));const operators_1=require(a0_0x296b('0x42'));const axios=require(a0_0x296b('0x32'));const tar=require(a0_0x296b('0x45'));class CloudApi{constructor(_0x332dca,_0x2d3c78){this[a0_0x296b('0x1e')]=uuid_1['v4']();const [_0x342fb7,_0x67e950]=new Buffer(_0x2d3c78,a0_0x296b('0x33'))[a0_0x296b('0x38')]()[a0_0x296b('0x3e')]('|');this[a0_0x296b('0x53')]=_0x67e950===a0_0x296b('0x50');this['axiosInstance']=axios[a0_0x296b('0xe')]({'baseURL':_0x332dca,'timeout':0x7530,'headers':{'authorization':_0x2d3c78}});}[a0_0x296b('0x4e')](_0x2735ac){return this[a0_0x296b('0x1b')]['post']('/nx-cloud/tasks/start',{'taskId':_0x2735ac['id']+'-'+this[a0_0x296b('0x1e')],'startTime':new Date()[a0_0x296b('0x41')](),'target':_0x2735ac[a0_0x296b('0x9')][a0_0x296b('0x9')],'projectName':_0x2735ac[a0_0x296b('0x9')]['project'],'hash':_0x2735ac[a0_0x296b('0x22')]});}[a0_0x296b('0x31')](_0x184e99){return this[a0_0x296b('0x1b')][a0_0x296b('0x34')](a0_0x296b('0x6'),{'taskId':_0x184e99['id']+'-'+this[a0_0x296b('0x1e')],'endTime':new Date()[a0_0x296b('0x41')]()});}[a0_0x296b('0xf')](_0x325071){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xf4b60e=yield this[a0_0x296b('0x1b')]({'method':a0_0x296b('0x20'),'url':a0_0x296b('0x11')+_0x325071});if(!_0xf4b60e[a0_0x296b('0x19')]||!_0xf4b60e['data']['url']||!(typeof _0xf4b60e[a0_0x296b('0x19')][a0_0x296b('0xc')]===a0_0x296b('0x1a'))){throw new Error(a0_0x296b('0x4f')+JSON['stringify'](_0xf4b60e[a0_0x296b('0x19')]));}return _0xf4b60e[a0_0x296b('0x19')]['url'];});}['retrieveCache'](_0x19bb6c){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1a854f=yield this['axiosInstance']({'method':a0_0x296b('0x20'),'url':a0_0x296b('0x14')+_0x19bb6c});if(!_0x1a854f[a0_0x296b('0x19')]||!_0x1a854f[a0_0x296b('0x19')]['url']||!(typeof _0x1a854f[a0_0x296b('0x19')]['url']===a0_0x296b('0x1a'))){throw new Error('Invalid\x20remote\x20cache\x20response:\x20'+JSON[a0_0x296b('0x5')](_0x1a854f[a0_0x296b('0x19')]));}return _0x1a854f[a0_0x296b('0x19')]['url'];});}}class CloudRemoteCache{constructor(_0x233864,_0x3d40f6){this[a0_0x296b('0x12')]=_0x233864;this[a0_0x296b('0x48')]=_0x3d40f6;}[a0_0x296b('0x21')](_0x42cbd1,_0x1e51c8){return __awaiter(this,void 0x0,void 0x0,function*(){try{const _0x488200=yield this[a0_0x296b('0x48')][a0_0x296b('0x25')](_0x42cbd1);const _0x24bdec=this[a0_0x296b('0x3c')](_0x42cbd1,_0x1e51c8);yield this[a0_0x296b('0x49')](_0x488200,_0x24bdec);this['createCommitFile'](_0x42cbd1,_0x1e51c8);return!![];}catch(_0x42807a){if(_0x42807a[a0_0x296b('0x4c')]&&_0x42807a[a0_0x296b('0x4c')]['status']===0x194){}else{this[a0_0x296b('0x26')](_0x42807a);}return![];}});}[a0_0x296b('0x1')](_0x2bcaf1,_0x167172){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a0_0x296b('0x48')][a0_0x296b('0x53')]){try{const _0x522108=yield this[a0_0x296b('0x48')][a0_0x296b('0xf')](_0x2bcaf1);const _0x33edb9=yield this[a0_0x296b('0x44')](_0x2bcaf1,_0x167172);yield this[a0_0x296b('0x43')](_0x522108,_0x33edb9);return!![];}catch(_0xeceaf7){this[a0_0x296b('0x26')](_0xeceaf7);return![];}}else{return!![];}});}['addErrorMessage'](_0x1e7a9f){if(_0x1e7a9f[a0_0x296b('0x3d')]==='ECONNREFUSED'||_0x1e7a9f[a0_0x296b('0x3d')]==='EAI_AGAIN'||_0x1e7a9f['code']==='ENOTFOUND'){this[a0_0x296b('0x12')][a0_0x296b('0x10')]='Cannot\x20connect\x20to\x20remote\x20cache.';}else if(_0x1e7a9f['response'][a0_0x296b('0x2e')]===0x191){this[a0_0x296b('0x12')][a0_0x296b('0x10')]=a0_0x296b('0x2d');}else{this[a0_0x296b('0x12')][a0_0x296b('0x10')]=_0x1e7a9f[a0_0x296b('0x46')];}}[a0_0x296b('0x3c')](_0x48b783,_0x4e3922){return path[a0_0x296b('0x1f')](_0x4e3922,_0x48b783+a0_0x296b('0x0'));}[a0_0x296b('0x49')](_0x27486f,_0x285682){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x5276e2=yield axios(_0x27486f,{'method':a0_0x296b('0x3a'),'responseType':a0_0x296b('0x4a'),'maxContentLength':0x3e8*0x3e8*0xc8});const _0x377f3b=_0x5276e2[a0_0x296b('0x19')][a0_0x296b('0x15')](tar['x']({'cwd':path['dirname'](_0x285682)}));return new Promise(_0xb1bf3e=>{_0x377f3b['on']('close',()=>{_0xb1bf3e();});});});}[a0_0x296b('0x13')](_0x57f295,_0x1348f){fs_1[a0_0x296b('0xa')](path[a0_0x296b('0x1f')](_0x1348f,_0x57f295+a0_0x296b('0x16')),a0_0x296b('0x4b'));}[a0_0x296b('0x44')](_0x1d6211,_0x317f21){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x40cd6d=this[a0_0x296b('0x3c')](_0x1d6211,_0x317f21);yield tar['c']({'gzip':!![],'file':_0x40cd6d,'cwd':_0x317f21},[_0x1d6211]);return _0x40cd6d;});}[a0_0x296b('0x43')](_0x45ffc5,_0x531e00){return __awaiter(this,void 0x0,void 0x0,function*(){yield axios(_0x45ffc5,{'method':a0_0x296b('0x24'),'data':fs[a0_0x296b('0x7')](_0x531e00),'headers':{'Content-Type':a0_0x296b('0x2c')},'maxContentLength':0x3e8*0x3e8*0xc8});});}}const nxCloudTaskRunner=(_0x3bc2d0,_0x2b401b,_0x47dd4f)=>{if(process[a0_0x296b('0x54')]['NX_CLOUD_AUTH_TOKEN']||_0x2b401b['accessToken']){const _0x34b145=createApi(_0x2b401b);const _0x360e4c=new ErrorReporter();const _0x3ef8f0=new TaskRunnerLifeCycle(_0x360e4c,_0x34b145);const _0x316c09=new CloudRemoteCache(_0x360e4c,_0x34b145);const _0x162b0c=tasks_runner_v2_1['tasksRunnerV2'](_0x3bc2d0,Object['assign'](Object[a0_0x296b('0x52')]({},_0x2b401b),{'remoteCache':_0x316c09,'lifeCycle':_0x3ef8f0}),_0x47dd4f);return _0x3ef8f0[a0_0x296b('0x8')]()[a0_0x296b('0x15')](operators_1['tap'](()=>_0x360e4c[a0_0x296b('0x1c')]()),operators_1[a0_0x296b('0x29')](()=>_0x162b0c));}else{return tasks_runner_v2_1['tasksRunnerV2'](_0x3bc2d0,_0x2b401b,_0x47dd4f);}};class TaskRunnerLifeCycle{constructor(_0x5e4cfb,_0x9da718){this[a0_0x296b('0x12')]=_0x5e4cfb;this[a0_0x296b('0x48')]=_0x9da718;this[a0_0x296b('0x2b')]={};}[a0_0x296b('0x4e')](_0xb21ea4){if(this[a0_0x296b('0x48')][a0_0x296b('0x53')]){this[a0_0x296b('0x2b')][_0xb21ea4['id']+a0_0x296b('0x3')]=this[a0_0x296b('0x48')][a0_0x296b('0x4e')](_0xb21ea4)[a0_0x296b('0x2a')](_0x7f2d32=>{this['errors'][a0_0x296b('0x51')]=_0x7f2d32['message'];});}}[a0_0x296b('0x31')](_0xd8348e,_0x47a0a1){if(this['api'][a0_0x296b('0x53')]){const _0x204d9d=this[a0_0x296b('0x2b')][_0xd8348e['id']+a0_0x296b('0x3')][a0_0x296b('0x28')](()=>{return this[a0_0x296b('0x48')][a0_0x296b('0x31')](_0xd8348e);})[a0_0x296b('0x2a')](_0x365710=>{this[a0_0x296b('0x12')][a0_0x296b('0x51')]=_0x365710[a0_0x296b('0x46')];});this[a0_0x296b('0x2b')][_0xd8348e['id']+a0_0x296b('0x17')]=_0x204d9d;}}[a0_0x296b('0x8')](){return rxjs_1[a0_0x296b('0x37')](Promise[a0_0x296b('0x39')](Object[a0_0x296b('0xd')](this['promises'])));}}class ErrorReporter{constructor(){this[a0_0x296b('0x10')]=null;this[a0_0x296b('0x51')]=null;}[a0_0x296b('0x1c')](){if(this[a0_0x296b('0x10')]||this[a0_0x296b('0x51')]){console['warn'](a0_0x296b('0x4d'));console[a0_0x296b('0x2')]('-\x20'+this[a0_0x296b('0x10')]);console[a0_0x296b('0x2')]('-\x20'+this['lifeCycleError']);}}}function createApi(_0x3946df){const _0x4864bb=_0x3946df[a0_0x296b('0xc')]||a0_0x296b('0x30');if(process[a0_0x296b('0x54')]['NX_CLOUD_AUTH_TOKEN']){return new CloudApi(_0x4864bb,process[a0_0x296b('0x54')][a0_0x296b('0x3f')]);}else{return new CloudApi(_0x4864bb,_0x3946df['accessToken']);}}exports[a0_0x296b('0x1d')]=nxCloudTaskRunner;

3

lib/schematics/init/init.d.ts

@@ -1,1 +0,2 @@

export default function init(): import("@angular-devkit/schematics").Rule;
import { Schema } from './schema';
export default function init(ops: Schema): import("@angular-devkit/schematics").Rule;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const workspace_1 = require("@nrwl/workspace");
function init() {
function init(ops) {
return workspace_1.updateJsonInTree('nx.json', json => {
return Object.assign({}, json, { tasksRunnerOptions: {
return Object.assign(Object.assign({}, json), { tasksRunnerOptions: {
default: {
runner: '@nrwl/nx-cloud',
options: {
accessToken: ops.token,
cacheableOperations: ['build', 'test', 'lint']

@@ -11,0 +12,0 @@ }

@@ -6,3 +6,10 @@ {

"type": "object",
"properties": {}
"properties": {
"token": {
"type": "string",
"description": "Nx Cloud access token. You can generate one at https://nx.app."
}
},
"additionalProperties": false,
"required": ["token"]
}
{
"name": "@nrwl/nx-cloud",
"version": "8.12.5",
"version": "9.0.0",
"description": "Nx Cloud plugin for Nx",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc