Repository: marp-team/marp-vscode
Pull request #297 (2021-10-02 08:13:44)

Remove alert for web extensions
Reverts 6f4a19f. It had been added because I could not confirm contribution by markdown-it extension, but actually it was no meanings for github.dev.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bde41e4..433ceb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@
 
 - Update launch option for testing web extension ([#296](https://github.com/marp-team/marp-vscode/pull/296))
 
+### Removed
+
+- Alert about preview of web extension ([#297](https://github.com/marp-team/marp-vscode/pull/297))
+
 ## v1.4.0 - 2021-09-03
 
 ### Breaking
diff --git a/src/extension.ts b/src/extension.ts
index 169906d..2e99dec 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -13,7 +13,6 @@ import lineNumber from './plugins/line-number'
 import outline, { rule as outlineRule } from './plugins/outline'
 import themes, { Themes } from './themes'
 import { detectMarpFromMarkdown, marpConfiguration } from './utils'
-import { showAlertForWebExtension } from './web/alert'
 
 const shouldRefreshConfs = [
   'markdown.marp.breaks',
@@ -53,7 +52,7 @@ const hackGetScriptsToExecuteMarpScriptFirst = (resourceProvider: any) => {
 
         if (marpScriptIdx >= 0) {
           const [marpScript] = scripts.splice(marpScriptIdx, 1)
-          scripts.unshift(marpScript.replace('async', ''))
+          scripts.unshift(marpScript.replace(/\s*async/, ''))
         }
 
         return scripts.join('\n')
@@ -176,9 +175,7 @@ export function extendMarkdownIt(md: any) {
   return md
 }
 
-export const activate = ({ subscriptions, globalState }: ExtensionContext) => {
-  showAlertForWebExtension(globalState)
-
+export const activate = ({ subscriptions }: ExtensionContext) => {
   diagnostics(subscriptions)
   languageProvider(subscriptions)
 
diff --git a/src/web/alert.ts b/src/web/alert.ts
deleted file mode 100644
index 48cc7f8..0000000
--- a/src/web/alert.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { env, window, MessageItem, Memento } from 'vscode'
-
-const dontShowAgainKey = 'webExtAlertDontShowAgain' as const
-
-export const continueItem: MessageItem = { title: 'Continue' }
-export const dontShowAgainItem: MessageItem = {
-  title: "Don't show again",
-  isCloseAffordance: true,
-}
-
-export const showAlertForWebExtension = async (memento: Memento) => {
-  if (env.appHost !== 'web') return
-  if (memento.get(dontShowAgainKey)) return
-
-  const ret = await window.showErrorMessage(
-    'You are using Marp for VS Code extension on the web.',
-    {
-      modal: true,
-      detail:
-        'Marp extension for Web is very early preview. Please note that most of the features are not working correctly.',
-    },
-    continueItem,
-    dontShowAgainItem
-  )
-
-  if (ret === dontShowAgainItem) await memento.update(dontShowAgainKey, true)
-}


Test patch:
diff --git a/src/extension.test.ts b/src/extension.test.ts
index 92c05b7..34299b7 100644
--- a/src/extension.test.ts
+++ b/src/extension.test.ts
@@ -6,21 +6,12 @@ import { Marp } from '@marp-team/marp-core'
 import dedent from 'dedent'
 import markdownIt from 'markdown-it'
 import * as nodeFetch from 'node-fetch'
-import {
-  Memento,
-  MessageItem,
-  Uri,
-  commands,
-  window,
-  workspace,
-  env,
-} from 'vscode'
+import { Memento, Uri, commands, workspace, env } from 'vscode'
 
 jest.mock('node-fetch')
 jest.mock('vscode')
 
 let themes: typeof import('./themes')['default']
-let dontShowAgainItem: MessageItem
 
 const extension = (): typeof import('./extension') => {
   let ext
@@ -28,7 +19,6 @@ const extension = (): typeof import('./extension') => {
   jest.isolateModules(() => {
     ext = require('./extension') // Shut up cache
     themes = require('./themes').default
-    dontShowAgainItem = require('./web/alert').dontShowAgainItem
   })
 
   return ext
@@ -72,51 +62,6 @@ describe('#activate', () => {
       'markdown.preview.refresh'
     )
   })
-
-  it('does not show alert modal', () => {
-    extension().activate(extContext())
-    expect(window.showErrorMessage).not.toHaveBeenCalled()
-  })
-
-  describe('when running Web extension', () => {
-    let previousAppHost: string
-
-    beforeEach(() => {
-      previousAppHost = env.appHost
-      ;(env as any).appHost = 'web'
-    })
-
-    afterEach(() => {
-      ;(env as any).appHost = previousAppHost
-    })
-
-    it('shows alert modal', () => {
-      extension().activate(extContext())
-      expect(window.showErrorMessage).toHaveBeenCalledWith(
-        expect.stringContaining('Marp for VS Code extension on the web'),
-        expect.objectContaining({ modal: true }),
-        expect.objectContaining({ title: expect.any(String) }),
-        expect.objectContaining({ title: expect.any(String) })
-      )
-    })
-
-    it(`does not show alert modal again if reacted to "Don't show again"`, async () => {
-      const { activate } = extension()
-      const showErrorMessageMock = window.showErrorMessage as jest.Mock
-      showErrorMessageMock.mockResolvedValueOnce(dontShowAgainItem)
-
-      // React to "Don't show again"
-      const context = extContext()
-      activate(context)
-
-      expect(window.showErrorMessage).toHaveBeenCalledTimes(1)
-      await showErrorMessageMock.mock.results[0].value
-
-      // Activate extension again, with already reacted globalState
-      activate({ ...extContext(), globalState: context.globalState })
-      expect(window.showErrorMessage).toHaveBeenCalledTimes(1)
-    })
-  })
 })
 
 describe('#extendMarkdownIt', () => {
@@ -540,7 +485,7 @@ describe('#extendMarkdownIt', () => {
       md.render('test', { resourceProvider })
 
       expect(_contentProvider.getScripts()).toMatchInlineSnapshot(`
-        "<script 
+        "<script
           src=\\"https://example.com/marp-vscode/preview.js\\"
           nonce=\\"0987654321\\"
         ></script>