New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-css-require

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-css-require - npm Package Compare versions

Comparing version 0.1.4 to 0.4.0

3

dist/src/nodeCssRequire.d.ts

@@ -11,4 +11,5 @@ import { AcceptedPlugin } from 'postcss';

}
export declare function compileCss(code: string, filename: string, config?: CompileCssConfiguration): CompileCssResult;
export declare function compileCss(code: string, filename: string, config?: CompileCssConfiguration): Promise<CompileCssResult>;
export declare function compileCssSync(code: string, filename: string, config?: CompileCssConfiguration): CompileCssResult;
export declare const register: () => void;
//# sourceMappingURL=nodeCssRequire.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.register = exports.compileCss = void 0;
exports.register = exports.compileCssSync = exports.compileCss = void 0;
/* eslint-disable @typescript-eslint/no-var-requires */

@@ -12,8 +12,40 @@ const pirates_1 = require("pirates");

const postcss_modules_sync_1 = __importDefault(require("postcss-modules-sync"));
const postcss_modules_1 = __importDefault(require("postcss-modules"));
const register_1 = require("@swc-node/register/register");
function compileCss(code, filename, config) {
const crypto_1 = require("crypto");
function generateScopedName(name, filename, css) {
const i = css.indexOf(`.${name}`);
const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
const hash = (0, crypto_1.createHash)('md5').update(css).digest('hex');
return `${name}_${hash}_${lineNumber}`;
}
async function compileCss(code, filename, config) {
let exportedTokens = {};
const plugins = [
(0, postcss_modules_1.default)({
generateScopedName: generateScopedName,
getJSON: (cssFileName, json, outputFileName) => {
exportedTokens = json;
},
}),
];
let res = (0, postcss_1.default)(plugins).process(code, { from: filename });
await res;
// apply other postcss magic after class names have been mapped
if ((config === null || config === void 0 ? void 0 : config.plugins) && config.plugins.length > 0) {
res = (0, postcss_1.default)(config.plugins).process(res.css, { from: filename });
await res;
}
const js = `module.exports = JSON.parse('${JSON.stringify(exportedTokens)}');`;
return {
js,
css: res.css,
};
}
exports.compileCss = compileCss;
function compileCssSync(code, filename, config) {
let exportedTokens = {};
const plugins = [
(0, postcss_modules_sync_1.default)({
generateScopedName: (config === null || config === void 0 ? void 0 : config.generateScopedName) || '[path][local]-[hash:base64:10]',
generateScopedName: generateScopedName,
getJSON: (tokens) => {

@@ -42,8 +74,8 @@ exportedTokens = tokens;

}
exports.compileCss = compileCss;
function compileJs(code, filename) {
return compileCss(code, filename).js;
exports.compileCssSync = compileCssSync;
function compileJsSync(code, filename) {
return compileCssSync(code, filename).js;
}
const register = () => {
(0, pirates_1.addHook)((code, filename) => compileJs(code, filename), {
(0, pirates_1.addHook)((code, filename) => compileJsSync(code, filename), {
exts: ['.css'],

@@ -50,0 +82,0 @@ });

{
"name": "node-css-require",
"version": "0.1.4",
"version": "0.4.0",
"description": "Load CSS modules when running Node.js CLI and server applications",

@@ -39,6 +39,7 @@ "keywords": [

"postcss": "^8.4.14",
"postcss-modules": "^5.0.0",
"postcss-modules-sync": "^1.0.0"
},
"devDependencies": {
"@goldstack/utils-git": "0.1.37",
"@goldstack/utils-git": "0.2.0",
"@types/jest": "^28.1.8",

@@ -45,0 +46,0 @@ "@types/node": "^18.7.13",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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