@umijs/bundler-utils 4.0.0-rc.14 → 4.0.0-rc.17

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.
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { RequestListener } from 'http';
3
+ import { HttpsServerOptions } from './types';
4
+ export type { Server as SpdyServer } from 'spdy';
5
+ export declare function resolveHttpsConfig(httpsConfig: HttpsServerOptions): Promise<{
6
+ key: string;
7
+ cert: string;
8
+ }>;
9
+ export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsServerOptions): Promise<import("https").Server>;
package/dist/https.js ADDED
@@ -0,0 +1,75 @@
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.createHttpsServer = exports.resolveHttpsConfig = void 0;
7
+ const utils_1 = require("@umijs/utils");
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const spdy_1 = __importDefault(require("spdy"));
11
+ const defaultHttpsHosts = [
12
+ 'localhost',
13
+ '127.0.0.1',
14
+ ];
15
+ // vite mode requires a key cert
16
+ async function resolveHttpsConfig(httpsConfig) {
17
+ // Check if mkcert is installed
18
+ try {
19
+ await utils_1.execa.execa('mkcert', ['--version']);
20
+ }
21
+ catch (e) {
22
+ utils_1.logger.error('[HTTPS] The mkcert has not been installed.');
23
+ utils_1.logger.info('[HTTPS] Please follow the guide to install manually.');
24
+ switch (process.platform) {
25
+ case 'darwin':
26
+ console.log(utils_1.chalk.green('$ brew install mkcert'));
27
+ console.log(utils_1.chalk.gray('# If you use firefox, please install nss.'));
28
+ console.log(utils_1.chalk.green('$ brew install nss'));
29
+ console.log(utils_1.chalk.green('$ mkcert -install'));
30
+ break;
31
+ case 'win32':
32
+ console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#windows'));
33
+ break;
34
+ case 'linux':
35
+ console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#linux'));
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ throw new Error(`[HTTPS] mkcert not found.`);
41
+ }
42
+ let { key, cert, hosts } = httpsConfig;
43
+ hosts = hosts || defaultHttpsHosts;
44
+ if (!key || !cert) {
45
+ key = (0, path_1.join)(__dirname, 'umi.key.pem');
46
+ cert = (0, path_1.join)(__dirname, 'umi.pem');
47
+ }
48
+ // Generate cert and key files if they are not exist.
49
+ if (!(0, fs_1.existsSync)(key) || !(0, fs_1.existsSync)(cert)) {
50
+ utils_1.logger.wait('[HTTPS] Generating cert and key files...');
51
+ await utils_1.execa.execa('mkcert', [
52
+ '-cert-file',
53
+ cert,
54
+ '-key-file',
55
+ key,
56
+ ...hosts,
57
+ ]);
58
+ }
59
+ return {
60
+ key,
61
+ cert,
62
+ };
63
+ }
64
+ exports.resolveHttpsConfig = resolveHttpsConfig;
65
+ async function createHttpsServer(app, httpsConfig) {
66
+ utils_1.logger.wait('[HTTPS] Starting service in https mode...');
67
+ const { key, cert } = await resolveHttpsConfig(httpsConfig);
68
+ // Create server
69
+ const http2Service = spdy_1.default.createServer({
70
+ key: (0, fs_1.readFileSync)(key, 'utf-8'),
71
+ cert: (0, fs_1.readFileSync)(cert, 'utf-8'),
72
+ }, app);
73
+ return http2Service;
74
+ }
75
+ exports.createHttpsServer = createHttpsServer;
package/dist/index.d.ts CHANGED
@@ -7,3 +7,5 @@ export declare function parseModuleSync(opts: {
7
7
  path: string;
8
8
  }): readonly [imports: readonly import("@umijs/bundler-utils/compiled/es-module-lexer").ImportSpecifier[], exports: readonly string[], facade: boolean];
9
9
  export declare function isDepPath(path: string): boolean;
10
+ export * from './https';
11
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,12 +1,17 @@
1
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
- });
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
10
15
  };
11
16
  Object.defineProperty(exports, "__esModule", { value: true });
12
17
  exports.isDepPath = exports.parseModuleSync = exports.parseModule = void 0;
@@ -14,11 +19,9 @@ const es_module_lexer_1 = require("@umijs/bundler-utils/compiled/es-module-lexer
14
19
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
15
20
  const utils_1 = require("@umijs/utils");
16
21
  const path_1 = require("path");
17
- function parseModule(opts) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- yield es_module_lexer_1.init;
20
- return parseModuleSync(opts);
21
- });
22
+ async function parseModule(opts) {
23
+ await es_module_lexer_1.init;
24
+ return parseModuleSync(opts);
22
25
  }
23
26
  exports.parseModule = parseModule;
24
27
  function parseModuleSync(opts) {
@@ -38,3 +41,5 @@ function isDepPath(path) {
38
41
  umiMonorepoPaths.some((p) => (0, utils_1.winPath)(path).includes(p)));
39
42
  }
40
43
  exports.isDepPath = isDepPath;
44
+ __exportStar(require("./https"), exports);
45
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,5 @@
1
+ export interface HttpsServerOptions {
2
+ key?: string;
3
+ cert?: string;
4
+ hosts?: string[];
5
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-utils",
3
- "version": "4.0.0-rc.14",
3
+ "version": "4.0.0-rc.17",
4
4
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-utils#readme",
5
5
  "bugs": "https://github.com/umijs/umi-next/issues",
6
6
  "repository": {
@@ -20,9 +20,10 @@
20
20
  "dev": "pnpm build -- --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@umijs/utils": "4.0.0-rc.14",
23
+ "@umijs/utils": "4.0.0-rc.17",
24
24
  "esbuild": "0.14.36",
25
- "regenerate-unicode-properties": "10.0.1"
25
+ "regenerate-unicode-properties": "10.0.1",
26
+ "spdy": "^4.0.2"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@babel/code-frame": "7.16.7",
@@ -50,8 +51,9 @@
50
51
  "@types/babel__generator": "7.6.4",
51
52
  "@types/babel__parser": "7.1.1",
52
53
  "@types/babel__template": "7.4.1",
53
- "@types/babel__traverse": "7.17.0",
54
+ "@types/babel__traverse": "7.17.1",
54
55
  "@types/less": "3.0.3",
56
+ "@types/spdy": "^3.4.5",
55
57
  "cjs-module-lexer": "1.2.2",
56
58
  "es-module-lexer": "0.10.5",
57
59
  "express": "4.17.3",