@sveltejs/vite-plugin-svelte
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "@sveltejs/vite-plugin-svelte", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"license": "MIT", | ||
@@ -50,3 +50,3 @@ "author": "dominikg", | ||
"svelte-hmr": "^0.15.1", | ||
"vitefu": "^0.2.1" | ||
"vitefu": "^0.2.2" | ||
}, | ||
@@ -53,0 +53,0 @@ "peerDependencies": { |
@@ -5,3 +5,5 @@ import { log } from './log'; | ||
import { readFileSync } from 'fs'; | ||
import { dirname } from 'path'; | ||
import { performance } from 'perf_hooks'; | ||
import { normalizePath } from 'vite'; | ||
@@ -89,2 +91,23 @@ interface Stat { | ||
/** | ||
* utility to get the package name a file belongs to | ||
* | ||
* @param {string} file to find package for | ||
* @returns {path:string,name:string} tuple of path,name where name is the parsed package name and path is the normalized path to it | ||
*/ | ||
async function getClosestNamedPackage(file: string): Promise<{ name: string; path: string }> { | ||
let name = '$unknown'; | ||
let path = await findClosestPkgJsonPath(file, (pkgPath) => { | ||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')); | ||
if (pkg.name != null) { | ||
name = pkg.name; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
// return normalized path with appended '/' so .startsWith works for future file checks | ||
path = normalizePath(dirname(path ?? file)) + '/'; | ||
return { name, path }; | ||
} | ||
export class VitePluginSvelteStats { | ||
@@ -113,2 +136,3 @@ // package directory -> package name | ||
} | ||
file = normalizePath(file); | ||
const start = performance.now(); | ||
@@ -139,21 +163,26 @@ const stat: Stat = { file, start, end: start }; | ||
private async _finish(collection: StatCollection) { | ||
collection.finished = true; | ||
const now = performance.now(); | ||
collection.duration = now - collection.collectionStart; | ||
const logResult = collection.options.logResult(collection); | ||
if (logResult) { | ||
await this._aggregateStatsResult(collection); | ||
log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats!)); | ||
try { | ||
collection.finished = true; | ||
const now = performance.now(); | ||
collection.duration = now - collection.collectionStart; | ||
const logResult = collection.options.logResult(collection); | ||
if (logResult) { | ||
await this._aggregateStatsResult(collection); | ||
log.info(`${collection.name} done.`, formatPackageStats(collection.packageStats!)); | ||
} | ||
// cut some ties to free it for garbage collection | ||
const index = this._collections.indexOf(collection); | ||
this._collections.splice(index, 1); | ||
collection.stats.length = 0; | ||
collection.stats = []; | ||
if (collection.packageStats) { | ||
collection.packageStats.length = 0; | ||
collection.packageStats = []; | ||
} | ||
collection.start = () => () => {}; | ||
collection.finish = () => {}; | ||
} catch (e) { | ||
// this should not happen, but stats taking also should not break the process | ||
log.debug.once(`failed to finish stats for ${collection.name}`, e); | ||
} | ||
// cut some ties to free it for garbage collection | ||
const index = this._collections.indexOf(collection); | ||
this._collections.splice(index, 1); | ||
collection.stats.length = 0; | ||
collection.stats = []; | ||
if (collection.packageStats) { | ||
collection.packageStats.length = 0; | ||
collection.packageStats = []; | ||
} | ||
collection.start = () => () => {}; | ||
collection.finish = () => {}; | ||
} | ||
@@ -166,24 +195,6 @@ | ||
if (!pkg) { | ||
// check for package.json first | ||
let pkgPath = await findClosestPkgJsonPath(stat.file); | ||
if (pkgPath) { | ||
let path = pkgPath?.replace(/package.json$/, ''); | ||
let name = JSON.parse(readFileSync(pkgPath, 'utf-8')).name; | ||
if (!name) { | ||
// some packages have nameless nested package.json | ||
pkgPath = await findClosestPkgJsonPath(path); | ||
if (pkgPath) { | ||
path = pkgPath?.replace(/package.json$/, ''); | ||
name = JSON.parse(readFileSync(pkgPath, 'utf-8')).name; | ||
} | ||
} | ||
if (path && name) { | ||
pkg = { path, name }; | ||
this._packages.push(pkg); | ||
} | ||
} | ||
pkg = await getClosestNamedPackage(stat.file); | ||
this._packages.push(pkg); | ||
} | ||
// TODO is it possible that we want to track files where there is no named packge.json as parent? | ||
// what do we want to do for that, try to find common root paths for different stats? | ||
stat.pkg = pkg?.name ?? '$unknown'; | ||
stat.pkg = pkg.name; | ||
} | ||
@@ -190,0 +201,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
583119
7743
Updatedvitefu@^0.2.2