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

rollup-plugin-external-globals

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-external-globals - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

22

lib/import-to-globals.js

@@ -76,2 +76,15 @@ const {walk} = require("estree-walker");

function writeDynamicImport(code, node, globalName) {
code.overwrite(node.start, node.end, `Promise.resolve(${globalName})`);
}
function getDynamicImportSource(node) {
if (node.type === "ImportExpression") {
return node.source.value;
}
if (node.type === "CallExpression" && node.callee.type === "Import") {
return node.arguments[0].value;
}
}
function importToGlobals({ast, code, names}) {

@@ -94,4 +107,5 @@ let scope = attachScopes(ast, "scope");

enter(node, parent) {
if (/^import/i.test(node.type)) {
if (/^importdec/i.test(node.type)) {
this.skip();
return;
}

@@ -108,2 +122,8 @@ if (node.scope) {

}
const source = getDynamicImportSource(node);
if (names.hasOwnProperty(source)) {
writeDynamicImport(code, node, names[source]);
isTouched = true;
this.skip();
}
},

@@ -110,0 +130,0 @@ leave(node) {

16

package.json
{
"name": "rollup-plugin-external-globals",
"version": "0.3.1",
"version": "0.4.0",
"description": "Transform external imports into global variables like output.globals.",

@@ -28,14 +28,14 @@ "keywords": [

"devDependencies": {
"c8": "^5.0.1",
"c8": "^5.0.4",
"endent": "^1.3.0",
"eslint": "^5.16.0",
"mocha": "^6.1.4",
"rollup": "^1.14.0",
"mocha": "^6.2.0",
"rollup": "^1.21.4",
"tempdir-yaml": "^0.3.0"
},
"dependencies": {
"estree-walker": "^0.6.1",
"is-reference": "^1.1.2",
"magic-string": "^0.25.2",
"rollup-pluginutils": "^2.8.1"
"estree-walker": "^0.8.1",
"is-reference": "^1.1.3",
"magic-string": "^0.25.3",
"rollup-pluginutils": "^2.8.2"
},

@@ -42,0 +42,0 @@ "peerDependencies": {

@@ -51,4 +51,23 @@ rollup-plugin-external-globals

Note that this plugin only works with import/export syntax. If you are using a module loader transformer e.g. `rollup-plugin-commonjs`, you have to put this plugin *after* the transformer plugin.
It also transforms dynamic import:
```js
import("jquery")
.then($ => {
$ = $.default || $;
console.log($(".test"));
});
// transformed
Promise.resolve($)
.then($ => {
$ = $.default || $;
console.log($(".test"));
});
```
> **Note:** when using dynamic import, you should notice that in ES module, the resolved object is aways a module namespace, but the global variable might be not.
> **Note:** this plugin only works with import/export syntax. If you are using a module loader transformer e.g. `rollup-plugin-commonjs`, you have to put this plugin *after* the transformer plugin.
API

@@ -88,2 +107,6 @@ ----

* 0.4.0 (Sep 24, 2019)
- Add: transform dynamic imports i.e. `import("foo")` => `Promise.resolve(FOO)`.
* 0.3.1 (Jun 6, 2019)

@@ -90,0 +113,0 @@

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