feat: docker compose maybe

This commit is contained in:
2023-11-13 16:10:04 -05:00
parent 180b261e40
commit b625ccd8d6
8031 changed files with 2182966 additions and 0 deletions

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Babel>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"babel.d.ts","sourceRoot":"","sources":["../../src/transformers/babel.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAErD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CA0C3C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const core_1 = require("@babel/core");
const transformer = async ({ content, filename, options, map = undefined, }) => {
const babelOptions = {
...options,
inputSourceMap: typeof map === 'string' ? JSON.parse(map) : map !== null && map !== void 0 ? map : undefined,
sourceType: 'module',
// istanbul ignore next
sourceMaps: !!(options === null || options === void 0 ? void 0 : options.sourceMaps),
filename,
minified: false,
ast: false,
code: true,
caller: {
name: 'svelte-preprocess',
supportsStaticESM: true,
supportsDynamicImport: true,
// this isn't supported by Svelte but let it error with a good error on this syntax untouched
supportsTopLevelAwait: true,
// todo: this can be enabled once all "peer deps" understand this
// this syntax is supported since rollup@1.26.0 and webpack@5.0.0-beta.21
// supportsExportNamespaceFrom: true,
...options === null || options === void 0 ? void 0 : options.caller,
},
};
const result = await (0, core_1.transformAsync)(content, babelOptions);
if (result == null) {
return { code: content };
}
const { code, map: sourcemap } = result;
return {
code: code,
map: sourcemap !== null && sourcemap !== void 0 ? sourcemap : undefined,
};
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"babel.js","sourceRoot":"","sources":["../../src/transformers/babel.ts"],"names":[],"mappings":";;;AAAA,sCAA6C;AAK7C,MAAM,WAAW,GAA+B,KAAK,EAAE,EACrD,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,GAAG,SAAS,GAChB,EAAE,EAAE;IACH,MAAM,YAAY,GAAG;QACnB,GAAG,OAAO;QACV,cAAc,EACZ,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,SAAS;QAC9D,UAAU,EAAE,QAAQ;QACpB,uBAAuB;QACvB,UAAU,EAAE,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;QACjC,QAAQ;QACR,QAAQ,EAAE,KAAK;QACf,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE;YACN,IAAI,EAAE,mBAAmB;YACzB,iBAAiB,EAAE,IAAI;YACvB,qBAAqB,EAAE,IAAI;YAC3B,6FAA6F;YAC7F,qBAAqB,EAAE,IAAI;YAC3B,iEAAiE;YACjE,yEAAyE;YACzE,qCAAqC;YACrC,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;SACnB;KACkB,CAAC;IAEtB,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAc,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAE3D,IAAI,MAAM,IAAI,IAAI,EAAE;QAClB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;KAC1B;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAExC,OAAO;QACL,IAAI,EAAE,IAAc;QACpB,GAAG,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,SAAS;KAC5B,CAAC;AACJ,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Coffeescript>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"coffeescript.d.ts","sourceRoot":"","sources":["../../src/transformers/coffeescript.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAErD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,YAAY,CA0BlD,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,24 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const coffeescript_1 = __importDefault(require("coffeescript"));
const transformer = ({ content, filename, options, }) => {
const coffeeOptions = {
filename,
/*
* Since `coffeescript` transpiles variables to `var` definitions, it uses a safety mechanism to prevent variables from bleeding to outside contexts. This mechanism consists of wrapping your `coffeescript` code inside an IIFE which, unfortunately, prevents `svelte` from finding your variables. To bypass this behavior, `svelte-preprocess` sets the [`bare` coffeescript compiler option](https://coffeescript.org/#lexical-scope) to `true`.
*/
bare: true,
...options,
};
if (coffeeOptions.sourceMap) {
const { js: code, v3SourceMap } = coffeescript_1.default.compile(content, coffeeOptions);
const map = JSON.parse(v3SourceMap);
return { code, map };
}
return { code: coffeescript_1.default.compile(content, coffeeOptions) };
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"coffeescript.js","sourceRoot":"","sources":["../../src/transformers/coffeescript.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAwC;AAIxC,MAAM,WAAW,GAAsC,CAAC,EACtD,OAAO,EACP,QAAQ,EACR,OAAO,GACR,EAAE,EAAE;IACH,MAAM,aAAa,GAAG;QACpB,QAAQ;QACR;;WAEG;QACH,IAAI,EAAE,IAAI;QACV,GAAG,OAAO;KAC2B,CAAC;IAExC,IAAI,aAAa,CAAC,SAAS,EAAE;QAC3B,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,sBAAY,CAAC,OAAO,CACpD,OAAO,EACP,aAAa,CACd,CAAC;QAEF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAEpC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;KACtB;IAED,OAAO,EAAE,IAAI,EAAE,sBAAY,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.GlobalStyle>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"globalStyle.d.ts","sourceRoot":"","sources":["../../src/transformers/globalStyle.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA8DrD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,WAAW,CAmBjD,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,69 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const postcss_1 = __importDefault(require("postcss"));
const globalifySelector_1 = require("../modules/globalifySelector");
const selectorPattern = /:global(?!\()/;
const globalifyRulePlugin = (root) => {
root.walkRules(selectorPattern, (rule) => {
var _a;
const modifiedSelectors = rule.selectors
.filter((selector) => selector !== ':global')
.map((selector) => {
const [beginning, ...rest] = selector.split(selectorPattern);
if (rest.length === 0)
return beginning;
return [beginning, ...rest.map(globalifySelector_1.globalifySelector)]
.map((str) => str.trim())
.join(' ')
.trim();
});
if (modifiedSelectors.length === 0) {
if (((_a = rule.parent) === null || _a === void 0 ? void 0 : _a.type) === 'atrule' && rule.selector === ':global') {
rule.replaceWith(...rule.nodes);
}
else {
rule.remove();
}
return;
}
rule.replaceWith(rule.clone({
selectors: modifiedSelectors,
}));
});
};
const globalAttrPlugin = (root) => {
root.walkAtRules(/keyframes$/, (atrule) => {
if (!atrule.params.startsWith('-global-')) {
atrule.replaceWith(atrule.clone({
params: `-global-${atrule.params}`,
}));
}
});
root.walkRules((rule) => {
var _a, _b;
// we use endsWith for checking @keyframes and prefixed @-{prefix}-keyframes
if ((_b = (_a = rule === null || rule === void 0 ? void 0 : rule.parent) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.endsWith('keyframes')) {
return;
}
rule.replaceWith(rule.clone({
selectors: rule.selectors.map(globalifySelector_1.globalifySelector),
}));
});
};
const transformer = async ({ content, filename, options, map, attributes, }) => {
const plugins = [
globalifyRulePlugin,
(attributes === null || attributes === void 0 ? void 0 : attributes.global) && globalAttrPlugin,
].filter(Boolean);
const { css, map: newMap } = await (0, postcss_1.default)(plugins).process(content, {
from: filename,
to: filename,
map: (options === null || options === void 0 ? void 0 : options.sourceMap) ? { prev: map } : false,
});
return { code: css, map: newMap };
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"globalStyle.js","sourceRoot":"","sources":["../../src/transformers/globalStyle.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAE9B,oEAAiE;AAKjE,MAAM,eAAe,GAAG,eAAe,CAAC;AAExC,MAAM,mBAAmB,GAAG,CAAC,IAAe,EAAE,EAAE;IAC9C,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;;QACvC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS;aACrC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,SAAS,CAAC;aAC5C,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YAChB,MAAM,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YAE7D,IAAI,IAAI,C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AE,QAAQ,CAAC,WAAW,CAAC,EAAE;YAC9D,OAAO;SACR;QAED,IAAI,CAAC,WAAW,CACd,IAAI,CAAC,KAAK,CAAC;YACT,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,qCAAiB,CAAC;SACjD,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,WAAW,GAAqC,KAAK,EAAE,EAC3D,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,EACH,UAAU,GACX,EAAE,EAAE;IACH,MAAM,OAAO,GAAG;QACd,mBAAmB;QACnB,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,KAAI,gBAAgB;KACvC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,iBAAO,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE;QACnE,IAAI,EAAE,QAAQ;QACd,EAAE,EAAE,QAAQ;QACZ,GAAG,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK;KAChD,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACpC,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Less>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"less.d.ts","sourceRoot":"","sources":["../../src/transformers/less.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAErD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAyB1C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,27 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const path_1 = require("path");
const less_1 = __importDefault(require("less"));
const utils_1 = require("../modules/utils");
const transformer = async ({ content, filename, options = {}, }) => {
options = {
paths: (0, utils_1.getIncludePaths)(filename, options.paths),
...options,
};
const { css, map, imports } = await less_1.default.render(content, {
sourceMap: {},
filename,
...options,
});
const dependencies = imports.map((path) => (0, path_1.isAbsolute)(path) ? path : (0, path_1.join)(process.cwd(), path));
return {
code: css,
map,
dependencies,
};
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"less.js","sourceRoot":"","sources":["../../src/transformers/less.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAwC;AAExC,gDAAwB;AAExB,4CAAmD;AAInD,MAAM,WAAW,GAA8B,KAAK,EAAE,EACpD,OAAO,EACP,QAAQ,EACR,OAAO,GAAG,EAAE,GACb,EAAE,EAAE;IACH,OAAO,GAAG;QACR,KAAK,EAAE,IAAA,uBAAe,EAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC;QAC/C,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,MAAM,cAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACvD,SAAS,EAAE,EAAE;QACb,QAAQ;QACR,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAChD,IAAA,iBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CACpD,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,GAAG;QACT,GAAG;QACH,YAAY;KACb,CAAC;AACJ,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,4 @@
import type { Transformer, Options } from '../types';
/** Adapted from https://github.com/TehShrike/svelte-preprocess-postcss */
declare const transformer: Transformer<Options.Postcss>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"postcss.d.ts","sourceRoot":"","sources":["../../src/transformers/postcss.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA2DrD,0EAA0E;AAC1E,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CA2B7C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,84 @@
"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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const postcss_1 = __importDefault(require("postcss"));
async function process({ options: { plugins = [], parser, syntax } = {}, content, filename, sourceMap, }) {
const { css, map, messages } = await (0, postcss_1.default)(plugins).process(content, {
from: filename,
to: filename,
map: { prev: sourceMap, inline: false },
parser,
syntax,
});
const dependencies = messages.reduce((acc, msg) => {
// istanbul ignore if
if (msg.type !== 'dependency')
return acc;
acc.push(msg.file);
return acc;
}, []);
return { code: css, map, dependencies };
}
async function getConfigFromFile(options) {
try {
/** If not, look for a postcss config file */
const { default: postcssLoadConfig } = await Promise.resolve().then(() => __importStar(require(`postcss-load-config`)));
const loadedConfig = await postcssLoadConfig(options, options === null || options === void 0 ? void 0 : options.configFilePath);
return {
error: null,
config: {
plugins: loadedConfig.plugins,
// `postcss-load-config` puts all other props in a `options` object
...loadedConfig.options,
},
};
}
catch (e) {
return {
config: null,
error: e,
};
}
}
/** Adapted from https://github.com/TehShrike/svelte-preprocess-postcss */
const transformer = async ({ content, filename, options = {}, map, }) => {
let fileConfig = null;
if (!options.plugins) {
fileConfig = await getConfigFromFile(options);
options = { ...options, ...fileConfig.config };
}
if (options.plugins || options.syntax || options.parser) {
return process({ options, content, filename, sourceMap: map });
}
if ((fileConfig === null || fileConfig === void 0 ? void 0 : fileConfig.error) != null) {
console.error(`[svelte-preprocess] PostCSS configuration was not passed or is invalid. If you expect to load it from a file make sure to install "postcss-load-config" and try again.\n\n${fileConfig.error}`);
}
return { code: content, map, dependencies: [] };
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"postcss.js","sourceRoot":"","sources":["../../src/transformers/postcss.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA8B;AAI9B,KAAK,UAAU,OAAO,CAAC,EACrB,OAAO,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,EAC9C,OAAO,EACP,QAAQ,EACR,SAAS,GAMV;IACC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAA,iBAAO,EAAC,OAAO,CAAC,CAAC,OAAO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AI,CAAC;IAEhB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QACpB,UAAU,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;KAChD;IAED,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE;QACvD,OAAO,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;KAChE;IAED,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,KAAI,IAAI,EAAE;QAC7B,OAAO,CAAC,KAAK,CACX,6KAA6K,UAAU,CAAC,KAAK,EAAE,CAChM,CAAC;KACH;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,EAAW,EAAE,CAAC;AAC3D,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Pug>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"pug.d.ts","sourceRoot":"","sources":["../../src/transformers/pug.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAoDrD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,CAuCzC,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,83 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const detect_indent_1 = __importDefault(require("detect-indent"));
const pug_1 = __importDefault(require("pug"));
// Mixins to use svelte template features
const GET_MIXINS = (indentationType) => `mixin if(condition)
%_| {#if !{condition}}
%_block
%_| {/if}
mixin else
%_| {:else}
%_block
mixin elseif(condition)
%_| {:else if !{condition}}
%_block
mixin key(expression)
%_| {#key !{expression}}
%_block
%_| {/key}
mixin each(loop)
%_| {#each !{loop}}
%_block
%_| {/each}
mixin await(promise)
%_| {#await !{promise}}
%_block
%_| {/await}
mixin then(answer)
%_| {:then !{answer}}
%_block
mixin catch(error)
%_| {:catch !{error}}
%_block
mixin html(expression)
%_| {@html !{expression}}
mixin const(expression)
%_| {@const !{expression}}
mixin debug(variables)
%_| {@debug !{variables}}`.replace(/%_/g, indentationType === 'tab' ? '\t' : ' ');
const transformer = async ({ content, filename, options, }) => {
var _a;
const pugOptions = {
// needed so pug doesn't mirror boolean attributes
// and prop spreading expressions.
doctype: 'html',
compileDebug: false,
filename,
...options,
};
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);
let code;
try {
code = compiled();
}
catch (e) {
// The error message does not have much context, add more of it
if (e instanceof Error) {
e.message = `[svelte-preprocess] Pug error while preprocessing ${filename}\n\n${e.message}`;
}
throw e;
}
return {
code,
dependencies: (_a = compiled.dependencies) !== null && _a !== void 0 ? _a : [],
};
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"pug.js","sourceRoot":"","sources":["../../src/transformers/pug.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAyC;AACzC,8CAAsB;AAItB,yCAAyC;AACzC,MAAM,UAAU,GAAG,CAAC,cAA+B,EAAE,EAAE,CACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA2CwB,CAAC,OAAO,CAC9B,KAAK,EACL,cAAc,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CACvC,CAAC;AAEJ,MAAM,WAAW,GAA6B,KAAK,EAAE,EACnD,OAAO,EACP,QAAQ,EACR,OAAO,GACR,EAAE,EAAE;;IACH,MAAM,UAAU,GAAG;QACjB,kDAAkD;QAClD,kCAAkC;QAClC,OAAO,EAAE,MAAM;QACf,YAAY,EAAE,KAAK;QACnB,QAAQ;QACR,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,IAAA,uBAAY,EAAC,OAAO,CAAC,CAAC;IACvD,MAAM,KAAK,GAAG,GAAG,UAAU,CAAC,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,OAAO,CAAC,KAAK,OAAO,EAAE,CAAC;IACrE,MAAM,QAAQ,GAAG,aAAG,CAAC,OAAO,CAC1B,KAAK,EACL,UAAU,CAE0C,CAAC;IAEvD,IAAI,IAAY,CAAC;IAEjB,IAAI;QACF,IAAI,GAAG,QAAQ,EAAE,CAAC;KACnB;IAAC,OAAO,CAAC,EAAE;QACV,+DAA+D;QAC/D,IAAI,CAAC,YAAY,KAAK,EAAE;YACtB,CAAC,CAAC,OAAO,GAAG,qDAAqD,QAAQ,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;SAC7F;QAED,MAAM,CAAC,CAAC;KACT;IAED,OAAO;QACL,IAAI;QACJ,YAAY,EAAE,MAAA,QAAQ,CAAC,YAAY,mCAAI,EAAE;KAC1C,CAAC;AACJ,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Replace>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/transformers/replace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAErD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAiB7C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const transformer = async ({ content, options, }) => {
let newContent = content;
if (options == null) {
return { code: content };
}
for (const [regex, replacer] of options) {
newContent = newContent.replace(regex, replacer);
}
return {
code: newContent,
};
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/transformers/replace.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAiC,KAAK,EAAE,EACvD,OAAO,EACP,OAAO,GACR,EAAE,EAAE;IACH,IAAI,UAAU,GAAG,OAAO,CAAC;IAEzB,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;KAC1B;IAED,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,OAAO,EAAE;QACvC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,QAAe,CAAC,CAAC;KACzD;IAED,OAAO;QACL,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Sass>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"scss.d.ts","sourceRoot":"","sources":["../../src/transformers/scss.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA6BrD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAmD1C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,91 @@
"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 });
exports.transformer = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const utils_1 = require("../modules/utils");
const tildeImporter = (url, prev) => {
if (!url.startsWith('~')) {
return null;
}
// not sure why this ends up here, but let's remove it
prev = prev.replace('http://localhost', '');
// on windows, path comes encoded
if (process.platform === 'win32') {
prev = decodeURIComponent(prev);
}
const modulePath = (0, path_1.join)('node_modules', ...url.slice(1).split(/[\\/]/g));
const foundPath = (0, utils_1.findUp)({ what: modulePath, from: prev });
// istanbul ignore if
if (foundPath == null) {
return null;
}
const contents = (0, fs_1.readFileSync)(foundPath).toString();
return { contents };
};
const transformer = async ({ content, filename, options = {}, }) => {
var _a;
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`,
outputStyle: 'expanded',
file: filename,
data: content,
};
if (Array.isArray(sassOptions.importer)) {
sassOptions.importer = [tildeImporter, ...sassOptions.importer];
}
else if (sassOptions.importer == null) {
sassOptions.importer = [tildeImporter];
}
else {
sassOptions.importer = [sassOptions.importer, tildeImporter];
}
// scss errors if passed an empty string
if (content.length === 0) {
return { code: '' };
}
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;

View File

@ -0,0 +1 @@
{"version":3,"file":"scss.js","sourceRoot":"","sources":["../../src/transformers/scss.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAAkC;AAClC,+BAAwC;AAExC,4CAA2D;AAK3D,MAAM,aAAa,GAAuB,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;IACtD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,sDAAsD;IACtD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAE5C,iCAAiC;IACjC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QAChC,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;KACjC;IAED,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,cAAc,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzE,MAAM,SAAS,GAAG,IAAA,cAAM,EAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAE3D,qBAAqB;IACrB,IAAI,SAAS,IAAI,IAAI,EAAE;QACrB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,QAAQ,GAAG,IAAA,iBAAY,EAAC,SAAS,CAAC,CAAC,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AAU,EAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;QACxD,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK;QACtB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC7B,GAAG,EAAE,MAAA,QAAQ,CAAC,GAAG,0CAAE,QAAQ,EAAE;QAC7B,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,MAAM,CAC3D,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,iBAAiB,CAC7C;KACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,3 @@
import type { Transformer, Options } from '../types';
declare const transformer: Transformer<Options.Stylus>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"stylus.d.ts","sourceRoot":"","sources":["../../src/transformers/stylus.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAMrD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAmC5C,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,39 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = void 0;
const path_1 = __importDefault(require("path"));
const stylus_1 = __importDefault(require("stylus"));
const utils_1 = require("../modules/utils");
const transformer = ({ content, filename, options = {}, }) => {
options = {
paths: (0, utils_1.getIncludePaths)(filename, options.paths),
...options,
};
return new Promise((resolve, reject) => {
const style = (0, stylus_1.default)(content, {
filename,
...options,
}).set('sourcemap', options.sourcemap);
style.render((err, css) => {
var _a;
// istanbul ignore next
if (err)
reject(err);
if ((_a = style.sourcemap) === null || _a === void 0 ? void 0 : _a.sources) {
style.sourcemap.sources = style.sourcemap.sources.map((source) => path_1.default.resolve(source));
}
resolve({
code: css,
map: style.sourcemap,
// .map() necessary for windows compatibility
dependencies: style
.deps(filename)
.map((filePath) => path_1.default.resolve(filePath)),
});
});
});
};
exports.transformer = transformer;

View File

@ -0,0 +1 @@
{"version":3,"file":"stylus.js","sourceRoot":"","sources":["../../src/transformers/stylus.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,oDAA4B;AAE5B,4CAAmD;AASnD,MAAM,WAAW,GAAgC,CAAC,EAChD,OAAO,EACP,QAAQ,EACR,OAAO,GAAG,EAAE,GACb,EAAE,EAAE;IACH,OAAO,GAAG;QACR,KAAK,EAAE,IAAA,uBAAe,EAAC,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC;QAC/C,GAAG,OAAO;KACX,CAAC;IAEF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAA,gBAAM,EAAC,OAAO,EAAE;YAC5B,QAAQ;YACR,GAAG,OAAO;SACX,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAgC,CAAC;QAEtE,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;;YACxB,uBAAuB;YACvB,IAAI,GAAG;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,IAAI,MAAA,KAAK,CAAC,SAAS,0CAAE,OAAO,EAAE;gBAC5B,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC/D,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CACrB,CAAC;aACH;YAED,OAAO,CAAC;gBACN,IAAI,EAAE,GAAG;gBACT,GAAG,EAAE,KAAK,CAAC,SAAS;gBACpB,6CAA6C;gBAC7C,YAAY,EAAE,KAAK;qBAChB,IAAI,CAAC,QAAkB,CAAC;qBACxB,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;aAC7C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEO,kCAAW"}

View File

@ -0,0 +1,11 @@
import ts from 'typescript';
import type { Transformer, Options } from '../types';
export declare function loadTsconfig(compilerOptionsJSON: any, filename: string, tsOptions: Options.Typescript): {
errors: never[];
options: any;
} | {
errors: ts.Diagnostic[];
options: ts.CompilerOptions;
};
declare const transformer: Transformer<Options.Typescript>;
export { transformer };

View File

@ -0,0 +1 @@
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../src/transformers/typescript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAW5B,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAC;AAgUtE,wBAAgB,YAAY,CAC1B,mBAAmB,EAAE,GAAG,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,OAAO,CAAC,UAAU;;;;;;EAyD9B;AA8FD,QAAA,MAAM,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAiDhD,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}

View File

@ -0,0 +1,358 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformer = exports.loadTsconfig = void 0;
const path_1 = require("path");
const typescript_1 = __importDefault(require("typescript"));
const compiler_1 = require("svelte/compiler");
const magic_string_1 = __importDefault(require("magic-string"));
const sorcery_1 = require("sorcery");
const errors_1 = require("../modules/errors");
const markup_1 = require("../modules/markup");
const utils_1 = require("../modules/utils");
const package_json_1 = __importDefault(require("svelte/package.json"));
const injectedCodeSeparator = 'const $$$$$$$$ = null;';
/**
* Map of valid tsconfigs (no errors). Key is the path.
*/
const tsconfigMap = new Map();
const importsNotUsedAsValuesDeprecated = parseInt(typescript_1.default.version.split('.')[0], 10) >= 5;
function createFormatDiagnosticsHost(cwd) {
return {
getCanonicalFileName: (fileName) => fileName.replace('.injected.ts', ''),
getCurrentDirectory: () => cwd,
getNewLine: () => typescript_1.default.sys.newLine,
};
}
function formatDiagnostics(diagnostics, basePath) {
if (Array.isArray(diagnostics)) {
return typescript_1.default.formatDiagnosticsWithColorAndContext(diagnostics, createFormatDiagnosticsHost(basePath));
}
return typescript_1.default.formatDiagnostic(diagnostics, createFormatDiagnosticsHost(basePath));
}
const importTransformer = (context) => {
const visit = (node) => {
var _a, _b, _c;
if (typescript_1.default.isImportDeclaration(node)) {
if ((_a = node.importClause) === null || _a === void 0 ? void 0 : _a.isTypeOnly) {
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();
}
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;
};
};
function getScriptContent(markup, module) {
const regex = (0, markup_1.createTagRegex)('script', 'gi');
let match;
while ((match = regex.exec(markup)) !== null) {
const { context } = (0, markup_1.parseAttributes)(match[1] || '');
if ((context !== 'module' && !module) || (context === 'module' && module)) {
return match[2];
}
}
return '';
}
function createSourceMapChain({ filename, content, compilerOptions, }) {
if (compilerOptions.sourceMap) {
return {
content: {
[filename]: content,
},
sourcemaps: {},
};
}
}
function injectVarsToCode({ content, markup, filename, attributes, sourceMapChain, }) {
if (!markup)
return content;
// @ts-ignore different in Svelte 5
const { vars } = (0, compiler_1.compile)((0, markup_1.stripTags)(markup), {
generate: false,
varsReport: 'full',
errorMode: 'warn',
filename,
});
const sep = `\n${injectedCodeSeparator}\n`;
const varnames = vars.map((v) => v.name.startsWith('$') && !v.name.startsWith('$$')
? `${v.name},${v.name.slice(1)}`
: v.name);
const contentForCodestores = content +
// Append instance script content because it's valid
// to import a store in module script and autosubscribe to it in instance script
((attributes === null || attributes === void 0 ? void 0 : attributes.context) === 'module' ? getScriptContent(markup, false) : '');
// This regex extracts all possible store variables
// TODO investigate if it's possible to achieve this with a
// TS transformer (previous attemps have failed)
const codestores = Array.from(contentForCodestores.match(/\$[^\s();:,[\]{}.?!+\-=*/\\~|&%<>^`"'°§#0-9][^\s();:,[\]{}.?!+\-=*/\\~|&%<>^`"'°§#]*/g) || [], (name) => name.slice(1)).filter((name) => !utils_1.JAVASCRIPT_RESERVED_KEYWORD_SET.has(name));
const varsString = [...codestores, ...varnames].join(',');
const injectedVars = `const $$vars$$ = [${varsString}];`;
// Append instance/markup script content because it's valid
// to import things in one and reference it in the other.
const injectedCode = (attributes === null || attributes === void 0 ? void 0 : attributes.context) === 'module'
? `${sep}${getScriptContent(markup, false)}\n${injectedVars}`
: `${sep}${getScriptContent(markup, true)}\n${injectedVars}`;
if (sourceMapChain) {
const ms = new magic_string_1.default(content).append(injectedCode);
const fname = `${filename}.injected.ts`;
const code = ms.toString();
const map = ms.generateMap({
source: filename,
file: fname,
hires: true,
});
sourceMapChain.content[fname] = code;
sourceMapChain.sourcemaps[fname] = map;
return code;
}
return `${content}${injectedCode}`;
}
function stripInjectedCode({ transpiledCode, markup, filename, sourceMapChain, }) {
if (!markup)
return transpiledCode;
const injectedCodeStart = transpiledCode.indexOf(injectedCodeSeparator);
if (sourceMapChain) {
const ms = new magic_string_1.default(transpiledCode).snip(0, injectedCodeStart);
const source = `${filename}.transpiled.js`;
const file = `${filename}.js`;
const code = ms.toString();
const map = ms.generateMap({
source,
file,
hires: true,
});
sourceMapChain.content[file] = code;
sourceMapChain.sourcemaps[file] = map;
return code;
}
return transpiledCode.slice(0, injectedCodeStart);
}
async function concatSourceMaps({ filename, markup, sourceMapChain, }) {
if (!sourceMapChain)
return;
if (!markup) {
return sourceMapChain.sourcemaps[`${filename}.js`];
}
const chain = await (0, sorcery_1.load)(`${filename}.js`, sourceMapChain);
return chain.apply();
}
let warned = false;
function getCompilerOptions({ filename, options, basePath, }) {
var _a;
const inputOptions = (_a = options.compilerOptions) !== null && _a !== void 0 ? _a : {};
const { errors, options: convertedCompilerOptions } = options.tsconfigFile !== false || options.tsconfigDirectory
? loadTsconfig(inputOptions, filename, options)
: typescript_1.default.convertCompilerOptionsFromJson(inputOptions, basePath);
if (errors.length) {
throw new Error(formatDiagnostics(errors, basePath));
}
const compilerOptions = {
target: typescript_1.default.ScriptTarget.ES2015,
moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
...convertedCompilerOptions,
allowNonTsExtensions: true,
// Clear outDir since it causes source map issues when the files aren't actually written to disk.
outDir: undefined,
};
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 ||
compilerOptions.target === typescript_1.default.ScriptTarget.ES5) {
throw new Error(`Svelte only supports es6+ syntax. Set your 'compilerOptions.target' to 'es6' or higher.`);
}
return compilerOptions;
}
function transpileTs({ code, fileName, basePath, options, compilerOptions, transformers, }) {
const { outputText: transpiledCode, sourceMapText, diagnostics, } = typescript_1.default.transpileModule(code, {
fileName,
compilerOptions,
reportDiagnostics: options.reportDiagnostics !== false,
transformers,
});
if (diagnostics && diagnostics.length > 0) {
// could this be handled elsewhere?
const hasError = diagnostics.some((d) => d.category === typescript_1.default.DiagnosticCategory.Error);
const formattedDiagnostics = formatDiagnostics(diagnostics, basePath);
console.log(formattedDiagnostics);
if (hasError) {
(0, errors_1.throwTypescriptError)();
}
}
return { transpiledCode, sourceMapText, diagnostics };
}
function loadTsconfig(compilerOptionsJSON, filename, tsOptions) {
if (typeof tsOptions.tsconfigFile === 'boolean') {
return { errors: [], options: compilerOptionsJSON };
}
let basePath = process.cwd();
const fileDirectory = (tsOptions.tsconfigDirectory ||
(0, path_1.dirname)(filename));
let tsconfigFile = tsOptions.tsconfigFile ||
typescript_1.default.findConfigFile(fileDirectory, typescript_1.default.sys.fileExists);
if (!tsconfigFile) {
return { errors: [], options: compilerOptionsJSON };
}
tsconfigFile = (0, path_1.isAbsolute)(tsconfigFile)
? tsconfigFile
: (0, path_1.join)(basePath, tsconfigFile);
basePath = (0, path_1.dirname)(tsconfigFile);
if (tsconfigMap.has(tsconfigFile)) {
return {
errors: [],
options: tsconfigMap.get(tsconfigFile),
};
}
const { error, config } = typescript_1.default.readConfigFile(tsconfigFile, typescript_1.default.sys.readFile);
if (error) {
throw new Error(formatDiagnostics(error, basePath));
}
// Do this so TS will not search for initial files which might take a while
config.include = [];
let { errors, options } = typescript_1.default.parseJsonConfigFileContent(config, typescript_1.default.sys, basePath, compilerOptionsJSON, tsconfigFile);
// Filter out "no files found error"
errors = errors.filter((d) => d.code !== 18003);
if (errors.length === 0) {
tsconfigMap.set(tsconfigFile, options);
}
return { errors, options };
}
exports.loadTsconfig = loadTsconfig;
async function mixedImportsTranspiler({ content, filename = 'source.svelte', markup, options = {}, attributes, compilerOptions, basePath, }) {
const sourceMapChain = createSourceMapChain({
filename,
content,
compilerOptions,
});
const injectedCode = injectVarsToCode({
content,
markup,
filename,
attributes,
sourceMapChain,
});
const { transpiledCode, sourceMapText, diagnostics } = transpileTs({
code: injectedCode,
fileName: `${filename}.injected.ts`,
basePath,
options,
compilerOptions,
});
if (sourceMapChain && sourceMapText) {
const fname = `${filename}.transpiled.js`;
sourceMapChain.content[fname] = transpiledCode;
sourceMapChain.sourcemaps[fname] = JSON.parse(sourceMapText);
}
const code = stripInjectedCode({
transpiledCode,
markup,
filename,
sourceMapChain,
});
// Sorcery tries to load the code/map from disk if it's empty,
// prevent that because it would try to load inexistent files
// https://github.com/Rich-Harris/sorcery/issues/167
if (!code) {
return { code, diagnostics };
}
const map = await concatSourceMaps({
filename,
markup,
sourceMapChain,
});
return {
code,
map,
diagnostics,
};
}
async function simpleTranspiler({ content, filename = 'source.svelte', options = {}, compilerOptions, basePath, }) {
const { transpiledCode, sourceMapText, diagnostics } = transpileTs({
code: content,
// `preserveValueImports` essentially does the same as our import transformer,
// keeping all imports that are not type imports
transformers: compilerOptions.preserveValueImports ||
compilerOptions.verbatimModuleSyntax
? undefined
: { before: [importTransformer] },
fileName: filename,
basePath,
options,
compilerOptions,
});
return {
code: transpiledCode,
map: sourceMapText,
diagnostics,
};
}
const transformer = async ({ content, filename, markup, options = {}, attributes, }) => {
const basePath = process.cwd();
if (filename == null)
return { code: content };
filename = (0, path_1.isAbsolute)(filename) ? filename : (0, path_1.resolve)(basePath, filename);
const compilerOptions = getCompilerOptions({ filename, options, basePath });
const versionParts = package_json_1.default.version.split('.');
const canUseMixedImportsTranspiler = +versionParts[0] === 4 ||
(+versionParts[0] === 3 && +versionParts[1] >= 39);
if (!canUseMixedImportsTranspiler && options.handleMixedImports) {
throw new Error('You need at least Svelte 3.39 and at most Svelte 4.x to use the handleMixedImports option. ' +
'The option is no longer available for Svelte 5 and beyond. Use the verbatimModuleSyntax TypeScript option instead.');
}
const handleMixedImports = !compilerOptions.preserveValueImports &&
!compilerOptions.verbatimModuleSyntax &&
(options.handleMixedImports === false
? false
: options.handleMixedImports || canUseMixedImportsTranspiler);
return handleMixedImports
? mixedImportsTranspiler({
content,
filename,
markup,
options,
attributes,
compilerOptions,
basePath,
})
: simpleTranspiler({
content,
filename,
markup,
options,
attributes,
compilerOptions,
basePath,
});
};
exports.transformer = transformer;

File diff suppressed because one or more lines are too long