11'use strict' ;
22
3- const fs = require ( 'fs' ) ;
4- const fsp = require ( 'fs' ) . promises ;
5- const os = require ( 'os' ) ;
63const path = require ( 'path' ) ;
7- const stream = require ( 'stream' ) ;
8- const { Readable } = require ( 'stream' ) ;
9- const { promisify } = require ( 'util' ) ;
104const { log, progress, style } = require ( '../utils/serverless-utils/log' ) ;
11- const currentVersion = require ( '../../package' ) . version ;
125const ServerlessError = require ( '../serverless-error' ) ;
136const standaloneUtils = require ( '../utils/standalone' ) ;
14- const safeMoveFile = require ( '../utils/fs/safe-move-file' ) ;
157const { remove } = require ( '../utils/fs/remove' ) ;
168const cliCommandsSchema = require ( '../cli/commands-schema' ) ;
179
18- const pipeline = promisify ( stream . pipeline ) ;
19-
20- const BINARY_TMP_PATH = path . resolve ( os . tmpdir ( ) , 'serverless-binary-tmp' ) ;
21-
2210const BINARY_PATH = standaloneUtils . path ;
2311const mainProgress = progress . get ( 'main' ) ;
12+ const upgradeCommandDeprecationMessage = [
13+ 'The standalone `sls upgrade` command is deprecated and no longer updates osls.' ,
14+ 'It is scheduled for removal in osls v4.0.0.' ,
15+ '' ,
16+ 'Upgrade osls via npm instead:' ,
17+ '' ,
18+ ' npm install -g osls@latest' ,
19+ '' ,
20+ 'More info: https://github.com/oss-serverless/osls/blob/main/docs/guides/deprecations.md#STANDALONE_UPGRADE_COMMAND_DEPRECATED' ,
21+ ] . join ( '\n' ) ;
2422
2523module . exports = class Standalone {
2624 constructor ( serverless , cliOptions ) {
@@ -43,58 +41,9 @@ module.exports = class Standalone {
4341 }
4442
4543 async upgrade ( ) {
46- mainProgress . notice ( 'Resolving latest standalone version' , { isMainEvent : true } ) ;
47- const tagName = await standaloneUtils . resolveLatestTag ( ) ;
48- const latestVersion = tagName . slice ( 1 ) ;
49- if ( latestVersion === currentVersion ) {
50- log . notice ( ) ;
51- log . notice . skip (
52- `Already at latest version ${ style . aside (
53- `(${ Math . floor (
54- ( Date . now ( ) - this . serverless . pluginManager . commandRunStartTime ) / 1000
55- ) } s)`
56- ) } `
57- ) ;
58- return ;
59- }
60- const currentMajor = Number ( currentVersion . split ( '.' ) [ 0 ] ) ;
61- const latestMajor = Number ( latestVersion . split ( '.' ) [ 0 ] ) ;
62- if ( latestMajor > currentMajor && ! this . cliOptions . major ) {
63- throw new ServerlessError (
64- [
65- 'Cannot upgrade to a new major release without introducing a breaking changes' ,
66- '' ,
67- 'If you\'ve confirmed it\'s safe and want to upgrade, run "sls upgrade --major"' ,
68- '' ,
69- 'Note: Service is safe to upgrade if no deprecations are logged during its deployment.' ,
70- ` Check https://github.com/serverless/serverless/releases/tag/v${ latestMajor } .0.0 ` +
71- 'for list of all breaking changes' ,
72- ] . join ( '\n' ) ,
73- 'CANNOT_UPGRADE_MAJOR'
74- ) ;
75- }
76- mainProgress . notice ( 'Downloading latest standalone version' , { isMainEvent : true } ) ;
77- const executableUrl = standaloneUtils . resolveUrl ( tagName ) ;
78- const standaloneResponse = await fetch ( executableUrl ) ;
79- if ( ! standaloneResponse . ok ) {
80- throw new ServerlessError (
81- 'Sorry unable to `upgrade` at this point ' +
82- `(server rejected request with ${ standaloneResponse . status } )` ,
83- 'UPGRADE_ERROR'
84- ) ;
85- }
86- await remove ( BINARY_TMP_PATH ) ;
87- await pipeline (
88- Readable . fromWeb ( standaloneResponse . body ) ,
89- fs . createWriteStream ( BINARY_TMP_PATH )
90- ) ;
91- await safeMoveFile ( BINARY_TMP_PATH , BINARY_PATH ) ;
92- await fsp . chmod ( BINARY_PATH , 0o755 ) ;
93- log . notice ( ) ;
94- log . notice . success (
95- `Successfully upgraded to ${ tagName } ${ style . aside (
96- `(${ Math . floor ( ( Date . now ( ) - this . serverless . pluginManager . commandRunStartTime ) / 1000 ) } s)`
97- ) } `
44+ throw new ServerlessError (
45+ upgradeCommandDeprecationMessage ,
46+ 'STANDALONE_UPGRADE_COMMAND_DEPRECATED'
9847 ) ;
9948 }
10049
0 commit comments