Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hubspot/ui-extensions-dev-server

Package Overview
Dependencies
Maintainers
23
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hubspot/ui-extensions-dev-server - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

cli/config.js

20

cli/run.js

@@ -7,3 +7,3 @@ #!/usr/bin/env node

buildSingleExtension,
startDevMode,
DevModeInterface,
} = require('../index');

@@ -14,2 +14,4 @@

const logger = require('./logger');
const path = require('path');
const { MAIN_APP_CONFIG } = require('../lib/constants');

@@ -23,6 +25,8 @@ // eslint-disable-next-line no-floating-promise/no-floating-promise

} else if (DEV_MODE) {
startDevMode({
extension: extension || (await promptForExtensionToRun()),
outputDir: OUTPUT_DIR,
DevModeInterface.start({
extension: extension
? path.parse(extension).name
: await promptForExtensionToRun(),
logger,
projectFiles: [path.join(process.cwd(), '..', MAIN_APP_CONFIG)],
});

@@ -40,1 +44,9 @@ } else if (BUILD_MODE) {

})();
async function shutdown() {
await DevModeInterface.cleanup();
process.exit(0);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
const prompts = require('prompts');
const path = require('path');
const { getExtensionsList } = require('../lib/extensions');
const { getExtensionsList } = require('./extensions');

@@ -27,3 +28,3 @@ async function promptForExtensionToRun() {

);
return response.extension;
return path.parse(response.extension).name;
}

@@ -30,0 +31,0 @@

4

index.js

@@ -7,3 +7,3 @@ const {

const { startDevMode } = require('./lib/dev');
const DevModeInterface = require('./lib/DevModeInterface');

@@ -14,3 +14,3 @@ module.exports = {

buildSingleExtension,
startDevMode,
DevModeInterface,
};

@@ -6,3 +6,3 @@ const { build } = require('vite');

const { getUrlSafeFileName } = require('./utils');
const { loadConfig } = require('./config');
const { loadConfig } = require('../cli/config');

@@ -14,3 +14,3 @@ const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];

async function buildAllExtensions({ outputDir }) {
async function buildAllExtensions({ outputDir, logger = console }) {
const config = loadConfig();

@@ -27,3 +27,6 @@ const extensionKeys = Object.keys(config);

rollup: [
manifestPlugin({ output: getUrlSafeFileName(data.module.file) }),
manifestPlugin({
output: getUrlSafeFileName(data.module.file),
logger,
}),
],

@@ -41,2 +44,3 @@ },

root = process.cwd(), // This is the vite default, so using that as our default
logger = console,
}) {

@@ -60,3 +64,3 @@ const output = getUrlSafeFileName(file);

...ROLLUP_OPTIONS,
plugins: [manifestPlugin({ output })],
plugins: [manifestPlugin({ output, logger })],
},

@@ -70,3 +74,8 @@ outDir: outputDir,

async function remoteBuild(root, entryPoint, outputDir = OUTPUT_DIR) {
async function remoteBuild(
root,
entryPoint,
outputDir = OUTPUT_DIR,
logger = console
) {
const fileInfo = path.parse(entryPoint);

@@ -84,3 +93,3 @@

plugins: {
rollup: [manifestPlugin({ minify: true, output })],
rollup: [manifestPlugin({ minify: true, output, logger })],
},

@@ -87,0 +96,0 @@ minify: true,

const { createServer } = require('vite');
const path = require('path');
const startDevServer = require('./server');

@@ -10,3 +11,2 @@ const devBuildPlugin = require('./plugins/devBuildPlugin');

} = require('./constants');
const { loadConfig } = require('./config');

@@ -29,3 +29,3 @@ async function _createViteDevServer(

watch: {
ignored: [`${process.cwd()}/${outputDir}/**/*`],
ignored: [path.join(outputDir, '/**/*')],
},

@@ -40,4 +40,10 @@ },

plugins: [
devBuildPlugin({ extensionConfig, outputDir, baseMessage, logger }),
devBuildPlugin({
extensionConfig,
outputDir,
baseMessage,
logger,
}),
],
clearScreen: false,
});

@@ -47,3 +53,3 @@ }

async function startDevMode({
extension,
extensionConfig,
logger,

@@ -54,16 +60,6 @@ outputDir = OUTPUT_DIR,

}) {
if (!extension) {
if (!extensionConfig) {
throw new Error('Unable to determine which extension to run');
}
const config = loadConfig();
const extensionConfig = config[extension];
if (!extensionConfig) {
throw new Error(
`Unable to locate a configuration file for the specified extension ${extension}`
);
}
extensionConfig.output = getUrlSafeFileName(extensionConfig.data.module.file);
const baseMessage = Object.freeze({

@@ -82,3 +78,3 @@ appName: extensionConfig.data.appName,

);
startDevServer(
return startDevServer(
outputDir,

@@ -85,0 +81,0 @@ expressPort,

@@ -55,6 +55,6 @@ const { ROLLUP_OPTIONS, WEBSOCKET_MESSAGE_VERSION } = require('../constants');

plugins: [
...(ROLLUP_OPTIONS.plugins || []),
manifestPlugin({
minify: false,
output: extensionConfig.output,
logger,
}),

@@ -71,2 +71,3 @@ ],

},
clearScreen: false,
});

@@ -115,3 +116,3 @@ return true;

if (server.ws.clients.size === 0) {
logger.warn('Bundle updated, no browsers connected to notify');
logger.info('Bundle updated, no browsers connected to notify');
return [];

@@ -131,3 +132,3 @@ }

}
logger.warn('Sending shutdown message to connected browsers');
logger.info('Sending shutdown message to connected browsers');
if (localServer && localServer.ws) {

@@ -134,0 +135,0 @@ localServer.ws.send({

@@ -10,3 +10,3 @@ const { readFileSync } = require('fs');

function plugin(options = {}) {
function manifestPlugin(options = {}) {
return {

@@ -41,3 +41,2 @@ name: 'ui-extensions-manifest-generation-plugin',

const bundles = Object.keys(bundle).filter(cur => cur.endsWith('.js'));
if (bundles.length === 1) {

@@ -111,2 +110,2 @@ return {

module.exports = plugin;
module.exports = manifestPlugin;
const express = require('express');
const path = require('path');
const cors = require('cors');
const fs = require('fs');
const { EXTENSIONS_MESSAGE_VERSION, MANIFEST_FILE } = require('./constants');
const extensionsService = require('./extensionsService');

@@ -20,11 +18,13 @@ function startDevServer(

app.use(express.static(outputDir));
_addExtensionsEndpoint(
const endpointsAdded = extensionsService.add(
app,
expressPort,
webSocketPort,
outputDir,
baseMessage,
logger
baseMessage
);
endpointsAdded.forEach(endpoint => {
logger.info(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
});
// Vite middlewares needs to go last because it's greedy and will block other middleware

@@ -34,49 +34,6 @@ app.use(viteDevServer.middlewares);

const server = app.listen({ port: expressPort }, () => {
logger.warn(`Listening at ${baseMessage.callback}`);
logger.info(`Listening at ${baseMessage.callback}`);
});
_configureShutDownHandlers(server, viteDevServer, logger);
}
function _addExtensionsEndpoint(
server,
expressPort,
webSocketPort,
outputDir,
baseMessage,
logger
) {
const endpoint = '/extensions';
server.get(endpoint, (_req, res) => {
try {
const output = path.parse(baseMessage.callback).name;
const manifest = JSON.parse(
fs.readFileSync(
path.join(process.cwd(), `${outputDir}/${output}-${MANIFEST_FILE}`)
)
);
const response = {
websocket: `ws://localhost:${webSocketPort}`,
version: EXTENSIONS_MESSAGE_VERSION,
extensions: [
{
...baseMessage,
manifest,
},
],
};
res.status(200).json(response);
} catch (e) {
res.status(500).json({
message: 'Unable to load manifest file',
});
}
});
logger.warn(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
}
function _configureShutDownHandlers(server, viteDevServer, logger) {
async function shutdown() {
logger.warn('\nCleaning up after ourselves...');
return async function shutdown() {
await viteDevServer.pluginContainer.close();

@@ -87,8 +44,5 @@ // Stop new connections to express server

process.exit(0);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);
};
}
module.exports = startDevServer;
const path = require('path');
const fs = require('fs');
const { MANIFEST_FILE } = require('./constants');

@@ -17,5 +19,16 @@ function getUrlSafeFileName(filePath) {

function loadManifest(outputDir, output) {
try {
return JSON.parse(
fs.readFileSync(path.join(outputDir, `${output}-${MANIFEST_FILE}`))
);
} catch (e) {
return {};
}
}
module.exports = {
getUrlSafeFileName,
stripAnsiColorCodes,
loadManifest,
};
{
"name": "@hubspot/ui-extensions-dev-server",
"version": "0.3.1",
"version": "0.4.0",
"description": "",

@@ -14,2 +14,4 @@ "main": "index.js",

"files": [
"cli/config.js",
"cli/extensions.js",
"cli/logger.js",

@@ -21,6 +23,6 @@ "cli/run.js",

"lib/build.js",
"lib/config.js",
"lib/constants.js",
"lib/dev.js",
"lib/extensions.js",
"lib/extensionsService.js",
"lib/DevModeInterface.js",
"lib/server.js",

@@ -66,3 +68,3 @@ "lib/utils.js",

},
"gitHead": "3da4a07183d48528ef431d46a8d327c053c4fe94"
"gitHead": "1269fb86282dd5f6b9686d064b6c652f00cb863f"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc