Socket
Socket
Sign inDemoInstall

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.5.0 to 2.5.1

41

lib/__tests__/index.test.js

@@ -144,12 +144,37 @@ 'use strict';

it('does not throw on inexistent files', function () {
var pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: 'non-existent-file.js'
};
describe('works well with non-existent files', function () {
it('when browser field has a unique file', function () {
var pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: 'non-existent-file.js'
};
(0, _index2.default)({ pkg: pkg, log: log }, { pkgJson: pkgJson });
(0, _index2.default)({ pkg: pkg, log: log }, { pkgJson: pkgJson });
expect(fs.readFileSync(pkg.dir + '/main.js').toString()).toMatchSnapshot();
});
it('when browser field has several files', function () {
var pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: {
'non-existent-file.js': false,
'non-existent-dir/non-existent-file-in-dir.js': false,
'non-existent-file-2.js': 'test-browser.js',
'non-existent-file-3.js': 'non-existent-file-4.js'
}
};
(0, _index2.default)({ pkg: pkg, log: log }, { pkgJson: pkgJson });
expect(fs.readFileSync(pkg.dir + '/non-existent-file.js').toString()).toMatchSnapshot();
expect(fs.readFileSync(pkg.dir + '/non-existent-dir/non-existent-file-in-dir.js').toString()).toMatchSnapshot();
expect(fs.readFileSync(pkg.dir + '/non-existent-file-2.js').toString()).toMatchSnapshot();
expect(fs.readFileSync(pkg.dir + '/non-existent-file-3.js').toString()).toMatchSnapshot();
});
});
//# sourceMappingURL=index.test.js.map

22

lib/index.js

@@ -25,5 +25,5 @@ 'use strict';

var _fs = require('fs');
var _fsExtra = require('fs-extra');
var _fs2 = _interopRequireDefault(_fs);
var _fsExtra2 = _interopRequireDefault(_fsExtra);

@@ -107,7 +107,17 @@ var _packages = require('liferay-npm-build-tools-common/lib/packages');

try {
var contents = _fs2.default.readFileSync(src).toString();
var contents = '';
try {
contents = _fsExtra2.default.readFileSync(src).toString();
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
contents = contents.replace('\'' + pkgId + '/' + srcModuleName + '\'', '\'' + pkgId + '/' + destModuleName + '\'');
_fs2.default.writeFileSync(dest, '/* Module replaced with ' + srcName + ' by liferay-npm-bundler-plugin-replace-browser-modules */\n' + contents);
_fsExtra2.default.mkdirsSync(_path2.default.dirname(dest));
_fsExtra2.default.writeFileSync(dest, '/* Module replaced with ' + srcName + ' by liferay-npm-bundler-plugin-replace-browser-modules */\n' + contents);
} catch (err) {

@@ -130,4 +140,6 @@ if (err.code !== 'ENOENT') {

_fs2.default.writeFileSync(file, '/* Module ignored by ' + 'liferay-npm-bundler-plugin-replace-browser-modules */\n');
_fsExtra2.default.mkdirsSync(_path2.default.dirname(file));
_fsExtra2.default.writeFileSync(file, '/* 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.5.0",
"version": "2.5.1",
"description": "A liferay-npm-bundler plugin to replace files listed under the browser/module entry of package.json files.",

@@ -16,4 +16,5 @@ "main": "lib/index.js",

"dependencies": {
"liferay-npm-build-tools-common": "2.5.0"
"fs-extra": "^7.0.1",
"liferay-npm-build-tools-common": "2.5.1"
}
}

@@ -143,11 +143,50 @@ import * as fs from 'fs-extra';

it('does not throw on inexistent files', () => {
const pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: 'non-existent-file.js',
};
describe('works well with non-existent files', () => {
it('when browser field has a unique file', () => {
const pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: 'non-existent-file.js',
};
plugin({pkg, log}, {pkgJson});
plugin({pkg, log}, {pkgJson});
expect(
fs.readFileSync(`${pkg.dir}/main.js`).toString()
).toMatchSnapshot();
});
it('when browser field has several files', () => {
const pkgJson = {
name: pkg.name,
version: pkg.version,
main: 'main.js',
browser: {
'non-existent-file.js': false,
'non-existent-dir/non-existent-file-in-dir.js': false,
'non-existent-file-2.js': 'test-browser.js',
'non-existent-file-3.js': 'non-existent-file-4.js',
},
};
plugin({pkg, log}, {pkgJson});
expect(
fs.readFileSync(`${pkg.dir}/non-existent-file.js`).toString()
).toMatchSnapshot();
expect(
fs
.readFileSync(
`${pkg.dir}/non-existent-dir/non-existent-file-in-dir.js`
)
.toString()
).toMatchSnapshot();
expect(
fs.readFileSync(`${pkg.dir}/non-existent-file-2.js`).toString()
).toMatchSnapshot();
expect(
fs.readFileSync(`${pkg.dir}/non-existent-file-3.js`).toString()
).toMatchSnapshot();
});
});

@@ -1,2 +0,2 @@

import fs from 'fs';
import fs from 'fs-extra';
import * as pkgs from 'liferay-npm-build-tools-common/lib/packages';

@@ -85,4 +85,12 @@ import path from 'path';

try {
let contents = fs.readFileSync(src).toString();
let contents = '';
try {
contents = fs.readFileSync(src).toString();
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
contents = contents.replace(

@@ -93,2 +101,4 @@ `'${pkgId}/${srcModuleName}'`,

fs.mkdirsSync(path.dirname(dest));
fs.writeFileSync(

@@ -121,2 +131,4 @@ dest,

fs.mkdirsSync(path.dirname(file));
fs.writeFileSync(

@@ -123,0 +135,0 @@ file,

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