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

@stencil/postcss

Package Overview
Dependencies
Maintainers
10
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencil/postcss - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

dist/declarations.d.ts

8

dist/index.d.ts

@@ -1,7 +0,1 @@

export interface PluginTransformResults {
code?: string;
id?: string;
}
export interface PluginCtx {
fs: any;
}
export {};

@@ -1,23 +0,127 @@

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const postCss = require("postcss");
module.exports = function postcss(options = {}) {
import postCss from 'postcss';
function loadDiagnostic(context, postcssError, filePath) {
if (!postcssError || !context) {
return;
}
const level = postcssError.level === 'warning' ? 'warn' : postcssError.level || 'error';
const diagnostic = {
level,
type: 'postcss',
language: 'postcss',
header: `postcss ${level}`,
code: postcssError.status && postcssError.status.toString(),
relFilePath: null,
absFilePath: null,
messageText: postcssError.reason,
lines: []
};
if (filePath) {
diagnostic.absFilePath = filePath;
diagnostic.relFilePath = formatFileName(context.config.rootDir, diagnostic.absFilePath);
diagnostic.header = formatHeader('postcss', diagnostic.absFilePath, context.config.rootDir, postcssError.line);
if (postcssError.line > -1) {
try {
const sourceText = context.fs.readFileSync(diagnostic.absFilePath);
const srcLines = sourceText.split(/(\r?\n)/);
const errorLine = {
lineIndex: postcssError.line - 1,
lineNumber: postcssError.line,
text: srcLines[postcssError.line - 1],
errorCharStart: postcssError.column,
errorLength: 0
};
for (let i = errorLine.errorCharStart; i >= 0; i--) {
if (STOP_CHARS.indexOf(errorLine.text.charAt(i)) > -1) {
break;
}
errorLine.errorCharStart = i;
}
for (let j = errorLine.errorCharStart; j <= errorLine.text.length; j++) {
if (STOP_CHARS.indexOf(errorLine.text.charAt(j)) > -1) {
break;
}
errorLine.errorLength++;
}
if (errorLine.errorLength === 0 && errorLine.errorCharStart > 0) {
errorLine.errorLength = 1;
errorLine.errorCharStart--;
}
diagnostic.lines.push(errorLine);
if (errorLine.lineIndex > 0) {
const previousLine = {
lineIndex: errorLine.lineIndex - 1,
lineNumber: errorLine.lineNumber - 1,
text: srcLines[errorLine.lineIndex - 1],
errorCharStart: -1,
errorLength: -1
};
diagnostic.lines.unshift(previousLine);
}
if (errorLine.lineIndex + 1 < srcLines.length) {
const nextLine = {
lineIndex: errorLine.lineIndex + 1,
lineNumber: errorLine.lineNumber + 1,
text: srcLines[errorLine.lineIndex + 1],
errorCharStart: -1,
errorLength: -1
};
diagnostic.lines.push(nextLine);
}
}
catch (e) {
console.error(`StylePostcssPlugin loadDiagnostic, ${e}`);
}
}
}
context.diagnostics.push(diagnostic);
}
function formatFileName(rootDir, fileName) {
if (!rootDir || !fileName)
return '';
fileName = fileName.replace(rootDir, '');
if (/\/|\\/.test(fileName.charAt(0))) {
fileName = fileName.substr(1);
}
if (fileName.length > 80) {
fileName = '...' + fileName.substr(fileName.length - 80);
}
return fileName;
}
function formatHeader(type, fileName, rootDir, startLineNumber = null, endLineNumber = null) {
let header = `${type}: ${formatFileName(rootDir, fileName)}`;
if (startLineNumber !== null && startLineNumber > 0) {
if (endLineNumber !== null && endLineNumber > startLineNumber) {
header += `, lines: ${startLineNumber} - ${endLineNumber}`;
}
else {
header += `, line: ${startLineNumber}`;
}
}
return header;
}
const STOP_CHARS = ['', '\n', '\r', '\t', ' ', ':', ';', ',', '{', '}', '.', '#', '@', '!', '[', ']', '(', ')', '&', '+', '~', '^', '*', '$'];
function usePlugin(fileName) {
return /(\.css|\.pcss)$/i.test(fileName);
}
function createResultsId(fileName) {
// create what the new path is post transform (.css)
const pathParts = fileName.split('.');
pathParts[pathParts.length - 1] = 'css';
return pathParts.join('.');
}
module.exports = function postcss(opts = {}) {
return {
transform: function (sourceText, id, context) {
if (!options.hasOwnProperty('plugins') || options.plugins.length < 1) {
transform: function (sourceText, fileName, context) {
if (!opts.hasOwnProperty('plugins') || opts.plugins.length < 1) {
return null;
}
if (!context || !usePlugin(id)) {
if (!context || !usePlugin(fileName)) {
return null;
}
const results = {};
results.id = id;
const results = {
id: createResultsId(fileName)
};
if (sourceText.trim() === '') {

@@ -27,19 +131,45 @@ results.code = '';

}
return postCss(options.plugins)
.process(sourceText, {
from: id
})
.then((postCssResults) => __awaiter(this, void 0, void 0, function* () {
const warnings = postCssResults.warnings().map(warn => {
return `${warn.type}: ${warn.text}`;
return new Promise(resolve => {
postCss(opts.plugins)
.process(sourceText, {
from: fileName
})
.then(postCssResults => {
const warnings = postCssResults.warnings();
if (warnings.length > 0) {
// emit diagnostics for each warning
warnings.forEach((warn) => {
const err = {
reason: warn.text,
level: warn.type,
column: warn.column || -1,
line: warn.line || -1
};
loadDiagnostic(context, err, fileName);
});
const mappedWarnings = warnings
.map((warn) => {
return `${warn.type} ${warn.plugin ? `(${warn.plugin})` : ''}: ${warn.text}`;
})
.join(', ');
results.code = `/** postcss ${mappedWarnings} **/`;
resolve(results);
}
else {
results.code = postCssResults.css.toString();
// write this css content to memory only so it can be referenced
// later by other plugins (autoprefixer)
// but no need to actually write to disk
context.fs.writeFile(results.id, results.code, { inMemoryOnly: true }).then(() => {
resolve(results);
});
}
return results;
})
.catch((err) => {
loadDiagnostic(context, err, fileName);
results.code = `/** postcss error${err && err.message ? ': ' + err.message : ''} **/`;
resolve(results);
});
if (warnings.length > 0) {
results.code = `/** postcss error${warnings.join(', ')} **/`;
}
else {
results.code = postCssResults.css;
yield context.fs.writeFile(results.id, results.code, { inMemoryOnly: true });
}
return results;
}));
});
},

@@ -49,4 +179,1 @@ name: 'postcss'

};
function usePlugin(id) {
return /(.\.css|.pcss)$/i.test(id);
}
{
"name": "@stencil/postcss",
"version": "0.0.2",
"version": "0.0.3",
"license": "MIT",
"main": "dist/index.js",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/"
],
"scripts": {
"build": "tsc",
"prebuild": "rimraf ./dist && npm run test && npm run lint",
"build": "tsc && npm run rollup",
"watch": "tsc --watch",
"deploy": "npm run build && np --any-branch"
"rollup": "rollup -c",
"version": "npm run build",
"deploy": "np",
"lint": "tslint --project tsconfig.json",
"test": "jest",
"test.watch": "jest --watch"
},
"files": [
"dist/"
],
"dependencies": {

@@ -19,5 +26,11 @@ "postcss": "6.0.17"

"devDependencies": {
"@types/jest": "^22.1.3",
"@types/node": "^8.5.1",
"np": "^2.18.3",
"typescript": "^2.7.1"
"jest": "^22.4.2",
"np": "^2.20.1",
"rimraf": "^2.6.2",
"rollup": "^0.56.2",
"tslint": "^5.9.1",
"tslint-ionic-rules": "0.0.14",
"typescript": "^2.7.2"
},

@@ -34,3 +47,16 @@ "repository": {

"postcss"
]
],
"jest": {
"transform": {
"^.+\\.(js|ts|tsx)$": "<rootDir>/test/jest.preprocessor.js"
},
"testRegex": "(\\.(test|spec))\\.(tsx?|jsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"json",
"jsx"
]
}
}
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