Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
node_modules
dist
src/generated-meta.ts
shared/meta.ts

# local env files
.env.local
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@
"dev": "tsdown --watch",
"build": "tsdown",
"postinstall": "npm run update",
"update": "vscode-ext-gen --scope npmx",
"update": "vscode-ext-gen --scope npmx --output ./shared/meta.ts",
"check": "npm run lint:fix && npm run typecheck",
"test": "vitest",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"typecheck": "tsgo --noEmit",
"typecheck": "tsgo -b --noEmit",
Comment thread
9romise marked this conversation as resolved.
"vscode:prepublish": "npm run build",
"publish": "npx @vscode/vsce publish --no-dependencies",
"package": "npx @vscode/vsce package --no-dependencies",
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/types/meta.ts → shared/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { ConfigKey } from '../generated-meta'
import type { ConfigKey } from './meta'

type StripPrefix<T, Prefix extends string>
= T extends `${Prefix}${infer Rest}`
? Rest
: never

export type DiagnosticsCode = StripPrefix<ConfigKey, 'npmx.diagnostics.'>

export type PackageManager = 'npm' | 'pnpm' | 'yarn'
2 changes: 1 addition & 1 deletion src/api/package.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MaybeError, PackageVersionsInfoWithMetadata } from 'fast-npm-meta'
import { CACHE_MAX_AGE_ONE_DAY } from '#constants'
import { CACHE_MAX_AGE_ONE_DAY } from '#shared/constants'
import { logger } from '#state'
import { createBatchRunner } from '#utils/batch'
import { getVersionsBatch } from 'fast-npm-meta'
Expand Down
2 changes: 1 addition & 1 deletion src/api/replacement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ModuleReplacement } from 'module-replacements'
import { CACHE_MAX_AGE_ONE_DAY, NPMX_DEV_API } from '#constants'
import { CACHE_MAX_AGE_ONE_DAY, NPMX_DEV_API } from '#shared/constants'
import { logger } from '#state'
import { encodePackageName } from '#utils/package'
import { defineCachedFunction } from 'ocache'
Expand Down
2 changes: 1 addition & 1 deletion src/api/vulnerability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CACHE_MAX_AGE_ONE_DAY, NPMX_DEV_API } from '#constants'
import { CACHE_MAX_AGE_ONE_DAY, NPMX_DEV_API } from '#shared/constants'
import { logger } from '#state'
import { encodePackageName, formatPackageId } from '#utils/package'
import { defineCachedFunction } from 'ocache'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/add-to-ignore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ConfigurationTarget } from 'vscode'
import { scopedConfigs } from '#shared/meta'
import { checkIgnored } from '#utils/ignore'
import { workspace } from 'vscode'
import { scopedConfigs } from '../generated-meta'

export async function addToIgnore(scope: string, name: string, target: ConfigurationTarget) {
const ignoreScope = `ignore.${scope}`
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open-file-in-npmx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PACKAGE_JSON_BASENAME } from '#constants'
import { PACKAGE_JSON_BASENAME } from '#shared/constants'
import { logger } from '#state'
import { readPackageManifest } from '#utils/file'
import { npmxFileUrl } from '#utils/links'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open-in-browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NPMX_DEV } from '#constants'
import { NPMX_DEV } from '#shared/constants'
import { env, Uri } from 'vscode'

export function openInBrowser() {
Expand Down
2 changes: 1 addition & 1 deletion src/composables/workspace-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Uri } from 'vscode'
import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { deleteWorkspaceContextCache, getWorkspaceContext } from '#core/workspace'
import { SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { logger } from '#state'
import { isSupportedDependencyDocument, isWorkspaceLevelFile } from '#utils/file'
import { useDisposable, useFileSystemWatcher } from 'reactive-vscode'
Expand Down
7 changes: 4 additions & 3 deletions src/core/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { CatalogsInfo, PackageManager, ResolvedDependencyInfo } from '#types/context'
import type { PackageManager } from '#shared/types'
import type { CatalogsInfo, ResolvedDependencyInfo } from '#types/context'
import type { DependencyInfo, PackageManifestInfo, WorkspaceCatalogInfo } from '#types/extractor'
import type { CacheOptions } from 'ocache'
import type { WorkspaceFolder } from 'vscode'
import { getPackageInfo } from '#api/package'
import { PNPM_WORKSPACE_BASENAME, YARN_WORKSPACE_BASENAME } from '#constants'
import { PNPM_WORKSPACE_BASENAME, YARN_WORKSPACE_BASENAME } from '#shared/constants'
import { logger } from '#state'
import { isOffsetInRange } from '#utils/ast'
import { resolveDependencySpec } from '#utils/dependency'
Expand All @@ -29,7 +30,7 @@ async function getPackageManager(uri: Uri): Promise<PackageManager> {
const result = await commands.executeCommand<PackageManager>('npm.packageManager', uri)
return result || 'npm'
} catch (error) {
console.error('Error getting package manager:', error)
logger.error('Error getting package manager:', error)
window.showErrorMessage('Failed to detect package manager. Defaulting to npm.')
return 'npm'
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useWorkspaceContext } from '#composables/workspace-context'
import { commands, displayName, version } from '#shared/meta'
import { defineExtension, useCommands } from 'reactive-vscode'
import { openFileInNpmx } from './commands/open-file-in-npmx'
import { openInBrowser } from './commands/open-in-browser'
import { commands, displayName, version } from './generated-meta'
import { useCodeActions } from './providers/code-actions'
import { useCompletionItem } from './providers/completion-item'
import { useDecorators } from './providers/decorators'
Expand Down
2 changes: 1 addition & 1 deletion src/providers/code-actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { config, internalCommands } from '#state'
import { computed, useCommand, watch } from 'reactive-vscode'
import { CodeActionKind, languages } from 'vscode'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CodeActionContext, TextDocument } from 'vscode'
import { describe, expect, it } from 'vitest'
import { CodeActionKind, ConfigurationTarget, Diagnostic, DiagnosticSeverity, Range, Uri } from 'vscode'
import { QuickFixProvider } from '../../src/providers/code-actions/quick-fix'
import { QuickFixProvider } from './quick-fix'

const provider = new QuickFixProvider()

Expand Down
2 changes: 1 addition & 1 deletion src/providers/code-actions/quick-fix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DiagnosticsCode } from '#types/meta'
import type { DiagnosticsCode } from '#shared/types'
import type { CodeActionContext, CodeActionProvider, Diagnostic, Range, TextDocument } from 'vscode'
import { internalCommands } from '#state'
import { CodeAction, CodeActionKind, ConfigurationTarget, WorkspaceEdit } from 'vscode'
Expand Down
2 changes: 1 addition & 1 deletion src/providers/completion-item/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PACKAGE_JSON_BASENAME, SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { PACKAGE_JSON_BASENAME, SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { config } from '#state'
import { watchEffect } from 'reactive-vscode'
import { languages } from 'vscode'
Expand Down
4 changes: 2 additions & 2 deletions src/providers/completion-item/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CompletionItemProvider, Position, TextDocument } from 'vscode'
import { PRERELEASE_PATTERN } from '#constants'
import { getResolvedDependencyByOffset } from '#core/workspace'
import { PRERELEASE_PATTERN } from '#shared/constants'
import { config } from '#state'
import { offsetRangeToRange } from '#utils/ast'
import { formatUpgradeVersion } from '#utils/version'
Expand All @@ -25,7 +25,7 @@ export class VersionCompletionItemProvider implements CompletionItemProvider {
const items: CompletionItem[] = []

for (const version in pkg.versionsMeta) {
const meta = pkg.versionsMeta[version]
const meta = pkg.versionsMeta[version]!

if (meta.deprecated != null)
continue
Expand Down
2 changes: 1 addition & 1 deletion src/providers/definition/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PACKAGE_JSON_BASENAME } from '#constants'
import { PACKAGE_JSON_BASENAME } from '#shared/constants'
import { useDisposable } from 'reactive-vscode'
import { languages } from 'vscode'
import { CatalogDefinitionProvider } from './catalog'
Expand Down
4 changes: 2 additions & 2 deletions src/providers/diagnostics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { ResolvedDependencyInfo } from '#types/context'
import type { OffsetRange } from '#types/extractor'
import type { Awaitable } from 'reactive-vscode'
import type { Diagnostic, TextDocument, Uri } from 'vscode'
import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { getResolvedDependencies } from '#core/workspace'
import { SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { displayName } from '#shared/meta'
import { config, logger } from '#state'
import { offsetRangeToRange } from '#utils/ast'
import { isSupportedDependencyDocument } from '#utils/file'
import { debounce } from 'perfect-debounce'
import { computed, nextTick, useActiveTextEditor, useDisposable, useDocumentText, useFileSystemWatcher, watch } from 'reactive-vscode'
import { languages, TabInputText, window, workspace } from 'vscode'
import { displayName } from '../../generated-meta'
import { checkDeprecation } from './rules/deprecation'
import { checkDistTag } from './rules/dist-tag'
import { checkEngineMismatch } from './rules/engine-mismatch'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from '#test-utils/diagnostics'
import { describe, expect, it } from 'vitest'
import { checkDeprecation } from '../../src/providers/diagnostics/rules/deprecation'
import { createContext } from './context'
import { checkDeprecation } from './deprecation'

function createDeprecationContext(version: string) {
return createContext({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from '#test-utils/diagnostics'
import { describe, expect, it } from 'vitest'
import { checkDistTag } from '../../src/providers/diagnostics/rules/dist-tag'
import { createContext } from './context'
import { checkDistTag } from './dist-tag'

describe('checkDistTag', () => {
it('should flag when version matches a dist tag', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { resolveEngineMismatches } from '../../src/providers/diagnostics/rules/engine-mismatch'
import { resolveEngineMismatches } from './engine-mismatch'

describe('resolveEngineMismatches', () => {
it('should flag when engine ranges do not overlap', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from '#test-utils/diagnostics'
import { describe, expect, it } from 'vitest'
import { checkReplacement } from '../../src/providers/diagnostics/rules/replacement'
import { createContext } from './context'
import { checkReplacement } from './replacement'

function createReplacementContext(name: string) {
return createContext({ name, version: '^1.0.0' })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PackageInfo } from '#api/package'
import type { ResolvedDependencyInfo } from '#types/context'
import { createContext } from '#test-utils/diagnostics'
import { describe, expect, it } from 'vitest'
import { resolveUpgrade } from '../../src/providers/diagnostics/rules/upgrade'
import { createContext } from './context'
import { resolveUpgrade } from './upgrade'

const distTags: Record<string, string> = {
latest: '2.7.0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext } from '#test-utils/diagnostics'
import { describe, expect, it } from 'vitest'
import { checkVulnerability } from '../../src/providers/diagnostics/rules/vulnerability'
import { createContext } from './context'
import { checkVulnerability } from './vulnerability'

function createVulnerabilityContext(name: string) {
return createContext({ name, version: '1.0.0', versionsMeta: { '1.0.0': {} } })
Expand Down
2 changes: 1 addition & 1 deletion src/providers/document-link/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { config } from '#state'
import { watchEffect } from 'reactive-vscode'
import { languages } from 'vscode'
Expand Down
2 changes: 1 addition & 1 deletion src/providers/hover/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SUPPORTED_DOCUMENT_PATTERN } from '#constants'
import { SUPPORTED_DOCUMENT_PATTERN } from '#shared/constants'
import { config } from '#state'
import { watchEffect } from 'reactive-vscode'
import { languages } from 'vscode'
Expand Down
2 changes: 1 addition & 1 deletion src/providers/hover/npmx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HoverProvider, Position, TextDocument } from 'vscode'
import { SPACER } from '#constants'
import { getResolvedDependencyByOffset } from '#core/workspace'
import { SPACER } from '#shared/constants'
import { jsrPackageUrl, npmxDocsUrl, npmxPackageUrl } from '#utils/links'
import { Hover, MarkdownString } from 'vscode'

Expand Down
4 changes: 2 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NestedScopedConfigs } from './generated-meta'
import type { NestedScopedConfigs } from '#shared/meta'
import { displayName, scopedConfigs } from '#shared/meta'
import { defineConfig, defineLogger } from 'reactive-vscode'
import { displayName, scopedConfigs } from './generated-meta'

export const config = defineConfig<NestedScopedConfigs>(scopedConfigs.scope)

Expand Down
2 changes: 0 additions & 2 deletions src/types/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { PackageInfo } from '#api/package'
import type { DependencyInfo } from '#types/extractor'

export type PackageManager = 'npm' | 'pnpm' | 'yarn'

export type DependencyProtocol
= | 'npm'
| 'jsr'
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PackageManifestInfo } from '#types/extractor'
import type { TextDocument, Uri } from 'vscode'
import { PACKAGE_JSON_BASENAME, PNPM_WORKSPACE_BASENAME, YARN_WORKSPACE_BASENAME } from '#constants'
import { PACKAGE_JSON_BASENAME, PNPM_WORKSPACE_BASENAME, YARN_WORKSPACE_BASENAME } from '#shared/constants'
import { basename } from 'pathe'
import { workspace } from 'vscode'

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/links.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NPMX_DEV } from '#constants'
import { NPMX_DEV } from '#shared/constants'

const SPACES = /\s+/g

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function resolveExactVersion(pkg: PackageInfo, version: string) {
version = 'latest'

if (Object.hasOwn(pkg.distTags, version))
return pkg.distTags[version]
return pkg.distTags[version]!

const versions = Object.keys(pkg.versionsMeta)
if (versions.length === 0)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/__setup__/msw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NPMX_DEV_API } from '#constants'
import { NPMX_DEV_API } from '#shared/constants'
import { all } from 'module-replacements'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
Expand Down
6 changes: 3 additions & 3 deletions tests/diagnostics/context.ts → tests/utils/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { PackageInfo } from '#api/package'
import type { Engines } from 'fast-npm-meta'
import type { PackageInfo } from '../../src/api/package'
import type { DiagnosticContext } from '../../src/providers/diagnostics'
import { resolveDependencySpec } from '#utils/dependency'
import { resolveExactVersion } from '#utils/package'
import { Uri } from 'vscode'
import { resolveDependencySpec } from '../../src/utils/dependency'
import { resolveExactVersion } from '../../src/utils/package'

interface CreateContextOptions {
name: string
Expand Down
21 changes: 21 additions & 0 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tsbuildinfo/app",
"paths": {
"#shared/*": ["./shared/*"],
"#state": ["./src/state.ts"],
"#api/*": ["./src/api/*"],
"#types/*": ["./src/types/*"],
"#utils/*": ["./src/utils/*"],
"#core/*": ["./src/core/*"],
"#composables/*": ["./src/composables/*"],
"#test-utils/*": ["./tests/utils/*"]
}
},
"include": [
"src/**/*",
"shared",
"tests"
]
}
17 changes: 17 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate relevant config files
TS_APP="$(fd -HI '^tsconfig\.app\.json$' | head -n1 || true)"
TS_DOWN="$(fd -HI '^tsdown\.config\.ts$' | head -n1 || true)"
VITEST="$(fd -HI '^vitest\.config\.ts$' | head -n1 || true)"

echo "tsconfig.app.json: ${TS_APP:-NOT FOUND}"
echo "tsdown.config.ts: ${TS_DOWN:-NOT FOUND}"
echo "vitest.config.ts: ${VITEST:-NOT FOUND}"
echo

# Show TS path aliases
if [[ -n "${TS_APP}" ]]; then
  echo "=== paths in tsconfig.app.json ==="
  rg -n -C2 '"paths"|#shared|#api|#types|#utils|#core|#composables|#test-utils' "$TS_APP"
  echo
fi

# Show bundler resolver/alias settings
if [[ -n "${TS_DOWN}" ]]; then
  echo "=== resolver settings in tsdown.config.ts ==="
  rg -n -C3 'alias|resolve|tsconfig|paths|plugin' "$TS_DOWN"
  echo
fi

# Confirm test-only alias support exists
if [[ -n "${VITEST}" ]]; then
  echo "=== alias support in vitest.config.ts ==="
  rg -n -C2 'vite-tsconfig-paths|plugins' "$VITEST"
fi

Repository: npmx-dev/vscode-npmx

Length of output: 1363


Add path alias mappings to tsdown.config.ts to match tsconfig.app.json

Line 6 ("moduleResolution": "Bundler") is correct, but tsdown.config.ts is missing the path alias mappings defined in tsconfig.app.json. Vitest will resolve aliases like #shared/* and #api/* via vite-tsconfig-paths, but the production bundler will fail at runtime unless tsdown is configured with equivalent aliases. Add the following to tsdown.config.ts alias object:

'#shared/*': resolve('./shared/*'),
'#state': resolve('./src/state.ts'),
'#api/*': resolve('./src/api/*'),
'#types/*': resolve('./src/types/*'),
'#utils/*': resolve('./src/utils/*'),
'#core/*': resolve('./src/core/*'),
'#composables/*': resolve('./src/composables/*'),
'#test-utils/*': resolve('./tests/utils/*'),

"resolveJsonModule": true,
"types": ["node"],
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"skipLibCheck": true
}
}
26 changes: 4 additions & 22 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"paths": {
"#constants": ["./src/constants.ts"],
"#state": ["./src/state.ts"],
"#types/*": ["./src/types/*"],
"#api/*": ["./src/api/*"],
"#utils/*": ["./src/utils/*"],
"#core/*": ["./src/core/*"],
"#composables/*": ["./src/composables/*"]
},
"resolveJsonModule": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noEmit": true,
"skipLibCheck": true
}
"references": [
{ "path": "./tsconfig.app.json" }
],
"files": []
Comment thread
9romise marked this conversation as resolved.
}
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
include: ['tests/**/*.test.ts'],
include: ['**/*.test.ts'],
setupFiles: ['tests/__setup__/index.ts'],
server: {
deps: {
Expand Down
Loading