vite-plugin-entry-shaking
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
28760
764
- Removedglobby@^13.1.2
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removedbraces@3.0.3(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@13.2.2(transitive)
- Removedignore@5.3.2(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedslash@4.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)