From deeca27cc4290ef02d4f793ce5189dd18cf023ec Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Sat, 9 Mar 2024 14:29:41 +0100 Subject: [PATCH] refactor: project quality of life improvements (#254) * refactor: simplify asset link URI resolving * refactor: simplify types in test utilities * refactor: keep same `getWorkspaceUri` parameters as `vscode.Uri.joinPath` * refactor: add types and simplufy `getWorkspaceUri` calls * refactor: move extension properties to environment variables --- src/__tests__/commands/code-provider.e2e.ts | 8 ++-- src/__tests__/commands/preview-config.e2e.ts | 19 ++++++--- .../commands/preview-modifier-json.e2e.ts | 24 ++++++------ .../commands/preview-modifier.e2e.ts | 36 ++++++++--------- src/__tests__/extension.e2e.ts | 4 +- src/__tests__/manifestAssetCompletions.e2e.ts | 12 +++--- src/__tests__/manifestDiagnostics.e2e.ts | 39 +++++++++---------- src/__tests__/manifestLinks.e2e.ts | 22 +++++------ .../manifestPluginCompletions.e2e.ts | 12 +++--- src/__tests__/schemas/eas-metadata.e2e.ts | 8 ++-- src/__tests__/schemas/eas.e2e.ts | 8 ++-- src/__tests__/schemas/expo-module.e2e.ts | 10 ++--- src/__tests__/schemas/expo-xdl.e2e.ts | 8 ++-- src/__tests__/utils/vscode.ts | 28 +++++-------- src/__tests__/utils/wait.ts | 6 +-- src/expo/__tests__/project.test.ts | 7 ++-- src/expoDebuggers.ts | 3 +- src/manifestDiagnostics.ts | 2 +- src/manifestLinks.ts | 7 ++-- src/manifestPluginCompletions.ts | 2 +- src/preview/ExpoConfigCodeProvider.ts | 4 +- src/preview/IntrospectCodeProvider.ts | 4 +- src/settings.ts | 16 ++++---- src/types.d.ts | 7 ++++ src/utils/cache.ts | 2 +- src/utils/telemetry.ts | 6 +-- test/mocha/vscode-runner.ts | 7 ++++ webpack.config.js | 7 ++++ 28 files changed, 169 insertions(+), 149 deletions(-) create mode 100644 src/types.d.ts diff --git a/src/__tests__/commands/code-provider.e2e.ts b/src/__tests__/commands/code-provider.e2e.ts index ce4c9792..adf4307f 100644 --- a/src/__tests__/commands/code-provider.e2e.ts +++ b/src/__tests__/commands/code-provider.e2e.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import * as jsonc from 'jsonc-parser'; -import { commands, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { PreviewCommand, PreviewModProvider } from '../../preview/constants'; import { @@ -13,11 +13,11 @@ import { import { waitForFalse, waitForTrue } from '../utils/wait'; describe('CodeProvider', () => { - let app: TextEditor; + let app: vscode.TextEditor; let restoreContent: ReturnType; before(async () => { - app = await window.showTextDocument(getWorkspaceUri('preview/app.json')); + app = await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json')); restoreContent = storeOriginalContent(app); }); @@ -27,7 +27,7 @@ describe('CodeProvider', () => { }); it('updates preview on added and removed content', async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidManifest ); diff --git a/src/__tests__/commands/preview-config.e2e.ts b/src/__tests__/commands/preview-config.e2e.ts index ef70f6b2..4d735a10 100644 --- a/src/__tests__/commands/preview-config.e2e.ts +++ b/src/__tests__/commands/preview-config.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, window } from 'vscode'; +import vscode from 'vscode'; import { ExpoConfigType, PreviewCommand } from '../../preview/constants'; import { sanitizeSnapshotValues } from '../utils/snapshot'; @@ -7,7 +7,7 @@ import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vs describe(PreviewCommand.OpenExpoConfigPrebuild, () => { beforeEach(async () => { - await window.showTextDocument(getWorkspaceUri('preview/app.json')); + await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json')); }); afterEach(async () => { @@ -15,7 +15,10 @@ describe(PreviewCommand.OpenExpoConfigPrebuild, () => { }); it(`runs for ${ExpoConfigType.INTROSPECT}`, async () => { - await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.INTROSPECT); + await vscode.commands.executeCommand( + PreviewCommand.OpenExpoConfigPrebuild, + ExpoConfigType.INTROSPECT + ); const preview = await waitForEditorOpen('_app.config.json'); expect(preview).to.exist; @@ -25,7 +28,10 @@ describe(PreviewCommand.OpenExpoConfigPrebuild, () => { }); it(`runs for ${ExpoConfigType.PREBUILD}`, async () => { - await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.PREBUILD); + await vscode.commands.executeCommand( + PreviewCommand.OpenExpoConfigPrebuild, + ExpoConfigType.PREBUILD + ); const preview = await waitForEditorOpen('_app.config.json'); expect(preview).to.exist; @@ -35,7 +41,10 @@ describe(PreviewCommand.OpenExpoConfigPrebuild, () => { }); it(`runs for ${ExpoConfigType.PUBLIC}`, async () => { - await commands.executeCommand(PreviewCommand.OpenExpoConfigPrebuild, ExpoConfigType.PUBLIC); + await vscode.commands.executeCommand( + PreviewCommand.OpenExpoConfigPrebuild, + ExpoConfigType.PUBLIC + ); const preview = await waitForEditorOpen('exp.json'); expect(preview).to.exist; diff --git a/src/__tests__/commands/preview-modifier-json.e2e.ts b/src/__tests__/commands/preview-modifier-json.e2e.ts index d8912f56..6dedc7f9 100644 --- a/src/__tests__/commands/preview-modifier-json.e2e.ts +++ b/src/__tests__/commands/preview-modifier-json.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, window } from 'vscode'; +import vscode from 'vscode'; import { PreviewCommand, PreviewModProvider } from '../../preview/constants'; import { sanitizeSnapshotValues } from '../utils/snapshot'; @@ -7,7 +7,7 @@ import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vs describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { beforeEach(async () => { - await window.showTextDocument(getWorkspaceUri('preview/app.json')); + await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json')); }); afterEach(async () => { @@ -15,7 +15,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidColors} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidColors ); @@ -28,7 +28,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidColorsNight} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidColorsNight ); @@ -41,7 +41,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidGradleProperties} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidGradleProperties ); @@ -54,7 +54,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidManifest} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidManifest ); @@ -67,7 +67,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidStrings} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidStrings ); @@ -80,7 +80,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.androidStyles} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.androidStyles ); @@ -93,7 +93,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.iosEntitlements} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.iosEntitlements ); @@ -106,7 +106,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.iosExpoPlist} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.iosExpoPlist ); @@ -119,7 +119,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.iosInfoPlist} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.iosInfoPlist ); @@ -132,7 +132,7 @@ describe(PreviewCommand.OpenExpoFileJsonPrebuild, () => { }); it(`runs for ${PreviewModProvider.iosPodfileProperties} in json format`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFileJsonPrebuild, PreviewModProvider.iosPodfileProperties ); diff --git a/src/__tests__/commands/preview-modifier.e2e.ts b/src/__tests__/commands/preview-modifier.e2e.ts index 64327450..0a7c937b 100644 --- a/src/__tests__/commands/preview-modifier.e2e.ts +++ b/src/__tests__/commands/preview-modifier.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, window } from 'vscode'; +import vscode from 'vscode'; import { PreviewCommand, PreviewModProvider } from '../../preview/constants'; import { sanitizeSnapshotValues } from '../utils/snapshot'; @@ -7,7 +7,7 @@ import { closeAllEditors, getWorkspaceUri, waitForEditorOpen } from '../utils/vs describe(PreviewCommand.OpenExpoFilePrebuild, () => { beforeEach(async () => { - await window.showTextDocument(getWorkspaceUri('preview/app.json')); + await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json')); }); afterEach(async () => { @@ -15,7 +15,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidColors}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidColors ); @@ -28,7 +28,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidColorsNight}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidColorsNight ); @@ -41,7 +41,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidGradleProperties}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidGradleProperties ); @@ -54,7 +54,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidManifest}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidManifest ); @@ -67,7 +67,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidStrings}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidStrings ); @@ -80,7 +80,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.androidStyles}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidStyles ); @@ -93,7 +93,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.iosEntitlements}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.iosEntitlements ); @@ -106,7 +106,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.iosExpoPlist}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.iosExpoPlist ); @@ -119,7 +119,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.iosInfoPlist}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.iosInfoPlist ); @@ -132,7 +132,7 @@ describe(PreviewCommand.OpenExpoFilePrebuild, () => { }); it(`runs for ${PreviewModProvider.iosPodfileProperties}`, async () => { - await commands.executeCommand( + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.iosPodfileProperties ); @@ -151,8 +151,8 @@ describe('dynamic configs', () => { }); it(`runs ${PreviewModProvider.androidManifest} for app.json`, async () => { - await window.showTextDocument(getWorkspaceUri('preview/app.json')); - await commands.executeCommand( + await vscode.window.showTextDocument(getWorkspaceUri('preview', 'app.json')); + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidManifest ); @@ -165,8 +165,8 @@ describe('dynamic configs', () => { }); it(`runs ${PreviewModProvider.iosInfoPlist} for app.config.js`, async () => { - await window.showTextDocument(getWorkspaceUri('preview-config-js/app.config.js')); - await commands.executeCommand( + await vscode.window.showTextDocument(getWorkspaceUri('preview-config-js', 'app.config.js')); + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.iosInfoPlist ); @@ -179,8 +179,8 @@ describe('dynamic configs', () => { }); it(`runs ${PreviewModProvider.androidManifest} for app.config.ts`, async () => { - await window.showTextDocument(getWorkspaceUri('preview-config-ts/app.config.ts')); - await commands.executeCommand( + await vscode.window.showTextDocument(getWorkspaceUri('preview-config-ts', 'app.config.ts')); + await vscode.commands.executeCommand( PreviewCommand.OpenExpoFilePrebuild, PreviewModProvider.androidManifest ); diff --git a/src/__tests__/extension.e2e.ts b/src/__tests__/extension.e2e.ts index 78909278..e19fd4f5 100644 --- a/src/__tests__/extension.e2e.ts +++ b/src/__tests__/extension.e2e.ts @@ -1,10 +1,8 @@ import { expect } from 'chai'; import { extensions } from 'vscode'; -import { EXTENSION_ID } from './utils/vscode'; - describe('extension', () => { it('is activated', () => { - expect(extensions.getExtension(EXTENSION_ID)?.isActive).to.equal(true); + expect(extensions.getExtension(process.env.EXTENSION_ID)?.isActive).to.equal(true); }); }); diff --git a/src/__tests__/manifestAssetCompletions.e2e.ts b/src/__tests__/manifestAssetCompletions.e2e.ts index 6e31eaa2..ae238b70 100644 --- a/src/__tests__/manifestAssetCompletions.e2e.ts +++ b/src/__tests__/manifestAssetCompletions.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeActiveEditor, findContentRange, getWorkspaceUri } from './utils/vscode'; @@ -7,10 +7,10 @@ describe('ManifestAssetCompletionsProvider', () => { // Test for both app.json and app.config.json formats ['app.json', 'app.config.json'].forEach((manifestFile) => { describe(`manifest: ${manifestFile}`, () => { - let app: TextEditor; + let app: vscode.TextEditor; beforeEach(async () => { - app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`)); + app = await vscode.window.showTextDocument(getWorkspaceUri('manifest', manifestFile)); }); afterEach(() => closeActiveEditor()); @@ -19,7 +19,7 @@ describe('ManifestAssetCompletionsProvider', () => { const range = findContentRange(app, './assets/icon.png'); await app.edit((builder) => builder.replace(range, './')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start @@ -34,7 +34,7 @@ describe('ManifestAssetCompletionsProvider', () => { const range = findContentRange(app, './assets/icon.png'); await app.edit((builder) => builder.replace(range, './assets/')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start @@ -54,7 +54,7 @@ describe('ManifestAssetCompletionsProvider', () => { const range = findContentRange(app, 'portrait'); await app.edit((builder) => builder.replace(range, './')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/manifestDiagnostics.e2e.ts b/src/__tests__/manifestDiagnostics.e2e.ts index 5eff8518..c9515177 100644 --- a/src/__tests__/manifestDiagnostics.e2e.ts +++ b/src/__tests__/manifestDiagnostics.e2e.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import fs from 'fs'; import path from 'path'; -import { DiagnosticSeverity, languages, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -10,6 +10,7 @@ import { replaceEditorContent, } from './utils/vscode'; import { waitFor } from './utils/wait'; +import { readWorkspaceFile } from '../utils/file'; describe('ManifestDiagnosticsProvider', () => { // Based on: https://github.com/microsoft/vscode-extension-samples/blob/fdd3bb95ce8e38ffe58fc9158797239fdf5017f1/lsp-sample/client/src/test/diagnostics.test.ts#L31 @@ -17,17 +18,15 @@ describe('ManifestDiagnosticsProvider', () => { // Test for both app.json and app.config.json formats ['app.json', 'app.config.json'].forEach((manifestFile) => { describe(`manifest: ${manifestFile}`, () => { - let app: TextEditor; + let app: vscode.TextEditor; let content: string; before(async () => { - content = await window - .showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`)) - .then((editor) => editor.document.getText()); + content = await readWorkspaceFile(getWorkspaceUri('manifest', manifestFile)); }); beforeEach(async () => { - app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`)); + app = await vscode.window.showTextDocument(getWorkspaceUri('manifest', manifestFile)); }); afterEach(() => replaceEditorContent(app, content)); @@ -38,13 +37,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(range, './assets/doesnt-exist.png')); await waitFor(1000); - const diagnostics = await languages.getDiagnostics(app.document.uri); + const diagnostics = await vscode.languages.getDiagnostics(app.document.uri); expect(diagnostics).to.have.length(1); expect(diagnostics[0]).contain({ code: 'FILE_NOT_FOUND', message: 'File not found: ./assets/doesnt-exist.png', - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); }); @@ -53,13 +52,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(range, './assets')); await waitFor(1000); - const diagnostics = await languages.getDiagnostics(app.document.uri); + const diagnostics = await vscode.languages.getDiagnostics(app.document.uri); expect(diagnostics).to.have.length(1); expect(diagnostics[0]).contain({ code: 'FILE_IS_DIRECTORY', message: 'File is a directory: ./assets', - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); }); @@ -68,13 +67,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(range, '"doesnt-exists",')); await waitFor(1000); - const diagnostics = await languages.getDiagnostics(app.document.uri); + const diagnostics = await vscode.languages.getDiagnostics(app.document.uri); expect(diagnostics).to.have.length(1); expect(diagnostics[0]).contain({ code: 'PLUGIN_NOT_FOUND', message: 'Plugin not found: doesnt-exists', - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); }); @@ -83,13 +82,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(range, `"plugins": ["",`)); await waitFor(1000); - const diagnostics = await languages.getDiagnostics(app.document.uri); + const diagnostics = await vscode.languages.getDiagnostics(app.document.uri); expect(diagnostics).to.have.length(1); expect(diagnostics[0]).contain({ code: `PLUGIN_DEFINITION_INVALID`, message: 'Plugin definition is empty, expected a file or dependency name', - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); }); @@ -98,13 +97,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(range, `"plugins": [[],`)); await waitFor(1000); - const diagnostics = await languages.getDiagnostics(app.document.uri); + const diagnostics = await vscode.languages.getDiagnostics(app.document.uri); expect(diagnostics).to.have.length(1); expect(diagnostics[0]).contain({ code: `PLUGIN_DEFINITION_INVALID`, message: 'Plugin definition is empty, expected a file or dependency name', - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); }); @@ -115,7 +114,7 @@ describe('ManifestDiagnosticsProvider', () => { ? '.expo/temporary-plugin.js' : '.expo/temporary-config-plugin.js'; - const pluginFile = getWorkspaceUri(`manifest/${pluginName}`).fsPath; + const pluginFile = getWorkspaceUri('manifest', pluginName).fsPath; // Force-remove the new plugin, to ensure it's not installed // Also use a gitignored folder to make sure its never committed @@ -125,13 +124,13 @@ describe('ManifestDiagnosticsProvider', () => { await app.edit((builder) => builder.replace(preRange, `"./${pluginName}",`)); await waitFor(1000); - const preInstallDiagnostic = await languages.getDiagnostics(app.document.uri); + const preInstallDiagnostic = await vscode.languages.getDiagnostics(app.document.uri); expect(preInstallDiagnostic).to.have.length(1); expect(preInstallDiagnostic[0]).contain({ code: 'PLUGIN_NOT_FOUND', message: `Plugin not found: ./${pluginName}`, - severity: DiagnosticSeverity.Warning, + severity: vscode.DiagnosticSeverity.Warning, }); // Create the new plugin file @@ -147,7 +146,7 @@ describe('ManifestDiagnosticsProvider', () => { ); await waitFor(1000); - const postInstallDiagnostic = await languages.getDiagnostics(app.document.uri); + const postInstallDiagnostic = await vscode.languages.getDiagnostics(app.document.uri); expect(postInstallDiagnostic).to.have.length(0); fs.rmSync(pluginFile, { force: true }); diff --git a/src/__tests__/manifestLinks.e2e.ts b/src/__tests__/manifestLinks.e2e.ts index dd055d63..16bef08b 100644 --- a/src/__tests__/manifestLinks.e2e.ts +++ b/src/__tests__/manifestLinks.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, DocumentLink, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -14,17 +14,17 @@ describe('ManifestLinksProvider', () => { // Test for both app.json and app.config.json formats ['app.json', 'app.config.json'].forEach((manifestFile) => { describe(`manifest: ${manifestFile}`, () => { - let app: TextEditor; + let app: vscode.TextEditor; beforeEach(async () => { - app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`)); + app = await vscode.window.showTextDocument(getWorkspaceUri('manifest', manifestFile)); }); afterEach(() => closeAllEditors()); describe('assets', () => { it('opens valid asset link', async () => { - const links = await commands.executeCommand( + const links = await vscode.commands.executeCommand( 'vscode.executeLinkProvider', app.document.uri ); @@ -32,14 +32,14 @@ describe('ManifestLinksProvider', () => { const range = findContentRange(app, './assets/icon.png'); const link = links.find((link) => link.range.contains(range)); - await commands.executeCommand('vscode.open', link?.target); + await vscode.commands.executeCommand('vscode.open', link?.target); expect(await waitForActiveTabNameOpen('icon.png')).to.equal(true); }); }); describe('plugins', () => { it('opens valid plugin from package', async () => { - const links = await commands.executeCommand( + const links = await vscode.commands.executeCommand( 'vscode.executeLinkProvider', app.document.uri ); @@ -47,12 +47,12 @@ describe('ManifestLinksProvider', () => { const range = findContentRange(app, 'expo-system-ui'); const link = links.find((link) => link.range.contains(range)); - await commands.executeCommand('vscode.open', link?.target); + await vscode.commands.executeCommand('vscode.open', link?.target); expect(await waitForActiveTabNameOpen('app.plugin.js')).to.equal(true); }); it('opens valid plugin from package with options', async () => { - const links = await commands.executeCommand( + const links = await vscode.commands.executeCommand( 'vscode.executeLinkProvider', app.document.uri ); @@ -60,12 +60,12 @@ describe('ManifestLinksProvider', () => { const range = findContentRange(app, 'expo-camera'); const link = links.find((link) => link.range.contains(range)); - await commands.executeCommand('vscode.open', link?.target); + await vscode.commands.executeCommand('vscode.open', link?.target); expect(await waitForActiveTabNameOpen('app.plugin.js')).to.equal(true); }); it('opens valid plugin from local file', async () => { - const links = await commands.executeCommand( + const links = await vscode.commands.executeCommand( 'vscode.executeLinkProvider', app.document.uri ); @@ -73,7 +73,7 @@ describe('ManifestLinksProvider', () => { const range = findContentRange(app, './plugins/valid'); const link = links.find((link) => link.range.contains(range)); - await commands.executeCommand('vscode.open', link?.target); + await vscode.commands.executeCommand('vscode.open', link?.target); expect(await waitForActiveTabNameOpen('valid.js')).to.equal(true); }); }); diff --git a/src/__tests__/manifestPluginCompletions.e2e.ts b/src/__tests__/manifestPluginCompletions.e2e.ts index 93d1f6b8..a104cbed 100644 --- a/src/__tests__/manifestPluginCompletions.e2e.ts +++ b/src/__tests__/manifestPluginCompletions.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeActiveEditor, findContentRange, getWorkspaceUri } from './utils/vscode'; @@ -7,10 +7,10 @@ describe('ManifestPluginCompletionsProvider', () => { // Test for both app.json and app.config.json formats ['app.json', 'app.config.json'].forEach((manifestFile) => { describe(`manifest: ${manifestFile}`, () => { - let app: TextEditor; + let app: vscode.TextEditor; beforeEach(async () => { - app = await window.showTextDocument(getWorkspaceUri(`manifest/${manifestFile}`)); + app = await vscode.window.showTextDocument(getWorkspaceUri('manifest', manifestFile)); }); afterEach(() => closeActiveEditor()); @@ -19,7 +19,7 @@ describe('ManifestPluginCompletionsProvider', () => { const range = findContentRange(app, 'expo-system-ui'); await app.edit((builder) => builder.replace(range, '')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start @@ -35,7 +35,7 @@ describe('ManifestPluginCompletionsProvider', () => { const range = findContentRange(app, './plugins/valid'); await app.edit((builder) => builder.replace(range, './')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start @@ -52,7 +52,7 @@ describe('ManifestPluginCompletionsProvider', () => { const range = findContentRange(app, './plugins/valid'); await app.edit((builder) => builder.replace(range, './plugins/')); - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/schemas/eas-metadata.e2e.ts b/src/__tests__/schemas/eas-metadata.e2e.ts index c6b32fe5..2185d3fd 100644 --- a/src/__tests__/schemas/eas-metadata.e2e.ts +++ b/src/__tests__/schemas/eas-metadata.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -10,11 +10,11 @@ import { import { waitForTrue } from '../utils/wait'; describe('eas-metadata', () => { - let app: TextEditor; + let app: vscode.TextEditor; let restoreContent: ReturnType; before(async () => { - app = await window.showTextDocument(getWorkspaceUri('schema-eas/store.config.json')); + app = await vscode.window.showTextDocument(getWorkspaceUri('schema-eas', 'store.config.json')); restoreContent = storeOriginalContent(app); }); @@ -30,7 +30,7 @@ describe('eas-metadata', () => { // Retry the suggestions a couple of times, the schema might still need to be downloaded const result = await waitForTrue(async () => { - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/schemas/eas.e2e.ts b/src/__tests__/schemas/eas.e2e.ts index fe3b92dd..4326fc94 100644 --- a/src/__tests__/schemas/eas.e2e.ts +++ b/src/__tests__/schemas/eas.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -10,11 +10,11 @@ import { import { waitForTrue } from '../utils/wait'; describe('eas', () => { - let app: TextEditor; + let app: vscode.TextEditor; let restoreContent: ReturnType; before(async () => { - app = await window.showTextDocument(getWorkspaceUri('schema-eas/eas.json')); + app = await vscode.window.showTextDocument(getWorkspaceUri('schema-eas', 'eas.json')); restoreContent = storeOriginalContent(app); }); @@ -30,7 +30,7 @@ describe('eas', () => { // Retry the suggestions a couple of times, the schema might still need to be downloaded const result = await waitForTrue(async () => { - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/schemas/expo-module.e2e.ts b/src/__tests__/schemas/expo-module.e2e.ts index 13648e70..e8eec4c1 100644 --- a/src/__tests__/schemas/expo-module.e2e.ts +++ b/src/__tests__/schemas/expo-module.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -10,12 +10,12 @@ import { import { waitForTrue } from '../utils/wait'; describe('expo-module', () => { - let app: TextEditor; + let app: vscode.TextEditor; let restoreContent: ReturnType; before(async () => { - app = await window.showTextDocument( - getWorkspaceUri('schema-expo-module/expo-module.config.json') + app = await vscode.window.showTextDocument( + getWorkspaceUri('schema-expo-module', 'expo-module.config.json') ); restoreContent = storeOriginalContent(app); }); @@ -32,7 +32,7 @@ describe('expo-module', () => { // Retry the suggestions a couple of times, the schema might still need to be downloaded const result = await waitForTrue(async () => { - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/schemas/expo-xdl.e2e.ts b/src/__tests__/schemas/expo-xdl.e2e.ts index 177b97a1..d3d19351 100644 --- a/src/__tests__/schemas/expo-xdl.e2e.ts +++ b/src/__tests__/schemas/expo-xdl.e2e.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { commands, CompletionList, TextEditor, window } from 'vscode'; +import vscode from 'vscode'; import { closeAllEditors, @@ -10,11 +10,11 @@ import { import { waitForTrue } from '../utils/wait'; describe('expo-xdl', () => { - let app: TextEditor; + let app: vscode.TextEditor; let restoreContent: ReturnType; before(async () => { - app = await window.showTextDocument(getWorkspaceUri('schema-expo-xdl/app.json')); + app = await vscode.window.showTextDocument(getWorkspaceUri('schema-expo-xdl', 'app.json')); restoreContent = storeOriginalContent(app); }); @@ -30,7 +30,7 @@ describe('expo-xdl', () => { // Retry the suggestions a couple of times, the schema might still need to be downloaded const result = await waitForTrue(async () => { - const suggestions = await commands.executeCommand( + const suggestions = await vscode.commands.executeCommand( 'vscode.executeCompletionItemProvider', app.document.uri, range.start diff --git a/src/__tests__/utils/vscode.ts b/src/__tests__/utils/vscode.ts index c1a4b52a..446015f0 100644 --- a/src/__tests__/utils/vscode.ts +++ b/src/__tests__/utils/vscode.ts @@ -4,36 +4,26 @@ import vscode from 'vscode'; import { type WaitForValueOptions, waitForTrue, waitForValue } from './wait'; -const pkg = require('../../../../package'); - -/** - * The unique ID of this extension. - */ -export const EXTENSION_ID = `${pkg.publisher}.${pkg.name}`; - /** * Get the URI to a file or folder within the workspace. */ -export function getWorkspaceUri(relativePath: string): vscode.Uri { - const rootPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath; - assert(rootPath, `Workspace root path not found, can't create path to ${relativePath}`); - return vscode.Uri.file(path.join(rootPath, relativePath)); +export function getWorkspaceUri(...relativePath: string[]) { + const workspace = vscode.workspace.workspaceFolders?.[0]; + assert(workspace, `(First) workspace not found, can't create path to ${relativePath}`); + return vscode.Uri.joinPath(workspace.uri, ...relativePath); } /** * Wait until vscode has activated this extension. */ export function waitForExtension() { - return waitForTrue(() => vscode.extensions.getExtension(EXTENSION_ID)?.isActive); + return waitForTrue(() => vscode.extensions.getExtension(process.env.EXTENSION_ID)?.isActive); } /** * Wait until vscode has opened a visible file. */ -export function waitForEditorOpen( - fileName: string, - options?: WaitForValueOptions -): Promise { +export function waitForEditorOpen(fileName: string, options?: WaitForValueOptions) { return waitForValue( () => vscode.window.visibleTextEditors.find( @@ -48,7 +38,7 @@ export function waitForEditorOpen( * Wait until the active tab name is opened. * This can by any type of file, from text editor to asset. */ -export function waitForActiveTabNameOpen(tabName: string, delay = 500): Promise { +export function waitForActiveTabNameOpen(tabName: string, delay = 500) { return waitForTrue(() => tabName === vscode.window.tabGroups.activeTabGroup.activeTab?.label, { delay, }); @@ -73,7 +63,7 @@ export function closeActiveEditor() { /** * Find the editor content position by search string. */ -export function findContentPosition(editor: vscode.TextEditor, search: string): vscode.Position { +export function findContentPosition(editor: vscode.TextEditor, search: string) { const content = editor.document.getText(); const offset = content.indexOf(search); @@ -85,7 +75,7 @@ export function findContentPosition(editor: vscode.TextEditor, search: string): /** * Find the editor content range by search string. */ -export function findContentRange(editor: vscode.TextEditor, search: string): vscode.Range { +export function findContentRange(editor: vscode.TextEditor, search: string) { const start = findContentPosition(editor, search); const end = new vscode.Position(start.line, start.character + search.length); return new vscode.Range(start, end); diff --git a/src/__tests__/utils/wait.ts b/src/__tests__/utils/wait.ts index f6068656..d226e9a0 100644 --- a/src/__tests__/utils/wait.ts +++ b/src/__tests__/utils/wait.ts @@ -1,7 +1,7 @@ /** * Wait for the total amount of milliseconds. */ -export async function waitFor(delay: number = 500) { +export function waitFor(delay: number = 500) { return new Promise((resolve) => setTimeout(resolve, delay)); } @@ -22,7 +22,7 @@ export type WaitForValueOptions = { export async function waitForValue( action: () => T, { delay = 250, retries = 25_000 / 250, attempts = 0 }: WaitForValueOptions = {} -): Promise { +): Promise | undefined> { const value = await action(); if (value === undefined && attempts <= retries) { @@ -33,7 +33,7 @@ export async function waitForValue( return value; } -export async function waitForTrue>( +export function waitForTrue>( action: () => T, options?: WaitForValueOptions ) { diff --git a/src/expo/__tests__/project.test.ts b/src/expo/__tests__/project.test.ts index 621fa4b6..13fa3044 100644 --- a/src/expo/__tests__/project.test.ts +++ b/src/expo/__tests__/project.test.ts @@ -2,6 +2,7 @@ import { expect } from 'chai'; import { findNodeAtLocation } from 'jsonc-parser'; import vscode from 'vscode'; +import { getWorkspaceUri } from '../../__tests__/utils/vscode'; import { readWorkspaceFile } from '../../utils/file'; import { ExpoProjectCache, findProjectFromWorkspaces } from '../project'; @@ -44,9 +45,9 @@ describe('ExpoProject', () => { using projects = stubProjectCache(); const project = await findProjectFromWorkspaces(projects, './manifest'); - const workspace = vscode.workspace.workspaceFolders![0]; - const packageUri = vscode.Uri.joinPath(workspace.uri, 'manifest', 'package.json'); - const packageFile = JSON.parse(await readWorkspaceFile(packageUri)); + const packageFile = JSON.parse( + await readWorkspaceFile(getWorkspaceUri('manifest', 'package.json')) + ); expect(project?.expoVersion).to.equal(packageFile.dependencies.expo); }); diff --git a/src/expoDebuggers.ts b/src/expoDebuggers.ts index a8ac95aa..9159929a 100644 --- a/src/expoDebuggers.ts +++ b/src/expoDebuggers.ts @@ -15,13 +15,12 @@ import { } from './expo/project'; import { debug } from './utils/debug'; import { featureTelemetry } from './utils/telemetry'; -import { version as extensionVersion } from '../package.json'; const log = debug.extend('expo-debuggers'); const DEBUG_TYPE = 'expo'; const DEBUG_COMMAND = 'expo.debug.start'; -const DEBUG_USER_AGENT = `vscode/${vscode.version} vscode-expo-tools/${extensionVersion}`; +const DEBUG_USER_AGENT = `vscode/${vscode.version} ${process.env.EXTENSION_NAME}/${process.env.EXTENSION_VERSION}`; interface ExpoDebugConfig extends vscode.DebugConfiguration { projectRoot: string; diff --git a/src/manifestDiagnostics.ts b/src/manifestDiagnostics.ts index 6d28059b..f8177f9a 100644 --- a/src/manifestDiagnostics.ts +++ b/src/manifestDiagnostics.ts @@ -1,7 +1,7 @@ import { findNodeAtLocation, Node } from 'jsonc-parser'; import vscode from 'vscode'; -import { FileReference, getFileReferences, manifestPattern } from './expo/manifest'; +import { type FileReference, getFileReferences, manifestPattern } from './expo/manifest'; import { getPluginDefinition, resolvePluginFunctionUnsafe } from './expo/plugin'; import { ExpoProject, ExpoProjectCache } from './expo/project'; import { isManifestPluginValidationEnabled } from './settings'; diff --git a/src/manifestLinks.ts b/src/manifestLinks.ts index d8e48ba3..43943e31 100644 --- a/src/manifestLinks.ts +++ b/src/manifestLinks.ts @@ -1,5 +1,4 @@ import { findNodeAtLocation } from 'jsonc-parser'; -import path from 'path'; import vscode from 'vscode'; import { getFileReferences, manifestPattern } from './expo/manifest'; @@ -65,8 +64,10 @@ export class ManifestLinksProvider extends ExpoLinkProvider { const range = getDocumentRange(document, reference.fileRange); if (!pluginsRange?.contains(range)) { - const file = path.resolve(project.root.fsPath, reference.filePath); - const link = new vscode.DocumentLink(range, vscode.Uri.file(file)); + const link = new vscode.DocumentLink( + range, + vscode.Uri.joinPath(project.root, reference.filePath) + ); link.tooltip = 'Go to asset'; links.push(link); diff --git a/src/manifestPluginCompletions.ts b/src/manifestPluginCompletions.ts index 387b0c47..ba933750 100644 --- a/src/manifestPluginCompletions.ts +++ b/src/manifestPluginCompletions.ts @@ -3,7 +3,7 @@ import path from 'path'; import vscode from 'vscode'; import { manifestPattern } from './expo/manifest'; -import { PluginInfo, resolveInstalledPluginInfo, resolvePluginInfo } from './expo/plugin'; +import { type PluginInfo, resolveInstalledPluginInfo, resolvePluginInfo } from './expo/plugin'; import { ExpoProjectCache } from './expo/project'; import { getManifestFileReferencesExcludedFiles, diff --git a/src/preview/ExpoConfigCodeProvider.ts b/src/preview/ExpoConfigCodeProvider.ts index fbe15ef1..1bfc7dac 100644 --- a/src/preview/ExpoConfigCodeProvider.ts +++ b/src/preview/ExpoConfigCodeProvider.ts @@ -1,9 +1,9 @@ import vscode from 'vscode'; -import { CodeProvider, BasicCodeProviderOptions, CodeProviderLanguage } from './CodeProvider'; +import { CodeProvider, type BasicCodeProviderOptions, CodeProviderLanguage } from './CodeProvider'; import { ExpoConfigType } from './constants'; import { spawnExpoCli } from '../expo/cli'; -import { ExpoConfig, getConfig } from '../packages/config'; +import { type ExpoConfig, getConfig } from '../packages/config'; import { compileModsAsync } from '../packages/config-plugins'; import { getPrebuildConfigAsync } from '../packages/prebuild-config'; diff --git a/src/preview/IntrospectCodeProvider.ts b/src/preview/IntrospectCodeProvider.ts index 99943bca..ca083fb4 100644 --- a/src/preview/IntrospectCodeProvider.ts +++ b/src/preview/IntrospectCodeProvider.ts @@ -1,9 +1,9 @@ import assert from 'assert'; import vscode from 'vscode'; -import { BasicCodeProviderOptions, CodeProvider, CodeProviderLanguage } from './CodeProvider'; +import { type BasicCodeProviderOptions, CodeProvider, CodeProviderLanguage } from './CodeProvider'; import { spawnExpoCli } from '../expo/cli'; -import { ExpoConfig } from '../packages/config'; +import { type ExpoConfig } from '../packages/config'; import { type ModPlatform, compileModsAsync } from '../packages/config-plugins'; import { getPrebuildConfigAsync } from '../packages/prebuild-config'; diff --git a/src/settings.ts b/src/settings.ts index 9ad09eb3..7f58561a 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,11 +1,11 @@ -import { ConfigurationScope, workspace } from 'vscode'; +import vscode from 'vscode'; /** * Determine if we should validate the config plugins within app manifests. * This uses the `expo.appManifest.pluginValidation` setting from the configuration scope. */ -export function isManifestPluginValidationEnabled(scope?: ConfigurationScope) { - return workspace +export function isManifestPluginValidationEnabled(scope?: vscode.ConfigurationScope) { + return vscode.workspace .getConfiguration('expo.appManifest', scope) .get('pluginValidation', true); } @@ -14,8 +14,10 @@ export function isManifestPluginValidationEnabled(scope?: ConfigurationScope) { * Determine if we should show file references auto-complete in app manifests. * This uses the `expo.appManifest.fileReferences` setting from the configuration scope. */ -export function isManifestFileReferencesEnabled(scope?: ConfigurationScope) { - return workspace.getConfiguration('expo.appManifest', scope).get('fileReferences', true); +export function isManifestFileReferencesEnabled(scope?: vscode.ConfigurationScope) { + return vscode.workspace + .getConfiguration('expo.appManifest', scope) + .get('fileReferences', true); } /** @@ -24,8 +26,8 @@ export function isManifestFileReferencesEnabled(scope?: ConfigurationScope) { * - `files.exclude` - main vscode file exclusion * - `expo.appManifest.fileReferences.excludeGlobPatterns` - expo-specific file exclusion */ -export function getManifestFileReferencesExcludedFiles(scope?: ConfigurationScope) { - const config = workspace.getConfiguration(undefined, scope); +export function getManifestFileReferencesExcludedFiles(scope?: vscode.ConfigurationScope) { + const config = vscode.workspace.getConfiguration(undefined, scope); return { ...config.get>('files.exclude', {}), diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 00000000..c90166be --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,7 @@ +declare namespace NodeJS { + export interface ProcessEnv { + EXTENSION_NAME: string; + EXTENSION_VERSION: string; + EXTENSION_ID: string; + } +} diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 91acadab..e71c1413 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -1,4 +1,4 @@ -import { Disposable, ExtensionContext } from 'vscode'; +import type { Disposable, ExtensionContext } from 'vscode'; export abstract class MapCacheProvider implements Disposable { protected cache: Map = new Map(); diff --git a/src/utils/telemetry.ts b/src/utils/telemetry.ts index 9c55ae88..e8e0aa7e 100644 --- a/src/utils/telemetry.ts +++ b/src/utils/telemetry.ts @@ -1,8 +1,8 @@ import TelemetryReporter, { - TelemetryEventMeasurements, - TelemetryEventProperties, + type TelemetryEventMeasurements, + type TelemetryEventProperties, } from '@vscode/extension-telemetry'; -import { ExtensionContext } from 'vscode'; +import { type ExtensionContext } from 'vscode'; import { debug } from './debug'; diff --git a/test/mocha/vscode-runner.ts b/test/mocha/vscode-runner.ts index 0d5fb379..f13553b1 100644 --- a/test/mocha/vscode-runner.ts +++ b/test/mocha/vscode-runner.ts @@ -9,6 +9,13 @@ Symbol.dispose ??= Symbol('Symbol.dispose'); // @ts-expect-error Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose'); +const pkg = require('../../../package.json'); + +// Define the extension properties +process.env.EXTENSION_NAME = pkg.name; +process.env.EXTENSION_VERSION = pkg.version; +process.env.EXTENSION_ID = `${pkg.publisher}.${pkg.name}`; + export async function run() { // Configure the test runner const tests = new Mocha({ diff --git a/webpack.config.js b/webpack.config.js index e0611487..6d9eeeae 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,8 @@ const path = require('path'); const webpack = require('webpack'); +const pkg = require('./package.json'); + /** @type {import('webpack').Configuration} */ module.exports = { target: 'node', @@ -37,10 +39,15 @@ module.exports = { ], plugins: [ new webpack.DefinePlugin({ + // Pass-through environment variables from current machine 'process.env.VSCODE_EXPO_DEBUG': JSON.stringify(process.env.VSCODE_EXPO_DEBUG), 'process.env.VSCODE_EXPO_TELEMETRY_KEY': JSON.stringify( process.env.VSCODE_EXPO_TELEMETRY_KEY ), + // Avoid having to import the package.json in the extension + 'process.env.EXTENSION_NAME': JSON.stringify(pkg.name), + 'process.env.EXTENSION_VERSION': JSON.stringify(pkg.version), + 'process.env.EXTENSION_ID': JSON.stringify(`${pkg.publisher}.${pkg.name}`), }), ], resolve: {