Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manifest plugin, collect-styles.js node resolution #27

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 39 additions & 45 deletions packages/vinxi/lib/manifest/collect-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,55 @@ async function getViteModuleNode(vite, file, ssr) {
return null;
}

const resolvedId = await vite.pluginContainer.resolveId(file, undefined, {
ssr: ssr,
});
let nodePath = file;

if (!resolvedId) {
console.log("not found");
return;
let node = await vite.moduleGraph.getModuleById(nodePath);
if (!node) {
const resolvedId = await vite.pluginContainer.resolveId(file, undefined, {
ssr: ssr,
});

if (!resolvedId) {
console.log("not found");
return;
}
nodePath = resolvedId.id;
node = await vite.moduleGraph.getModuleById(nodePath);
}

const id = resolvedId.id;
if (!node) {
nodePath = resolve(nodePath);
node = await vite.moduleGraph.getModuleByUrl(nodePath);
}

const normalizedPath = resolve(id);
// Only not sure what to do with absolutePath as this is currently also not used.
// https://github.com/nksaraf/vinxi/blob/06700abbbbae34015faeba84830797daf4f54817/packages/vinxi/lib/manifest/collect-styles.js#L35

try {
let node = await vite.moduleGraph.getModuleById(normalizedPath);

if (!node) {
const absolutePath = resolve(file);
node = await vite.moduleGraph.getModuleByUrl(normalizedPath);
if (!node) {
if (ssr) {
await vite.moduleGraph.ensureEntryFromUrl(normalizedPath, ssr);
node = await vite.moduleGraph.getModuleById(normalizedPath);
} else {
await vite.moduleGraph.ensureEntryFromUrl(normalizedPath);
node = await vite.moduleGraph.getModuleById(normalizedPath);
}
}
// if (!node) {
// nodePath = resolve(file); // absolute path
// node = await vite.moduleGraph.getModuleByUrl(nodePath);
// }

if (!node.transformResult && !ssr) {
await vite.transformRequest(normalizedPath);
node = await vite.moduleGraph.getModuleById(normalizedPath);
}
if (!node) {
await vite.moduleGraph.ensureEntryFromUrl(nodePath, ssr);
node = await vite.moduleGraph.getModuleById(nodePath);
}

if (ssr && !node.ssrTransformResult) {
if (skip.includes(file)) {
return null;
}
await vite.ssrLoadModule(file);
node = await vite.moduleGraph.getModuleById(normalizedPath);
}
} else {
if (!node.transformResult && !ssr) {
await vite.transformRequest(normalizedPath);
node = await vite.moduleGraph.getModuleById(normalizedPath);
}

if (ssr && !node.ssrTransformResult) {
if (skip.includes(file)) {
return null;
}
await vite.ssrLoadModule(normalizedPath);
node = await vite.moduleGraph.getModuleById(normalizedPath);
try {
if (!node.transformResult && !ssr) {
await vite.transformRequest(nodePath);
node = await vite.moduleGraph.getModuleById(nodePath);
}

if (ssr && !node.ssrTransformResult) {
if (skip.includes(file)) {
return null;
}
await vite.ssrLoadModule(file);
node = await vite.moduleGraph.getModuleById(nodePath);
}

return node;
} catch (e) {
console.error(e);
Expand Down
Loading