Skip to content

Commit

Permalink
more robust solution for prepareFindSvelteComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
marigold-kfrederix committed Nov 26, 2020
1 parent 63479c7 commit 7fccd19
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/partialHydration/prepareFindSvelteComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ export const removeHash = (pathWithHash) => {

const prepareFindSvelteComponent = ({ ssrFolder, rootDir, clientComponents: clientFolder, distDir }) => {
const rootDirFixed = windowsPathFix(rootDir);
const ssrComponents = glob.sync(`${ssrFolder}/**/*.js`);
const ssrComponents = glob.sync(`${ssrFolder}/**/*.js`).map(windowsPathFix);
const clientComponents = glob
.sync(`${clientFolder}/**/*.js`)
.map((c) => `${path.sep}${path.relative(windowsPathFix(distDir), c)}`);
.map((c) => windowsPathFix(`${path.sep}${path.relative(distDir, c)}`));

const cache = new Map();

const findComponent = (name, folder): SvelteComponentFiles => {
const nameFixed = windowsPathFix(name);
const cacheKey = JSON.stringify({ name, folder });
if (cache.has(cacheKey)) return cache.get(cacheKey);

console.log('findComponent: ', { nameFixed, folder });

// abs path first
if (name.includes(rootDirFixed)) {
if (nameFixed.includes(rootDirFixed)) {
const rel = windowsPathFix(path.relative(path.join(rootDirFixed, 'src'), name)).replace('.svelte', '.js');
const parsed = path.parse(rel);
const ssr = ssrComponents.find((c) => c.endsWith(rel));
Expand Down

0 comments on commit 7fccd19

Please sign in to comment.