@platformatic/node 2.58.0 → 2.59.1

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) {
@@ -288,7 +300,6 @@ export class NodeStackable extends BaseStackable {
288
300
 
289
301
  async _findEntrypoint () {
290
302
  const config = this.configManager.current
291
- const outputRoot = resolve(this.root, config.application.outputDirectory)
292
303
 
293
304
  if (config.node.main) {
294
305
  return pathResolve(this.root, config.node.main)
@@ -312,19 +323,7 @@ export class NodeStackable extends BaseStackable {
312
323
  }
313
324
  }
314
325
 
315
- let root = this.root
316
-
317
- if (this.isProduction) {
318
- const hasCommand = this.configManager.current.application.commands.build
319
- const hasBuildScript = await this.#hasBuildScript()
320
-
321
- if (hasCommand || hasBuildScript) {
322
- this.verifyOutputDirectory(outputRoot)
323
- root = outputRoot
324
- }
325
- }
326
-
327
- return pathResolve(root, entrypoint)
326
+ return pathResolve(this.root, entrypoint)
328
327
  }
329
328
 
330
329
  async #hasBuildScript () {
@@ -339,6 +338,32 @@ export class NodeStackable extends BaseStackable {
339
338
 
340
339
  return hasBuildScript
341
340
  }
341
+
342
+ async getWatchConfig () {
343
+ const config = this.configManager.current
344
+
345
+ const enabled = config.watch?.enabled !== false
346
+
347
+ if (!enabled) {
348
+ return { enabled, path: this.root }
349
+ }
350
+
351
+ // ignore the outDir from tsconfig or service config if any
352
+ let ignore = config.watch?.ignore
353
+ if (!ignore) {
354
+ const tsConfig = await getTsconfig(this.root, config)
355
+ if (tsConfig) {
356
+ ignore = ignoreDirs(tsConfig?.compilerOptions?.outDir, tsConfig?.watchOptions?.excludeDirectories)
357
+ }
358
+ }
359
+
360
+ return {
361
+ enabled,
362
+ path: this.root,
363
+ allow: config.watch?.allow,
364
+ ignore
365
+ }
366
+ }
342
367
  }
343
368
 
344
369
  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.1",
4
4
  "description": "Platformatic Node.js Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -15,27 +15,28 @@
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/basic": "2.59.1",
21
+ "@platformatic/config": "2.59.1",
22
+ "@platformatic/utils": "2.59.1"
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.1",
35
+ "@platformatic/composer": "2.59.1"
35
36
  },
36
37
  "scripts": {
37
- "test": "npm run lint && borp --concurrency=1 --no-timeout",
38
- "coverage": "npm run lint && borp -C -X test -X test/fixtures --concurrency=1 --no-timeout",
38
+ "test": "pnpm run lint && borp --concurrency=1 --no-timeout",
39
+ "coverage": "pnpm run lint && borp -C -X test -X test/fixtures --concurrency=1 --no-timeout",
39
40
  "gen-schema": "node lib/schema.js > schema.json",
40
41
  "gen-types": "json2ts > config.d.ts < schema.json",
41
42
  "build": "pnpm run gen-schema && pnpm run gen-types",
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.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Stackable",
5
5
  "type": "object",