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

broccoli-webpack-cached

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

broccoli-webpack-cached - npm Package Compare versions

Comparing version 0.1.6 to 0.2.0-beta

85

index.js
'use strict';
var fs = require('fs');
var RSVP = require('rsvp');

@@ -7,2 +8,3 @@ var path = require('path');

var webpack = require('webpack');
var MemoryFS = require('memory-fs');
var Plugin = require('broccoli-plugin');

@@ -42,2 +44,8 @@ var symlinkOrCopySync = require('symlink-or-copy').sync;

WebpackFilter.prototype.initializeCompiler = function() {
// Allow for deferred/lazy webpack config (e.g. if we need to wait until
// broccoli nodes are setup so we can get at the input/output paths).
if (typeof this.options === 'function') {
this.options = this.options();
}
if (this.options.context) throw new Error("WebpackFilter will set the webpack context, you shouldn't set it.");

@@ -52,5 +60,5 @@ if (this.options.cache) throw new Error("WebpackFilter will set the webpack cache, you shouldn't set it.");

// Tell Webpack to write to this plugin's cache folder
// Tell Webpack to write to root of memory fs
this.options.output = this.options.output || {};
this.options.output.path = this.cachePath;
this.options.output.path = '/';

@@ -78,4 +86,15 @@ // Change our working directory so resolve.modulesDirectories searches the

// By default, log webpack's output to the console
this.options.logStats = (this.options.logStats === undefined) ? true : this.options.logStats;
var DEFAULT_LOG_OPTIONS = true;
// {
// // assets: true,
// colors: true,
// timings: true,
// modules: true,
// cached: true,
// reasons: true,
// // chunkOrigins: true
// };
this.options.logStats = (this.options.logStats === undefined) ? DEFAULT_LOG_OPTIONS : this.options.logStats;
// Prevent Webpack's ResultSymlinkPlugin from breaking relative paths in symlinked

@@ -91,5 +110,10 @@ // modules (a common problem with Broccoli's highly symlinked output trees).

// Run webpack
resp = webpack(this.options);
// Use memory-fs (like webpack-dev-server does) so it doesn't write anything to disk
var mfs = new MemoryFS();
resp.outputFileSystem = mfs;
// Switch back to original working directory

@@ -111,4 +135,8 @@ process.chdir(cwd);

// If there is a Webpack error (hard OR soft error), show it and reject
if(err) {
console.error('Webpack error in', err.module.rawRequest);
if (err) {
if (err.module) {
console.error('Webpack error in', err.module.rawRequest);
} else {
console.error('Webpack error');
}

@@ -143,2 +171,3 @@ // Broccoli will log this custom error message itself

var jsonStats = stats.toJson();
if (that.options.logStats) console.log("\n[webpack]", stats.toString(that.options.logStats));

@@ -148,8 +177,29 @@ if (jsonStats.errors.length > 0) jsonStats.errors.forEach(console.error);

var memoryFS = that.compiler.outputFileSystem;
var writtenFiles = allMemoryFSFiles(memoryFS);
// Question... does webpack re-write cached assets to the outputFileSystem?
// Get all of the assets from webpack, both emitted in this current compile
// pass and not emitted (aka, cached). And then symlink all of them from the
// pass and not emitted (aka, cached). And symlink all of them from the
// cache folder (where webpack writes) to the output folder
writtenFiles.forEach(function(f) {
// Write the new file to the broccoli cache dir
mkdirp.sync(path.dirname(that.cachePath + f));
fs.writeFileSync(that.cachePath + f, memoryFS.readFileSync("/" + f));
// And symlink to the output
mkdirp.sync(path.dirname(that.outputPath + '/' + f));
symlinkOrCopySync(that.cachePath + '/' + f, that.outputPath + '/' + f);
});
// Make sure we pick up the assets not emitted (aka cached) during the last build
jsonStats.assets.map(function(asset) {
mkdirp.sync(path.dirname(that.outputPath + '/' + asset.name));
symlinkOrCopySync(that.cachePath + '/' + asset.name, that.outputPath + '/' + asset.name);
if (asset.emitted === false) {
mkdirp.sync(path.dirname(that.outputPath + '/' + asset.name));
symlinkOrCopySync(that.cachePath + '/' + asset.name, that.outputPath + '/' + asset.name);
}
});

@@ -164,2 +214,21 @@

var allMemoryFSFiles = function(memoryFS, dir) {
dir = dir !== undefined ? dir : '/';
var result = [];
var list = memoryFS.readdirSync(dir);
list.forEach(function(file) {
file = path.join(dir, file);
var stat = memoryFS.statSync(file);
if (stat && stat.isDirectory()) {
result = result.concat(allMemoryFSFiles(memoryFS, file));
} else {
result.push(file);
}
});
return result;
}
module.exports = WebpackFilter;

3

package.json
{
"name": "broccoli-webpack-cached",
"version": "0.1.6",
"version": "0.2.0-beta",
"description": "Yet another webpack plugin for Broccoli. This one relies on webpack's caching for speed, but does it in a way that works well as a broccoli plugin (symlinking from the webpack cache to the output folder as needed).",

@@ -9,2 +9,3 @@ "main": "index.js",

"broccoli-plugin": "^1.0.0",
"memory-fs": "^0.3.0",
"mkdirp": "^0.5.1",

@@ -11,0 +12,0 @@ "rsvp": "^3.0.20",

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