From 5aaeee8ee299d3a2667b297657f45da214cc9540 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 14 Jun 2024 11:05:20 +0200 Subject: [PATCH 1/3] fix: deprecate default export in favor of named export This deprecates the default export in favor of the new named export `sveltePreprocess`. It's done to ensure a better interop between CJS and ESM without resorting to hacks in the future. It also enables people using `"module": "NodeNext"` in their `tsconfig.json` to import without type errors. The sub exports were also adjusted so that the transpiled TS output doesn't include `__importDefault` wrappers, which makes Node's static analysis miss those named exports. --- README.md | 10 ++++----- docs/getting-started.md | 15 ++++++-------- docs/migration-guide.md | 6 ++++++ docs/preprocessing.md | 16 +++++++-------- docs/usage.md | 15 +++++++------- src/index.ts | 28 +++++++++++++++----------- src/processors/babel.ts | 7 ++++++- src/processors/coffeescript.ts | 7 ++++++- src/processors/globalStyle.ts | 7 ++++++- src/processors/less.ts | 7 ++++++- src/processors/postcss.ts | 5 ++++- src/processors/pug.ts | 7 ++++++- src/processors/replace.ts | 7 ++++++- src/processors/scss.ts | 7 ++++++- src/processors/stylus.ts | 7 ++++++- src/processors/typescript.ts | 7 ++++++- test/autoProcess/autoProcess.test.ts | 2 +- test/autoProcess/externalFiles.test.ts | 2 +- test/autoProcess/markup.test.ts | 2 +- test/autoProcess/script.test.ts | 2 +- test/autoProcess/sourceMaps.test.ts | 2 +- test/autoProcess/style.test.ts | 2 +- test/transformers/babel.test.ts | 2 +- test/transformers/less.test.ts | 2 +- test/transformers/postcss.test.ts | 2 +- test/transformers/pug.test.ts | 2 +- test/transformers/scss.test.ts | 2 +- test/transformers/stylus.test.ts | 2 +- test/transformers/typescript.test.ts | 2 +- 29 files changed, 118 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index a4ac2d6f..f94ceaba 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,10 @@ Writing your own preprocessor for, i.e SCSS is easy enough, but it can be cumber It is recommended to use with `svelte.config.js` file, located at the project root. For other usage, please refer to [usage documentation](#usage-documentation). ```js -import preprocess from 'svelte-preprocess'; +import { sveltePreprocess } from 'svelte-preprocess'; const config = { - preprocess: preprocess({ ... }) + preprocess: sveltePreprocess({ ... }) } export default config; @@ -121,9 +121,9 @@ _**Note**: needs PostCSS to be installed._ For example, with `@babel/preset-env` your config could be: ```js -import preprocess from 'svelte-preprocess' +import { sveltePreprocess } from 'svelte-preprocess' ... - preprocess: preprocess({ + preprocess: sveltePreprocess({ babel: { presets: [ [ @@ -169,7 +169,7 @@ Which, in a production environment, would turn into ```svelte -{#if "production" !== 'development'} +{#if 'production' !== 'development'}

Production environment!

{/if} ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index 9465c175..99d1570e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -43,7 +43,7 @@ Let's use `svelte-preprocess` in [auto-preprocessing mode](/docs/preprocessing.m ```diff import svelte from 'rollup-plugin-svelte' -+ import sveltePreprocess from 'svelte-preprocess'; ++ import { sveltePreprocess } from 'svelte-preprocess'; const production = !process.env.ROLLUP_WATCH @@ -88,7 +88,7 @@ After the installation is complete, we still need to configure our PostCSS optio ```diff import svelte from 'rollup-plugin-svelte' -import sveltePreprocess from 'svelte-preprocess'; +import { sveltePreprocess } from 'svelte-preprocess'; + import typescript from '@rollup/plugin-typescript'; const production = !process.env.ROLLUP_WATCH @@ -126,9 +126,7 @@ export default { And we're done! Our components can now be written as: ```html - +