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 2.13.2 to 2.13.3-alpha.6

LICENSE.md

188

lib/index.js

@@ -1,40 +0,38 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (_ref, _ref2) {
var log = _ref.log,
pkg = _ref.pkg;
var pkgJson = _ref2.pkgJson;
var browser = pkgJson.browser || pkgJson.unpkg || pkgJson.jsdelivr;
if (typeof browser === 'string') {
replaceMainModule(pkg.dir, browser, pkgJson, log);
} else if (browser) {
replaceModules(pkg.dir, browser, pkgJson, log);
} else {
log.info('replace-browser-modules', 'No browser modules found');
}
"use strict";
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _fsExtra = require('fs-extra');
var _fsExtra2 = _interopRequireDefault(_fsExtra);
var _packages = require('liferay-npm-build-tools-common/lib/packages');
var pkgs = _interopRequireWildcard(_packages);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
const pkgs = __importStar(require("liferay-npm-build-tools-common/lib/packages"));
const path_1 = __importDefault(require("path"));
/**
* @return {void}
*/
function default_1({ log, pkg }, { pkgJson }) {
const browser = pkgJson.browser || pkgJson.unpkg || pkgJson.jsdelivr;
if (typeof browser === 'string') {
replaceMainModule(pkg.dir, browser, pkgJson, log);
}
else if (browser) {
replaceModules(pkg.dir, browser, pkgJson, log);
}
else {
log.info('replace-browser-modules', 'No browser modules found');
}
}
exports.default = default_1;
/**
* Copy "browser"/"module" module file on top of "main" module file.

@@ -47,19 +45,10 @@ * @param {FilePath} pkgDir directory where package is placed

*/
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
function replaceMainModule(pkgDir, browser, pkgJson, log) {
var pkgId = pkgJson.name + '@' + pkgJson.version;
var main = pkgJson.main || 'index.js';
var srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, browser)).asNative;
var destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, main)).asNative;
replaceFile(pkgId, srcPath, browser, destPath, main, log);
const pkgId = `${pkgJson.name}@${pkgJson.version}`;
const main = pkgJson.main || 'index.js';
const srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, browser)).asNative;
const destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, main))
.asNative;
replaceFile(pkgId, srcPath, browser, destPath, main, log);
}
/**

@@ -73,25 +62,16 @@ * Copy "browser"/"module" module files on top of their server versions.

*/
/**
* @return {void}
*/
function replaceModules(pkgDir, browser, pkgJson, log) {
var pkgId = pkgJson.name + '@' + pkgJson.version;
Object.keys(browser).forEach(function (fromModuleName) {
var toModuleName = browser[fromModuleName];
var destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, fromModuleName)).asNative;
if (toModuleName == false) {
ignoreFile(destPath, fromModuleName, log);
} else {
var srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, toModuleName)).asNative;
replaceFile(pkgId, srcPath, toModuleName, destPath, fromModuleName, log);
}
});
const pkgId = `${pkgJson.name}@${pkgJson.version}`;
Object.keys(browser).forEach(fromModuleName => {
const toModuleName = browser[fromModuleName];
const destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, fromModuleName)).asNative;
if (toModuleName == false) {
ignoreFile(destPath, fromModuleName, log);
}
else {
const srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, toModuleName)).asNative;
replaceFile(pkgId, srcPath, toModuleName, destPath, fromModuleName, log);
}
});
}
/**

@@ -108,30 +88,28 @@ * Replace one package file with another.

function replaceFile(pkgId, srcPath, srcName, destPath, destName, log) {
var srcModuleName = srcName.replace('.js', '');
var destModuleName = destName.replace('.js', '');
log.info('replace-browser-modules', 'Replacing module ' + destName + ' with module ' + srcName);
try {
var contents = '';
try {
contents = _fsExtra2.default.readFileSync(srcPath).toString();
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
contents = contents.replace('\'' + pkgId + '/' + srcModuleName + '\'', '\'' + pkgId + '/' + destModuleName + '\'');
_fsExtra2.default.mkdirsSync(_path2.default.dirname(destPath));
_fsExtra2.default.writeFileSync(destPath, '/* Module replaced with ' + srcName + ' by liferay-npm-bundler-plugin-replace-browser-modules */\n' + contents);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
const srcModuleName = srcName.replace('.js', '');
const destModuleName = destName.replace('.js', '');
log.info('replace-browser-modules', `Replacing module ${destName} with module ${srcName}`);
try {
let contents = '';
try {
contents = fs_extra_1.default.readFileSync(srcPath).toString();
}
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
contents = contents.replace(`'${pkgId}/${srcModuleName}'`, `'${pkgId}/${destModuleName}'`);
fs_extra_1.default.mkdirsSync(path_1.default.dirname(destPath));
fs_extra_1.default.writeFileSync(destPath, '/* Module replaced with ' +
srcName +
' by liferay-npm-bundler-plugin-replace-browser-modules */\n' +
contents);
}
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
}
/**

@@ -145,8 +123,6 @@ * Ignores one package

function ignoreFile(filePath, moduleName, log) {
log.info('replace-browser-modules', 'Emptying module ' + moduleName + ' because it is server-only');
_fsExtra2.default.mkdirsSync(_path2.default.dirname(filePath));
_fsExtra2.default.writeFileSync(filePath, '/* Module ignored by ' + 'liferay-npm-bundler-plugin-replace-browser-modules */\n');
log.info('replace-browser-modules', `Emptying module ${moduleName} because it is server-only`);
fs_extra_1.default.mkdirsSync(path_1.default.dirname(filePath));
fs_extra_1.default.writeFileSync(filePath, '/* Module ignored by ' +
'liferay-npm-bundler-plugin-replace-browser-modules */\n');
}
//# sourceMappingURL=index.js.map
{
"name": "liferay-npm-bundler-plugin-replace-browser-modules",
"version": "2.13.2",
"version": "2.13.3-alpha.6+ae09044",
"description": "A liferay-npm-bundler plugin to replace files listed under the browser/module entry of package.json files.",
"main": "lib/index.js",
"scripts": {
"build": "babel --source-maps -D -d lib src --ignore '**/__tests__/**'",
"prepublish": "npm run build"
"copyfiles": "node ../../scripts/copyfiles.js",
"build": "tsc && yarn copyfiles",
"prepublish": "yarn build"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"recursive-copy": "^2.0.9"
},
"dependencies": {
"fs-extra": "^7.0.1",
"liferay-npm-build-tools-common": "2.13.2"
}
"fs-extra": "^8.1.0",
"liferay-npm-build-tools-common": "2.13.3-alpha.6+ae09044"
},
"gitHead": "ae09044beb216743cb2f1e2273aa6e055716ce64"
}

@@ -29,3 +29,3 @@ /**

overwrite: true,
}).then(done);
}).then(() => done());
});

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