@stencil/dev-server 0.0.19-1 → 5.0.0-next.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/utils.js DELETED
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const path = require("path");
12
- const url = require("url");
13
- const fs = require("fs");
14
- const promisify_1 = require("./promisify");
15
- const devcert_san_1 = require("devcert-san");
16
- exports.fsStatPr = promisify_1.promisify(fs.stat);
17
- exports.fsReadFilePr = promisify_1.promisify(fs.readFile);
18
- exports.fsReadDirPr = promisify_1.promisify(fs.readdir);
19
- function findClosestOpenPort(host, port) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- function t(portToCheck) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const isTaken = yield isPortTaken(host, portToCheck);
24
- if (!isTaken) {
25
- return portToCheck;
26
- }
27
- return t(portToCheck + 1);
28
- });
29
- }
30
- return t(port);
31
- });
32
- }
33
- exports.findClosestOpenPort = findClosestOpenPort;
34
- function isPortTaken(host, port) {
35
- return new Promise((resolve, reject) => {
36
- var net = require('net');
37
- var tester = net.createServer()
38
- .once('error', function (err) {
39
- if (err.code !== 'EADDRINUSE') {
40
- return resolve(true);
41
- }
42
- resolve(true);
43
- })
44
- .once('listening', function () {
45
- tester.once('close', function () {
46
- resolve(false);
47
- })
48
- .close();
49
- })
50
- .on('error', (err) => {
51
- reject(err);
52
- })
53
- .listen(port, host);
54
- });
55
- }
56
- exports.isPortTaken = isPortTaken;
57
- function parseOptions(optionInfo, argv) {
58
- return Object.keys(optionInfo).reduce((options, key) => {
59
- let foundIndex = argv.indexOf(`--${key}`);
60
- if (foundIndex === -1) {
61
- options[key] = optionInfo[key].default;
62
- return options;
63
- }
64
- switch (optionInfo[key].type) {
65
- case Boolean:
66
- options[key] = true;
67
- break;
68
- case Number:
69
- options[key] = parseInt(argv[foundIndex + 1], 10);
70
- break;
71
- default:
72
- options[key] = argv[foundIndex + 1];
73
- }
74
- return options;
75
- }, {});
76
- }
77
- exports.parseOptions = parseOptions;
78
- function parseConfigFile(baseDir, filePath) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- let config = {};
81
- try {
82
- const configFile = yield Promise.resolve().then(() => require(path.resolve(baseDir, filePath)));
83
- config = configFile.devServer || {};
84
- }
85
- catch (err) {
86
- if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
87
- throw new Error(`The specified configFile does not exist: ${filePath}`);
88
- }
89
- if (err.code === 'EACCES') {
90
- throw new Error(`You do not have permission to read the specified configFile: ${filePath}`);
91
- }
92
- }
93
- return config;
94
- });
95
- }
96
- exports.parseConfigFile = parseConfigFile;
97
- function getRequestedPath(requestUrl) {
98
- const parsed = url.parse(requestUrl);
99
- decodeURIComponent(requestUrl);
100
- return decodePathname(parsed.pathname || '');
101
- }
102
- exports.getRequestedPath = getRequestedPath;
103
- function getFileFromPath(wwwRoot, requestUrl) {
104
- const pathname = getRequestedPath(requestUrl);
105
- return path.normalize(path.join(wwwRoot, path.relative('/', pathname)));
106
- }
107
- exports.getFileFromPath = getFileFromPath;
108
- function getSSL() {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- return installSSL().then((cert) => {
111
- return {
112
- key: fs.readFileSync(cert.keyPath, 'utf-8'),
113
- cert: fs.readFileSync(cert.certPath, 'utf-8')
114
- };
115
- });
116
- });
117
- }
118
- exports.getSSL = getSSL;
119
- function installSSL() {
120
- try {
121
- // Certificates are cached by name, so two calls for getDevelopmentCertificate('foo') will return the same key and certificate
122
- return devcert_san_1.default('stencil-dev-server-ssl', {
123
- installCertutil: true
124
- });
125
- }
126
- catch (err) {
127
- throw new Error(`Failed to generate dev SSL certificate: ${err}\n`);
128
- }
129
- }
130
- function decodePathname(pathname) {
131
- const pieces = pathname.replace(/\\/g, "/").split('/');
132
- return pieces.map((piece) => {
133
- piece = decodeURIComponent(piece);
134
- if (process.platform === 'win32' && /\\/.test(piece)) {
135
- throw new Error('Invalid forward slash character');
136
- }
137
- return piece;
138
- }).join('/');
139
- }