Skip to content

Commit

Permalink
ESM path to file interop for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jan 10, 2022
1 parent 77b6321 commit 2c0c22d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/lib/ssr-route-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { pathToFileURL } from 'url';
import { workerData, parentPort } from 'worker_threads';

async function executeRouteModule({ modulePath, compilation, route, label, id }) {
const { getTemplate = null, getBody = null, getFrontmatter = null } = await import(modulePath).then(module => module);
const { getTemplate = null, getBody = null, getFrontmatter = null } = await import(pathToFileURL(modulePath)).then(module => module);
const parsedCompilation = JSON.parse(compilation);
const data = {
template: null,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lifecycles/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import fm from 'front-matter';
import path from 'path';
import toc from 'markdown-toc';
import { pathToFileURL } from 'url';

const generateGraph = async (compilation) => {

Expand All @@ -28,7 +29,7 @@ const generateGraph = async (compilation) => {
if (fs.statSync(fullPath).isDirectory()) {
routes = await walkDirectoryForRoutes(fullPath, routes);
} else {
const { getFrontmatter } = await import(fullPath);
const { getFrontmatter } = await import(pathToFileURL(fullPath));
const relativePagePath = fullPath.substring(routesDir.length - 1, fullPath.length);
const id = filename.split(path.sep)[filename.split(path.sep).length - 1].replace('.js', '');
const label = id.split('-')
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/plugins/resource/plugin-standard-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { ResourceInterface } from '../../lib/resource-interface.js';
import unified from 'unified';
import { fileURLToPath } from 'url';
import { pathToFileURL, fileURLToPath } from 'url';
import { Worker } from 'worker_threads';

function getCustomPageTemplates(contextPlugins, templateName) {
Expand Down Expand Up @@ -458,7 +458,7 @@ class StandardHtmlResource extends ResourceInterface {
});
});
} else {
const { getTemplate = null, getBody = null, getFrontmatter = null } = await import(routeLocation);
const { getTemplate = null, getBody = null, getFrontmatter = null } = await import(pathToFileURL(routeLocation));

if (getTemplate) {
ssrTemplate = await getTemplate(this.compilation, url);
Expand Down

0 comments on commit 2c0c22d

Please sign in to comment.