@rsbuild/core 0.0.28 → 1.0.0

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.
Files changed (59) hide show
  1. package/compiled/dotenv/index.js +1 -0
  2. package/compiled/dotenv/lib/main.d.ts +156 -0
  3. package/compiled/dotenv/license +23 -0
  4. package/compiled/dotenv/package.json +1 -0
  5. package/compiled/dotenv-expand/index.js +1 -0
  6. package/compiled/dotenv-expand/lib/main.d.ts +29 -0
  7. package/compiled/dotenv-expand/license +24 -0
  8. package/compiled/dotenv-expand/package.json +1 -0
  9. package/dist/cli/commands.d.ts +7 -1
  10. package/dist/cli/commands.js +33 -20
  11. package/dist/cli/config.js +28 -16
  12. package/dist/cli/prepare.js +1 -1
  13. package/dist/loadEnv.d.ts +5 -0
  14. package/dist/loadEnv.js +58 -0
  15. package/dist/plugins/asset.js +1 -1
  16. package/dist/plugins/bundleAnalyzer.js +1 -1
  17. package/dist/plugins/cache.js +1 -1
  18. package/dist/plugins/cleanOutput.js +1 -1
  19. package/dist/plugins/define.js +1 -1
  20. package/dist/plugins/devtool.js +1 -1
  21. package/dist/plugins/entry.js +1 -1
  22. package/dist/plugins/externals.js +1 -1
  23. package/dist/plugins/fileSize.js +1 -1
  24. package/dist/plugins/html.js +1 -1
  25. package/dist/plugins/inlineChunk.js +8 -12
  26. package/dist/plugins/moment.js +1 -1
  27. package/dist/plugins/nodeAddons.js +1 -1
  28. package/dist/plugins/performance.js +1 -1
  29. package/dist/plugins/splitChunks.js +1 -1
  30. package/dist/plugins/startUrl.js +1 -1
  31. package/dist/plugins/target.js +1 -1
  32. package/dist/plugins/toml.js +1 -1
  33. package/dist/plugins/wasm.js +1 -1
  34. package/dist/plugins/yaml.js +1 -1
  35. package/dist/rspack-provider/core/createContext.js +1 -1
  36. package/dist/rspack-provider/plugins/basic.js +1 -1
  37. package/dist/rspack-provider/plugins/css.js +1 -1
  38. package/dist/rspack-provider/plugins/hmr.js +1 -1
  39. package/dist/rspack-provider/plugins/less.js +1 -1
  40. package/dist/rspack-provider/plugins/minimize.js +1 -1
  41. package/dist/rspack-provider/plugins/output.js +1 -1
  42. package/dist/rspack-provider/plugins/progress.js +1 -1
  43. package/dist/rspack-provider/plugins/resolve.js +1 -1
  44. package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
  45. package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
  46. package/dist/rspack-provider/plugins/sass.js +1 -1
  47. package/dist/rspack-provider/plugins/swc.js +1 -1
  48. package/dist/rspack-provider/plugins/transition.js +1 -1
  49. package/dist/server/dev-middleware/index.js +1 -1
  50. package/dist/server/devServer.js +8 -9
  51. package/dist/server/middlewares.d.ts +2 -1
  52. package/dist/server/middlewares.js +23 -11
  53. package/dist/server/prodServer.d.ts +6 -3
  54. package/dist/server/prodServer.js +52 -11
  55. package/dist/server/proxy.d.ts +4 -3
  56. package/dist/server/restart.js +4 -1
  57. package/package.json +4 -4
  58. package/dist/server/https.d.ts +0 -6
  59. package/dist/server/https.js +0 -50
@@ -0,0 +1 @@
1
+ (()=>{var e={194:(e,t,r)=>{const o=r(147);const n=r(17);const s=r(37);const c=r(113);const a=r(684);const i=a.version;const u=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;function parse(e){const t={};let r=e.toString();r=r.replace(/\r\n?/gm,"\n");let o;while((o=u.exec(r))!=null){const e=o[1];let r=o[2]||"";r=r.trim();const n=r[0];r=r.replace(/^(['"`])([\s\S]*)\1$/gm,"$2");if(n==='"'){r=r.replace(/\\n/g,"\n");r=r.replace(/\\r/g,"\r")}t[e]=r}return t}function _parseVault(e){const t=_vaultPath(e);const r=l.configDotenv({path:t});if(!r.parsed){throw new Error(`MISSING_DATA: Cannot parse ${t} for an unknown reason`)}const o=_dotenvKey(e).split(",");const n=o.length;let s;for(let e=0;e<n;e++){try{const t=o[e].trim();const n=_instructions(r,t);s=l.decrypt(n.ciphertext,n.key);break}catch(t){if(e+1>=n){throw t}}}return l.parse(s)}function _log(e){console.log(`[dotenv@${i}][INFO] ${e}`)}function _warn(e){console.log(`[dotenv@${i}][WARN] ${e}`)}function _debug(e){console.log(`[dotenv@${i}][DEBUG] ${e}`)}function _dotenvKey(e){if(e&&e.DOTENV_KEY&&e.DOTENV_KEY.length>0){return e.DOTENV_KEY}if(process.env.DOTENV_KEY&&process.env.DOTENV_KEY.length>0){return process.env.DOTENV_KEY}return""}function _instructions(e,t){let r;try{r=new URL(t)}catch(e){if(e.code==="ERR_INVALID_URL"){throw new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development")}throw e}const o=r.password;if(!o){throw new Error("INVALID_DOTENV_KEY: Missing key part")}const n=r.searchParams.get("environment");if(!n){throw new Error("INVALID_DOTENV_KEY: Missing environment part")}const s=`DOTENV_VAULT_${n.toUpperCase()}`;const c=e.parsed[s];if(!c){throw new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${s} in your .env.vault file.`)}return{ciphertext:c,key:o}}function _vaultPath(e){let t=n.resolve(process.cwd(),".env");if(e&&e.path&&e.path.length>0){t=e.path}return t.endsWith(".vault")?t:`${t}.vault`}function _resolveHome(e){return e[0]==="~"?n.join(s.homedir(),e.slice(1)):e}function _configVault(e){_log("Loading env from encrypted .env.vault");const t=l._parseVault(e);let r=process.env;if(e&&e.processEnv!=null){r=e.processEnv}l.populate(r,t,e);return{parsed:t}}function configDotenv(e){let t=n.resolve(process.cwd(),".env");let r="utf8";const s=Boolean(e&&e.debug);if(e){if(e.path!=null){t=_resolveHome(e.path)}if(e.encoding!=null){r=e.encoding}}try{const n=l.parse(o.readFileSync(t,{encoding:r}));let s=process.env;if(e&&e.processEnv!=null){s=e.processEnv}l.populate(s,n,e);return{parsed:n}}catch(e){if(s){_debug(`Failed to load ${t} ${e.message}`)}return{error:e}}}function config(e){const t=_vaultPath(e);if(_dotenvKey(e).length===0){return l.configDotenv(e)}if(!o.existsSync(t)){_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${t}. Did you forget to build it?`);return l.configDotenv(e)}return l._configVault(e)}function decrypt(e,t){const r=Buffer.from(t.slice(-64),"hex");let o=Buffer.from(e,"base64");const n=o.slice(0,12);const s=o.slice(-16);o=o.slice(12,-16);try{const e=c.createDecipheriv("aes-256-gcm",r,n);e.setAuthTag(s);return`${e.update(o)}${e.final()}`}catch(e){const t=e instanceof RangeError;const r=e.message==="Invalid key length";const o=e.message==="Unsupported state or unable to authenticate data";if(t||r){const e="INVALID_DOTENV_KEY: It must be 64 characters long (or more)";throw new Error(e)}else if(o){const e="DECRYPTION_FAILED: Please check your DOTENV_KEY";throw new Error(e)}else{console.error("Error: ",e.code);console.error("Error: ",e.message);throw e}}}function populate(e,t,r={}){const o=Boolean(r&&r.debug);const n=Boolean(r&&r.override);if(typeof t!=="object"){throw new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate")}for(const r of Object.keys(t)){if(Object.prototype.hasOwnProperty.call(e,r)){if(n===true){e[r]=t[r]}if(o){if(n===true){_debug(`"${r}" is already defined and WAS overwritten`)}else{_debug(`"${r}" is already defined and was NOT overwritten`)}}}else{e[r]=t[r]}}}const l={configDotenv:configDotenv,_configVault:_configVault,_parseVault:_parseVault,config:config,decrypt:decrypt,parse:parse,populate:populate};e.exports.configDotenv=l.configDotenv;e.exports._configVault=l._configVault;e.exports._parseVault=l._parseVault;e.exports.config=l.config;e.exports.decrypt=l.decrypt;e.exports.parse=l.parse;e.exports.populate=l.populate;e.exports=l},684:e=>{"use strict";e.exports=require("./package.json")},113:e=>{"use strict";e.exports=require("crypto")},147:e=>{"use strict";e.exports=require("fs")},37:e=>{"use strict";e.exports=require("os")},17:e=>{"use strict";e.exports=require("path")}};var t={};function __nccwpck_require__(r){var o=t[r];if(o!==undefined){return o.exports}var n=t[r]={exports:{}};var s=true;try{e[r](n,n.exports,__nccwpck_require__);s=false}finally{if(s)delete t[r]}return n.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(194);module.exports=r})();
@@ -0,0 +1,156 @@
1
+ // TypeScript Version: 3.0
2
+ /// <reference types="node" />
3
+ import type { URL } from 'node:url';
4
+
5
+ export interface DotenvParseOutput {
6
+ [name: string]: string;
7
+ }
8
+
9
+ /**
10
+ * Parses a string or buffer in the .env file format into an object.
11
+ *
12
+ * See https://docs.dotenv.org
13
+ *
14
+ * @param src - contents to be parsed. example: `'DB_HOST=localhost'`
15
+ * @param options - additional options. example: `{ debug: true }`
16
+ * @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
17
+ */
18
+ export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
19
+ src: string | Buffer
20
+ ): T;
21
+
22
+ export interface DotenvConfigOptions {
23
+ /**
24
+ * Default: `path.resolve(process.cwd(), '.env')`
25
+ *
26
+ * Specify a custom path if your file containing environment variables is located elsewhere.
27
+ *
28
+ * example: `require('dotenv').config({ path: '/custom/path/to/.env' })`
29
+ */
30
+ path?: string | URL;
31
+
32
+ /**
33
+ * Default: `utf8`
34
+ *
35
+ * Specify the encoding of your file containing environment variables.
36
+ *
37
+ * example: `require('dotenv').config({ encoding: 'latin1' })`
38
+ */
39
+ encoding?: string;
40
+
41
+ /**
42
+ * Default: `false`
43
+ *
44
+ * Turn on logging to help debug why certain keys or values are not being set as you expect.
45
+ *
46
+ * example: `require('dotenv').config({ debug: process.env.DEBUG })`
47
+ */
48
+ debug?: boolean;
49
+
50
+ /**
51
+ * Default: `false`
52
+ *
53
+ * Override any environment variables that have already been set on your machine with values from your .env file.
54
+ *
55
+ * example: `require('dotenv').config({ override: true })`
56
+ */
57
+ override?: boolean;
58
+
59
+ /**
60
+ * Default: `process.env`
61
+ *
62
+ * Specify an object to write your secrets to. Defaults to process.env environment variables.
63
+ *
64
+ * example: `const processEnv = {}; require('dotenv').config({ processEnv: processEnv })`
65
+ */
66
+ processEnv?: DotenvPopulateInput;
67
+
68
+ /**
69
+ * Default: `undefined`
70
+ *
71
+ * Pass the DOTENV_KEY directly to config options. Defaults to looking for process.env.DOTENV_KEY environment variable. Note this only applies to decrypting .env.vault files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a .env file.
72
+ *
73
+ * example: `require('dotenv').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenv.org/vault/.env.vault?environment=production' })`
74
+ */
75
+ DOTENV_KEY?: string;
76
+ }
77
+
78
+ export interface DotenvConfigOutput {
79
+ error?: Error;
80
+ parsed?: DotenvParseOutput;
81
+ }
82
+
83
+ export interface DotenvPopulateOptions {
84
+ /**
85
+ * Default: `false`
86
+ *
87
+ * Turn on logging to help debug why certain keys or values are not being set as you expect.
88
+ *
89
+ * example: `require('dotenv').config({ debug: process.env.DEBUG })`
90
+ */
91
+ debug?: boolean;
92
+
93
+ /**
94
+ * Default: `false`
95
+ *
96
+ * Override any environment variables that have already been set on your machine with values from your .env file.
97
+ *
98
+ * example: `require('dotenv').config({ override: true })`
99
+ */
100
+ override?: boolean;
101
+ }
102
+
103
+ export interface DotenvPopulateOutput {
104
+ error?: Error;
105
+ }
106
+
107
+ export interface DotenvPopulateInput {
108
+ [name: string]: string;
109
+ }
110
+
111
+ /**
112
+ * Loads `.env` file contents into process.env by default. If `DOTENV_KEY` is present, it smartly attempts to load encrypted `.env.vault` file contents into process.env.
113
+ *
114
+ * See https://docs.dotenv.org
115
+ *
116
+ * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
117
+ * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
118
+ *
119
+ */
120
+ export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
121
+
122
+ /**
123
+ * Loads `.env` file contents into process.env.
124
+ *
125
+ * See https://docs.dotenv.org
126
+ *
127
+ * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
128
+ * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
129
+ *
130
+ */
131
+ export function configDotenv(options?: DotenvConfigOptions): DotenvConfigOutput;
132
+
133
+ /**
134
+ * Loads `source` json contents into `target` like process.env.
135
+ *
136
+ * See https://docs.dotenv.org
137
+ *
138
+ * @param processEnv - the target JSON object. in most cases use process.env but you can also pass your own JSON object
139
+ * @param parsed - the source JSON object
140
+ * @param options - additional options. example: `{ debug: true, override: false }`
141
+ * @returns {void}
142
+ *
143
+ */
144
+ export function populate(processEnv: DotenvPopulateInput, parsed: DotenvPopulateInput, options?: DotenvConfigOptions): DotenvPopulateOutput;
145
+
146
+ /**
147
+ * Decrypt ciphertext
148
+ *
149
+ * See https://docs.dotenv.org
150
+ *
151
+ * @param encrypted - the encrypted ciphertext string
152
+ * @param keyStr - the decryption key string
153
+ * @returns {string}
154
+ *
155
+ */
156
+ export function decrypt(encrypted: string, keyStr: string): string;
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2015, Scott Motte
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ {"name":"dotenv","version":"16.3.1","funding":"https://github.com/motdotla/dotenv?sponsor=1","license":"BSD-2-Clause","types":"lib/main.d.ts"}
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={183:e=>{function _searchLast(e,r){const n=Array.from(e.matchAll(r));return n.length>0?n.slice(-1)[0].index:-1}function _interpolate(e,r,n){const t=_searchLast(e,/(?!(?<=\\))\$/g);if(t===-1)return e;const s=e.slice(t);const a=/((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;const c=s.match(a);if(c!=null){const[,t,s,a]=c;return _interpolate(e.replace(t,r[s]||a||n.parsed[s]||""),r,n)}return e}function _resolveEscapeSequences(e){return e.replace(/\\\$/g,"$")}function expand(e){const r=e.ignoreProcessEnv?{}:process.env;for(const n in e.parsed){const t=Object.prototype.hasOwnProperty.call(r,n)?r[n]:e.parsed[n];e.parsed[n]=_resolveEscapeSequences(_interpolate(t,r,e))}for(const n in e.parsed){r[n]=e.parsed[n]}return e}e.exports.expand=expand}};var r={};function __nccwpck_require__(n){var t=r[n];if(t!==undefined){return t.exports}var s=r[n]={exports:{}};var a=true;try{e[n](s,s.exports,__nccwpck_require__);a=false}finally{if(a)delete r[n]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n=__nccwpck_require__(183);module.exports=n})();
@@ -0,0 +1,29 @@
1
+ // TypeScript Version: 3.0
2
+ /// <reference types="node" />
3
+
4
+ export interface DotenvExpandOptions {
5
+ ignoreProcessEnv?: boolean;
6
+ error?: Error;
7
+ parsed?: {
8
+ [name: string]: string;
9
+ }
10
+ }
11
+
12
+ export interface DotenvExpandOutput {
13
+ ignoreProcessEnv?: boolean;
14
+ error?: Error;
15
+ parsed?: {
16
+ [name: string]: string;
17
+ };
18
+ }
19
+
20
+ /**
21
+ * Adds variable expansion on top of dotenv.
22
+ *
23
+ * See https://docs.dotenv.org
24
+ *
25
+ * @param options - additional options. example: `{ ignoreProcessEnv: false, error: null, parsed: { { KEY: 'value' } }`
26
+ * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
27
+ *
28
+ */
29
+ export function expand(options?: DotenvExpandOptions): DotenvExpandOutput
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2016, Scott Motte
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
@@ -0,0 +1 @@
1
+ {"name":"dotenv-expand","author":"motdotla","version":"10.0.0","license":"BSD-2-Clause","types":"lib/main.d.ts"}
@@ -10,5 +10,11 @@ export type InspectOptions = CommonOptions & {
10
10
  export type DevOptions = CommonOptions & {
11
11
  open?: boolean;
12
12
  };
13
- export declare function init(options?: CommonOptions): Promise<import("@rsbuild/shared").RsbuildInstance<any>>;
13
+ export declare function init({
14
+ cliOptions,
15
+ isRestart
16
+ }: {
17
+ cliOptions?: CommonOptions;
18
+ isRestart?: boolean;
19
+ }): Promise<import("@rsbuild/shared").RsbuildInstance<any> | undefined>;
14
20
  export declare function runCli(): void;
@@ -35,30 +35,43 @@ module.exports = __toCommonJS(commands_exports);
35
35
  var import_path = require("path");
36
36
  var import_shared = require("@rsbuild/shared");
37
37
  var import_commander = require("../../compiled/commander");
38
+ var import_loadEnv = require("../loadEnv");
38
39
  var import_config = require("./config");
39
40
  let commonOpts = {};
40
- async function init(options) {
41
- if (options) {
42
- commonOpts = options;
41
+ async function init({
42
+ cliOptions,
43
+ isRestart
44
+ }) {
45
+ if (cliOptions) {
46
+ commonOpts = cliOptions;
47
+ }
48
+ try {
49
+ await (0, import_loadEnv.loadEnv)();
50
+ const config = await (0, import_config.loadConfig)(commonOpts.config);
51
+ const { createRsbuild } = await Promise.resolve().then(() => __toESM(require("../createRsbuild")));
52
+ return await createRsbuild({
53
+ rsbuildConfig: config,
54
+ provider: config.provider
55
+ });
56
+ } catch (err) {
57
+ if (isRestart) {
58
+ import_shared.logger.error(err);
59
+ } else {
60
+ throw err;
61
+ }
43
62
  }
44
- const config = await (0, import_config.loadConfig)(commonOpts.config);
45
- const { createRsbuild } = await Promise.resolve().then(() => __toESM(require("../createRsbuild")));
46
- return await createRsbuild({
47
- rsbuildConfig: config,
48
- provider: config.provider
49
- });
50
63
  }
51
64
  function runCli() {
52
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.0.28");
65
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("1.0.0");
53
66
  import_commander.program.command("dev").option(`--open`, "open the page in browser on startup").option(
54
67
  "-c --config <config>",
55
68
  "specify the configuration file, can be a relative or absolute path"
56
69
  ).description("starting the dev server").action(async (options) => {
57
70
  try {
58
- const rsbuild = await init(options);
59
- await rsbuild.startDevServer({
71
+ const rsbuild = await init({ cliOptions: options });
72
+ await (rsbuild == null ? void 0 : rsbuild.startDevServer({
60
73
  open: options.open
61
- });
74
+ }));
62
75
  } catch (err) {
63
76
  import_shared.logger.error("Failed to start dev server, please check logs.");
64
77
  import_shared.logger.error(err);
@@ -70,8 +83,8 @@ function runCli() {
70
83
  "specify the configuration file, can be a relative or absolute path"
71
84
  ).description("build the app for production").action(async (options) => {
72
85
  try {
73
- const rsbuild = await init(options);
74
- await rsbuild.build();
86
+ const rsbuild = await init({ cliOptions: options });
87
+ await (rsbuild == null ? void 0 : rsbuild.build());
75
88
  } catch (err) {
76
89
  import_shared.logger.error("Failed to build, please check logs.");
77
90
  import_shared.logger.error(err);
@@ -83,8 +96,8 @@ function runCli() {
83
96
  "specify the configuration file, can be a relative or absolute path"
84
97
  ).description("preview the production build locally").action(async (options) => {
85
98
  try {
86
- const rsbuild = await init(options);
87
- await rsbuild.preview();
99
+ const rsbuild = await init({ cliOptions: options });
100
+ await (rsbuild == null ? void 0 : rsbuild.preview());
88
101
  } catch (err) {
89
102
  import_shared.logger.error("Failed to start preview server, please check logs.");
90
103
  import_shared.logger.error(err);
@@ -96,13 +109,13 @@ function runCli() {
96
109
  "specify the configuration file, can be a relative or absolute path"
97
110
  ).action(async (options) => {
98
111
  try {
99
- const rsbuild = await init(options);
100
- await rsbuild.inspectConfig({
112
+ const rsbuild = await init({ cliOptions: options });
113
+ await (rsbuild == null ? void 0 : rsbuild.inspectConfig({
101
114
  env: options.env,
102
115
  verbose: options.verbose,
103
116
  outputPath: (0, import_path.join)(rsbuild.context.distPath, options.output),
104
117
  writeToDisk: true
105
- });
118
+ }));
106
119
  } catch (err) {
107
120
  import_shared.logger.error("Failed to inspect config, please check logs.");
108
121
  import_shared.logger.error(err);
@@ -65,29 +65,41 @@ const resolveConfigPath = (customConfig) => {
65
65
  };
66
66
  async function watchConfig(configFile) {
67
67
  const chokidar = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/chokidar")));
68
- const watcher = chokidar.watch(configFile, {});
69
- const callback = async () => {
70
- watcher.close();
71
- await (0, import_restart.restartDevServer)({ filePath: configFile });
72
- };
68
+ const watcher = chokidar.watch(configFile, {
69
+ // If watching fails due to read permissions, the errors will be suppressed silently.
70
+ ignorePermissionErrors: true
71
+ });
72
+ const callback = (0, import_shared.debounce)(
73
+ async () => {
74
+ watcher.close();
75
+ await (0, import_restart.restartDevServer)({ filePath: configFile });
76
+ },
77
+ // set 300ms debounce to avoid restart frequently
78
+ 300
79
+ );
73
80
  watcher.on("change", callback);
74
81
  watcher.on("unlink", callback);
75
82
  }
76
83
  async function loadConfig(customConfig) {
77
84
  const configFile = resolveConfigPath(customConfig);
78
85
  if (configFile) {
79
- const { default: jiti } = await Promise.resolve().then(() => __toESM(require("../../compiled/jiti")));
80
- const loadConfig2 = jiti(__filename, {
81
- esmResolve: true,
82
- // disable require cache to support restart CLI and read the new config
83
- requireCache: false,
84
- interopDefault: true
85
- });
86
- const command = process.argv[2];
87
- if (command === "dev") {
88
- watchConfig(configFile);
86
+ try {
87
+ const { default: jiti } = await Promise.resolve().then(() => __toESM(require("../../compiled/jiti")));
88
+ const loadConfig2 = jiti(__filename, {
89
+ esmResolve: true,
90
+ // disable require cache to support restart CLI and read the new config
91
+ requireCache: false,
92
+ interopDefault: true
93
+ });
94
+ const command = process.argv[2];
95
+ if (command === "dev") {
96
+ watchConfig(configFile);
97
+ }
98
+ return loadConfig2(configFile);
99
+ } catch (err) {
100
+ import_shared.logger.error(`Failed to load file: ${import_shared.color.dim(configFile)}`);
101
+ throw err;
89
102
  }
90
- return loadConfig2(configFile);
91
103
  }
92
104
  return {};
93
105
  }
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.0.28"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"1.0.0"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,5 @@
1
+ export declare function loadEnv({
2
+ dir
3
+ }?: {
4
+ dir?: string;
5
+ }): Promise<Record<string, string>>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var loadEnv_exports = {};
30
+ __export(loadEnv_exports, {
31
+ loadEnv: () => loadEnv
32
+ });
33
+ module.exports = __toCommonJS(loadEnv_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = require("path");
36
+ var import_shared = require("@rsbuild/shared");
37
+ async function loadEnv({ dir = process.cwd() } = {}) {
38
+ const { parse } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv")));
39
+ const { expand } = await Promise.resolve().then(() => __toESM(require("../compiled/dotenv-expand")));
40
+ const { NODE_ENV } = process.env;
41
+ const files = [
42
+ ".env",
43
+ ".env.local",
44
+ `.env.${NODE_ENV}`,
45
+ `.env.${NODE_ENV}.local`
46
+ ];
47
+ const envPaths = files.map((filename) => (0, import_path.join)(dir, filename)).filter(import_shared.isFileSync);
48
+ const parsed = {};
49
+ envPaths.forEach((envPath) => {
50
+ Object.assign(parsed, parse(import_fs.default.readFileSync(envPath)));
51
+ });
52
+ expand({ parsed });
53
+ return parsed;
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ loadEnv
58
+ });
@@ -42,7 +42,7 @@ function getRegExpForExts(exts) {
42
42
  );
43
43
  }
44
44
  const pluginAsset = () => ({
45
- name: "plugin-asset",
45
+ name: "rsbuild:asset",
46
46
  setup(api) {
47
47
  api.modifyBundlerChain((chain, { isProd }) => {
48
48
  const config = api.getNormalizedConfig();
@@ -33,7 +33,7 @@ __export(bundleAnalyzer_exports, {
33
33
  module.exports = __toCommonJS(bundleAnalyzer_exports);
34
34
  function pluginBundleAnalyzer() {
35
35
  return {
36
- name: "plugin-bundle-analyzer",
36
+ name: "rsbuild:bundle-analyzer",
37
37
  setup(api) {
38
38
  api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
39
39
  const config = api.getNormalizedConfig();
@@ -81,7 +81,7 @@ async function getBuildDependencies(context) {
81
81
  return buildDependencies;
82
82
  }
83
83
  const pluginCache = () => ({
84
- name: "plugin-cache",
84
+ name: "rsbuild:cache",
85
85
  setup(api) {
86
86
  api.modifyBundlerChain(async (chain, { target, env }) => {
87
87
  const { buildCache } = api.getNormalizedConfig().performance;
@@ -28,7 +28,7 @@ const emptyDir = async (dir) => {
28
28
  }
29
29
  };
30
30
  const pluginCleanOutput = () => ({
31
- name: "plugin-clean-output",
31
+ name: "rsbuild:clean-output",
32
32
  setup(api) {
33
33
  const clean = async () => {
34
34
  const config = api.getNormalizedConfig();
@@ -23,7 +23,7 @@ __export(define_exports, {
23
23
  module.exports = __toCommonJS(define_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginDefine = () => ({
26
- name: "plugin-define",
26
+ name: "rsbuild:define",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain, { CHAIN_ID, bundler }) => {
29
29
  const config = api.getNormalizedConfig();
@@ -23,7 +23,7 @@ __export(devtool_exports, {
23
23
  module.exports = __toCommonJS(devtool_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginDevtool = () => ({
26
- name: "plugin-devtool",
26
+ name: "rsbuild:devtool",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain, { isProd, isServer }) => {
29
29
  const config = api.getNormalizedConfig();
@@ -23,7 +23,7 @@ __export(entry_exports, {
23
23
  module.exports = __toCommonJS(entry_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginEntry = () => ({
26
- name: "plugin-entry",
26
+ name: "rsbuild:entry",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain(async (chain) => {
29
29
  const { entry } = api.context;
@@ -23,7 +23,7 @@ __export(externals_exports, {
23
23
  module.exports = __toCommonJS(externals_exports);
24
24
  function pluginExternals() {
25
25
  return {
26
- name: "plugin-externals",
26
+ name: "rsbuild:externals",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain) => {
29
29
  const { externals } = api.getNormalizedConfig().output;
@@ -136,7 +136,7 @@ async function printFileSizes(stats, distPath) {
136
136
  `);
137
137
  }
138
138
  const pluginFileSize = () => ({
139
- name: "plugin-file-size",
139
+ name: "rsbuild:file-size",
140
140
  setup(api) {
141
141
  api.onAfterBuild(async ({ stats }) => {
142
142
  const config = api.getNormalizedConfig();
@@ -161,7 +161,7 @@ const applyInjectTags = (api) => {
161
161
  });
162
162
  };
163
163
  const pluginHtml = () => ({
164
- name: "plugin-html",
164
+ name: "rsbuild:html",
165
165
  setup(api) {
166
166
  api.modifyBundlerChain(
167
167
  async (chain, { HtmlPlugin, isProd, CHAIN_ID, target }) => {
@@ -33,7 +33,7 @@ __export(inlineChunk_exports, {
33
33
  module.exports = __toCommonJS(inlineChunk_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  const pluginInlineChunk = () => ({
36
- name: "plugin-inline-chunk",
36
+ name: "rsbuild:inline-chunk",
37
37
  setup(api) {
38
38
  api.modifyBundlerChain(
39
39
  async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
@@ -43,21 +43,17 @@ const pluginInlineChunk = () => ({
43
43
  }
44
44
  const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared")));
45
45
  const {
46
- enableInlineStyles,
47
- // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
48
- enableInlineScripts
46
+ inlineStyles,
47
+ // todo: not support inlineScripts in Rspack yet, which will take unknown build error
48
+ inlineScripts
49
49
  } = config.output;
50
50
  const scriptTests = [];
51
51
  const styleTests = [];
52
- if (enableInlineScripts) {
53
- scriptTests.push(
54
- enableInlineScripts === true ? import_shared.JS_REGEX : enableInlineScripts
55
- );
52
+ if (inlineScripts) {
53
+ scriptTests.push(inlineScripts === true ? import_shared.JS_REGEX : inlineScripts);
56
54
  }
57
- if (enableInlineStyles) {
58
- styleTests.push(
59
- enableInlineStyles === true ? import_shared.CSS_REGEX : enableInlineStyles
60
- );
55
+ if (inlineStyles) {
56
+ styleTests.push(inlineStyles === true ? import_shared.CSS_REGEX : inlineStyles);
61
57
  }
62
58
  if (!scriptTests.length && !styleTests.length) {
63
59
  return;
@@ -47,7 +47,7 @@ class IgnorePlugin {
47
47
  }
48
48
  }
49
49
  const pluginMoment = () => ({
50
- name: "plugin-moment",
50
+ name: "rsbuild:moment",
51
51
  setup(api) {
52
52
  api.modifyBundlerChain(async (chain) => {
53
53
  const config = api.getNormalizedConfig();