@rsbuild/core 2.0.0-beta.0 → 2.0.0-beta.10
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/compiled/chokidar/index.d.ts +197 -29
- package/compiled/chokidar/package.json +1 -1
- package/compiled/connect-next/index.d.ts +56 -0
- package/compiled/connect-next/license +26 -0
- package/compiled/connect-next/package.json +1 -0
- package/compiled/cors/index.d.ts +56 -0
- package/compiled/cors/license +22 -0
- package/compiled/cors/package.json +1 -0
- package/compiled/css-loader/index.js +2 -2
- package/compiled/css-loader/package.json +1 -1
- package/compiled/html-rspack-plugin/index.d.ts +102 -1
- package/compiled/html-rspack-plugin/index.js +863 -20
- package/compiled/html-rspack-plugin/package.json +1 -1
- package/compiled/http-proxy-middleware/index.d.ts +268 -43
- package/compiled/http-proxy-middleware/package.json +1 -1
- package/compiled/jiti/LICENSE +21 -0
- package/compiled/jiti/README.md +243 -0
- package/compiled/jiti/dist/babel.cjs +46699 -0
- package/compiled/jiti/dist/jiti.cjs +4842 -0
- package/compiled/jiti/lib/jiti-cli.mjs +19 -0
- package/compiled/jiti/lib/jiti-hooks.mjs +89 -0
- package/compiled/jiti/lib/jiti-native.mjs +76 -0
- package/compiled/jiti/lib/jiti-register.d.mts +1 -0
- package/compiled/jiti/lib/jiti-register.mjs +2 -0
- package/compiled/jiti/lib/jiti.cjs +24 -0
- package/compiled/jiti/lib/jiti.d.cts +8 -0
- package/compiled/jiti/lib/jiti.d.mts +8 -0
- package/compiled/jiti/lib/jiti.mjs +23 -0
- package/compiled/jiti/lib/types.d.ts +363 -0
- package/compiled/jiti/package.json +133 -0
- package/compiled/postcss/index.js +1 -1
- package/compiled/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/postcss/lib/comment.d.ts +1 -1
- package/compiled/postcss/lib/container.d.ts +1 -1
- package/compiled/postcss/lib/css-syntax-error.d.ts +1 -1
- package/compiled/postcss/lib/declaration.d.ts +1 -1
- package/compiled/postcss/lib/document.d.ts +1 -1
- package/compiled/postcss/lib/input.d.ts +1 -1
- package/compiled/postcss/lib/lazy-result.d.ts +1 -1
- package/compiled/postcss/lib/no-work-result.d.ts +1 -1
- package/compiled/postcss/lib/node.d.ts +1 -1
- package/compiled/postcss/lib/previous-map.d.ts +1 -1
- package/compiled/postcss/lib/processor.d.ts +1 -1
- package/compiled/postcss/lib/result.d.ts +1 -1
- package/compiled/postcss/lib/root.d.ts +1 -1
- package/compiled/postcss/lib/rule.d.ts +1 -1
- package/compiled/postcss/lib/stringifier.d.ts +1 -1
- package/compiled/postcss/lib/warning.d.ts +1 -1
- package/compiled/postcss/package.json +1 -1
- package/compiled/postcss-loader/index.js +10 -9
- package/compiled/postcss-loader/package.json +1 -1
- package/compiled/rslog/index.d.ts +33 -2
- package/compiled/rslog/package.json +1 -1
- package/compiled/rspack-chain/package.json +1 -1
- package/compiled/rspack-chain/types/index.d.ts +0 -5
- package/compiled/rspack-manifest-plugin/index.d.ts +48 -0
- package/compiled/rspack-manifest-plugin/license +21 -0
- package/compiled/rspack-manifest-plugin/package.json +1 -0
- package/compiled/style-loader/index.js +37 -94
- package/compiled/style-loader/package.json +1 -1
- package/dist/{131.js → 958.js} +1706 -1655
- package/dist/chokidar.js +59 -57
- package/dist/client/hmr.js +3 -3
- package/dist/client/overlay.js +2 -2
- package/dist/connect-next.js +268 -0
- package/dist/{connect.js.LICENSE.txt → connect-next.js.LICENSE.txt} +3 -13
- package/dist/cors.js +2 -2
- package/dist/http-proxy-middleware.js +2985 -0
- package/dist/http-proxy-middleware.js.LICENSE.txt +69 -0
- package/dist/index.js +1 -1
- package/dist/launch-editor-middleware.js +96 -16
- package/dist/manifest-plugin.js +543 -21
- package/dist/memfs.js +241 -776
- package/dist/{710.js → mrmime.js} +2 -1
- package/dist/open.js +32 -28
- package/dist/range-parser.js +2 -2
- package/dist/remapping.js +2 -2
- package/dist/rslib-runtime.js +4 -4
- package/dist/sirv.js +14 -14
- package/dist/src.js +510 -0
- package/dist/tinyglobby.js +114 -69
- package/dist/transformLoader.mjs +38 -1
- package/dist/transformRawLoader.mjs +1 -1
- package/dist/ws.js +1549 -0
- package/dist-types/createContext.d.ts +3 -2
- package/dist-types/helpers/format.d.ts +2 -1
- package/dist-types/helpers/fs.d.ts +2 -1
- package/dist-types/helpers/index.d.ts +1 -1
- package/dist-types/helpers/stats.d.ts +4 -3
- package/dist-types/helpers/vendors.d.ts +0 -2
- package/dist-types/hooks.d.ts +3 -3
- package/dist-types/index.d.ts +4 -3
- package/dist-types/initPlugins.d.ts +2 -1
- package/dist-types/logger.d.ts +9 -3
- package/dist-types/pluginManager.d.ts +2 -1
- package/dist-types/restart.d.ts +4 -2
- package/dist-types/server/assets-middleware/index.d.ts +3 -2
- package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +2 -1
- package/dist-types/server/cliShortcuts.d.ts +4 -1
- package/dist-types/server/devMiddlewares.d.ts +4 -6
- package/dist-types/server/devServer.d.ts +8 -42
- package/dist-types/server/helper.d.ts +50 -16
- package/dist-types/server/historyApiFallback.d.ts +2 -1
- package/dist-types/server/middlewares.d.ts +5 -3
- package/dist-types/server/open.d.ts +4 -2
- package/dist-types/server/previewServer.d.ts +4 -0
- package/dist-types/server/proxy.d.ts +3 -2
- package/dist-types/server/runner/asModule.d.ts +1 -1
- package/dist-types/server/serverSetup.d.ts +2 -0
- package/dist-types/server/socketServer.d.ts +4 -1
- package/dist-types/server/watchFiles.d.ts +1 -1
- package/dist-types/types/config.d.ts +123 -25
- package/dist-types/types/context.d.ts +3 -0
- package/dist-types/types/hooks.d.ts +17 -15
- package/dist-types/types/plugin.d.ts +14 -11
- package/dist-types/types/rsbuild.d.ts +11 -4
- package/dist-types/types/thirdParty.d.ts +15 -6
- package/package.json +23 -26
- package/compiled/chokidar/handler.d.ts +0 -90
- package/compiled/http-proxy-middleware/index.js +0 -5284
- package/compiled/ws/index.d.ts +0 -437
- package/compiled/ws/index.js +0 -3166
- package/compiled/ws/license +0 -20
- package/compiled/ws/package.json +0 -1
- package/dist/397.js +0 -11
- package/dist/7.js +0 -1
- package/dist/743.js +0 -7
- package/dist/88.js +0 -40
- package/dist/connect.js +0 -581
- package/dist-types/server/prodServer.d.ts +0 -24
- /package/compiled/html-rspack-plugin/{loader.js → htmlLoader.js} +0 -0
- /package/dist/{131.js.LICENSE.txt → 958.js.LICENSE.txt} +0 -0
- /package/dist/client/{59.js → 797.js} +0 -0
- /package/dist/{31.js → trace-mapping.js} +0 -0
package/dist/open.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
let isDockerCached, cachedResult, canAccessPowerShellPromise, mountPoint, defaultMountPoint;
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import "
|
|
6
|
-
import { constants
|
|
7
|
-
|
|
2
|
+
import node_process from "node:process";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import node_child_process, { execFile as external_node_child_process_execFile } from "node:child_process";
|
|
6
|
+
import promises, { constants } from "node:fs/promises";
|
|
7
|
+
import { promisify } from "node:util";
|
|
8
|
+
import node_os from "node:os";
|
|
9
|
+
import node_fs from "node:fs";
|
|
10
|
+
import { Buffer } from "node:buffer";
|
|
8
11
|
function hasDockerEnv() {
|
|
9
12
|
try {
|
|
10
|
-
return
|
|
13
|
+
return node_fs.statSync('/.dockerenv'), !0;
|
|
11
14
|
} catch {
|
|
12
15
|
return !1;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
function hasDockerCGroup() {
|
|
16
19
|
try {
|
|
17
|
-
return
|
|
20
|
+
return node_fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
|
18
21
|
} catch {
|
|
19
22
|
return !1;
|
|
20
23
|
}
|
|
@@ -25,7 +28,7 @@ function isDocker() {
|
|
|
25
28
|
function isInsideContainer() {
|
|
26
29
|
return void 0 === cachedResult && (cachedResult = (()=>{
|
|
27
30
|
try {
|
|
28
|
-
return
|
|
31
|
+
return node_fs.statSync('/run/.containerenv'), !0;
|
|
29
32
|
} catch {
|
|
30
33
|
return !1;
|
|
31
34
|
}
|
|
@@ -35,13 +38,12 @@ let isWsl = ()=>{
|
|
|
35
38
|
if ('linux' !== node_process.platform) return !1;
|
|
36
39
|
if (node_os.release().toLowerCase().includes('microsoft')) return !isInsideContainer();
|
|
37
40
|
try {
|
|
38
|
-
|
|
39
|
-
} catch {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}, is_wsl = node_process.env.__IS_WSL_TEST__ ? isWsl : isWsl(), external_node_buffer_ = __webpack_require__("node:buffer"), powershell_utils_execFile = external_node_util_promisify(node_child_process.execFile), powerShellPath = ()=>`${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, executePowerShell = async (command, options = {})=>{
|
|
41
|
+
if (node_fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')) return !isInsideContainer();
|
|
42
|
+
} catch {}
|
|
43
|
+
return !!(node_fs.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop') || node_fs.existsSync('/run/WSL')) && !isInsideContainer();
|
|
44
|
+
}, is_wsl = node_process.env.__IS_WSL_TEST__ ? isWsl : isWsl(), execFile = promisify(node_child_process.execFile), powerShellPath = ()=>`${node_process.env.SYSTEMROOT || node_process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`, executePowerShell = async (command, options = {})=>{
|
|
43
45
|
let { powerShellPath: psPath, ...execFileOptions } = options, encodedCommand = executePowerShell.encodeCommand(command);
|
|
44
|
-
return
|
|
46
|
+
return execFile(psPath ?? powerShellPath(), [
|
|
45
47
|
...executePowerShell.argumentsPrefix,
|
|
46
48
|
encodedCommand
|
|
47
49
|
], {
|
|
@@ -62,8 +64,8 @@ executePowerShell.argumentsPrefix = [
|
|
|
62
64
|
'-ExecutionPolicy',
|
|
63
65
|
'Bypass',
|
|
64
66
|
'-EncodedCommand'
|
|
65
|
-
], executePowerShell.encodeCommand = (command)=>
|
|
66
|
-
let wsl_utils_execFile =
|
|
67
|
+
], executePowerShell.encodeCommand = (command)=>Buffer.from(command, 'utf16le').toString('base64'), executePowerShell.escapeArgument = (value)=>`'${String(value).replaceAll('\'', '\'\'')}'`;
|
|
68
|
+
let wsl_utils_execFile = promisify(node_child_process.execFile), wslDrivesMountPoint = (defaultMountPoint = '/mnt/', async function() {
|
|
67
69
|
if (mountPoint) return mountPoint;
|
|
68
70
|
let configFilePath = '/etc/wsl.conf', isConfigFileExists = !1;
|
|
69
71
|
try {
|
|
@@ -121,7 +123,7 @@ function defineLazyProperty(object, propertyName, valueGetter) {
|
|
|
121
123
|
}
|
|
122
124
|
}), object;
|
|
123
125
|
}
|
|
124
|
-
let execFileAsync =
|
|
126
|
+
let execFileAsync = promisify(external_node_child_process_execFile);
|
|
125
127
|
async function defaultBrowserId() {
|
|
126
128
|
if ('darwin' !== node_process.platform) throw Error('macOS only');
|
|
127
129
|
let { stdout } = await execFileAsync('defaults', [
|
|
@@ -131,7 +133,7 @@ async function defaultBrowserId() {
|
|
|
131
133
|
]), match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout), browserId = match?.groups.id ?? 'com.apple.Safari';
|
|
132
134
|
return 'com.apple.safari' === browserId ? 'com.apple.Safari' : browserId;
|
|
133
135
|
}
|
|
134
|
-
let run_applescript_execFileAsync =
|
|
136
|
+
let run_applescript_execFileAsync = promisify(external_node_child_process_execFile);
|
|
135
137
|
async function runAppleScript(script, { humanReadableOutput = !0, signal } = {}) {
|
|
136
138
|
if ('darwin' !== node_process.platform) throw Error('macOS only');
|
|
137
139
|
let execOptions = {};
|
|
@@ -148,7 +150,7 @@ async function runAppleScript(script, { humanReadableOutput = !0, signal } = {})
|
|
|
148
150
|
async function bundleName(bundleId) {
|
|
149
151
|
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
150
152
|
}
|
|
151
|
-
let windows_execFileAsync =
|
|
153
|
+
let windows_execFileAsync = promisify(external_node_child_process_execFile), windowsBrowserProgIds = {
|
|
152
154
|
MSEdgeHTM: {
|
|
153
155
|
name: 'Edge',
|
|
154
156
|
id: 'com.microsoft.edge'
|
|
@@ -224,11 +226,13 @@ async function defaultBrowser(_execFileAsync = windows_execFileAsync) {
|
|
|
224
226
|
'ProgId'
|
|
225
227
|
]), match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
226
228
|
if (!match) throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
227
|
-
let { id } = match.groups,
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
let { id } = match.groups, dotIndex = id.lastIndexOf('.'), hyphenIndex = id.lastIndexOf('-'), baseIdByDot = -1 === dotIndex ? void 0 : id.slice(0, dotIndex), baseIdByHyphen = -1 === hyphenIndex ? void 0 : id.slice(0, hyphenIndex);
|
|
230
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? {
|
|
231
|
+
name: id,
|
|
232
|
+
id
|
|
233
|
+
};
|
|
230
234
|
}
|
|
231
|
-
let default_browser_execFileAsync =
|
|
235
|
+
let default_browser_execFileAsync = promisify(external_node_child_process_execFile);
|
|
232
236
|
async function default_browser_defaultBrowser() {
|
|
233
237
|
if ('darwin' === node_process.platform) {
|
|
234
238
|
let id = await defaultBrowserId();
|
|
@@ -251,7 +255,7 @@ async function default_browser_defaultBrowser() {
|
|
|
251
255
|
if ('win32' === node_process.platform) return defaultBrowser();
|
|
252
256
|
throw Error('Only macOS, Linux, and Windows are supported');
|
|
253
257
|
}
|
|
254
|
-
let isInSsh = !!(node_process.env.SSH_CONNECTION || node_process.env.SSH_CLIENT || node_process.env.SSH_TTY),
|
|
258
|
+
let isInSsh = !!(node_process.env.SSH_CONNECTION || node_process.env.SSH_CLIENT || node_process.env.SSH_TTY), fallbackAttemptSymbol = Symbol('fallbackAttempt'), open_dirname = import.meta.url ? node_path.dirname(fileURLToPath(import.meta.url)) : '', localXdgOpenPath = node_path.join(open_dirname, 'xdg-open'), { platform: platform, arch: arch } = node_process, tryEachApp = async (apps, opener)=>{
|
|
255
259
|
if (0 === apps.length) return;
|
|
256
260
|
let errors = [];
|
|
257
261
|
for (let app of apps)try {
|
|
@@ -425,11 +429,11 @@ defineLazyProperty(open_apps, 'chrome', ()=>detectPlatformBinary({
|
|
|
425
429
|
})), defineLazyProperty(open_apps, 'safari', ()=>detectPlatformBinary({
|
|
426
430
|
darwin: 'Safari'
|
|
427
431
|
}));
|
|
428
|
-
|
|
432
|
+
export default ((target, options)=>{
|
|
429
433
|
if ('string' != typeof target) throw TypeError('Expected a `target`');
|
|
430
434
|
return baseOpen({
|
|
431
435
|
...options,
|
|
432
436
|
target
|
|
433
437
|
});
|
|
434
|
-
};
|
|
435
|
-
export {
|
|
438
|
+
});
|
|
439
|
+
export { open_apps as apps };
|
package/dist/range-parser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*!
|
|
1
|
+
/*! LICENSE: range-parser.js.LICENSE.txt */
|
|
2
2
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
3
3
|
__webpack_require__.add({
|
|
4
4
|
"../../node_modules/.pnpm/range-parser@1.2.1/node_modules/range-parser/index.js" (module) {
|
|
@@ -46,4 +46,4 @@ __webpack_require__.add({
|
|
|
46
46
|
return ranges.length < 1 ? -1 : options && options.combine ? combineRanges(ranges) : ranges;
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
});
|
|
49
|
+
}), __webpack_require__("../../node_modules/.pnpm/range-parser@1.2.1/node_modules/range-parser/index.js");
|
package/dist/remapping.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodedMappings as trace_mapping_decodedMappings, sourcemap_codec_encode, traceSegment, TraceMap as trace_mapping_TraceMap } from "./
|
|
1
|
+
import { decodedMappings as trace_mapping_decodedMappings, sourcemap_codec_encode, traceSegment, TraceMap as trace_mapping_TraceMap } from "./trace-mapping.js";
|
|
2
2
|
var SetArray = class {
|
|
3
3
|
constructor(){
|
|
4
4
|
this._indexes = {
|
|
@@ -193,4 +193,4 @@ function remapping(input, loader, options) {
|
|
|
193
193
|
decodedMappings: !1
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
|
-
export
|
|
196
|
+
export default remapping;
|
package/dist/rslib-runtime.js
CHANGED
|
@@ -5,11 +5,9 @@ function __webpack_require__(moduleId) {
|
|
|
5
5
|
var module = __webpack_module_cache__[moduleId] = {
|
|
6
6
|
exports: {}
|
|
7
7
|
};
|
|
8
|
-
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
8
|
+
return __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__), module.exports;
|
|
9
9
|
}
|
|
10
|
-
__webpack_require__.m = __webpack_modules__, __webpack_require__.
|
|
11
|
-
Object.assign(__webpack_require__.m, modules);
|
|
12
|
-
}, __webpack_require__.n = (module)=>{
|
|
10
|
+
__webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
|
|
13
11
|
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
14
12
|
return __webpack_require__.d(getter, {
|
|
15
13
|
a: getter
|
|
@@ -34,6 +32,8 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.add = function
|
|
|
34
32
|
enumerable: !0,
|
|
35
33
|
get: definition[key]
|
|
36
34
|
});
|
|
35
|
+
}, __webpack_require__.add = function registerModules(modules) {
|
|
36
|
+
Object.assign(__webpack_require__.m, modules);
|
|
37
37
|
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports)=>{
|
|
38
38
|
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
|
|
39
39
|
value: 'Module'
|
package/dist/sirv.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
2
|
+
import { join, normalize, resolve, sep } from "node:path";
|
|
3
|
+
import { join as external_path_join, resolve as external_path_resolve } from "path";
|
|
4
|
+
import { readdirSync, statSync as external_fs_statSync } from "fs";
|
|
2
5
|
import { parse } from "node:querystring";
|
|
3
|
-
import "./
|
|
4
|
-
import { lookup as mrmime_lookup } from "./710.js";
|
|
5
|
-
let external_path_ = __webpack_require__("path"), external_fs_ = __webpack_require__("fs");
|
|
6
|
+
import { lookup as mrmime_lookup } from "./mrmime.js";
|
|
6
7
|
function totalist(dir, callback, pre = '') {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
for(; i < arr.length; i++)abs = (0, external_path_.join)(dir, arr[i]), (stats = (0, external_fs_.statSync)(abs)).isDirectory() ? totalist(abs, callback, (0, external_path_.join)(pre, arr[i])) : callback((0, external_path_.join)(pre, arr[i]), abs, stats);
|
|
8
|
+
let arr = readdirSync(dir = external_path_resolve('.', dir)), i = 0, abs, stats;
|
|
9
|
+
for(; i < arr.length; i++)(stats = external_fs_statSync(abs = external_path_join(dir, arr[i]))).isDirectory() ? totalist(abs, callback, external_path_join(pre, arr[i])) : callback(external_path_join(pre, arr[i]), abs, stats);
|
|
10
10
|
}
|
|
11
11
|
function build_parse(req) {
|
|
12
12
|
let raw = req.url;
|
|
@@ -26,7 +26,7 @@ function build_parse(req) {
|
|
|
26
26
|
raw
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
let
|
|
29
|
+
let noop = ()=>{};
|
|
30
30
|
function isMatch(uri, arr) {
|
|
31
31
|
for(let i = 0; i < arr.length; i++)if (arr[i].test(uri)) return !0;
|
|
32
32
|
}
|
|
@@ -43,8 +43,8 @@ function viaCache(cache, uri, extns) {
|
|
|
43
43
|
}
|
|
44
44
|
function viaLocal(dir, isEtag, uri, extns) {
|
|
45
45
|
let abs, stats, name, headers, i = 0, arr = toAssume(uri, extns);
|
|
46
|
-
for(; i < arr.length; i++)if ((abs =
|
|
47
|
-
if ((stats =
|
|
46
|
+
for(; i < arr.length; i++)if ((abs = normalize(join(dir, name = arr[i]))).startsWith(dir) && existsSync(abs)) {
|
|
47
|
+
if ((stats = statSync(abs)).isDirectory()) continue;
|
|
48
48
|
return (headers = toHeaders(name, stats, isEtag))['Cache-Control'] = isEtag ? 'no-cache' : 'no-store', {
|
|
49
49
|
abs,
|
|
50
50
|
stats,
|
|
@@ -66,7 +66,7 @@ function send(req, res, file, stats, headers) {
|
|
|
66
66
|
if (end >= stats.size && (end = stats.size - 1), start >= stats.size) return res.setHeader('Content-Range', `bytes */${stats.size}`), res.statusCode = 416, res.end();
|
|
67
67
|
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`, headers['Content-Length'] = end - start + 1, headers['Accept-Ranges'] = 'bytes';
|
|
68
68
|
}
|
|
69
|
-
res.writeHead(code, headers),
|
|
69
|
+
res.writeHead(code, headers), createReadStream(file, opts).pipe(res);
|
|
70
70
|
}
|
|
71
71
|
let ENCODING = {
|
|
72
72
|
'.br': 'br',
|
|
@@ -83,7 +83,7 @@ function toHeaders(name, stats, isEtag) {
|
|
|
83
83
|
return enc && (headers['Content-Encoding'] = enc), isEtag && (headers.ETag = `W/"${stats.size}-${stats.mtime.getTime()}"`), headers;
|
|
84
84
|
}
|
|
85
85
|
function build(dir, opts = {}) {
|
|
86
|
-
dir =
|
|
86
|
+
dir = resolve(dir || '.');
|
|
87
87
|
let isNotFound = opts.onNoMatch || is404, setHeaders = opts.setHeaders || noop, extensions = opts.extensions || [
|
|
88
88
|
'html',
|
|
89
89
|
'htm'
|
|
@@ -107,7 +107,7 @@ function build(dir, opts = {}) {
|
|
|
107
107
|
headers
|
|
108
108
|
};
|
|
109
109
|
});
|
|
110
|
-
let lookup = opts.dev ? viaLocal.bind(0, dir +
|
|
110
|
+
let lookup = opts.dev ? viaLocal.bind(0, dir + sep, isEtag) : viaCache.bind(0, FILES);
|
|
111
111
|
return function(req, res, next) {
|
|
112
112
|
let extns = [
|
|
113
113
|
''
|
|
@@ -119,4 +119,4 @@ function build(dir, opts = {}) {
|
|
|
119
119
|
return data ? isEtag && req.headers['if-none-match'] === data.headers.ETag ? (res.writeHead(304), res.end()) : void ((gzips || brots) && res.setHeader('Vary', 'Accept-Encoding'), setHeaders(res, pathname, data.stats), send(req, res, data.abs, data.stats, data.headers)) : next ? next() : isNotFound(req, res);
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
|
-
export
|
|
122
|
+
export default build;
|