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";
2 years ago
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
2 years ago
function _plugin() {
const data = require("@parcel/plugin");
2 years ago
_plugin = function () {
return data;
};
2 years 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();
2 years 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;
}
}
2 years ago
let port = hmrOptions === null || hmrOptions === void 0 ? void 0 : hmrOptions.port;
2 years ago
if (typeof port === 'number') {
hmrServer = new _HMRServer.default({
port,
logger
});
hmrServers.set(port, hmrServer);
hmrServer.start();
}
2 years ago
break;
}
2 years ago
case 'watchEnd':
if (serveOptions) {
if (!server) {
return logger.warn({
message: 'Could not shutdown devserver because it does not exist.'
});
2 years ago
}
2 years ago
await server.stop();
servers.delete(server.options.port);
}
2 years ago
if (hmrOptions && hmrServer) {
hmrServer.stop(); // $FlowFixMe[prop-missing]
2 years ago
hmrServers.delete(hmrServer.wss.options.port);
}
2 years ago
break;
2 years ago
case 'buildStart':
if (server) {
server.buildStart();
}
break;
2 years ago
case 'buildSuccess':
if (serveOptions) {
if (!server) {
return logger.warn({
message: 'Could not send success event to devserver because it does not exist.'
});
}
2 years ago
server.buildSuccess(event.bundleGraph, event.requestBundle);
}
2 years ago
if (hmrServer) {
hmrServer.emitUpdate(event);
}
2 years ago
break;
2 years 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);
}
2 years ago
if (hmrServer) {
await hmrServer.emitError(options, event.diagnostics);
}
2 years ago
break;
}
2 years ago
}
2 years ago
});
2 years ago
exports.default = _default;