broccoli-plugin
Advanced tools
Comparing version 3.0.0 to 3.1.0
# master | ||
# 3.1.0 | ||
- Add `this.input` and `this.ouput` to broccoli-plugin instances, this aims to replace nearly all usage of `this.inputPaths` and `this.outputPath`. See the `Readme` for further details | ||
# 3.0.0 | ||
@@ -4,0 +8,0 @@ |
import { InputNode, TransformNode, TransformNodeInfo, FeatureSet, CallbackObject } from 'broccoli-node-api'; | ||
import { MapSeriesIterator, PluginOptions } from './interfaces'; | ||
import { FSOutput } from 'broccoli-output-wrapper'; | ||
import FSMerger = require('fs-merger'); | ||
declare class Plugin implements TransformNode { | ||
@@ -36,2 +38,4 @@ private _name; | ||
readonly outputPath: string; | ||
readonly input: FSMerger.FS; | ||
readonly output: FSOutput; | ||
private _checkOverrides; | ||
@@ -38,0 +42,0 @@ __broccoliGetInfo__(builderFeatures?: FeatureSet): TransformNodeInfo; |
"use strict"; | ||
const read_compat_1 = require("./read_compat"); | ||
const buildOutputWrapper = require("broccoli-output-wrapper"); | ||
const FSMerger = require("fs-merger"); | ||
const BROCCOLI_FEATURES = Object.freeze({ | ||
@@ -11,2 +13,3 @@ persistentOutputFlag: true, | ||
const PATHS = new WeakMap(); | ||
const FSFACADE = new WeakMap(); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
@@ -93,2 +96,14 @@ function isPossibleNode(node) { | ||
} | ||
get input() { | ||
if (!FSFACADE.has(this)) { | ||
throw new Error('BroccoliPlugin: this.input is only accessible once the build has begun.'); | ||
} | ||
return FSFACADE.get(this).input; | ||
} | ||
get output() { | ||
if (!FSFACADE.has(this)) { | ||
throw new Error('BroccoliPlugin: this.output is only accessible once the build has begun.'); | ||
} | ||
return FSFACADE.get(this).output; | ||
} | ||
_checkOverrides() { | ||
@@ -148,2 +163,6 @@ if (typeof this.rebuild === 'function') { | ||
} | ||
FSFACADE.set(this, { | ||
input: new FSMerger(this._inputNodes).fs, | ||
output: buildOutputWrapper(this), | ||
}); | ||
} | ||
@@ -150,0 +169,0 @@ toString() { |
{ | ||
"name": "broccoli-plugin", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Base class for all Broccoli plugins", | ||
@@ -27,2 +27,4 @@ "keywords": [ | ||
"broccoli-node-api": "^1.6.0", | ||
"broccoli-output-wrapper": "^2.0.0", | ||
"fs-merger": "^3.0.1", | ||
"promise-map-series": "^0.2.1", | ||
@@ -56,3 +58,3 @@ "quick-temp": "^0.1.3", | ||
"rsvp": "^4.8.4", | ||
"typescript": "^3.5.3" | ||
"typescript": "^3.6.4" | ||
}, | ||
@@ -59,0 +61,0 @@ "engines": { |
@@ -24,7 +24,7 @@ # The Broccoli Plugin Base Class | ||
// Read 'foo.txt' from the third input node | ||
const input = fs.readFileSync(`${this.inputPaths[2]}/foo.txt`); | ||
const input = this.input.readFileSync(`foo.txt`); | ||
const output = someCompiler(input); | ||
// Write to 'bar.txt' in this node's output | ||
fs.writeFileSync(`${this.outputPath}/bar.txt`, output); | ||
this.output.writeFileSync(`bar.txt`, output); | ||
} | ||
@@ -125,1 +125,80 @@ } | ||
- `column`: Column in which the error occurred (zero-indexed) | ||
### `Plugin.prototype.input` | ||
An api which enables a plugin to easily read from one or more input directories ergonomically and safely. | ||
_Note: We recommend users stop using this.inputPaths and instead rely on this.input. Our plan at present is to strongly consider deprecation of this.inputPaths once this.input has had time to bake._ | ||
this.input's features: | ||
- `this.input` reads from the provided `inputPaths`. No path concatenation required. | ||
- `this.input` provides readOnly file system APIs. This prevents a plugin from erroneously mutating its inputs. | ||
- `this.input` provides a merged view of inputs, this allows every plugin to easily support multiple inputs, without the use of `broccoli-merge-trees` or implementing a complex merge algorithm. | ||
- `this.input.at(index)` provides access to each individual input if desired. | ||
Example: | ||
```js | ||
// old | ||
fs.readFileSync(this.inputPaths[0] + '/file.txt'); | ||
// new (merged): Most Common | ||
this.input.readFileSync('file.txt'); | ||
// new (indexed): For when you need to disambiguate between inputs. | ||
this.input.at(0).readFileSync('file.txt); | ||
// ReadOnly | ||
this.input.writeFileSync // throws error | ||
``` | ||
### List of Methods | ||
- readFileSync | ||
- existsSync | ||
- lstatSync | ||
- statSync | ||
- readdirSync | ||
- at | ||
Read more about `input` [here](https://github.com/SparshithNR/fs-merger#fsmergerfs) | ||
Note: `input` will be available only after the `build` starts. | ||
### `Plugin.prototype.output` | ||
An api which enables a plugin to easily write to the output directory ergonomically and safely. | ||
_Note: We recommend users stop using this.outputPath and instead rely on this.output. Our plan at present is to strongly consider deprecation of this.outputPath once this.output has had time to bake._ | ||
this.output's features: | ||
- `this.ouput` writes to the `outputPath`. No path concatenation required. | ||
- `this.output` provides read operations on the `outputPath`. No path concatenation required. | ||
Ex: | ||
```js | ||
// old | ||
fs.writeFileSync(this.outputPath + '/file.txt', 'text'); | ||
// new | ||
this.output.writeFileSync('file.txt', 'text'); | ||
``` | ||
### List of Methods | ||
- readFileSync | ||
- existsSync | ||
- lstatSync | ||
- readdirSync | ||
- statSync | ||
- writeFileSync | ||
- appendFileSync | ||
- rmdirSync | ||
- mkdirSync | ||
Read more about APIs present in `output` [here](https://github.com/SparshithNR/broccoli-output-wrapper#apis). | ||
Note: `output` will be available only after the `build` starts. |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40992
445
203
0
7
2
+ Addedfs-merger@^3.0.1
+ Added@types/minimatch@3.0.5(transitive)
+ Added@types/symlink-or-copy@1.2.2(transitive)
+ Addedbroccoli-node-info@2.2.0(transitive)
+ Addedbroccoli-output-wrapper@2.0.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedensure-posix-path@1.1.1(transitive)
+ Addedfs-extra@8.1.0(transitive)
+ Addedfs-merger@3.2.1(transitive)
+ Addedfs-tree-diff@2.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedheimdalljs@0.2.6(transitive)
+ Addedheimdalljs-logger@0.1.10(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedmatcher-collection@2.0.1(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedpath-posix@1.0.0(transitive)
+ Addedrsvp@3.2.1(transitive)
+ Addeduniversalify@0.1.2(transitive)
+ Addedwalk-sync@2.2.0(transitive)
- Removedrsvp@3.6.2(transitive)