@sveltejs/vite-plugin-svelte 1.0.0-next.35 → 1.0.0-next.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { RollupError } from 'rollup';
2
- import { Warning } from './options';
2
+ import { ResolvedOptions, Warning } from './options';
3
3
  import { buildExtendedLogMessage } from './log';
4
4
  import { PartialMessage } from 'esbuild';
5
5
 
@@ -8,15 +8,15 @@ import { PartialMessage } from 'esbuild';
8
8
  * @param error a svelte compiler error, which is a mix of Warning and an error
9
9
  * @returns {RollupError} the converted error
10
10
  */
11
- export function toRollupError(error: Warning & Error): RollupError {
12
- const { filename, frame, start, code, name } = error;
11
+ export function toRollupError(error: Warning & Error, options: ResolvedOptions): RollupError {
12
+ const { filename, frame, start, code, name, stack } = error;
13
13
  const rollupError: RollupError = {
14
14
  name, // needed otherwise sveltekit coalesce_to_error turns it into a string
15
15
  id: filename,
16
16
  message: buildExtendedLogMessage(error), // include filename:line:column so that it's clickable
17
17
  frame: formatFrameForVite(frame),
18
18
  code,
19
- stack: ''
19
+ stack: options.isBuild || options.isDebug || !frame ? stack : ''
20
20
  };
21
21
  if (start) {
22
22
  rollupError.loc = {
@@ -33,8 +33,8 @@ export function toRollupError(error: Warning & Error): RollupError {
33
33
  * @param error a svelte compiler error, which is a mix of Warning and an error
34
34
  * @returns {PartialMessage} the converted error
35
35
  */
36
- export function toESBuildError(error: Warning & Error): PartialMessage {
37
- const { filename, frame, start } = error;
36
+ export function toESBuildError(error: Warning & Error, options: ResolvedOptions): PartialMessage {
37
+ const { filename, frame, start, stack } = error;
38
38
  const partialMessage: PartialMessage = {
39
39
  text: buildExtendedLogMessage(error)
40
40
  };
@@ -46,6 +46,9 @@ export function toESBuildError(error: Warning & Error): PartialMessage {
46
46
  lineText: lineFromFrame(start.line, frame) // needed to get a meaningful error message on cli
47
47
  };
48
48
  }
49
+ if (options.isBuild || options.isDebug || !frame) {
50
+ partialMessage.detail = stack;
51
+ }
49
52
  return partialMessage;
50
53
  }
51
54
 
@@ -27,7 +27,7 @@ export function esbuildSveltePlugin(options: ResolvedOptions): EsbuildPlugin {
27
27
  const contents = await compileSvelte(options, { filename, code });
28
28
  return { contents };
29
29
  } catch (e) {
30
- return { errors: [toESBuildError(e)] };
30
+ return { errors: [toESBuildError(e, options)] };
31
31
  }
32
32
  });
33
33
  }
@@ -73,7 +73,12 @@ async function compileSvelte(
73
73
  let preprocessed;
74
74
 
75
75
  if (options.preprocess) {
76
- preprocessed = await preprocess(code, options.preprocess, { filename });
76
+ try {
77
+ preprocessed = await preprocess(code, options.preprocess, { filename });
78
+ } catch (e) {
79
+ e.message = `Error while preprocessing ${filename}${e.message ? ` - ${e.message}` : ''}`;
80
+ throw e;
81
+ }
77
82
  if (preprocessed.map) compileOptions.sourcemap = preprocessed.map;
78
83
  }
79
84
 
package/src/utils/log.ts CHANGED
@@ -164,7 +164,10 @@ export function buildExtendedLogMessage(w: Warning) {
164
164
  parts.push(':', w.start.line, ':', w.start.column);
165
165
  }
166
166
  if (w.message) {
167
- parts.push(' ', w.message);
167
+ if (parts.length > 0) {
168
+ parts.push(' ');
169
+ }
170
+ parts.push(w.message);
168
171
  }
169
172
  return parts.join('');
170
173
  }
@@ -82,7 +82,8 @@ export async function preResolveOptions(
82
82
  // extras
83
83
  root: viteConfigWithResolvedRoot.root!,
84
84
  isBuild: viteEnv.command === 'build',
85
- isServe: viteEnv.command === 'serve'
85
+ isServe: viteEnv.command === 'serve',
86
+ isDebug: process.env.DEBUG != null
86
87
  };
87
88
  // configFile of svelteConfig contains the absolute path it was loaded from,
88
89
  // prefer it over the possibly relative inline path
@@ -491,6 +492,7 @@ export interface PreResolvedOptions extends Options {
491
492
  root: string;
492
493
  isBuild: boolean;
493
494
  isServe: boolean;
495
+ isDebug: boolean;
494
496
  }
495
497
 
496
498
  export interface ResolvedOptions extends PreResolvedOptions {