evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a command-line tool that compiles MDX files to JavaScript and generates source maps for debugging support. The tool should accept an MDX file path as input, compile it to JavaScript, generate a source map, and output both files.
.js extension.js.map extension//# sourceMappingURL=filename.js.map)Input file (test-input.mdx):
# Hello World
This is a test MDX file.
export const metadata = {
title: "Test"
}Expected behavior:
test-input.js containing compiled JavaScripttest-input.js.map containing the source map.js file includes a //# sourceMappingURL=test-input.js.map commentTest file: src/compile-mdx.test.js { .test-file }
import { test } from 'node:test'
import assert from 'node:assert'
import { readFileSync, writeFileSync, unlinkSync, existsSync } from 'node:fs'
import { execSync } from 'node:child_process'
test('compiles MDX file and generates source map', () => {
// Create test input file
const testMdx = `# Hello World
This is a test MDX file.
export const metadata = {
title: "Test"
}
`
writeFileSync('test-input.mdx', testMdx)
try {
// Run the compiler
execSync('node src/compile-mdx.js test-input.mdx', { encoding: 'utf-8' })
// Check that output files exist
assert.ok(existsSync('test-input.js'), 'JavaScript file should be created')
assert.ok(existsSync('test-input.js.map'), 'Source map file should be created')
// Check JavaScript file content
const jsContent = readFileSync('test-input.js', 'utf-8')
assert.ok(jsContent.includes('//# sourceMappingURL=test-input.js.map'),
'JavaScript file should include source map reference')
// Check source map file content
const sourceMap = JSON.parse(readFileSync('test-input.js.map', 'utf-8'))
assert.ok(sourceMap.version, 'Source map should have version')
assert.ok(sourceMap.sources, 'Source map should have sources')
assert.ok(sourceMap.mappings, 'Source map should have mappings')
assert.ok(sourceMap.sources.includes('test-input.mdx'),
'Source map should reference the original MDX file')
} finally {
// Cleanup
if (existsSync('test-input.mdx')) unlinkSync('test-input.mdx')
if (existsSync('test-input.js')) unlinkSync('test-input.js')
if (existsSync('test-input.js.map')) unlinkSync('test-input.js.map')
}
})Provides MDX compilation support with source map generation.
Provides the SourceMapGenerator class for creating source maps.
src/compile-mdx.js