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(unify): removing prism and adding infrastructure for shiki #18514

Merged
merged 49 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
288f854
feat: use shikijs for highlighting code
elevatebart Oct 15, 2021
04f80da
add line numbers
elevatebart Oct 15, 2021
5ff4766
fix Jess's remarks
elevatebart Oct 15, 2021
7652eb2
remove last instances of prism
elevatebart Oct 15, 2021
07cf11e
fix: remove unused prism packages
elevatebart Oct 15, 2021
199ced0
fix broken build
elevatebart Oct 15, 2021
9b21d6e
remove prism
elevatebart Oct 15, 2021
d2cfe60
remnove prism one last time
elevatebart Oct 15, 2021
69f416f
remove the last piece of prism in tests
elevatebart Oct 16, 2021
81aa7eb
remove prism and refactor
elevatebart Oct 16, 2021
233b9da
restore proper fe-shared test
elevatebart Oct 16, 2021
0eeae6e
use windi to color shiki
elevatebart Oct 16, 2021
3693b3b
rename theme and create test
elevatebart Oct 16, 2021
60929e5
cosmetic fixes
elevatebart Oct 16, 2021
29a75f7
Merge branch 'unified-desktop-gui' into spike/use-shiki
elevatebart Oct 18, 2021
407127d
avoid the jank
elevatebart Oct 18, 2021
e21c7aa
fix image imports in typescript
elevatebart Oct 18, 2021
8fe21f2
restore mistake
elevatebart Oct 18, 2021
ef06a82
make the shiki theme generator
elevatebart Oct 18, 2021
3fb08e9
gitignore the shiki-heme generated
elevatebart Oct 18, 2021
f7ccbc6
add the shiki theme generation to yarn build
elevatebart Oct 18, 2021
ace67eb
make shiki theme look good
elevatebart Oct 18, 2021
7c322fd
last colors to update
elevatebart Oct 18, 2021
bb5a38e
styling fixes
JessicaSachs Oct 19, 2021
f86e81f
Merge branch 'spike/use-shiki' of https://github.com/cypress-io/cypre…
JessicaSachs Oct 19, 2021
6dcfb9b
styling fixes
JessicaSachs Oct 19, 2021
952ef4c
styling fixes
JessicaSachs Oct 19, 2021
3d75ee6
styling fixes
JessicaSachs Oct 19, 2021
705b893
theme
JessicaSachs Oct 19, 2021
afe9f2d
fix relative positioning
JessicaSachs Oct 19, 2021
5d5057e
Update .gitignore
JessicaSachs Oct 19, 2021
55958a7
Update packages/frontend-shared/src/components/ShikiHighlight.vue
JessicaSachs Oct 19, 2021
c607b47
remove conflicting copy button
JessicaSachs Oct 19, 2021
d50cc68
Merge branch 'spike/use-shiki' of https://github.com/cypress-io/cypre…
JessicaSachs Oct 19, 2021
087debc
dont top level await
lmiller1990 Oct 19, 2021
452e7f6
add a readme for theme generation
elevatebart Oct 19, 2021
029fb48
ignore generated theme
elevatebart Oct 19, 2021
d91d2c4
fix integration test in launchpad
elevatebart Oct 19, 2021
730be2b
fix other integration test
elevatebart Oct 19, 2021
294f6ff
Merge branch 'unified-desktop-gui' into spike/use-shiki
Oct 19, 2021
871ca03
bring back the cypress theme
elevatebart Oct 19, 2021
b42c22b
fixing public path issue
JessicaSachs Oct 19, 2021
bbbb111
Merge branch 'spike/use-shiki' of https://github.com/cypress-io/cypre…
JessicaSachs Oct 19, 2021
6e54730
make e2e work
elevatebart Oct 19, 2021
55789ae
fix yarn dev (remove the double slash)
elevatebart Oct 19, 2021
8da29c1
review theme with ryan
elevatebart Oct 19, 2021
253693c
make copy on click optional
elevatebart Oct 19, 2021
82188c1
adjust viewports
elevatebart Oct 19, 2021
25a521e
move generation of theme before vite build
elevatebart Oct 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion npm/vite-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@cypress/react": "0.0.0-development",
"@cypress/vue": "0.0.0-development",
"@testing-library/cypress": "7.0.4",
"@vitejs/plugin-vue": "1.2.0",
"@vitejs/plugin-vue": "1.2.4",
"@vue/compiler-sfc": "3.2.6",
"cypress": "0.0.0-development",
"eslint-plugin-vue": "7.18.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"graphql-tag": "^2.12.5",
"javascript-time-ago": "2.3.8",
"just-my-luck": "3.0.0",
"prismjs": "1.24.0",
"rimraf": "3.0.2",
"rollup-plugin-polyfill-node": "^0.7.0",
"unplugin-icons": "^0.11.3",
Expand All @@ -59,8 +58,6 @@
"vite-svg-loader": "2.1.1",
"vue": "3.2.6",
"vue-i18n": "9.2.0-beta.7",
"vue-prism-component": "2.0.0",
"vue-prism-editor": "^2.0.0-alpha.2",
"vue-router": "4",
"vue-tsc": "^0.3.0",
"windicss": "3.1.4",
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend-shared/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Windi CSS can create an awesome interactive summary showing our usage of utility
## from this directory
yarn windi
```

## Generate the theme for shiki

See [the readme in the src/public/shiki/themes directory](./src/public/shiki/themes/ReadMe.md)
1 change: 0 additions & 1 deletion packages/frontend-shared/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = (on, config) => {
optimizeDeps: {
include: [
'@headlessui/vue',
'vue-prism-component',
'vue3-file-selector',
'just-my-luck',
'combine-properties',
Expand Down
7 changes: 7 additions & 0 deletions packages/frontend-shared/cypress/support/common.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// Add cy.mount, cy.mountFragment, cy.mountFragmentList
export * from './mock-graphql/mountFragment'

import { initHighlighter } from '@cy/components/ShikiHighlight.vue'

// Make sure highlighter is initialized before
// we show any code to avoid jank at rendering
// @ts-ignore
initHighlighter()
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export const stubWizard: MaybeResolver<Wizard> = {
],
allBundlers,
sampleCode: `
import { startDevServer } from '@cypress/vite-dev-server'
import { startDevServer } from '@cypress/vite-dev-server'

/* This is some test data. It does not need to be valid code. */
/* This is some test data. It does not need to be valid code. */
`,
chosenTestingTypePluginsInitialized: false,
testingTypes: (TESTING_TYPES as Writeable<typeof TESTING_TYPES>).map((type) => {
Expand Down
41 changes: 36 additions & 5 deletions packages/frontend-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"windi": "yarn windicss-analysis",
"cypress:open": "cross-env TZ=America/New_York node ../../scripts/cypress open-ct --project ${PWD}",
"cypress:run": "cross-env TZ=America/New_York node ../../scripts/cypress run-ct --project ${PWD}",
"dev": "vite --open"
"dev": "vite --open",
"generate-shiki-theme": "node ./script/generate-shiki-theme.js"
},
"dependencies": {
"shiki": "^0.9.12"
},
"dependencies": {},
"devDependencies": {
"@antfu/utils": "^0.3.0",
"@cypress/vite-dev-server": "0.0.0-development",
Expand All @@ -27,8 +30,8 @@
"@urql/exchange-execute": "1.1.0",
"@urql/exchange-graphcache": "4.3.3",
"@urql/vue": "0.4.3",
"@vitejs/plugin-vue": "^1.9.2",
"@vitejs/plugin-vue-jsx": "^1.1.8",
"@vitejs/plugin-vue": "1.2.4",
"@vitejs/plugin-vue-jsx": "1.1.6",
"@vue/compiler-core": "3.2.6",
"@vue/compiler-dom": "3.2.6",
"@vue/compiler-sfc": "3.2.6",
Expand Down Expand Up @@ -57,5 +60,33 @@
"windicss-analysis": "^0.3.4",
"wonka": "^4.0.15"
},
"module": "es2020"
"module": "es2020",
"vite": {
"optimizeDeps": {
"include": [
"@testing-library/cypress/add-commands",
"@urql/core",
"@urql/devtools",
"@urql/exchange-execute",
"@urql/exchange-graphcache",
"@urql/vue",
"@vue/test-utils",
"@vueuse/core",
"cypress-file-upload",
"dedent",
"fake-uuid",
"graphql",
"graphql-relay",
"graphql/jsutils/Path",
"lodash",
"path",
"shiki",
"socket.io-client",
"vue",
"vue-i18n",
"vue-toastification",
"wonka"
]
}
}
}
30 changes: 30 additions & 0 deletions packages/frontend-shared/script/generate-shiki-theme-ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable no-console */
import { colors } from '../.windicss/colors'
import * as fs from 'fs'

const filePath = './src/public/shiki/themes/cypress.theme'

fs.readFile(`${filePath}.template.json`,
{ encoding: 'utf8' },
(err, contents) => {
if (err) {
throw err
}

for (let colorName in colors) {
const colorScale = colors[colorName]

for (let colorGrade in colorScale) {
const variableNameRegExp = new RegExp(`-${colorName}-${colorGrade}"`, 'g')

contents = contents.replace(variableNameRegExp, `${colorScale[colorGrade]}"`)
}
}
fs.writeFile(`${filePath}.json`, contents, (err) => {
if (err) {
throw err
}

console.log(`${filePath}.json generated successfully`)
})
})
2 changes: 2 additions & 0 deletions packages/frontend-shared/script/generate-shiki-theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('@packages/ts/register')
module.exports = require('./generate-shiki-theme-ts').default
72 changes: 72 additions & 0 deletions packages/frontend-shared/src/components/ShikiHighlight.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import ShikiHighlight, { initHighlighter } from './ShikiHighlight.vue'
import code from '../../windi.config?raw'

const devServerCode = `const { defineConfig } = require('cypress')
const { devServer, defineDevServerConfig } = require('@cypress/vite-dev-server')

module.exports = defineConfig({
component: {
devServer,
devServerConfig: defineDevServerConfig({
entryHtmlFile: 'cypress/component/support/entry.html'
}),
},
})`

describe('<ShikiHighlight/>', { viewportWidth: 800, viewportHeight: 500 }, () => {
beforeEach(async () => {
await initHighlighter()
})

it('playground', () => {
cy.mount(() => (<div class="p-12">
<ShikiHighlight code={devServerCode} lang="js" lineNumbers />
</div>))
})

it('trims whitespace to show the correct number of lines', { viewportWidth: 500, viewportHeight: 500 }, () => {
const line = `console.log('my string')`
const numLines = 15

// Whitespace
// eslint-disable-next-line
const code = `


${Array.from(Array(numLines).keys()).map(() => line).join('\n')}


`

cy.mount(() => (<div class="p-12">
<ShikiHighlight code={code} lang="js" lineNumbers />
</div>))
.get('.line')
.should('have.length', numLines)
})

it('wraps long code without line numbers', { viewportWidth: 900, viewportHeight: 500 }, () => {
cy.mount(() => <div class="p-12"><ShikiHighlight wrap code={code} lang="ts" /></div>)
cy.get('.shiki').should('be.visible')
})

it('wraps long code with line numbers', () => {
cy.mount(() => <div class="p-12"><ShikiHighlight lineNumbers wrap code={code} lang="ts" /></div>)
cy.get('.shiki').should('be.visible')
})

it('render the code without arguments', () => {
cy.mount(() => <div class="p-12"><ShikiHighlight code={code} lang="ts" /></div>)
cy.get('.shiki').should('be.visible')
})

it('display inline and remove some of the padding when "inline"', { viewportWidth: 300, viewportHeight: 100 }, () => {
cy.mount(() => <ShikiHighlight code={'project: xv123456'} lang="yaml" inline />)
cy.get('.shiki').should('be.visible')
})

it('show line numbers when the prop is passed', () => {
cy.mount(() => <div class="p-12"><ShikiHighlight code={code} lang="ts" lineNumbers /></div>)
cy.get('.shiki').should('be.visible')
})
})
Loading