From 134c34535162b621d4f010386ed8bd4b3cba925e Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 22 Jul 2021 17:00:09 -0700 Subject: [PATCH] Try adding browser specific tsconfig Trying to add this to catch dependencies we take on node types --- .../extension-browser.webpack.config.js | 2 ++ extensions/markdown-language-features/package.json | 1 - .../src/commands/openDocumentLink.ts | 3 +-- .../src/features/documentLinkProvider.ts | 4 ++-- .../markdown-language-features/src/features/preview.ts | 2 +- .../src/features/previewContentProvider.ts | 8 ++++---- .../markdown-language-features/src/markdownEngine.ts | 2 +- .../markdown-language-features/src/typings/ref.d.ts | 3 ++- extensions/markdown-language-features/src/util/path.ts | 8 ++++++++ extensions/markdown-language-features/src/util/url.ts | 2 -- .../markdown-language-features/tsconfig.browser.json | 9 +++++++++ extensions/markdown-language-features/yarn.lock | 5 ----- extensions/shared.webpack.config.js | 9 +++++++-- 13 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 extensions/markdown-language-features/src/util/path.ts create mode 100644 extensions/markdown-language-features/tsconfig.browser.json diff --git a/extensions/markdown-language-features/extension-browser.webpack.config.js b/extensions/markdown-language-features/extension-browser.webpack.config.js index 7fcc53a728b..1b52e196f91 100644 --- a/extensions/markdown-language-features/extension-browser.webpack.config.js +++ b/extensions/markdown-language-features/extension-browser.webpack.config.js @@ -14,4 +14,6 @@ module.exports = withBrowserDefaults({ entry: { extension: './src/extension.ts' } +}, { + configFile: 'tsconfig.browser.json' }); diff --git a/extensions/markdown-language-features/package.json b/extensions/markdown-language-features/package.json index 4e13ef4b9f1..2be92c795bd 100644 --- a/extensions/markdown-language-features/package.json +++ b/extensions/markdown-language-features/package.json @@ -362,7 +362,6 @@ "@types/highlight.js": "10.1.0", "@types/lodash.throttle": "^4.1.3", "@types/markdown-it": "0.0.2", - "@types/node": "14.x", "@types/vscode-webview": "^1.57.0", "lodash.throttle": "^4.1.1" }, diff --git a/extensions/markdown-language-features/src/commands/openDocumentLink.ts b/extensions/markdown-language-features/src/commands/openDocumentLink.ts index 79288f2d1f4..04a9cafe510 100644 --- a/extensions/markdown-language-features/src/commands/openDocumentLink.ts +++ b/extensions/markdown-language-features/src/commands/openDocumentLink.ts @@ -4,12 +4,11 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; -import { extname } from 'path'; - import { Command } from '../commandManager'; import { MarkdownEngine } from '../markdownEngine'; import { TableOfContentsProvider } from '../tableOfContentsProvider'; import { isMarkdownFile } from '../util/file'; +import { extname } from '../util/path'; type UriComponents = { diff --git a/extensions/markdown-language-features/src/features/documentLinkProvider.ts b/extensions/markdown-language-features/src/features/documentLinkProvider.ts index becb168794e..e4015e69a76 100644 --- a/extensions/markdown-language-features/src/features/documentLinkProvider.ts +++ b/extensions/markdown-language-features/src/features/documentLinkProvider.ts @@ -3,11 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import { OpenDocumentLinkCommand } from '../commands/openDocumentLink'; import { getUriForLinkWithKnownExternalScheme, isOfScheme, Schemes } from '../util/links'; +import { dirname } from '../util/path'; const localize = nls.loadMessageBundle(); @@ -43,7 +43,7 @@ function parseLink( resourceUri = vscode.Uri.joinPath(root, tempUri.path); } } else { - const base = document.uri.with({ path: path.dirname(document.uri.fsPath) }); + const base = document.uri.with({ path: dirname(document.uri.fsPath) }); resourceUri = vscode.Uri.joinPath(base, tempUri.path); } } diff --git a/extensions/markdown-language-features/src/features/preview.ts b/extensions/markdown-language-features/src/features/preview.ts index 7f1ea512f76..8bc0eabdf39 100644 --- a/extensions/markdown-language-features/src/features/preview.ts +++ b/extensions/markdown-language-features/src/features/preview.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import { OpenDocumentLinkCommand, resolveLinkToMarkdownFile } from '../commands/openDocumentLink'; @@ -17,6 +16,7 @@ import { MarkdownPreviewConfigurationManager } from './previewConfig'; import { MarkdownContentProvider, MarkdownContentProviderOutput } from './previewContentProvider'; import { MarkdownEngine } from '../markdownEngine'; import { urlToUri } from '../util/url'; +import * as path from '../util/path'; const localize = nls.loadMessageBundle(); diff --git a/extensions/markdown-language-features/src/features/previewContentProvider.ts b/extensions/markdown-language-features/src/features/previewContentProvider.ts index 42cfa8e6c22..5ba85bdc4d9 100644 --- a/extensions/markdown-language-features/src/features/previewContentProvider.ts +++ b/extensions/markdown-language-features/src/features/previewContentProvider.ts @@ -3,13 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as path from 'path'; import * as vscode from 'vscode'; import * as nls from 'vscode-nls'; import { Logger } from '../logger'; import { MarkdownEngine } from '../markdownEngine'; import { MarkdownContributionProvider } from '../markdownExtensions'; import { ContentSecurityPolicyArbiter, MarkdownPreviewSecurityLevel } from '../security'; +import { basename, dirname, isAbsolute, join } from '../util/path'; import { WebviewResourceProvider } from '../util/resources'; import { MarkdownPreviewConfiguration, MarkdownPreviewConfigurationManager } from './previewConfig'; @@ -110,7 +110,7 @@ export class MarkdownContentProvider { public provideFileNotFoundContent( resource: vscode.Uri, ): string { - const resourcePath = path.basename(resource.fsPath); + const resourcePath = basename(resource.fsPath); const body = localize('preview.notFound', '{0} cannot be found', resourcePath); return ` @@ -136,7 +136,7 @@ export class MarkdownContentProvider { } // Assume it must be a local file - if (path.isAbsolute(href)) { + if (isAbsolute(href)) { return resourceProvider.asWebviewUri(vscode.Uri.file(href)).toString(); } @@ -147,7 +147,7 @@ export class MarkdownContentProvider { } // Otherwise look relative to the markdown file - return resourceProvider.asWebviewUri(vscode.Uri.file(path.join(path.dirname(resource.fsPath), href))).toString(); + return resourceProvider.asWebviewUri(vscode.Uri.file(join(dirname(resource.fsPath), href))).toString(); } private computeCustomStyleSheetIncludes(resourceProvider: WebviewResourceProvider, resource: vscode.Uri, config: MarkdownPreviewConfiguration): string { diff --git a/extensions/markdown-language-features/src/markdownEngine.ts b/extensions/markdown-language-features/src/markdownEngine.ts index c9f162ad294..ebcf6542824 100644 --- a/extensions/markdown-language-features/src/markdownEngine.ts +++ b/extensions/markdown-language-features/src/markdownEngine.ts @@ -96,7 +96,7 @@ export class MarkdownEngine { } } - const frontMatterPlugin = require('markdown-it-front-matter'); + const frontMatterPlugin = await import('markdown-it-front-matter'); // Extract rules from front matter plugin and apply at a lower precedence let fontMatterRule: any; frontMatterPlugin({ diff --git a/extensions/markdown-language-features/src/typings/ref.d.ts b/extensions/markdown-language-features/src/typings/ref.d.ts index 954bab971e3..70164f82d42 100644 --- a/extensions/markdown-language-features/src/typings/ref.d.ts +++ b/extensions/markdown-language-features/src/typings/ref.d.ts @@ -5,4 +5,5 @@ /// /// -/// + +declare module 'markdown-it-front-matter'; diff --git a/extensions/markdown-language-features/src/util/path.ts b/extensions/markdown-language-features/src/util/path.ts new file mode 100644 index 00000000000..f25fd080975 --- /dev/null +++ b/extensions/markdown-language-features/src/util/path.ts @@ -0,0 +1,8 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +/// + +export { basename, dirname, extname, isAbsolute, join } from 'path'; diff --git a/extensions/markdown-language-features/src/util/url.ts b/extensions/markdown-language-features/src/util/url.ts index d91cb4ab06d..ba2ead65732 100644 --- a/extensions/markdown-language-features/src/util/url.ts +++ b/extensions/markdown-language-features/src/util/url.ts @@ -5,8 +5,6 @@ import * as vscode from 'vscode'; -declare const URL: typeof import('url').URL; - /** * Tries to convert an url into a vscode uri and returns undefined if this is not possible. * `url` can be absolute or relative. diff --git a/extensions/markdown-language-features/tsconfig.browser.json b/extensions/markdown-language-features/tsconfig.browser.json new file mode 100644 index 00000000000..e4c0db0fd10 --- /dev/null +++ b/extensions/markdown-language-features/tsconfig.browser.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": [] + }, + "exclude": [ + "./src/test/**" + ] +} diff --git a/extensions/markdown-language-features/yarn.lock b/extensions/markdown-language-features/yarn.lock index c5a5632b09a..714e75d062d 100644 --- a/extensions/markdown-language-features/yarn.lock +++ b/extensions/markdown-language-features/yarn.lock @@ -26,11 +26,6 @@ resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-0.0.2.tgz#5d9ad19e6e6508cdd2f2596df86fd0aade598660" integrity sha1-XZrRnm5lCM3S8llt+G/Qqt5ZhmA= -"@types/node@14.x": - version "14.14.43" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.43.tgz#26bcbb0595b305400e8ceaf9a127a7f905ae49c8" - integrity sha512-3pwDJjp1PWacPTpH0LcfhgjvurQvrZFBrC6xxjaUEZ7ifUtT32jtjPxEMMblpqd2Mvx+k8haqQJLQxolyGN/cQ== - "@types/vscode-webview@^1.57.0": version "1.57.0" resolved "https://registry.yarnpkg.com/@types/vscode-webview/-/vscode-webview-1.57.0.tgz#bad5194d45ae8d03afc1c0f67f71ff5e7a243bbf" diff --git a/extensions/shared.webpack.config.js b/extensions/shared.webpack.config.js index 73e5036c7fb..6354472500c 100644 --- a/extensions/shared.webpack.config.js +++ b/extensions/shared.webpack.config.js @@ -85,9 +85,13 @@ function nodePlugins(context) { new NLSBundlePlugin(id) ]; } +/** + * @typedef {{ + * configFile?: string + * }} AdditionalBrowserConfig + */ - -function withBrowserDefaults(/**@type WebpackConfig*/extConfig) { +function withBrowserDefaults(/**@type WebpackConfig*/extConfig, /** @type AdditionalBrowserConfig */ additionalOptions = {}) { /** @type WebpackConfig */ let defaultConfig = { mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') @@ -112,6 +116,7 @@ function withBrowserDefaults(/**@type WebpackConfig*/extConfig) { // * enable sources maps for end-to-end source maps loader: 'ts-loader', options: { + configFile: additionalOptions.configFile, compilerOptions: { 'sourceMap': true, }