Socket
Socket
Sign inDemoInstall

liferay-npm-bundler-loader-css-loader

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

liferay-npm-bundler-loader-css-loader - npm Package Compare versions

Comparing version 2.17.1 to 2.18.0

43

lib/index.js

@@ -15,8 +15,9 @@ "use strict";

const path_1 = __importDefault(require("path"));
const read_json_sync_1 = __importDefault(require("read-json-sync"));
/**
* @param {object} context loader's context
*/
function default_1(context, { extension, pathModule = '/o' }) {
function default_1(context, { extension, namespaceDependencies = true, pathModule = '/o' }) {
const { filePath, log } = context;
const href = getHref(filePath, extension, pathModule);
const href = getHref(filePath, extension, pathModule, namespaceDependencies);
// Note that Liferay.ThemeDisplay.getPathContext() when called at runtime

@@ -50,3 +51,3 @@ // returns both pathProxy and the context path of the portal's webapp.

exports.default = default_1;
function getHref(filePath, extension, pathModule) {
function getHref(filePath, extension, pathModule, namespaceDependencies) {
let webContextPath;

@@ -68,11 +69,23 @@ if (project_1.default.jar.supported) {

}
project_1.default.sources
.map(source => source.asNative)
.forEach(sourcePath => {
// Remove `./` from sourcePath so that it matches the filePath correctly
sourcePath = sourcePath.substring(2);
if (filePath.startsWith(sourcePath)) {
filePath = filePath.substring(sourcePath.length + 1);
if (filePath.startsWith(`node_modules${path_1.default.sep}`)) {
const pathParts = filePath.split(path_1.default.sep);
const projectNameIndex = lastIndexOf(pathParts, 'node_modules') + 1;
const { version } = read_json_sync_1.default(path_1.default.join('node_modules', pathParts[projectNameIndex], 'package.json'));
if (namespaceDependencies) {
pathParts[projectNameIndex] = `${project_1.default.pkgJson.name}$${pathParts[projectNameIndex]}`;
}
});
pathParts[projectNameIndex] += `@${version}`;
filePath = pathParts.join(path_1.default.sep);
}
else {
// If file is inside a source folder, strip the folder name
for (let sourcePath of project_1.default.sources.map(source => source.asNative)) {
// Remove `./` from sourcePath so that it matches the filePath correctly
sourcePath = sourcePath.substring(2);
if (filePath.startsWith(sourcePath)) {
filePath = filePath.substring(sourcePath.length + 1);
break;
}
}
}
if (extension !== undefined) {

@@ -90,1 +103,9 @@ const extname = path_1.default.extname(filePath);

}
function lastIndexOf(array, item) {
for (let i = array.length - 1; i >= 0; i--) {
if (array[i] === item) {
return i;
}
}
return -1;
}
{
"name": "liferay-npm-bundler-loader-css-loader",
"version": "2.17.1",
"version": "2.18.0",
"description": "A liferay-npm-bundler loader that turns CSS files into JavaScript modules that inject a <link> into the HTML when they are required.",

@@ -12,5 +12,6 @@ "main": "lib/index.js",

"dependencies": {
"liferay-npm-build-tools-common": "2.17.1"
"liferay-npm-build-tools-common": "2.18.0",
"read-json-sync": "^2.0.1"
},
"gitHead": "33e9c0c40f47bf8eb1b8b7ef497b92b36bf511e3"
"gitHead": "b493e109afa2c706ce5fcea79b81a54ac72578d9"
}

@@ -11,2 +11,3 @@ /**

import path from 'path';
import readJsonSync from 'read-json-sync';

@@ -16,6 +17,14 @@ /**

*/
export default function(context, {extension, pathModule = '/o'}) {
export default function(
context,
{extension, namespaceDependencies = true, pathModule = '/o'}
) {
const {filePath, log} = context;
const href = getHref(filePath, extension, pathModule);
const href = getHref(
filePath,
extension,
pathModule,
namespaceDependencies
);

@@ -51,3 +60,3 @@ // Note that Liferay.ThemeDisplay.getPathContext() when called at runtime

function getHref(filePath, extension, pathModule) {
function getHref(filePath, extension, pathModule, namespaceDependencies) {
let webContextPath;

@@ -78,5 +87,27 @@

project.sources
.map(source => source.asNative)
.forEach(sourcePath => {
if (filePath.startsWith(`node_modules${path.sep}`)) {
const pathParts = filePath.split(path.sep);
const projectNameIndex = lastIndexOf(pathParts, 'node_modules') + 1;
const {version} = readJsonSync(
path.join(
'node_modules',
pathParts[projectNameIndex],
'package.json'
)
);
if (namespaceDependencies) {
pathParts[
projectNameIndex
] = `${project.pkgJson.name}$${pathParts[projectNameIndex]}`;
}
pathParts[projectNameIndex] += `@${version}`;
filePath = pathParts.join(path.sep);
} else {
// If file is inside a source folder, strip the folder name
for (let sourcePath of project.sources.map(source => source.asNative)) {
// Remove `./` from sourcePath so that it matches the filePath correctly

@@ -87,4 +118,7 @@ sourcePath = sourcePath.substring(2);

filePath = filePath.substring(sourcePath.length + 1);
break;
}
});
}
}

@@ -108,1 +142,11 @@ if (extension !== undefined) {

}
function lastIndexOf(array, item) {
for (let i = array.length - 1; i >= 0; i--) {
if (array[i] === item) {
return i;
}
}
return -1;
}
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