Son CV dans un terminal web en Javascript! https://terminal-cv.gregandev.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.1 KiB

"use strict";
1 year ago
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
1 year ago
function _plugin() {
const data = require("@parcel/plugin");
1 year ago
_plugin = function () {
return data;
};
1 year ago
return data;
}
var _HMRServer = _interopRequireDefault(require("./HMRServer"));
var _Server = _interopRequireDefault(require("./Server"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let servers = new Map();
let hmrServers = new Map();
var _default = new (_plugin().Reporter)({
async report({
event,
options,
logger
}) {
let {
serveOptions,
hmrOptions
} = options;
let server = serveOptions ? servers.get(serveOptions.port) : undefined;
let hmrPort = hmrOptions && hmrOptions.port || serveOptions && serveOptions.port;
let hmrServer = hmrPort ? hmrServers.get(hmrPort) : undefined;
switch (event.type) {
case 'watchStart':
{
if (serveOptions) {
var _serveOptions$publicU;
// If there's already a server when watching has just started, something
// is wrong.
if (server) {
return logger.warn({
message: 'Trying to create the devserver but it already exists.'
});
}
let serverOptions = { ...serveOptions,
projectRoot: options.projectRoot,
cacheDir: options.cacheDir,
// Override the target's publicUrl as that is likely meant for production.
// This could be configurable in the future.
publicUrl: (_serveOptions$publicU = serveOptions.publicUrl) !== null && _serveOptions$publicU !== void 0 ? _serveOptions$publicU : '/',
inputFS: options.inputFS,
outputFS: options.outputFS,
logger
};
server = new _Server.default(serverOptions);
servers.set(serveOptions.port, server);
const devServer = await server.start();
1 year ago
if (hmrOptions && hmrOptions.port === serveOptions.port) {
let hmrServerOptions = {
port: serveOptions.port,
devServer,
logger
};
hmrServer = new _HMRServer.default(hmrServerOptions);
hmrServers.set(serveOptions.port, hmrServer);
hmrServer.start();
return;
}
}
1 year ago
let port = hmrOptions === null || hmrOptions === void 0 ? void 0 : hmrOptions.port;
1 year ago
if (typeof port === 'number') {
hmrServer = new _HMRServer.default({
port,
logger
});
hmrServers.set(port, hmrServer);
hmrServer.start();
}
1 year ago
break;
}
1 year ago
case 'watchEnd':
if (serveOptions) {
if (!server) {
return logger.warn({
message: 'Could not shutdown devserver because it does not exist.'
});
1 year ago
}
1 year ago
await server.stop();
servers.delete(server.options.port);
}
1 year ago
if (hmrOptions && hmrServer) {
hmrServer.stop(); // $FlowFixMe[prop-missing]
1 year ago
hmrServers.delete(hmrServer.wss.options.port);
}
1 year ago
break;
1 year ago
case 'buildStart':
if (server) {
server.buildStart();
}
break;
1 year ago
case 'buildSuccess':
if (serveOptions) {
if (!server) {
return logger.warn({
message: 'Could not send success event to devserver because it does not exist.'
});
}
1 year ago
server.buildSuccess(event.bundleGraph, event.requestBundle);
}
1 year ago
if (hmrServer) {
hmrServer.emitUpdate(event);
}
1 year ago
break;
1 year ago
case 'buildFailure':
// On buildFailure watchStart sometimes has not been called yet
// do not throw an additional warning here
if (server) {
await server.buildError(options, event.diagnostics);
}
1 year ago
if (hmrServer) {
await hmrServer.emitError(options, event.diagnostics);
}
1 year ago
break;
}
1 year ago
}
1 year ago
});
1 year ago
exports.default = _default;