question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Customize / make more readable output of promise new promise (promise based dynamic remotes)

See original GitHub issue

Feature request

What is the expected behavior? Promise new promise syntax (promised based dynamic remotes) gives excellent flexibility in defining remotes. However, the build output of this is too verbose, showing the entire body of the function in the build output.

What is motivation or use case for adding/changing the behavior? Promise based dynamic remotes give great flexibility. But, the build output is hard to read, particularly when more than 1 promised based dynamic remote is specified. Other details of the build output can be obscured by the volume of the promised based dynamic remote output.

How should this be implemented in your opinion? It looks like this output comes from the readableIdentifier function in ExternalModule.js. readableIdentifier appears to be part of the Module class, and is implemented differently for different module types. For external modules, it looks like this:

         /**
	 * @param {RequestShortener} requestShortener the request shortener
	 * @returns {string} a user readable identifier of the module
	 */
	readableIdentifier(requestShortener) {
		return "external " + JSON.stringify(this.request);
	}

One possibly naive revision would be to truncate the stringified output to some maximum length. For example, change ExternalModule.js’ method to look like this:

         /**
	 * @param {RequestShortener} requestShortener the request shortener
	 * @returns {string} a user readable identifier of the module
	 */
	readableIdentifier(requestShortener) {
		const maxLength = 80;
		const stringifiedRequest = JSON.stringify(this.request);
		return "external " + (stringifiedRequest.length > maxLength ? stringifiedRequest.substring(0, maxLength) + '...': stringifiedRequest)
	}

Are you willing to work on this yourself? yes, although someone else likely has a better understanding. I’d be happy to test and otherwise assist

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
trevorgithubcommented, Nov 17, 2022

@alexander-akait , the update snapshots helped with some of the unit test problems. But I’ve also changed the behaviour, limiting the scope of where the readable identifier is potentially truncated. I only care about the external modules, and some of the tests were having problems with the broader shortening behaviour. So, I changed the wrapper function to take the module, and only perform the shortening if it’s an external module type, and the readable identifier is “too long”. Here’s what the new function looks like:

/**
 * @param {string} readableIdentifier user readable identifier of the module
 * @param {Module} module base module type
 * @returns {string} an elided readableIdentifier, when readableIdentifier exceeds a maximum length
 */
const truncateLongExternalModuleReadableIdentifier = (
	readableIdentifier,
	module
) => {
	const maxLength = 80;
	return module instanceof ExternalModule &&
		readableIdentifier.length > maxLength
		? readableIdentifier.substring(0, maxLength) + "..."
		: readableIdentifier;
};

and here’s an example usage:

                        if (error.module) {
				object.moduleIdentifier = error.module.identifier();
				object.moduleName = truncateLongExternalModuleReadableIdentifier(
					error.module.readableIdentifier(requestShortener),
					error.module
				);
			}
0reactions
trevorgithubcommented, Dec 23, 2022

You can use delegate modules “internal ./src/my-delegate.js”

Hi Zack,

Thanks for your reply. I have no idea what it means though. Can you please elaborate?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial - A Guide to Module Federation for Enterprise
A guide for supporting a fully dynamic, multi-environment Module ... the usage of promise new Promise to infer the remote at runtime.
Read more >
Build output with promise new promise syntax in webpack
Webpack supports the promise new promise syntax when defining remotes for module federation. This is documented on the official webpack page ...
Read more >
How can I lazy load remoteEntry.js · Issue #681 - GitHub
I see remote app start loading after all the remoteEntry.js loaded if i put all the remotes to host's webpack config.
Read more >
Module Federation - webpack
Promise Based Dynamic Remotes. Generally, remotes are configured using URL's like in this example: module.exports = { plugins: [ new ...
Read more >
4 Ways to Use Dynamic Remotes in Module Federation
Promise Based Dynamic Remotes ... Within the promise, we create a new script tag and inject it into the DOM to fetch the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found