@metacensus/library-research 0.8.0 → 0.9.2
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/vite.js +30 -10
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -18,17 +18,13 @@ export function research({ projects, }) {
|
|
|
18
18
|
let config;
|
|
19
19
|
let dirs = [];
|
|
20
20
|
const owner = (file) => dirs.find(([, dir]) => inside(file, dir))?.[0];
|
|
21
|
-
const
|
|
21
|
+
const place = (files, pattern, info) => {
|
|
22
22
|
const owned = files.filter(owner).sort();
|
|
23
23
|
const slugs = [...new Set(owned.map(owner))];
|
|
24
24
|
if (slugs.length > 1)
|
|
25
25
|
throw new Error(`${owned.join(', ')}: mixes ${slugs.join(' and ')}`);
|
|
26
|
-
return slugs[0];
|
|
27
|
-
};
|
|
28
|
-
const place = (files, pattern, info) => {
|
|
29
|
-
const slug = scope(files);
|
|
30
26
|
const name = typeof pattern === 'string' ? pattern : pattern(info);
|
|
31
|
-
return
|
|
27
|
+
return slugs[0] ? `${prefix}/${slugs[0]}/assets/${basename(name)}` : name;
|
|
32
28
|
};
|
|
33
29
|
const sources = (asset) => asset.originalFileNames.map((file) => resolve(config.root, file));
|
|
34
30
|
/**
|
|
@@ -173,11 +169,35 @@ export function research({ projects, }) {
|
|
|
173
169
|
assetFileNames: (asset) => place(sources(asset), assets, asset),
|
|
174
170
|
};
|
|
175
171
|
},
|
|
176
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Rolldown merges a byte-identical asset into one it already named, and
|
|
174
|
+
* Vite emits a shared chunk's CSS with no originalFileNames. Moving it
|
|
175
|
+
* here, after vite:build-html and before vite:build-import-analysis,
|
|
176
|
+
* reaches the preload lists but not the HTML, which links host CSS only.
|
|
177
|
+
*/
|
|
177
178
|
generateBundle(_options, bundle) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
const chunks = Object.values(bundle).filter((f) => f.type === 'chunk');
|
|
180
|
+
for (const file of Object.values(bundle)) {
|
|
181
|
+
if (file.type !== 'asset')
|
|
182
|
+
continue;
|
|
183
|
+
const importers = chunks.filter((chunk) => chunk.viteMetadata?.importedCss.has(file.fileName));
|
|
184
|
+
const fileName = place([...sources(file), ...importers.flatMap((c) => c.moduleIds)], file.fileName, file);
|
|
185
|
+
if (!importers.length || fileName === file.fileName)
|
|
186
|
+
continue;
|
|
187
|
+
if (importers.some((c) => !c.moduleIds.some(owner)))
|
|
188
|
+
this.error(`${importers.map((c) => c.fileName).join(', ')}: share ${file.fileName}, mixing the host and a project`);
|
|
189
|
+
delete bundle[file.fileName];
|
|
190
|
+
this.emitFile({
|
|
191
|
+
type: 'asset',
|
|
192
|
+
fileName,
|
|
193
|
+
name: file.names[0],
|
|
194
|
+
source: file.source,
|
|
195
|
+
});
|
|
196
|
+
for (const { viteMetadata } of importers) {
|
|
197
|
+
viteMetadata.importedCss.delete(file.fileName);
|
|
198
|
+
viteMetadata.importedCss.add(fileName);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
181
201
|
},
|
|
182
202
|
writeBundle({ dir: out = '' }) {
|
|
183
203
|
const marks = dirs.map(([slug, dir]) => {
|