Skip to content

Commit

Permalink
feat: enable open in editor from chrome devtools
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Jun 28, 2022
1 parent 37b88af commit 0014192
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"@stagas/chalk": "5.0.0",
"decarg": "^1.2.0",
"github-markdown-css": "5.1.0",
"open-in-editor-connect": "1.0.0",
"qrcode-terminal": "0.12.0",
"running-at": "0.3.22",
"vite": "2.8.6",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import commonjs from '@rollup/plugin-commonjs'
import chalk from '@stagas/chalk'
import { arg } from 'decarg'
import * as fs from 'fs'
import openInEditor from 'open-in-editor-connect'
import * as path from 'path'
import qrcode from 'qrcode-terminal'
import { InlineConfig as ViteConfig, mergeConfig, ViteDevServer } from 'vite'
Expand Down Expand Up @@ -246,6 +247,10 @@ export const open = async (options: Partial<Options>): Promise<ViteServer> => {
{
name: 'configure-server',
configureServer(server: ViteDevServer) {
server.middlewares.use(openInEditor('.', {
editor: { name: 'code' },
}))

server.middlewares.use((req, res, next) => {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
Expand Down
2 changes: 2 additions & 0 deletions types/modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ambient types like:
declare module 'qrcode-terminal'

declare module 'open-in-editor-connect'

declare module '*.md' {
// "unknown" would be more detailed depends on how you structure frontmatter
const attributes: Record<string, unknown>
Expand Down

0 comments on commit 0014192

Please sign in to comment.