Skip to content

Commit 385d6d9

Browse files
authored
Add timeout to prevent infinite builds (#19)
* add timeout to prevent infinite builds * use 5 seconds instead * remove build time validation (for now)
1 parent 569b557 commit 385d6d9

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

src/loader.js

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
33
const Markdoc = require('@markdoc/markdoc');
4-
const {defaultObject} = require('./runtime');
54

65
const DEFAULT_SCHEMA_PATH = './markdoc';
76

@@ -52,7 +51,6 @@ async function load(source) {
5251
dir, // Root directory from Next.js (contains next.config.js)
5352
mode = 'static',
5453
schemaPath = DEFAULT_SCHEMA_PATH,
55-
nextRuntime,
5654
} = this.getOptions() || {};
5755

5856
const schemaDir = path.resolve(dir, schemaPath || DEFAULT_SCHEMA_PATH);
@@ -65,87 +63,6 @@ async function load(source) {
6563
// https://nextjs.org/docs/advanced-features/src-directory
6664
const filepath = this.resourcePath.split('pages')[1];
6765

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-
14966
const partials = await gatherPartials.call(
15067
this,
15168
ast,

0 commit comments

Comments
 (0)