liferay-npm-bundler-plugin-replace-browser-modules
Advanced tools
Comparing version 2.13.0 to 2.13.1
@@ -41,3 +41,3 @@ 'use strict'; | ||
* Copy "browser"/"module" module file on top of "main" module file. | ||
* @param {String} pkgDir directory where package is placed | ||
* @param {FilePath} pkgDir directory where package is placed | ||
* @param {String} browser the value of the "browser"/"module" field | ||
@@ -58,6 +58,7 @@ * @param {Object} pkgJson package.json contents | ||
var src = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, browser)); | ||
var dest = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, main)); | ||
var srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, browser)).asNative; | ||
replaceFile(pkgId, src, browser, dest, main, log); | ||
var destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, main)).asNative; | ||
replaceFile(pkgId, srcPath, browser, destPath, main, log); | ||
} | ||
@@ -67,3 +68,3 @@ | ||
* Copy "browser"/"module" module files on top of their server versions. | ||
* @param {String} pkgDir directory where package is placed | ||
* @param {FilePath} pkgDir directory where package is placed | ||
* @param {Object} browser the value of the "browser"/"module" field | ||
@@ -82,12 +83,13 @@ * @param {Object} pkgJson package.json contents | ||
Object.keys(browser).forEach(function (from) { | ||
var to = browser[from]; | ||
var dest = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, from)); | ||
Object.keys(browser).forEach(function (fromModuleName) { | ||
var toModuleName = browser[fromModuleName]; | ||
if (to == false) { | ||
ignoreFile(dest, from, log); | ||
var destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, fromModuleName)).asNative; | ||
if (toModuleName == false) { | ||
ignoreFile(destPath, fromModuleName, log); | ||
} else { | ||
var src = _path2.default.join(pkgDir, pkgs.resolveModuleFile(pkgDir, to)); | ||
var srcPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, toModuleName)).asNative; | ||
replaceFile(pkgId, src, to, dest, from, log); | ||
replaceFile(pkgId, srcPath, toModuleName, destPath, fromModuleName, log); | ||
} | ||
@@ -100,5 +102,5 @@ }); | ||
* @param {String} pkgId package id (name@version) | ||
* @param {String} src path to source file | ||
* @param {String} srcPath path to source file | ||
* @param {String} srcName the name of the source file | ||
* @param {String} dest path to destination file | ||
* @param {String} destPath path to destination file | ||
* @param {String} destName the name of the destination file | ||
@@ -108,3 +110,3 @@ * @param {PluginLogger} log a logger | ||
*/ | ||
function replaceFile(pkgId, src, srcName, dest, destName, log) { | ||
function replaceFile(pkgId, srcPath, srcName, destPath, destName, log) { | ||
var srcModuleName = srcName.replace('.js', ''); | ||
@@ -119,3 +121,3 @@ var destModuleName = destName.replace('.js', ''); | ||
try { | ||
contents = _fsExtra2.default.readFileSync(src).toString(); | ||
contents = _fsExtra2.default.readFileSync(srcPath).toString(); | ||
} catch (err) { | ||
@@ -129,5 +131,5 @@ if (err.code !== 'ENOENT') { | ||
_fsExtra2.default.mkdirsSync(_path2.default.dirname(dest)); | ||
_fsExtra2.default.mkdirsSync(_path2.default.dirname(destPath)); | ||
_fsExtra2.default.writeFileSync(dest, '/* Module replaced with ' + srcName + ' by liferay-npm-bundler-plugin-replace-browser-modules */\n' + contents); | ||
_fsExtra2.default.writeFileSync(destPath, '/* Module replaced with ' + srcName + ' by liferay-npm-bundler-plugin-replace-browser-modules */\n' + contents); | ||
} catch (err) { | ||
@@ -142,14 +144,14 @@ if (err.code !== 'ENOENT') { | ||
* Ignores one package | ||
* @param {String} file path to file to be ignored | ||
* @param {String} fileName the name of the file | ||
* @param {String} filePath path to file to be ignored | ||
* @param {String} moduleName the name of the file | ||
* @param {PluginLogger} log a logger | ||
* @return {void} | ||
*/ | ||
function ignoreFile(file, fileName, log) { | ||
log.info('replace-browser-modules', 'Emptying module ' + fileName + ' because it is server-only'); | ||
function ignoreFile(filePath, moduleName, log) { | ||
log.info('replace-browser-modules', 'Emptying module ' + moduleName + ' because it is server-only'); | ||
_fsExtra2.default.mkdirsSync(_path2.default.dirname(file)); | ||
_fsExtra2.default.mkdirsSync(_path2.default.dirname(filePath)); | ||
_fsExtra2.default.writeFileSync(file, '/* Module ignored by ' + 'liferay-npm-bundler-plugin-replace-browser-modules */\n'); | ||
_fsExtra2.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.0", | ||
"version": "2.13.1", | ||
"description": "A liferay-npm-bundler plugin to replace files listed under the browser/module entry of package.json files.", | ||
@@ -17,4 +17,4 @@ "main": "lib/index.js", | ||
"fs-extra": "^7.0.1", | ||
"liferay-npm-build-tools-common": "2.13.0" | ||
"liferay-npm-build-tools-common": "2.13.1" | ||
} | ||
} |
@@ -8,2 +8,3 @@ /** | ||
import * as fs from 'fs-extra'; | ||
import FilePath from 'liferay-npm-build-tools-common/lib/file-path'; | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
@@ -18,3 +19,3 @@ import rcopy from 'recursive-copy'; | ||
version: '1.0.0', | ||
dir: `${__dirname}/pkg`, | ||
dir: new FilePath(`${__dirname}/pkg`), | ||
}; | ||
@@ -28,3 +29,5 @@ | ||
rcopy(`${__dirname}/__fixtures__`, pkg.dir, {overwrite: true}).then(done); | ||
rcopy(`${__dirname}/__fixtures__`, pkg.dir.asNative, { | ||
overwrite: true, | ||
}).then(done); | ||
}); | ||
@@ -34,4 +37,4 @@ | ||
afterEach(() => { | ||
fs.emptyDirSync(pkg.dir); | ||
fs.rmdirSync(pkg.dir); | ||
fs.emptyDirSync(pkg.dir.asNative); | ||
fs.rmdirSync(pkg.dir.asNative); | ||
}); | ||
@@ -38,0 +41,0 @@ |
@@ -28,3 +28,3 @@ /** | ||
* Copy "browser"/"module" module file on top of "main" module file. | ||
* @param {String} pkgDir directory where package is placed | ||
* @param {FilePath} pkgDir directory where package is placed | ||
* @param {String} browser the value of the "browser"/"module" field | ||
@@ -39,6 +39,10 @@ * @param {Object} pkgJson package.json contents | ||
const src = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, browser)); | ||
const dest = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, main)); | ||
const srcPath = pkgDir.join( | ||
pkgs.resolveModuleFile(pkgDir.asNative, browser) | ||
).asNative; | ||
replaceFile(pkgId, src, browser, dest, main, log); | ||
const destPath = pkgDir.join(pkgs.resolveModuleFile(pkgDir.asNative, main)) | ||
.asNative; | ||
replaceFile(pkgId, srcPath, browser, destPath, main, log); | ||
} | ||
@@ -48,3 +52,3 @@ | ||
* Copy "browser"/"module" module files on top of their server versions. | ||
* @param {String} pkgDir directory where package is placed | ||
* @param {FilePath} pkgDir directory where package is placed | ||
* @param {Object} browser the value of the "browser"/"module" field | ||
@@ -58,12 +62,24 @@ * @param {Object} pkgJson package.json contents | ||
Object.keys(browser).forEach(from => { | ||
const to = browser[from]; | ||
const dest = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, from)); | ||
Object.keys(browser).forEach(fromModuleName => { | ||
const toModuleName = browser[fromModuleName]; | ||
if (to == false) { | ||
ignoreFile(dest, from, log); | ||
const destPath = pkgDir.join( | ||
pkgs.resolveModuleFile(pkgDir.asNative, fromModuleName) | ||
).asNative; | ||
if (toModuleName == false) { | ||
ignoreFile(destPath, fromModuleName, log); | ||
} else { | ||
const src = path.join(pkgDir, pkgs.resolveModuleFile(pkgDir, to)); | ||
const srcPath = pkgDir.join( | ||
pkgs.resolveModuleFile(pkgDir.asNative, toModuleName) | ||
).asNative; | ||
replaceFile(pkgId, src, to, dest, from, log); | ||
replaceFile( | ||
pkgId, | ||
srcPath, | ||
toModuleName, | ||
destPath, | ||
fromModuleName, | ||
log | ||
); | ||
} | ||
@@ -76,5 +92,5 @@ }); | ||
* @param {String} pkgId package id (name@version) | ||
* @param {String} src path to source file | ||
* @param {String} srcPath path to source file | ||
* @param {String} srcName the name of the source file | ||
* @param {String} dest path to destination file | ||
* @param {String} destPath path to destination file | ||
* @param {String} destName the name of the destination file | ||
@@ -84,3 +100,3 @@ * @param {PluginLogger} log a logger | ||
*/ | ||
function replaceFile(pkgId, src, srcName, dest, destName, log) { | ||
function replaceFile(pkgId, srcPath, srcName, destPath, destName, log) { | ||
const srcModuleName = srcName.replace('.js', ''); | ||
@@ -98,3 +114,3 @@ const destModuleName = destName.replace('.js', ''); | ||
try { | ||
contents = fs.readFileSync(src).toString(); | ||
contents = fs.readFileSync(srcPath).toString(); | ||
} catch (err) { | ||
@@ -111,6 +127,6 @@ if (err.code !== 'ENOENT') { | ||
fs.mkdirsSync(path.dirname(dest)); | ||
fs.mkdirsSync(path.dirname(destPath)); | ||
fs.writeFileSync( | ||
dest, | ||
destPath, | ||
'/* Module replaced with ' + | ||
@@ -130,17 +146,17 @@ srcName + | ||
* Ignores one package | ||
* @param {String} file path to file to be ignored | ||
* @param {String} fileName the name of the file | ||
* @param {String} filePath path to file to be ignored | ||
* @param {String} moduleName the name of the file | ||
* @param {PluginLogger} log a logger | ||
* @return {void} | ||
*/ | ||
function ignoreFile(file, fileName, log) { | ||
function ignoreFile(filePath, moduleName, log) { | ||
log.info( | ||
'replace-browser-modules', | ||
`Emptying module ${fileName} because it is server-only` | ||
`Emptying module ${moduleName} because it is server-only` | ||
); | ||
fs.mkdirsSync(path.dirname(file)); | ||
fs.mkdirsSync(path.dirname(filePath)); | ||
fs.writeFileSync( | ||
file, | ||
filePath, | ||
'/* Module ignored by ' + | ||
@@ -147,0 +163,0 @@ 'liferay-npm-bundler-plugin-replace-browser-modules */\n' |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27511
486
+ Addedbabel-plugin-add-module-metadata@2.13.1(transitive)
+ Addedbabel-plugin-name-amd-modules@2.13.1(transitive)
+ Addedbabel-plugin-namespace-amd-define@2.13.1(transitive)
+ Addedbabel-plugin-namespace-modules@2.13.1(transitive)
+ Addedbabel-plugin-normalize-requires@2.13.1(transitive)
+ Addedbabel-plugin-wrap-modules-amd@2.13.1(transitive)
+ Addedbabel-preset-liferay-standard@2.13.1(transitive)
+ Addedliferay-npm-build-tools-common@2.13.1(transitive)
+ Addedliferay-npm-bundler-plugin-exclude-imports@2.13.1(transitive)
+ Addedliferay-npm-bundler-plugin-inject-imports-dependencies@2.13.1(transitive)
+ Addedliferay-npm-bundler-plugin-inject-peer-dependencies@2.13.1(transitive)
+ Addedliferay-npm-bundler-plugin-namespace-packages@2.13.1(transitive)
+ Addedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.13.1(transitive)
+ Addedliferay-npm-bundler-preset-standard@2.13.1(transitive)
- Removedbabel-plugin-add-module-metadata@2.13.0(transitive)
- Removedbabel-plugin-name-amd-modules@2.13.0(transitive)
- Removedbabel-plugin-namespace-amd-define@2.13.0(transitive)
- Removedbabel-plugin-namespace-modules@2.13.0(transitive)
- Removedbabel-plugin-normalize-requires@2.13.0(transitive)
- Removedbabel-plugin-wrap-modules-amd@2.13.0(transitive)
- Removedbabel-preset-liferay-standard@2.13.0(transitive)
- Removedliferay-npm-build-tools-common@2.13.0(transitive)
- Removedliferay-npm-bundler-plugin-exclude-imports@2.13.0(transitive)
- Removedliferay-npm-bundler-plugin-inject-imports-dependencies@2.13.0(transitive)
- Removedliferay-npm-bundler-plugin-inject-peer-dependencies@2.13.0(transitive)
- Removedliferay-npm-bundler-plugin-namespace-packages@2.13.0(transitive)
- Removedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.13.0(transitive)
- Removedliferay-npm-bundler-preset-standard@2.13.0(transitive)