Skip to content

Commit b64e6b1

Browse files
committed
migrate loader to js
1 parent f7e7f8d commit b64e6b1

File tree

9 files changed

+78
-124
lines changed

9 files changed

+78
-124
lines changed

packages/loader/index.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// stolen code from @jdx-js/loader
1+
// stolen code from @mdx-js/loader
22

33
/**
44
* Webpack loader
@@ -11,7 +11,7 @@
1111
module.exports = function (code) {
1212
const callback = this.async()
1313
// Note that `import()` caches, so this should be fast enough.
14-
import('./dist/loader.js').then((module) =>
14+
import('./lib/index.js').then((module) =>
1515
module.loader.call(this, code, callback)
1616
)
1717
}

packages/loader/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { ProcessorOptions } from '@orgajs/orgx'
2+
import type { LoaderContext } from 'webpack'
3+
4+
/**
5+
* A Webpack loader to compile MDX to JavaScript.
6+
*
7+
* [Reference for Loader API](https://webpack.js.org/api/loaders/)
8+
*
9+
* @this {LoaderContext<unknown>}
10+
* @param {string} value
11+
* The original module source code.
12+
* @returns {void}
13+
*/
14+
declare function orgLoader(this: LoaderContext<unknown>, value: string): void
15+
16+
export default orgLoader
17+
18+
export type Options = ProcessorOptions

packages/loader/package.json

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"version": "3.1.10",
44
"description": "Load org-mode content through orga.",
55
"type": "module",
6-
"exports": {
7-
".": {
8-
"import": "./dist/index.js",
9-
"require": "./index.cjs"
10-
}
11-
},
12-
"types": "./dist/index.d.ts",
6+
"main": "./index.cjs",
7+
"types": "index.d.ts",
8+
"files": [
9+
"lib/",
10+
"index.cjs",
11+
"index.d.ts"
12+
],
1313
"author": "Xiaoxing Hu <[email protected]>",
1414
"license": "MIT",
1515
"homepage": "https://github.com/orgapp/orgajs/tree/main/packages/loader#readme",
@@ -18,31 +18,22 @@
1818
"url": "https://github.com/orgapp/orgajs.git",
1919
"directory": "packages/loader"
2020
},
21-
"files": [
22-
"dist"
23-
],
2421
"scripts": {
25-
"build": "pnpm clean && pnpm compile",
26-
"test": "node --test --no-warnings --loader tsx tests/*.test.ts",
27-
"clean": "del ./dist tsconfig.tsbuildinfo",
28-
"compile": "tsc -b"
22+
"test": "node --test tests/*.test.js"
2923
},
3024
"dependencies": {
3125
"@orgajs/orgx": "workspace:^",
32-
"loader-utils": "^3.2.1",
3326
"vfile-reporter": "^7.0.5"
3427
},
3528
"devDependencies": {
3629
"@orgajs/react": "workspace:^",
37-
"@types/loader-utils": "^2.0.3",
38-
"@types/node": "^20.1.5",
30+
"@types/node": "^20.2.1",
3931
"babel-loader": "^9.1.2",
4032
"del-cli": "^5.0.0",
4133
"html-loader": "^4.2.0",
4234
"memfs": "^3.5.1",
4335
"react": "^18.2.0",
4436
"react-dom": "^18.2.0",
45-
"tsx": "^3.12.7",
46-
"webpack": "^5.82.1"
37+
"webpack": "^5.83.1"
4738
}
4839
}

packages/loader/src/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/loader/src/loader.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { promises as fs } from 'fs'
44
import webpack from 'webpack'
55
import { fileURLToPath } from 'url'
66

7-
export async function compile(fixture: string, options = {}) {
7+
export async function compile(fixture, options = {}) {
88
const base = new URL('.', import.meta.url)
99

1010
const result = await promisify(webpack)({
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import test from 'node:test'
2+
import * as assert from 'node:assert'
3+
import { compile } from './compiler.js'
4+
5+
test('basic org-mode parsing', async () => {
6+
const stats = await compile('fixture.org', {
7+
name: 'Alice',
8+
})
9+
10+
// wait for 3 seconds
11+
await new Promise((resolve) => setTimeout(resolve, 3000))
12+
console.log('after the wait')
13+
14+
const output = stats.toJson({ source: true }).modules[0].source
15+
assert.equal(
16+
output.trim(),
17+
`
18+
/*@jsxRuntime automatic @jsxImportSource react*/
19+
import {jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
20+
export const title = 'hello world';
21+
function _createOrgaContent(props) {
22+
const _components = Object.assign({
23+
div: "div",
24+
h1: "h1"
25+
}, props.components);
26+
return _jsxs(_components.div, {
27+
className: "section",
28+
children: [_jsxs(_components.h1, {
29+
children: ["headline one", " "]
30+
}), _jsx(_components.div, {
31+
style: {
32+
color: 'red'
33+
},
34+
children: "in a box"
35+
})]
36+
});
37+
}
38+
function OrgaContent(props = {}) {
39+
const {wrapper: OrgaLayout} = props.components || ({});
40+
return OrgaLayout ? _jsx(OrgaLayout, Object.assign({}, props, {
41+
children: _jsx(_createOrgaContent, props)
42+
})) : _createOrgaContent(props);
43+
}
44+
export default OrgaContent;
45+
`.trim()
46+
)
47+
})

packages/loader/tests/loader.test.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

packages/loader/tsconfig.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)