vite 5.0.0-beta.0 → 5.0.0-beta.2

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.
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { C as colors, D as bindShortcuts, x as createLogger, h as resolveConfig } from './chunks/dep-4033fb3a.js';
5
+ import { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-82f73734.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -31,13 +31,13 @@ import 'node:assert';
31
31
  import 'node:process';
32
32
  import 'node:v8';
33
33
  import 'rollup';
34
- import 'worker_threads';
35
34
  import 'node:http';
36
35
  import 'node:https';
37
36
  import 'zlib';
38
37
  import 'buffer';
39
38
  import 'https';
40
39
  import 'tls';
40
+ import 'worker_threads';
41
41
  import 'querystring';
42
42
  import 'node:readline';
43
43
  import 'node:zlib';
@@ -723,9 +723,20 @@ const convertHost = (v) => {
723
723
  }
724
724
  return v;
725
725
  };
726
+ /**
727
+ * base may be a number (like 0), should convert to empty string
728
+ */
729
+ const convertBase = (v) => {
730
+ if (v === 0) {
731
+ return '';
732
+ }
733
+ return v;
734
+ };
726
735
  cli
727
736
  .option('-c, --config <file>', `[string] use specified config file`)
728
- .option('--base <path>', `[string] public base path (default: /)`)
737
+ .option('--base <path>', `[string] public base path (default: /)`, {
738
+ type: [convertBase],
739
+ })
729
740
  .option('-l, --logLevel <level>', `[string] info | warn | error | silent`)
730
741
  .option('--clearScreen', `[boolean] allow/disable clear screen when logging`)
731
742
  .option('-d, --debug [feat]', `[string | boolean] show debug logs`)
@@ -747,7 +758,7 @@ cli
747
758
  filterDuplicateOptions(options);
748
759
  // output structure is preserved even after bundling so require()
749
760
  // is ok here
750
- const { createServer } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.I; });
761
+ const { createServer } = await import('./chunks/dep-82f73734.js').then(function (n) { return n.H; });
751
762
  try {
752
763
  const server = await createServer({
753
764
  root,
@@ -770,7 +781,7 @@ cli
770
781
  : '';
771
782
  info(`\n ${colors.green(`${colors.bold('VITE')} v${VERSION}`)} ${startupDurationString}\n`, { clear: !server.config.logger.hasWarned });
772
783
  server.printUrls();
773
- bindShortcuts(server, {
784
+ server.bindCLIShortcuts({
774
785
  print: true,
775
786
  customShortcuts: [
776
787
  profileSession && {
@@ -825,7 +836,7 @@ cli
825
836
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
826
837
  .action(async (root, options) => {
827
838
  filterDuplicateOptions(options);
828
- const { build } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.H; });
839
+ const { build } = await import('./chunks/dep-82f73734.js').then(function (n) { return n.G; });
829
840
  const buildOptions = cleanOptions(options);
830
841
  try {
831
842
  await build({
@@ -853,7 +864,7 @@ cli
853
864
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
854
865
  .action(async (root, options) => {
855
866
  filterDuplicateOptions(options);
856
- const { optimizeDeps } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.G; });
867
+ const { optimizeDeps } = await import('./chunks/dep-82f73734.js').then(function (n) { return n.F; });
857
868
  try {
858
869
  const config = await resolveConfig({
859
870
  root,
@@ -880,7 +891,7 @@ cli
880
891
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
881
892
  .action(async (root, options) => {
882
893
  filterDuplicateOptions(options);
883
- const { preview } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.J; });
894
+ const { preview } = await import('./chunks/dep-82f73734.js').then(function (n) { return n.I; });
884
895
  try {
885
896
  const server = await preview({
886
897
  root,
@@ -900,7 +911,7 @@ cli
900
911
  },
901
912
  });
902
913
  server.printUrls();
903
- bindShortcuts(server, { print: true });
914
+ server.bindCLIShortcuts({ print: true });
904
915
  }
905
916
  catch (e) {
906
917
  createLogger(options.logLevel).error(colors.red(`error when starting preview server:\n${e.stack}`), { error: e });
@@ -2,12 +2,10 @@
2
2
 
3
3
  import type { Agent } from 'node:http';
4
4
  import type { BuildOptions as BuildOptions_2 } from 'esbuild';
5
- import type { BundleAsyncOptions } from 'lightningcss';
6
5
  import { ChunkMetadata } from "../../types/metadata.js";
7
6
  import type { ClientRequest } from 'node:http';
8
7
  import type { ClientRequestArgs } from 'node:http';
9
8
  import { ConnectedPayload } from "../../types/hmrPayload.js";
10
- import type { CustomAtRules } from 'lightningcss';
11
9
  import { CustomEventMap } from "../../types/customEvent.js";
12
10
  import { CustomPayload } from "../../types/hmrPayload.js";
13
11
  import type { CustomPluginOptions } from 'rollup';
@@ -121,6 +119,14 @@ export declare interface AwaitWriteFinishOptions {
121
119
  pollInterval?: number
122
120
  }
123
121
 
122
+ export declare type BindCLIShortcutsOptions<Server = ViteDevServer | PreviewServer> = {
123
+ /**
124
+ * Print a one line hint to the terminal.
125
+ */
126
+ print?: boolean;
127
+ customShortcuts?: (CLIShortcut<Server> | undefined | null)[];
128
+ };
129
+
124
130
  /**
125
131
  * Bundles the app for production.
126
132
  * Returns a Promise containing the build result.
@@ -290,7 +296,6 @@ export declare interface BuildOptions {
290
296
  ssrManifest?: boolean | string;
291
297
  /**
292
298
  * Emit assets during SSR.
293
- * @experimental
294
299
  * @default false
295
300
  */
296
301
  ssrEmitAssets?: boolean;
@@ -315,6 +320,12 @@ export declare interface BuildOptions {
315
320
 
316
321
  export { ChunkMetadata }
317
322
 
323
+ export declare type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
324
+ key: string;
325
+ description: string;
326
+ action(server: Server): void | Promise<void>;
327
+ };
328
+
318
329
  export declare interface CommonServerOptions {
319
330
  /**
320
331
  * Specify server port. Note if the port is already being used, Vite will
@@ -511,6 +522,13 @@ export declare function createLogger(level?: LogLevel, options?: LoggerOptions):
511
522
 
512
523
  export declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
513
524
 
525
+ declare interface CSSModulesConfig {
526
+ /** The pattern to use when renaming class names and other identifiers. Default is `[hash]_[local]`. */
527
+ pattern?: string,
528
+ /** Whether to rename dashed identifiers, e.g. custom properties. */
529
+ dashedIdents?: boolean
530
+ }
531
+
514
532
  export declare interface CSSModulesOptions {
515
533
  getJSON?: (cssFileName: string, json: Record<string, string>, outputFileName: string) => void;
516
534
  scopeBehaviour?: 'global' | 'local';
@@ -709,6 +727,13 @@ export declare interface DepsOptimizer {
709
727
  options: DepOptimizationOptions;
710
728
  }
711
729
 
730
+ declare interface Drafts {
731
+ /** Whether to enable CSS nesting. */
732
+ nesting?: boolean,
733
+ /** Whether to enable @custom-media rules. */
734
+ customMedia?: boolean
735
+ }
736
+
712
737
  export { ErrorPayload }
713
738
 
714
739
  export declare interface ESBuildOptions extends EsbuildTransformOptions {
@@ -766,6 +791,32 @@ export declare type ExportsData = {
766
791
  jsxLoader?: boolean;
767
792
  };
768
793
 
794
+ declare const enum Features {
795
+ Nesting = 1,
796
+ NotSelectorList = 2,
797
+ DirSelector = 4,
798
+ LangSelectorList = 8,
799
+ IsSelector = 16,
800
+ TextDecorationThicknessPercent = 32,
801
+ MediaIntervalSyntax = 64,
802
+ MediaRangeSyntax = 128,
803
+ CustomMediaQueries = 256,
804
+ ClampFunction = 512,
805
+ ColorFunction = 1024,
806
+ OklabColors = 2048,
807
+ LabColors = 4096,
808
+ P3Colors = 8192,
809
+ HexAlphaColors = 16384,
810
+ SpaceSeparatedColorNotation = 32768,
811
+ FontFamilySystemUi = 65536,
812
+ DoublePositionGradients = 131072,
813
+ VendorPrefixes = 262144,
814
+ LogicalProperties = 524288,
815
+ Selectors = 31,
816
+ MediaQueries = 448,
817
+ Colors = 64512,
818
+ }
819
+
769
820
  export declare interface FileSystemServeOptions {
770
821
  /**
771
822
  * Strictly restrict file accessing outside of allowing paths.
@@ -1281,7 +1332,20 @@ export declare interface LibraryOptions {
1281
1332
  fileName?: string | ((format: ModuleFormat, entryName: string) => string);
1282
1333
  }
1283
1334
 
1284
- export declare type LightningCSSOptions = Omit<BundleAsyncOptions<CustomAtRules>, 'filename' | 'resolver' | 'minify' | 'sourceMap' | 'analyzeDependencies'>;
1335
+ /**
1336
+ * Options are spread, so you can also use options that are not typed here like
1337
+ * visitor (not exposed because it would impact too much the bundle size)
1338
+ */
1339
+ export declare type LightningCSSOptions = {
1340
+ targets?: Targets
1341
+ include?: Features
1342
+ exclude?: Features
1343
+ drafts?: Drafts
1344
+ nonStandard?: NonStandard
1345
+ pseudoClasses?: PseudoClasses
1346
+ unusedSymbols?: string[]
1347
+ cssModules?: CSSModulesConfig
1348
+ }
1285
1349
 
1286
1350
  export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel): Promise<{
1287
1351
  path: string;
@@ -1418,6 +1482,11 @@ export declare interface ModulePreloadOptions {
1418
1482
  resolveDependencies?: ResolveModulePreloadDependenciesFn;
1419
1483
  }
1420
1484
 
1485
+ declare interface NonStandard {
1486
+ /** Whether to enable the non-standard >>> and /deep/ selector combinators used by Angular and Vue. */
1487
+ deepSelectorCombinator?: boolean
1488
+ }
1489
+
1421
1490
  export declare function normalizePath(id: string): string;
1422
1491
 
1423
1492
  export declare interface OptimizedDepInfo {
@@ -1516,7 +1585,7 @@ declare interface Plugin_2 extends Plugin_3 {
1516
1585
  * Note: User plugins are resolved before running this hook so injecting other
1517
1586
  * plugins inside the `config` hook will have no effect.
1518
1587
  */
1519
- config?: ObjectHook<(this: void, config: UserConfig, env: ConfigEnv) => UserConfig | null | void | Promise<UserConfig | null | void>>;
1588
+ config?: ObjectHook<(this: void, config: UserConfig, env: ConfigEnv) => Omit<UserConfig, 'plugins'> | null | void | Promise<Omit<UserConfig, 'plugins'> | null | void>>;
1520
1589
  /**
1521
1590
  * Use this hook to read and store the final resolved vite config.
1522
1591
  */
@@ -1673,6 +1742,10 @@ export declare interface PreviewServer {
1673
1742
  * Print server urls
1674
1743
  */
1675
1744
  printUrls(): void;
1745
+ /**
1746
+ * Bind CLI shortcuts
1747
+ */
1748
+ bindCLIShortcuts(options?: BindCLIShortcutsOptions<PreviewServer>): void;
1676
1749
  }
1677
1750
 
1678
1751
  export declare type PreviewServerHook = (this: void, server: PreviewServer) => (() => void) | void | Promise<(() => void) | void>;
@@ -1694,6 +1767,14 @@ export declare interface ProxyOptions extends HttpProxy.ServerOptions {
1694
1767
 
1695
1768
  export { PrunePayload }
1696
1769
 
1770
+ declare interface PseudoClasses {
1771
+ hover?: string,
1772
+ active?: string,
1773
+ focus?: string,
1774
+ focusVisible?: string,
1775
+ focusWithin?: string
1776
+ }
1777
+
1697
1778
  export declare type RenderBuiltAssetUrl = (filename: string, type: {
1698
1779
  type: 'asset' | 'public';
1699
1780
  hostId: string;
@@ -2206,6 +2287,18 @@ export declare interface SSROptions {
2206
2287
 
2207
2288
  export declare type SSRTarget = 'node' | 'webworker';
2208
2289
 
2290
+ declare interface Targets {
2291
+ android?: number,
2292
+ chrome?: number,
2293
+ edge?: number,
2294
+ firefox?: number,
2295
+ ie?: number,
2296
+ ios_saf?: number,
2297
+ opera?: number,
2298
+ safari?: number,
2299
+ samsung?: number
2300
+ }
2301
+
2209
2302
  export declare namespace Terser {
2210
2303
  export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
2211
2304
 
@@ -2694,6 +2787,10 @@ export declare interface ViteDevServer {
2694
2787
  * Print server urls
2695
2788
  */
2696
2789
  printUrls(): void;
2790
+ /**
2791
+ * Bind CLI shortcuts
2792
+ */
2793
+ bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
2697
2794
  /**
2698
2795
  * Restart the server.
2699
2796
  *
@@ -1,5 +1,5 @@
1
- import { i as isInNodeModules } from './chunks/dep-4033fb3a.js';
2
- export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-4033fb3a.js';
1
+ import { i as isInNodeModules } from './chunks/dep-82f73734.js';
2
+ export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-82f73734.js';
3
3
  export { VERSION as version } from './constants.js';
4
4
  export { version as esbuildVersion } from 'esbuild';
5
5
  export { VERSION as rollupVersion } from 'rollup';
@@ -32,13 +32,13 @@ import 'module';
32
32
  import 'node:assert';
33
33
  import 'node:process';
34
34
  import 'node:v8';
35
- import 'worker_threads';
36
35
  import 'node:http';
37
36
  import 'node:https';
38
37
  import 'zlib';
39
38
  import 'buffer';
40
39
  import 'https';
41
40
  import 'tls';
41
+ import 'worker_threads';
42
42
  import 'querystring';
43
43
  import 'node:readline';
44
44
  import 'node:zlib';
@@ -1228,7 +1228,7 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
1228
1228
  }
1229
1229
 
1230
1230
  var srcExports = src.exports;
1231
- var debug$1 = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
1231
+ var debug$2 = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
1232
1232
 
1233
1233
  var utils$3 = {};
1234
1234
 
@@ -3385,7 +3385,7 @@ const _require = node_module.createRequire((typeof document === 'undefined' ? re
3385
3385
  const filter = process.env.VITE_DEBUG_FILTER;
3386
3386
  const DEBUG = process.env.DEBUG;
3387
3387
  function createDebugger(namespace, options = {}) {
3388
- const log = debug$1(namespace);
3388
+ const log = debug$2(namespace);
3389
3389
  const { onlyWhenFocused } = options;
3390
3390
  let enabled = log.enabled;
3391
3391
  if (enabled && onlyWhenFocused) {
@@ -3423,6 +3423,12 @@ function fsPathFromId(id) {
3423
3423
  function fsPathFromUrl(url) {
3424
3424
  return fsPathFromId(cleanUrl(url));
3425
3425
  }
3426
+ function withTrailingSlash(path) {
3427
+ if (path[path.length - 1] !== '/') {
3428
+ return `${path}/`;
3429
+ }
3430
+ return path;
3431
+ }
3426
3432
  /**
3427
3433
  * Check if dir is a parent of file
3428
3434
  *
@@ -3433,9 +3439,7 @@ function fsPathFromUrl(url) {
3433
3439
  * @returns true if dir is a parent of file
3434
3440
  */
3435
3441
  function isParentDirectory(dir, file) {
3436
- if (dir[dir.length - 1] !== '/') {
3437
- dir = `${dir}/`;
3438
- }
3442
+ dir = withTrailingSlash(dir);
3439
3443
  return (file.startsWith(dir) ||
3440
3444
  (isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase())));
3441
3445
  }
@@ -3700,6 +3704,245 @@ function splitVendorChunkPlugin() {
3700
3704
  };
3701
3705
  }
3702
3706
 
3707
+ var convertSourceMap$1 = {};
3708
+
3709
+ (function (exports) {
3710
+
3711
+ Object.defineProperty(exports, 'commentRegex', {
3712
+ get: function getCommentRegex () {
3713
+ // Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.
3714
+ return /^\s*?\/[\/\*][@#]\s+?sourceMappingURL=data:(((?:application|text)\/json)(?:;charset=([^;,]+?)?)?)?(?:;(base64))?,(.*?)$/mg;
3715
+ }
3716
+ });
3717
+
3718
+
3719
+ Object.defineProperty(exports, 'mapFileCommentRegex', {
3720
+ get: function getMapFileCommentRegex () {
3721
+ // Matches sourceMappingURL in either // or /* comment styles.
3722
+ return /(?:\/\/[@#][ \t]+?sourceMappingURL=([^\s'"`]+?)[ \t]*?$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*?(?:\*\/){1}[ \t]*?$)/mg;
3723
+ }
3724
+ });
3725
+
3726
+ var decodeBase64;
3727
+ if (typeof Buffer !== 'undefined') {
3728
+ if (typeof Buffer.from === 'function') {
3729
+ decodeBase64 = decodeBase64WithBufferFrom;
3730
+ } else {
3731
+ decodeBase64 = decodeBase64WithNewBuffer;
3732
+ }
3733
+ } else {
3734
+ decodeBase64 = decodeBase64WithAtob;
3735
+ }
3736
+
3737
+ function decodeBase64WithBufferFrom(base64) {
3738
+ return Buffer.from(base64, 'base64').toString();
3739
+ }
3740
+
3741
+ function decodeBase64WithNewBuffer(base64) {
3742
+ if (typeof value === 'number') {
3743
+ throw new TypeError('The value to decode must not be of type number.');
3744
+ }
3745
+ return new Buffer(base64, 'base64').toString();
3746
+ }
3747
+
3748
+ function decodeBase64WithAtob(base64) {
3749
+ return decodeURIComponent(escape(atob(base64)));
3750
+ }
3751
+
3752
+ function stripComment(sm) {
3753
+ return sm.split(',').pop();
3754
+ }
3755
+
3756
+ function readFromFileMap(sm, read) {
3757
+ var r = exports.mapFileCommentRegex.exec(sm);
3758
+ // for some odd reason //# .. captures in 1 and /* .. */ in 2
3759
+ var filename = r[1] || r[2];
3760
+
3761
+ try {
3762
+ var sm = read(filename);
3763
+ if (sm != null && typeof sm.catch === 'function') {
3764
+ return sm.catch(throwError);
3765
+ } else {
3766
+ return sm;
3767
+ }
3768
+ } catch (e) {
3769
+ throwError(e);
3770
+ }
3771
+
3772
+ function throwError(e) {
3773
+ throw new Error('An error occurred while trying to read the map file at ' + filename + '\n' + e.stack);
3774
+ }
3775
+ }
3776
+
3777
+ function Converter (sm, opts) {
3778
+ opts = opts || {};
3779
+
3780
+ if (opts.hasComment) {
3781
+ sm = stripComment(sm);
3782
+ }
3783
+
3784
+ if (opts.encoding === 'base64') {
3785
+ sm = decodeBase64(sm);
3786
+ } else if (opts.encoding === 'uri') {
3787
+ sm = decodeURIComponent(sm);
3788
+ }
3789
+
3790
+ if (opts.isJSON || opts.encoding) {
3791
+ sm = JSON.parse(sm);
3792
+ }
3793
+
3794
+ this.sourcemap = sm;
3795
+ }
3796
+
3797
+ Converter.prototype.toJSON = function (space) {
3798
+ return JSON.stringify(this.sourcemap, null, space);
3799
+ };
3800
+
3801
+ if (typeof Buffer !== 'undefined') {
3802
+ if (typeof Buffer.from === 'function') {
3803
+ Converter.prototype.toBase64 = encodeBase64WithBufferFrom;
3804
+ } else {
3805
+ Converter.prototype.toBase64 = encodeBase64WithNewBuffer;
3806
+ }
3807
+ } else {
3808
+ Converter.prototype.toBase64 = encodeBase64WithBtoa;
3809
+ }
3810
+
3811
+ function encodeBase64WithBufferFrom() {
3812
+ var json = this.toJSON();
3813
+ return Buffer.from(json, 'utf8').toString('base64');
3814
+ }
3815
+
3816
+ function encodeBase64WithNewBuffer() {
3817
+ var json = this.toJSON();
3818
+ if (typeof json === 'number') {
3819
+ throw new TypeError('The json to encode must not be of type number.');
3820
+ }
3821
+ return new Buffer(json, 'utf8').toString('base64');
3822
+ }
3823
+
3824
+ function encodeBase64WithBtoa() {
3825
+ var json = this.toJSON();
3826
+ return btoa(unescape(encodeURIComponent(json)));
3827
+ }
3828
+
3829
+ Converter.prototype.toURI = function () {
3830
+ var json = this.toJSON();
3831
+ return encodeURIComponent(json);
3832
+ };
3833
+
3834
+ Converter.prototype.toComment = function (options) {
3835
+ var encoding, content, data;
3836
+ if (options != null && options.encoding === 'uri') {
3837
+ encoding = '';
3838
+ content = this.toURI();
3839
+ } else {
3840
+ encoding = ';base64';
3841
+ content = this.toBase64();
3842
+ }
3843
+ data = 'sourceMappingURL=data:application/json;charset=utf-8' + encoding + ',' + content;
3844
+ return options != null && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
3845
+ };
3846
+
3847
+ // returns copy instead of original
3848
+ Converter.prototype.toObject = function () {
3849
+ return JSON.parse(this.toJSON());
3850
+ };
3851
+
3852
+ Converter.prototype.addProperty = function (key, value) {
3853
+ if (this.sourcemap.hasOwnProperty(key)) throw new Error('property "' + key + '" already exists on the sourcemap, use set property instead');
3854
+ return this.setProperty(key, value);
3855
+ };
3856
+
3857
+ Converter.prototype.setProperty = function (key, value) {
3858
+ this.sourcemap[key] = value;
3859
+ return this;
3860
+ };
3861
+
3862
+ Converter.prototype.getProperty = function (key) {
3863
+ return this.sourcemap[key];
3864
+ };
3865
+
3866
+ exports.fromObject = function (obj) {
3867
+ return new Converter(obj);
3868
+ };
3869
+
3870
+ exports.fromJSON = function (json) {
3871
+ return new Converter(json, { isJSON: true });
3872
+ };
3873
+
3874
+ exports.fromURI = function (uri) {
3875
+ return new Converter(uri, { encoding: 'uri' });
3876
+ };
3877
+
3878
+ exports.fromBase64 = function (base64) {
3879
+ return new Converter(base64, { encoding: 'base64' });
3880
+ };
3881
+
3882
+ exports.fromComment = function (comment) {
3883
+ var m, encoding;
3884
+ comment = comment
3885
+ .replace(/^\/\*/g, '//')
3886
+ .replace(/\*\/$/g, '');
3887
+ m = exports.commentRegex.exec(comment);
3888
+ encoding = m && m[4] || 'uri';
3889
+ return new Converter(comment, { encoding: encoding, hasComment: true });
3890
+ };
3891
+
3892
+ function makeConverter(sm) {
3893
+ return new Converter(sm, { isJSON: true });
3894
+ }
3895
+
3896
+ exports.fromMapFileComment = function (comment, read) {
3897
+ if (typeof read === 'string') {
3898
+ throw new Error(
3899
+ 'String directory paths are no longer supported with `fromMapFileComment`\n' +
3900
+ 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
3901
+ )
3902
+ }
3903
+
3904
+ var sm = readFromFileMap(comment, read);
3905
+ if (sm != null && typeof sm.then === 'function') {
3906
+ return sm.then(makeConverter);
3907
+ } else {
3908
+ return makeConverter(sm);
3909
+ }
3910
+ };
3911
+
3912
+ // Finds last sourcemap comment in file or returns null if none was found
3913
+ exports.fromSource = function (content) {
3914
+ var m = content.match(exports.commentRegex);
3915
+ return m ? exports.fromComment(m.pop()) : null;
3916
+ };
3917
+
3918
+ // Finds last sourcemap comment in file or returns null if none was found
3919
+ exports.fromMapFileSource = function (content, read) {
3920
+ if (typeof read === 'string') {
3921
+ throw new Error(
3922
+ 'String directory paths are no longer supported with `fromMapFileSource`\n' +
3923
+ 'Please review the Upgrading documentation at https://github.com/thlorenz/convert-source-map#upgrading'
3924
+ )
3925
+ }
3926
+ var m = content.match(exports.mapFileCommentRegex);
3927
+ return m ? exports.fromMapFileComment(m.pop(), read) : null;
3928
+ };
3929
+
3930
+ exports.removeComments = function (src) {
3931
+ return src.replace(exports.commentRegex, '');
3932
+ };
3933
+
3934
+ exports.removeMapFileComments = function (src) {
3935
+ return src.replace(exports.mapFileCommentRegex, '');
3936
+ };
3937
+
3938
+ exports.generateMapFileComment = function (file, options) {
3939
+ var data = 'sourceMappingURL=' + file;
3940
+ return options && options.multiline ? '/*# ' + data + ' */' : '//# ' + data;
3941
+ };
3942
+ } (convertSourceMap$1));
3943
+
3944
+ var convertSourceMap = /*@__PURE__*/getDefaultExportFromCjs(convertSourceMap$1);
3945
+
3703
3946
  /*!
3704
3947
  * etag
3705
3948
  * Copyright(c) 2014-2016 Douglas Christopher Wilson
@@ -4012,7 +4255,7 @@ function getBtoa() {
4012
4255
  }
4013
4256
  }
4014
4257
 
4015
- const btoa = /*#__PURE__*/ getBtoa();
4258
+ const btoa$1 = /*#__PURE__*/ getBtoa();
4016
4259
 
4017
4260
  class SourceMap {
4018
4261
  constructor(properties) {
@@ -4032,7 +4275,7 @@ class SourceMap {
4032
4275
  }
4033
4276
 
4034
4277
  toUrl() {
4035
- return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
4278
+ return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
4036
4279
  }
4037
4280
  }
4038
4281
 
@@ -4999,7 +5242,7 @@ class MagicString {
4999
5242
  }
5000
5243
  }
5001
5244
 
5002
- const debug = createDebugger('vite:sourcemap', {
5245
+ const debug$1 = createDebugger('vite:sourcemap', {
5003
5246
  onlyWhenFocused: true,
5004
5247
  });
5005
5248
  function genSourceMapUrl(map) {
@@ -5009,7 +5252,7 @@ function genSourceMapUrl(map) {
5009
5252
  return `data:application/json;base64,${Buffer.from(map).toString('base64')}`;
5010
5253
  }
5011
5254
  function getCodeWithSourcemap(type, code, map) {
5012
- if (debug) {
5255
+ if (debug$1) {
5013
5256
  code += `\n/*${JSON.stringify(map, null, 2).replace(/\*\//g, '*\\/')}*/\n`;
5014
5257
  }
5015
5258
  if (type === 'js') {
@@ -5021,6 +5264,9 @@ function getCodeWithSourcemap(type, code, map) {
5021
5264
  return code;
5022
5265
  }
5023
5266
 
5267
+ const debug = createDebugger('vite:send', {
5268
+ onlyWhenFocused: true,
5269
+ });
5024
5270
  const alias = {
5025
5271
  js: 'application/javascript',
5026
5272
  css: 'text/css',
@@ -5051,11 +5297,22 @@ function send(req, res, content, type, options) {
5051
5297
  content = getCodeWithSourcemap(type, content.toString(), map);
5052
5298
  }
5053
5299
  }
5054
- else {
5055
- if (type === 'js' && (!map || map.mappings !== '')) {
5300
+ // inject fallback sourcemap for js for improved debugging
5301
+ // https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
5302
+ else if (type === 'js' && (!map || map.mappings !== '')) {
5303
+ const code = content.toString();
5304
+ // if the code has existing inline sourcemap, assume it's correct and skip
5305
+ if (convertSourceMap.mapFileCommentRegex.test(code)) {
5306
+ debug?.(`Skipped injecting fallback sourcemap for ${req.url}`);
5307
+ }
5308
+ else {
5056
5309
  const urlWithoutTimestamp = removeTimestampQuery(req.url);
5057
- const ms = new MagicString(content.toString());
5058
- content = getCodeWithSourcemap(type, content.toString(), ms.generateMap({ source: urlWithoutTimestamp, hires: 'boundary' }));
5310
+ const ms = new MagicString(code);
5311
+ content = getCodeWithSourcemap(type, code, ms.generateMap({
5312
+ source: path$3.basename(urlWithoutTimestamp),
5313
+ hires: 'boundary',
5314
+ includeContent: true,
5315
+ }));
5059
5316
  }
5060
5317
  }
5061
5318
  res.statusCode = 200;