@sveltejs/vite-plugin-svelte 2.0.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +170 -68
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/fixtures/preprocess/foo.scss +3 -0
- package/src/__tests__/preprocess.spec.ts +51 -0
- package/src/index.ts +55 -7
- package/src/preprocess.ts +18 -10
- package/src/utils/__tests__/sourcemaps.spec.ts +79 -0
- package/src/utils/compile.ts +4 -4
- package/src/utils/constants.ts +3 -0
- package/src/utils/log.ts +19 -9
- package/src/utils/options.ts +8 -10
- package/src/utils/sourcemaps.ts +67 -14
- package/src/utils/vite-plugin-svelte-cache.ts +55 -0
- package/src/utils/vite-plugin-svelte-stats.ts +13 -35
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
|
-
//eslint-disable-next-line node/no-missing-import
|
|
3
|
-
import { findClosestPkgJsonPath } from 'vitefu';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
import { dirname } from 'path';
|
|
6
2
|
import { performance } from 'perf_hooks';
|
|
7
3
|
import { normalizePath } from 'vite';
|
|
4
|
+
import { VitePluginSvelteCache } from './vite-plugin-svelte-cache';
|
|
8
5
|
|
|
9
6
|
interface Stat {
|
|
10
7
|
file: string;
|
|
@@ -87,31 +84,13 @@ function formatPackageStats(pkgStats: PackageStats[]) {
|
|
|
87
84
|
return table;
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
/**
|
|
91
|
-
* utility to get the package name a file belongs to
|
|
92
|
-
*
|
|
93
|
-
* @param {string} file to find package for
|
|
94
|
-
* @returns {path:string,name:string} tuple of path,name where name is the parsed package name and path is the normalized path to it
|
|
95
|
-
*/
|
|
96
|
-
async function getClosestNamedPackage(file: string): Promise<{ name: string; path: string }> {
|
|
97
|
-
let name = '$unknown';
|
|
98
|
-
let path = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
99
|
-
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
100
|
-
if (pkg.name != null) {
|
|
101
|
-
name = pkg.name;
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
});
|
|
106
|
-
// return normalized path with appended '/' so .startsWith works for future file checks
|
|
107
|
-
path = normalizePath(dirname(path ?? file)) + '/';
|
|
108
|
-
return { name, path };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
87
|
export class VitePluginSvelteStats {
|
|
112
88
|
// package directory -> package name
|
|
113
|
-
private
|
|
89
|
+
private _cache: VitePluginSvelteCache;
|
|
114
90
|
private _collections: StatCollection[] = [];
|
|
91
|
+
constructor(cache: VitePluginSvelteCache) {
|
|
92
|
+
this._cache = cache;
|
|
93
|
+
}
|
|
115
94
|
startCollection(name: string, opts?: Partial<CollectionOptions>) {
|
|
116
95
|
const options = {
|
|
117
96
|
...defaultCollectionOptions,
|
|
@@ -140,7 +119,7 @@ export class VitePluginSvelteStats {
|
|
|
140
119
|
stats.push(stat);
|
|
141
120
|
if (!hasLoggedProgress && options.logInProgress(collection, now)) {
|
|
142
121
|
hasLoggedProgress = true;
|
|
143
|
-
log.
|
|
122
|
+
log.debug(`${name} in progress ...`, undefined, 'stats');
|
|
144
123
|
}
|
|
145
124
|
};
|
|
146
125
|
},
|
|
@@ -164,7 +143,11 @@ export class VitePluginSvelteStats {
|
|
|
164
143
|
const logResult = collection.options.logResult(collection);
|
|
165
144
|
if (logResult) {
|
|
166
145
|
await this._aggregateStatsResult(collection);
|
|
167
|
-
log.
|
|
146
|
+
log.debug(
|
|
147
|
+
`${collection.name} done.\n${formatPackageStats(collection.packageStats!)}`,
|
|
148
|
+
undefined,
|
|
149
|
+
'stats'
|
|
150
|
+
);
|
|
168
151
|
}
|
|
169
152
|
// cut some ties to free it for garbage collection
|
|
170
153
|
const index = this._collections.indexOf(collection);
|
|
@@ -179,19 +162,14 @@ export class VitePluginSvelteStats {
|
|
|
179
162
|
collection.finish = () => {};
|
|
180
163
|
} catch (e) {
|
|
181
164
|
// this should not happen, but stats taking also should not break the process
|
|
182
|
-
log.debug.once(`failed to finish stats for ${collection.name}`, e);
|
|
165
|
+
log.debug.once(`failed to finish stats for ${collection.name}\n`, e, 'stats');
|
|
183
166
|
}
|
|
184
167
|
}
|
|
185
168
|
|
|
186
169
|
private async _aggregateStatsResult(collection: StatCollection) {
|
|
187
170
|
const stats = collection.stats;
|
|
188
171
|
for (const stat of stats) {
|
|
189
|
-
|
|
190
|
-
if (!pkg) {
|
|
191
|
-
pkg = await getClosestNamedPackage(stat.file);
|
|
192
|
-
this._packages.push(pkg);
|
|
193
|
-
}
|
|
194
|
-
stat.pkg = pkg.name;
|
|
172
|
+
stat.pkg = (await this._cache.getPackageInfo(stat.file)).name;
|
|
195
173
|
}
|
|
196
174
|
|
|
197
175
|
// group stats
|