@@ -4,14 +4,6 @@ const Markdoc = require('@markdoc/markdoc');
4
4
5
5
const DEFAULT_SCHEMA_PATH = './markdoc' ;
6
6
7
- // https://stackoverflow.com/questions/53799385/how-can-i-convert-a-windows-path-to-posix-path-using-node-path
8
- function normalizeAbsolutePath ( s ) {
9
- return s
10
- . replace ( / ^ [ a - z A - Z ] : / , '' ) // replace C: for Windows
11
- . split ( path . sep )
12
- . join ( path . posix . sep ) ;
13
- }
14
-
15
7
async function gatherPartials ( ast , schemaDir ) {
16
8
let partials = { } ;
17
9
@@ -24,7 +16,7 @@ async function gatherPartials(ast, schemaDir) {
24
16
typeof file === 'string' &&
25
17
! partials [ file ]
26
18
) {
27
- const filepath = path . posix . join ( schemaDir , file ) ;
19
+ const filepath = path . join ( schemaDir , file ) ;
28
20
// parsing is not done here because then we have to serialize and reload from JSON at runtime
29
21
const content = await fs . promises . readFile ( filepath , { encoding : 'utf8' } ) ;
30
22
@@ -45,6 +37,7 @@ async function gatherPartials(ast, schemaDir) {
45
37
// Returning a JSX object is what allows fast refresh to work
46
38
async function load ( source ) {
47
39
const logger = this . getLogger ( '@markdoc/next.js' ) ;
40
+ // https://webpack.js.org/concepts/module-resolution/
48
41
const resolve = this . getResolve ( {
49
42
// https://webpack.js.org/api/loaders/#thisgetresolve
50
43
extensions : [ '.js' , '.jsx' , '.json' , '.ts' , '.tsx' , '...' ] ,
@@ -54,7 +47,7 @@ async function load(source) {
54
47
const { mode = 'static' , schemaPath = DEFAULT_SCHEMA_PATH } =
55
48
this . getOptions ( ) || { } ;
56
49
57
- const schemaDir = path . posix . resolve ( schemaPath || DEFAULT_SCHEMA_PATH ) ;
50
+ const schemaDir = path . resolve ( schemaPath || DEFAULT_SCHEMA_PATH ) ;
58
51
59
52
// Grabs the path of the file relative to the `/pages` directory
60
53
// to pass into the app props later.
@@ -121,7 +114,7 @@ async function load(source) {
121
114
const partials = await gatherPartials . call (
122
115
this ,
123
116
ast ,
124
- path . posix . resolve ( schemaDir , 'partials' )
117
+ path . resolve ( schemaDir , 'partials' )
125
118
) ;
126
119
127
120
// IDEA: consider making this an option per-page
@@ -134,9 +127,7 @@ async function load(source) {
134
127
135
128
async function readDir ( variable ) {
136
129
try {
137
- const module = normalizeAbsolutePath (
138
- await resolve ( schemaDir , variable )
139
- ) ;
130
+ const module = await resolve ( schemaDir , variable ) ;
140
131
return `import * as ${ variable } from '${ module } '` ;
141
132
} catch ( error ) {
142
133
return `const ${ variable } = {};` ;
@@ -171,9 +162,7 @@ import yaml from 'js-yaml';
171
162
// renderers is imported separately so Markdoc isn't sent to the client
172
163
import Markdoc, {renderers} from '@markdoc/markdoc'
173
164
174
- import {getSchema} from '${ normalizeAbsolutePath (
175
- await resolve ( __dirname , './runtime' )
176
- ) } ';
165
+ import {getSchema} from '${ await resolve ( __dirname , './runtime' ) } ';
177
166
/**
178
167
* Schema is imported like this so end-user's code is compiled using build-in babel/webpack configs.
179
168
* This enables typescript/ESnext support
0 commit comments