Skip to content

Commit

Permalink
fix svelte treeshake (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott authored Dec 13, 2020
1 parent 961dc77 commit a60e025
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import {Plugin} from 'rollup';
import {VM as VM2} from 'vm2';
import {AbstractLogger, InstallTarget} from '../types';
import {getWebDependencyName, isRemoteUrl, isTruthy} from '../util';
import {getWebDependencyName, isJavaScript, isRemoteUrl, isTruthy} from '../util';

// Use CJS intentionally here! ESM interface is async but CJS is sync, and this file is sync
const {parse} = require('cjs-module-lexer');
Expand Down Expand Up @@ -119,6 +119,9 @@ export function rollupPluginWrapInstallTargets(
if (isRemoteUrl(val)) {
continue;
}
if (!isJavaScript(val)) {
continue;
}
const allInstallTargets = installTargets.filter(
(imp) => getWebDependencyName(imp.specifier) === key,
);
Expand Down
7 changes: 6 additions & 1 deletion esinstall/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export function createInstallTarget(specifier: string, all = true): InstallTarge
};
}

export function isJavaScript(pathname: string): boolean {
const ext = path.extname(pathname).toLowerCase();
return (ext === '.js' || ext === '.mjs' || ext === '.cjs');
}

/**
* Detect the web dependency "type" as either JS or ASSET:
* - BUNDLE: Install and bundle this file with Rollup engine.
Expand All @@ -198,7 +203,7 @@ export function createInstallTarget(specifier: string, all = true): InstallTarge
export function getWebDependencyType(pathname: string): 'ASSET' | 'BUNDLE' {
const ext = path.extname(pathname).toLowerCase();
// JavaScript should always be bundled.
if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
if (isJavaScript(pathname)) {
return 'BUNDLE';
}
// Svelte & Vue should always be bundled because we want to show the missing plugin
Expand Down

1 comment on commit a60e025

@vercel
Copy link

@vercel vercel bot commented on a60e025 Dec 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.