Skip to content

Commit 72a557d

Browse files
committed
migrate @orgajs/rollup to js
1 parent fad7a4e commit 72a557d

File tree

8 files changed

+93
-439
lines changed

8 files changed

+93
-439
lines changed

.gitignore

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,15 @@ typings/
8989
# next.js build output
9090
.next
9191

92-
dist
9392
.npmrc
94-
*.tsbuildinfo
9593

9694
# private
9795
.archive
9896

99-
# yarn 2
100-
.yarn/*
101-
!.yarn/patches
102-
!.yarn/releases
103-
!.yarn/plugins
104-
!.yarn/sdks
105-
!.yarn/versions
106-
.pnp.*
10797
/.idea
10898
.vscode
99+
100+
# build artifacts
101+
dist
102+
*.tsbuildinfo
103+
packages/rollup/**/*.d.ts

packages/rollup/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @typedef {import('@rollup/pluginutils').FilterPattern} FilterPattern
3+
* @typedef {import('rollup').Plugin} Plugin
4+
* @typedef {import('rollup').SourceDescription} SourceDescription
5+
*/
6+
7+
/**
8+
* @typedef {Omit<import('@orgajs/orgx').CompileOptions, 'SourceMapGenerator'>} CompileOptions
9+
* Default configuration.
10+
*
11+
* @typedef RollupPluginOptions
12+
* Extra configuration.
13+
* @property {FilterPattern} [include]
14+
* List of picomatch patterns to include
15+
* @property {FilterPattern} [exclude]
16+
* List of picomatch patterns to exclude
17+
*
18+
* @typedef {CompileOptions & RollupPluginOptions} Options
19+
* Configuration.
20+
*/
21+
22+
import { VFile } from 'vfile'
23+
import { createFilter } from '@rollup/pluginutils'
24+
import { createProcessor } from '@orgajs/orgx'
25+
import { SourceMapGenerator } from 'source-map'
26+
27+
/**
28+
* Compile org-mode w/ rollup.
29+
*
30+
* @param {Options | null | undefined} [options]
31+
* Configuration.
32+
* @return {Plugin}
33+
* Rollup plugin.
34+
*/
35+
export default function (options) {
36+
const { include, exclude, ...rest } = options || {}
37+
const processor = createProcessor({
38+
SourceMapGenerator,
39+
...rest,
40+
})
41+
const filter = createFilter(include, exclude)
42+
43+
return {
44+
name: '@orgajs/rollup',
45+
async transform(value, path) {
46+
const file = new VFile({ value, path })
47+
48+
if (file.extname === '.org' && filter(file.path)) {
49+
const compiled = await processor.process(file)
50+
const code = String(compiled.value)
51+
/** @type {SourceDescription} */
52+
// @ts-expect-error: a) `undefined` is fine, b) `sourceRoot: undefined` is fine too.
53+
const result = { code, map: compiled.map }
54+
return result
55+
}
56+
},
57+
}
58+
}

packages/rollup/package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"description": "Rollup plugin for Orga",
55
"license": "MIT",
66
"files": [
7-
"dist/index.js",
8-
"dist/index.d.ts"
7+
"index.js",
8+
"index.d.ts"
99
],
10-
"main": "dist/index.js",
10+
"main": "index.js",
11+
"types": "index.d.ts",
1112
"type": "module",
1213
"author": "Xiaoxing Hu <[email protected]>",
1314
"homepage": "https://orga.js.org",
@@ -17,10 +18,8 @@
1718
"directory": "packages/rollup"
1819
},
1920
"scripts": {
20-
"build": "pnpm clean && pnpm compile",
21-
"clean": "del ./dist tsconfig.tsbuildinfo",
22-
"test": "ava",
23-
"compile": "tsc -b"
21+
"build": "tsc -b",
22+
"test": "node --test test.js"
2423
},
2524
"ava": {
2625
"typescript": {
@@ -35,12 +34,9 @@
3534
}
3635
},
3736
"devDependencies": {
38-
"@ava/typescript": "^4.0.0",
3937
"@types/node": "^20.2.1",
4038
"@types/react": "^18.2.6",
4139
"@types/react-dom": "^18.2.4",
42-
"ava": "^5.2.0",
43-
"del-cli": "^3.0.1",
4440
"react": "^18.2.0",
4541
"react-dom": "^18.2.0",
4642
"rollup": "^3.22.0",

packages/rollup/src/index.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import test from 'ava'
1+
import test from 'node:test'
2+
import assert from 'node:assert'
23
import { promises as fs } from 'fs'
34
import { rollup } from 'rollup'
45
import { fileURLToPath } from 'url'
56
import rollupOrg from './index.js'
67
import { renderToStaticMarkup } from 'react-dom/server'
78
import { createElement } from 'react'
89

9-
test('@orgajs/rollup', async (t) => {
10+
test('@orgajs/rollup', async () => {
1011
await fs.writeFile(new URL('rollup.org', import.meta.url), '* Hi')
1112

1213
const bundle = await rollup({
@@ -25,7 +26,7 @@ test('@orgajs/rollup', async (t) => {
2526

2627
// t.is(output[0].map ? output[0].map.mappings : undefined, undefined)
2728

28-
t.is(
29+
assert.equal(
2930
renderToStaticMarkup(createElement(Content)),
3031
'<div class="section"><h1>Hi</h1></div>'
3132
)

packages/rollup/tsconfig.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
2-
"extends": "../../tsconfig.esm.json",
3-
"compilerOptions": {
4-
"rootDir": "./src",
5-
"outDir": "./dist"
6-
},
7-
"references": [{ "path": "../orgx" }],
8-
"include": ["./src"]
2+
"extends": "../../tsconfig.types.json",
3+
"include": ["index.js"],
4+
"exclude": ["coverage/", "node_modules/"],
5+
"references": [{ "path": "../orgx" }]
96
}

0 commit comments

Comments
 (0)