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

@stylable/core

Package Overview
Dependencies
Maintainers
6
Versions
218
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stylable/core - npm Package Compare versions

Comparing version 4.1.0-alpha.3 to 4.1.0

2

dist/create-infra-structure.js

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

const module_resolver_1 = require("./module-resolver");
function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = module_resolver_1.createDefaultResolver(fileSystem, resolveOptions), cssParser = parser_1.safeParse, createDiagnostics) {
function createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions = {}, resolveNamespace, timedCacheOptions, resolveModule = module_resolver_1.createDefaultResolver(fileSystem, resolveOptions), cssParser = parser_1.cssParse, createDiagnostics) {
let resolvePath = (context = projectRoot, moduleId) => {

@@ -16,0 +16,0 @@ return path_1.default.isAbsolute(moduleId) ? moduleId : resolveModule(context, moduleId);

@@ -130,60 +130,57 @@ "use strict";

}
else if (customValues[value]) {
// no op resolved at the bottom
}
else if (value === 'url') {
// postcss-value-parser treats url differently:
// https://github.com/TrySound/postcss-value-parser/issues/34
const url = parsedNode.nodes[0];
if ((url.type === 'word' || url.type === 'string') &&
url.value.startsWith('~')) {
const sourceDir = path_1.dirname(meta.source);
url.value = stylable_assets_1.assureRelativeUrlPrefix(path_1.relative(sourceDir, resolver.resolvePath(url.value.slice(1), sourceDir)).replace(/\\/gm, '/'));
}
}
else if (value === 'format') {
// preserve native format function quotation
parsedNode.resolvedValue = stringifyFunction(value, parsedNode, true);
}
else {
if (customValues[value]) {
// no op resolved at the bottom
}
else if (value === 'url') {
// postcss-value-parser treats url differently:
// https://github.com/TrySound/postcss-value-parser/issues/34
const url = parsedNode.nodes[0];
if ((url.type === 'word' || url.type === 'string') &&
url.value.startsWith('~')) {
const sourceDir = path_1.dirname(meta.source);
url.value = stylable_assets_1.assureRelativeUrlPrefix(path_1.relative(sourceDir, resolver.resolvePath(url.value.slice(1), sourceDir)).replace(/\\/gm, '/'));
}
}
else if (value === 'format') {
// preserve native format function quotation
parsedNode.resolvedValue = stringifyFunction(value, parsedNode, true);
}
else {
const formatterRef = meta.mappedSymbols[value];
const formatter = resolver.deepResolve(formatterRef);
const formatter = resolver.deepResolve(meta.mappedSymbols[value]);
if (formatter && formatter._kind === 'js') {
const formatterArgs = stylable_value_parsers_1.getFormatterArgs(parsedNode);
if (formatter && formatter._kind === 'js') {
try {
parsedNode.resolvedValue = formatter.symbol.apply(null, formatterArgs);
if (valueHook && typeof parsedNode.resolvedValue === 'string') {
parsedNode.resolvedValue = valueHook(parsedNode.resolvedValue, { name: parsedNode.value, args: formatterArgs }, true, passedThrough);
}
try {
parsedNode.resolvedValue = formatter.symbol.apply(null, formatterArgs);
if (valueHook && typeof parsedNode.resolvedValue === 'string') {
parsedNode.resolvedValue = valueHook(parsedNode.resolvedValue, { name: parsedNode.value, args: formatterArgs }, true, passedThrough);
}
catch (error) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
if (diagnostics && node) {
diagnostics.warn(node, exports.functionWarnings.FAIL_TO_EXECUTE_FORMATTER(parsedNode.resolvedValue, error.message), { word: node.value });
}
}
catch (error) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
if (diagnostics && node) {
diagnostics.warn(node, exports.functionWarnings.FAIL_TO_EXECUTE_FORMATTER(parsedNode.resolvedValue, error.message), { word: node.value });
}
}
else if (value === 'var') {
const varWithPrefix = parsedNode.nodes[0].value;
if (stylable_utils_1.isCSSVarProp(varWithPrefix)) {
if (cssVarsMapping && cssVarsMapping[varWithPrefix]) {
parsedNode.nodes[0].value = cssVarsMapping[varWithPrefix];
}
}
else if (value === 'var') {
const varWithPrefix = parsedNode.nodes[0].value;
if (stylable_utils_1.isCSSVarProp(varWithPrefix)) {
if (cssVarsMapping && cssVarsMapping[varWithPrefix]) {
parsedNode.nodes[0].value = cssVarsMapping[varWithPrefix];
}
// handle default values
if (parsedNode.nodes.length > 2) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
}
}
else if (native_reserved_lists_1.isCssNativeFunction(value)) {
// handle default values
if (parsedNode.nodes.length > 2) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
}
else if (diagnostics && node) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
diagnostics.warn(node, exports.functionWarnings.UNKNOWN_FORMATTER(value), {
word: value,
});
}
}
else if (native_reserved_lists_1.isCssNativeFunction(value)) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
}
else if (diagnostics && node) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
diagnostics.warn(node, exports.functionWarnings.UNKNOWN_FORMATTER(value), {
word: value,
});
}
}

@@ -222,3 +219,2 @@ break;

return { outputValue, topLevelType, typeError };
// }
// TODO: handle calc (parse internals but maintain expression)

@@ -225,0 +221,0 @@ // TODO: check this thing. native function that accent our function does not work

@@ -1,2 +0,2 @@

export { safeParse } from './parser';
export * from './parser';
export * from './cached-process-file';

@@ -3,0 +3,0 @@ export * from './stylable-processor';

@@ -25,5 +25,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.pseudoStates = exports.safeParse = void 0;
var parser_1 = require("./parser");
Object.defineProperty(exports, "safeParse", { enumerable: true, get: function () { return parser_1.safeParse; } });
exports.pseudoStates = void 0;
__exportStar(require("./parser"), exports);
__exportStar(require("./cached-process-file"), exports);

@@ -30,0 +29,0 @@ __exportStar(require("./stylable-processor"), exports);

@@ -1,2 +0,2 @@

import { ProcessOptions, Root } from 'postcss';
import { ProcessOptions, Root, parse as cssParse } from 'postcss';
import type { CSSObject } from './types';

@@ -6,2 +6,3 @@ export declare function cssObjectToAst(cssObject: CSSObject, sourceFile?: string): import("postcss").LazyResult;

export declare function safeParse(css: string, options?: ProcessOptions): Root;
export { cssParse };
//# sourceMappingURL=parser.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -6,4 +25,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.safeParse = exports.cssObjectToAst = void 0;
const postcss_1 = __importDefault(require("postcss"));
exports.cssParse = exports.safeParse = exports.cssObjectToAst = void 0;
const postcss_1 = __importStar(require("postcss"));
Object.defineProperty(exports, "cssParse", { enumerable: true, get: function () { return postcss_1.parse; } });
const postcss_nested_1 = __importDefault(require("postcss-nested"));

@@ -10,0 +30,0 @@ const postcss_js_1 = __importDefault(require("postcss-js"));

@@ -6,2 +6,3 @@ import type * as postcss from 'postcss';

export declare function isExternal(url: string): boolean;
export declare function isUrl(maybeUrl: string): boolean;
export declare function isAsset(url: string): boolean;

@@ -8,0 +9,0 @@ export declare function makeAbsolute(resourcePath: string, rootContext: string, moduleContext: string): string;

@@ -6,5 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.assureRelativeUrlPrefix = exports.fixRelativeUrls = exports.processDeclarationUrls = exports.makeAbsolute = exports.isAsset = exports.isExternal = exports.collectAssets = void 0;
exports.assureRelativeUrlPrefix = exports.fixRelativeUrls = exports.processDeclarationUrls = exports.makeAbsolute = exports.isAsset = exports.isUrl = exports.isExternal = exports.collectAssets = void 0;
const path_1 = __importDefault(require("path"));
const is_url_superb_1 = __importDefault(require("is-url-superb"));
const css_selector_tokenizer_1 = __importDefault(require("css-selector-tokenizer"));

@@ -22,5 +21,19 @@ const { parseValues, stringifyValues } = css_selector_tokenizer_1.default;

function isExternal(url) {
return url === '' || url.startsWith('data:') || is_url_superb_1.default(url);
return url === '' || url.startsWith('data:') || isUrl(url);
}
exports.isExternal = isExternal;
function isUrl(maybeUrl) {
maybeUrl = maybeUrl.trim();
if (maybeUrl.includes(' ')) {
return false;
}
try {
new URL(maybeUrl);
return true;
}
catch {
return false;
}
}
exports.isUrl = isUrl;
function isAsset(url) {

@@ -27,0 +40,0 @@ return !isExternal(url);

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

const a = resolved[0];
const b = resolved[1];
const b = resolved[resolved.length - 1];
rule.after(selector_utils_1.createWarningRule(b.symbol.name, this.scope(b.symbol.name, b.meta.namespace), path_1.basename(b.meta.source), a.symbol.name, this.scope(a.symbol.name, a.meta.namespace), path_1.basename(a.meta.source), true));

@@ -563,0 +563,0 @@ });

@@ -76,3 +76,3 @@ import type * as postcss from 'postcss';

export declare function getNamedArgs(node: ParsedValue): ParsedValue[][];
export declare function getFormatterArgs(node: ParsedValue, allowComments?: boolean, _reportWarning?: ReportWarning, perserveQuotes?: boolean): string[];
export declare function getFormatterArgs(node: ParsedValue, allowComments?: boolean, reportWarning?: ReportWarning, preserveQuotes?: boolean): string[];
export declare function getStringValue(nodes: ParsedValue | ParsedValue[]): string;

@@ -79,0 +79,0 @@ export declare function groupValues(nodes: any[], divType?: string): any[];

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

exports.getNamedArgs = getNamedArgs;
function getFormatterArgs(node, allowComments = false, _reportWarning, perserveQuotes = false) {
function getFormatterArgs(node, allowComments = false, reportWarning, preserveQuotes = false) {
const argsResult = [];

@@ -206,3 +206,3 @@ let currentArg = '';

else if (currentNode.type === 'string') {
currentArg += perserveQuotes
currentArg += preserveQuotes
? postcss_value_parser_1.default.stringify(currentNode)

@@ -228,4 +228,4 @@ : currentNode.value;

function checkEmptyArg() {
if (currentArg.trim() === '' && _reportWarning) {
_reportWarning(`${postcss_value_parser_1.default.stringify(node)}: argument at index ${argIndex} is empty`);
if (reportWarning && currentArg.trim() === '') {
reportWarning(`${postcss_value_parser_1.default.stringify(node)}: argument at index ${argIndex} is empty`);
}

@@ -232,0 +232,0 @@ }

@@ -54,3 +54,3 @@ import type { FileProcessor, MinimalFS } from './cached-process-file';

initCache(): void;
createResolver({ requireModule, resolverCache, }?: Pick<StylableConfig, 'requireModule' | 'resolverCache'>): StylableResolver;
createResolver({ requireModule, resolverCache, }: Pick<StylableConfig, 'requireModule' | 'resolverCache'>): StylableResolver;
createProcessor({ resolveNamespace }?: CreateProcessorOptions): StylableProcessor;

@@ -57,0 +57,0 @@ createTransformer(options?: Partial<TransformerOptions>): StylableTransformer;

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

class Stylable {
constructor(projectRoot, fileSystem, requireModule, delimiter = '__', onProcess, diagnostics = new diagnostics_1.Diagnostics(), hooks = {}, resolveOptions = {}, optimizer, mode = 'production', resolveNamespace, timedCacheOptions, resolveModule, cssParser = parser_1.safeParse, resolverCache) {
constructor(projectRoot, fileSystem, requireModule, delimiter = '__', onProcess, diagnostics = new diagnostics_1.Diagnostics(), hooks = {}, resolveOptions = {}, optimizer, mode = 'production', resolveNamespace, timedCacheOptions, resolveModule, cssParser = parser_1.cssParse, resolverCache) {
this.projectRoot = projectRoot;

@@ -44,3 +44,3 @@ this.fileSystem = fileSystem;

}
createResolver({ requireModule, resolverCache, } = {}) {
createResolver({ requireModule, resolverCache, }) {
return new stylable_resolver_1.StylableResolver(this.fileProcessor, requireModule || this.requireModule, resolverCache || this.resolverCache);

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

{
"name": "@stylable/core",
"version": "4.1.0-alpha.3",
"version": "4.1.0",
"description": "CSS for Components",

@@ -13,4 +13,3 @@ "main": "dist/index.js",

"deindent": "^0.1.0",
"enhanced-resolve": "^5.7.0",
"is-url-superb": "^5.0.0",
"enhanced-resolve": "^5.8.0",
"is-vendor-prefixed": "^4.0.0",

@@ -20,3 +19,3 @@ "jest-docblock": "^26.0.0",

"lodash.clonedeepwith": "^4.5.0",
"postcss": "^8.2.8",
"postcss": "^8.2.10",
"postcss-js": "^3.0.3",

@@ -23,0 +22,0 @@ "postcss-nested": "^5.0.5",

import path from 'path';
import { cachedProcessFile, FileProcessor, MinimalFS } from './cached-process-file';
import { CssParser, safeParse } from './parser';
import { cssParse, CssParser } from './parser';
import { process, processNamespace, StylableMeta } from './stylable-processor';

@@ -22,3 +22,3 @@ import { timedCache, TimedCacheOptions } from './timed-cache';

resolveModule = createDefaultResolver(fileSystem, resolveOptions),
cssParser: CssParser = safeParse,
cssParser: CssParser = cssParse,
createDiagnostics?: (from: string) => Diagnostics

@@ -25,0 +25,0 @@ ): StylableInfrastructure {

@@ -250,75 +250,69 @@ import { dirname, relative } from 'path';

parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
} else if (customValues[value]) {
// no op resolved at the bottom
} else if (value === 'url') {
// postcss-value-parser treats url differently:
// https://github.com/TrySound/postcss-value-parser/issues/34
const url = parsedNode.nodes[0];
if (
(url.type === 'word' || url.type === 'string') &&
url.value.startsWith('~')
) {
const sourceDir = dirname(meta.source);
url.value = assureRelativeUrlPrefix(
relative(
sourceDir,
resolver.resolvePath(url.value.slice(1), sourceDir)
).replace(/\\/gm, '/')
);
}
} else if (value === 'format') {
// preserve native format function quotation
parsedNode.resolvedValue = stringifyFunction(value, parsedNode, true);
} else {
if (customValues[value]) {
// no op resolved at the bottom
} else if (value === 'url') {
// postcss-value-parser treats url differently:
// https://github.com/TrySound/postcss-value-parser/issues/34
const url = parsedNode.nodes[0];
if (
(url.type === 'word' || url.type === 'string') &&
url.value.startsWith('~')
) {
const sourceDir = dirname(meta.source);
url.value = assureRelativeUrlPrefix(
relative(
sourceDir,
resolver.resolvePath(url.value.slice(1), sourceDir)
).replace(/\\/gm, '/')
);
}
} else if (value === 'format') {
// preserve native format function quotation
parsedNode.resolvedValue = stringifyFunction(value, parsedNode, true);
} else {
const formatterRef = meta.mappedSymbols[value];
const formatter = resolver.deepResolve(formatterRef);
const formatter = resolver.deepResolve(meta.mappedSymbols[value]);
if (formatter && formatter._kind === 'js') {
const formatterArgs = getFormatterArgs(parsedNode);
if (formatter && formatter._kind === 'js') {
try {
parsedNode.resolvedValue = formatter.symbol.apply(
null,
formatterArgs
try {
parsedNode.resolvedValue = formatter.symbol.apply(null, formatterArgs);
if (valueHook && typeof parsedNode.resolvedValue === 'string') {
parsedNode.resolvedValue = valueHook(
parsedNode.resolvedValue,
{ name: parsedNode.value, args: formatterArgs },
true,
passedThrough
);
if (valueHook && typeof parsedNode.resolvedValue === 'string') {
parsedNode.resolvedValue = valueHook(
}
} catch (error) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
if (diagnostics && node) {
diagnostics.warn(
node,
functionWarnings.FAIL_TO_EXECUTE_FORMATTER(
parsedNode.resolvedValue,
{ name: parsedNode.value, args: formatterArgs },
true,
passedThrough
);
}
} catch (error) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
if (diagnostics && node) {
diagnostics.warn(
node,
functionWarnings.FAIL_TO_EXECUTE_FORMATTER(
parsedNode.resolvedValue,
error.message
),
{ word: (node as postcss.Declaration).value }
);
}
error.message
),
{ word: (node as postcss.Declaration).value }
);
}
} else if (value === 'var') {
const varWithPrefix = parsedNode.nodes[0].value;
if (isCSSVarProp(varWithPrefix)) {
if (cssVarsMapping && cssVarsMapping[varWithPrefix]) {
parsedNode.nodes[0].value = cssVarsMapping[varWithPrefix];
}
}
} else if (value === 'var') {
const varWithPrefix = parsedNode.nodes[0].value;
if (isCSSVarProp(varWithPrefix)) {
if (cssVarsMapping && cssVarsMapping[varWithPrefix]) {
parsedNode.nodes[0].value = cssVarsMapping[varWithPrefix];
}
// handle default values
if (parsedNode.nodes.length > 2) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
}
} else if (isCssNativeFunction(value)) {
}
// handle default values
if (parsedNode.nodes.length > 2) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
} else if (diagnostics && node) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
diagnostics.warn(node, functionWarnings.UNKNOWN_FORMATTER(value), {
word: value,
});
}
} else if (isCssNativeFunction(value)) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
} else if (diagnostics && node) {
parsedNode.resolvedValue = stringifyFunction(value, parsedNode);
diagnostics.warn(node, functionWarnings.UNKNOWN_FORMATTER(value), {
word: value,
});
}

@@ -357,3 +351,2 @@ }

return { outputValue, topLevelType, typeError };
// }
// TODO: handle calc (parse internals but maintain expression)

@@ -360,0 +353,0 @@ // TODO: check this thing. native function that accent our function does not work

@@ -1,2 +0,2 @@

export { safeParse } from './parser';
export * from './parser';
export * from './cached-process-file';

@@ -3,0 +3,0 @@ export * from './stylable-processor';

@@ -1,2 +0,2 @@

import postcss, { ProcessOptions, Root } from 'postcss';
import postcss, { ProcessOptions, Root, parse as cssParse } from 'postcss';
import postcssNested from 'postcss-nested';

@@ -18,1 +18,3 @@ import postcssJS from 'postcss-js';

}
export { cssParse };
import path from 'path';
import type * as postcss from 'postcss';
import isUrl from 'is-url-superb';
import cssSelectorTokenizer from 'css-selector-tokenizer';

@@ -24,2 +23,15 @@ import type { ParsedValue } from './types';

export function isUrl(maybeUrl: string) {
maybeUrl = maybeUrl.trim();
if (maybeUrl.includes(' ')) {
return false;
}
try {
new URL(maybeUrl);
return true;
} catch {
return false;
}
}
export function isAsset(url: string) {

@@ -26,0 +38,0 @@ return !isExternal(url);

@@ -795,3 +795,3 @@ import { basename } from 'path';

const a = resolved[0];
const b = resolved[1];
const b = resolved[resolved.length - 1];
rule.after(

@@ -798,0 +798,0 @@ createWarningRule(

@@ -266,4 +266,4 @@ import type * as postcss from 'postcss';

allowComments = false,
_reportWarning?: ReportWarning,
perserveQuotes = false
reportWarning?: ReportWarning,
preserveQuotes = false
) {

@@ -285,3 +285,3 @@ const argsResult = [];

} else if (currentNode.type === 'string') {
currentArg += perserveQuotes
currentArg += preserveQuotes
? postcssValueParser.stringify(currentNode)

@@ -307,4 +307,4 @@ : currentNode.value;

function checkEmptyArg() {
if (currentArg.trim() === '' && _reportWarning) {
_reportWarning(
if (reportWarning && currentArg.trim() === '') {
reportWarning(
`${postcssValueParser.stringify(

@@ -311,0 +311,0 @@ node as postcssValueParser.Node

import type { FileProcessor, MinimalFS } from './cached-process-file';
import { createInfrastructure } from './create-infra-structure';
import { Diagnostics } from './diagnostics';
import { CssParser, safeParse } from './parser';
import { CssParser, cssParse } from './parser';
import { processNamespace, StylableMeta, StylableProcessor } from './stylable-processor';

@@ -83,3 +83,3 @@ import { StylableResolverCache, StylableResolver } from './stylable-resolver';

protected resolveModule?: ModuleResolver,
protected cssParser: CssParser = safeParse,
protected cssParser: CssParser = cssParse,
protected resolverCache?: StylableResolverCache

@@ -107,3 +107,3 @@ ) {

resolverCache,
}: Pick<StylableConfig, 'requireModule' | 'resolverCache'> = {}) {
}: Pick<StylableConfig, 'requireModule' | 'resolverCache'>) {
return new StylableResolver(

@@ -110,0 +110,0 @@ this.fileProcessor,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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