wattpm 2.52.0 → 2.52.1-alpha.0

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.
@@ -86,6 +86,63 @@ export async function installDependencies (logger, root, services, production, p
86
86
  }
87
87
  }
88
88
 
89
+ async function updateDependencies (logger, availableVersions, path, target, force) {
90
+ // Parse the configuration file, if any
91
+ const packageJsonPath = resolve(path, 'package.json')
92
+
93
+ if (!existsSync(packageJsonPath)) {
94
+ return
95
+ }
96
+
97
+ let updated = false
98
+ const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8'))
99
+
100
+ for (const section of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
101
+ const sectionLabel = section === 'dependencies' ? '' : ` (${bold(section)})`
102
+ for (const [pkg, range] of Object.entries(packageJson[section] ?? {})) {
103
+ let specifier = range[0]
104
+
105
+ if (!packages.includes(pkg)) {
106
+ continue
107
+ }
108
+
109
+ let newRange
110
+ if (specifier !== '^' && specifier !== '~') {
111
+ if (!force) {
112
+ logger.fatal(
113
+ `Dependency ${bold(pkg)} of ${target}${sectionLabel} requires a non-updatable range ${bold(range)}. Try again with ${bold('-f/--force')} to update to the latest version.`
114
+ )
115
+ }
116
+
117
+ specifier = '^'
118
+ newRange = availableVersions[0]
119
+ } else {
120
+ newRange = availableVersions.find(v => satisfies(v, range))
121
+ }
122
+
123
+ // Nothing new, move on
124
+ if (!newRange) {
125
+ continue
126
+ }
127
+
128
+ newRange = specifier + newRange
129
+
130
+ if (newRange && specifier + newRange !== range) {
131
+ updated = true
132
+ logger.info(
133
+ `Updating dependency ${bold(pkg)} of ${target}${sectionLabel} from ${bold(range)} to ${bold(newRange)} ...`
134
+ )
135
+
136
+ packageJson[section][pkg] = newRange
137
+ }
138
+ }
139
+ }
140
+
141
+ if (updated) {
142
+ await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
143
+ }
144
+ }
145
+
89
146
  export async function buildCommand (logger, args) {
90
147
  const { positionals } = parseArgs(args, {}, false)
91
148
  /* c8 ignore next */
@@ -152,7 +209,19 @@ export async function installCommand (logger, args) {
152
209
  }
153
210
 
154
211
  export async function updateCommand (logger, args) {
155
- const { positionals } = parseArgs(args, {}, false)
212
+ const {
213
+ positionals,
214
+ values: { force }
215
+ } = parseArgs(
216
+ args,
217
+ {
218
+ force: {
219
+ type: 'boolean',
220
+ short: 'f'
221
+ }
222
+ },
223
+ false
224
+ )
156
225
 
157
226
  /* c8 ignore next */
158
227
  const root = getRoot(positionals)
@@ -176,54 +245,11 @@ export async function updateCommand (logger, args) {
176
245
  .map(s => s.version)
177
246
  )
178
247
 
248
+ await updateDependencies(logger, availableVersions, root, `the ${bold('application')}`, force)
249
+
179
250
  // Now, for all the services in the configuration file, update the dependencies
180
251
  for (const service of services) {
181
- // Parse the configuration file, if any
182
- const packageJsonPath = resolve(service.path, 'package.json')
183
- if (!existsSync(packageJsonPath)) {
184
- continue
185
- }
186
-
187
- let updated = false
188
- const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8'))
189
-
190
- for (const section of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
191
- const sectionLabel = section === 'dependencies' ? '' : ` (${bold(section)})`
192
- for (const [pkg, range] of Object.entries(packageJson[section] ?? {})) {
193
- const specifier = range[0]
194
-
195
- if (!packages.includes(pkg)) {
196
- continue
197
- }
198
-
199
- if (specifier !== '^' && specifier !== '~') {
200
- continue
201
- }
202
-
203
- // Search the first version that satisfies the range
204
- let newRange = availableVersions.find(v => satisfies(v, range))
205
-
206
- // Nothing new, move on
207
- if (!newRange) {
208
- continue
209
- }
210
-
211
- newRange = specifier + newRange
212
-
213
- if (newRange && specifier + newRange !== range) {
214
- updated = true
215
- logger.info(
216
- `Updating dependency ${bold(pkg)} of service ${bold(service.id)}${sectionLabel} from ${bold(range)} to ${bold(newRange)} ...`
217
- )
218
-
219
- packageJson[section][pkg] = newRange
220
- }
221
- }
222
- }
223
-
224
- if (updated) {
225
- await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
226
- }
252
+ await updateDependencies(logger, availableVersions, service.path, `the service ${bold(service.id)}`, force)
227
253
  }
228
254
 
229
255
  logger.done('All dependencies have been updated.')
@@ -268,6 +294,12 @@ export const help = {
268
294
  name: 'root',
269
295
  description: 'The directory containing the application (the default is the current directory)'
270
296
  }
297
+ ],
298
+ options: [
299
+ {
300
+ usage: '-f --force',
301
+ description: 'Force dependencies update even if it violates the package.json version range'
302
+ }
271
303
  ]
272
304
  }
273
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wattpm",
3
- "version": "2.52.0",
3
+ "version": "2.52.1-alpha.0",
4
4
  "description": "The Node.js Application Server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -36,11 +36,11 @@
36
36
  "semver": "^7.7.0",
37
37
  "split2": "^4.2.0",
38
38
  "table": "^6.8.2",
39
- "@platformatic/basic": "2.52.0",
40
- "@platformatic/config": "2.52.0",
41
- "@platformatic/control": "2.52.0",
42
- "@platformatic/runtime": "2.52.0",
43
- "@platformatic/utils": "2.52.0"
39
+ "@platformatic/basic": "2.52.1-alpha.0",
40
+ "@platformatic/config": "2.52.1-alpha.0",
41
+ "@platformatic/control": "2.52.1-alpha.0",
42
+ "@platformatic/utils": "2.52.1-alpha.0",
43
+ "@platformatic/runtime": "2.52.1-alpha.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "borp": "^0.19.0",
@@ -50,7 +50,7 @@
50
50
  "neostandard": "^0.12.0",
51
51
  "typescript": "^5.5.4",
52
52
  "undici": "^7.0.0",
53
- "@platformatic/node": "2.52.0"
53
+ "@platformatic/node": "2.52.1-alpha.0"
54
54
  },
55
55
  "scripts": {
56
56
  "test": "npm run lint && borp --concurrency=1 --timeout=300000",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/wattpm/2.52.0.json",
2
+ "$id": "https://schemas.platformatic.dev/wattpm/2.52.1-alpha.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {