xhs-mp-compiler-cli 1.4.0-beta.2 → 1.4.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.
- package/dist/compiler.d.ts +13 -15
- package/dist/compiler.js +40 -96
- package/dist/{compilerImpl.js → compilerCP.js} +42 -29
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -5
- package/dist/packs/mp-pack/index.js +1 -0
- package/dist/packs/webpack/dev-server/index.js +0 -1
- package/dist/packs/webpack/index.d.ts +1 -1
- package/dist/packs/webpack/index.js +4 -3
- package/dist/packs/webpack/webpack.d.ts +1 -1
- package/dist/packs/webpack/webpack.js +2 -6
- package/dist/presets/configs/miniprogram/render/index.d.ts +3 -2
- package/dist/presets/configs/miniprogram/render/index.js +2 -2
- package/dist/presets/configs/miniprogram/service/index.js +0 -1
- package/dist/utils/apm/index.js +30 -13
- package/package.json +12 -26
- package/dist/compilerImpl.d.ts +0 -1
- package/dist/compilerImplChildProcess.js +0 -33
- package/dist/compilerImplThreadWorker.d.ts +0 -1
- package/dist/compilerImplThreadWorker.js +0 -30
- package/dist/compilerImplWebWorker.d.ts +0 -6
- package/dist/compilerImplWebWorker.js +0 -25
- package/dist/dev-server/compatibleAPI.d.ts +0 -25
- package/dist/dev-server/compatibleAPI.js +0 -56
- package/dist/dev-server/escapeHtml.d.ts +0 -5
- package/dist/dev-server/escapeHtml.js +0 -50
- package/dist/dev-server/etag.d.ts +0 -10
- package/dist/dev-server/etag.js +0 -69
- package/dist/dev-server/getFilenameFromUrl.d.ts +0 -9
- package/dist/dev-server/getFilenameFromUrl.js +0 -102
- package/dist/dev-server/getPaths.d.ts +0 -6
- package/dist/dev-server/getPaths.js +0 -20
- package/dist/dev-server/index.d.ts +0 -98
- package/dist/dev-server/index.js +0 -90
- package/dist/dev-server/memorize.d.ts +0 -7
- package/dist/dev-server/memorize.js +0 -23
- package/dist/dev-server/middleware.d.ts +0 -2
- package/dist/dev-server/middleware.js +0 -477
- package/dist/dev-server/ready.d.ts +0 -4
- package/dist/dev-server/ready.js +0 -11
- package/dist/sharedFs.d.ts +0 -2
- package/dist/sharedFs.js +0 -4
- package/dist/utils/workerPool.d.ts +0 -29
- package/dist/utils/workerPool.js +0 -115
- /package/dist/{compilerImplChildProcess.d.ts → compilerCP.d.ts} +0 -0
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node/http" />
|
|
3
|
-
/// <reference types="node/fs" />
|
|
4
|
-
import { MultiCompiler, Compiler, MultiStats, Stats } from 'xhs-mp-pack';
|
|
5
|
-
import { IncomingMessage, ServerResponse as NodeServerResponse } from "http";
|
|
6
|
-
import { ReadStream } from "fs";
|
|
7
|
-
import type { ExpectedResponse } from "./compatibleAPI";
|
|
8
|
-
import { Extra } from "./getFilenameFromUrl";
|
|
9
|
-
import { AbstractCompiler } from "../compiler";
|
|
10
|
-
export type ExtendedServerResponse = NodeServerResponse & {
|
|
11
|
-
locals?: {
|
|
12
|
-
mppack?: {
|
|
13
|
-
devMiddleware?: Context;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export type Response = ExtendedServerResponse & ExpectedResponse;
|
|
18
|
-
export type NextFunction = (err?: any) => void;
|
|
19
|
-
export type WatchOptions = NonNullable<any>;
|
|
20
|
-
export type Watching = Compiler["watching"];
|
|
21
|
-
export type MultiWatching = ReturnType<MultiCompiler["watch"]>;
|
|
22
|
-
export type OutputFileSystem = {
|
|
23
|
-
createReadStream?: typeof import("fs").createReadStream;
|
|
24
|
-
statSync?: typeof import("fs").statSync;
|
|
25
|
-
lstat?: typeof import("fs").lstat;
|
|
26
|
-
readFileSync?: typeof import("fs").readFileSync;
|
|
27
|
-
};
|
|
28
|
-
type Logger = ReturnType<Compiler["getInfrastructureLogger"]>;
|
|
29
|
-
interface ResponseData {
|
|
30
|
-
data: Buffer | ReadStream;
|
|
31
|
-
byteLength: number;
|
|
32
|
-
}
|
|
33
|
-
export { IncomingMessage };
|
|
34
|
-
type ModifyResponseData = (req: Request, res: Response, data: Buffer | ReadStream, byteLength: number) => ResponseData;
|
|
35
|
-
export interface Context {
|
|
36
|
-
state: boolean;
|
|
37
|
-
stats: Stats | MultiStats | undefined;
|
|
38
|
-
callbacks: Array<(stats?: Stats | MultiStats) => void>;
|
|
39
|
-
options: Options;
|
|
40
|
-
compiler: Compiler | MultiCompiler;
|
|
41
|
-
watching: Watching | MultiWatching | undefined;
|
|
42
|
-
logger: Logger;
|
|
43
|
-
outputFileSystem: OutputFileSystem;
|
|
44
|
-
}
|
|
45
|
-
export type FilledContext = Omit<Context, "watching"> & {
|
|
46
|
-
watching: Watching | MultiWatching;
|
|
47
|
-
};
|
|
48
|
-
type NormalizedHeaders = Record<string, string | number> | Array<{
|
|
49
|
-
key: string;
|
|
50
|
-
value: number | string;
|
|
51
|
-
}>;
|
|
52
|
-
type Headers = NormalizedHeaders | ((req: Request, res: Response, context: Context) => void | undefined | NormalizedHeaders) | undefined;
|
|
53
|
-
interface Options {
|
|
54
|
-
mimeTypes?: {
|
|
55
|
-
[key: string]: string;
|
|
56
|
-
};
|
|
57
|
-
mimeTypeDefault?: string;
|
|
58
|
-
writeToDisk?: boolean | ((targetPath: string) => boolean);
|
|
59
|
-
methods?: string[];
|
|
60
|
-
headers?: Headers;
|
|
61
|
-
publicPath?: NonNullable<any>["publicPath"];
|
|
62
|
-
stats?: Stats;
|
|
63
|
-
serverSideRender?: boolean;
|
|
64
|
-
outputFileSystem?: OutputFileSystem;
|
|
65
|
-
index?: boolean | string;
|
|
66
|
-
modifyResponseData?: ModifyResponseData;
|
|
67
|
-
etag?: "weak" | "strong";
|
|
68
|
-
lastModified?: boolean;
|
|
69
|
-
}
|
|
70
|
-
type Middleware = (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
71
|
-
type GetFilenameFromUrl = (url: string, extra?: Extra) => string | undefined;
|
|
72
|
-
type WaitUntilValid = (callback: (stats?: Stats | MultiStats) => void) => void;
|
|
73
|
-
type Invalidate = (callback: (stats?: Stats | MultiStats) => void) => void;
|
|
74
|
-
type Close = (callback: (err: Error | null | undefined) => void) => void;
|
|
75
|
-
interface AdditionalMethods {
|
|
76
|
-
getFilenameFromUrl: GetFilenameFromUrl;
|
|
77
|
-
waitUntilValid: WaitUntilValid;
|
|
78
|
-
invalidate: Invalidate;
|
|
79
|
-
close: Close;
|
|
80
|
-
context: Context;
|
|
81
|
-
}
|
|
82
|
-
type API = Middleware & AdditionalMethods;
|
|
83
|
-
declare function MPPackMiddleware(compiler: AbstractCompiler, options?: Options): API;
|
|
84
|
-
declare namespace MPPackMiddleware {
|
|
85
|
-
var koaWrapper: (compiler: AbstractCompiler, options?: Options | undefined) => {
|
|
86
|
-
(ctx: {
|
|
87
|
-
req: Request;
|
|
88
|
-
res: Response;
|
|
89
|
-
status: number;
|
|
90
|
-
body: Buffer | ReadStream | {
|
|
91
|
-
message: string;
|
|
92
|
-
};
|
|
93
|
-
state: Object;
|
|
94
|
-
}, next: Function): Promise<unknown>;
|
|
95
|
-
devMiddleware: API;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
export default MPPackMiddleware;
|
package/dist/dev-server/index.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.IncomingMessage = void 0;
|
|
16
|
-
const mime_types_1 = __importDefault(require("mime-types"));
|
|
17
|
-
const middleware_1 = __importDefault(require("./middleware"));
|
|
18
|
-
const getFilenameFromUrl_1 = __importDefault(require("./getFilenameFromUrl"));
|
|
19
|
-
const ready_1 = __importDefault(require("./ready"));
|
|
20
|
-
const http_1 = require("http");
|
|
21
|
-
Object.defineProperty(exports, "IncomingMessage", { enumerable: true, get: function () { return http_1.IncomingMessage; } });
|
|
22
|
-
function MPPackMiddleware(compiler, options = {}) {
|
|
23
|
-
const { mimeTypes } = options;
|
|
24
|
-
if (mimeTypes) {
|
|
25
|
-
const { types } = mime_types_1.default;
|
|
26
|
-
mime_types_1.default.types = Object.assign(Object.assign({}, types), mimeTypes);
|
|
27
|
-
}
|
|
28
|
-
const context = {
|
|
29
|
-
state: false,
|
|
30
|
-
stats: undefined,
|
|
31
|
-
callbacks: [],
|
|
32
|
-
options,
|
|
33
|
-
compiler,
|
|
34
|
-
logger: console,
|
|
35
|
-
};
|
|
36
|
-
const filledContext = context;
|
|
37
|
-
const instance = (0, middleware_1.default)(filledContext);
|
|
38
|
-
instance.getFilenameFromUrl = (url, extra) => (0, getFilenameFromUrl_1.default)(filledContext, url, extra);
|
|
39
|
-
instance.waitUntilValid = (callback = () => { }) => {
|
|
40
|
-
(0, ready_1.default)(filledContext, callback);
|
|
41
|
-
};
|
|
42
|
-
instance.invalidate = (callback = () => { }) => {
|
|
43
|
-
(0, ready_1.default)(filledContext, callback);
|
|
44
|
-
filledContext.watching.invalidate();
|
|
45
|
-
};
|
|
46
|
-
instance.close = (callback = () => { }) => {
|
|
47
|
-
filledContext.watching.close(callback);
|
|
48
|
-
};
|
|
49
|
-
instance.context = filledContext;
|
|
50
|
-
return instance;
|
|
51
|
-
}
|
|
52
|
-
function koaWrapper(compiler, options) {
|
|
53
|
-
const devMiddleware = MPPackMiddleware(compiler, options);
|
|
54
|
-
const wrapper = function mppackDevMiddleware(ctx, next) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
const { req } = ctx;
|
|
58
|
-
const { res } = ctx;
|
|
59
|
-
res.locals = ctx.state;
|
|
60
|
-
res.status = (status) => {
|
|
61
|
-
ctx.status = status;
|
|
62
|
-
};
|
|
63
|
-
res.pipeInto = (stream) => {
|
|
64
|
-
ctx.body = stream;
|
|
65
|
-
resolve(null);
|
|
66
|
-
};
|
|
67
|
-
res.send = (content) => {
|
|
68
|
-
ctx.body = content;
|
|
69
|
-
resolve(null);
|
|
70
|
-
};
|
|
71
|
-
devMiddleware(req, res, (err) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
reject(err);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
resolve(next());
|
|
77
|
-
}).catch((err) => {
|
|
78
|
-
ctx.status = err.statusCode || err.status || 500;
|
|
79
|
-
ctx.body = {
|
|
80
|
-
message: err.message,
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
wrapper.devMiddleware = devMiddleware;
|
|
87
|
-
return wrapper;
|
|
88
|
-
}
|
|
89
|
-
MPPackMiddleware.koaWrapper = koaWrapper;
|
|
90
|
-
exports.default = MPPackMiddleware;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const cacheStore = new WeakMap();
|
|
3
|
-
function memorize(fn, { cache = new Map() } = {}, callback) {
|
|
4
|
-
const memoized = (...arguments_) => {
|
|
5
|
-
const [key] = arguments_;
|
|
6
|
-
const cacheItem = cache.get(key);
|
|
7
|
-
if (cacheItem) {
|
|
8
|
-
return cacheItem.data;
|
|
9
|
-
}
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
let result = fn.apply(this, arguments_);
|
|
12
|
-
if (callback) {
|
|
13
|
-
result = callback(result);
|
|
14
|
-
}
|
|
15
|
-
cache.set(key, {
|
|
16
|
-
data: result,
|
|
17
|
-
});
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
cacheStore.set(memoized, cache);
|
|
21
|
-
return memoized;
|
|
22
|
-
}
|
|
23
|
-
module.exports = memorize;
|