circus-router
Advanced tools
Comparing version 1.0.1 to 1.1.0
var NullDependency = require('webpack/lib/dependencies/NullDependency'); | ||
function RequireRouterListing(blocks, expr, resource) { | ||
function RequireRouterListing(data, blocks, expr, resource) { | ||
NullDependency.call(this); | ||
this.Class = RequireRouterListing; | ||
this.data = data; | ||
this.blocks = blocks; | ||
@@ -58,3 +59,12 @@ this.expr = expr; | ||
source.replace(dep.range[0], dep.range[1] - 1, '' + namespace + '.loader(__webpack_require__, ' + JSON.stringify(content) + ')'); | ||
if (dep.data) { | ||
// Strip the root JSON object syntax so we can construct our own. | ||
content = JSON.stringify(content).replace(/^\{|\}$/g, ''); | ||
// Break this into multiple components that will build around the data source component if one exists | ||
source.replace(dep.range[0], dep.data.range[0] - 1, namespace + '.loader(__webpack_require__, {"data":'); | ||
source.replace(dep.data.range[1], dep.range[1] - 1, ',' + content + '})'); | ||
} else { | ||
source.replace(dep.range[0], dep.range[1] - 1, namespace + '.loader(__webpack_require__, ' + JSON.stringify(content) + ')'); | ||
} | ||
}; | ||
@@ -61,0 +71,0 @@ |
@@ -86,4 +86,6 @@ var BasicEvaluatedExpression = require('webpack/lib/BasicEvaluatedExpression'), | ||
compiler.parser.plugin('call ' + namespace + '.loader', function(expr) { | ||
var dependenciesIndex = expr.arguments.length > 1 ? 1 : 0; | ||
// Do not parse if no args or an empty array is passed. | ||
if (!expr.arguments[0] || !expr.arguments[0].elements || !expr.arguments[0].elements.length) { | ||
if (!expr.arguments[dependenciesIndex] || !expr.arguments[dependenciesIndex].elements || !expr.arguments[dependenciesIndex].elements.length) { | ||
this.state.compilation.warnings.push(new Error(this.state.current.resource + ':' + expr.loc.start.line + ' - No imports')); | ||
@@ -93,3 +95,4 @@ return; | ||
var dependenciesExpr = this.evaluateExpression(expr.arguments[0]), | ||
var dataExpr = expr.arguments.length > 1 ? this.evaluateExpression(expr.arguments[0]) : undefined, | ||
dependenciesExpr = this.evaluateExpression(expr.arguments[dependenciesIndex]), | ||
old = this.state.current; | ||
@@ -111,3 +114,3 @@ | ||
this.state.current.addDependency(new RequireRouterListing(blocks, expr, this.state.current.resource)); | ||
this.state.current.addDependency(new RequireRouterListing(dataExpr, blocks, expr, this.state.current.resource)); | ||
return true; | ||
@@ -114,0 +117,0 @@ }); |
{ | ||
"name": "circus-router", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Router parser for Circus components", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"chai": "^1.10.0", | ||
"circus": "^2.0.0", | ||
"circus": "^4.0.0", | ||
"gulp": "^3.8.10", | ||
@@ -25,0 +25,0 @@ "gulp-istanbul": "^0.5.0", |
@@ -59,2 +59,13 @@ # circus-router | ||
If two parameters are passed, the first paramter is passed to the loader runtime and maybe used as needed for initialization. | ||
```javascript | ||
Circus.loader({root: '/foo'}, [ | ||
'./home', | ||
'./items' | ||
]); | ||
``` | ||
Would pass the object containing `root` to the generated module json at runtime. | ||
### Generated Code | ||
@@ -61,0 +72,0 @@ |
@@ -5,4 +5,9 @@ # Release Notes | ||
[Commits](https://github.com/walmartlabs/circus-router/compare/v1.0.1...master) | ||
[Commits](https://github.com/walmartlabs/circus-router/compare/v1.1.0...master) | ||
## v1.1.0 - April 15th, 2015 | ||
- [#1](https://github.com/walmartlabs/circus-router/pull/1) - Add data field to loader ([@kpdecker](https://api.github.com/users/kpdecker)) | ||
[Commits](https://github.com/walmartlabs/circus-router/compare/v1.0.1...v1.1.0) | ||
## v1.0.1 - February 6th, 2015 | ||
@@ -9,0 +14,0 @@ - Fix exec under Webpack 1.5 - df9662c |
@@ -60,4 +60,6 @@ var Circus = require('circus'), | ||
var pack = JSON.parse(fs.readFileSync(outputDir + '/circus.json').toString()); | ||
delete pack.circusVersion; // To avoid erroring the tests | ||
expect(pack).to.eql({ | ||
"bootstrap": "bootstrap.js", | ||
"components": [], | ||
"chunks": [ | ||
@@ -93,2 +95,3 @@ {"js": "bundle.js", "css": "0.bundle.css"}, | ||
"bundle.js", | ||
"0.bundle.css", | ||
"bundle.js.map", | ||
@@ -100,4 +103,3 @@ "1.bundle.js", | ||
"3.bundle.js", | ||
"3.bundle.js.map", | ||
"0.bundle.css" | ||
"3.bundle.js.map" | ||
], | ||
@@ -115,3 +117,4 @@ "published": { | ||
}, | ||
"entry": "bundle.js" | ||
"entry": "bundle.js", | ||
"usedModules": [] | ||
}); | ||
@@ -151,9 +154,11 @@ | ||
var output = fs.readFileSync(outputDir + '/bundle.js').toString(); | ||
expect(output).to.match(/Circus.loader\(__webpack_require__, \{"modules":\{"1":\{"chunk":1\}\},"routes":\{"\/foo":1,"\/bar":1\}\}\);/); | ||
expect(output).to.match(/Circus.loader\(__webpack_require__, \{"modules":\{"2":\{"chunk":2\}\},"routes":\{"\/foo":2,"\/bar":2\}\}\);/); | ||
expect(output).to.contain('Circus.loader(__webpack_require__, {"modules":{"1":{"chunk":1}},"routes":{"/foo":1,"/bar":1}});'); | ||
expect(output).to.contain('Circus.loader(__webpack_require__, {"modules":{"2":{"chunk":2}},"routes":{"/foo":2,"/bar":2}});'); | ||
// Verify the module map output | ||
var pack = JSON.parse(fs.readFileSync(outputDir + '/circus.json').toString()); | ||
delete pack.circusVersion; // To avoid erroring the tests | ||
expect(pack).to.eql({ | ||
"bootstrap": "bootstrap.js", | ||
"components": [], | ||
"chunks": [ | ||
@@ -198,3 +203,4 @@ {"js": "bundle.js"}, | ||
}, | ||
"entry": "bundle.js" | ||
"entry": "bundle.js", | ||
"usedModules": [] | ||
}); | ||
@@ -286,2 +292,28 @@ | ||
}); | ||
it('should include app data if passed', function(done) { | ||
var entry = path.resolve(__dirname + '/../fixtures/loader-data.js'); | ||
var config = { | ||
entry: entry, | ||
output: {path: outputDir}, | ||
circusNamespace: 'Circus', | ||
externals: { | ||
'circus': 'Circus' | ||
} | ||
}; | ||
config = CircusRouter.config(config); | ||
config = Circus.config(config); | ||
webpack(config, function(err, status) { | ||
expect(err).to.not.exist; | ||
expect(status.compilation.errors).to.be.empty; | ||
expect(status.compilation.warnings).to.be.empty; | ||
var output = fs.readFileSync(outputDir + '/bundle.js').toString(); | ||
expect(output).to.contain('Circus.loader(__webpack_require__, {"data":{root: \'/root\'},"modules":{"2":{"chunk":1}},"routes":{"/foo":2,"/bar":2}});'); | ||
done(); | ||
}); | ||
}); | ||
it('should handle typeof', function(done) { | ||
@@ -288,0 +320,0 @@ var config = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39597
42
886
85