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

Allow multiple trees as input to Filter #175

Closed
wants to merge 3 commits into from

Conversation

SparshithNR
Copy link
Contributor

@SparshithNR SparshithNR commented Aug 23, 2019

  • Using fs-merger
    1. Allow filter developers to reduce mergeTree or funneling entire array of trees to one tree and then pass it to filter
    2. Allows input array of trees as input.
  • input/output :
    1. Provides good ergonomics and avoids appending the this.outputPath
  • Test:
    1. Added additional tests to make sure that Filter can take more than one tree

Example:

class Awk extends Filter {
  constructor(inputNode, search, replace, options) {
    options = options || {};
    super(inputNode, {
      annotation: options.annotation
    });
    this.search = search;
    this.replace = replace;
    this.extensions = ['txt'];
    this.targetExtension = 'txt';
  }
  processString(content, relativePath) {
    return content.replace(this.search, this.replace);
  };
}
module.exports = new Awk(['fixture','fixture_2'], 'test', 'real');

Since we are now allowing users to pass two paths/nodes. We avoid a uncessary merge/funnel.
Before to achive the above result we had to below sinppet.

let fullTree = mergeTree(['fixture','fixture_2'];
module.exports = new Awk(fullTree, 'test', 'real');

@SparshithNR SparshithNR reopened this Aug 28, 2019
@SparshithNR SparshithNR changed the title [WIP] Using fs-merger module to facilitate array of trees as input to persistent filter Using fs-merger module to facilitate array of trees as input to persistent filter Aug 28, 2019
Copy link
Contributor

@chriseppstein chriseppstein left a comment

Choose a reason for hiding this comment

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

I didn't review everything, but I have enough questions to pause at this point.

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
lib/dependencies.js Outdated Show resolved Hide resolved
@SparshithNR SparshithNR changed the title Using fs-merger module to facilitate array of trees as input to persistent filter Use inout/output feature from broccoli-plugin Dec 6, 2019
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
test/test.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
Using fs-merger
1. Allow filter developers to reduce mergeTree or funneling entire array of trees to one tree and then pass it to filter
2. Allows input array of trees as input.

input/output :
1. Provides good ergonomics and avoids appending the this.outputPath

Test:
1. Added additional tests to make sure that Filter can take more than one tree
@@ -104,8 +101,19 @@ module.exports = class Filter extends Plugin {
return !!result;
}

constructor(inputTree, options) {
super([inputTree], {
get fsMerger() {
Copy link
Collaborator

@stefanpenner stefanpenner Dec 12, 2019

Choose a reason for hiding this comment

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

as implemented fsMerger is still part of the public API for subclasses, this seems sorta strange given the above weakmap usage.

index.js Outdated Show resolved Hide resolved
@SparshithNR SparshithNR changed the title Use inout/output feature from broccoli-plugin Allow multiple trees as input to Filter Dec 12, 2019
@SparshithNR
Copy link
Contributor Author

Input output facade is addressed in #187.
We will address allowing multiple trees as input in this PR.

try {
let result;
let srcPath = srcDir + '/' + relativePath;
let srcDir = this.inputPaths[0]; // keeping this line to maintain the signature of the fn.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using this.inputPaths[0] here is breaking encapsulation, post this.input and this.output migration it should be possible to use only the new APIs, what features are missing or different approaches are required to make this statement true.

let forceInvalidation = invalidated.includes(relativePath);

this._logger.debug('[operation:%s] %s', operation, relativePath);

switch (operation) {
case 'mkdir': {
instrumentation.mkdir++;
return fs.mkdirSync(outputPath);
return this.output.mkdirSync(outputPath, { recursive: true });
Copy link
Collaborator

Choose a reason for hiding this comment

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


if (this.dependencyInvalidation && !this.dependencies) {
this.dependencies = this.processor.initialDependencies(srcDir);
this.dependencies = this.processor.initialDependencies(this.inputPaths);
Copy link
Collaborator

Choose a reason for hiding this comment

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

^^

@@ -121,6 +129,10 @@ module.exports = class Filter extends Plugin {
loggerName += ' > [' + annotation + ']';
}

FSMERGER.set(this, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently I am worried, that this plugin does not use this.input, did we make a mistake with it? By not using this.input we are making it hard for future optimizations, as ensuring all plugins go through this.input this.output opens many doors when it comes to future optimizations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may have to make changes to the fs-merger library to somehow match inputPaths and input to broccoli-persistent-filter where we expect input can be broccoli-node string or an object with prefix/getDestinationPath function.

@SparshithNR
Copy link
Contributor Author

Closing this as #188 is addressing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants