broccoli-ractive
Advanced tools
+60
-64
| var Promise = require( 'es6-promise' ).Promise, | ||
| quickTemp = require( 'quick-temp' ), | ||
| Writer = require( 'broccoli-writer' ), | ||
| Ractive = require( 'ractive' ), | ||
@@ -18,5 +18,7 @@ rcu = require( 'rcu' ), | ||
| module.exports = RactiveCompiler; | ||
| rcu.init( Ractive ); | ||
| var RactiveCompiler, templates = {}, builders = {}; | ||
| var templates = {}, builders = {}; | ||
@@ -46,3 +48,3 @@ promisify = (function ( slice ) { | ||
| RactiveCompiler = function ( inputTree, options ) { | ||
| function RactiveCompiler ( inputTree, options ) { | ||
| var key; | ||
@@ -71,72 +73,57 @@ | ||
| } | ||
| }; | ||
| } | ||
| RactiveCompiler.prototype = { | ||
| constructor: RactiveCompiler, | ||
| RactiveCompiler.prototype = Object.create( Writer.prototype ); | ||
| RactiveCompiler.prototype.constructor = RactiveCompiler; | ||
| read: function (readTree) { | ||
| var self = this; | ||
| RactiveCompiler.prototype.write = function ( readTree, destDir ) { | ||
| var self = this; | ||
| quickTemp.makeOrRemake( this, 'ractiveCompiler' ); | ||
| return readTree( self.inputTree ).then( function ( srcDir ) { | ||
| return this.write( readTree, this.ractiveCompiler ).then( function () { | ||
| return self.ractiveCompiler; | ||
| // glob all input file patterns, and create components from them | ||
| var promises = self.files.map( resolvePattern ).map( function ( pattern ) { | ||
| return glob( pattern ).then( createComponents ); | ||
| }); | ||
| }, | ||
| cleanup: function () { | ||
| quickTemp.remove( this, 'ractive-compiler' ); | ||
| }, | ||
| return Promise.all( promises ); | ||
| write: function ( readTree, destDir ) { | ||
| var self = this; | ||
| function resolvePattern ( pattern ) { | ||
| return path.join( srcDir, pattern ); | ||
| } | ||
| return readTree( self.inputTree ).then( function ( srcDir ) { | ||
| function createComponents ( matches ) { | ||
| var promises = matches.map( function ( componentPath ) { | ||
| var relativePath, outputPath, outputFolder; | ||
| // glob all input file patterns, and create components from them | ||
| var promises = self.files.map( resolvePattern ).map( function ( pattern ) { | ||
| return glob( pattern ).then( createComponents ); | ||
| }); | ||
| relativePath = path.relative( srcDir, componentPath ); | ||
| return Promise.all( promises ); | ||
| outputPath = path.join( destDir, self.destDir, relativePath.replace( fileExtension, '.js' ) ); | ||
| outputFolder = path.join( outputPath, '..' ); | ||
| function resolvePattern ( pattern ) { | ||
| return path.join( srcDir, pattern ); | ||
| } | ||
| return createComponent( componentPath ).then( writeComponent ); | ||
| function createComponents ( matches ) { | ||
| var promises = matches.map( function ( componentPath ) { | ||
| var relativePath, outputPath, outputFolder; | ||
| function writeComponent ( built ) { | ||
| return mkdirp( outputFolder ).then( function () { | ||
| return writeFile( outputPath, built ); | ||
| }); | ||
| } | ||
| }); | ||
| relativePath = path.relative( srcDir, componentPath ); | ||
| return Promise.all( promises ); | ||
| } | ||
| }); | ||
| outputPath = path.join( destDir, self.destDir, relativePath.replace( fileExtension, '.js' ) ); | ||
| outputFolder = path.join( outputPath, '..' ); | ||
| function createComponent ( componentPath ) { | ||
| return readFile( componentPath ).then( function ( result ) { | ||
| var source, parsed, builder, built; | ||
| return createComponent( componentPath ).then( writeComponent ); | ||
| source = result.toString(); | ||
| parsed = rcu.parse( source ); | ||
| function writeComponent ( built ) { | ||
| return mkdirp( outputFolder ).then( function () { | ||
| return writeFile( outputPath, built ); | ||
| }); | ||
| } | ||
| }); | ||
| builder = builders[ self.type ]; | ||
| built = builder( parsed ); | ||
| return Promise.all( promises ); | ||
| } | ||
| return built; | ||
| }); | ||
| function createComponent ( componentPath ) { | ||
| return readFile( componentPath ).then( function ( result ) { | ||
| var source, parsed, builder, built; | ||
| source = result.toString(); | ||
| parsed = rcu.parse( source ); | ||
| builder = builders[ self.type ]; | ||
| built = builder( parsed ); | ||
| return built; | ||
| }); | ||
| } | ||
| } | ||
@@ -186,11 +173,16 @@ }; | ||
| builders.amd = function ( definition ) { | ||
| var builtModule = '' + | ||
| 'define([' + | ||
| definition.imports.map( getImportPath ).concat( '"require"', '"ractive"' ).join( ',\n' ) + | ||
| '], function(' + | ||
| definition.imports.map( getImportName ).concat( 'require', 'Ractive' ).join( ',\n' ) + | ||
| var dependencies, builtModule; | ||
| dependencies = definition.imports.map( getImportPath ).concat( definition.modules ); | ||
| builtModule = '' + | ||
| 'define([\n\t' + | ||
| dependencies.map( quote ).concat( '"require"', '"ractive"' ).join( ',\n\t' ) + '\n' + | ||
| '], function(\n\t' + | ||
| dependencies.map( getDependencyName ).concat( 'require', 'Ractive' ).join( ',\n\t' ) + '\n' + | ||
| '){\n' + | ||
| createBody( definition ) + | ||
| 'return __export__;'; | ||
| 'return __export__;\n' + | ||
| '});'; | ||
@@ -200,8 +192,12 @@ return builtModule; | ||
| function getImportPath ( imported ) { | ||
| return '\t"' + imported.href.replace( fileExtension, '' ) + '"'; | ||
| return imported.href.replace( fileExtension, '' ); | ||
| } | ||
| function getImportName ( imported, i ) { | ||
| return '\t__import' + i + '__'; | ||
| function quote ( str ) { | ||
| return '"' + str + '"'; | ||
| } | ||
| function getDependencyName ( imported, i ) { | ||
| return '__import' + i + '__'; | ||
| } | ||
| }; | ||
@@ -208,0 +204,0 @@ |
+3
-3
| { | ||
| "name": "broccoli-ractive", | ||
| "version": "0.1.4", | ||
| "version": "0.1.5", | ||
| "author": "Rich-Harris", | ||
@@ -18,4 +18,4 @@ "main": "index.js", | ||
| "glob": "^4.0.0", | ||
| "quick-temp": "^0.1.2", | ||
| "clean-css": "^2.1.8" | ||
| "clean-css": "^2.1.8", | ||
| "broccoli-writer": "^0.1.1" | ||
| }, | ||
@@ -22,0 +22,0 @@ "devDependencies": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
477421
-0.01%13477
-0.03%99
1.02%+ Added
+ Added
+ Added
- Removed