Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
es-dependencies-transform
Advanced tools
Browserify tranform for dependencies (DI container switcher).
Browserify tranform for dependencies (DI container switcher). The original purpose is to switch the dependency injection mapping module before the code is being process by browserify.
In denial it is just a text replace in JS files prior to further processing via browserify.
#!json
"devDependencies": {
"es-dependencies-transform": "^1.0.0"
}
#!javascript
// Browserify
var browserify = require('browserify');
// Dependencies transformer
var dependencies_transform = require('es-dependencies-transform');
// Bundle task
gulp.task('BUNDLE_APP', function() {
// Init browserify with you main app entry point (script)
var appBundler = browserify({
entries: './dev/js/app.js'
})
// DI Context could resolved in various ways
// Different tasks, read from config file, etc.
var dependenciesContext = 'context_1';
// Bundle app
appBundler
// Here is our DI transformation
.transform(dependencies_transform, {
context: dependenciesContext
})
// Any other transformations
// Bundle and dist the app
.bundle()
.pipe(source('app.min.js'))
.pipe(gulp.dest('./dist/js/'));
});
#!javascript
.transform(dependencies_transform, {
context: 'NAME_OF_THE_CONTEXT',
searchFor: 'reg ex string' // OPTIONAL, default value "import dependenciesMapping from '(.*\\/).*';"
replaceWith: 'reg ex string' // OPTIONAL, default value "import dependenciesMapping from '$1#replace#';" ($1#replace# - required string, used as the location in string of the injected context)
})
This is a micro DI solution example:
##app.js##
#!javascript
// ... other code
// Dependencies Injection
import Dependencies from './dependencies/injections';
// ... other code
##injections.js##
#!javascript
// Dependency resolver
import DependencyResolver from '../utils/dependecyResolver';
// Dependencies mapper file
// This will be transformed in bundling process
import dependenciesMapping from './EXAMPLE_CONTEXT';
// Register dependencies
DependencyResolver.registerMany(dependenciesMapping);
export default {};
##Example DI mapping file EXAMPLE_CONTEXT.js##
#!javascript
// Info
console.log('Used Dependencies Context: EXAMPLE_CONTEXT');
// Concrete instances
import Service1 from '../location-of-service-1';
import Service2 from '../location-of-service-2';
// Register dependencies
export default [
{
name: 'Service1',
instance: Service1
},
{
name: 'Service2',
instance: Service2
}
];
##dependecyResolver.js##
#!javascript
/*
* This class resolves and register dependencies
* Is is a small dependecy injection framework
*/
class DependencyResolver {
/*
* Constructor
*/
constructor() {
// Prepare registerd dependencies
this.dependencies = [];
}
/*
* Register dependency
*
* @param {string} name - name of the dependency
* @param {obj} instance - intance object witch will be used for injection
*/
register(name, instance) {
// Already registered
if (this.dependencies[name]) {
throw new Error('Can\'t register ' + name + '. It has been already registerd.');
}
this.dependencies[name] = instance;
}
/*
* Register multiple dependencies
*
* @param {array} dependencies - Register mutiple dependencies
*/
registerMany(dependencies) {
dependencies.map((dependency) => {
this.register(dependency.name, dependency.instance);
});
}
/*
* Resolve dependency
*
* @param {string} name - name of the dependecy tried to resolve
*/
resolve(name) {
// Registred dependecy
if (this.dependencies[name]) {
return this.dependencies[name];
}
// Not found
throw new Error('Can\'t resolve ' + name);
}
}
// Export service instance
export default new DependencyResolver();
##Usage of registred service in DI mapping##
#!javascript
// ... other code
// Import DI resolver
import DependencyResolver from './utils/dependecyResolver';
// Get service instance from DI resolver
const service1 = DependencyResolver.resolve('Service1');
// Call any methods on the service instance
service1.MethodA();
// or service could be just an object or value
// ... other code
FAQs
Browserify tranform for dependencies (DI container switcher).
The npm package es-dependencies-transform receives a total of 1 weekly downloads. As such, es-dependencies-transform popularity was classified as not popular.
We found that es-dependencies-transform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.