Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

broccoli

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli - npm Package Compare versions

Comparing version 0.15.3 to 0.15.4

6

CHANGELOG.md
# master
# 0.15.4
* Send `Cache-Control` header for directory listings and redirects
* Honor `liveReloadPath` middleware option in directory listings as well
* Add `autoIndex` middleware option to disable directory listings
# 0.15.3

@@ -4,0 +10,0 @@

36

lib/middleware.js

@@ -11,4 +11,8 @@ var path = require('path')

module.exports = function(watcher/* , options */) {
var options = arguments[1] || {};
// Supported options:
// autoIndex (default: true) - set to false to disable directory listings
// liveReloadPath - LiveReload script URL for error pages
module.exports = function(watcher, options) {
if (options == null) options = {}
if (options.autoIndex == null) options.autoIndex = true

@@ -34,3 +38,3 @@ return function broccoliMiddleware(request, response, next) {

} catch (e) {
// 404
// not found
next()

@@ -41,2 +45,9 @@ return

if (stat.isDirectory()) {
var hasIndex = fs.existsSync(path.join(filename, 'index.html'))
if (!hasIndex && !options.autoIndex) {
next()
return
}
// If no trailing slash, redirect. We use path.sep because filename

@@ -47,2 +58,3 @@ // has backslashes on Windows.

response.setHeader('Location', url.format(urlObj))
response.setHeader('Cache-Control', 'private, max-age=0, must-revalidate')
response.writeHead(301)

@@ -53,7 +65,4 @@ response.end()

// if folder doesn't contain an index.html file,
// browse the folder
if (!fs.existsSync(filename + 'index.html')) {
response.writeHead(200)
response.end(dirTemplate({
if (!hasIndex) { // implied: options.autoIndex is true
var context = {
url: request.url,

@@ -67,5 +76,9 @@ files: fs.readdirSync(filename).sort().map(function (child){

}
})
}))
return;
}),
liveReloadPath: options.liveReloadPath
}
response.setHeader('Cache-Control', 'private, max-age=0, must-revalidate')
response.writeHead(200)
response.end(dirTemplate(context))
return
}

@@ -92,3 +105,2 @@

}
// we don't want stale build files
response.setHeader('Cache-Control', 'private, max-age=0, must-revalidate')

@@ -95,0 +107,0 @@ response.setHeader('Content-Length', stat.size)

{
"name": "broccoli",
"description": "Fast client-side asset builder",
"version": "0.15.3",
"version": "0.15.4",
"author": "Jo Liss <joliss42@gmail.com>",

@@ -27,4 +27,4 @@ "main": "lib/index.js",

"copy-dereference": "^1.0.0",
"findup-sync": "^0.1.2",
"handlebars": "^2.0.0",
"findup-sync": "^0.2.1",
"handlebars": "^3.0.1",
"mime": "^1.2.11",

@@ -34,7 +34,7 @@ "promise-map-series": "^0.2.1",

"rimraf": "^2.2.8",
"rsvp": "^3.0.6",
"rsvp": "^3.0.17",
"tiny-lr": "^0.1.4"
},
"devDependencies": {
"jshint": "~2.5.6",
"jshint": "~2.6.3",
"tap": "^0.4.8"

@@ -47,4 +47,4 @@ },

"pretest": "jshint lib test",
"test": "tap --stderr --timeout 2 ./test/*_test.js"
"test": "tap --stderr --timeout 10 ./test/*_test.js"
}
}

@@ -28,16 +28,16 @@ # Broccoli

## Getting Started
Check out
[broccoli-sample-app](https://github.com/broccolijs/broccoli-sample-app).
## Brocfile.js
A `Brocfile.js` file in the project root contains the build specification. It
should export a tree which may simply be the directory path (as a string). To
build more advanced output trees you may want to use some of the plugins listed
below.
should export a tree.
The following would export the `app/` subdirectory as a tree:
A tree can be any string representing a directory path, like `'app'` or
`'src'`. Or a tree can be an object conforming to the [Plugin API
Specification](#plugin-api-specification). A `Brocfile.js` will usually
directly work with only directory paths, and then use the plugins in the
[Plugins](#plugins) section to generate transformed trees.
The following simple `Brocfile.js` would export the `app/` subdirectory as a
tree:
```js

@@ -47,4 +47,25 @@ module.exports = 'app'

Alternatively, the following would export the `app/` subdirectory as `appkit/`:
With that Brocfile, the build result would equal the contents of the `app`
tree in your project folder. For example, say your project contains these
files:
app
├─ main.js
└─ helper.js
Brocfile.js
package.json
Running `broccoli build the-output` (a command provided by
[broccoli-cli](https://github.com/broccolijs/broccoli-cli)) would generate
the following folder within your project folder:
the-output
├─ main.js
└─ helper.js
### Using plugins in a `Brocfile.js`
The following `Brocfile.js` exports the `app/` subdirectory as `appkit/`:
```js

@@ -59,5 +80,25 @@ var pickFiles = require('broccoli-static-compiler')

That example uses the plugin
[`broccoli-static-compiler`](https://www.npmjs.com/package/broccoli-static-compiler).
In order for the `require` call to work, you must first put the plugin in
your `devDependencies` and install it, with
npm install --save-dev broccoli-static-compiler
With the above `Brocfile.js` and the file tree from the previous example,
running `broccoli build the-output` would generate the following folder:
the-output
└─ appkit
├─ main.js
└─ helper.js
### A larger example
You can see a full-featured `Brocfile.js` in
[broccoli-sample-app](https://github.com/broccolijs/broccoli-sample-app/blob/master/Brocfile.js).
## Plugins
You can find plugins on [broccoliplugins.com](http://broccoliplugins.com) or under the [broccoli-plugin-keyword](https://www.npmjs.org/browse/keyword/broccoli-plugin) on npm.
You can find plugins on [broccoliplugins.com](http://broccoliplugins.com) or under the [broccoli-plugin keyword](https://www.npmjs.org/browse/keyword/broccoli-plugin) on npm.

@@ -82,6 +123,9 @@ ### Running Broccoli, Directly or Through Other Tools

Broccoli defines a single plugin API: a tree. A tree object represents a tree
(directory hierarchy) of files that can be regenerated on each build.
(directory hierarchy) of files that will be regenerated on each build.
By convention, plugins will export a function that takes one or more input
trees, and returns an output tree object.
trees, and returns an output tree object. Usually your plugin will be
implemented as a class representing a tree, but it is recommended to make the
`new` operator optional
([example](https://github.com/joliss/broccoli-coffee/blob/a55b3a6677f6d9da83334e9c916ae5e57895d1a6/index.js#L8)).

@@ -88,0 +132,0 @@ A tree object must supply two methods that will be called by Broccoli:

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