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

liferay-npm-bundler-plugin-replace-browser-modules

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

liferay-npm-bundler-plugin-replace-browser-modules - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

30

lib/__tests__/index.test.js

@@ -40,3 +40,5 @@ 'use strict';

pkgFiles.forEach(function (file) {
fs.unlink(pkg.dir + '/' + file);
try {
fs.unlink(pkg.dir + '/' + file);
} catch (err) {}
});

@@ -58,2 +60,28 @@ });

it('works with unpkg field too', function () {
var pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'test-main.js.file',
unpkg: 'test-browser.js.file'
};
(0, _index2.default)({ pkg: pkg }, { pkgJson: pkgJson });
expect(fs.readFileSync(pkg.dir + '/test-main.js.file').toString()).toMatchSnapshot();
});
it('works with jsdelivr field too', function () {
var pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'test-main.js.file',
jsdelivr: 'test-browser.js.file'
};
(0, _index2.default)({ pkg: pkg }, { pkgJson: pkgJson });
expect(fs.readFileSync(pkg.dir + '/test-main.js.file').toString()).toMatchSnapshot();
});
it('replaces server files with browser files', function () {

@@ -60,0 +88,0 @@ var pkgJson = {

18

lib/index.js

@@ -12,9 +12,9 @@ 'use strict';

var browser = pkgJson.browser;
var browser = pkgJson.browser || pkgJson.unpkg || pkgJson.jsdelivr;
if (browser) {
if (typeof browser === 'string') {
replaceMainModule(pkg.dir, pkgJson);
replaceMainModule(pkg.dir, browser, pkgJson);
} else {
replaceModules(pkg.dir, pkgJson);
replaceModules(pkg.dir, browser, pkgJson);
}

@@ -31,10 +31,10 @@ }

/**
* Copy "browser" module file on top of "main" module file.
* Copy "browser"/"module" module file on top of "main" module file.
* @param {String} pkgDir directory where package is placed
* @param {String} browser the value of the "browser"/"module" field
* @param {Object} pkgJson package.json contents
* @return {void}
*/
function replaceMainModule(pkgDir, pkgJson) {
function replaceMainModule(pkgDir, browser, pkgJson) {
var pkgId = pkgJson.name + '@' + pkgJson.version;
var browser = pkgJson.browser;
var main = pkgJson.main || 'index.js';

@@ -49,4 +49,5 @@

/**
* Copy "browser" module files on top of their server versions.
* Copy "browser"/"module" module files on top of their server versions.
* @param {String} pkgDir directory where package is placed
* @param {String} browser the value of the "browser"/"module" field
* @param {Object} pkgJson package.json contents

@@ -60,5 +61,4 @@ * @return {void}

*/
function replaceModules(pkgDir, pkgJson) {
function replaceModules(pkgDir, browser, pkgJson) {
var pkgId = pkgJson.name + '@' + pkgJson.version;
var browser = pkgJson.browser;

@@ -65,0 +65,0 @@ Object.keys(browser).forEach(function (from) {

{
"name": "liferay-npm-bundler-plugin-replace-browser-modules",
"version": "1.1.0",
"description": "A liferay-npm-bundler plugin to replace files listed under the browser entry of package.json files.",
"version": "1.2.0",
"description": "A liferay-npm-bundler plugin to replace files listed under the browser/module entry of package.json files.",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "scripts": {

# liferay-npm-bundler-plugin-replace-browser-modules
> Replace modules listed under `browser` section of `package.json` files.
> Replace modules listed under `browser`/`unpkg`/`jsdelivr` section of
`package.json` files.

@@ -27,4 +28,5 @@ ## Installation

This plugin scans `package.json` for a browser entry and copies browser modules
on top of server modules or deletes them when set to `false`.
This plugin scans `package.json` for a `browser`/`unpkg`/`jsdelivr` entry and
copies browser modules on top of server modules or deletes them when set to
`false`.

@@ -31,0 +33,0 @@ Please read the

@@ -34,3 +34,5 @@ import cpFile from 'cp-file';

pkgFiles.forEach(file => {
fs.unlink(`${pkg.dir}/${file}`);
try {
fs.unlink(`${pkg.dir}/${file}`);
} catch (err) {}
});

@@ -54,2 +56,32 @@ });

it('works with unpkg field too', () => {
const pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'test-main.js.file',
unpkg: 'test-browser.js.file',
};
plugin({ pkg }, { pkgJson });
expect(
fs.readFileSync(`${pkg.dir}/test-main.js.file`).toString(),
).toMatchSnapshot();
});
it('works with jsdelivr field too', () => {
const pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'test-main.js.file',
jsdelivr: 'test-browser.js.file',
};
plugin({ pkg }, { pkgJson });
expect(
fs.readFileSync(`${pkg.dir}/test-main.js.file`).toString(),
).toMatchSnapshot();
});
it('replaces server files with browser files', () => {

@@ -56,0 +88,0 @@ const pkgJson = {

@@ -7,9 +7,9 @@ import fs from 'fs';

export default function({ pkg, config }, { pkgJson }) {
const browser = pkgJson.browser;
const browser = pkgJson.browser || pkgJson.unpkg || pkgJson.jsdelivr;
if (browser) {
if (typeof browser === 'string') {
replaceMainModule(pkg.dir, pkgJson);
replaceMainModule(pkg.dir, browser, pkgJson);
} else {
replaceModules(pkg.dir, pkgJson);
replaceModules(pkg.dir, browser, pkgJson);
}

@@ -20,10 +20,10 @@ }

/**
* Copy "browser" module file on top of "main" module file.
* Copy "browser"/"module" module file on top of "main" module file.
* @param {String} pkgDir directory where package is placed
* @param {String} browser the value of the "browser"/"module" field
* @param {Object} pkgJson package.json contents
* @return {void}
*/
function replaceMainModule(pkgDir, pkgJson) {
function replaceMainModule(pkgDir, browser, pkgJson) {
const pkgId = `${pkgJson.name}@${pkgJson.version}`;
const browser = pkgJson.browser;
const main = pkgJson.main || 'index.js';

@@ -38,10 +38,10 @@

/**
* Copy "browser" module files on top of their server versions.
* Copy "browser"/"module" module files on top of their server versions.
* @param {String} pkgDir directory where package is placed
* @param {String} browser the value of the "browser"/"module" field
* @param {Object} pkgJson package.json contents
* @return {void}
*/
function replaceModules(pkgDir, pkgJson) {
function replaceModules(pkgDir, browser, pkgJson) {
const pkgId = `${pkgJson.name}@${pkgJson.version}`;
const browser = pkgJson.browser;

@@ -48,0 +48,0 @@ Object.keys(browser).forEach(from => {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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