Skip to content

Commit cdb44a9

Browse files
refactor: Improved the text of new packages to be installed
1 parent 8cc050d commit cdb44a9

File tree

6 files changed

+26
-54
lines changed

6 files changed

+26
-54
lines changed

locales/bundle.l10n.jsonc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"Package \"{0}\" pending installation: {1}.": "", // The package has been declared as a dependency, but no version has yet been installed.
2929
"Newer version of \"{0}\" is available: {1}.": "", // New version available which can be used by user.
3030
"Pre-release version of \"{0}\".": "", // The defined user version is a pre-release, and there is no better alternative yet.
31-
"Ready-to-install package. Just run your package manager install command.": "", // User must run the `npm install` to install new packages based on version defined.
31+
"Ready-to-install package \"{0}\" at version {1}. Just run your package manager install command.": "", // User must run the `npm install` to install new packages based on version defined.
3232
"Security advisory: this package version has a known flaw level {0}/{1}.": "", // Diagnostic warning when a security advisory exists.
3333
"Please upgrade to version {0} or higher.": "", // Suggested upgrade to a version above.
3434
"No fix available yet.": "", // The flaw is not yet known to be resolved in a future release.
@@ -38,7 +38,6 @@
3838
"Install packages": "", // Forces the display of the notification suggesting to update the package (two or more packages to be installed).
3939

4040
// DocumentDecoration.ts related.
41-
"Install pending": "", // The package was never installed, but the version entered by the user is the latest available.
4241
"Update available:": "", // The package has already been installed and has a new version available.
4342
"Latest version:": "", // The package was never installed, and the user's version is not the latest available.
4443
"install pending": "", // The informed version has not yet been installed by the user.

locales/bundle.l10n.pt-br.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"Package \"{0}\" pending installation: {1}.": "Dependência \"{0}\" com instalação pendente: {1}",
2020
"Newer version of \"{0}\" is available: {1}.": "Versão mais nova disponível para a dependência \"{0}\": {1}",
2121
"Pre-release version of \"{0}\".": "Versão pre-release de \"{0}\".",
22-
"Ready-to-install package. Just run your package manager install command.": "Pacote pronto para instalar. Basta executar o comando `install` do seu gerenciador de dependências.",
22+
"Ready-to-install package \"{0}\" at version {1}. Just run your package manager install command.": "Pacote pronto para instalar. Basta executar o comando `install` do seu gerenciador de dependências.",
2323
"Security advisory: this package version has a known flaw level {0}/{1}.": "",
2424
"Please upgrade to version {0} or higher.": "Por favor, atualize para a versão {0} ou superior.",
2525
"No fix available yet.": "Ainda não há uma correção disponível.",
@@ -28,7 +28,6 @@
2828
"Install package": "Instalar dependência",
2929
"Install packages": "Instalar dependências",
3030

31-
"Install pending": "Instalação pendente",
3231
"Update available:": "Atualização disponível:",
3332
"Latest version:": "Versão mais recente:",
3433
"install pending": "instalação pendente",

src/Diagnostic.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,16 @@ export const getPackageDiagnostic = async (
164164
)
165165
}
166166

167-
if (!(await packageInfo.isInstalled())) {
168-
return new PackageRelatedDiagnostic(
169-
packageInfo.versionRange,
170-
l10n.t(
171-
'Package "{0}" pending installation: {1}.',
172-
packageInfo.name,
173-
versionLatest
174-
),
175-
DiagnosticSeverity.Information,
176-
document,
177-
packageInfo,
178-
DiagnosticType.READY_TO_INSTALL
179-
)
180-
}
181-
182167
if (!(await packageInfo.isVersionUpdatable())) {
183168
// The user has the latest version defined in `package.json`,
184169
// but still needs to run `npm install` to complete.
185170
if (await packageInfo.requiresInstallCommand()) {
186171
return new PackageRelatedDiagnostic(
187172
packageInfo.versionRange,
188173
l10n.t(
189-
"Ready-to-install package. Just run your package manager install command."
174+
'Ready-to-install package "{0}" at version {1}. Just run your package manager install command.',
175+
packageInfo.name,
176+
versionLatest
190177
),
191178
DiagnosticSeverity.Information,
192179
document,

src/DocumentDecoration.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,6 @@ export class DocumentDecoration {
208208
const packageVersionInstalled =
209209
await packageInfo.packageRelated.getVersionInstalled()
210210

211-
// It informs that the version has not yet been installed,
212-
// but the user's version is in fact the last one available.
213-
if (
214-
!packageVersionInstalled &&
215-
(await packageInfo.packageRelated.isVersionMaxed())
216-
) {
217-
return this.setLine(line, [
218-
new Message(
219-
Icons.PENDING,
220-
ThemeLight.ICON_AVAILABLE,
221-
ThemeDark.ICON_AVAILABLE
222-
),
223-
new Message(l10n.t("Install pending")),
224-
])
225-
}
226-
227211
if (await packageInfo.packageRelated.requiresInstallCommand()) {
228212
return this.setLine(line, [
229213
new Message(

src/PackageInfo.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@ export class PackageInfo {
4444
return this.versionRange.end.line
4545
}
4646

47-
// Check if the package is installed.
48-
public async isInstalled(): Promise<boolean> {
49-
const packagesInstalled = await getPackagesInstalled()
50-
51-
if (!packagesInstalled) {
52-
return false
53-
}
54-
55-
return (
56-
this.name in packagesInstalled &&
57-
packagesInstalled[this.name] !== undefined
58-
)
59-
}
60-
6147
// Check if is a valid package name.
6248
// Eg. "typescript" instead of "type script".
6349
public isNameValid(): boolean {
@@ -129,7 +115,11 @@ export class PackageInfo {
129115
}
130116

131117
const versionLatest = (await this.getVersionLatest())!
132-
const versionNormalized = this.getVersionNormalized()!
118+
const versionNormalized = this.getVersionNormalized()
119+
120+
if (!versionNormalized) {
121+
return true
122+
}
133123

134124
// Check if the version difference is compatible with what was configured by the user.
135125
// If the difference is less than the minimum configured then there is no need for a diagnostic.

src/extension.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ describe("package diagnostics", () => {
4242
selectFirsts: 1,
4343
})
4444

45-
expect(diagnostics[0]?.message).toContain("pending installation")
45+
expect(diagnostics[0]?.message).toContain("run your package manager")
4646
expect(diagnostics[0]?.severity).toBe(DiagnosticSeverity.Information)
47-
expect(decorations[0]).toContain("Install pending")
47+
expect(decorations[0]).toContain(
48+
"Now run your package manager install command."
49+
)
4850
expect(actions[0]?.title).toBe("Install package")
4951
expect(actions).toHaveLength(1)
5052
})
@@ -268,7 +270,9 @@ describe("package diagnostics", () => {
268270
packagesRepository: { "npm-outdated": ["1.0.0", "1.0.1"] },
269271
})
270272

271-
expect(diagnostics[0]?.message).toContain("run your package manager")
273+
expect(diagnostics[0]?.message).toBe(
274+
'Ready-to-install package "npm-outdated" at version 1.0.1. Just run your package manager install command.'
275+
)
272276
expect(decorations[0]).toContain(
273277
"Now run your package manager install command."
274278
)
@@ -312,6 +316,15 @@ describe("package diagnostics", () => {
312316
expect(decorations).toStrictEqual([])
313317
})
314318

319+
it("dependency version is incomplete/empty", async () => {
320+
const { decorations } = await vscodeSimulator({
321+
packageJson: { dependencies: { "npm-outdated": "" } },
322+
packagesRepository: { "npm-outdated": ["1.0.0"] },
323+
})
324+
325+
expect(decorations[0]).toContain("(install pending)")
326+
})
327+
315328
it("decorations simple", async () => {
316329
const { decorations } = await vscodeSimulator({
317330
configurations: { decorations: "simple" },

0 commit comments

Comments
 (0)