@platformatic/node 2.58.0 → 2.59.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.
package/index.js CHANGED
@@ -17,6 +17,7 @@ import { readFile } from 'node:fs/promises'
17
17
  import { Server } from 'node:http'
18
18
  import { resolve as pathResolve, resolve } from 'node:path'
19
19
  import { packageJson, schema } from './lib/schema.js'
20
+ import { getTsconfig, ignoreDirs, isServiceBuildable } from './lib/utils.js'
20
21
 
21
22
  const validFields = [
22
23
  'main',
@@ -70,6 +71,17 @@ export class NodeStackable extends BaseStackable {
70
71
  }
71
72
 
72
73
  const config = this.configManager.current
74
+
75
+ if (!this.isProduction && await isServiceBuildable(this.root, config)) {
76
+ this.logger.info(`Building "${this.serviceId}" before starting, in dev`)
77
+ try {
78
+ await this.build()
79
+ this.childManager = null
80
+ } catch (e) {
81
+ this.logger.error(`Error building "${this.serviceId}" before starting, in dev: ${e.message}`)
82
+ }
83
+ }
84
+
73
85
  const command = config.application.commands[this.isProduction ? 'production' : 'development']
74
86
 
75
87
  if (command) {
@@ -339,6 +351,32 @@ export class NodeStackable extends BaseStackable {
339
351
 
340
352
  return hasBuildScript
341
353
  }
354
+
355
+ async getWatchConfig () {
356
+ const config = this.configManager.current
357
+
358
+ const enabled = config.watch?.enabled !== false
359
+
360
+ if (!enabled) {
361
+ return { enabled, path: this.root }
362
+ }
363
+
364
+ // ignore the outDir from tsconfig or service config if any
365
+ let ignore = config.watch?.ignore
366
+ if (!ignore) {
367
+ const tsConfig = await getTsconfig(this.root, config)
368
+ if (tsConfig) {
369
+ ignore = ignoreDirs(tsConfig?.compilerOptions?.outDir, tsConfig?.watchOptions?.excludeDirectories)
370
+ }
371
+ }
372
+
373
+ return {
374
+ enabled,
375
+ path: this.root,
376
+ allow: config.watch?.allow,
377
+ ignore
378
+ }
379
+ }
342
380
  }
343
381
 
344
382
  async function getEntrypointInformation (root) {
package/lib/utils.js ADDED
@@ -0,0 +1,68 @@
1
+ import path, { join } from 'node:path'
2
+ import { readFile } from 'node:fs/promises'
3
+ import json5 from 'json5'
4
+
5
+ export async function isServiceBuildable (serviceRoot, config) {
6
+ // skip vite as stackable as it has its own build command
7
+ if (config?.vite) {
8
+ return false
9
+ }
10
+
11
+ if (config?.application?.commands?.build) {
12
+ return true
13
+ }
14
+
15
+ // Check if package.json exists and has a build command
16
+ const packageJsonPath = join(serviceRoot, 'package.json')
17
+
18
+ try {
19
+ // File exists, try to read and parse it
20
+ try {
21
+ const content = await readFile(packageJsonPath, 'utf8')
22
+ const packageJson = JSON.parse(content)
23
+ if (packageJson.scripts && packageJson.scripts.build) {
24
+ return true
25
+ }
26
+ } catch {
27
+ // Invalid JSON or other read error
28
+ }
29
+ } catch {
30
+ // package.json doesn't exist
31
+ }
32
+
33
+ return false
34
+ }
35
+
36
+ export async function getTsconfig (root, config) {
37
+ try {
38
+ const tsConfigPath = config?.plugins?.typescript?.tsConfig || path.resolve(root, 'tsconfig.json')
39
+ const tsConfig = json5.parse(await readFile(tsConfigPath, 'utf8'))
40
+
41
+ return Object.assign(tsConfig.compilerOptions, config?.plugins?.typescript)
42
+ } catch {
43
+ return null
44
+ }
45
+ }
46
+
47
+ export function ignoreDirs (outDir, watchOptionsExcludeDirectories) {
48
+ const ignore = new Set()
49
+
50
+ if (watchOptionsExcludeDirectories) {
51
+ for (const dir of watchOptionsExcludeDirectories) {
52
+ ignore.add(dir)
53
+ }
54
+ }
55
+
56
+ if (outDir) {
57
+ ignore.add(outDir)
58
+ if (!outDir.endsWith('/**')) {
59
+ ignore.add(`${outDir}/**`)
60
+ }
61
+ }
62
+
63
+ if (ignore.size === 0) {
64
+ return ['dist', 'dist/**']
65
+ }
66
+
67
+ return Array.from(ignore)
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "2.58.0",
3
+ "version": "2.59.0",
4
4
  "description": "Platformatic Node.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,23 +15,24 @@
15
15
  },
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "dependencies": {
18
+ "json5": "^2.2.3",
18
19
  "light-my-request": "^6.0.0",
19
- "@platformatic/config": "2.58.0",
20
- "@platformatic/utils": "2.58.0",
21
- "@platformatic/basic": "2.58.0"
20
+ "@platformatic/config": "2.59.0",
21
+ "@platformatic/basic": "2.59.0",
22
+ "@platformatic/utils": "2.59.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "borp": "^0.19.0",
25
- "express": "^4.19.2",
26
26
  "eslint": "9",
27
+ "express": "^4.19.2",
27
28
  "fastify": "^5.0.0",
28
29
  "json-schema-to-typescript": "^15.0.1",
29
30
  "koa": "^2.15.3",
30
31
  "neostandard": "^0.12.0",
31
32
  "tsx": "^4.19.0",
32
33
  "typescript": "^5.5.4",
33
- "@platformatic/composer": "2.58.0",
34
- "@platformatic/service": "2.58.0"
34
+ "@platformatic/service": "2.59.0",
35
+ "@platformatic/composer": "2.59.0"
35
36
  },
36
37
  "scripts": {
37
38
  "test": "npm run lint && borp --concurrency=1 --no-timeout",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/node/2.58.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/2.59.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Stackable",
5
5
  "type": "object",