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

babel-plugin-globals

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-globals - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

26

index.js

@@ -60,3 +60,7 @@ 'use strict';

nodes.push(t.expressionStatement(
t.assignmentExpression('=', id, t.objectExpression([]))
t.assignmentExpression('=', id, t.logicalExpression(
'||',
id,
t.objectExpression([])
))
));

@@ -91,13 +95,19 @@ }

function getGlobalIdentifier(state, filePath, name, opt_isWildcard) {
assertFilenameRequired(state.file.opts.filename);
var globalName = state.opts.globalName;
if (name || opt_isWildcard) {
globalName += 'Named';
var id;
if (typeof globalName === 'function') {
id = globalName(state, filePath, name, opt_isWildcard);
}
else {
if (name || opt_isWildcard) {
globalName += 'Named';
}
assertFilenameRequired(state.file.opts.filename);
filePath = path.resolve(path.dirname(state.file.opts.filename), filePath);
var splitPath = filePath.split(path.sep);
var moduleName = splitPath[splitPath.length - 1];
filePath = path.resolve(path.dirname(state.file.opts.filename), filePath);
var splitPath = filePath.split(path.sep);
var moduleName = splitPath[splitPath.length - 1];
var id = 'this.' + globalName + '.' + moduleName + (name ? '.' + name : '');
id = 'this.' + globalName + '.' + moduleName + (name ? '.' + name : '');
}

@@ -104,0 +114,0 @@ return t.identifier(id);

{
"name": "babel-plugin-globals",
"version": "1.0.1",
"version": "1.1.0",
"description": "A babel plugin that exposes ES6 modules to global variables.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -25,5 +25,16 @@ babel-plugin-globals

### Plugin options
- `globalName` **{string}** The name of the global variable that the modules should be exported to.
#### `globalName` **{string|!function()}**
The name of the global variable that the modules should be exported to.
Default exports will be exported as `<globalName>.<filename>` whilst named exports will be exported as
`<globalName>Named.<fileName>.<exportName>`.
`globalName` can also receive a function that returns the whole variable path for each export (e.g. `(state, filePath, name, isWildcard) => 'this.MyModule.Views' + (name ? '.' + name : '')`)
### Babel options
- `filename` **{string}** This is an optional existing babel option, but is required for this plugin, since the plugin uses the file name to decide the name of the keys that will be exported in the global variable.
#### `filename` **{string}**
This is an optional existing babel option, but is required for this plugin, since the plugin uses the file name to decide the name of the keys that will be exported in the global variable.
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