liferay-npm-bundler-plugin-replace-browser-modules
Advanced tools
Comparing version 2.6.0-alpha.c8357d7f to 2.6.0
@@ -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 |
@@ -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.6.0-alpha.c8357d7f", | ||
"version": "2.6.0", | ||
"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.6.0-alpha.c8357d7f" | ||
"fs-extra": "^7.0.1", | ||
"liferay-npm-build-tools-common": "2.6.0" | ||
} | ||
} |
@@ -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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
45296
636
1
2
+ Addedfs-extra@^7.0.1
+ Addedfs-extra@7.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedliferay-npm-build-tools-common@2.6.0(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removedliferay-npm-build-tools-common@2.6.0-alpha.c8357d7f(transitive)