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

Tree-shaking package imports that include file extensions #969

Closed
FredKSchott opened this issue Aug 31, 2020 · 1 comment · Fixed by #972
Closed

Tree-shaking package imports that include file extensions #969

FredKSchott opened this issue Aug 31, 2020 · 1 comment · Fixed by #972
Labels
bug Something isn't working contributors welcome! contributors welcome!

Comments

@FredKSchott
Copy link
Owner

Original Discussion: #965
/cc @Papierschiff

For example, create a new module test at the node_modules directory with one file, add one method to this file, export this method and use it in your code. I get the following behaviour for imports

import * as TestModule from 'test'; // is working
import * as TestModule from 'test/index'; // is working
import * as TestModule from 'test/index.js'; // is not working("Generated an empty chunk: "te

Bug is most likely coming from this line in src/rollup-plugins/rollup-plugin-wrap-install-targets.ts:

        const allInstallTargets = installTargets.filter(
          (imp) => imp.specifier.replace(/\.js$/, 'js') === key,
        );

We convert a .js -> js for packages like tippy.js that get installed as tippyjs.js. It looks like we need to restrict this to only a package name. In the past, we've done that by calling:

import validatePackageName from 'validate-npm-package-name';
if (validatePackageName(imp.specifier).validForNewPackages) {
  // this is a package name, not a path within a package
@zhusjfaker
Copy link

c.ts
export * from './a';
export * from './b';

index.ts
import { TestBComponent } from './c';

snowpack will install a.ts & b.ts
treeshake is not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributors welcome! contributors welcome!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants