@adobe/aem-cli 16.16.6 → 16.16.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +2 -1
- package/src/server/utils.js +9 -9
- package/src/up.cmd.js +6 -0
- package/src/update-check.js +125 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [16.16.7](https://github.com/adobe/helix-cli/compare/v16.16.6...v16.16.7) (2025-11-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **server:** transform plain text 401/403 to Chrome-compatible HTML for sidekick ([#2414](https://github.com/adobe/helix-cli/issues/2414)) ([a261c6d](https://github.com/adobe/helix-cli/commit/a261c6dfa7a44ae44cd68bcf65f1a3473e1607cb)), closes [#2601](https://github.com/adobe/helix-cli/issues/2601)
|
|
7
|
+
|
|
1
8
|
## [16.16.6](https://github.com/adobe/helix-cli/compare/v16.16.5...v16.16.6) (2025-11-26)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aem-cli",
|
|
3
|
-
"version": "16.16.
|
|
3
|
+
"version": "16.16.7",
|
|
4
4
|
"description": "AEM CLI",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"shelljs": "0.10.0",
|
|
79
79
|
"unified": "11.0.5",
|
|
80
80
|
"uuid": "13.0.0",
|
|
81
|
+
"xdg-basedir": "5.1.0",
|
|
81
82
|
"yargs": "18.0.0"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
package/src/server/utils.js
CHANGED
|
@@ -412,15 +412,15 @@ window.LiveReloadOptions = {
|
|
|
412
412
|
return;
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
</html
|
|
423
|
-
|
|
415
|
+
// Transform plain text 401/403 responses into Chrome-compatible HTML
|
|
416
|
+
// This allows the sidekick to recognize the error page and enable login
|
|
417
|
+
const statusText = ret.status === 401 ? '401 Unauthorized' : '403 Forbidden';
|
|
418
|
+
const escapedUrl = url
|
|
419
|
+
.replace(/&/g, '&')
|
|
420
|
+
.replace(/"/g, '"');
|
|
421
|
+
|
|
422
|
+
const textBody = `<html><head><meta name="color-scheme" content="light dark"><meta property="hlx:proxyUrl" content="${escapedUrl}"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">${statusText}</pre></body></html>`;
|
|
423
|
+
|
|
424
424
|
respHeaders['content-type'] = 'text/html';
|
|
425
425
|
res
|
|
426
426
|
.set(respHeaders)
|
package/src/up.cmd.js
CHANGED
|
@@ -17,6 +17,7 @@ import { HelixProject } from './server/HelixProject.js';
|
|
|
17
17
|
import GitUtils from './git-utils.js';
|
|
18
18
|
import pkgJson from './package.cjs';
|
|
19
19
|
import { AbstractServerCommand } from './abstract-server.cmd.js';
|
|
20
|
+
import { checkForUpdates } from './update-check.js';
|
|
20
21
|
|
|
21
22
|
export default class UpCommand extends AbstractServerCommand {
|
|
22
23
|
withLiveReload(value) {
|
|
@@ -121,6 +122,11 @@ export default class UpCommand extends AbstractServerCommand {
|
|
|
121
122
|
this.log.info(chalk`{yellow /_/ |_/_____/_/ /_/ /____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/}`);
|
|
122
123
|
this.log.info('');
|
|
123
124
|
|
|
125
|
+
// Check for updates asynchronously (non-blocking)
|
|
126
|
+
checkForUpdates('@adobe/aem-cli', pkgJson.version, this.log).catch(() => {
|
|
127
|
+
// Silently ignore errors
|
|
128
|
+
});
|
|
129
|
+
|
|
124
130
|
const ref = await GitUtils.getBranch(this.directory);
|
|
125
131
|
this._gitUrl = await GitUtils.getOriginURL(this.directory, { ref });
|
|
126
132
|
if (!this._gitUrl) {
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import os from 'os';
|
|
15
|
+
import semver from 'semver';
|
|
16
|
+
import chalk from 'chalk-template';
|
|
17
|
+
import { xdgCache } from 'xdg-basedir';
|
|
18
|
+
import { getFetch } from './fetch-utils.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets the path to the update check cache file using XDG base directories.
|
|
22
|
+
* @returns {string} Path to the cache file
|
|
23
|
+
*/
|
|
24
|
+
function getUpdateCheckCacheFile() {
|
|
25
|
+
const cacheDir = xdgCache || path.join(os.homedir(), '.cache');
|
|
26
|
+
return path.join(cacheDir, 'aem-cli', 'last-update-check');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Checks if we should skip the update check based on the last check time.
|
|
31
|
+
* @returns {Promise<boolean>} True if we should skip the check
|
|
32
|
+
*/
|
|
33
|
+
async function shouldSkipUpdateCheck() {
|
|
34
|
+
try {
|
|
35
|
+
const cacheFile = getUpdateCheckCacheFile();
|
|
36
|
+
const stats = await fs.stat(cacheFile);
|
|
37
|
+
const lastCheck = stats.mtime.getTime();
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
const oneDayInMs = 24 * 60 * 60 * 1000;
|
|
40
|
+
|
|
41
|
+
return (now - lastCheck) < oneDayInMs;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
// If file doesn't exist or any other error, we should check
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Updates the last update check timestamp.
|
|
50
|
+
*/
|
|
51
|
+
async function updateLastCheckTime() {
|
|
52
|
+
try {
|
|
53
|
+
const cacheFile = getUpdateCheckCacheFile();
|
|
54
|
+
const cacheDir = path.dirname(cacheFile);
|
|
55
|
+
|
|
56
|
+
// Ensure cache directory exists
|
|
57
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
58
|
+
|
|
59
|
+
// Touch the file to update its mtime
|
|
60
|
+
await fs.writeFile(cacheFile, Date.now().toString());
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// Silently ignore errors - this is not critical
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a newer version of the package is available on npm.
|
|
68
|
+
* @param {string} packageName - The npm package name to check
|
|
69
|
+
* @param {string} currentVersion - The current version of the package
|
|
70
|
+
* @param {object} logger - Logger instance for outputting messages
|
|
71
|
+
* @returns {Promise<void>}
|
|
72
|
+
*/
|
|
73
|
+
export async function checkForUpdates(packageName, currentVersion, logger) {
|
|
74
|
+
try {
|
|
75
|
+
// Check if we should skip the update check (rate limiting)
|
|
76
|
+
if (await shouldSkipUpdateCheck()) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const fetch = getFetch();
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
|
|
83
|
+
|
|
84
|
+
const response = await fetch(`https://registry.npmjs.org/${packageName}`, {
|
|
85
|
+
signal: controller.signal,
|
|
86
|
+
});
|
|
87
|
+
clearTimeout(timeoutId);
|
|
88
|
+
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
// Silently fail if we can't check for updates
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const data = await response.json();
|
|
95
|
+
const latestVersion = data['dist-tags']?.latest;
|
|
96
|
+
|
|
97
|
+
if (latestVersion && semver.gt(latestVersion, currentVersion)) {
|
|
98
|
+
const boxWidth = 61;
|
|
99
|
+
const updateMsg = `Update available! ${currentVersion} → ${latestVersion}`;
|
|
100
|
+
const installMsg = `Run npm install -g ${packageName} to update`;
|
|
101
|
+
|
|
102
|
+
// Use String.padEnd() instead of manual padding calculation
|
|
103
|
+
const updatePadded = ` ${updateMsg}`.padEnd(boxWidth - 1);
|
|
104
|
+
const installPadded = ` ${installMsg}`.padEnd(boxWidth - 1);
|
|
105
|
+
|
|
106
|
+
logger.warn('');
|
|
107
|
+
logger.warn(chalk`{yellow ╭─────────────────────────────────────────────────────────────╮}`);
|
|
108
|
+
logger.warn(chalk`{yellow │ │}`);
|
|
109
|
+
logger.warn(chalk`{yellow │${updatePadded} │}`);
|
|
110
|
+
logger.warn(chalk`{yellow │${installPadded} │}`);
|
|
111
|
+
logger.warn(chalk`{yellow │ │}`);
|
|
112
|
+
logger.warn(chalk`{yellow ╰─────────────────────────────────────────────────────────────╯}`);
|
|
113
|
+
logger.warn('');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Update the last check time after a successful check
|
|
117
|
+
await updateLastCheckTime();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
// Silently fail - don't block the command if update check fails
|
|
120
|
+
// Only log in debug mode if available
|
|
121
|
+
if (logger.level === 'debug' || logger.level === 'silly') {
|
|
122
|
+
logger.debug(`Update check failed: ${error.message}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|