Skip to content

Commit

Permalink
[fix] running lint as a seperate CI task and fixes all errors to ensu…
Browse files Browse the repository at this point in the history
…re CI passes (#463)

* [fix] running lint as a seperate CI task and fixes all errors to ensure CI passes

* fixes lint rules by adding typescript recommended, will have to fix types as they are failing now

* fixes types and found a bug with ui.writeError

* fixes failing test

* fix failing test

* fixes more tests
  • Loading branch information
gabrielcsapo committed May 12, 2020
1 parent cbc6c4a commit 337f616
Show file tree
Hide file tree
Showing 45 changed files with 538 additions and 880 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
sourceType: 'module',
},
plugins: ['node', 'prettier'],
extends: ['eslint:recommended', 'plugin:node/recommended'],
extends: ['eslint:recommended', 'plugin:node/recommended', 'plugin:@typescript-eslint/recommended'],
env: {
node: true,
},
Expand All @@ -19,6 +19,7 @@ module.exports = {
'node/no-missing-require': ['error', {
'tryExtensions': ['.js', '.json', '.node', '.ts'],
}],
'@typescript-eslint/ban-ts-ignore': 'off',
'node/no-missing-import': 'off',
'node/no-unsupported-features': 'off',
'node/no-unsupported-features/es-syntax': 'off',
Expand All @@ -31,6 +32,7 @@ module.exports = {
mocha: true,
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
'mocha/no-exclusive-tests': 'error',
'mocha/handle-done-callback': 'error',
},
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on:
pull_request:
push:
# filtering branches here, prevents duplicate builds from pull_request and push
branches:
branches:
- master
- 'v*'
# always run CI for tags
tags:
- '*'
# early issue detection, run CI weekly on Sundays

# early issue detection, run CI weekly on Sundays
schedule:
- cron: '0 6 * * 0'

Expand All @@ -26,17 +26,20 @@ jobs:

steps:
- uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
version: ${{ matrix.node_version }}

- name: install yarn
run: npm install -g yarn cross-env

- name: install dependencies
run: yarn install --frozen-lockfile

- name: lint
run: yarn lint

- name: test
run: cross-env CI=true yarn test
run: cross-env CI=true yarn test
158 changes: 81 additions & 77 deletions lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,83 @@ import filterMap from './utils/filter-map';
import { EventEmitter } from 'events';
import { TransformNode, SourceNode, Node } from 'broccoli-node-api';
import NodeWrapper from './wrappers/node';
import heimdall from 'heimdalljs';
import underscoreString from 'underscore.string';
// @ts-ignore
import broccoliNodeInfo from 'broccoli-node-info';
import HeimdallLogger from 'heimdalljs-logger';

const heimdall = require('heimdalljs');
const underscoreString = require('underscore.string');
const broccoliNodeInfo = require('broccoli-node-info');
const logger = require('heimdalljs-logger')('broccoli:builder');
const logger = new HeimdallLogger('broccoli:builder');

// Clean up left-over temporary directories on uncaught exception.
tmp.setGracefulCleanup();

function reParentNodes(outputNodeWrapper: any) {
// re-parent heimdall nodes according to input nodes
const seen = new Set();
const queue = [outputNodeWrapper];
let node;
let parent;
const stack: any = [];
while ((node = queue.pop()) !== undefined) {
if (parent === node) {
parent = stack.pop();
} else {
queue.push(node);

let heimdallNode = node.__heimdall__;
if (heimdallNode === undefined || seen.has(heimdallNode)) {
// make 0 time node
const cookie = heimdall.start(Object.assign({}, heimdallNode.id));
heimdallNode = heimdall.current;
heimdallNode.id.broccoliCachedNode = true;
cookie.stop();
heimdallNode.stats.time.self = 0;
} else {
seen.add(heimdallNode);
// Only push children for non "cached inputs"
const inputNodeWrappers = node.inputNodeWrappers;
for (let i = inputNodeWrappers.length - 1; i >= 0; i--) {
queue.push(inputNodeWrappers[i]);
}
}

if (parent) {
heimdallNode.remove();
parent.__heimdall__.addChild(heimdallNode);
stack.push(parent);
}
parent = node;
}
}
}

function aggregateTime() {
const queue = [heimdall.current];
const stack: any = [];
let parent;
let node;
while ((node = queue.pop()) !== undefined) {
if (parent === node) {
parent = stack.pop();
if (parent !== undefined) {
parent.stats.time.total += node.stats.time.total;
}
} else {
const children = node._children;
queue.push(node);
for (let i = children.length - 1; i >= 0; i--) {
queue.push(children[i]);
}
if (parent) {
stack.push(parent);
}
node.stats.time.total = node.stats.time.self;
parent = node;
}
}
}

interface BuilderOptions {
tmpdir?: string | null;
}
Expand Down Expand Up @@ -170,7 +238,7 @@ class Builder extends EventEmitter {
await pipeline;
this.buildHeimdallTree(this.outputNodeWrapper);
} finally {
let buildsSkipped = filterMap(
const buildsSkipped = filterMap(
this._nodeWrappers.values(),
(nw: NodeWrappers) => nw.buildState.built === false
).length;
Expand Down Expand Up @@ -198,7 +266,7 @@ class Builder extends EventEmitter {
// This method recursively traverses the node graph and returns a nodeWrapper.
// The nodeWrapper graph parallels the node graph 1:1.
makeNodeWrapper(node: Node, _stack: any = []) {
let wrapper = this._nodeWrappers.get(node);
const wrapper = this._nodeWrappers.get(node);
if (wrapper !== undefined) {
return wrapper;
}
Expand Down Expand Up @@ -337,9 +405,11 @@ class Builder extends EventEmitter {
this.builderTmpDir = tmpObj.name;
this.builderTmpDirCleanup = tmpObj.removeCallback;

for (let nodeWrapper of this._nodeWrappers.values()) {
for (const nodeWrapper of this._nodeWrappers.values()) {
if (nodeWrapper.nodeInfo.nodeType === 'transform') {
(nodeWrapper as TransformNodeWrapper).inputPaths = nodeWrapper.inputNodeWrappers.map((nw: any) => nw.outputPath);
(nodeWrapper as TransformNodeWrapper).inputPaths = nodeWrapper.inputNodeWrappers.map(
(nw: any) => nw.outputPath
);
nodeWrapper.outputPath = this.mkTmpDir(nodeWrapper, 'out');

if (nodeWrapper.nodeInfo.needsCache) {
Expand All @@ -357,7 +427,7 @@ class Builder extends EventEmitter {
// /tmp/broccoli-9rLfJh/out-067-merge_trees_vendor_packages
// type is 'out' or 'cache'
mkTmpDir(nodeWrapper: NodeWrappers, type: 'out' | 'cache') {
let nameAndAnnotation =
const nameAndAnnotation =
nodeWrapper.nodeInfo.name + ' ' + (nodeWrapper.nodeInfo.annotation || '');
// slugify turns fooBar into foobar, so we call underscored first to
// preserve word boundaries
Expand All @@ -381,7 +451,7 @@ class Builder extends EventEmitter {
}

setupNodes() {
for (let nw of this._nodeWrappers.values()) {
for (const nw of this._nodeWrappers.values()) {
try {
nw.setup(this.features);
} catch (err) {
Expand All @@ -400,7 +470,7 @@ class Builder extends EventEmitter {
name = node.nodeInfo.annotation || node.nodeInfo.name;
}

node.__heimdall_cookie__ = heimdall.start({
node['__heimdall_cookie__'] = heimdall.start({
name,
label: node.label,
broccoliNode: true,
Expand Down Expand Up @@ -437,70 +507,4 @@ class Builder extends EventEmitter {
}
}

function reParentNodes(outputNodeWrapper: any) {
// re-parent heimdall nodes according to input nodes
const seen = new Set();
const queue = [outputNodeWrapper];
let node;
let parent;
let stack: any = [];
while ((node = queue.pop()) !== undefined) {
if (parent === node) {
parent = stack.pop();
} else {
queue.push(node);

let heimdallNode = node.__heimdall__;
if (heimdallNode === undefined || seen.has(heimdallNode)) {
// make 0 time node
const cookie = heimdall.start(Object.assign({}, heimdallNode.id));
heimdallNode = heimdall.current;
heimdallNode.id.broccoliCachedNode = true;
cookie.stop();
heimdallNode.stats.time.self = 0;
} else {
seen.add(heimdallNode);
// Only push children for non "cached inputs"
const inputNodeWrappers = node.inputNodeWrappers;
for (let i = inputNodeWrappers.length - 1; i >= 0; i--) {
queue.push(inputNodeWrappers[i]);
}
}

if (parent) {
heimdallNode.remove();
parent.__heimdall__.addChild(heimdallNode);
stack.push(parent);
}
parent = node;
}
}
}

function aggregateTime() {
let queue = [heimdall.current];
let stack: any = [];
let parent;
let node;
while ((node = queue.pop()) !== undefined) {
if (parent === node) {
parent = stack.pop();
if (parent !== undefined) {
parent.stats.time.total += node.stats.time.total;
}
} else {
const children = node._children;
queue.push(node);
for (let i = children.length - 1; i >= 0; i--) {
queue.push(children[i]);
}
if (parent) {
stack.push(parent);
}
node.stats.time.total = node.stats.time.self;
parent = node;
}
}
}

export = Builder;
1 change: 1 addition & 0 deletions lib/cancelation-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class CancelationRequest {
}

then() {
// eslint-disable-next-line prefer-rest-params
return this._pendingWork.then(...arguments);
}

Expand Down

0 comments on commit 337f616

Please sign in to comment.