-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
shikiji-core
package, improve bundling (#42)
- Loading branch information
Showing
44 changed files
with
1,675 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "packages/shikiji-core/vendor/vscode-textmate"] | ||
path = packages/shikiji-core/vendor/vscode-textmate | ||
url = https://github.com/microsoft/vscode-textmate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# shikiji-core | ||
|
||
The core functionality of [Shikiji](https://github.com/antfu/shikiji), without any grammar of themes bundled. | ||
|
||
It's the same as importing `shikiji/core`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "shikiji-core", | ||
"type": "module", | ||
"version": "0.9.3-alpha.0", | ||
"description": "Core of Shikiji", | ||
"author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/antfu/shikiji#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/antfu/shikiji.git", | ||
"directory": "packages/shikiji-core" | ||
}, | ||
"bugs": "https://github.com/antfu/shikiji/issues", | ||
"keywords": [ | ||
"shiki" | ||
], | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"./wasm": { | ||
"types": "./dist/wasm.d.mts", | ||
"default": "./dist/wasm.mjs" | ||
}, | ||
"./textmate": { | ||
"types": "./dist/textmate.d.mts", | ||
"default": "./dist/textmate.mjs" | ||
}, | ||
"./types": { | ||
"types": "./dist/types.d.mts" | ||
}, | ||
"./dist/*": "./dist/*", | ||
"./*": "./dist/*" | ||
}, | ||
"main": "./dist/index.mjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.mts", | ||
"typesVersions": { | ||
"*": { | ||
"wasm": [ | ||
"./dist/wasm.d.mts" | ||
], | ||
"types": [ | ||
"./dist/types.d.mts" | ||
], | ||
"textmate": [ | ||
"./dist/textmate.d.mts" | ||
], | ||
"*": [ | ||
"./dist/*", | ||
"./*" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c", | ||
"dev": "rollup -cw", | ||
"prepublishOnly": "nr build", | ||
"test": "vitest" | ||
}, | ||
"devDependencies": { | ||
"hast-util-to-html": "^9.0.0", | ||
"vscode-oniguruma": "^1.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// @ts-check | ||
import { defineConfig } from 'rollup' | ||
import { nodeResolve } from '@rollup/plugin-node-resolve' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import replace from '@rollup/plugin-replace' | ||
import dts from 'rollup-plugin-dts' | ||
import json from '@rollup/plugin-json' | ||
import fs from 'fs-extra' | ||
import ts from 'rollup-plugin-typescript2' | ||
|
||
const entries = [ | ||
'src/index.ts', | ||
'src/types.ts', | ||
'src/textmate.ts', | ||
'src/wasm.ts', | ||
] | ||
|
||
const plugins = [ | ||
ts({ | ||
check: false, | ||
}), | ||
replace({ | ||
'DebugFlags.InDebugMode': 'false', | ||
'preventAssignment': true, | ||
}), | ||
nodeResolve(), | ||
commonjs(), | ||
json({ | ||
namedExports: false, | ||
preferConst: true, | ||
compact: true, | ||
}), | ||
wasmPlugin(), | ||
] | ||
|
||
export default defineConfig([ | ||
{ | ||
input: entries, | ||
output: { | ||
dir: 'dist', | ||
format: 'esm', | ||
entryFileNames: '[name].mjs', | ||
chunkFileNames: (f) => { | ||
if (f.name === 'onig') | ||
return 'onig.mjs' | ||
return 'chunks-[name].mjs' | ||
}, | ||
}, | ||
plugins: [ | ||
...plugins, | ||
], | ||
}, | ||
{ | ||
input: entries, | ||
output: { | ||
dir: 'dist', | ||
format: 'esm', | ||
chunkFileNames: '[name].d.mts', | ||
entryFileNames: f => `${f.name.replace(/src[\\\/]/, '')}.d.mts`, | ||
}, | ||
plugins: [ | ||
dts({ | ||
respectExternal: true, | ||
}), | ||
{ | ||
name: 'post', | ||
async buildEnd() { | ||
await fs.writeFile('dist/onig.d.mts', 'declare const binary: ArrayBuffer; export default binary;', 'utf-8') | ||
}, | ||
}, | ||
], | ||
onwarn: (warning, warn) => { | ||
if (!/Circular|an empty chunk/.test(warning.message)) | ||
warn(warning) | ||
}, | ||
external: [], | ||
}, | ||
]) | ||
|
||
/** | ||
* @returns {import('rollup').Plugin} Plugin | ||
*/ | ||
export function wasmPlugin() { | ||
return { | ||
name: 'wasm', | ||
async load(id) { | ||
if (!id.endsWith('.wasm')) | ||
return | ||
const binary = await fs.readFile(id) | ||
const base64 = binary.toString('base64') | ||
return `export default Uint8Array.from(atob(${JSON.stringify(base64)}), c => c.charCodeAt(0))` | ||
}, | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/shikiji/src/core/bundle-factory.ts → packages/shikiji-core/src/bundle-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/shikiji/src/core/highlighter.ts → packages/shikiji-core/src/highlighter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/shikiji/src/core/index.ts → packages/shikiji-core/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/shikiji/src/core/normalize.ts → packages/shikiji-core/src/normalize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
packages/shikiji/src/core/registry.ts → packages/shikiji-core/src/registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/shikiji/src/core/renderer-html.ts → packages/shikiji-core/src/renderer-html.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.