@amamo/mdx 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/compiler.d.ts +28 -0
- package/dist/compiler.js +446 -0
- package/dist/config.d.ts +123 -0
- package/dist/config.js +134 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2 -0
- package/dist/native.d.ts +71 -0
- package/dist/native.js +68 -0
- package/dist/next-loader.cjs +33 -0
- package/dist/next.d.ts +8 -0
- package/dist/next.js +64 -0
- package/dist/shiki.d.ts +7 -0
- package/dist/shiki.js +82 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +100 -0
- package/native.cjs +39 -0
- package/native.d.ts +12 -0
- package/package.json +124 -0
package/dist/vite.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createAdapterCompiler } from './compiler.js';
|
|
2
|
+
export function amamoMdx(config) {
|
|
3
|
+
let compilerPromise;
|
|
4
|
+
let startup;
|
|
5
|
+
let disposed = false;
|
|
6
|
+
function compiler() {
|
|
7
|
+
compilerPromise ??= createAdapterCompiler(config);
|
|
8
|
+
return compilerPromise;
|
|
9
|
+
}
|
|
10
|
+
function ensureBuild() {
|
|
11
|
+
startup ??= compiler().then((instance) => instance.build());
|
|
12
|
+
return startup;
|
|
13
|
+
}
|
|
14
|
+
async function dispose() {
|
|
15
|
+
if (disposed || !compilerPromise)
|
|
16
|
+
return;
|
|
17
|
+
disposed = true;
|
|
18
|
+
const instance = await compilerPromise;
|
|
19
|
+
await instance.dispose();
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
name: 'amamo-mdx',
|
|
23
|
+
enforce: 'pre',
|
|
24
|
+
sharedDuringBuild: true,
|
|
25
|
+
async buildStart() {
|
|
26
|
+
await ensureBuild();
|
|
27
|
+
},
|
|
28
|
+
async transform(_source, id) {
|
|
29
|
+
const instance = await compiler();
|
|
30
|
+
if (!instance.isContentFile(id))
|
|
31
|
+
return null;
|
|
32
|
+
const result = await instance.transform(id);
|
|
33
|
+
return { code: result.code, map: result.map };
|
|
34
|
+
},
|
|
35
|
+
async configureServer(server) {
|
|
36
|
+
await ensureBuild();
|
|
37
|
+
const instance = await compiler();
|
|
38
|
+
const update = async (file) => {
|
|
39
|
+
if (!instance.isContentFile(file))
|
|
40
|
+
return;
|
|
41
|
+
try {
|
|
42
|
+
const result = await instance.transform(file);
|
|
43
|
+
if (result.outputsWritten > 0)
|
|
44
|
+
invalidateGeneratedModule(server, instance);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
reportWatchError(server, error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const remove = async (file) => {
|
|
51
|
+
if (!instance.isContentFile(file))
|
|
52
|
+
return;
|
|
53
|
+
try {
|
|
54
|
+
if (await instance.remove(file))
|
|
55
|
+
invalidateGeneratedModule(server, instance);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
reportWatchError(server, error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
server.watcher.on('add', update);
|
|
62
|
+
server.watcher.on('change', update);
|
|
63
|
+
server.watcher.on('unlink', remove);
|
|
64
|
+
server.httpServer?.once('close', async () => {
|
|
65
|
+
server.watcher.off('add', update);
|
|
66
|
+
server.watcher.off('change', update);
|
|
67
|
+
server.watcher.off('unlink', remove);
|
|
68
|
+
try {
|
|
69
|
+
await dispose();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
server.config.logger.error(asError(error).stack ?? asError(error).message);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
async closeBundle() {
|
|
77
|
+
await dispose();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function invalidateGeneratedModule(server, compiler) {
|
|
82
|
+
const module = server.moduleGraph.getModuleById(compiler.generatedCollectionModule);
|
|
83
|
+
if (module)
|
|
84
|
+
server.moduleGraph.invalidateModule(module);
|
|
85
|
+
server.hot.send({ type: 'full-reload' });
|
|
86
|
+
}
|
|
87
|
+
function reportWatchError(server, error) {
|
|
88
|
+
const value = asError(error);
|
|
89
|
+
server.config.logger.error(value.stack ?? value.message);
|
|
90
|
+
server.hot.send({
|
|
91
|
+
type: 'error',
|
|
92
|
+
err: {
|
|
93
|
+
message: value.message,
|
|
94
|
+
stack: value.stack ?? value.message,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function asError(error) {
|
|
99
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
100
|
+
}
|
package/native.cjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const target = nativeTarget()
|
|
4
|
+
const localBinding = `./index.${target}.node`
|
|
5
|
+
const packageName = `@amamo/mdx-${target}`
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
module.exports = require(localBinding)
|
|
9
|
+
} catch (localError) {
|
|
10
|
+
try {
|
|
11
|
+
const binding = require(packageName)
|
|
12
|
+
const bindingVersion = require(`${packageName}/package.json`).version
|
|
13
|
+
const packageVersion = require('./package.json').version
|
|
14
|
+
if (bindingVersion !== packageVersion) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`AMAMO_NATIVE_VERSION_MISMATCH: expected ${packageVersion}, received ${bindingVersion}`,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
module.exports = binding
|
|
20
|
+
} catch (packageError) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`AMAMO_NATIVE_UNAVAILABLE: No native binding for ${target}; reinstall @amamo/mdx on a supported platform`,
|
|
23
|
+
{ cause: new AggregateError([localError, packageError]) },
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function nativeTarget() {
|
|
29
|
+
if (process.platform === 'darwin' && ['arm64', 'x64'].includes(process.arch)) {
|
|
30
|
+
return `darwin-${process.arch}`
|
|
31
|
+
}
|
|
32
|
+
if (process.platform === 'win32' && process.arch === 'x64') return 'win32-x64-msvc'
|
|
33
|
+
if (process.platform === 'linux' && ['arm64', 'x64'].includes(process.arch)) {
|
|
34
|
+
const report = process.report?.getReport()
|
|
35
|
+
const libc = report?.header?.glibcVersionRuntime ? 'gnu' : 'musl'
|
|
36
|
+
return `linux-${process.arch}-${libc}`
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`AMAMO_NATIVE_UNSUPPORTED: ${process.platform}-${process.arch}`)
|
|
39
|
+
}
|
package/native.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class PreparedBatch {
|
|
4
|
+
get codeBlocksJson(): string
|
|
5
|
+
finish(highlightsJson: string): string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function prepareBatch(configJson: string, inputsJson: string): PreparedBatch
|
|
9
|
+
|
|
10
|
+
export declare function pruneCache(cacheDirectory: string, keepKeysJson: string): number
|
|
11
|
+
|
|
12
|
+
export declare function renderManifests(configJson: string, recordsJson: string): string
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amamo/mdx",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A native MDX content compiler with Vite and Next adapters",
|
|
5
|
+
"homepage": "https://jikkai.github.io/mdx/",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "白熱 <sonne@asaki.me>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/jikkai/mdx"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/*.cjs",
|
|
14
|
+
"dist/*.d.ts",
|
|
15
|
+
"dist/*.js",
|
|
16
|
+
"native.cjs",
|
|
17
|
+
"native.d.ts",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"types": "./dist/vite.d.ts",
|
|
29
|
+
"import": "./dist/vite.js"
|
|
30
|
+
},
|
|
31
|
+
"./next": {
|
|
32
|
+
"types": "./dist/next.d.ts",
|
|
33
|
+
"import": "./dist/next.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"prepare": "simple-git-hooks",
|
|
38
|
+
"build:native": "napi build --platform --output-dir . --no-js --dts native.d.ts",
|
|
39
|
+
"build:ts": "tsc -p tsconfig.json",
|
|
40
|
+
"build": "pnpm run build:native && pnpm run build:ts",
|
|
41
|
+
"format": "oxfmt . && cargo fmt",
|
|
42
|
+
"format:check": "oxfmt --check . && cargo fmt --check",
|
|
43
|
+
"lint": "oxlint .",
|
|
44
|
+
"lint:fix": "oxlint --fix .",
|
|
45
|
+
"prepublishOnly": "napi prepublish -t npm --no-gh-release",
|
|
46
|
+
"test": "pnpm run build && vitest run src/__tests__",
|
|
47
|
+
"test:rust": "cargo test",
|
|
48
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
49
|
+
"check": "pnpm run format:check && pnpm run lint && cargo clippy --all-targets -- -D warnings && cargo test && pnpm run typecheck && pnpm run test",
|
|
50
|
+
"release": "verso"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"shiki": "4.4.2"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@amamo/oxlint-config": "1.0.0",
|
|
57
|
+
"@amamo/verso": "1.0.0",
|
|
58
|
+
"@napi-rs/cli": "3.8.2",
|
|
59
|
+
"@types/node": "26.1.2",
|
|
60
|
+
"@types/react": "19.2.18",
|
|
61
|
+
"@types/react-dom": "19.2.4",
|
|
62
|
+
"lint-staged": "17.3.0",
|
|
63
|
+
"next": "16.3.0",
|
|
64
|
+
"oxfmt": "0.62.0",
|
|
65
|
+
"oxlint": "1.77.0",
|
|
66
|
+
"react": "19.2.8",
|
|
67
|
+
"react-dom": "19.2.8",
|
|
68
|
+
"simple-git-hooks": "2.13.1",
|
|
69
|
+
"typescript": "7.0.2",
|
|
70
|
+
"vite": "8.2.0",
|
|
71
|
+
"vitest": "4.1.10"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {
|
|
74
|
+
"next": "^16.0.0",
|
|
75
|
+
"react": "^19.0.0",
|
|
76
|
+
"vite": "^8.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"next": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"react": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"vite": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"simple-git-hooks": {
|
|
90
|
+
"pre-commit": "pnpm exec lint-staged"
|
|
91
|
+
},
|
|
92
|
+
"lint-staged": {
|
|
93
|
+
"*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}": [
|
|
94
|
+
"oxfmt --check --no-error-on-unmatched-pattern",
|
|
95
|
+
"oxlint --no-error-on-unmatched-pattern"
|
|
96
|
+
],
|
|
97
|
+
"*.{json,jsonc,json5,yaml,yml,toml,md,mdx,css,scss,less,html,graphql,gql}": "oxfmt --check --no-error-on-unmatched-pattern"
|
|
98
|
+
},
|
|
99
|
+
"napi": {
|
|
100
|
+
"binaryName": "index",
|
|
101
|
+
"targets": [
|
|
102
|
+
"aarch64-apple-darwin",
|
|
103
|
+
"x86_64-apple-darwin",
|
|
104
|
+
"aarch64-unknown-linux-gnu",
|
|
105
|
+
"x86_64-unknown-linux-gnu",
|
|
106
|
+
"aarch64-unknown-linux-musl",
|
|
107
|
+
"x86_64-unknown-linux-musl",
|
|
108
|
+
"x86_64-pc-windows-msvc"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
"engines": {
|
|
112
|
+
"node": ">=20.19"
|
|
113
|
+
},
|
|
114
|
+
"packageManager": "pnpm@11.20.0",
|
|
115
|
+
"optionalDependencies": {
|
|
116
|
+
"@amamo/mdx-darwin-arm64": "0.1.1",
|
|
117
|
+
"@amamo/mdx-darwin-x64": "0.1.1",
|
|
118
|
+
"@amamo/mdx-linux-arm64-gnu": "0.1.1",
|
|
119
|
+
"@amamo/mdx-linux-x64-gnu": "0.1.1",
|
|
120
|
+
"@amamo/mdx-linux-arm64-musl": "0.1.1",
|
|
121
|
+
"@amamo/mdx-linux-x64-musl": "0.1.1",
|
|
122
|
+
"@amamo/mdx-win32-x64-msvc": "0.1.1"
|
|
123
|
+
}
|
|
124
|
+
}
|