svelte-preprocess
Advanced tools
Comparing version 4.10.7 to 5.0.0-alpha.0
import type { AutoPreprocessGroup, AutoPreprocessOptions, Processed, TransformerArgs, TransformerOptions } from './types'; | ||
export declare const transform: (name: string | null | undefined, options: TransformerOptions, { content, markup, map, filename, attributes }: TransformerArgs<any>) => Promise<Processed>; | ||
export declare function sveltePreprocess({ aliases, markupTagName, preserve, defaults, sourceMap, ...rest }?: AutoPreprocessOptions): AutoPreprocessGroup; | ||
export declare function sveltePreprocess({ aliases, markupTagName, preserve, sourceMap, ...rest }?: AutoPreprocessOptions): AutoPreprocessGroup; |
"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) { | ||
@@ -28,3 +32,9 @@ if (k2 === undefined) k2 = k; | ||
const markup_1 = require("./modules/markup"); | ||
const TARGET_LANGUAGES = Object.freeze({ | ||
markup: 'html', | ||
style: 'css', | ||
script: 'javascript', | ||
}); | ||
const transform = async (name, options, { content, markup, map, filename, attributes }) => { | ||
var _a; | ||
if (name == null || options === false) { | ||
@@ -37,3 +47,3 @@ return { code: content }; | ||
// todo: maybe add a try-catch here looking for module-not-found errors | ||
const { transformer } = await Promise.resolve().then(() => __importStar(require(`./transformers/${name}`))); | ||
const { transformer } = await (_a = `./transformers/${name}`, Promise.resolve().then(() => __importStar(require(_a)))); | ||
return transformer({ | ||
@@ -51,13 +61,3 @@ content, | ||
var _b, _c; | ||
var { aliases, markupTagName = 'template', preserve = [], defaults, sourceMap = (_c = ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') !== null && _c !== void 0 ? _c : false, ...rest } = _a === void 0 ? {} : _a; | ||
const defaultLanguages = Object.freeze({ | ||
markup: 'html', | ||
style: 'css', | ||
script: 'javascript', | ||
...defaults, | ||
}); | ||
// todo: remove this on v5 | ||
if (defaults != null) { | ||
console.warn('[svelte-preprocess] Deprecation notice: using the "defaults" option is no longer recommended and will be removed in the next major version. Instead, define the language being used explicitly via the lang attribute.\n\nSee https://github.com/sveltejs/svelte-preprocess/issues/362'); | ||
} | ||
var { aliases, markupTagName = 'template', preserve = [], sourceMap = (_c = ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'development') !== null && _c !== void 0 ? _c : false, ...rest } = _a === void 0 ? {} : _a; | ||
const transformers = rest; | ||
@@ -101,3 +101,3 @@ if (aliases === null || aliases === void 0 ? void 0 : aliases.length) { | ||
if (lang == null || alias == null) { | ||
alias = defaultLanguages[type]; | ||
alias = TARGET_LANGUAGES[type]; | ||
lang = (0, language_1.getLanguageFromAlias)(alias); | ||
@@ -205,3 +205,2 @@ } | ||
return { | ||
defaultLanguages, | ||
markup, | ||
@@ -208,0 +207,0 @@ script, |
@@ -0,0 +0,0 @@ import { sveltePreprocess } from './autoProcess'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare const throwError: (msg: string) => never; | ||
export declare const throwTypescriptError: () => void; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare function globalifySelector(selector: string): string; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import type { PreprocessorArgs } from '../types'; |
@@ -6,5 +6,2 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
// todo: remove on v5 | ||
let hasLoggedDeprecatedLangTypescriptWarning = false; | ||
let hasLoggedDeprecatedTypeWarning = false; | ||
const LANGUAGE_DEFAULTS = { | ||
@@ -84,18 +81,3 @@ sass: { | ||
alias = attributes.lang; | ||
if (alias === 'typescript' && !hasLoggedDeprecatedLangTypescriptWarning) { | ||
hasLoggedDeprecatedLangTypescriptWarning = true; | ||
console.warn(`[svelte-preprocess] Deprecation notice: using 'lang="typescript"' is no longer recommended and will be removed in the next major version. Please use 'lang="ts"' instead.`); | ||
} | ||
} | ||
else if (attributes.type) { | ||
// istanbul ignore if | ||
if (typeof attributes.type !== 'string') { | ||
throw new Error('type attribute must be string'); | ||
} | ||
alias = attributes.type.replace(/^(text|application)\/(.*)$/, '$2'); | ||
if (attributes.type.includes('text/') && !hasLoggedDeprecatedTypeWarning) { | ||
hasLoggedDeprecatedTypeWarning = true; | ||
console.warn(`[svelte-preprocess] Deprecation notice: using the "type" attribute is no longer recommended and will be removed in the next major version. Please use the "lang" attribute instead.`); | ||
} | ||
} | ||
else if (typeof attributes.src === 'string' && | ||
@@ -102,0 +84,0 @@ (0, utils_1.isValidLocalPath)(attributes.src)) { |
@@ -10,3 +10,3 @@ import type { Transformer, Preprocessor } from '../types'; | ||
content: string; | ||
filename: string; | ||
}, transformer: Preprocessor | Transformer<unknown>, options?: Record<string, any>): Promise<import("svelte/types/compiler/preprocess/types").Processed>; | ||
filename?: string; | ||
}, transformer: Preprocessor | Transformer<unknown>, options?: Record<string, any>): Promise<import("../types").Processed>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare function prepareContent({ options, content, }: { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import type { PreprocessorArgs } from '../types'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,2 +0,1 @@ | ||
export declare function importAny(...modules: string[]): Promise<any>; | ||
export declare function concat(...arrs: any[]): any[]; | ||
@@ -3,0 +2,0 @@ /** Paths used by preprocessors to resolve @imports */ |
"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) { | ||
@@ -21,21 +25,11 @@ if (k2 === undefined) k2 = k; | ||
}; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JAVASCRIPT_RESERVED_KEYWORD_SET = exports.setProp = exports.findUp = exports.isValidLocalPath = exports.hasDepInstalled = exports.getIncludePaths = exports.concat = exports.importAny = void 0; | ||
exports.JAVASCRIPT_RESERVED_KEYWORD_SET = exports.setProp = exports.findUp = exports.isValidLocalPath = exports.hasDepInstalled = exports.getIncludePaths = exports.concat = void 0; | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
async function importAny(...modules) { | ||
try { | ||
const mod = await modules.reduce((acc, moduleName) => acc.catch(() => Promise.resolve().then(() => __importStar(require(moduleName)))), Promise.reject()); | ||
return mod; | ||
} | ||
catch (e) { | ||
throw new Error(`Cannot find any of modules: ${modules}\n\n${e}`); | ||
} | ||
} | ||
exports.importAny = importAny; | ||
function concat(...arrs) { | ||
return arrs.reduce((acc, a) => { | ||
if (a) { | ||
if (a) | ||
return acc.concat(a); | ||
} | ||
return acc; | ||
@@ -68,3 +62,3 @@ }, []); | ||
try { | ||
await Promise.resolve().then(() => __importStar(require(dep))); | ||
await (_a = dep, Promise.resolve().then(() => __importStar(require(_a)))); | ||
result = true; | ||
@@ -71,0 +65,0 @@ } |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options?: Options.Babel | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Babel) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options?: Options.Coffeescript | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Coffeescript) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup } from '../types'; | ||
declare const _default: () => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options?: Options.Less | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Less) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options?: Options.Postcss | undefined) => PreprocessorGroup; | ||
/** Adapted from https://github.com/TehShrike/svelte-preprocess-postcss */ | ||
declare const _default: (options?: Options.Postcss) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { Options, PreprocessorGroup } from '../types/index'; | ||
declare const _default: (options?: Options.Pug | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Pug) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options: Options.Replace) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { PreprocessorGroup, Options } from '../types'; | ||
declare const _default: (options?: Options.Sass | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Sass) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { Options, PreprocessorGroup } from '../types'; | ||
declare const _default: (options?: Options.Stylus | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Stylus) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { Options, PreprocessorGroup } from '../types'; | ||
declare const _default: (options?: Options.Typescript | undefined) => PreprocessorGroup; | ||
declare const _default: (options?: Options.Typescript) => PreprocessorGroup; | ||
export default _default; |
"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; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Babel>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Coffeescript>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.GlobalStyle>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Less>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import type { Transformer, Options } from '../types'; |
"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; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Pug>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Replace>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Sass>; | ||
export { transformer }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = 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) { | ||
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; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,18 +30,2 @@ exports.transformer = void 0; | ||
const utils_1 = require("../modules/utils"); | ||
let sass; | ||
function getProcessedResult(result) { | ||
var _a; | ||
// For some reason, scss includes the main 'file' in the array, we don't want that | ||
// Unfortunately I didn't manage to reproduce this in the test env | ||
// More info: https://github.com/sveltejs/svelte-preprocess/issues/346 | ||
const absoluteEntryPath = (0, path_1.isAbsolute)(result.stats.entry) | ||
? result.stats.entry | ||
: (0, path_1.join)(process.cwd(), result.stats.entry); | ||
const processed = { | ||
code: result.css.toString(), | ||
map: (_a = result.map) === null || _a === void 0 ? void 0 : _a.toString(), | ||
dependencies: Array.from(result.stats.includedFiles).filter((filepath) => filepath !== absoluteEntryPath), | ||
}; | ||
return processed; | ||
} | ||
const tildeImporter = (url, prev) => { | ||
@@ -45,16 +52,12 @@ if (!url.startsWith('~')) { | ||
var _a; | ||
let implementation = (_a = options === null || options === void 0 ? void 0 : options.implementation) !== null && _a !== void 0 ? _a : sass; | ||
if (implementation == null) { | ||
const mod = (await (0, utils_1.importAny)('sass', 'node-sass')); | ||
// eslint-disable-next-line no-multi-assign | ||
implementation = sass = mod.default; | ||
} | ||
const { renderSync, prependData, ...restOptions } = { | ||
...options, | ||
const { renderSync } = await Promise.resolve().then(() => __importStar(require('sass'))); | ||
const { prependData, ...restOptions } = options; | ||
const sassOptions = { | ||
...restOptions, | ||
includePaths: (0, utils_1.getIncludePaths)(filename, options.includePaths), | ||
sourceMap: true, | ||
sourceMapEmbed: false, | ||
omitSourceMapUrl: true, | ||
outFile: `${filename}.css`, | ||
omitSourceMapUrl: true, // return sourcemap only in result.map | ||
}; | ||
const sassOptions = { | ||
...restOptions, | ||
outputStyle: 'expanded', | ||
file: filename, | ||
@@ -73,16 +76,19 @@ data: content, | ||
// scss errors if passed an empty string | ||
if (sassOptions.data.length === 0) { | ||
if (content.length === 0) { | ||
return { code: '' }; | ||
} | ||
if (renderSync) { | ||
return getProcessedResult(implementation.renderSync(sassOptions)); | ||
} | ||
return new Promise((resolve, reject) => { | ||
implementation.render(sassOptions, (err, result) => { | ||
if (err) | ||
return reject(err); | ||
resolve(getProcessedResult(result)); | ||
}); | ||
}); | ||
const compiled = renderSync(sassOptions); | ||
// For some reason, scss includes the main 'file' in the array, we don't want that | ||
// Unfortunately I didn't manage to reproduce this in the test env | ||
// More info: https://github.com/sveltejs/svelte-preprocess/issues/346 | ||
const absoluteEntryPath = (0, path_1.isAbsolute)(compiled.stats.entry) | ||
? compiled.stats.entry | ||
: (0, path_1.join)(process.cwd(), compiled.stats.entry); | ||
const processed = { | ||
code: compiled.css.toString(), | ||
map: (_a = compiled.map) === null || _a === void 0 ? void 0 : _a.toString(), | ||
dependencies: Array.from(compiled.stats.includedFiles).filter((filepath) => filepath !== absoluteEntryPath), | ||
}; | ||
return processed; | ||
}; | ||
exports.transformer = transformer; |
import type { Transformer, Options } from '../types'; | ||
declare const transformer: Transformer<Options.Stylus>; | ||
export { transformer }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import ts from 'typescript'; |
@@ -0,0 +0,0 @@ "use strict"; |
import * as Options from './options'; | ||
import type { Processed as SvelteProcessed, Preprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess'; | ||
import type { Processed as SvelteProcessed, Preprocessor as SveltePreprocessor, PreprocessorGroup } from 'svelte/types/compiler/preprocess'; | ||
export { Options }; | ||
export { Processed as SvelteProcessed, PreprocessorGroup, Preprocessor, } from 'svelte/types/compiler/preprocess'; | ||
export declare type PreprocessorArgs = Preprocessor extends (options: infer T) => any ? T : never; | ||
export declare type TransformerArgs<T> = { | ||
export { PreprocessorGroup } from 'svelte/types/compiler/preprocess'; | ||
export type PreprocessorArgs = Preprocessor extends (options: infer T) => any ? T : never; | ||
export type TransformerArgs<T> = { | ||
content: string; | ||
@@ -15,7 +15,18 @@ filename?: string; | ||
}; | ||
export declare type Processed = SvelteProcessed & { | ||
/** | ||
* Small extension to the official SvelteProcessed type | ||
* to include possible diagnostics. | ||
* Used for the typescript transformer. | ||
*/ | ||
export type Processed = SvelteProcessed & { | ||
diagnostics?: any[]; | ||
}; | ||
export declare type Transformer<T> = (args: TransformerArgs<T>) => Processed | Promise<Processed>; | ||
export declare type TransformerOptions<T = any> = boolean | T | Transformer<T>; | ||
/** | ||
* Svelte preprocessor type with guaranteed Processed results | ||
* | ||
* The official type also considers `void` | ||
* */ | ||
export type Preprocessor = (options: Parameters<SveltePreprocessor>[0]) => Processed | Promise<Processed>; | ||
export type Transformer<T> = (args: TransformerArgs<T>) => Processed | Promise<Processed>; | ||
export type TransformerOptions<T = any> = boolean | T | Transformer<T>; | ||
export interface Transformers { | ||
@@ -35,19 +46,7 @@ babel?: TransformerOptions<Options.Babel>; | ||
} | ||
export declare type AutoPreprocessGroup = PreprocessorGroup & { | ||
defaultLanguages: Readonly<{ | ||
markup: string; | ||
style: string; | ||
script: string; | ||
}>; | ||
}; | ||
export declare type AutoPreprocessOptions = { | ||
export type AutoPreprocessGroup = PreprocessorGroup; | ||
export type AutoPreprocessOptions = { | ||
markupTagName?: string; | ||
aliases?: Array<[string, string]>; | ||
preserve?: string[]; | ||
/** @deprecated Don't use "defaults" anymore, define the language being used explicitly instead */ | ||
defaults?: { | ||
markup?: string; | ||
style?: string; | ||
script?: string; | ||
}; | ||
sourceMap?: boolean; | ||
@@ -54,0 +53,0 @@ babel?: TransformerOptions<Options.Babel>; |
"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; |
@@ -0,13 +1,13 @@ | ||
import type { LegacyStringOptions } from 'sass'; | ||
import type * as postcss from 'postcss'; | ||
import type { Options as SassOptions, render, renderSync } from 'sass'; | ||
import type { Options as PugOptions } from 'pug'; | ||
import type { TransformOptions as BabelOptions } from '@babel/core'; | ||
declare type ContentModifier = { | ||
type ContentModifier = { | ||
prependData?: string; | ||
stripIndent?: boolean; | ||
}; | ||
declare type MarkupOptions = { | ||
type MarkupOptions = { | ||
markupTagName?: string; | ||
}; | ||
export declare type Coffeescript = { | ||
export type Coffeescript = { | ||
sourceMap?: boolean; | ||
@@ -17,7 +17,7 @@ filename?: never; | ||
} & ContentModifier; | ||
export declare type Postcss = postcss.ProcessOptions & { | ||
export type Postcss = postcss.ProcessOptions & { | ||
plugins?: postcss.AcceptedPlugin[]; | ||
configFilePath?: string; | ||
} & ContentModifier; | ||
export declare type Babel = BabelOptions & { | ||
export type Babel = BabelOptions & { | ||
sourceType?: 'module'; | ||
@@ -29,11 +29,5 @@ minified?: false; | ||
} & ContentModifier; | ||
export declare type Pug = Omit<PugOptions, 'filename' | 'doctype' | 'compileDebug'> & ContentModifier & MarkupOptions; | ||
export declare type Sass = Omit<SassOptions, 'file' | 'data'> & { | ||
implementation?: { | ||
render: typeof render; | ||
renderSync: typeof renderSync; | ||
}; | ||
renderSync?: boolean; | ||
} & ContentModifier; | ||
export declare type Less = { | ||
export type Pug = Omit<PugOptions, 'filename' | 'doctype' | 'compileDebug'> & ContentModifier & MarkupOptions; | ||
export type Sass = Omit<LegacyStringOptions<'sync'>, 'file' | 'data'> & ContentModifier; | ||
export type Less = { | ||
paths?: string[]; | ||
@@ -49,3 +43,3 @@ plugins?: any[]; | ||
} & ContentModifier; | ||
export declare type Stylus = { | ||
export type Stylus = { | ||
globals?: Record<string, any>; | ||
@@ -57,3 +51,3 @@ functions?: Record<string, any>; | ||
} & ContentModifier; | ||
export declare type Typescript = { | ||
export type Typescript = { | ||
compilerOptions?: any; | ||
@@ -68,3 +62,3 @@ tsconfigFile?: string | boolean; | ||
} | ||
export declare type Replace = Array<[string | RegExp, string] | [RegExp, (substring: string, ...args: any[]) => string]>; | ||
export type Replace = Array<[string | RegExp, string] | [RegExp, (substring: string, ...args: any[]) => string]>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "svelte-preprocess", | ||
"version": "4.10.7", | ||
"version": "5.0.0-alpha.0", | ||
"license": "MIT", | ||
@@ -21,6 +21,6 @@ "main": "dist/index.js", | ||
"engines": { | ||
"node": ">= 9.11.2" | ||
"node": ">= 14.10.0" | ||
}, | ||
"volta": { | ||
"node": "14.18.2" | ||
"node": "14.19.2" | ||
}, | ||
@@ -33,7 +33,7 @@ "files": [ | ||
"build": "tsc --build tsconfig.build.json", | ||
"dev": "npm run build -- -w", | ||
"dev": "pnpm build -w", | ||
"test": "jest", | ||
"lint": "eslint --ext js,ts .", | ||
"format": "prettier --write \"**/*.{ts,js,json}\"", | ||
"postinstall": "echo \"[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: node-sass/sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...\"", | ||
"postinstall": "echo \"[svelte-preprocess] Don't forget to install the preprocessors packages that will be used: sass, stylus, less, postcss & postcss-load-config, coffeescript, pug, etc...\"", | ||
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md", | ||
@@ -43,14 +43,5 @@ "patch": "npm version patch -m 'chore(release): %s'", | ||
"major": "npm version major -m 'chore(release): %s'", | ||
"prepublishOnly": "npm run test && npm run build" | ||
"prepublishOnly": "pnpm test && pnpm build", | ||
"prepare": "husky install" | ||
}, | ||
"jest": { | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"<rootDir>/src/**/*.ts", | ||
"!<rootDir>/src/types/**/*.ts" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
} | ||
}, | ||
"commitlint": { | ||
@@ -61,10 +52,2 @@ "extends": [ | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged", | ||
"pre-push": "tsc --noEmit", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"post-merge": "yarn" | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -80,39 +63,38 @@ "*.{ts,js,tsx,jsx}": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.10.2", | ||
"@babel/preset-env": "^7.10.2", | ||
"@babel/core": "^7.20.5", | ||
"@babel/preset-env": "^7.20.2", | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0", | ||
"@kiwi/eslint-config": "^1.18.1", | ||
"@kiwi/prettier-config": "^1.18.1", | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^14.0.11", | ||
"@types/node-sass": "^4.11.1", | ||
"@types/stylus": "^0.48.32", | ||
"autoprefixer": "^9.8.0", | ||
"babel-minify": "^0.5.1", | ||
"coffeescript": "^2.5.1", | ||
"conventional-changelog-cli": "^2.0.34", | ||
"eslint": "^7.32.0", | ||
"husky": "^4.2.5", | ||
"jest": "^27.2.4", | ||
"less": "^3.11.3", | ||
"lint-staged": "^10.5.3", | ||
"node-sass": "^5.0.0", | ||
"postcss": "^8", | ||
"@kiwi/eslint-config": "^2.0.2", | ||
"@kiwi/prettier-config": "^2.0.2", | ||
"@types/babel__core": "^7.1.20", | ||
"@types/jest": "^27.5.2", | ||
"@types/node": "^14.18.34", | ||
"@types/stylus": "^0.48.38", | ||
"autoprefixer": "^9.8.8", | ||
"babel-minify": "^0.5.2", | ||
"coffeescript": "^2.7.0", | ||
"conventional-changelog-cli": "^2.2.2", | ||
"eslint": "^8.29.0", | ||
"husky": "^8.0.2", | ||
"jest": "^27.5.1", | ||
"less": "^3.13.1", | ||
"lint-staged": "^10.5.4", | ||
"postcss": "^8.4.19", | ||
"postcss-easy-import": "^3.0.0", | ||
"postcss-load-config": "^3.0.0", | ||
"prettier": "^2.4.1", | ||
"pug": "^3.0.0", | ||
"sass": "^1.26.8", | ||
"postcss-load-config": "^3.1.4", | ||
"prettier": "^2.8.1", | ||
"pug": "^3.0.2", | ||
"sass": "^1.56.2", | ||
"stylus": "^0.55.0", | ||
"sugarss": "^2.0.0", | ||
"svelte": "^3.42.0", | ||
"ts-jest": "^27.0.5", | ||
"typescript": "^4.4.2" | ||
"svelte": "^3.54.0", | ||
"ts-jest": "^27.1.5", | ||
"typescript": "^4.9.4" | ||
}, | ||
"dependencies": { | ||
"@types/pug": "^2.0.4", | ||
"@types/sass": "^1.16.0", | ||
"detect-indent": "^6.0.0", | ||
"magic-string": "^0.25.7", | ||
"@types/pug": "^2.0.6", | ||
"@types/sass": "^1.43.1", | ||
"detect-indent": "^6.1.0", | ||
"magic-string": "^0.27.0", | ||
"sorcery": "^0.10.0", | ||
@@ -144,5 +126,2 @@ "strip-indent": "^3.0.0" | ||
}, | ||
"node-sass": { | ||
"optional": true | ||
}, | ||
"postcss": { | ||
@@ -149,0 +128,0 @@ "optional": true |
@@ -35,3 +35,3 @@ # Svelte Preprocess | ||
`Svelte`'s own parser understands only JavaScript, CSS and its HTML-like syntax. To make it possible to write components in other languages, such as TypeScript or SCSS, `Svelte` provides the [preprocess API](https://svelte.dev/docs#svelte_preprocess), which allows to easily transform the content of your `markup` and your `style`/`script` tags. | ||
`Svelte`'s own parser understands only JavaScript, CSS and its HTML-like syntax. To make it possible to write components in other languages, such as TypeScript or SCSS, `Svelte` provides the [preprocess API](https://svelte.dev/docs#compile-time-svelte-preprocess), which allows to easily transform the content of your `markup` and your `style`/`script` tags. | ||
@@ -38,0 +38,0 @@ Writing your own preprocessor for, i.e SCSS is easy enough, but it can be cumbersome to have to always configure multiple preprocessors for the languages you'll be using. |
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
152424
30
66
2216
8
2
+ Addedmagic-string@0.27.0(transitive)
- Removedmagic-string@0.25.9(transitive)
Updated@types/pug@^2.0.6
Updated@types/sass@^1.43.1
Updateddetect-indent@^6.1.0
Updatedmagic-string@^0.27.0