1
1
const fs = require ( 'fs' ) ;
2
2
const path = require ( 'path' ) ;
3
3
const Markdoc = require ( '@markdoc/markdoc' ) ;
4
- const { defaultObject} = require ( './runtime' ) ;
5
4
6
5
const DEFAULT_SCHEMA_PATH = './markdoc' ;
7
6
@@ -52,7 +51,6 @@ async function load(source) {
52
51
dir, // Root directory from Next.js (contains next.config.js)
53
52
mode = 'static' ,
54
53
schemaPath = DEFAULT_SCHEMA_PATH ,
55
- nextRuntime,
56
54
} = this . getOptions ( ) || { } ;
57
55
58
56
const schemaDir = path . resolve ( dir , schemaPath || DEFAULT_SCHEMA_PATH ) ;
@@ -65,87 +63,6 @@ async function load(source) {
65
63
// https://nextjs.org/docs/advanced-features/src-directory
66
64
const filepath = this . resourcePath . split ( 'pages' ) [ 1 ] ;
67
65
68
- // Only run validation when during server compilation
69
- if ( nextRuntime === 'nodejs' ) {
70
- // This is just to get subcompilation working with Next.js's fast refresh
71
- let previousRequire = global . require ;
72
- global . require = previousRequire || require || __non_webpack_require__ ;
73
-
74
- // This imports the config as an in-memory object
75
- const importAtBuildTime = async ( resource ) => {
76
- try {
77
- const object = await this . importModule (
78
- await resolve ( schemaDir , resource )
79
- ) ;
80
- return defaultObject ( object ) ;
81
- } catch ( error ) {
82
- return undefined ;
83
- }
84
- } ;
85
-
86
- const cfg = {
87
- tags : await importAtBuildTime ( 'tags' ) ,
88
- nodes : await importAtBuildTime ( 'nodes' ) ,
89
- functions : await importAtBuildTime ( 'functions' ) ,
90
- ...( await importAtBuildTime ( 'config' ) ) ,
91
- } ;
92
-
93
- const errors = Markdoc . validate ( ast , cfg )
94
- // tags are not yet registered, so ignore these errors
95
- . filter ( ( e ) => e . error . id !== 'tag-undefined' )
96
- . filter ( ( e ) => {
97
- switch ( e . error . level ) {
98
- case 'debug' :
99
- case 'error' :
100
- case 'info' : {
101
- console [ e . error . level ] ( e . error . message ) ;
102
- break ;
103
- }
104
- case 'warning' : {
105
- console . warn ( e . error . message ) ;
106
- break ;
107
- }
108
- case 'critical' : {
109
- console . error ( e . error . message ) ;
110
- break ;
111
- }
112
- default : {
113
- console . log ( e . error . message ) ;
114
- break ;
115
- }
116
- }
117
- return e . error . level === 'critical' ;
118
- } )
119
- . flatMap ( ( e ) => {
120
- const lines = source . split ( '\n' ) ;
121
-
122
- const message = [ e . error . message , ...lines . slice ( ...e . lines ) ] ;
123
-
124
- if (
125
- e . error &&
126
- e . error . location &&
127
- e . error . location . start &&
128
- e . error . location . start . offset
129
- ) {
130
- const prev = lines . slice ( 0 , e . lines [ 0 ] ) . join ( '\n' ) . length ;
131
- const diff = e . error . location . start . offset - prev ;
132
-
133
- const pointer = `${ ' ' . repeat ( diff ) } ^` ;
134
- message . push ( pointer ) ;
135
- }
136
-
137
- // add extra newline between errors
138
- message . push ( '' ) ;
139
- return message ;
140
- } ) ;
141
-
142
- if ( errors . length ) {
143
- throw new Error ( errors . join ( '\n' ) ) ;
144
- }
145
-
146
- global . require = previousRequire ;
147
- }
148
-
149
66
const partials = await gatherPartials . call (
150
67
this ,
151
68
ast ,
0 commit comments