svelte-preprocess-cssmodules
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -30,3 +30,3 @@ "use strict"; | ||
const markup = ({ content, filename }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const isIncluded = yield lib_1.isFileIncluded(pluginOptions.includePaths, filename); | ||
const isIncluded = lib_1.isFileIncluded(pluginOptions.includePaths, filename); | ||
if (!isIncluded || (!pluginOptions.parseStyleTag && !pluginOptions.parseExternalStylesheet)) { | ||
@@ -75,2 +75,5 @@ return { code: content }; | ||
pluginOptions = Object.assign(Object.assign({}, defaultOptions()), options); | ||
if (pluginOptions.includePaths) { | ||
pluginOptions.includePaths = lib_1.normalizeIncludePaths(pluginOptions.includePaths); | ||
} | ||
return { | ||
@@ -77,0 +80,0 @@ markup, |
import type { Ast } from 'svelte/types/compiler/interfaces.d'; | ||
export declare const isFileIncluded: (includePaths: string[], filename: string) => Promise<boolean>; | ||
export declare const normalizeIncludePaths: (paths: string[]) => string[]; | ||
export declare const isFileIncluded: (includePaths: string[], filename: string) => boolean; | ||
export declare const hasModuleImports: (content: string) => boolean; | ||
export declare const hasModuleAttribute: (ast: Ast) => boolean; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
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) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -15,20 +6,12 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hasModuleAttribute = exports.hasModuleImports = exports.isFileIncluded = void 0; | ||
exports.hasModuleAttribute = exports.hasModuleImports = exports.isFileIncluded = exports.normalizeIncludePaths = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
exports.isFileIncluded = (includePaths, filename) => __awaiter(void 0, void 0, void 0, function* () { | ||
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) => { | ||
if (includePaths.length < 1) { | ||
return true; | ||
} | ||
const isIncluded = yield new Promise((resolve) => { | ||
includePaths.forEach((includePath, index) => { | ||
if (filename.indexOf(path_1.default.resolve(includePath)) !== -1) { | ||
resolve(true); | ||
} | ||
if (index === includePaths.length - 1) { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
return isIncluded; | ||
}); | ||
return includePaths.some((includePath) => filename.startsWith(includePath)); | ||
}; | ||
exports.hasModuleImports = (content) => { | ||
@@ -35,0 +18,0 @@ const pattern = /(?<!\/\/\s*)import\s*(?:(.+)\s+from\s+)?['|"](.+?(module\.s?css))['|"];?/gm; |
{ | ||
"name": "svelte-preprocess-cssmodules", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Svelte preprocessor to generate CSS Modules classname on Svelte components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -258,3 +258,3 @@ # Svelte preprocess CSS Modules | ||
- The option `parseExternalSylesheet` need to be enabled. | ||
- The option `parseExternalStylesheet` need to be enabled. | ||
- The css file must follow the convention `FILENAME.module.css` in order to be processed. | ||
@@ -708,5 +708,5 @@ | ||
preprocess: [ | ||
cssModules([ | ||
cssModules({ | ||
useAsDefaultScoping: true | ||
]), | ||
}), | ||
], | ||
@@ -740,6 +740,6 @@ ... | ||
preprocess: [ | ||
cssModules([ | ||
cssModules({ | ||
useAsDefaultScoping: true, | ||
includePaths: ['./src'], | ||
]), | ||
}), | ||
], | ||
@@ -757,5 +757,5 @@ ... | ||
preprocess: [ | ||
cssModules([ | ||
cssModules({ | ||
mode: 'mixed', | ||
]), | ||
}), | ||
], | ||
@@ -762,0 +762,0 @@ ... |
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
87840
51
1433