Skip to content

Commit c542f30

Browse files
committed
Enhance update output/mechanism
1 parent d27f37f commit c542f30

File tree

6 files changed

+51
-34
lines changed

6 files changed

+51
-34
lines changed

programs/cli/check-updates.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function isStableVersion(version: string) {
1616
return Boolean(v && v.prerelease.length === 0)
1717
}
1818

19-
export default async function checkUpdates(): Promise<string | null> {
19+
export default async function checkUpdates(): Promise<{
20+
suffix: string
21+
message: string
22+
} | null> {
2023
const packageJson = getCliPackageJson()
2124
let update = null
2225

@@ -29,7 +32,9 @@ export default async function checkUpdates(): Promise<string | null> {
2932
}
3033

3134
if (update && isStableVersion(update.latest)) {
32-
return messages.checkUpdates(packageJson, update)
35+
if (isStableVersion(packageJson.version)) {
36+
return messages.checkUpdates(packageJson, update)
37+
}
3338
}
3439

3540
return null

programs/cli/cli-lib/messages.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ export function checkUpdates(
8181
packageJson: Record<string, any>,
8282
update: {latest: string}
8383
) {
84-
return (
84+
const suffix = colors.gray(`(version ${String(update.latest)} is available!)`)
85+
const message =
8586
`${getLoggingPrefix('info')} 🧩 ${colors.blue('Extension.js')} update available.\n\n` +
8687
`You are currently using version ${colors.red(String(packageJson.version))}. ` +
8788
`Latest stable is ${colors.green(String(update.latest))}.\n` +
8889
`Update to the latest stable to get fixes and new features.`
89-
)
90+
91+
return {suffix, message}
9092
}
9193

9294
export function unsupportedNodeVersion() {

programs/cli/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,28 @@ import {registerPreviewCommand} from './commands/preview'
2121
import {registerBuildCommand} from './commands/build'
2222

2323
const cliPackageJson = getCliPackageJson()
24-
process.env.EXTENSION_CLI_VERSION = cliPackageJson.version
24+
25+
function developVersion() {
26+
try {
27+
const pkg = require('extension-develop/package.json')
28+
return pkg?.version || cliPackageJson.version
29+
} catch {
30+
return cliPackageJson.version
31+
}
32+
}
33+
34+
process.env.EXTENSION_DEVELOP_VERSION = developVersion()
2535

2636
checkUpdates().then((updateMessage) => {
2737
if (!updateMessage) return
2838

2939
if (process.env.EXTENSION_CLI_BANNER_PRINTED === 'true') {
3040
// eslint-disable-next-line no-console
31-
console.log(updateMessage)
41+
console.log(updateMessage.message)
3242
return
3343
}
3444

35-
process.env.EXTENSION_CLI_UPDATE_MESSAGE = updateMessage
45+
process.env.EXTENSION_CLI_UPDATE_SUFFIX = updateMessage.suffix
3646
})
3747

3848
const extensionJs = program

programs/develop/webpack/plugin-browsers/browsers-lib/banner.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ type HostPort = {host?: string; port?: number | string}
1818

1919
const printedKeys = new Set<string>()
2020

21-
function readUpdateMessageOnce() {
22-
const message = process.env.EXTENSION_CLI_UPDATE_MESSAGE
23-
if (!message) return null
24-
delete process.env.EXTENSION_CLI_UPDATE_MESSAGE
25-
return message
21+
function readUpdateSuffixOnce() {
22+
const suffix = process.env.EXTENSION_CLI_UPDATE_SUFFIX
23+
24+
if (!suffix) return null
25+
26+
delete process.env.EXTENSION_CLI_UPDATE_SUFFIX
27+
28+
return suffix
2629
}
2730

2831
function keyFor(
@@ -50,6 +53,7 @@ export async function printDevBannerOnce(opts: {
5053

5154
const info = (await opts.getInfo()) || null
5255
const manifestPath = path.join(opts.outPath, 'manifest.json')
56+
const updateSuffix = readUpdateSuffixOnce()
5357

5458
if (!fs.existsSync(manifestPath)) return false
5559

@@ -72,13 +76,10 @@ export async function printDevBannerOnce(opts: {
7276
manifest,
7377
opts.browser,
7478
message,
75-
opts.browserVersionLine
79+
opts.browserVersionLine,
80+
updateSuffix || undefined
7681
)
7782
)
78-
const updateMessage = readUpdateMessageOnce()
79-
if (updateMessage) {
80-
console.log(updateMessage)
81-
}
8283
console.log(messages.emptyLine())
8384
markBannerPrinted()
8485
process.env.EXTENSION_CLI_BANNER_PRINTED = 'true'
@@ -101,6 +102,7 @@ export async function printProdBannerOnce(opts: {
101102
opts.browserVersionLine && opts.browserVersionLine.trim().length > 0
102103
? opts.browserVersionLine.trim()
103104
: String(opts.browser || 'unknown')
105+
const updateSuffix = readUpdateSuffixOnce()
104106

105107
try {
106108
const manifestPath = path.join(opts.outPath, 'manifest.json')
@@ -123,13 +125,10 @@ export async function printProdBannerOnce(opts: {
123125
manifest,
124126
opts.browser,
125127
message,
126-
browserLabel
128+
browserLabel,
129+
updateSuffix || undefined
127130
)
128131
)
129-
const updateMessage = readUpdateMessageOnce()
130-
if (updateMessage) {
131-
console.log(updateMessage)
132-
}
133132
console.log(messages.emptyLine())
134133
} else {
135134
// Fallback: manifest-only summary using the unified dev/preview layout.
@@ -149,23 +148,16 @@ export async function printProdBannerOnce(opts: {
149148
manifest,
150149
opts.browser,
151150
message,
152-
browserLabel
151+
browserLabel,
152+
updateSuffix || undefined
153153
)
154154
)
155-
const updateMessage = readUpdateMessageOnce()
156-
if (updateMessage) {
157-
console.log(updateMessage)
158-
}
159155
console.log(messages.emptyLine())
160156
}
161157
} catch {
162158
// Fallback: if anything goes wrong, still try to print a minimal card
163159
console.log(messages.emptyLine())
164160
console.log(coreMessages.runningInProduction(opts.outPath, browserLabel))
165-
const updateMessage = readUpdateMessageOnce()
166-
if (updateMessage) {
167-
console.log(updateMessage)
168-
}
169161
console.log(messages.emptyLine())
170162
}
171163

programs/develop/webpack/plugin-browsers/browsers-lib/messages.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ export function runningInDevelopment(
942942
manifest: DevManifestInfo,
943943
browser: DevOptions['browser'],
944944
message: DevClientMessage,
945-
browserVersionLine?: string
945+
browserVersionLine?: string,
946+
updateSuffix?: string
946947
) {
947948
const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
948949
const manifestName = manifest.name || 'Extension.js'
@@ -994,6 +995,7 @@ export function runningInDevelopment(
994995
}
995996
// Note: keep dynamic import here to avoid ESM JSON import issues at compile time in some bundlers
996997
const extensionVersion =
998+
process.env.EXTENSION_DEVELOP_VERSION ||
997999
process.env.EXTENSION_CLI_VERSION ||
9981000
(() => {
9991001
try {
@@ -1091,10 +1093,12 @@ export function runningInDevelopment(
10911093

10921094
const lines: string[] = []
10931095

1096+
const updateNotice = updateSuffix ? ` ${updateSuffix}` : ''
1097+
10941098
lines.push(
10951099
` 🧩 ${colors.brightBlue('Extension.js')} ${colors.gray(
10961100
`${extensionVersion}`
1097-
)}`,
1101+
)}${updateNotice}`,
10981102
` Browser ${colors.gray(browserLabel)}`,
10991103
` Extension ${colors.gray(
11001104
version ? `${name} ${version}` : name || manifestName

programs/develop/webpack/plugin-extension/feature-special-folders/__spec__/warn-upon-folder-changes.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ const createFakeCompiler = () => {
4545

4646
const runCycle = (
4747
compiler: any,
48-
compilation: {warnings: any[]; errors: any[]; contextDependencies: Set<string>}
48+
compilation: {
49+
warnings: any[]
50+
errors: any[]
51+
contextDependencies: Set<string>
52+
}
4953
) => {
5054
;(compiler.hooks.watchRun as any).__invokeAll()
5155
;(compiler.hooks.thisCompilation as any).__invokeAll(compilation)

0 commit comments

Comments
 (0)