diff --git a/README.md b/README.md
index a4ac2d6f..79da5240 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Svelte Preprocess
-> A [Svelte](https://svelte.dev) preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.
+> A [Svelte](https://svelte.dev) preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Civet, Pug and much more.
@@ -176,7 +176,7 @@ into
### Built-in support for commonly used languages
-The current supported languages out-of-the-box are Sass, Stylus, Less, CoffeeScript, TypeScript, Pug, PostCSS, Babel.
+The current supported languages out-of-the-box are Sass, Stylus, Less, CoffeeScript, TypeScript, Civet, Pug, PostCSS, Babel.
```html
diff --git a/docs/getting-started.md b/docs/getting-started.md
index 9465c175..caea9990 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -28,6 +28,7 @@ $ npm install -D svelte-preprocess
- Babel: `npm install -D @babel/core @babel/preset-...`
- CoffeeScript: `npm install -D coffeescript`
- TypeScript: `npm install -D typescript`
+- Civet: `npm install -D @danielx/civet`
- PostCSS: `npm install -D postcss postcss-load-config`
- SugarSS: `npm install -D postcss sugarss`
- Less: `npm install -D less`
@@ -70,7 +71,7 @@ export default {
}
```
-Now our app's code can be written in any of the syntaxes supported by `svelte-preprocess`: Sass, Stylus, Less, CoffeeScript, TypeScript, Pug, PostCSS, Babel.
+Now our app's code can be written in any of the syntaxes supported by `svelte-preprocess`: Sass, Stylus, Less, CoffeeScript, TypeScript, Civet, Pug, PostCSS, Babel.
_**Note:** If you use VS Code, check [its usage guide](/docs/usage.md#with-svelte-vs-code) to make the Svelte VS Code extension understand the content of your components._
diff --git a/docs/preprocessing.md b/docs/preprocessing.md
index c49d0401..c7b6aeab 100644
--- a/docs/preprocessing.md
+++ b/docs/preprocessing.md
@@ -11,6 +11,7 @@
- [Preprocessors](#preprocessors)
- [Babel](#babel)
- [CoffeeScript](#coffeescript)
+ - [Civet](#civet)
- [Less](#less)
- [PostCSS, SugarSS](#postcss-sugarss)
- [Pug](#pug)
@@ -96,6 +97,7 @@ export default {
babel: { ... },
postcss: { ... },
coffeescript: { ... },
+ civet: { ... },
pug: { ... },
}),
}),
@@ -203,6 +205,7 @@ import {
pug,
coffeescript,
typescript,
+ civet,
less,
scss,
sass,
@@ -221,6 +224,7 @@ export default {
pug({ ... }),
coffeescript({ ... }),
typescript({ ... }),
+ civet({ ... }),
less({ ... }),
scss({ ... }),
sass({ ... }),
@@ -256,6 +260,10 @@ _Note: If you want to transpile your app to be supported in older browsers, you
The CoffeeScript processor accepts no extra options and only transpiles CoffeeScript code down to esm compliant JavaScript code.
+### Civet
+
+The Civet processor accepts no extra options and only transpiles Civet code down to esm compliant JavaScript code.
+
### Less
You can check the [Less API reference](http://lesscss.org/usage/#less-options) for Less specific options.
diff --git a/package.json b/package.json
index 01dc94aa..7d31aafd 100644
--- a/package.json
+++ b/package.json
@@ -62,6 +62,7 @@
"@babel/preset-env": "^7.23.6",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
+ "@danielx/civet": "^0.6.83",
"@kiwi/eslint-config": "^2.0.2",
"@kiwi/prettier-config": "^2.0.2",
"@types/babel__core": "^7.20.5",
@@ -98,6 +99,7 @@
},
"peerDependencies": {
"@babel/core": "^7.10.2",
+ "@danielx/civet": "^0.6.83",
"coffeescript": "^2.5.1",
"less": "^3.11.3 || ^4.0.0",
"postcss": "^7 || ^8",
@@ -113,6 +115,9 @@
"@babel/core": {
"optional": true
},
+ "@danielx/civet": {
+ "optional": true
+ },
"coffeescript": {
"optional": true
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bcc98704..d5a2e393 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -34,6 +34,9 @@ devDependencies:
'@commitlint/config-conventional':
specifier: ^11.0.0
version: 11.0.0
+ '@danielx/civet':
+ specifier: ^0.6.83
+ version: 0.6.83(typescript@5.0.2)
'@kiwi/eslint-config':
specifier: ^2.0.2
version: 2.0.2(eslint@8.29.0)(jest@29.5.0)(prettier@2.8.1)(svelte@3.54.0)(typescript@5.0.2)
@@ -1596,6 +1599,28 @@ packages:
engines: {node: '>=v10.22.0'}
dev: true
+ /@cspotcode/source-map-support@0.8.1:
+ resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}
+ engines: {node: '>=12'}
+ dependencies:
+ '@jridgewell/trace-mapping': 0.3.9
+ dev: true
+
+ /@danielx/civet@0.6.83(typescript@5.0.2):
+ resolution: {integrity: sha512-QtrR8oiMOa4Eia5Ef1o9FcmWM5JOAxS/+1M/sKk8tVmgzfngv3sPIitUgLblXph4pvB7wz6Vha+gEihRJpIYBA==}
+ engines: {node: '>=19 || ^18.6.0 || ^16.17.0'}
+ hasBin: true
+ peerDependencies:
+ typescript: ^4.5 || ^5.0
+ dependencies:
+ '@cspotcode/source-map-support': 0.8.1
+ '@typescript/vfs': 1.5.0
+ typescript: 5.0.2
+ unplugin: 1.8.1
+ transitivePeerDependencies:
+ - supports-color
+ dev: true
+
/@eslint/eslintrc@1.3.3:
resolution: {integrity: sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
@@ -1899,7 +1924,6 @@ packages:
/@jridgewell/sourcemap-codec@1.4.15:
resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==}
- dev: false
/@jridgewell/trace-mapping@0.3.17:
resolution: {integrity: sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g==}
@@ -1908,6 +1932,13 @@ packages:
'@jridgewell/sourcemap-codec': 1.4.14
dev: true
+ /@jridgewell/trace-mapping@0.3.9:
+ resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==}
+ dependencies:
+ '@jridgewell/resolve-uri': 3.1.0
+ '@jridgewell/sourcemap-codec': 1.4.15
+ dev: true
+
/@kiwi/eslint-config@2.0.2(eslint@8.29.0)(jest@29.5.0)(prettier@2.8.1)(svelte@3.54.0)(typescript@5.0.2):
resolution: {integrity: sha512-MVH1R5nI4GFoN6/pEl6Pz+WYE+71V8ENX6MtC51/8O9eKq+hX1yJvBXXR55FVvv37F/cmV7KpoE8ebGzAgx/QQ==}
peerDependencies:
@@ -2247,6 +2278,14 @@ packages:
eslint-visitor-keys: 3.3.0
dev: true
+ /@typescript/vfs@1.5.0:
+ resolution: {integrity: sha512-AJS307bPgbsZZ9ggCT3wwpg3VbTKMFNHfaY/uF0ahSkYYrPF2dSSKDNIDIQAHm9qJqbLvCsSJH7yN4Vs/CsMMg==}
+ dependencies:
+ debug: 4.3.4
+ transitivePeerDependencies:
+ - supports-color
+ dev: true
+
/JSONStream@1.3.5:
resolution: {integrity: sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==}
hasBin: true
@@ -2269,6 +2308,12 @@ packages:
hasBin: true
dev: true
+ /acorn@8.11.3:
+ resolution: {integrity: sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==}
+ engines: {node: '>=0.4.0'}
+ hasBin: true
+ dev: true
+
/acorn@8.8.1:
resolution: {integrity: sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==}
engines: {node: '>=0.4.0'}
@@ -2932,6 +2977,21 @@ packages:
fsevents: 2.3.3
dev: true
+ /chokidar@3.6.0:
+ resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==}
+ engines: {node: '>= 8.10.0'}
+ dependencies:
+ anymatch: 3.1.3
+ braces: 3.0.2
+ glob-parent: 5.1.2
+ is-binary-path: 2.1.0
+ is-glob: 4.0.3
+ normalize-path: 3.0.0
+ readdirp: 3.6.0
+ optionalDependencies:
+ fsevents: 2.3.3
+ dev: true
+
/ci-info@3.7.0:
resolution: {integrity: sha512-2CpRNYmImPx+RXKLq6jko/L07phmS9I02TyqkcNU20GCF/GgaWvc58hPtjxDX8lPpkdwc9sNh72V9k00S7ezog==}
engines: {node: '>=8'}
@@ -6960,6 +7020,15 @@ packages:
engines: {node: '>= 10.0.0'}
dev: true
+ /unplugin@1.8.1:
+ resolution: {integrity: sha512-NDAvOEnZmeSRRmjfD0FoLzfve2/9lqceO5bR4J/2V72zphnFdq7UYo3fg6F1y1HfZEaSHa+7bZgbEN+z5x8ZDQ==}
+ dependencies:
+ acorn: 8.11.3
+ chokidar: 3.6.0
+ webpack-sources: 3.2.3
+ webpack-virtual-modules: 0.6.1
+ dev: true
+
/update-browserslist-db@1.0.13(browserslist@4.22.2):
resolution: {integrity: sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==}
hasBin: true
@@ -7024,6 +7093,15 @@ packages:
makeerror: 1.0.12
dev: true
+ /webpack-sources@3.2.3:
+ resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
+ engines: {node: '>=10.13.0'}
+ dev: true
+
+ /webpack-virtual-modules@0.6.1:
+ resolution: {integrity: sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==}
+ dev: true
+
/which-boxed-primitive@1.0.2:
resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==}
dependencies:
diff --git a/src/index.ts b/src/index.ts
index baa7f302..5554f564 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -10,6 +10,7 @@ export default exports = module.exports = sveltePreprocess;
export { default as pug } from './processors/pug';
export { default as coffeescript } from './processors/coffeescript';
export { default as typescript } from './processors/typescript';
+export { default as civet } from './processors/civet';
export { default as less } from './processors/less';
export { default as scss, default as sass } from './processors/scss';
export { default as stylus } from './processors/stylus';
diff --git a/src/modules/language.ts b/src/modules/language.ts
index 67481f8b..d2105fb8 100644
--- a/src/modules/language.ts
+++ b/src/modules/language.ts
@@ -15,6 +15,9 @@ const LANGUAGE_DEFAULTS: Record = {
coffeescript: {
stripIndent: true,
},
+ civet: {
+ stripIndent: true,
+ },
stylus: {
stripIndent: true,
},
@@ -36,6 +39,7 @@ export const ALIAS_MAP = new Map([
['js', 'javascript'],
['coffee', 'coffeescript'],
['ts', 'typescript'],
+ ['civet', 'civet'],
]);
export const SOURCE_MAP_PROP_MAP: Record = {
diff --git a/src/processors/civet.ts b/src/processors/civet.ts
new file mode 100644
index 00000000..5b6b7792
--- /dev/null
+++ b/src/processors/civet.ts
@@ -0,0 +1,38 @@
+import { getTagInfo } from '../modules/tagInfo';
+import { concat } from '../modules/utils';
+import { prepareContent } from '../modules/prepareContent';
+
+import type { PreprocessorGroup, Options } from '../types';
+
+export default (options?: Options.Civet): PreprocessorGroup => ({
+ async script(svelteFile) {
+ const { transformer } = await import('../transformers/civet');
+
+ let { content, filename, attributes, lang, dependencies } =
+ await getTagInfo(svelteFile);
+
+ if (lang !== 'civet') {
+ return { code: content };
+ }
+
+ content = prepareContent({
+ options: {
+ ...options,
+ stripIndent: true,
+ },
+ content,
+ });
+
+ const transformed = await transformer({
+ content,
+ filename,
+ attributes,
+ options,
+ });
+
+ return {
+ ...transformed,
+ dependencies: concat(dependencies, transformed.dependencies),
+ };
+ },
+});
diff --git a/src/transformers/civet.ts b/src/transformers/civet.ts
new file mode 100644
index 00000000..9c453564
--- /dev/null
+++ b/src/transformers/civet.ts
@@ -0,0 +1,27 @@
+import civet from '@danielx/civet';
+
+import type { Transformer, Options } from '../types';
+
+const transformer: Transformer = ({
+ content,
+ filename,
+ options,
+}) => {
+ const civetOptions = {
+ filename,
+ js: false,
+ ...options,
+ } as Omit;
+
+ if (civetOptions.sourceMap) {
+ const compiledTS = civet.compile(content, civetOptions);
+
+ const map = JSON.parse(compiledTS);
+
+ return { code: compiledTS, map };
+ }
+
+ return { code: civet.compile(content, civetOptions) };
+};
+
+export { transformer };
diff --git a/src/types/options.ts b/src/types/options.ts
index a12d4c0b..b00e0038 100644
--- a/src/types/options.ts
+++ b/src/types/options.ts
@@ -2,6 +2,7 @@ import type { LegacyStringOptions } from 'sass';
import type * as postcss from 'postcss';
import type { Options as PugOptions } from 'pug';
import type { TransformOptions as BabelOptions } from '@babel/core';
+import type { ParseOptions } from '@danielx/civet';
type ContentModifier = {
prependData?: string;
@@ -18,6 +19,13 @@ export type Coffeescript = {
bare?: never;
} & ContentModifier;
+export type Civet = {
+ filename?: string;
+ js?: boolean;
+ sourceMap?: boolean;
+ parseOptions?: ParseOptions;
+} & ContentModifier;
+
export type Postcss = postcss.ProcessOptions & {
plugins?: postcss.AcceptedPlugin[];
// custom
diff --git a/test/fixtures/script.civet b/test/fixtures/script.civet
new file mode 100644
index 00000000..6e4a4411
--- /dev/null
+++ b/test/fixtures/script.civet
@@ -0,0 +1 @@
+export hello = 'world';
diff --git a/test/processors/civet.test.ts b/test/processors/civet.test.ts
new file mode 100644
index 00000000..197e64b4
--- /dev/null
+++ b/test/processors/civet.test.ts
@@ -0,0 +1,47 @@
+import { civet } from '../../src';
+import { getFixtureContent, preprocess } from '../utils';
+
+const EXPECTED_SCRIPT = getFixtureContent('script.js');
+
+describe(`processor - civet`, () => {
+ it('should ignore other languages', async () => {
+ const template = ``;
+ const options = {};
+
+ const preprocessed = await preprocess(template, [civet(options)]);
+
+ expect(preprocessed.toString?.()).toBe(template);
+ });
+
+ it('should leave other languages untouched', async () => {
+ const template = ``;
+ const options = {
+ stripIndent: true,
+ prependData: '/* potato */',
+ };
+
+ const preprocessed = await preprocess(template, [civet(options)]);
+
+ expect(preprocessed.toString?.()).toBe(template);
+ });
+
+ it('should support external src files', async () => {
+ const template = ``;
+ const options = {};
+
+ const preprocessed = await preprocess(template, [civet(options)]);
+
+ expect(preprocessed.toString?.()).toContain(EXPECTED_SCRIPT);
+ });
+
+ it('should support prepended data', async () => {
+ const template = ``;
+ const options = {
+ prependData: '### potato ###',
+ };
+
+ const preprocessed = await preprocess(template, [civet(options)]);
+
+ expect(preprocessed.toString?.()).toContain('/* potato */');
+ });
+});