vite 5.3.0-beta.1 → 5.3.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.
@@ -1,4 +1,4 @@
1
- import { B as getDefaultExportFromCjs } from './dep-Dz0We6of.js';
1
+ import { B as getDefaultExportFromCjs } from './dep-DxsHXWQ1.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-IQS-Za7F.js';
package/dist/node/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path';
2
- import fs from 'node:fs';
2
+ import fs__default from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-Dz0We6of.js';
5
+ import { A as colors, v as createLogger, r as resolveConfig } from './chunks/dep-DxsHXWQ1.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -12,7 +12,9 @@ import 'tty';
12
12
  import 'path';
13
13
  import 'esbuild';
14
14
  import 'fs';
15
- import 'assert';
15
+ import 'node:events';
16
+ import 'node:stream';
17
+ import 'node:string_decoder';
16
18
  import 'node:child_process';
17
19
  import 'node:http';
18
20
  import 'node:https';
@@ -33,13 +35,13 @@ import 'node:v8';
33
35
  import 'node:worker_threads';
34
36
  import 'node:buffer';
35
37
  import 'rollup/parseAst';
36
- import 'node:events';
37
38
  import 'querystring';
38
39
  import 'node:readline';
39
40
  import 'zlib';
40
41
  import 'buffer';
41
42
  import 'https';
42
43
  import 'tls';
44
+ import 'assert';
43
45
  import 'node:zlib';
44
46
 
45
47
  function toArr(any) {
@@ -655,269 +657,258 @@ class CAC extends EventEmitter {
655
657
 
656
658
  const cac = (name = "") => new CAC(name);
657
659
 
658
- const cli = cac('vite');
660
+ const cli = cac("vite");
659
661
  let profileSession = global.__vite_profile_session;
660
662
  let profileCount = 0;
661
663
  const stopProfiler = (log) => {
662
- if (!profileSession)
663
- return;
664
- return new Promise((res, rej) => {
665
- profileSession.post('Profiler.stop', (err, { profile }) => {
666
- // Write profile to disk, upload, etc.
667
- if (!err) {
668
- const outPath = path.resolve(`./vite-profile-${profileCount++}.cpuprofile`);
669
- fs.writeFileSync(outPath, JSON.stringify(profile));
670
- log(colors.yellow(`CPU profile written to ${colors.white(colors.dim(outPath))}`));
671
- profileSession = undefined;
672
- res();
673
- }
674
- else {
675
- rej(err);
676
- }
677
- });
664
+ if (!profileSession) return;
665
+ return new Promise((res, rej) => {
666
+ profileSession.post("Profiler.stop", (err, { profile }) => {
667
+ if (!err) {
668
+ const outPath = path.resolve(
669
+ `./vite-profile-${profileCount++}.cpuprofile`
670
+ );
671
+ fs__default.writeFileSync(outPath, JSON.stringify(profile));
672
+ log(
673
+ colors.yellow(
674
+ `CPU profile written to ${colors.white(colors.dim(outPath))}`
675
+ )
676
+ );
677
+ profileSession = void 0;
678
+ res();
679
+ } else {
680
+ rej(err);
681
+ }
678
682
  });
683
+ });
679
684
  };
680
685
  const filterDuplicateOptions = (options) => {
681
- for (const [key, value] of Object.entries(options)) {
682
- if (Array.isArray(value)) {
683
- options[key] = value[value.length - 1];
684
- }
686
+ for (const [key, value] of Object.entries(options)) {
687
+ if (Array.isArray(value)) {
688
+ options[key] = value[value.length - 1];
685
689
  }
690
+ }
686
691
  };
687
- /**
688
- * removing global flags before passing as command specific sub-configs
689
- */
690
692
  function cleanOptions(options) {
691
- const ret = { ...options };
692
- delete ret['--'];
693
- delete ret.c;
694
- delete ret.config;
695
- delete ret.base;
696
- delete ret.l;
697
- delete ret.logLevel;
698
- delete ret.clearScreen;
699
- delete ret.d;
700
- delete ret.debug;
701
- delete ret.f;
702
- delete ret.filter;
703
- delete ret.m;
704
- delete ret.mode;
705
- // convert the sourcemap option to a boolean if necessary
706
- if ('sourcemap' in ret) {
707
- const sourcemap = ret.sourcemap;
708
- ret.sourcemap =
709
- sourcemap === 'true'
710
- ? true
711
- : sourcemap === 'false'
712
- ? false
713
- : ret.sourcemap;
714
- }
715
- return ret;
693
+ const ret = { ...options };
694
+ delete ret["--"];
695
+ delete ret.c;
696
+ delete ret.config;
697
+ delete ret.base;
698
+ delete ret.l;
699
+ delete ret.logLevel;
700
+ delete ret.clearScreen;
701
+ delete ret.d;
702
+ delete ret.debug;
703
+ delete ret.f;
704
+ delete ret.filter;
705
+ delete ret.m;
706
+ delete ret.mode;
707
+ if ("sourcemap" in ret) {
708
+ const sourcemap = ret.sourcemap;
709
+ ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;
710
+ }
711
+ return ret;
716
712
  }
717
- /**
718
- * host may be a number (like 0), should convert to string
719
- */
720
713
  const convertHost = (v) => {
721
- if (typeof v === 'number') {
722
- return String(v);
723
- }
724
- return v;
714
+ if (typeof v === "number") {
715
+ return String(v);
716
+ }
717
+ return v;
725
718
  };
726
- /**
727
- * base may be a number (like 0), should convert to empty string
728
- */
729
719
  const convertBase = (v) => {
730
- if (v === 0) {
731
- return '';
732
- }
733
- return v;
720
+ if (v === 0) {
721
+ return "";
722
+ }
723
+ return v;
734
724
  };
735
- cli
736
- .option('-c, --config <file>', `[string] use specified config file`)
737
- .option('--base <path>', `[string] public base path (default: /)`, {
738
- type: [convertBase],
739
- })
740
- .option('-l, --logLevel <level>', `[string] info | warn | error | silent`)
741
- .option('--clearScreen', `[boolean] allow/disable clear screen when logging`)
742
- .option('-d, --debug [feat]', `[string | boolean] show debug logs`)
743
- .option('-f, --filter <filter>', `[string] filter debug logs`)
744
- .option('-m, --mode <mode>', `[string] set env mode`);
745
- // dev
746
- cli
747
- .command('[root]', 'start dev server') // default command
748
- .alias('serve') // the command is called 'serve' in Vite's API
749
- .alias('dev') // alias to align with the script name
750
- .option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
751
- .option('--port <port>', `[number] specify port`)
752
- .option('--open [path]', `[boolean | string] open browser on startup`)
753
- .option('--cors', `[boolean] enable CORS`)
754
- .option('--strictPort', `[boolean] exit if specified port is already in use`)
755
- .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
756
- .action(async (root, options) => {
757
- filterDuplicateOptions(options);
758
- // output structure is preserved even after bundling so require()
759
- // is ok here
760
- const { createServer } = await import('./chunks/dep-Dz0We6of.js').then(function (n) { return n.E; });
761
- try {
762
- const server = await createServer({
763
- root,
764
- base: options.base,
765
- mode: options.mode,
766
- configFile: options.config,
767
- logLevel: options.logLevel,
768
- clearScreen: options.clearScreen,
769
- optimizeDeps: { force: options.force },
770
- server: cleanOptions(options),
771
- });
772
- if (!server.httpServer) {
773
- throw new Error('HTTP server not available');
774
- }
775
- await server.listen();
776
- const info = server.config.logger.info;
777
- const viteStartTime = global.__vite_start_time ?? false;
778
- const startupDurationString = viteStartTime
779
- ? colors.dim(`ready in ${colors.reset(colors.bold(Math.ceil(performance.now() - viteStartTime)))} ms`)
780
- : '';
781
- const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
782
- info(`\n ${colors.green(`${colors.bold('VITE')} v${VERSION}`)} ${startupDurationString}\n`, {
783
- clear: !hasExistingLogs,
784
- });
785
- server.printUrls();
786
- const customShortcuts = [];
787
- if (profileSession) {
788
- customShortcuts.push({
789
- key: 'p',
790
- description: 'start/stop the profiler',
791
- async action(server) {
792
- if (profileSession) {
793
- await stopProfiler(server.config.logger.info);
794
- }
795
- else {
796
- const inspector = await import('node:inspector').then((r) => r.default);
797
- await new Promise((res) => {
798
- profileSession = new inspector.Session();
799
- profileSession.connect();
800
- profileSession.post('Profiler.enable', () => {
801
- profileSession.post('Profiler.start', () => {
802
- server.config.logger.info('Profiler started');
803
- res();
804
- });
805
- });
806
- });
807
- }
808
- },
725
+ cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
726
+ type: [convertBase]
727
+ }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
728
+ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--open [path]", `[boolean | string] open browser on startup`).option("--cors", `[boolean] enable CORS`).option("--strictPort", `[boolean] exit if specified port is already in use`).option(
729
+ "--force",
730
+ `[boolean] force the optimizer to ignore the cache and re-bundle`
731
+ ).action(async (root, options) => {
732
+ filterDuplicateOptions(options);
733
+ const { createServer } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.E; });
734
+ try {
735
+ const server = await createServer({
736
+ root,
737
+ base: options.base,
738
+ mode: options.mode,
739
+ configFile: options.config,
740
+ logLevel: options.logLevel,
741
+ clearScreen: options.clearScreen,
742
+ optimizeDeps: { force: options.force },
743
+ server: cleanOptions(options)
744
+ });
745
+ if (!server.httpServer) {
746
+ throw new Error("HTTP server not available");
747
+ }
748
+ await server.listen();
749
+ const info = server.config.logger.info;
750
+ const viteStartTime = global.__vite_start_time ?? false;
751
+ const startupDurationString = viteStartTime ? colors.dim(
752
+ `ready in ${colors.reset(
753
+ colors.bold(Math.ceil(performance.now() - viteStartTime))
754
+ )} ms`
755
+ ) : "";
756
+ const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
757
+ info(
758
+ `
759
+ ${colors.green(
760
+ `${colors.bold("VITE")} v${VERSION}`
761
+ )} ${startupDurationString}
762
+ `,
763
+ {
764
+ clear: !hasExistingLogs
765
+ }
766
+ );
767
+ server.printUrls();
768
+ const customShortcuts = [];
769
+ if (profileSession) {
770
+ customShortcuts.push({
771
+ key: "p",
772
+ description: "start/stop the profiler",
773
+ async action(server2) {
774
+ if (profileSession) {
775
+ await stopProfiler(server2.config.logger.info);
776
+ } else {
777
+ const inspector = await import('node:inspector').then(
778
+ (r) => r.default
779
+ );
780
+ await new Promise((res) => {
781
+ profileSession = new inspector.Session();
782
+ profileSession.connect();
783
+ profileSession.post("Profiler.enable", () => {
784
+ profileSession.post("Profiler.start", () => {
785
+ server2.config.logger.info("Profiler started");
786
+ res();
787
+ });
788
+ });
809
789
  });
790
+ }
810
791
  }
811
- server.bindCLIShortcuts({ print: true, customShortcuts });
812
- }
813
- catch (e) {
814
- const logger = createLogger(options.logLevel);
815
- logger.error(colors.red(`error when starting dev server:\n${e.stack}`), {
816
- error: e,
817
- });
818
- stopProfiler(logger.info);
819
- process.exit(1);
792
+ });
820
793
  }
794
+ server.bindCLIShortcuts({ print: true, customShortcuts });
795
+ } catch (e) {
796
+ const logger = createLogger(options.logLevel);
797
+ logger.error(colors.red(`error when starting dev server:
798
+ ${e.stack}`), {
799
+ error: e
800
+ });
801
+ stopProfiler(logger.info);
802
+ process.exit(1);
803
+ }
821
804
  });
822
- // build
823
- cli
824
- .command('build [root]', 'build for production')
825
- .option('--target <target>', `[string] transpile target (default: 'modules')`)
826
- .option('--outDir <dir>', `[string] output directory (default: dist)`)
827
- .option('--assetsDir <dir>', `[string] directory under outDir to place assets in (default: assets)`)
828
- .option('--assetsInlineLimit <number>', `[number] static asset base64 inline threshold in bytes (default: 4096)`)
829
- .option('--ssr [entry]', `[string] build specified entry for server-side rendering`)
830
- .option('--sourcemap [output]', `[boolean | "inline" | "hidden"] output source maps for build (default: false)`)
831
- .option('--minify [minifier]', `[boolean | "terser" | "esbuild"] enable/disable minification, ` +
832
- `or specify minifier to use (default: esbuild)`)
833
- .option('--manifest [name]', `[boolean | string] emit build manifest json`)
834
- .option('--ssrManifest [name]', `[boolean | string] emit ssr manifest json`)
835
- .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
836
- .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
837
- .action(async (root, options) => {
838
- filterDuplicateOptions(options);
839
- const { build } = await import('./chunks/dep-Dz0We6of.js').then(function (n) { return n.F; });
840
- const buildOptions = cleanOptions(options);
841
- try {
842
- await build({
843
- root,
844
- base: options.base,
845
- mode: options.mode,
846
- configFile: options.config,
847
- logLevel: options.logLevel,
848
- clearScreen: options.clearScreen,
849
- build: buildOptions,
850
- });
851
- }
852
- catch (e) {
853
- createLogger(options.logLevel).error(colors.red(`error during build:\n${e.stack}`), { error: e });
854
- process.exit(1);
855
- }
856
- finally {
857
- stopProfiler((message) => createLogger(options.logLevel).info(message));
858
- }
805
+ cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
806
+ "--assetsDir <dir>",
807
+ `[string] directory under outDir to place assets in (default: assets)`
808
+ ).option(
809
+ "--assetsInlineLimit <number>",
810
+ `[number] static asset base64 inline threshold in bytes (default: 4096)`
811
+ ).option(
812
+ "--ssr [entry]",
813
+ `[string] build specified entry for server-side rendering`
814
+ ).option(
815
+ "--sourcemap [output]",
816
+ `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
817
+ ).option(
818
+ "--minify [minifier]",
819
+ `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
820
+ ).option("--manifest [name]", `[boolean | string] emit build manifest json`).option("--ssrManifest [name]", `[boolean | string] emit ssr manifest json`).option(
821
+ "--emptyOutDir",
822
+ `[boolean] force empty outDir when it's outside of root`
823
+ ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {
824
+ filterDuplicateOptions(options);
825
+ const { build } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.F; });
826
+ const buildOptions = cleanOptions(options);
827
+ try {
828
+ await build({
829
+ root,
830
+ base: options.base,
831
+ mode: options.mode,
832
+ configFile: options.config,
833
+ logLevel: options.logLevel,
834
+ clearScreen: options.clearScreen,
835
+ build: buildOptions
836
+ });
837
+ } catch (e) {
838
+ createLogger(options.logLevel).error(
839
+ colors.red(`error during build:
840
+ ${e.stack}`),
841
+ { error: e }
842
+ );
843
+ process.exit(1);
844
+ } finally {
845
+ stopProfiler((message) => createLogger(options.logLevel).info(message));
846
+ }
859
847
  });
860
- // optimize
861
- cli
862
- .command('optimize [root]', 'pre-bundle dependencies')
863
- .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
864
- .action(async (root, options) => {
848
+ cli.command("optimize [root]", "pre-bundle dependencies").option(
849
+ "--force",
850
+ `[boolean] force the optimizer to ignore the cache and re-bundle`
851
+ ).action(
852
+ async (root, options) => {
865
853
  filterDuplicateOptions(options);
866
- const { optimizeDeps } = await import('./chunks/dep-Dz0We6of.js').then(function (n) { return n.D; });
854
+ const { optimizeDeps } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.D; });
867
855
  try {
868
- const config = await resolveConfig({
869
- root,
870
- base: options.base,
871
- configFile: options.config,
872
- logLevel: options.logLevel,
873
- mode: options.mode,
874
- }, 'serve');
875
- await optimizeDeps(config, options.force, true);
876
- }
877
- catch (e) {
878
- createLogger(options.logLevel).error(colors.red(`error when optimizing deps:\n${e.stack}`), { error: e });
879
- process.exit(1);
880
- }
881
- });
882
- // preview
883
- cli
884
- .command('preview [root]', 'locally preview production build')
885
- .option('--host [host]', `[string] specify hostname`, { type: [convertHost] })
886
- .option('--port <port>', `[number] specify port`)
887
- .option('--strictPort', `[boolean] exit if specified port is already in use`)
888
- .option('--open [path]', `[boolean | string] open browser on startup`)
889
- .option('--outDir <dir>', `[string] output directory (default: dist)`)
890
- .action(async (root, options) => {
856
+ const config = await resolveConfig(
857
+ {
858
+ root,
859
+ base: options.base,
860
+ configFile: options.config,
861
+ logLevel: options.logLevel,
862
+ mode: options.mode
863
+ },
864
+ "serve"
865
+ );
866
+ await optimizeDeps(config, options.force, true);
867
+ } catch (e) {
868
+ createLogger(options.logLevel).error(
869
+ colors.red(`error when optimizing deps:
870
+ ${e.stack}`),
871
+ { error: e }
872
+ );
873
+ process.exit(1);
874
+ }
875
+ }
876
+ );
877
+ cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
878
+ async (root, options) => {
891
879
  filterDuplicateOptions(options);
892
- const { preview } = await import('./chunks/dep-Dz0We6of.js').then(function (n) { return n.G; });
880
+ const { preview } = await import('./chunks/dep-DxsHXWQ1.js').then(function (n) { return n.G; });
893
881
  try {
894
- const server = await preview({
895
- root,
896
- base: options.base,
897
- configFile: options.config,
898
- logLevel: options.logLevel,
899
- mode: options.mode,
900
- build: {
901
- outDir: options.outDir,
902
- },
903
- preview: {
904
- port: options.port,
905
- strictPort: options.strictPort,
906
- host: options.host,
907
- open: options.open,
908
- },
909
- });
910
- server.printUrls();
911
- server.bindCLIShortcuts({ print: true });
912
- }
913
- catch (e) {
914
- createLogger(options.logLevel).error(colors.red(`error when starting preview server:\n${e.stack}`), { error: e });
915
- process.exit(1);
916
- }
917
- finally {
918
- stopProfiler((message) => createLogger(options.logLevel).info(message));
919
- }
920
- });
882
+ const server = await preview({
883
+ root,
884
+ base: options.base,
885
+ configFile: options.config,
886
+ logLevel: options.logLevel,
887
+ mode: options.mode,
888
+ build: {
889
+ outDir: options.outDir
890
+ },
891
+ preview: {
892
+ port: options.port,
893
+ strictPort: options.strictPort,
894
+ host: options.host,
895
+ open: options.open
896
+ }
897
+ });
898
+ server.printUrls();
899
+ server.bindCLIShortcuts({ print: true });
900
+ } catch (e) {
901
+ createLogger(options.logLevel).error(
902
+ colors.red(`error when starting preview server:
903
+ ${e.stack}`),
904
+ { error: e }
905
+ );
906
+ process.exit(1);
907
+ } finally {
908
+ stopProfiler((message) => createLogger(options.logLevel).info(message));
909
+ }
910
+ }
911
+ );
921
912
  cli.help();
922
913
  cli.version(VERSION);
923
914
  cli.parse();