svelte-preprocess-cssmodules
Advanced tools
Comparing version 2.2.4 to 2.2.5
@@ -1,6 +0,6 @@ | ||
import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess/index.d'; | ||
import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess/index'; | ||
import type { PluginOptions } from './types'; | ||
declare const _default: (options: Partial<PluginOptions>) => PreprocessorGroup; | ||
declare const _default: (options?: Partial<PluginOptions>) => PreprocessorGroup; | ||
export default _default; | ||
export declare const cssModules: (options: Partial<PluginOptions>) => PreprocessorGroup; | ||
export declare const cssModules: (options?: Partial<PluginOptions>) => PreprocessorGroup; | ||
export declare const linearPreprocess: (preprocessors: PreprocessorGroup[]) => PreprocessorGroup[]; |
@@ -32,4 +32,6 @@ "use strict"; | ||
const markup = ({ content, filename }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const isIncluded = lib_1.isFileIncluded(pluginOptions.includePaths, filename); | ||
if (!isIncluded || (!pluginOptions.parseStyleTag && !pluginOptions.parseExternalStylesheet)) { | ||
var _a; | ||
if (!filename || | ||
!(0, lib_1.isFileIncluded)(pluginOptions.includePaths, filename) || | ||
(!pluginOptions.parseStyleTag && !pluginOptions.parseExternalStylesheet)) { | ||
return { code: content }; | ||
@@ -39,15 +41,15 @@ } | ||
try { | ||
ast = compiler_1.parse(content, { filename }); | ||
ast = (0, compiler_1.parse)(content, { filename }); | ||
} | ||
catch (err) { | ||
throw new Error(`${err}\n\nThe svelte component failed to be parsed. Make sure cssModules is running after all other preprocessors by wrapping them with "cssModulesPreprocess().after()"`); | ||
throw new Error(`${err}\n\nThe svelte component failed to be parsed. Make sure cssModules is running after all other preprocessors by wrapping them with "linearPreprocess()" from svelte-preprocess-cssmodules`); | ||
} | ||
if (!pluginOptions.useAsDefaultScoping && | ||
!lib_1.hasModuleAttribute(ast) && | ||
!lib_1.hasModuleImports(content)) { | ||
!(0, lib_1.hasModuleAttribute)(ast) && | ||
!(0, lib_1.hasModuleImports)(content)) { | ||
return { code: content }; | ||
} | ||
let { mode, hashSeeder } = pluginOptions; | ||
if (pluginOptions.parseStyleTag && lib_1.hasModuleAttribute(ast)) { | ||
const moduleAttribute = ast.css.attributes.find((item) => item.name === 'module'); | ||
if (pluginOptions.parseStyleTag && (0, lib_1.hasModuleAttribute)(ast)) { | ||
const moduleAttribute = (_a = ast.css) === null || _a === void 0 ? void 0 : _a.attributes.find((item) => item.name === 'module'); | ||
mode = moduleAttribute.value !== true ? moduleAttribute.value[0].data : mode; | ||
@@ -66,11 +68,11 @@ } | ||
case 'scoped': { | ||
parsedContent = yield processors_1.scopedProcessor(ast, content, filename, pluginOptions); | ||
parsedContent = yield (0, processors_1.scopedProcessor)(ast, content, filename, pluginOptions); | ||
break; | ||
} | ||
case 'mixed': { | ||
parsedContent = yield processors_1.mixedProcessor(ast, content, filename, pluginOptions); | ||
parsedContent = yield (0, processors_1.mixedProcessor)(ast, content, filename, pluginOptions); | ||
break; | ||
} | ||
default: { | ||
parsedContent = yield processors_1.nativeProcessor(ast, content, filename, pluginOptions); | ||
parsedContent = yield (0, processors_1.nativeProcessor)(ast, content, filename, pluginOptions); | ||
break; | ||
@@ -83,6 +85,6 @@ } | ||
}); | ||
const cssModulesPreprocessor = (options) => { | ||
const cssModulesPreprocessor = (options = {}) => { | ||
pluginOptions = Object.assign(Object.assign({}, defaultOptions()), options); | ||
if (pluginOptions.includePaths) { | ||
pluginOptions.includePaths = lib_1.normalizeIncludePaths(pluginOptions.includePaths); | ||
pluginOptions.includePaths = (0, lib_1.normalizeIncludePaths)(pluginOptions.includePaths); | ||
} | ||
@@ -100,3 +102,3 @@ return { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return compiler_1.preprocess(content, p, { filename }); | ||
return (0, compiler_1.preprocess)(content, p, { filename }); | ||
}); | ||
@@ -103,0 +105,0 @@ }, |
@@ -34,3 +34,3 @@ "use strict"; | ||
if (content) { | ||
url = url.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, (all, hashType, digestType, maxLength) => getHashDijest_1.default(content, hashType, digestType, parseInt(maxLength, 10))); | ||
url = url.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, (all, hashType, digestType, maxLength) => (0, getHashDijest_1.default)(content, hashType, digestType, parseInt(maxLength, 10))); | ||
} | ||
@@ -37,0 +37,0 @@ return url |
@@ -42,3 +42,3 @@ "use strict"; | ||
const getHashDigest = (buffer, hashType, digestType, maxLength = 9999) => { | ||
const hash = crypto_1.createHash(hashType || 'md5'); | ||
const hash = (0, crypto_1.createHash)(hashType || 'md5'); | ||
hash.update(buffer); | ||
@@ -53,7 +53,7 @@ if (digestType === 'base26' || | ||
digestType === 'base64') { | ||
return encodeBufferToBase(hash.digest(), parseInt(digestType.substr(4), 10)).substr(0, maxLength); | ||
return encodeBufferToBase(hash.digest(), parseInt(digestType.substring(4), 10)).substring(0, maxLength); | ||
} | ||
const encoding = digestType || 'hex'; | ||
return hash.digest(encoding).substr(0, maxLength); | ||
return hash.digest(encoding).substring(0, maxLength); | ||
}; | ||
exports.default = getHashDigest; |
@@ -13,3 +13,3 @@ interface Context { | ||
} | ||
export declare type GetLocalIdent = { | ||
export type GetLocalIdent = { | ||
(context: Context, localIdentName: LocalIdentName, localName: string, options: Options): string; | ||
@@ -16,0 +16,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLocalIdent = void 0; | ||
exports.getLocalIdent = (_context, localIdentName) => localIdentName.interpolatedName; | ||
const getLocalIdent = (_context, localIdentName) => localIdentName.interpolatedName; | ||
exports.getLocalIdent = getLocalIdent; |
"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]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -9,4 +9,5 @@ "use strict"; | ||
const normalizePath = (filepath) => path_1.default.sep === '\\' ? filepath.replace(/\\/g, '/') : filepath; | ||
exports.normalizeIncludePaths = (paths) => paths.map((includePath) => normalizePath(path_1.default.resolve(includePath))); | ||
exports.isFileIncluded = (includePaths, filename) => { | ||
const normalizeIncludePaths = (paths) => paths.map((includePath) => normalizePath(path_1.default.resolve(includePath))); | ||
exports.normalizeIncludePaths = normalizeIncludePaths; | ||
const isFileIncluded = (includePaths, filename) => { | ||
if (includePaths.length < 1) { | ||
@@ -17,7 +18,9 @@ return true; | ||
}; | ||
exports.hasModuleImports = (content) => { | ||
exports.isFileIncluded = isFileIncluded; | ||
const hasModuleImports = (content) => { | ||
const pattern = /(?<!\/\/\s*)import\s*(?:(.+)\s+from\s+)?['|"](.+?(module\.s?css))['|"];?/gm; | ||
return content.search(pattern) !== -1; | ||
}; | ||
exports.hasModuleAttribute = (ast) => { | ||
exports.hasModuleImports = hasModuleImports; | ||
const hasModuleAttribute = (ast) => { | ||
var _a; | ||
@@ -27,1 +30,2 @@ const moduleAttribute = (_a = ast === null || ast === void 0 ? void 0 : ast.css) === null || _a === void 0 ? void 0 : _a.attributes.find((item) => item.name === 'module'); | ||
}; | ||
exports.hasModuleAttribute = hasModuleAttribute; |
"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]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -29,2 +33,3 @@ if (k2 === undefined) k2 = k; | ||
const compiler_1 = require("svelte/compiler"); | ||
const estree_walker_1 = require("estree-walker"); | ||
exports.default = (processor) => { | ||
@@ -37,3 +42,3 @@ const ast = processor.ast; | ||
let importedContent = ''; | ||
compiler_1.walk(ast, { | ||
(0, estree_walker_1.walk)(ast, { | ||
enter(baseNode) { | ||
@@ -53,3 +58,3 @@ const node = baseNode; | ||
let fileMagicContent = new magic_string_1.default(fileStyle); | ||
processor.ast = compiler_1.parse(fileStyle, { filename: absolutePath }); | ||
processor.ast = (0, compiler_1.parse)(fileStyle, { filename: absolutePath }); | ||
processor.magicContent = fileMagicContent; | ||
@@ -56,0 +61,0 @@ processor.styleParser(processor); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const compiler_1 = require("svelte/compiler"); | ||
const estree_walker_1 = require("estree-walker"); | ||
const updateMultipleClasses = (processor, classNames) => { | ||
@@ -77,3 +77,3 @@ const classes = classNames.split(' '); | ||
const cssVar = cssVariables(processor); | ||
compiler_1.walk(processor.ast.html, { | ||
(0, estree_walker_1.walk)(processor.ast.html, { | ||
enter(baseNode) { | ||
@@ -80,0 +80,0 @@ const node = baseNode; |
@@ -1,4 +0,4 @@ | ||
import type { Ast } from 'svelte/types/compiler/interfaces.d'; | ||
import type { Ast } from 'svelte/types/compiler/interfaces'; | ||
import type { PluginOptions } from '../types'; | ||
declare const mixedProcessor: (ast: Ast, content: string, filename: string, options: PluginOptions) => Promise<string>; | ||
export default mixedProcessor; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const compiler_1 = require("svelte/compiler"); | ||
const estree_walker_1 = require("estree-walker"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
@@ -31,3 +31,3 @@ const updateSelectorBoundaries = (boundaries, start, end) => { | ||
const ast = processor.ast; | ||
compiler_1.walk(ast, { | ||
(0, estree_walker_1.walk)(ast, { | ||
enter(baseNode) { | ||
@@ -34,0 +34,0 @@ const node = baseNode; |
@@ -1,4 +0,4 @@ | ||
import type { Ast } from 'svelte/types/compiler/interfaces.d'; | ||
import type { Ast } from 'svelte/types/compiler/interfaces'; | ||
import type { PluginOptions } from '../types'; | ||
declare const nativeProcessor: (ast: Ast, content: string, filename: string, options: PluginOptions) => Promise<string>; | ||
export default nativeProcessor; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const compiler_1 = require("svelte/compiler"); | ||
const estree_walker_1 = require("estree-walker"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
@@ -33,3 +33,3 @@ const updateSelectorBoundaries = (boundaries, start, end) => { | ||
let selectorBoundaries = []; | ||
compiler_1.walk(ast, { | ||
(0, estree_walker_1.walk)(ast, { | ||
enter(baseNode) { | ||
@@ -36,0 +36,0 @@ const node = baseNode; |
@@ -15,3 +15,3 @@ import MagicString from 'magic-string'; | ||
style: { | ||
ast: Style; | ||
ast?: Style; | ||
openTag: string; | ||
@@ -18,0 +18,0 @@ closeTag: string; |
@@ -18,3 +18,4 @@ "use strict"; | ||
this.createModuleClassname = (name) => { | ||
const generatedClassName = lib_1.createClassName(this.filename, this.rawContent, this.ast.css.content.styles, name, this.options); | ||
var _a, _b; | ||
const generatedClassName = (0, lib_1.createClassName)(this.filename, this.rawContent, (_b = (_a = this.ast.css) === null || _a === void 0 ? void 0 : _a.content.styles) !== null && _b !== void 0 ? _b : '', name, this.options); | ||
return generatedClassName; | ||
@@ -24,3 +25,3 @@ }; | ||
if (this.isParsingImports) { | ||
this.importedCssModuleList[lib_1.camelCase(name)] = value; | ||
this.importedCssModuleList[(0, lib_1.camelCase)(name)] = value; | ||
} | ||
@@ -31,12 +32,12 @@ this.cssModuleList[name] = value; | ||
if (this.options.parseStyleTag && | ||
(lib_1.hasModuleAttribute(this.ast) || (this.options.useAsDefaultScoping && this.ast.css))) { | ||
((0, lib_1.hasModuleAttribute)(this.ast) || (this.options.useAsDefaultScoping && this.ast.css))) { | ||
this.isParsingImports = false; | ||
this.styleParser(this); | ||
} | ||
if (this.options.parseExternalStylesheet && lib_1.hasModuleImports(this.rawContent)) { | ||
if (this.options.parseExternalStylesheet && (0, lib_1.hasModuleImports)(this.rawContent)) { | ||
this.isParsingImports = true; | ||
parsers_1.parseImportDeclaration(this); | ||
(0, parsers_1.parseImportDeclaration)(this); | ||
} | ||
if (Object.keys(this.cssModuleList).length > 0 || Object.keys(this.cssVarList).length > 0) { | ||
parsers_1.parseTemplate(this); | ||
(0, parsers_1.parseTemplate)(this); | ||
} | ||
@@ -50,3 +51,3 @@ return this.magicContent.toString(); | ||
bindedVariableNodes.forEach((item) => { | ||
var _a; | ||
var _a, _b, _c; | ||
if (item.children) { | ||
@@ -56,3 +57,3 @@ const child = item.children[0]; | ||
const varName = child.type === 'String' ? name.replace(/\./, '-') : name; | ||
const generatedVarName = lib_1.generateName(this.filename, this.ast.css.content.styles, varName, { | ||
const generatedVarName = (0, lib_1.generateName)(this.filename, (_c = (_b = this.ast.css) === null || _b === void 0 ? void 0 : _b.content.styles) !== null && _c !== void 0 ? _c : '', varName, { | ||
hashSeeder: ['style', 'filepath'], | ||
@@ -82,3 +83,3 @@ localIdentName: `[local]-${this.options.cssVariableHash}`, | ||
this.storeAnimationProperties = (node) => { | ||
if (node.type === 'Declaration' && node.property === 'animation') { | ||
if (node.type === 'Declaration' && ['animation', 'animation-name'].includes(node.property)) { | ||
let names = 0; | ||
@@ -85,0 +86,0 @@ let properties = 0; |
@@ -1,4 +0,4 @@ | ||
import type { Ast } from 'svelte/types/compiler/interfaces.d'; | ||
import type { Ast } from 'svelte/types/compiler/interfaces'; | ||
import type { PluginOptions } from '../types'; | ||
declare const scopedProcessor: (ast: Ast, content: string, filename: string, options: PluginOptions) => Promise<string>; | ||
export default scopedProcessor; |
@@ -15,7 +15,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const compiler_1 = require("svelte/compiler"); | ||
const estree_walker_1 = require("estree-walker"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
const parser = (processor) => { | ||
const ast = processor.ast; | ||
compiler_1.walk(ast, { | ||
(0, estree_walker_1.walk)(ast, { | ||
enter(baseNode) { | ||
@@ -22,0 +22,0 @@ const node = baseNode; |
import type { GetLocalIdent } from '../lib'; | ||
export declare type PluginOptions = { | ||
export type PluginOptions = { | ||
cssVariableHash: string; | ||
@@ -14,3 +14,3 @@ getLocalIdent: GetLocalIdent; | ||
}; | ||
export declare type CSSModuleList = Record<string, string>; | ||
export declare type CSSModuleDirectory = Record<string, CSSModuleList>; | ||
export type CSSModuleList = Record<string, string>; | ||
export type CSSModuleDirectory = Record<string, CSSModuleList>; |
{ | ||
"name": "svelte-preprocess-cssmodules", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Svelte preprocessor to generate CSS Modules classname on Svelte components", | ||
@@ -59,2 +59,3 @@ "keywords": [ | ||
"big.js": "^6.1.1", | ||
"estree-walker": "^2.0.2", | ||
"magic-string": "^0.25.7" | ||
@@ -65,4 +66,4 @@ }, | ||
"@types/estree": "0.0.47", | ||
"@typescript-eslint/eslint-plugin": "^4.4.0", | ||
"@typescript-eslint/parser": "^4.4.0", | ||
"@typescript-eslint/eslint-plugin": "^5.62.0", | ||
"@typescript-eslint/parser": "^5.62.0", | ||
"eslint": "^7.10.0", | ||
@@ -72,13 +73,11 @@ "eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"estree-walker": "^3.0.0", | ||
"husky": "^4.3.0", | ||
"jest": "^26.0.1", | ||
"lint-staged": "^10.5.1", | ||
"prettier": "^2.1.2", | ||
"svelte": "^3.22.3", | ||
"typescript": "^4.0.3" | ||
"prettier": "^3.3.3", | ||
"svelte": "^3.59.2", | ||
"typescript": "^4.9.5" | ||
}, | ||
"peerDependencies": { | ||
"svelte": "^3.20.0", | ||
"typescript": "^4.0.0" | ||
"svelte": "^3.20.0 || ^4.0.0" | ||
}, | ||
@@ -85,0 +84,0 @@ "files": [ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108614
14
1736
+ Addedestree-walker@^2.0.2
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Addedaria-query@5.3.2(transitive)
+ Addedaxobject-query@4.1.0(transitive)
+ Addedcode-red@1.0.4(transitive)
+ Addedcss-tree@2.3.1(transitive)
+ Addedestree-walker@2.0.23.0.3(transitive)
+ Addedis-reference@3.0.3(transitive)
+ Addedlocate-character@3.0.0(transitive)
+ Addedmagic-string@0.30.12(transitive)
+ Addedmdn-data@2.0.30(transitive)
+ Addedperiscopic@3.1.0(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedsvelte@4.2.19(transitive)
- Removedsvelte@3.59.2(transitive)
- Removedtypescript@4.9.5(transitive)