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.13.2 to 2.13.3-alpha.6

LICENSE.md

158

lib/index.js

@@ -1,92 +0,82 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (context, _ref) {
var extension = _ref.extension,
_ref$pathModule = _ref.pathModule,
pathModule = _ref$pathModule === undefined ? '/o' : _ref$pathModule;
var filePath = context.filePath,
log = context.log;
var href = getHref(filePath, extension, pathModule);
// Note that Liferay.ThemeDisplay.getPathContext() when called at runtime
// returns both pathProxy and the context path of the portal's webapp.
context.extraArtifacts[filePath + '.js.wrap-modules-amd.template'] = '\nvar link = document.createElement("link");\nlink.setAttribute("rel", "stylesheet");\nlink.setAttribute("type", "text/css");\nlink.setAttribute("href", Liferay.ThemeDisplay.getPathContext() + "' + href + '");\n\nfunction defineModule() {\n\t__WRAPPED_MODULE__\t\n}\n\nlink.onload = defineModule;\n\nlink.onerror = function() {\n\tconsole.warn(\'Unable to load ' + href + '. However, its .js module will still be defined to avoid breaking execution flow (expect some visual degradation).\');\n\n\tdefineModule();\n}\n\ndocument.querySelector("head").appendChild(link);\n';
context.extraArtifacts[filePath + '.js'] = '\nmodule.exports = link;\n';
log.info('css-loader', 'Generated .js module to inject \'' + href + '\'');
"use strict";
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const file_path_1 = __importDefault(require("liferay-npm-build-tools-common/lib/file-path"));
const project_1 = __importDefault(require("liferay-npm-build-tools-common/lib/project"));
const path_1 = __importDefault(require("path"));
/**
* @param {object} context loader's context
*/
function default_1(context, { extension, pathModule = '/o' }) {
const { filePath, log } = context;
const href = getHref(filePath, extension, pathModule);
// Note that Liferay.ThemeDisplay.getPathContext() when called at runtime
// returns both pathProxy and the context path of the portal's webapp.
context.extraArtifacts[`${filePath}.js.wrap-modules-amd.template`] = `
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", Liferay.ThemeDisplay.getPathContext() + "${href}");
var _fs = require('fs');
function defineModule() {
__WRAPPED_MODULE__
}
var _fs2 = _interopRequireDefault(_fs);
link.onload = defineModule;
var _filePath = require('liferay-npm-build-tools-common/lib/file-path');
link.onerror = function() {
console.warn('Unable to load ${href}. However, its .js module will still be defined to avoid breaking execution flow (expect some visual degradation).');
var _filePath2 = _interopRequireDefault(_filePath);
defineModule();
}
var _project = require('liferay-npm-build-tools-common/lib/project');
var _project2 = _interopRequireDefault(_project);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
document.querySelector("head").appendChild(link);
`;
context.extraArtifacts[`${filePath}.js`] = `
module.exports = link;
`;
log.info('css-loader', `Generated .js module to inject '${href}'`);
}
exports.default = default_1;
function getHref(filePath, extension, pathModule) {
var webContextPath = void 0;
if (_project2.default.jar.supported) {
webContextPath = _project2.default.jar.webContextPath;
} else {
var bnd = _fs2.default.readFileSync(_project2.default.dir.join('bnd.bnd').asNative).toString();
var lines = bnd.split('\n');
var webContextPathLine = lines.find(function (line) {
return line.startsWith('Web-ContextPath:');
});
webContextPath = webContextPathLine.substring(16).trim();
}
_project2.default.sources.asNative.forEach(function (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 (extension !== undefined) {
var extname = _path2.default.extname(filePath);
if (extname == '') {
filePath = filePath + '.' + extension;
} else {
filePath = filePath.replace(new RegExp('\\' + extname + '$'), '' + extension);
}
}
filePath = new _filePath2.default(filePath).asPosix;
return '' + pathModule + webContextPath + '/' + filePath;
let webContextPath;
if (project_1.default.jar.supported) {
webContextPath = project_1.default.jar.webContextPath;
}
else {
const bnd = fs_1.default
.readFileSync(project_1.default.dir.join('bnd.bnd').asNative)
.toString();
const lines = bnd.split('\n');
const webContextPathLine = lines.find(line => line.startsWith('Web-ContextPath:'));
webContextPath = webContextPathLine.substring(16).trim();
}
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 (extension !== undefined) {
const extname = path_1.default.extname(filePath);
if (extname == '') {
filePath = `${filePath}.${extension}`;
}
else {
filePath = filePath.replace(new RegExp(`\\${extname}$`), `${extension}`);
}
}
filePath = new file_path_1.default(filePath).asPosix;
return `${pathModule}${webContextPath}/${filePath}`;
}
/**
* @param {object} context loader's context
*/
/**
* © 2017 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
//# sourceMappingURL=index.js.map
{
"name": "liferay-npm-bundler-loader-css-loader",
"version": "2.13.2",
"description": "A liferay-npm-bundler loader that turns CSS files into JavaScript modules that inject a <link> into the HTML when they are required.",
"main": "lib/index.js",
"scripts": {
"build": "babel --source-maps -D -d lib src",
"prepublish": "npm run build"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-es2015": "^6.24.1"
},
"dependencies": {
"liferay-npm-build-tools-common": "2.13.2"
}
"name": "liferay-npm-bundler-loader-css-loader",
"version": "2.13.3-alpha.6+ae09044",
"description": "A liferay-npm-bundler loader that turns CSS files into JavaScript modules that inject a <link> into the HTML when they are required.",
"main": "lib/index.js",
"scripts": {
"copyfiles": "node ../../scripts/copyfiles.js",
"build": "tsc && yarn copyfiles",
"prepublish": "yarn build"
},
"dependencies": {
"liferay-npm-build-tools-common": "2.13.3-alpha.6+ae09044"
},
"gitHead": "ae09044beb216743cb2f1e2273aa6e055716ce64"
}

@@ -68,10 +68,12 @@ /**

project.sources.asNative.forEach(sourcePath => {
// Remove `./` from sourcePath so that it matches the filePath correctly
sourcePath = sourcePath.substring(2);
project.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(sourcePath)) {
filePath = filePath.substring(sourcePath.length + 1);
}
});

@@ -78,0 +80,0 @@ if (extension !== undefined) {

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