Skip to content

Commit 0ef1625

Browse files
authored
feat: remove experimental.generateMissingPreprocessorSourcemaps (#514)
1 parent 1c780ce commit 0ef1625

File tree

8 files changed

+9
-180
lines changed

8 files changed

+9
-180
lines changed

.changeset/funny-dryers-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
remove experimental.generateMissingPreprocessorSourcemaps

docs/config.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,6 @@ export default {
251251

252252
Use extra preprocessors that delegate style and TypeScript preprocessing to native Vite plugins. TypeScript will be transformed with esbuild. Styles will be transformed using [Vite's CSS plugin](https://vitejs.dev/guide/features.html#css), which handles `@imports`, `url()` references, PostCSS, CSS Modules, and `.scss`/`.sass`/`.less`/`.styl`/`.stylus` files. Do not use together with TypeScript or style preprocessors from `svelte-preprocess` as attempts to transform the content twice will fail!
253253

254-
### generateMissingPreprocessorSourcemaps
255-
256-
- **Type:** `boolean`
257-
- **Default:** `false`
258-
259-
If a preprocessor does not provide a sourcemap, a best-effort fallback sourcemap will be provided. This option requires [diff-match-patch](https://github.com/google/diff-match-patch) to be installed as a peer dependency.
260-
261254
### dynamicCompileOptions
262255

263256
- **Type:**

packages/vite-plugin-svelte/package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,11 @@
5353
"vitefu": "^0.2.2"
5454
},
5555
"peerDependencies": {
56-
"diff-match-patch": "^1.0.5",
5756
"svelte": "^3.44.0",
5857
"vite": "^3.0.0"
5958
},
60-
"peerDependenciesMeta": {
61-
"diff-match-patch": {
62-
"optional": true
63-
}
64-
},
6559
"devDependencies": {
6660
"@types/debug": "^4.1.7",
67-
"@types/diff-match-patch": "^1.0.32",
68-
"diff-match-patch": "^1.0.5",
6961
"esbuild": "^0.15.16",
7062
"rollup": "^2.79.1",
7163
"svelte": "^3.53.1",

packages/vite-plugin-svelte/src/utils/__tests__/sourcemap.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/vite-plugin-svelte/src/utils/options.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ function handleDeprecatedOptions(options: ResolvedOptions) {
315315
'experimental.prebundleSvelteLibraries is no longer experimental and has moved to prebundleSvelteLibraries'
316316
);
317317
}
318+
if ((options.experimental as any)?.generateMissingPreprocessorSourcemaps) {
319+
log.warn('experimental.generateMissingPreprocessorSourcemaps has been removed.');
320+
}
318321
}
319322

320323
// vite passes unresolved `root`option to config hook but we need the resolved value, so do it here
@@ -693,15 +696,6 @@ export interface ExperimentalOptions {
693696
*/
694697
useVitePreprocess?: boolean;
695698

696-
/**
697-
* If a preprocessor does not provide a sourcemap, a best-effort fallback sourcemap will be provided.
698-
* This option requires `diff-match-patch` to be installed as a peer dependency.
699-
*
700-
* @see https://github.com/google/diff-match-patch
701-
* @default false
702-
*/
703-
generateMissingPreprocessorSourcemaps?: boolean;
704-
705699
/**
706700
* A function to update `compilerOptions` before compilation
707701
*

packages/vite-plugin-svelte/src/utils/preprocess.ts

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { ResolvedConfig, Plugin } from 'vite';
22
import MagicString from 'magic-string';
33
import { preprocess } from 'svelte/compiler';
4-
import { PreprocessorGroup, Processed, ResolvedOptions } from './options';
4+
import { PreprocessorGroup, ResolvedOptions } from './options';
55
import { log } from './log';
6-
import { buildSourceMap } from './sourcemap';
76
import path from 'path';
87
import { vitePreprocess } from '../preprocess';
98

@@ -117,67 +116,4 @@ export function addExtraPreprocessors(options: ResolvedOptions, config: Resolved
117116
options.preprocess = [...prependPreprocessors, options.preprocess, ...appendPreprocessors];
118117
}
119118
}
120-
const generateMissingSourceMaps = !!options.experimental?.generateMissingPreprocessorSourcemaps;
121-
if (options.preprocess && generateMissingSourceMaps) {
122-
options.preprocess = Array.isArray(options.preprocess)
123-
? options.preprocess.map((p, i) => validateSourceMapOutputWrapper(p, i))
124-
: validateSourceMapOutputWrapper(options.preprocess, 0);
125-
}
126-
}
127-
128-
function validateSourceMapOutputWrapper(group: PreprocessorGroup, i: number): PreprocessorGroup {
129-
const wrapper: PreprocessorGroup = {};
130-
131-
for (const [processorType, processorFn] of Object.entries(group) as Array<
132-
// eslint-disable-next-line no-unused-vars
133-
[keyof PreprocessorGroup, (options: { filename?: string; content: string }) => Processed]
134-
>) {
135-
wrapper[processorType] = async (options) => {
136-
const result = await processorFn(options);
137-
138-
if (result && result.code !== options.content) {
139-
let invalidMap = false;
140-
if (!result.map) {
141-
invalidMap = true;
142-
log.warn.enabled &&
143-
log.warn.once(
144-
`preprocessor at index ${i} did not return a sourcemap for ${processorType} transform`,
145-
{
146-
filename: options.filename,
147-
type: processorType,
148-
processor: processorFn.toString()
149-
}
150-
);
151-
} else if ((result.map as any)?.mappings === '') {
152-
invalidMap = true;
153-
log.warn.enabled &&
154-
log.warn.once(
155-
`preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
156-
{
157-
filename: options.filename,
158-
type: processorType,
159-
processor: processorFn.toString()
160-
}
161-
);
162-
}
163-
if (invalidMap) {
164-
try {
165-
const map = await buildSourceMap(options.content, result.code, options.filename);
166-
if (map) {
167-
log.debug.enabled &&
168-
log.debug(
169-
`adding generated sourcemap to preprocesor result for ${options.filename}`
170-
);
171-
result.map = map;
172-
}
173-
} catch (e) {
174-
log.error(`failed to build sourcemap`, e);
175-
}
176-
}
177-
}
178-
return result;
179-
};
180-
}
181-
182-
return wrapper;
183119
}

packages/vite-plugin-svelte/src/utils/sourcemap.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)