Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dependency updates incl. textmate #377

Merged
merged 10 commits into from
Dec 18, 2022
15 changes: 11 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ module.exports = {
testTimeout: 10000,
testEnvironment: 'node',
globals: {
__BROWSER__: false,
'ts-jest': {
tsconfig: {
__BROWSER__: false
},
snapshotFormat: {
escapeString: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a change in Jest -> they don't escape anymore. For the sake of simplicity (no updated snapshots) in this PR I set the tests to use the previous behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made those changes in Jest ;) - but I dig not making things change unnecessarily

printBasicPrototype: true
},
transform: {
'^.+\\.tsx?$': [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another Jest change, this needs now to be a part of the transform object.

'ts-jest',
{
target: 'esnext',
lib: ['ESNext', 'DOM', 'WebWorker']
}
}
]
}
}
5 changes: 2 additions & 3 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"packages": [
"packages/*"
],
"packages": ["packages/*"],
"useWorkspaces": true,
"version": "0.11.0",
"npmClient": "pnpm"
}
50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"scripts": {
"build": "pnpm -r build",
"dev": "pnpm -r --parallel watch",
"dev": "pnpm -r --parallel watch",
"fmt": "prettier --write packages/**/*.ts",
"test": "cross-env NODE_OPTIONS=--max-old-space-size=4096 jest --colors",
"update": "npm run update:themes && npm run update:grammars",
Expand All @@ -21,36 +21,38 @@
]
},
"devDependencies": {
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^3.1.0",
"@rollup/plugin-commonjs": "^23.0.5",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@rollup/plugin-terser": "^0.2.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^26.0.24",
"@types/jest": "^29.2.4",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.12",
"@types/node": "^18.11.15",
"@types/unzipper": "^0.10.5",
"chalk": "^4.1.2",
"chalk": "^5.2.0",
"cross-env": "^7.0.3",
"esbuild": "^0.14.22",
"esno": "^0.5.0",
"fast-plist": "^0.1.2",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"jsonc-parser": "^3.0.0",
"lerna": "^3.22.1",
"lint-staged": "^10.5.4",
"esno": "^0.16.3",
"fast-plist": "^0.1.3",
"fs-extra": "^11.1.0",
"jest": "^29.3.1",
"jsonc-parser": "^3.2.0",
"lerna": "^6.1.0",
"lint-staged": "^13.1.0",
"lodash.kebabcase": "^4.1.1",
"prettier": "^2.5.1",
"rollup": "^2.67.2",
"prettier": "^2.8.1",
"rollup": "^3.7.4",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-dts": "^3.0.2",
"rollup-plugin-esbuild": "^4.8.2",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^26.5.6",
"tsup": "^4.14.0",
"typescript": "^4.5.5",
"rollup-plugin-dts": "^5.0.0",
"rollup-plugin-esbuild": "^5.0.0",
"ts-jest": "^29.0.3",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"unzipper": "^0.10.11",
"yorkie": "^2.0.0"
},
"license": "MIT"
"license": "MIT",
"dependencies": {
"esbuild": "^0.16.7"
}
}
8 changes: 4 additions & 4 deletions packages/renderer-path/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"watch": "rollup -c -w"
},
"peerDependencies": {
"shiki": "^0.9.3"
"shiki": "^0.11.1"
},
"devDependencies": {
"@types/node": "^14.17.7",
"@types/opentype.js": "^1.3.3",
"@types/node": "^18.11.15",
"@types/opentype.js": "^1.3.4",
"opentype.js": "^1.3.4",
"shiki": "^0.9.7"
"shiki": "^0.11.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//@ts-check

// Re: https://github.com/rollup/plugins/issues/1366
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
global['__filename'] = __filename;

import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
import rollupReplace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
import terser from '@rollup/plugin-terser'

const replace = opts => {
return rollupReplace({
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer-path/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"target": "ES2020",
"esModuleInterop": true,
"moduleResolution": "node",
"lib": ["esnext", "DOM"],
Expand Down
8 changes: 4 additions & 4 deletions packages/renderer-svg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
},
"peerDependencies": {
"playwright": "^1.9.2",
"shiki": "^0.10.1"
"shiki": "^0.11.1"
},
"devDependencies": {
"@types/node": "^14.17.7",
"playwright": "^1.19.1",
"shiki": "^0.10.1"
"@types/node": "^18.11.15",
"playwright": "^1.28.1",
"shiki": "^0.11.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
//@ts-check

// Re: https://github.com/rollup/plugins/issues/1366
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
global['__filename'] = __filename;

import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
import { terser } from 'rollup-plugin-terser'
import terser from '@rollup/plugin-terser'
import rollupReplace from '@rollup/plugin-replace'

const replace = opts => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ test(`SVG renderer should ignore minimal background width when it's own boundari
const out = (await r).renderToSVG([[{ content: 'foo', color: '#aabbccff' }]])
expect(out).toContain(`<svg viewBox="0 0 156`)
// expect(out).toMatchSnapshot()

})
2 changes: 1 addition & 1 deletion packages/renderer-svg/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"target": "ES2020",
"esModuleInterop": true,
"moduleResolution": "node",
"lib": ["esnext", "DOM"],
Expand Down
8 changes: 4 additions & 4 deletions packages/shiki/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"url": "git+https://github.com/octref/shiki.git"
},
"dependencies": {
"jsonc-parser": "^3.0.0",
"vscode-oniguruma": "^1.6.1",
"vscode-textmate": "^6.0.0"
"jsonc-parser": "^3.2.0",
"vscode-oniguruma": "^1.7.0",
"vscode-textmate": "^8.0.0"
},
"devDependencies": {
"@types/node": "^14.17.7"
"@types/node": "^18.11.15"
},
"browser": {
"fs": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
//@ts-check

// Re: https://github.com/rollup/plugins/issues/1366
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
global['__filename'] = __filename;

import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import dts from 'rollup-plugin-dts'
import esbuild from 'rollup-plugin-esbuild'
import copy from 'rollup-plugin-copy'
import { terser } from 'rollup-plugin-terser'
import { version } from './package.json'
import terser from '@rollup/plugin-terser'
import rollupReplace from '@rollup/plugin-replace'
import { defineConfig } from 'rollup'
import { resolve } from 'path'
import { readFileSync } from 'fs'



const replace = opts => {
return rollupReplace({
Expand All @@ -16,6 +25,8 @@ const replace = opts => {
})
}

const pkg = JSON.parse(readFileSync('./package.json', 'utf8'))

const external = ['vscode-oniguruma', 'vscode-textmate']
const globals = {
'vscode-oniguruma': 'vscode-oniguruma',
Expand Down Expand Up @@ -78,7 +89,7 @@ export default defineConfig([
plugins: [
replace({
__BROWSER__: JSON.stringify(true),
__CDN_ROOT__: `https://unpkg.com/shiki@${version}/`
__CDN_ROOT__: `https://unpkg.com/shiki@${pkg.version}/`
}),
esbuild(),
nodeResolve(),
Expand All @@ -99,7 +110,7 @@ export default defineConfig([
plugins: [
replace({
__BROWSER__: JSON.stringify(true),
__CDN_ROOT__: `https://cdn.jsdelivr.net/npm/shiki@${version}/`
__CDN_ROOT__: `https://cdn.jsdelivr.net/npm/shiki@${pkg.version}/`
}),
esbuild(),
nodeResolve(),
Expand All @@ -118,7 +129,7 @@ export default defineConfig([
plugins: [
dts(),
copy({
targets: [{ src: require.resolve('vscode-oniguruma/release/onig.wasm'), dest: 'dist' }]
targets: [{ src: resolve('node_modules/vscode-oniguruma/release/onig.wasm'), dest: 'dist' }]
})
],
onwarn: (warning, warn) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Handle multiple font styles 1`] = `"<pre class=\\"shiki\\" style=\\"background-color: #263238\\"><code><span class=\\"line\\"><span style=\\"color: #89DDFF; font-style: italic\\">**</span><span style=\\"color: #89DDFF; font-style: italic\\">*</span><span style=\\"color: #F07178; font-style: italic\\">bold italic</span><span style=\\"color: #89DDFF; font-style: italic\\">*</span><span style=\\"color: #89DDFF; font-style: italic\\">**</span></span></code></pre>"`;
exports[`Handle multiple font styles 1`] = `"<pre class=\\"shiki\\" style=\\"background-color: #263238\\"><code><span class=\\"line\\"><span style=\\"color: #89DDFF; font-weight: bold\\">**</span><span style=\\"color: #89DDFF; font-style: italic; font-weight: bold\\">*</span><span style=\\"color: #F07178; font-style: italic; font-weight: bold\\">bold italic</span><span style=\\"color: #89DDFF; font-style: italic; font-weight: bold\\">*</span><span style=\\"color: #89DDFF; font-weight: bold\\">**</span></span></code></pre>"`;
12 changes: 12 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-bold.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff",
"fontStyle": "bold"
}
}
]
}
12 changes: 12 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-italic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff",
"fontStyle": "italic"
}
}
]
}
11 changes: 11 additions & 0 deletions packages/shiki/src/__tests__/custom-fonts/font-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tokenColors": [
{
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#ffffff"
}
}
]
}
47 changes: 47 additions & 0 deletions packages/shiki/src/__tests__/fontStyle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path'
import { getHighlighter, loadTheme } from '../index'

test('No font-style is applied if none is specified', async () => {
const fNone = await loadTheme(path.resolve(__dirname, './custom-fonts/font-none.json'))
const highlighter = await getHighlighter({
theme: fNone,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).not.toContain('font-style:')
})

test('An italic font-style is applied if specified', async () => {
const fItalic = await loadTheme(path.resolve(__dirname, './custom-fonts/font-italic.json'))
const highlighter = await getHighlighter({
theme: fItalic,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).toContain('font-style: italic')
})

test('A bold font-style is applied if specified', async () => {
const fBold = await loadTheme(path.resolve(__dirname, './custom-fonts/font-bold.json'))
const highlighter = await getHighlighter({
theme: fBold,
langs: ['js']
})
// console.log(JSON.stringify(highlighter.codeToThemedTokens(`function() {return 1}`, 'js'), null, 2))
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).toContain('font-weight: bold')
})

test('A bold fontStyle should not apply an italic font-style', async () => {
const fBold = await loadTheme(path.resolve(__dirname, './custom-fonts/font-bold.json'))
const highlighter = await getHighlighter({
theme: fBold,
langs: ['js']
})
const out = highlighter.codeToHtml(`function() {return 1}`, { lang: 'js' })

expect(out).not.toContain('font-style: italic')
})
4 changes: 2 additions & 2 deletions packages/shiki/src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, dirpathparts } from './utils'
import type { IOnigLib, IRawGrammar, IRawTheme } from 'vscode-textmate'
import type { IGrammar, IOnigLib, IRawTheme } from 'vscode-textmate'
import { loadWASM, createOnigScanner, createOnigString } from 'vscode-oniguruma'
import { parse, ParseError } from 'jsonc-parser'
import type { IShikiTheme } from './types'
Expand Down Expand Up @@ -150,7 +150,7 @@ export async function fetchTheme(themePath: string): Promise<IShikiTheme> {
return shikiTheme
}

export async function fetchGrammar(filepath: string): Promise<IRawGrammar> {
export async function fetchGrammar(filepath: string): Promise<IGrammar> {
return await _fetchJSONAssets(filepath)
}

Expand Down
Loading