Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Import: Support path imports #22869

Closed
aduth opened this issue Jun 3, 2020 · 1 comment
Closed

Lazy Import: Support path imports #22869

aduth opened this issue Jun 3, 2020 · 1 comment
Labels
[Package] Lazy import /packages/lazy-import [Type] Enhancement A suggestion for improvement.

Comments

@aduth
Copy link
Member

aduth commented Jun 3, 2020

The @wordpress/lazy-import package introduced in #22684 allows for importing modules which may or may not be already installed. It's intended to be mostly interchangeable with a dynamic import or CommonJS require (aside from the fact that it returns a promise).

As part of the changes in #22684, existing usage of dependencies required in a benchmark script were ported to use @wordpress/lazy-import. One amongst these was the fbjs package, which requires that a module be imported from its path within the package, even going so far as to throw an error when the root-level package is imported.

Currently, @wordpress/lazy-import does not support path imports, which required a unique workaround for the above scenario.

Task: Support path imports in @worpress/lazy-import

Implementation Notes:

Existing supported usage should not be impacted.

Path-based imports should be supported, as in the following example:

await lazyImport( 'fbjs/lib/shallowEqual@^1.0.0' );

As noted at #22684 (comment) , the npm-package-arg package used in @wordpress/lazy-import does not support strings formatted this way. It may be required to extract the path separate from this existing process, or create a custom implementation for extracting the package, path, and version from a given string.

@gziolo
Copy link
Member

gziolo commented Nov 10, 2020

It was implemented in #23751 but the final API was simplified to take advantage of all features that npm-package-arg offers:

 lazyImport( 'fbjs@^1.0.0', {
	localPath: './lib/shallowEqual',
} );

We can always revisit and offer the API proposed originally. I'm closing the issue for now, but we can always reopen.

@gziolo gziolo closed this as completed Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Lazy import /packages/lazy-import [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants