Socket
Socket
Sign inDemoInstall

rcs-core

Package Overview
Dependencies
59
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.5.1 to 3.6.0

5

CHANGELOG.md

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

3.6.0 - January, 07 2021
* 9f59986 Feat: setInclude | warn on already excluded values (#121) (Jan Peer Stöcklmair)
* 2907583 Chore(deps): bump lodash from 4.17.15 to 4.17.20 (#118) (dependabot[bot])
3.5.1 - November, 12 2020

@@ -2,0 +7,0 @@

11

dest/allWarnings.d.ts

@@ -6,4 +6,12 @@ export interface Source {

}
export declare type WarningTypes = 'compressed' | 'ignoredFound';
export declare class Warnings {
ranOnMinifiedFiles: boolean;
list: Record<WarningTypes, {
[s: string]: Source[];
}>;
/**
* @deprecated This has been renamed to
* 'rcs.warnings.list.compressed' instead of 'rcs.warnings.warningArray
*/
warningArray: {

@@ -15,3 +23,4 @@ [s: string]: Source[];

reset(): void;
append(value: string, source: Source | undefined): void;
append(value: string, source: Source | undefined, warningType?: WarningTypes): void;
private warnList;
warn(): void;

@@ -18,0 +27,0 @@ }

85

dest/allWarnings.js

@@ -10,3 +10,27 @@ "use strict";

this.ranOnMinifiedFiles = false;
this.list = {
compressed: {},
ignoredFound: {}
};
/**
* @deprecated This has been renamed to
* 'rcs.warnings.list.compressed' instead of 'rcs.warnings.warningArray
*/
this.warningArray = {};
this.warnList = list => {
Object.entries(list).forEach(([key, line]) => {
if (line.length) {
// eslint-disable-next-line no-console
console.warn(` - '${key}' found in: `); // eslint-disable-next-line no-console
line.forEach(e => console.warn(` ${e.file}(${e.line}): ${this.summary(e.text)}`));
} else {
// eslint-disable-next-line no-console
console.warn(` - '${key}'`);
}
});
};
this.reset();

@@ -25,46 +49,55 @@ }

reset() {
this.warningArray = {};
this.list = {
compressed: {},
ignoredFound: {}
};
this.ranOnMinifiedFiles = false;
}
append(value, source) {
if (value in this.warningArray) {
if (source && this.warningArray[value].findIndex(e => e.file === source.file && e.line === source.line) === -1) {
this.warningArray[value].push(source);
append(value, source, warningType = 'compressed') {
const typeList = this.list[warningType]; // check if these values are some reserved values like __proto__
// as these can be found in the ignored selectors
if (value in typeList && !typeList[value].findIndex) {
return;
}
if (value in typeList) {
if (source && typeList[value].findIndex(e => e.file === source.file && e.line === source.line) === -1) {
typeList[value].push(source);
}
} else {
this.warningArray[value] = source ? [source] : [];
typeList[value] = source ? [source] : [];
}
this.warningArray = this.list.compressed;
}
warn() {
const keys = Object.keys(this.warningArray);
if (!keys.length) return; // eslint-disable-next-line no-console
const compressedEntries = Object.entries(this.list.compressed);
const ignoredFoundEntries = Object.entries(this.list.ignoredFound); // warn if some ignored selectors has been searched for
console.warn('WARNING: The following selectors were not found in the rename table, but ' + 'appears in the compressed map. In order to avoid that some other selectors ' + 'are used instead, they were appended with \'_conflict\'. You need to fix this ' + 'either by:\n'); // eslint-disable-next-line no-console
if (ignoredFoundEntries.length) {
console.warn('WARNING: The following selectors got found but were ignored. ' + 'please check if you do not want to allow these selectors instead');
this.warnList(this.list.ignoredFound);
} // warn if compressed selectors has been found
console.warn('- Creating a CSS rule with the selector name and re-run the process, or'); // eslint-disable-next-line no-console
console.warn('- Excluding the selectors so it\'s not renamed, or'); // eslint-disable-next-line no-console
if (compressedEntries.length) {
// eslint-disable-next-line no-console
console.warn('WARNING: The following selectors were not found in the rename table, but ' + 'appears in the compressed map. In order to avoid that some other selectors ' + 'are used instead, they were appended with \'_conflict\'. You need to fix this ' + 'either by:\n'); // eslint-disable-next-line no-console
console.warn('- Adding the value to the reserved selectors table so it\'s not used as a possible short name\n\n'); // eslint-disable-next-line no-console
console.warn('- Creating a CSS rule with the selector name and re-run the process, or'); // eslint-disable-next-line no-console
console.warn('The failing selector are:');
keys.forEach(key => {
const line = this.warningArray[key];
console.warn('- Excluding the selectors so it\'s not renamed, or'); // eslint-disable-next-line no-console
if (line.length) {
// eslint-disable-next-line no-console
console.warn(` - '${key}' found in: `); // eslint-disable-next-line no-console
console.warn('- Adding the value to the reserved selectors table so it\'s not used as a possible short name\n\n'); // eslint-disable-next-line no-console
line.forEach(e => console.warn(` ${e.file}(${e.line}): ${this.summary(e.text)}`));
} else {
console.warn('The failing selector are:');
this.warnList(this.list.compressed);
if (this.ranOnMinifiedFiles) {
// eslint-disable-next-line no-console
console.warn(` - '${key}'`);
console.warn('WARNING: You shouldn\'t run this software on minified files as it\'ll be ' + 'hard to debug errors whenever they happens.\n');
}
});
if (this.ranOnMinifiedFiles) {
// eslint-disable-next-line no-console
console.warn('WARNING: You shouldn\'t run this software on minified files as it\'ll be ' + 'hard to debug errors whenever they happens.\n');
}

@@ -71,0 +104,0 @@ }

@@ -26,2 +26,3 @@ /// <reference types="node" />

static replaceAnAttributeSelector(result: string | false, attributeSelector: string, value: AttributeSelector, slicedSelector: string): string | false;
constructor(name?: string);
selectorFirstChar: () => string;

@@ -44,3 +45,2 @@ prefetchValue: (selector: string) => string;

setAttributeSelector(attributeSelector: string | string[]): void;
isExcluded(string: string): boolean;
replaceAttributeSelector(selector: string): string | false;

@@ -47,0 +47,0 @@ }

@@ -27,4 +27,4 @@ "use strict";

class AttributeLibrary extends baseLibrary_1.BaseLibrary {
constructor() {
super(...arguments);
constructor(name) {
super(name);
this.attributeSelectors = {}; // Get the selector char for this child class

@@ -43,2 +43,4 @@

this.getAttributeSelectorRegex = () => regex_1.default.idAttributeSelectors;
this.setExclude(excludeList_1.default);
} // used at many place, let make a single function for this

@@ -137,2 +139,3 @@

this.attributeSelectors = {};
this.setExclude(excludeList_1.default);
}

@@ -298,10 +301,2 @@

isExcluded(string) {
if (excludeList_1.default.includes(string)) {
return true;
}
return super.isExcluded(string);
}
replaceAttributeSelector(selector) {

@@ -308,0 +303,0 @@ if (!this.isValidSelector(selector)) {

@@ -25,2 +25,4 @@ /// <reference types="node" />

excludesRegex: (RegExp | string)[];
includes: string[];
includesRegex: (RegExp | string)[];
prefix: string;

@@ -54,3 +56,5 @@ suffix: string;

setSuffix(suffix: string): void;
private setInternalLists;
setExclude(toExclude: string | RegExp | (string | RegExp)[]): void;
setInclude(toInclude: string | RegExp | (string | RegExp)[]): void;
setReserved(toReserve: string | string[]): void;

@@ -57,0 +61,0 @@ isReserved(string: string): boolean;

@@ -24,2 +24,4 @@ "use strict";

this.excludesRegex = [];
this.includes = [];
this.includesRegex = [];
this.prefix = '';

@@ -39,3 +41,3 @@ this.suffix = '';

static hasReservedValue(value, source) {
allWarnings_1.default.append(value, source);
allWarnings_1.default.append(value, source, 'compressed');
return `${value}_conflict`;

@@ -50,2 +52,4 @@ }

this.excludesRegex = [];
this.includes = [];
this.includesRegex = [];
this.prefix = '';

@@ -97,2 +101,3 @@ this.suffix = '';

if (this.isExcluded(finalValue)) {
allWarnings_1.default.append(finalValue, opts.source, 'ignoredFound');
return value;

@@ -243,7 +248,7 @@ }

setExclude(toExclude) {
if (!toExclude) return;
setInternalLists(string, listPointer, regexListPointer) {
if (!string) return;
if (Array.isArray(toExclude)) {
toExclude.forEach(e => this.setExclude(e));
if (Array.isArray(string)) {
string.forEach(e => this.setInternalLists(e, listPointer, regexListPointer));
return;

@@ -253,13 +258,21 @@ } // todo jpeer: check if failes

if (this.excludes.includes(toExclude) || this.excludesRegex.includes(toExclude)) {
if (listPointer.includes(string) || regexListPointer.includes(string)) {
return;
}
if (toExclude instanceof RegExp) {
this.excludesRegex.push(toExclude);
if (string instanceof RegExp) {
regexListPointer.push(string);
} else {
this.excludes.push(toExclude);
listPointer.push(string);
}
}
setExclude(toExclude) {
this.setInternalLists(toExclude, this.excludes, this.excludesRegex);
}
setInclude(toInclude) {
this.setInternalLists(toInclude, this.includes, this.includesRegex);
}
setReserved(toReserve) {

@@ -287,6 +300,10 @@ if (!toReserve) return;

if (this.excludes.includes(string)) {
return true;
if (this.includesRegex.some(includeRegex => string.match(includeRegex))) {
return false;
}
return !this.includes.includes(string);
}
return this.excludesRegex.some(excludeRegex => string.match(excludeRegex));
return this.excludesRegex.some(excludeRegex => string.match(excludeRegex) && !this.includesRegex.some(includeRegex => string.match(includeRegex)));
}

@@ -293,0 +310,0 @@

@@ -19,2 +19,3 @@ import { IdSelectorLibrary } from './idSelectorLibrary';

setExclude(...args: Parameters<BaseLibrary['setExclude']>): ReturnType<BaseLibrary['setExclude']>;
setInclude(...args: Parameters<BaseLibrary['setInclude']>): ReturnType<BaseLibrary['setInclude']>;
setReserved(...args: Parameters<BaseLibrary['setReserved']>): ReturnType<BaseLibrary['setReserved']>;

@@ -21,0 +22,0 @@ setAttributeSelector(data: string | string[]): void;

@@ -95,2 +95,6 @@ "use strict";

setInclude(...args) {
this.callOnBoth('setInclude', ...args);
}
setReserved(...args) {

@@ -97,0 +101,0 @@ this.callOnBoth('setReserved', ...args);

{
"name": "rcs-core",
"version": "3.5.1",
"version": "3.6.0",
"description": "Rename css selectors across all files",
"main": "dest",
"scripts": {
"test": "jest --coverage",
"test": "tsc --noEmit && jest --coverage",
"build": "rimraf dest && tsc && babel dest -d dest",

@@ -9,0 +9,0 @@ "lint": "eslint lib/**/*.ts __tests__/**/*.ts",

@@ -18,2 +18,8 @@ # rcs-core

## Caveats
Correctly using `rcs-core` or any of its [plugins](#plugins) on large project means few rules should be followed.
[This document](docs/caveats.md) explains most of them.
## Installation

@@ -30,9 +36,13 @@ ```sh

> **Note** couple of selectors are [excluded by default](./lib/helpers/excludeList.ts). You can activate them by using `.setInclude` **before** you fill the library
1. Fill your library with all selectors (we assume there is just one CSS file)
```js
rcs.fillLibraries(fs.readFileSync('./src/styles.css', 'utf8'));
// excluding specific selectors
rcs.selectorsLibrary.setExclude('selector-to-ignore');
// include specific selectors which has been ignored by default
rcs.selectorsLibrary.setInclude('center');
rcs.fillLibraries(fs.readFileSync('./src/styles.css', 'utf8'));
```

@@ -55,2 +65,5 @@

// output some warnings which has been stacked through the process
rcs.warnings.warn();
fs.writeFileSync('./dist/styles.css', css);

@@ -57,0 +70,0 @@ fs.writeFileSync('./dist/App.js', js);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc