Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inline-critical

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inline-critical - npm Package Compare versions

Comparing version 9.0.1 to 10.0.0

37

cli.js
#!/usr/bin/env node
import {EOL} from 'node:os';
import {readFileSync} from 'node:fs';
import process from 'node:process';
import meow from 'meow';
import picocolors from 'picocolors';
import indentString from 'indent-string';
import stdin from 'get-stdin';
import {parse} from 'css';
import escapeRegExp from 'lodash.escaperegexp';
import defaults from 'lodash.defaults';
import {inline as inlineCritical} from './index.js';
'use strict';
const os = require('os');
const fs = require('fs');
const meow = require('meow');
const chalk = require('chalk');
const indentString = require('indent-string');
const stdin = require('get-stdin');
const css = require('css');
const escapeRegExp = require('lodash.escaperegexp');
const defaults = require('lodash.defaults');
const inlineCritical = require('.');
let ok;

@@ -36,2 +34,3 @@ const help = `

autoVersion: true,
importMeta: import.meta,
flags: {

@@ -125,4 +124,4 @@ css: {

function processError(error) {
process.stderr.write(chalk.red(indentString(`Error: ${error.message || error}`, 2)));
process.stderr.write(os.EOL);
process.stderr.write(picocolors.red(indentString(`Error: ${error.message || error}`, 2)));
process.stderr.write(EOL);
process.stderr.write(indentString(help, 2));

@@ -134,3 +133,3 @@ process.exit(1);

try {
return fs.readFileSync(file, 'utf8');
return readFileSync(file, 'utf8');
} catch (error) {

@@ -148,3 +147,3 @@ processError(error);

try {
css.parse(data);
parse(data);
options_.css = data;

@@ -159,3 +158,3 @@ } catch {

try {
css.parse(temporary);
parse(temporary);
options_.css = temporary;

@@ -175,3 +174,3 @@ } catch {

const out = inlineCritical(html, styles, options);
process.stdout.write(out.toString(), process.exit);
process.stdout.write(out?.toString() ?? '', process.exit);
} catch (error) {

@@ -178,0 +177,0 @@ processError(error);

@@ -12,14 +12,14 @@ /**

'use strict';
import {existsSync, readFileSync, writeFileSync} from 'node:fs';
import process from 'node:process';
import {Buffer} from 'node:buffer';
import {resolve, join} from 'node:path';
import isString from 'lodash.isstring';
import isRegExp from 'lodash.isregexp';
import reaver from 'reaver';
import slash from 'slash';
const fs = require('fs');
const path = require('path');
const isString = require('lodash.isstring');
const isRegExp = require('lodash.isregexp');
const reaver = require('reaver');
const slash = require('slash');
import Dom from './src/dom.js';
import {removeDuplicateStyles} from './src/css.js';
const Dom = require('./src/dom');
const {removeDuplicateStyles} = require('./src/css');
const DEFAULT_OPTIONS = {

@@ -50,4 +50,4 @@ extract: false,

*/
function inline(html, styles, options) {
const o = {...DEFAULT_OPTIONS, ...(options || {})};
export function inline(html, styles, options) {
const o = {...DEFAULT_OPTIONS, ...options};

@@ -63,3 +63,3 @@ if (!isString(html)) {

if (!Array.isArray(o.ignore)) {
o.ignore = [o.ignore].filter((i) => i);
o.ignore = [o.ignore].filter(Boolean);
}

@@ -168,10 +168,10 @@

if (o.extract) {
const file = path.resolve(path.join(o.basePath || process.cwd, href));
const file = resolve(join(o.basePath || process.cwd, href));
if (fs.existsSync(file)) {
const orig = fs.readFileSync(file);
if (existsSync(file)) {
const orig = readFileSync(file);
const diff = removeDuplicateStyles(orig, inlined);
const filename = reaver.rev(file, diff);
fs.writeFileSync(filename, diff);
writeFileSync(filename, diff);
link.setAttribute('href', normalizePath(reaver.rev(href, diff)));

@@ -231,2 +231,2 @@ } else if (!/\/\//.test(href)) {

module.exports = inline;
export default inline;
{
"name": "inline-critical",
"version": "9.0.1",
"version": "10.0.0",
"description": "Inline critical-path css and load the existing stylesheets asynchronously",
"main": "index.js",
"exports": "./index.js",
"type": "module",
"scripts": {
"jest": "jest --coverage",
"xo": "xo",
"jest": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --runInBand --detectOpenHandles",
"xo": "xo --fix",
"test": "npm run xo && npm run jest"

@@ -35,10 +37,9 @@ },

"dependencies": {
"chalk": "^4.1.2",
"clean-css": "^5.2.0",
"clean-css": "^5.3.1",
"css": "^3.0.0",
"detect-indent": "^6.1.0",
"detect-indent": "^7.0.1",
"fg-loadcss": "^2.1.0",
"get-stdin": "^8.0.0",
"indent-string": "^4.0.0",
"jsdom": "^17.0.0",
"get-stdin": "^9.0.0",
"indent-string": "^5.0.0",
"jsdom": "^20.0.0",
"lodash.defaults": "^4.2.0",

@@ -48,16 +49,19 @@ "lodash.escaperegexp": "^4.1.2",

"lodash.isstring": "^4.0.1",
"meow": "^9.0.0",
"normalize-newline": "^3.0.0",
"postcss": "^8.3.8",
"meow": "^10.1.3",
"normalize-newline": "^4.1.0",
"picocolors": "^1.0.0",
"postcss": "^8.4.16",
"postcss-discard": "^2.0.0",
"reaver": "^2.0.0",
"slash": "^3.0.0",
"uglify-js": "^3.14.2"
"slash": "^5.0.0",
"uglify-js": "^3.17.1"
},
"devDependencies": {
"execa": "^5.1.1",
"fs-extra": "^9.1.0",
"jest": "^27.2.2",
"read-pkg-up": "^7.0.1",
"xo": "^0.44.0"
"cross-env": "^7.0.3",
"eslint": "^8.23.1",
"execa": "^6.1.0",
"fs-extra": "^10.1.0",
"jest": "^29.0.3",
"read-pkg-up": "^9.1.0",
"xo": "^0.52.3"
},

@@ -91,4 +95,4 @@ "xo": {

"engines": {
"node": "^10 || ^12 || >=14"
"node": ">=14.16"
}
}

@@ -1,8 +0,6 @@

'use strict';
import CleanCSS from 'clean-css';
import postcss from 'postcss';
import discard from 'postcss-discard';
import normalizeNewline from 'normalize-newline';
const CleanCSS = require('clean-css');
const postcss = require('postcss');
const discard = require('postcss-discard');
const normalizeNewline = require('normalize-newline');
/**

@@ -13,3 +11,3 @@ * Minify CSS

*/
function minifyCss(styles) {
export function minifyCss(styles) {
return new CleanCSS().minify(styles).styles;

@@ -24,3 +22,3 @@ }

*/
function removeDuplicateStyles(styles, ...css) {
export function removeDuplicateStyles(styles, ...css) {
const _styles = normalizeNewline(minifyCss(styles || ''));

@@ -34,6 +32,1 @@ const _css = normalizeNewline(minifyCss(css.join('\n')));

}
module.exports = {
minifyCss,
removeDuplicateStyles,
};

@@ -1,9 +0,9 @@

'use strict';
import {readFileSync} from 'node:fs';
import {join, dirname} from 'node:path';
import {createRequire} from 'node:module';
import {JSDOM} from 'jsdom';
import detectIndent from 'detect-indent';
import {minify as _minify} from 'uglify-js';
const fs = require('fs');
const path = require('path');
const {JSDOM} = require('jsdom');
const detectIndent = require('detect-indent');
const UglifyJS = require('uglify-js');
const require = createRequire(import.meta.url);
const loadCssMain = require.resolve('fg-loadcss');

@@ -19,5 +19,5 @@

function getScript() {
const loadCSS = fs.readFileSync(path.join(path.dirname(loadCssMain), 'cssrelpreload.js'), 'utf8');
const loadCSS = readFileSync(join(dirname(loadCssMain), 'cssrelpreload.js'), 'utf8');
return UglifyJS.minify(loadCSS).code.trim();
return _minify(loadCSS).code.trim();
}

@@ -154,5 +154,3 @@

querySelector(...selector) {
const s = flatten(selector)
.filter((s) => s)
.join(',');
const s = flatten(selector).filter(Boolean).join(',');

@@ -163,5 +161,3 @@ return this.document.querySelector(s);

querySelectorAll(...selector) {
const s = flatten(selector)
.filter((s) => s)
.join(',');
const s = flatten(selector).filter(Boolean).join(',');

@@ -255,2 +251,2 @@ return this.document.querySelectorAll(s);

module.exports = Dom;
export default Dom;
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