liferay-npm-bundler-plugin-replace-browser-modules
Advanced tools
Comparing version 2.1.1 to 2.2.0
'use strict'; | ||
var _cpFile = require('cp-file'); | ||
var _fsExtra = require('fs-extra'); | ||
var _cpFile2 = _interopRequireDefault(_cpFile); | ||
var fs = _interopRequireWildcard(_fsExtra); | ||
var _fs = require('fs'); | ||
var fs = _interopRequireWildcard(_fs); | ||
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger'); | ||
@@ -15,2 +11,6 @@ | ||
var _recursiveCopy = require('recursive-copy'); | ||
var _recursiveCopy2 = _interopRequireDefault(_recursiveCopy); | ||
var _index = require('../index'); | ||
@@ -20,6 +20,6 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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 }; } | ||
// Package descriptor used in tests | ||
@@ -30,16 +30,12 @@ var pkg = { | ||
version: '1.0.0', | ||
dir: process.cwd() + '/packages/' + 'liferay-npm-bundler-plugin-replace-browser-modules/src/__tests__' | ||
dir: __dirname + '/pkg' | ||
}; | ||
// Package files used in tests | ||
var pkgFiles = ['test-2.js.file', 'test-browser-2.js.file', 'test-browser.js.file', 'test-main.js.file', 'test.js.file']; | ||
var log = void 0; | ||
// Restore package status prior to running each test | ||
beforeEach(function () { | ||
beforeEach(function (done) { | ||
log = new _pluginLogger2.default(); | ||
pkgFiles.forEach(function (file) { | ||
_cpFile2.default.sync(pkg.dir + '/sources/' + file, pkg.dir + '/' + file); | ||
}); | ||
(0, _recursiveCopy2.default)(__dirname + '/__fixtures__', pkg.dir, { overwrite: true }).then(done); | ||
}); | ||
@@ -49,7 +45,4 @@ | ||
afterEach(function () { | ||
pkgFiles.forEach(function (file) { | ||
try { | ||
fs.unlinkSync(pkg.dir + '/' + file); | ||
} catch (err) {} | ||
}); | ||
fs.emptyDirSync(pkg.dir); | ||
fs.rmdirSync(pkg.dir); | ||
}); | ||
@@ -61,4 +54,4 @@ | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
browser: 'test-browser.js.file' | ||
main: 'test-main.js', | ||
browser: 'test-browser.js' | ||
}; | ||
@@ -75,4 +68,4 @@ | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
browser: 'test-browser.js.file' | ||
main: 'test-main.js', | ||
browser: 'test-browser.js' | ||
}; | ||
@@ -82,5 +75,18 @@ | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js').toString()).toMatchSnapshot(); | ||
}); | ||
it('replaces main directory with browser file', function () { | ||
var pkgJson = { | ||
name: pkg.name, | ||
version: pkg.version, | ||
main: './dir', | ||
browser: 'test-browser.js' | ||
}; | ||
(0, _index2.default)({ pkg: pkg, log: log }, { pkgJson: pkgJson }); | ||
expect(fs.readFileSync(pkg.dir + '/dir/index.js').toString()).toMatchSnapshot(); | ||
}); | ||
it('works with unpkg field too', function () { | ||
@@ -90,4 +96,4 @@ var pkgJson = { | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
unpkg: 'test-browser.js.file' | ||
main: 'test-main.js', | ||
unpkg: 'test-browser.js' | ||
}; | ||
@@ -97,3 +103,3 @@ | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js').toString()).toMatchSnapshot(); | ||
}); | ||
@@ -105,4 +111,4 @@ | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
jsdelivr: 'test-browser.js.file' | ||
main: 'test-main.js', | ||
jsdelivr: 'test-browser.js' | ||
}; | ||
@@ -112,3 +118,3 @@ | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-main.js').toString()).toMatchSnapshot(); | ||
}); | ||
@@ -121,4 +127,5 @@ | ||
browser: { | ||
'test-browser.js.file': 'test.js.file', | ||
'test-browser-2.js.file': 'test-2.js.file' | ||
'dir': 'test-main.js', | ||
'test-browser.js': 'test.js', | ||
'test-browser-2.js': 'test-2.js' | ||
} | ||
@@ -129,4 +136,5 @@ }; | ||
expect(fs.readFileSync(pkg.dir + '/test-browser.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-browser-2.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/dir/index.js').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-browser.js').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-browser-2.js').toString()).toMatchSnapshot(); | ||
}); | ||
@@ -140,3 +148,3 @@ | ||
browser: { | ||
'test-browser.js.file': false | ||
'test-browser.js': false | ||
} | ||
@@ -147,3 +155,3 @@ }; | ||
expect(fs.readFileSync(pkg.dir + '/test-browser.js.file').toString()).toMatchSnapshot(); | ||
expect(fs.readFileSync(pkg.dir + '/test-browser.js').toString()).toMatchSnapshot(); | ||
}); | ||
@@ -150,0 +158,0 @@ |
@@ -29,2 +29,6 @@ 'use strict'; | ||
var _packages = require('liferay-npm-build-tools-common/lib/packages'); | ||
var pkgs = _interopRequireWildcard(_packages); | ||
var _path = require('path'); | ||
@@ -34,2 +38,4 @@ | ||
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 }; } | ||
@@ -49,4 +55,4 @@ | ||
var src = _path2.default.join(pkgDir, browser); | ||
var dest = _path2.default.join(pkgDir, main); | ||
var src = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, browser)); | ||
var dest = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, main)); | ||
@@ -74,3 +80,3 @@ replaceFile(pkgId, src, browser, dest, main, log); | ||
var to = browser[from]; | ||
var dest = _path2.default.join(pkgDir, from); | ||
var dest = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, from)); | ||
@@ -80,3 +86,3 @@ if (to == false) { | ||
} else { | ||
var src = _path2.default.join(pkgDir, to); | ||
var src = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, to)); | ||
@@ -83,0 +89,0 @@ replaceFile(pkgId, src, to, dest, from, log); |
{ | ||
"name": "liferay-npm-bundler-plugin-replace-browser-modules", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A liferay-npm-bundler plugin to replace files listed under the browser/module entry of package.json files.", | ||
@@ -13,4 +13,7 @@ "main": "lib/index.js", | ||
"babel-preset-es2015": "^6.24.1", | ||
"cp-file": "^4.2.0" | ||
"recursive-copy": "^2.0.9" | ||
}, | ||
"dependencies": { | ||
"liferay-npm-build-tools-common": "2.2.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
import cpFile from 'cp-file'; | ||
import * as fs from 'fs'; | ||
import * as fs from 'fs-extra'; | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
import rcopy from 'recursive-copy'; | ||
import plugin from '../index'; | ||
@@ -11,24 +11,12 @@ | ||
version: '1.0.0', | ||
dir: | ||
`${process.cwd()}/packages/` + | ||
`liferay-npm-bundler-plugin-replace-browser-modules/src/__tests__`, | ||
dir: `${__dirname}/pkg`, | ||
}; | ||
// Package files used in tests | ||
const pkgFiles = [ | ||
'test-2.js.file', | ||
'test-browser-2.js.file', | ||
'test-browser.js.file', | ||
'test-main.js.file', | ||
'test.js.file', | ||
]; | ||
let log; | ||
// Restore package status prior to running each test | ||
beforeEach(() => { | ||
beforeEach(done => { | ||
log = new PluginLogger(); | ||
pkgFiles.forEach(file => { | ||
cpFile.sync(`${pkg.dir}/sources/${file}`, `${pkg.dir}/${file}`); | ||
}); | ||
rcopy(`${__dirname}/__fixtures__`, pkg.dir, {overwrite: true}).then(done); | ||
}); | ||
@@ -38,7 +26,4 @@ | ||
afterEach(() => { | ||
pkgFiles.forEach(file => { | ||
try { | ||
fs.unlinkSync(`${pkg.dir}/${file}`); | ||
} catch (err) {} | ||
}); | ||
fs.emptyDirSync(pkg.dir); | ||
fs.rmdirSync(pkg.dir); | ||
}); | ||
@@ -50,4 +35,4 @@ | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
browser: 'test-browser.js.file', | ||
main: 'test-main.js', | ||
browser: 'test-browser.js', | ||
}; | ||
@@ -64,4 +49,4 @@ | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
browser: 'test-browser.js.file', | ||
main: 'test-main.js', | ||
browser: 'test-browser.js', | ||
}; | ||
@@ -72,6 +57,21 @@ | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-main.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/test-main.js`).toString() | ||
).toMatchSnapshot(); | ||
}); | ||
it('replaces main directory with browser file', () => { | ||
const pkgJson = { | ||
name: pkg.name, | ||
version: pkg.version, | ||
main: './dir', | ||
browser: 'test-browser.js', | ||
}; | ||
plugin({pkg, log}, {pkgJson}); | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/dir/index.js`).toString() | ||
).toMatchSnapshot(); | ||
}); | ||
it('works with unpkg field too', () => { | ||
@@ -81,4 +81,4 @@ const pkgJson = { | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
unpkg: 'test-browser.js.file', | ||
main: 'test-main.js', | ||
unpkg: 'test-browser.js', | ||
}; | ||
@@ -89,3 +89,3 @@ | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-main.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/test-main.js`).toString() | ||
).toMatchSnapshot(); | ||
@@ -98,4 +98,4 @@ }); | ||
version: pkg.version, | ||
main: 'test-main.js.file', | ||
jsdelivr: 'test-browser.js.file', | ||
main: 'test-main.js', | ||
jsdelivr: 'test-browser.js', | ||
}; | ||
@@ -106,3 +106,3 @@ | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-main.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/test-main.js`).toString() | ||
).toMatchSnapshot(); | ||
@@ -116,4 +116,5 @@ }); | ||
browser: { | ||
'test-browser.js.file': 'test.js.file', | ||
'test-browser-2.js.file': 'test-2.js.file', | ||
'dir': 'test-main.js', | ||
'test-browser.js': 'test.js', | ||
'test-browser-2.js': 'test-2.js', | ||
}, | ||
@@ -125,7 +126,10 @@ }; | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-browser.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/dir/index.js`).toString() | ||
).toMatchSnapshot(); | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-browser-2.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/test-browser.js`).toString() | ||
).toMatchSnapshot(); | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-browser-2.js`).toString() | ||
).toMatchSnapshot(); | ||
}); | ||
@@ -139,3 +143,3 @@ | ||
browser: { | ||
'test-browser.js.file': false, | ||
'test-browser.js': false, | ||
}, | ||
@@ -147,3 +151,3 @@ }; | ||
expect( | ||
fs.readFileSync(`${pkg.dir}/test-browser.js.file`).toString() | ||
fs.readFileSync(`${pkg.dir}/test-browser.js`).toString() | ||
).toMatchSnapshot(); | ||
@@ -150,0 +154,0 @@ }); |
import fs from 'fs'; | ||
import * as pkgs from 'liferay-npm-build-tools-common/lib/packages'; | ||
import path from 'path'; | ||
@@ -33,4 +34,4 @@ | ||
const src = path.join(pkgDir, browser); | ||
const dest = path.join(pkgDir, main); | ||
const src = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, browser)); | ||
const dest = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, main)); | ||
@@ -53,3 +54,3 @@ replaceFile(pkgId, src, browser, dest, main, log); | ||
const to = browser[from]; | ||
const dest = path.join(pkgDir, from); | ||
const dest = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, from)); | ||
@@ -59,3 +60,3 @@ if (to == false) { | ||
} else { | ||
const src = path.join(pkgDir, to); | ||
const src = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, to)); | ||
@@ -62,0 +63,0 @@ replaceFile(pkgId, src, to, dest, from, log); |
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
38399
29
562
1
+ Addedliferay-npm-build-tools-common@2.2.0(transitive)
+ Addedread-json-sync@2.0.1(transitive)