svelte-preprocess
Advanced tools
Comparing version 4.10.7 to 5.0.4
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,2 +32,7 @@ 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 }) => { | ||
@@ -37,3 +46,3 @@ if (name == null || options === false) { | ||
// 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 Promise.resolve(`${`./transformers/${name}`}`).then(s => __importStar(require(s))); | ||
return transformer({ | ||
@@ -51,13 +60,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 +100,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 +204,2 @@ } | ||
return { | ||
defaultLanguages, | ||
markup, | ||
@@ -208,0 +206,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 = { | ||
@@ -35,2 +32,3 @@ sass: { | ||
['sugarss', 'css'], | ||
['sss', 'css'], | ||
['sass', 'scss'], | ||
@@ -85,18 +83,3 @@ ['styl', 'stylus'], | ||
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' && | ||
@@ -103,0 +86,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) { | ||
@@ -22,20 +26,9 @@ if (k2 === undefined) k2 = k; | ||
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 +61,3 @@ }, []); | ||
try { | ||
await Promise.resolve().then(() => __importStar(require(dep))); | ||
await Promise.resolve(`${dep}`).then(s => __importStar(require(s))); | ||
result = true; | ||
@@ -71,0 +64,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 }; |
@@ -10,3 +10,3 @@ "use strict"; | ||
// Mixins to use svelte template features | ||
const GET_MIXINS = (identationType) => `mixin if(condition) | ||
const GET_MIXINS = (indentationType) => `mixin if(condition) | ||
%_| {#if !{condition}} | ||
@@ -54,3 +54,3 @@ %_block | ||
mixin debug(variables) | ||
%_| {@debug !{variables}}`.replace(/%_/g, identationType === 'tab' ? '\t' : ' '); | ||
%_| {@debug !{variables}}`.replace(/%_/g, indentationType === 'tab' ? '\t' : ' '); | ||
const transformer = async ({ content, filename, options, }) => { | ||
@@ -66,4 +66,4 @@ var _a; | ||
}; | ||
const { type: identationType } = (0, detect_indent_1.default)(content); | ||
const input = `${GET_MIXINS(identationType !== null && identationType !== void 0 ? identationType : 'space')}\n${content}`; | ||
const { type: indentationType } = (0, detect_indent_1.default)(content); | ||
const input = `${GET_MIXINS(indentationType !== null && indentationType !== void 0 ? indentationType : 'space')}\n${content}`; | ||
const compiled = pug_1.default.compile(input, pugOptions); | ||
@@ -70,0 +70,0 @@ let code; |
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'; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const magic_string_1 = __importDefault(require("magic-string")); | ||
const sorcery_1 = __importDefault(require("sorcery")); | ||
const sorcery_1 = require("sorcery"); | ||
const errors_1 = require("../modules/errors"); | ||
@@ -22,2 +22,3 @@ const markup_1 = require("../modules/markup"); | ||
const tsconfigMap = new Map(); | ||
const importsNotUsedAsValuesDeprecated = parseInt(typescript_1.default.version.split('.')[0], 10) >= 5; | ||
function createFormatDiagnosticsHost(cwd) { | ||
@@ -38,12 +39,25 @@ return { | ||
const visit = (node) => { | ||
var _a; | ||
var _a, _b, _c; | ||
if (typescript_1.default.isImportDeclaration(node)) { | ||
if ((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.isTypeOnly) { | ||
return typescript_1.default.createEmptyStatement(); | ||
if (!((_b = typescript_1.default.factory) === null || _b === void 0 ? void 0 : _b.createEmptyStatement)) { | ||
// @ts-expect-error removed in TS 5.0 | ||
return typescript_1.default.createEmptyStatement(); | ||
} | ||
return typescript_1.default.factory.createEmptyStatement(); | ||
} | ||
return typescript_1.default.createImportDeclaration(node.decorators, node.modifiers, node.importClause, node.moduleSpecifier); | ||
if (!((_c = typescript_1.default.factory) === null || _c === void 0 ? void 0 : _c.createImportDeclaration)) { | ||
// @ts-expect-error removed in TS 5.0 | ||
return typescript_1.default.createImportDeclaration( | ||
// @ts-expect-error removed in TS 5.0 | ||
node.decorators, node.modifiers, node.importClause, node.moduleSpecifier); | ||
} | ||
return typescript_1.default.factory.createImportDeclaration(node.modifiers, node.importClause, node.moduleSpecifier); | ||
} | ||
return typescript_1.default.visitEachChild(node, (child) => visit(child), context); | ||
}; | ||
return (node) => typescript_1.default.visitNode(node, visit); | ||
return (node) => { | ||
typescript_1.default.visitNode(node, visit); | ||
return node; | ||
}; | ||
}; | ||
@@ -140,5 +154,6 @@ function getScriptContent(markup, module) { | ||
} | ||
const chain = await sorcery_1.default.load(`${filename}.js`, sourceMapChain); | ||
const chain = await (0, sorcery_1.load)(`${filename}.js`, sourceMapChain); | ||
return chain.apply(); | ||
} | ||
let warned = false; | ||
function getCompilerOptions({ filename, options, basePath, }) { | ||
@@ -157,3 +172,2 @@ var _a; | ||
...convertedCompilerOptions, | ||
importsNotUsedAsValues: typescript_1.default.ImportsNotUsedAsValues.Error, | ||
allowNonTsExtensions: true, | ||
@@ -163,2 +177,20 @@ // Clear outDir since it causes source map issues when the files aren't actually written to disk. | ||
}; | ||
if (!importsNotUsedAsValuesDeprecated || | ||
(compilerOptions.ignoreDeprecations === '5.0' && | ||
!compilerOptions.verbatimModuleSyntax)) { | ||
compilerOptions.importsNotUsedAsValues = typescript_1.default.ImportsNotUsedAsValues.Error; | ||
} | ||
// Ease TS 5 migration pains a little and add the deprecation flag automatically if needed | ||
if (importsNotUsedAsValuesDeprecated && | ||
!compilerOptions.ignoreDeprecations && | ||
(compilerOptions.importsNotUsedAsValues || | ||
compilerOptions.preserveValueImports)) { | ||
if (!warned) { | ||
warned = true; | ||
console.warn('tsconfig options "importsNotUsedAsValues" and "preserveValueImports" are deprecated. ' + | ||
'Either set "ignoreDeprecations" to "5.0" in your tsconfig.json to silence this warning, ' + | ||
'or replace them in favor of the new "verbatimModuleSyntax" flag.'); | ||
} | ||
compilerOptions.ignoreDeprecations = '5.0'; | ||
} | ||
if (compilerOptions.target === typescript_1.default.ScriptTarget.ES3 || | ||
@@ -278,3 +310,4 @@ compilerOptions.target === typescript_1.default.ScriptTarget.ES5) { | ||
// keeping all imports that are not type imports | ||
transformers: compilerOptions.preserveValueImports | ||
transformers: compilerOptions.preserveValueImports || | ||
compilerOptions.verbatimModuleSyntax | ||
? undefined | ||
@@ -305,2 +338,3 @@ : { before: [importTransformer] }, | ||
const handleMixedImports = !compilerOptions.preserveValueImports && | ||
!compilerOptions.verbatimModuleSyntax && | ||
(options.handleMixedImports === false | ||
@@ -307,0 +341,0 @@ ? false |
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 }); |
124
package.json
{ | ||
"name": "svelte-preprocess", | ||
"version": "4.10.7", | ||
"version": "5.0.4", | ||
"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" | ||
}, | ||
@@ -30,26 +30,2 @@ "files": [ | ||
], | ||
"scripts": { | ||
"prebuild": "node scripts.js rmrf ./dist", | ||
"build": "tsc --build tsconfig.build.json", | ||
"dev": "npm run 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...\"", | ||
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md", | ||
"patch": "npm version patch -m 'chore(release): %s'", | ||
"minor": "npm version minor -m 'chore(release): %s'", | ||
"major": "npm version major -m 'chore(release): %s'", | ||
"prepublishOnly": "npm run test && npm run build" | ||
}, | ||
"jest": { | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"<rootDir>/src/**/*.ts", | ||
"!<rootDir>/src/types/**/*.ts" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
} | ||
}, | ||
"commitlint": { | ||
@@ -60,10 +36,2 @@ "extends": [ | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged", | ||
"pre-push": "tsc --noEmit", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"post-merge": "yarn" | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -79,40 +47,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": "^29.5.0", | ||
"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" | ||
"sugarss": "^4.0.0", | ||
"svelte": "^3.54.0", | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^5.0.2" | ||
}, | ||
"dependencies": { | ||
"@types/pug": "^2.0.4", | ||
"@types/sass": "^1.16.0", | ||
"detect-indent": "^6.0.0", | ||
"magic-string": "^0.25.7", | ||
"sorcery": "^0.10.0", | ||
"@types/pug": "^2.0.6", | ||
"detect-indent": "^6.1.0", | ||
"magic-string": "^0.27.0", | ||
"sorcery": "^0.11.0", | ||
"strip-indent": "^3.0.0" | ||
@@ -129,5 +95,5 @@ }, | ||
"stylus": "^0.55.0", | ||
"sugarss": "^2.0.0", | ||
"svelte": "^3.23.0", | ||
"typescript": "^3.9.5 || ^4.0.0" | ||
"sugarss": "^2.0.0 || ^3.0.0 || ^4.0.0", | ||
"svelte": "^3.23.0 || ^4.0.0-next.0 || ^4.0.0", | ||
"typescript": ">=3.9.5 || ^4.0.0 || ^5.0.0" | ||
}, | ||
@@ -144,5 +110,2 @@ "peerDependenciesMeta": { | ||
}, | ||
"node-sass": { | ||
"optional": true | ||
}, | ||
"postcss": { | ||
@@ -169,3 +132,16 @@ "optional": true | ||
} | ||
}, | ||
"scripts": { | ||
"prebuild": "node scripts.js rmrf ./dist", | ||
"build": "tsc --build tsconfig.build.json", | ||
"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: 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", | ||
"patch": "npm version patch -m 'chore(release): %s'", | ||
"minor": "npm version minor -m 'chore(release): %s'", | ||
"major": "npm version major -m 'chore(release): %s'" | ||
} | ||
} | ||
} |
@@ -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. |
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
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
163521
16
30
127
2249
8
+ Added@types/estree@1.0.5(transitive)
+ Addedacorn@8.12.1(transitive)
+ Addedaria-query@5.3.1(transitive)
+ Addedaxobject-query@4.1.0(transitive)
+ Addedbuffer-crc32@1.0.0(transitive)
+ Addedcode-red@1.0.4(transitive)
+ Addedcss-tree@2.3.1(transitive)
+ Addedestree-walker@3.0.3(transitive)
+ Addedis-reference@3.0.2(transitive)
+ Addedlocate-character@3.0.0(transitive)
+ Addedmagic-string@0.27.00.30.11(transitive)
+ Addedmdn-data@2.0.30(transitive)
+ Addedperiscopic@3.1.0(transitive)
+ Addedsorcery@0.11.1(transitive)
+ Addedsugarss@4.0.1(transitive)
+ Addedsvelte@4.2.19(transitive)
+ Addedtypescript@5.6.2(transitive)
- Removed@types/sass@^1.16.0
- Removed@types/sass@1.45.0(transitive)
- Removedbuffer-crc32@0.2.13(transitive)
- Removedmagic-string@0.25.9(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedsorcery@0.10.0(transitive)
- Removedsourcemap-codec@1.4.8(transitive)
- Removedsugarss@2.0.0(transitive)
- Removedsvelte@3.59.2(transitive)
- Removedtypescript@4.9.5(transitive)
Updated@types/pug@^2.0.6
Updateddetect-indent@^6.1.0
Updatedmagic-string@^0.27.0
Updatedsorcery@^0.11.0