@remotion/bundler 3.1.7 → 3.1.11
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/bundler.d.ts +7 -0
- package/dist/bundler.js +76 -0
- package/dist/dev-middleware/compatible-api.d.ts +10 -0
- package/dist/dev-middleware/compatible-api.js +44 -0
- package/dist/dev-middleware/get-filename-from-url.d.ts +2 -0
- package/dist/dev-middleware/get-filename-from-url.js +92 -0
- package/dist/dev-middleware/get-paths.d.ts +7 -0
- package/dist/dev-middleware/get-paths.js +19 -0
- package/dist/dev-middleware/index.d.ts +3 -0
- package/dist/dev-middleware/index.js +57 -0
- package/dist/dev-middleware/is-color-supported.d.ts +1 -0
- package/dist/dev-middleware/is-color-supported.js +37 -0
- package/dist/dev-middleware/middleware.d.ts +4 -0
- package/dist/dev-middleware/middleware.js +141 -0
- package/dist/dev-middleware/range-parser.d.ts +15 -0
- package/dist/dev-middleware/range-parser.js +96 -0
- package/dist/dev-middleware/ready.d.ts +5 -0
- package/dist/dev-middleware/ready.js +13 -0
- package/dist/dev-middleware/setup-hooks.d.ts +2 -0
- package/dist/dev-middleware/setup-hooks.js +44 -0
- package/dist/dev-middleware/setup-output-filesystem.d.ts +2 -0
- package/dist/dev-middleware/setup-output-filesystem.js +13 -0
- package/dist/dev-middleware/types.d.ts +11 -0
- package/dist/dev-middleware/types.js +2 -0
- package/dist/error-overlay/entry-basic.d.ts +1 -0
- package/dist/error-overlay/entry-basic.js +21 -0
- package/dist/error-overlay/react-overlay/effects/format-warning.d.ts +11 -0
- package/dist/error-overlay/react-overlay/effects/format-warning.js +41 -0
- package/dist/error-overlay/react-overlay/effects/map-error-to-react-stack.d.ts +7 -0
- package/dist/error-overlay/react-overlay/effects/map-error-to-react-stack.js +46 -0
- package/dist/error-overlay/react-overlay/effects/proxy-console.d.ts +24 -0
- package/dist/error-overlay/react-overlay/effects/proxy-console.js +63 -0
- package/dist/error-overlay/react-overlay/effects/resolve-file-source.d.ts +3 -0
- package/dist/error-overlay/react-overlay/effects/resolve-file-source.js +31 -0
- package/dist/error-overlay/react-overlay/effects/stack-trace-limit.d.ts +3 -0
- package/dist/error-overlay/react-overlay/effects/stack-trace-limit.js +43 -0
- package/dist/error-overlay/react-overlay/effects/unhandled-error.d.ts +4 -0
- package/dist/error-overlay/react-overlay/effects/unhandled-error.js +45 -0
- package/dist/error-overlay/react-overlay/effects/unhandled-rejection.d.ts +4 -0
- package/dist/error-overlay/react-overlay/effects/unhandled-rejection.js +41 -0
- package/dist/error-overlay/react-overlay/index.d.ts +2 -0
- package/dist/error-overlay/react-overlay/index.js +21 -0
- package/dist/error-overlay/react-overlay/listen-to-runtime-errors.d.ts +8 -0
- package/dist/error-overlay/react-overlay/listen-to-runtime-errors.js +78 -0
- package/dist/error-overlay/react-overlay/utils/get-file-source.d.ts +1 -0
- package/dist/error-overlay/react-overlay/utils/get-file-source.js +21 -0
- package/dist/error-overlay/react-overlay/utils/get-lines-around.d.ts +14 -0
- package/dist/error-overlay/react-overlay/utils/get-lines-around.js +24 -0
- package/dist/error-overlay/react-overlay/utils/get-source-map.d.ts +13 -0
- package/dist/error-overlay/react-overlay/utils/get-source-map.js +58 -0
- package/dist/error-overlay/react-overlay/utils/get-stack-frames.d.ts +2 -0
- package/dist/error-overlay/react-overlay/utils/get-stack-frames.js +27 -0
- package/dist/error-overlay/react-overlay/utils/open-in-editor.d.ts +12 -0
- package/dist/error-overlay/react-overlay/utils/open-in-editor.js +459 -0
- package/dist/error-overlay/react-overlay/utils/parser.d.ts +2 -0
- package/dist/error-overlay/react-overlay/utils/parser.js +117 -0
- package/dist/error-overlay/react-overlay/utils/stack-frame.d.ts +40 -0
- package/dist/error-overlay/react-overlay/utils/stack-frame.js +31 -0
- package/dist/error-overlay/react-overlay/utils/unmapper.d.ts +2 -0
- package/dist/error-overlay/react-overlay/utils/unmapper.js +64 -0
- package/dist/error-overlay/remotion-overlay/AskOnDiscord.d.ts +2 -0
- package/dist/error-overlay/remotion-overlay/AskOnDiscord.js +14 -0
- package/dist/error-overlay/remotion-overlay/Button.d.ts +6 -0
- package/dist/error-overlay/remotion-overlay/Button.js +24 -0
- package/dist/error-overlay/remotion-overlay/CodeFrame.d.ts +6 -0
- package/dist/error-overlay/remotion-overlay/CodeFrame.js +28 -0
- package/dist/error-overlay/remotion-overlay/DismissButton.d.ts +2 -0
- package/dist/error-overlay/remotion-overlay/DismissButton.js +23 -0
- package/dist/error-overlay/remotion-overlay/ErrorDisplay.d.ts +5 -0
- package/dist/error-overlay/remotion-overlay/ErrorDisplay.js +45 -0
- package/dist/error-overlay/remotion-overlay/ErrorLoader.d.ts +4 -0
- package/dist/error-overlay/remotion-overlay/ErrorLoader.js +61 -0
- package/dist/error-overlay/remotion-overlay/ErrorTitle.d.ts +6 -0
- package/dist/error-overlay/remotion-overlay/ErrorTitle.js +41 -0
- package/dist/error-overlay/remotion-overlay/OpenInEditor.d.ts +5 -0
- package/dist/error-overlay/remotion-overlay/OpenInEditor.js +90 -0
- package/dist/error-overlay/remotion-overlay/Overlay.d.ts +14 -0
- package/dist/error-overlay/remotion-overlay/Overlay.js +49 -0
- package/dist/error-overlay/remotion-overlay/SearchGitHubIssues.d.ts +4 -0
- package/dist/error-overlay/remotion-overlay/SearchGitHubIssues.js +13 -0
- package/dist/error-overlay/remotion-overlay/StackFrame.d.ts +8 -0
- package/dist/error-overlay/remotion-overlay/StackFrame.js +48 -0
- package/dist/error-overlay/remotion-overlay/Symbolicating.d.ts +2 -0
- package/dist/error-overlay/remotion-overlay/Symbolicating.js +8 -0
- package/dist/error-overlay/remotion-overlay/carets.d.ts +3 -0
- package/dist/error-overlay/remotion-overlay/carets.js +12 -0
- package/dist/error-overlay/remotion-overlay/format-location.d.ts +1 -0
- package/dist/error-overlay/remotion-overlay/format-location.js +10 -0
- package/dist/error-overlay/remotion-overlay/index.d.ts +1 -0
- package/dist/error-overlay/remotion-overlay/index.js +18 -0
- package/dist/get-latest-remotion-version.d.ts +1 -0
- package/dist/get-latest-remotion-version.js +31 -0
- package/dist/get-package-manager.d.ts +8 -0
- package/dist/get-package-manager.js +38 -0
- package/dist/get-port.d.ts +1 -0
- package/dist/get-port.js +80 -0
- package/dist/hot-middleware/client.d.ts +19 -0
- package/dist/hot-middleware/client.js +206 -0
- package/dist/hot-middleware/index.d.ts +13 -0
- package/dist/hot-middleware/index.js +180 -0
- package/dist/hot-middleware/process-update.d.ts +12 -0
- package/dist/hot-middleware/process-update.js +147 -0
- package/dist/hot-middleware/strip-ansi.d.ts +1 -0
- package/dist/hot-middleware/strip-ansi.js +21 -0
- package/dist/hot-middleware/types.d.ts +37 -0
- package/dist/hot-middleware/types.js +17 -0
- package/dist/is-path-inside.d.ts +1 -0
- package/dist/is-path-inside.js +27 -0
- package/dist/p-limit.d.ts +1 -0
- package/dist/p-limit.js +57 -0
- package/dist/project-info.d.ts +5 -0
- package/dist/project-info.js +22 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +121 -0
- package/dist/serve-static.d.ts +9 -0
- package/dist/serve-static.js +81 -0
- package/dist/setup-environment.js +3 -1
- package/dist/start-server-pure.d.ts +8 -0
- package/dist/start-server-pure.js +68 -0
- package/dist/start-server.d.ts +8 -0
- package/dist/start-server.js +132 -0
- package/dist/static-preview.d.ts +1 -0
- package/dist/static-preview.js +40 -0
- package/dist/test/expect-to-throw.d.ts +1 -0
- package/dist/test/expect-to-throw.js +14 -0
- package/dist/test/latest-remotion-version.test.d.ts +1 -0
- package/dist/test/latest-remotion-version.test.js +6 -0
- package/dist/test/parse-error-stack.test.d.ts +1 -0
- package/dist/test/parse-error-stack.test.js +17 -0
- package/dist/test/parse-module-not-found.test.d.ts +1 -0
- package/dist/test/parse-module-not-found.test.js +17 -0
- package/dist/test/secure-source-read.test.d.ts +1 -0
- package/dist/test/secure-source-read.test.js +8 -0
- package/dist/ts-alias-plugin.d.ts +4 -0
- package/dist/ts-alias-plugin.js +21 -0
- package/dist/update-available.d.ts +10 -0
- package/dist/update-available.js +36 -0
- package/package.json +3 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WebpackOverrideFn } from 'remotion';
|
|
2
|
+
export declare const bundle: (entryPoint: string, onProgressUpdate?: ((progress: number) => void) | undefined, options?: {
|
|
3
|
+
webpackOverride?: WebpackOverrideFn | undefined;
|
|
4
|
+
outDir?: string | undefined;
|
|
5
|
+
enableCaching?: boolean | undefined;
|
|
6
|
+
publicPath?: string | undefined;
|
|
7
|
+
} | undefined) => Promise<string>;
|
package/dist/bundler.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.bundle = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const remotion_1 = require("remotion");
|
|
11
|
+
const util_1 = require("util");
|
|
12
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
13
|
+
const copy_dir_1 = require("./copy-dir");
|
|
14
|
+
const static_preview_1 = require("./static-preview");
|
|
15
|
+
const webpack_config_1 = require("./webpack-config");
|
|
16
|
+
const entry = require.resolve('./renderEntry');
|
|
17
|
+
const promisified = (0, util_1.promisify)(webpack_1.default);
|
|
18
|
+
const prepareOutDir = async (specified) => {
|
|
19
|
+
if (specified) {
|
|
20
|
+
await fs_1.default.promises.mkdir(specified, { recursive: true });
|
|
21
|
+
return specified;
|
|
22
|
+
}
|
|
23
|
+
return fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'react-motion-graphics'));
|
|
24
|
+
};
|
|
25
|
+
const trimLeadingSlash = (p) => {
|
|
26
|
+
if (p.startsWith('/')) {
|
|
27
|
+
return trimLeadingSlash(p.substr(1));
|
|
28
|
+
}
|
|
29
|
+
return p;
|
|
30
|
+
};
|
|
31
|
+
const trimTrailingSlash = (p) => {
|
|
32
|
+
if (p.endsWith('/')) {
|
|
33
|
+
return trimTrailingSlash(p.substr(0, p.length - 1));
|
|
34
|
+
}
|
|
35
|
+
return p;
|
|
36
|
+
};
|
|
37
|
+
const bundle = async (entryPoint, onProgressUpdate, options) => {
|
|
38
|
+
var _a, _b, _c, _d;
|
|
39
|
+
const outDir = await prepareOutDir((_a = options === null || options === void 0 ? void 0 : options.outDir) !== null && _a !== void 0 ? _a : null);
|
|
40
|
+
const output = await promisified([
|
|
41
|
+
(0, webpack_config_1.webpackConfig)({
|
|
42
|
+
entry,
|
|
43
|
+
userDefinedComponent: entryPoint,
|
|
44
|
+
outDir,
|
|
45
|
+
environment: 'production',
|
|
46
|
+
webpackOverride: (_b = options === null || options === void 0 ? void 0 : options.webpackOverride) !== null && _b !== void 0 ? _b : remotion_1.Internals.defaultOverrideFunction,
|
|
47
|
+
onProgressUpdate,
|
|
48
|
+
enableCaching: (_c = options === null || options === void 0 ? void 0 : options.enableCaching) !== null && _c !== void 0 ? _c : remotion_1.Internals.DEFAULT_WEBPACK_CACHE_ENABLED,
|
|
49
|
+
maxTimelineTracks: 15,
|
|
50
|
+
// For production, the variables are set dynamically
|
|
51
|
+
envVariables: {},
|
|
52
|
+
inputProps: {},
|
|
53
|
+
}),
|
|
54
|
+
]);
|
|
55
|
+
if (!output) {
|
|
56
|
+
throw new Error('Expected webpack output');
|
|
57
|
+
}
|
|
58
|
+
const { errors } = output.toJson();
|
|
59
|
+
if (errors !== undefined && errors.length > 0) {
|
|
60
|
+
throw new Error(errors[0].message + '\n' + errors[0].details);
|
|
61
|
+
}
|
|
62
|
+
const baseDir = (_d = options === null || options === void 0 ? void 0 : options.publicPath) !== null && _d !== void 0 ? _d : '/';
|
|
63
|
+
const publicDir = '/' +
|
|
64
|
+
[trimTrailingSlash(trimLeadingSlash(baseDir)), 'public']
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join('/');
|
|
67
|
+
const from = path_1.default.join(process.cwd(), 'public');
|
|
68
|
+
const to = path_1.default.join(outDir, 'public');
|
|
69
|
+
if (fs_1.default.existsSync(from)) {
|
|
70
|
+
await (0, copy_dir_1.copyDir)(from, to);
|
|
71
|
+
}
|
|
72
|
+
const html = (0, static_preview_1.indexHtml)(publicDir, baseDir, null);
|
|
73
|
+
fs_1.default.writeFileSync(path_1.default.join(outDir, 'index.html'), html);
|
|
74
|
+
return outDir;
|
|
75
|
+
};
|
|
76
|
+
exports.bundle = bundle;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
|
+
import { ReadStream } from 'fs';
|
|
5
|
+
export declare function getHeaderNames(res: Response): string[];
|
|
6
|
+
export declare function getHeaderFromRequest(req: Request, name: string): string | string[] | undefined;
|
|
7
|
+
export declare function getHeaderFromResponse(res: Response, name: string): string;
|
|
8
|
+
export declare function setHeaderForResponse(res: Response, name: string, value: string | number): void;
|
|
9
|
+
export declare function setStatusCode(res: Response, code: number): void;
|
|
10
|
+
export declare function send(req: Request, res: Response, bufferOtStream: ReadStream | string | Buffer, byteLength: number): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.send = exports.setStatusCode = exports.setHeaderForResponse = exports.getHeaderFromResponse = exports.getHeaderFromRequest = exports.getHeaderNames = void 0;
|
|
4
|
+
function getHeaderNames(res) {
|
|
5
|
+
if (typeof res.getHeaderNames !== 'function') {
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
return Object.keys(res._headers || {});
|
|
8
|
+
}
|
|
9
|
+
return res.getHeaderNames();
|
|
10
|
+
}
|
|
11
|
+
exports.getHeaderNames = getHeaderNames;
|
|
12
|
+
function getHeaderFromRequest(req, name) {
|
|
13
|
+
// Express API
|
|
14
|
+
if (typeof req.get === 'function') {
|
|
15
|
+
return req.get(name);
|
|
16
|
+
}
|
|
17
|
+
return req.headers[name];
|
|
18
|
+
}
|
|
19
|
+
exports.getHeaderFromRequest = getHeaderFromRequest;
|
|
20
|
+
function getHeaderFromResponse(res, name) {
|
|
21
|
+
return res.get(name);
|
|
22
|
+
}
|
|
23
|
+
exports.getHeaderFromResponse = getHeaderFromResponse;
|
|
24
|
+
function setHeaderForResponse(res, name, value) {
|
|
25
|
+
res.set(name, typeof value === 'number' ? String(value) : value);
|
|
26
|
+
}
|
|
27
|
+
exports.setHeaderForResponse = setHeaderForResponse;
|
|
28
|
+
function setStatusCode(res, code) {
|
|
29
|
+
res.status(code);
|
|
30
|
+
}
|
|
31
|
+
exports.setStatusCode = setStatusCode;
|
|
32
|
+
function send(req, res, bufferOtStream, byteLength) {
|
|
33
|
+
if (typeof bufferOtStream === 'string' || Buffer.isBuffer(bufferOtStream)) {
|
|
34
|
+
res.send(bufferOtStream);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setHeaderForResponse(res, 'Content-Length', byteLength);
|
|
38
|
+
if (req.method === 'HEAD') {
|
|
39
|
+
res.end();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
bufferOtStream.pipe(res);
|
|
43
|
+
}
|
|
44
|
+
exports.send = send;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFilenameFromUrl = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
// eslint-disable-next-line no-restricted-imports
|
|
9
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
10
|
+
const url_1 = require("url");
|
|
11
|
+
const get_paths_1 = require("./get-paths");
|
|
12
|
+
const cacheStore = new WeakMap();
|
|
13
|
+
const mem = (fn, { cache = new Map() } = {}) => {
|
|
14
|
+
const memoized = (...arguments_) => {
|
|
15
|
+
const [key] = arguments_;
|
|
16
|
+
const cacheItem = cache.get(key);
|
|
17
|
+
if (cacheItem) {
|
|
18
|
+
return cacheItem.data;
|
|
19
|
+
}
|
|
20
|
+
const result = fn.apply(this, arguments_);
|
|
21
|
+
cache.set(key, {
|
|
22
|
+
data: result,
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
cacheStore.set(memoized, cache);
|
|
27
|
+
return memoized;
|
|
28
|
+
};
|
|
29
|
+
const memoizedParse = mem(url_1.parse);
|
|
30
|
+
function getFilenameFromUrl(context, url) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const paths = (0, get_paths_1.getPaths)(context);
|
|
33
|
+
let foundFilename;
|
|
34
|
+
let urlObject;
|
|
35
|
+
try {
|
|
36
|
+
// The `url` property of the `request` is contains only `pathname`, `search` and `hash`
|
|
37
|
+
urlObject = memoizedParse(url, false, true);
|
|
38
|
+
}
|
|
39
|
+
catch (_ignoreError) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const { publicPath, outputPath } of paths) {
|
|
43
|
+
let filename;
|
|
44
|
+
let publicPathObject;
|
|
45
|
+
try {
|
|
46
|
+
publicPathObject = memoizedParse(publicPath !== 'auto' && publicPath ? publicPath : '/', false, true);
|
|
47
|
+
}
|
|
48
|
+
catch (_ignoreError) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if ((_a = urlObject.pathname) === null || _a === void 0 ? void 0 : _a.startsWith(publicPathObject.pathname)) {
|
|
52
|
+
filename = outputPath;
|
|
53
|
+
// Strip the `pathname` property from the `publicPath` option from the start of requested url
|
|
54
|
+
// `/complex/foo.js` => `foo.js`
|
|
55
|
+
const pathname = urlObject.pathname.substr(publicPathObject.pathname.length);
|
|
56
|
+
if (pathname) {
|
|
57
|
+
filename = path_1.default.join(outputPath, querystring_1.default.unescape(pathname));
|
|
58
|
+
}
|
|
59
|
+
if (!context.outputFileSystem) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
let fsStats = (_b = context.outputFileSystem) === null || _b === void 0 ? void 0 : _b.statSync(filename);
|
|
64
|
+
if (fsStats.isFile()) {
|
|
65
|
+
foundFilename = filename;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
else if (fsStats.isDirectory()) {
|
|
69
|
+
const indexValue = 'index.html';
|
|
70
|
+
filename = path_1.default.join(filename, indexValue);
|
|
71
|
+
// eslint-disable-next-line max-depth
|
|
72
|
+
try {
|
|
73
|
+
fsStats = context.outputFileSystem.statSync(filename);
|
|
74
|
+
}
|
|
75
|
+
catch (__ignoreError) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line max-depth
|
|
79
|
+
if (fsStats.isFile()) {
|
|
80
|
+
foundFilename = filename;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (_ignoreError) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return foundFilename;
|
|
91
|
+
}
|
|
92
|
+
exports.getFilenameFromUrl = getFilenameFromUrl;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPaths = void 0;
|
|
4
|
+
function getPaths(context) {
|
|
5
|
+
const { stats } = context;
|
|
6
|
+
const publicPaths = [];
|
|
7
|
+
if (!stats) {
|
|
8
|
+
return publicPaths;
|
|
9
|
+
}
|
|
10
|
+
const { compilation } = stats;
|
|
11
|
+
// The `output.path` is always present and always absolute
|
|
12
|
+
const outputPath = compilation.getPath(compilation.outputOptions.path || '');
|
|
13
|
+
const publicPath = compilation.outputOptions.publicPath
|
|
14
|
+
? compilation.getPath(compilation.outputOptions.publicPath)
|
|
15
|
+
: '';
|
|
16
|
+
publicPaths.push({ outputPath, publicPath });
|
|
17
|
+
return publicPaths;
|
|
18
|
+
}
|
|
19
|
+
exports.getPaths = getPaths;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wdm = void 0;
|
|
4
|
+
const get_filename_from_url_1 = require("./get-filename-from-url");
|
|
5
|
+
const middleware_1 = require("./middleware");
|
|
6
|
+
const ready_1 = require("./ready");
|
|
7
|
+
const setup_hooks_1 = require("./setup-hooks");
|
|
8
|
+
const setup_output_filesystem_1 = require("./setup-output-filesystem");
|
|
9
|
+
const noop = () => undefined;
|
|
10
|
+
const wdm = (compiler) => {
|
|
11
|
+
const context = {
|
|
12
|
+
state: false,
|
|
13
|
+
stats: undefined,
|
|
14
|
+
callbacks: [],
|
|
15
|
+
compiler,
|
|
16
|
+
watching: undefined,
|
|
17
|
+
logger: compiler.getInfrastructureLogger('webpack-dev-middleware'),
|
|
18
|
+
outputFileSystem: undefined,
|
|
19
|
+
};
|
|
20
|
+
(0, setup_hooks_1.setupHooks)(context);
|
|
21
|
+
(0, setup_output_filesystem_1.setupOutputFileSystem)(context);
|
|
22
|
+
// Start watching
|
|
23
|
+
if (context.compiler.watching) {
|
|
24
|
+
context.watching = context.compiler.watching;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const errorHandler = (error) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
context.logger.error(error);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const watchOptions = context.compiler.options.watchOptions || {};
|
|
33
|
+
context.watching = context.compiler.watch(watchOptions, errorHandler);
|
|
34
|
+
}
|
|
35
|
+
const instance = (0, middleware_1.middleware)(context);
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
instance.getFilenameFromUrl = (url) => (0, get_filename_from_url_1.getFilenameFromUrl)(context, url);
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
instance.waitUntilValid = (callback = noop) => {
|
|
40
|
+
(0, ready_1.ready)(context, callback);
|
|
41
|
+
};
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
instance.invalidate = (callback = noop) => {
|
|
44
|
+
var _a;
|
|
45
|
+
(0, ready_1.ready)(context, callback);
|
|
46
|
+
(_a = context.watching) === null || _a === void 0 ? void 0 : _a.invalidate();
|
|
47
|
+
};
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
instance.close = (callback = noop) => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = context.watching) === null || _a === void 0 ? void 0 : _a.close(callback);
|
|
52
|
+
};
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
instance.context = context;
|
|
55
|
+
return instance;
|
|
56
|
+
};
|
|
57
|
+
exports.wdm = wdm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isColorSupported: boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var _a;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.isColorSupported = void 0;
|
|
28
|
+
const tty = __importStar(require("tty"));
|
|
29
|
+
const argv = process.argv || [];
|
|
30
|
+
const env = process.env || {};
|
|
31
|
+
const isDisabled = 'NO_COLOR' in env || argv.includes('--no-color');
|
|
32
|
+
const isForced = 'FORCE_COLOR' in env || argv.includes('--color');
|
|
33
|
+
const isWindows = process.platform === 'win32';
|
|
34
|
+
const isCompatibleTerminal = ((_a = tty === null || tty === void 0 ? void 0 : tty.isatty) === null || _a === void 0 ? void 0 : _a.call(tty, 1)) && env.TERM && env.TERM !== 'dumb';
|
|
35
|
+
const isCI = 'CI' in env &&
|
|
36
|
+
('GITHUB_ACTIONS' in env || 'GITLAB_CI' in env || 'CIRCLECI' in env);
|
|
37
|
+
exports.isColorSupported = !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import { DevMiddlewareContext } from './types';
|
|
3
|
+
export declare type MiddleWare = (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
4
|
+
export declare function middleware(context: DevMiddlewareContext): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.middleware = void 0;
|
|
7
|
+
const mime_types_1 = __importDefault(require("mime-types"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const compatible_api_1 = require("./compatible-api");
|
|
10
|
+
const get_filename_from_url_1 = require("./get-filename-from-url");
|
|
11
|
+
const range_parser_1 = require("./range-parser");
|
|
12
|
+
const ready_1 = require("./ready");
|
|
13
|
+
function getValueContentRangeHeader(type, size, range) {
|
|
14
|
+
return `${type} ${range ? `${range.start}-${range.end}` : '*'}/${size}`;
|
|
15
|
+
}
|
|
16
|
+
function createHtmlDocument(title, body) {
|
|
17
|
+
return (`${'<!DOCTYPE html>\n' +
|
|
18
|
+
'<html lang="en">\n' +
|
|
19
|
+
'<head>\n' +
|
|
20
|
+
'<meta charset="utf-8">\n' +
|
|
21
|
+
'<title>'}${title}</title>\n` +
|
|
22
|
+
`</head>\n` +
|
|
23
|
+
`<body>\n` +
|
|
24
|
+
`<pre>${body}</pre>\n` +
|
|
25
|
+
`</body>\n` +
|
|
26
|
+
`</html>\n`);
|
|
27
|
+
}
|
|
28
|
+
const BYTES_RANGE_REGEXP = /^ *bytes/i;
|
|
29
|
+
function middleware(context) {
|
|
30
|
+
return async function (req, res, next) {
|
|
31
|
+
const acceptedMethods = ['GET', 'HEAD'];
|
|
32
|
+
// fixes #282. credit @cexoso. in certain edge situations res.locals is undefined.
|
|
33
|
+
res.locals = res.locals || {};
|
|
34
|
+
if (req.method && !acceptedMethods.includes(req.method)) {
|
|
35
|
+
await goNext();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(0, ready_1.ready)(context, processRequest, req);
|
|
39
|
+
function goNext() {
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
async function processRequest() {
|
|
43
|
+
var _a;
|
|
44
|
+
const filename = (0, get_filename_from_url_1.getFilenameFromUrl)(context, req.url);
|
|
45
|
+
if (!filename) {
|
|
46
|
+
await goNext();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @type {{key: string, value: string | number}[]}
|
|
51
|
+
*/
|
|
52
|
+
if (!(0, compatible_api_1.getHeaderFromResponse)(res, 'Content-Type')) {
|
|
53
|
+
// content-type name(like application/javascript; charset=utf-8) or false
|
|
54
|
+
const contentType = mime_types_1.default.contentType(path_1.default.extname(filename));
|
|
55
|
+
// Only set content-type header if media type is known
|
|
56
|
+
// https://tools.ietf.org/html/rfc7231#section-3.1.1.5
|
|
57
|
+
if (contentType) {
|
|
58
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Content-Type', contentType);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!(0, compatible_api_1.getHeaderFromResponse)(res, 'Accept-Ranges')) {
|
|
62
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Accept-Ranges', 'bytes');
|
|
63
|
+
}
|
|
64
|
+
const rangeHeader = (0, compatible_api_1.getHeaderFromRequest)(req, 'range');
|
|
65
|
+
let start;
|
|
66
|
+
let end;
|
|
67
|
+
if (rangeHeader &&
|
|
68
|
+
BYTES_RANGE_REGEXP.test(rangeHeader) &&
|
|
69
|
+
context.outputFileSystem) {
|
|
70
|
+
const size = await new Promise((resolve) => {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = context.outputFileSystem) === null || _a === void 0 ? void 0 : _a.lstat(filename, (error, stats) => {
|
|
73
|
+
var _a;
|
|
74
|
+
if (error) {
|
|
75
|
+
context.logger.error(error);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
resolve((_a = stats === null || stats === void 0 ? void 0 : stats.size) !== null && _a !== void 0 ? _a : 0);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const parsedRanges = (0, range_parser_1.parseRange)(size, rangeHeader);
|
|
82
|
+
if (parsedRanges === -1) {
|
|
83
|
+
const message = "Unsatisfiable range for 'Range' header.";
|
|
84
|
+
context.logger.error(message);
|
|
85
|
+
const existingHeaders = (0, compatible_api_1.getHeaderNames)(res);
|
|
86
|
+
for (let i = 0; i < existingHeaders.length; i++) {
|
|
87
|
+
res.removeHeader(existingHeaders[i]);
|
|
88
|
+
}
|
|
89
|
+
(0, compatible_api_1.setStatusCode)(res, 416);
|
|
90
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Content-Range', getValueContentRangeHeader('bytes', size));
|
|
91
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Content-Type', 'text/html; charset=utf-8');
|
|
92
|
+
const document = createHtmlDocument(416, `Error: ${message}`);
|
|
93
|
+
const _byteLength = Buffer.byteLength(document);
|
|
94
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Content-Length', Buffer.byteLength(document));
|
|
95
|
+
(0, compatible_api_1.send)(req, res, document, _byteLength);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (parsedRanges === -2) {
|
|
99
|
+
context.logger.error("A malformed 'Range' header was provided. A regular response will be sent for this request.");
|
|
100
|
+
}
|
|
101
|
+
else if (parsedRanges.length > 1) {
|
|
102
|
+
context.logger.error("A 'Range' header with multiple ranges was provided. Multiple ranges are not supported, so a regular response will be sent for this request.");
|
|
103
|
+
}
|
|
104
|
+
if (parsedRanges !== -2 && parsedRanges.length === 1) {
|
|
105
|
+
// Content-Range
|
|
106
|
+
(0, compatible_api_1.setStatusCode)(res, 206);
|
|
107
|
+
(0, compatible_api_1.setHeaderForResponse)(res, 'Content-Range', getValueContentRangeHeader('bytes', size, parsedRanges[0]));
|
|
108
|
+
[{ start, end }] = parsedRanges;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const isFsSupportsStream = typeof ((_a = context.outputFileSystem) === null || _a === void 0 ? void 0 : _a.createReadStream) === 'function';
|
|
112
|
+
let bufferOtStream;
|
|
113
|
+
let byteLength = 0;
|
|
114
|
+
try {
|
|
115
|
+
if (typeof start !== 'undefined' &&
|
|
116
|
+
typeof end !== 'undefined' &&
|
|
117
|
+
isFsSupportsStream &&
|
|
118
|
+
context.outputFileSystem) {
|
|
119
|
+
bufferOtStream = context.outputFileSystem.createReadStream(filename, {
|
|
120
|
+
start,
|
|
121
|
+
end,
|
|
122
|
+
});
|
|
123
|
+
byteLength = end - start + 1;
|
|
124
|
+
}
|
|
125
|
+
else if (context.outputFileSystem) {
|
|
126
|
+
bufferOtStream = context.outputFileSystem.readFileSync(filename);
|
|
127
|
+
// @ts-expect-error
|
|
128
|
+
byteLength = bufferOtStream.byteLength;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (_ignoreError) {
|
|
132
|
+
await goNext();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (bufferOtStream) {
|
|
136
|
+
(0, compatible_api_1.send)(req, res, bufferOtStream, byteLength);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
exports.middleware = middleware;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* range-parser
|
|
3
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
4
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
declare type Range = {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
};
|
|
11
|
+
declare type Ranges = Range[] & {
|
|
12
|
+
type?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function parseRange(size: number, str: string | string[]): Ranges | -1 | -2;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* range-parser
|
|
4
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
5
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
6
|
+
* MIT Licensed
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.parseRange = void 0;
|
|
10
|
+
function parseRange(size, str) {
|
|
11
|
+
if (typeof str !== 'string') {
|
|
12
|
+
throw new TypeError('argument str must be a string');
|
|
13
|
+
}
|
|
14
|
+
const index = str.indexOf('=');
|
|
15
|
+
if (index === -1) {
|
|
16
|
+
return -2;
|
|
17
|
+
}
|
|
18
|
+
// split the range string
|
|
19
|
+
const arr = str.slice(index + 1).split(',');
|
|
20
|
+
const ranges = [];
|
|
21
|
+
// add ranges type
|
|
22
|
+
ranges.type = str.slice(0, index);
|
|
23
|
+
// parse all ranges
|
|
24
|
+
for (let i = 0; i < arr.length; i++) {
|
|
25
|
+
const range = arr[i].split('-');
|
|
26
|
+
let start = parseInt(range[0], 10);
|
|
27
|
+
let end = parseInt(range[1], 10);
|
|
28
|
+
// -nnn
|
|
29
|
+
if (isNaN(start)) {
|
|
30
|
+
start = size - end;
|
|
31
|
+
end = size - 1;
|
|
32
|
+
// nnn-
|
|
33
|
+
}
|
|
34
|
+
else if (isNaN(end)) {
|
|
35
|
+
end = size - 1;
|
|
36
|
+
}
|
|
37
|
+
// limit last-byte-pos to current length
|
|
38
|
+
if (end > size - 1) {
|
|
39
|
+
end = size - 1;
|
|
40
|
+
}
|
|
41
|
+
// invalid or unsatisifiable
|
|
42
|
+
if (isNaN(start) || isNaN(end) || start > end || start < 0) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// add range
|
|
46
|
+
ranges.push({
|
|
47
|
+
start,
|
|
48
|
+
end,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (ranges.length < 1) {
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
return combineRanges(ranges);
|
|
55
|
+
}
|
|
56
|
+
exports.parseRange = parseRange;
|
|
57
|
+
function combineRanges(ranges) {
|
|
58
|
+
const ordered = ranges.map(mapWithIndex).sort(sortByRangeStart);
|
|
59
|
+
let j = 0;
|
|
60
|
+
for (let i = 1; i < ordered.length; i++) {
|
|
61
|
+
const range = ordered[i];
|
|
62
|
+
const current = ordered[j];
|
|
63
|
+
if (range.start > current.end + 1) {
|
|
64
|
+
// next range
|
|
65
|
+
ordered[++j] = range;
|
|
66
|
+
}
|
|
67
|
+
else if (range.end > current.end) {
|
|
68
|
+
// extend range
|
|
69
|
+
current.end = range.end;
|
|
70
|
+
current.index = Math.min(current.index, range.index);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
ordered.length = j + 1;
|
|
74
|
+
const combined = ordered.sort(sortByRangeIndex).map(mapWithoutIndex);
|
|
75
|
+
combined.type = ranges.type;
|
|
76
|
+
return combined;
|
|
77
|
+
}
|
|
78
|
+
function mapWithIndex(range, index) {
|
|
79
|
+
return {
|
|
80
|
+
start: range.start,
|
|
81
|
+
end: range.end,
|
|
82
|
+
index,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function mapWithoutIndex(range) {
|
|
86
|
+
return {
|
|
87
|
+
start: range.start,
|
|
88
|
+
end: range.end,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function sortByRangeIndex(a, b) {
|
|
92
|
+
return a.index - b.index;
|
|
93
|
+
}
|
|
94
|
+
function sortByRangeStart(a, b) {
|
|
95
|
+
return a.start - b.start;
|
|
96
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage } from 'http';
|
|
3
|
+
import webpack from 'webpack';
|
|
4
|
+
import { DevMiddlewareContext } from './types';
|
|
5
|
+
export declare function ready(context: DevMiddlewareContext, callback: (stats: webpack.Stats | undefined) => undefined | Promise<void>, req?: IncomingMessage): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ready = void 0;
|
|
4
|
+
function ready(context, callback, req) {
|
|
5
|
+
if (context.state) {
|
|
6
|
+
callback(context.stats);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const name = (req === null || req === void 0 ? void 0 : req.url) || callback.name;
|
|
10
|
+
context.logger.info(`wait until bundle finished${name ? `: ${name}` : ''}`);
|
|
11
|
+
context.callbacks.push(callback);
|
|
12
|
+
}
|
|
13
|
+
exports.ready = ready;
|