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

assets-include

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assets-include - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

test/data/.config.yml.json

6

History.md

@@ -0,1 +1,7 @@

0.3.0 / 2012-07-03
==================
* Added support for new cache boosters created by assets-packager 0.5+.
* Supports cache boosters via -s option from command line.
0.2.1 / 2012-06-19

@@ -2,0 +8,0 @@ ==================

23

lib/include.js

@@ -12,2 +12,8 @@ var AssetsExpander = require('assets-expander'),

this.options.root = path.normalize(path.join(this.rootPath, this.options.root));
if (this.options.cacheBoosters) {
var cacheFile = path.join(this.rootPath, path.dirname(pathToConfig), '.' + path.basename(pathToConfig) + '.json');
if (path.existsSync(cacheFile))
this.cacheInfo = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
}
};

@@ -33,3 +39,3 @@

if (this.options.bundled) {
return [self._assetPathWithMTime(self._bundledPath(bundleInfo))];
return [self._assetPathWithStamp(self._bundledPath(bundleInfo), bundleInfo)];
} else {

@@ -44,3 +50,3 @@ var expanderOptions = {

.map(function(assetPath) {
return self._assetPathWithMTime(assetPath);
return self._assetPathWithStamp(assetPath, bundleInfo);
});

@@ -65,9 +71,14 @@ }

_assetPathWithMTime: function(assetPath) {
var relativePath = assetPath.replace(this.options.root, ''),
mtime = assetPath.indexOf('/') == 0 ?
_assetPathWithStamp: function(assetPath, bundleInfo) {
var relativePath = assetPath.replace(this.options.root, '');
if (this.options.bundled && this.cacheInfo) {
var cacheStamp = this.cacheInfo[bundleInfo.type + '/' + bundleInfo.group];
return relativePath.replace(/\.(css|js)/, '-' + cacheStamp + ".$1");
} else {
var mtime = assetPath.indexOf('/') == 0 ?
fs.statSync(assetPath).mtime.getTime() :
fs.statSync(path.join(this.rootPath, assetPath)).mtime.getTime();
return relativePath + "?" + mtime;
return relativePath + "?" + mtime;
}
},

@@ -74,0 +85,0 @@

@@ -5,3 +5,3 @@ {

"description": "Include assets into your views with ease (assets-packager compatible).",
"version": "0.2.1",
"version": "0.3.0",
"repository": {

@@ -8,0 +8,0 @@ "url": ""

@@ -41,2 +41,8 @@ var vows = require('vows'),

}),
'bundled scripts with cache boosters': binaryContext('-b -s -r ./data/public -c ./data/config.yml javascripts/all.js', {
'must give bundled script inclusion': function(error, stdout) {
assert.equal(stdout.match(/<script/g).length, 1);
assert.equal(stdout.match(/"\/javascripts\/bundled\/all-test1234567\.js"/g).length, 1);
}
}),
'bundled and inlined scripts': binaryContext('-b -i -r ./data/public -c ./data/config.yml javascripts/all.js', {

@@ -43,0 +49,0 @@ 'must give bundled script inclusion': function(error, stdout) {

@@ -42,2 +42,12 @@ var vows = require('vows'),

}),
'in plain (dev) mode as CSS with cache boosters': includeContext({
'should give a list of link tags': function(include) {
var asFragment = include.group('stylesheets/all.css');
assert(/\/stylesheets\/one.css\?\d+/.test(asFragment), 'missing one.css');
assert(/\/stylesheets\/two.css\?\d+/.test(asFragment), 'missing two.css');
assert(/\/stylesheets\/three.css\?\d+/.test(asFragment), 'missing three.css');
assert.equal(asFragment.match(/link/g).length, 3);
assert.equal(asFragment.match(/rel="stylesheet"/g).length, 3);
}
}, { cacheBoosters: true }),
'in plain (dev) mode as LESS': includeContext({

@@ -59,3 +69,10 @@ 'should give a list of link tags': function(include) {

}
}, { bundled: true })
}, { bundled: true }),
'in bundled mode as CSS with cache boosters': includeContext({
'should give a bundled link tag with version id': function(include) {
var asFragment = include.group('stylesheets/all.css');
assert(/"\/stylesheets\/bundled\/all-test2345678.css"/.test(asFragment), 'missing all.css');
assert.equal(asFragment.match(/<link/g).length, 1);
}
}, { bundled: true, cacheBoosters: true })
},

@@ -78,3 +95,10 @@ 'scripts group': {

}
}, { bundled: true })
}, { bundled: true }),
'in bundled (prod) mode with cache boosters': includeContext({
'should give a bundled script tag': function(include) {
var asFragment = include.group('javascripts/all.js');
assert(/"\/javascripts\/bundled\/all-test1234567.js"/.test(asFragment), 'missing all.js');
assert.equal(asFragment.match(/<script/g).length, 1);
}
}, { bundled: true, cacheBoosters: true })
},

@@ -116,3 +140,10 @@ 'custom': {

}
}, { bundled: true })
}, { bundled: true }),
'in bundled (prod) mode as CSS with cache boosters': includeContext({
'should give one stylesheet': function(include) {
var list = include.list('stylesheets/all.css');
assert.equal(list.length, 1);
assert(/\/stylesheets\/bundled\/all-test2345678.css/.test(list[0]), 'missing all.less')
}
}, { bundled: true, cacheBoosters: true })
},

@@ -134,3 +165,10 @@ 'list of scripts': {

}
}, { bundled: true })
}, { bundled: true }),
'in bundled (prod) mode with cache boosters': includeContext({
'should give one stylesheet': function(include) {
var list = include.list('javascripts/all.js');
assert.equal(list.length, 1);
assert(/\/javascripts\/bundled\/all-test1234567.js/.test(list[0]), 'missing all.js')
}
}, { bundled: true, cacheBoosters: true })
}

@@ -137,0 +175,0 @@ });

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