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

vite-plugin-entry-shaking

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-entry-shaking - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

9

dist/index.d.ts

@@ -7,4 +7,3 @@ import { PluginOption } from 'vite';

extensions?: string[];
include?: string[];
root?: string;
ignorePatterns?: any[];
debug?: boolean;

@@ -41,9 +40,7 @@ };

/** Determines whether a given file should be transformed. */
declare const transformRequired: (id: string, includedPaths: string[], options: FinalPluginOptions) => boolean;
declare const transformRequired: (id: string, options: FinalPluginOptions) => boolean;
/** Merges user options with the default ones. */
declare const mergeOptions: (userOptions: PluginOptions) => FinalPluginOptions;
/** Lists all of the paths matching the `include` option. */
declare const listIncluded: (finalOptions: FinalPluginOptions) => Promise<string[]>;
declare function createEntryShakingPlugin(userOptions: PluginOptions): Promise<PluginOption>;
export { analyzeEntries, createEntryShakingPlugin as default, listIncluded, mergeOptions, transformRequired };
export { analyzeEntries, createEntryShakingPlugin as default, mergeOptions, transformRequired };
{
"name": "vite-plugin-entry-shaking",
"version": "0.0.3",
"version": "0.1.0",
"description": "Mimic tree-shaking behaviour when importing code from an entry file in development mode.",

@@ -42,3 +42,2 @@ "author": "Charles Gruenais",

"es-module-lexer": "^1.0.3",
"globby": "^13.1.2",
"magic-string": "^0.26.3"

@@ -45,0 +44,0 @@ },

import type { PluginOption, ResolvedConfig, Logger } from 'vite';
import { normalizePath } from 'vite';
import { globby } from 'globby';
import { join, parse, resolve } from 'path';
import { parse } from 'path';

@@ -33,8 +32,7 @@ import type { FinalPluginOptions, PluginEntries, PluginOptions, PluginTargets } from './types';

id: string,
includedPaths: string[],
options: FinalPluginOptions,
) => {
const extension = id.split('.').pop()!;
return includedPaths.includes(id)
&& options.extensions.includes(extension);
const isIgnored = options.ignorePatterns.some((pattern) => id.match(pattern));
return !isIgnored && options.extensions.includes(extension);
};

@@ -47,5 +45,4 @@

extensions: ['js', 'jsx', 'mjs', 'ts', 'tsx', 'mts'],
include: [],
ignorePatterns: [/node_modules/, ...userOptions.ignorePatterns ?? []],
debug: false,
root: '.',
...userOptions,

@@ -55,13 +52,2 @@ targets: userOptions.targets.map(normalizePath),

/** Lists all of the paths matching the `include` option. */
export const listIncluded = async (
finalOptions: FinalPluginOptions,
): Promise<string[]> => {
const filter = (pattern: any) => normalizePath(join(finalOptions.root, pattern));
const include = ['!node_modules', './**/*', ...finalOptions.include];
const includedPaths = await globby(include.map(filter));
const resolvedPaths = includedPaths.map((path) => normalizePath(resolve(process.cwd(), path)));
return resolvedPaths;
};
export default async function createEntryShakingPlugin(

@@ -74,3 +60,2 @@ userOptions: PluginOptions,

const entries = await analyzeEntries(options.targets);
const includedPaths = await listIncluded(options);

@@ -89,3 +74,2 @@ return {

logger.info(`${logPrefix} List of parsed entries: Map(${JSON.stringify(Array.from(entries))})`);
logger.info(`${logPrefix} Included ${includedPaths.length} files within the plugin scope.`);
}

@@ -102,3 +86,3 @@ },

async transform(code, id) {
const requiresTransform = transformRequired(id, includedPaths, options);
const requiresTransform = transformRequired(id, options);
if (options.debug) {

@@ -105,0 +89,0 @@ logger.info(`${logPrefix} ${requiresTransform

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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