Socket
Socket
Sign inDemoInstall

rollup-plugin-cjs-es

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-cjs-es - npm Package Compare versions

Comparing version 0.9.0 to 1.0.0

184

index.js

@@ -5,3 +5,3 @@ const fs = require("fs");

const {transform: cjsEs} = require("cjs-es");
const {createFilter} = require("rollup-pluginutils");
const {createFilter} = require("@rollup/pluginutils");
const {analyze: esInfoAnalyze} = require("es-info");

@@ -116,3 +116,3 @@

}
if (exportTypeCache.hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(exportTypeCache, id)) {
return exportTypeCache[id];

@@ -155,82 +155,2 @@ }

async function updateEsExportTable({id, context, info}) {
if (!exportTable[id]) {
exportTable[id] = {id};
}
Object.assign(exportTable[id], info.export);
exportTable[id].trusted = true;
exportTable[id].loaded = true;
await Promise.all(Object.entries(info.import).map(async ([name, importInfo]) => {
if (!importInfo.default && !importInfo.named.length && !importInfo.all) {
return;
}
importInfo.id = id;
importInfo.trusted = true;
let importee = await context.resolveId(name, id);
let external = false;
if (!importee) {
importee = name;
external = true;
}
if (!exportTable[importee]) {
exportTable[importee] = {id: importee};
}
if (!exportTable[importee].expects) {
exportTable[importee].expects = [];
}
importInfo.external = external;
exportTable[importee].expects.push(importInfo);
}));
}
async function updateCjsExportTable({
id,
context,
transformContext: {
importedProperties,
namedExports,
objectExports,
finalExportType,
finalImportType
},
guessedIds
}) {
if (!exportTable[id]) {
exportTable[id] = {id};
}
const props = new Set([...namedExports.keys(), ...objectExports.keys()]);
exportTable[id].default = finalExportType === "default";
exportTable[id].named = finalExportType === "named" ? [...props] : [];
exportTable[id].exportedProps = [...props];
exportTable[id].loaded = true;
exportTable[id].trusted = !guessedIds.has(id);
await Promise.all(Object.entries(finalImportType).map(async ([name, type]) => {
const props = importedProperties.get(name) || [];
const importInfo = {
id,
named: type === "named" ? [...props] : [],
default: type === "default",
all: type === "named" && !props.length,
importedProps: [...props]
};
let importee = await context.resolveId(name, id);
let external = false;
if (!importee) {
importee = name;
external = true;
}
if (!exportTable[importee]) {
exportTable[importee] = {id: importee};
}
if (!exportTable[importee].expects) {
exportTable[importee].expects = [];
}
importInfo.external = external;
importInfo.trusted = !guessedIds.has(importee);
exportTable[importee].expects.push(importInfo);
}));
}
async function transform(code, id) {

@@ -242,4 +162,9 @@ if (!filter(id)) {

const info = esInfoAnalyze({ast});
const exportTableUpdater = createExportTableUpdater({
id,
exportTable,
resolve: this.resolve.bind(this)
});
if (isEsModule(info)) {
await updateEsExportTable({context: this, info, id});
await exportTableUpdater.updateFromEs(info);
return;

@@ -253,5 +178,6 @@ }

importStyle: async requireId => {
const absId = await this.resolveId(requireId, id);
guessedIds.add(absId);
return getExportType(absId || requireId, id);
const result = await this.resolve(requireId, id);
const finalId = result ? result.id : requireId;
guessedIds.add(finalId);
return getExportType(finalId, id);
},

@@ -268,8 +194,3 @@ exportStyle: () => {

if (result.isTouched) {
await updateCjsExportTable({
context: this,
id,
transformContext: result.context,
guessedIds
});
await exportTableUpdater.updateFromCjs(result.context, guessedIds);
return {

@@ -335,2 +256,81 @@ code: result.code,

function createExportTableUpdater({id, exportTable, resolve}) {
return {updateFromCjs, updateFromEs};
async function resolveImportee(name) {
const result = await resolve(name, id);
return result || {
id: name,
external: true
};
}
function addExpect(id, expect) {
if (!exportTable[id]) {
exportTable[id] = {id};
}
if (!exportTable[id].expects) {
exportTable[id].expects = [];
}
exportTable[id].expects.push(expect);
}
async function updateFromEs(info) {
if (!exportTable[id]) {
exportTable[id] = {id};
}
Object.assign(exportTable[id], info.export);
exportTable[id].trusted = true;
exportTable[id].loaded = true;
await Promise.all(Object.entries(info.import).map(async ([name, importInfo]) => {
if (!importInfo.default && !importInfo.named.length && !importInfo.all) {
return;
}
const importee = await resolveImportee(name);
importInfo.id = id;
importInfo.trusted = true;
importInfo.external = importee.external;
addExpect(importee.id, importInfo);
}));
}
async function updateFromCjs(
{
importedProperties,
namedExports,
objectExports,
finalExportType,
finalImportType
},
guessedIds
) {
if (!exportTable[id]) {
exportTable[id] = {id};
}
const props = new Set([...namedExports.keys(), ...objectExports.keys()]);
exportTable[id].default = finalExportType === "default";
exportTable[id].named = finalExportType === "named" ? [...props] : [];
exportTable[id].exportedProps = [...props];
exportTable[id].loaded = true;
exportTable[id].trusted = !guessedIds.has(id);
await Promise.all(Object.entries(finalImportType).map(async ([name, type]) => {
const props = importedProperties.get(name) || [];
const importee = await resolveImportee(name);
const importInfo = {
id,
named: type === "named" ? [...props] : [],
default: type === "default",
all: type === "named" && !props.length,
importedProps: [...props],
external: importee.external,
trusted: !guessedIds.has(importee.id)
};
addExpect(importee.id, importInfo);
}));
}
}
module.exports = factory;
{
"name": "rollup-plugin-cjs-es",
"version": "0.9.0",
"version": "1.0.0",
"description": "Convert CommonJS module into ES module",

@@ -17,3 +17,3 @@ "keywords": [

"scripts": {
"test": "eslint \"**/*.js\" --cache && c8 --reporter=lcov mocha",
"test": "eslint \"**/*.js\" --cache && c8 --reporter=lcov mocha -b",
"preversion": "npm test",

@@ -26,17 +26,17 @@ "postversion": "git push --follow-tags && npm publish"

"devDependencies": {
"c8": "^5.0.1",
"endent": "^1.3.0",
"eslint": "^5.16.0",
"mocha": "^6.1.4",
"rollup": "^1.15.2",
"sinon": "^7.3.2",
"c8": "^7.1.0",
"endent": "^1.4.1",
"eslint": "^6.8.0",
"mocha": "^7.1.0",
"rollup": "^2.0.5",
"sinon": "^9.0.1",
"tempdir-yaml": "^0.3.0"
},
"dependencies": {
"cjs-es": "^0.8.0",
"es-info": "^0.3.0",
"rollup-pluginutils": "^2.8.1"
"@rollup/pluginutils": "^3.0.8",
"cjs-es": "^0.8.2",
"es-info": "^0.3.0"
},
"peerDependencies": {
"rollup": "^1.15.2"
"rollup": "^2.0.5"
},

@@ -43,0 +43,0 @@ "engines": {

@@ -327,2 +327,6 @@ rollup-plugin-cjs-es

* 1.0.0 (Mar 13, 2020)
- **Breaking: bump rollup to 2.0**
* 0.9.0 (Jun 14, 2019)

@@ -329,0 +333,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