@platformatic/runtime 0.30.1 → 0.31.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.
@@ -0,0 +1,4 @@
1
+ PLT_SERVER_HOSTNAME=127.0.0.1
2
+ PORT=3001
3
+ PLT_SERVER_LOGGER_LEVEL=info
4
+ DATABASE_URL=sqlite://./db.sqlite
package/index.js CHANGED
@@ -4,6 +4,7 @@ const { platformaticRuntime } = require('./lib/config')
4
4
  const { start } = require('./lib/start')
5
5
  const unifiedApi = require('./lib/unified-api')
6
6
  const RuntimeApi = require('./lib/api')
7
+ const { compile } = require('./lib/compile')
7
8
 
8
9
  module.exports.buildServer = buildServer
9
10
  module.exports.platformaticRuntime = platformaticRuntime
@@ -11,3 +12,4 @@ module.exports.schema = platformaticRuntime.schema
11
12
  module.exports.RuntimeApi = RuntimeApi
12
13
  module.exports.start = start
13
14
  module.exports.unifiedApi = unifiedApi
15
+ module.exports.compile = compile
package/lib/compile.js CHANGED
@@ -1,41 +1,50 @@
1
1
  'use strict'
2
2
 
3
- const { loadConfig, tsCompiler } = require('@platformatic/service')
3
+ const { tsCompiler } = require('@platformatic/service')
4
+ const { loadConfig } = require('./unified-api')
5
+ const { dirname } = require('node:path')
6
+
4
7
  const pino = require('pino')
5
8
  const pretty = require('pino-pretty')
6
9
  const { isatty } = require('node:tty')
7
10
 
8
- const { platformaticRuntime } = require('./config')
9
-
10
- async function compile (argv) {
11
- const { configManager } = await loadConfig({}, argv, platformaticRuntime, {
11
+ async function compile (argv, logger) {
12
+ const { configManager, configType } = await loadConfig({}, argv, undefined, {
12
13
  watch: false
13
14
  })
14
15
 
15
- let stream
16
+ /* c8 ignore next */
17
+ if (!logger) {
18
+ let stream
16
19
 
17
- /* c8 ignore next 6 */
18
- if (isatty(process.stdout.fd)) {
19
- stream = pretty({
20
- translateTime: 'SYS:HH:MM:ss',
21
- ignore: 'hostname,pid'
22
- })
20
+ if (isatty(process.stdout.fd)) {
21
+ stream = pretty({
22
+ translateTime: 'SYS:HH:MM:ss',
23
+ ignore: 'hostname,pid'
24
+ })
25
+ }
26
+
27
+ logger = pino(stream)
23
28
  }
24
29
 
25
- const logger = pino(stream)
30
+ let compiled = false
26
31
 
27
- for (const service of configManager.current.services) {
28
- const childLogger = logger.child({ name: service.id })
32
+ if (configType === 'runtime') {
33
+ for (const service of configManager.current.services) {
34
+ const childLogger = logger.child({ name: service.id })
29
35
 
30
- const serviceConfig = await loadConfig({}, argv, platformaticRuntime, {
31
- watch: false
32
- })
36
+ const serviceConfig = await loadConfig({}, argv, undefined, {
37
+ watch: false
38
+ })
33
39
 
34
- const compiled = await tsCompiler.compile(service.path, serviceConfig.config, childLogger)
35
- if (!compiled) {
36
- logger.trace('No typescript found, skipping compilation')
40
+ const serviceWasCompiled = await tsCompiler.compile(service.path, serviceConfig.config, childLogger)
41
+ compiled ||= serviceWasCompiled
37
42
  }
43
+ } else {
44
+ compiled = await tsCompiler.compile(dirname(configManager.fullPath), configManager.current, logger)
38
45
  }
46
+
47
+ return compiled
39
48
  }
40
49
 
41
50
  module.exports.compile = compile
@@ -135,7 +135,12 @@ async function _loadConfig (minimistConfig, args, configType, overrides) {
135
135
  configType = await getConfigType(args)
136
136
  }
137
137
 
138
- return loadConfig(minimistConfig, args, getApp(configType), overrides)
138
+ const app = getApp(configType)
139
+ const res = await loadConfig(minimistConfig, args, app, overrides)
140
+ res.configType = configType
141
+ res.app = app
142
+
143
+ return res
139
144
  }
140
145
 
141
146
  async function _start (args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "standard": "^17.1.0",
25
25
  "tsd": "^0.28.1",
26
26
  "typescript": "^5.1.6",
27
- "@platformatic/sql-mapper": "0.30.1",
28
- "@platformatic/sql-graphql": "0.30.1"
27
+ "@platformatic/sql-mapper": "0.31.0",
28
+ "@platformatic/sql-graphql": "0.31.0"
29
29
  },
30
30
  "dependencies": {
31
31
  "@hapi/topo": "^6.0.2",
@@ -40,11 +40,11 @@
40
40
  "pino": "^8.14.1",
41
41
  "pino-pretty": "^10.0.0",
42
42
  "undici": "^5.22.1",
43
- "@platformatic/composer": "0.30.1",
44
- "@platformatic/config": "0.30.1",
45
- "@platformatic/db": "0.30.1",
46
- "@platformatic/service": "0.30.1",
47
- "@platformatic/utils": "0.30.1"
43
+ "@platformatic/composer": "0.31.0",
44
+ "@platformatic/config": "0.31.0",
45
+ "@platformatic/db": "0.31.0",
46
+ "@platformatic/service": "0.31.0",
47
+ "@platformatic/utils": "0.31.0"
48
48
  },
49
49
  "standard": {
50
50
  "ignore": [
package/runtime.mjs CHANGED
@@ -7,7 +7,9 @@ import isMain from 'es-main'
7
7
  import helpMe from 'help-me'
8
8
  import parseArgs from 'minimist'
9
9
  import { start } from './lib/start.js'
10
- import { compile } from './lib/compile.js'
10
+ import { compile as compileCmd } from './lib/compile.js'
11
+
12
+ export const compile = compileCmd
11
13
 
12
14
  const help = helpMe({
13
15
  dir: join(import.meta.url, 'help'),
@@ -14,20 +14,8 @@ try {
14
14
  } catch {
15
15
  }
16
16
 
17
- test('compile without tsconfigs', async () => {
18
- const config = join(import.meta.url, '..', '..', 'fixtures', 'configs', 'monorepo.json')
19
- await execa(cliPath, ['compile', '-c', config])
20
- })
21
-
22
- test('compile with tsconfig', async (t) => {
23
- const tmpDir = await mkdtemp(path.join(base, 'test-runtime-compile-'))
24
- const prev = process.cwd()
25
- process.chdir(tmpDir)
26
- t.after(() => {
27
- process.chdir(prev)
28
- })
29
-
30
- t.after(async () => {
17
+ function delDir (tmpDir) {
18
+ return async function () {
31
19
  // We give up after 10s.
32
20
  // This is because on Windows, it's very hard to delete files if the file
33
21
  // system is not collaborating.
@@ -42,8 +30,24 @@ test('compile with tsconfig', async (t) => {
42
30
  }
43
31
  }
44
32
  }
33
+ }
34
+ }
35
+
36
+ test('compile without tsconfigs', async () => {
37
+ const config = join(import.meta.url, '..', '..', 'fixtures', 'configs', 'monorepo.json')
38
+ await execa(cliPath, ['compile', '-c', config])
39
+ })
40
+
41
+ test('compile with tsconfig', async (t) => {
42
+ const tmpDir = await mkdtemp(path.join(base, 'test-runtime-compile-'))
43
+ const prev = process.cwd()
44
+ process.chdir(tmpDir)
45
+ t.after(() => {
46
+ process.chdir(prev)
45
47
  })
46
48
 
49
+ t.after(delDir(tmpDir))
50
+
47
51
  const folder = join(import.meta.url, '..', '..', 'fixtures', 'typescript')
48
52
  await cp(folder, tmpDir, { recursive: true })
49
53
 
@@ -72,22 +76,7 @@ test('compile with tsconfig custom flags', async (t) => {
72
76
  process.chdir(prev)
73
77
  })
74
78
 
75
- t.after(async () => {
76
- // We give up after 10s.
77
- // This is because on Windows, it's very hard to delete files if the file
78
- // system is not collaborating.
79
- for (let i = 0; i < 10; i++) {
80
- try {
81
- await rm(tmpDir, { recursive: true, force: true })
82
- break
83
- } catch (err) {
84
- if (err.code === 'EBUSY') {
85
- await sleep(1000)
86
- continue
87
- }
88
- }
89
- }
90
- })
79
+ t.after(delDir(tmpDir))
91
80
 
92
81
  const folder = join(import.meta.url, '..', '..', 'fixtures', 'typescript-custom-flags')
93
82
  await cp(folder, tmpDir, { recursive: true })
@@ -108,3 +97,28 @@ test('compile with tsconfig custom flags', async (t) => {
108
97
  assert.deepStrictEqual(lines[i].msg, expected[i].msg)
109
98
  }
110
99
  })
100
+
101
+ test('compile single service', async (t) => {
102
+ const tmpDir = await mkdtemp(path.join(base, 'test-runtime-compile-'))
103
+ const prev = process.cwd()
104
+ process.chdir(tmpDir)
105
+ t.after(() => {
106
+ process.chdir(prev)
107
+ })
108
+
109
+ t.after(delDir(tmpDir))
110
+
111
+ const folder = join(import.meta.url, '..', '..', 'fixtures', 'typescript', 'services', 'movies')
112
+ await cp(folder, tmpDir, { recursive: true })
113
+
114
+ const { stdout } = await execa(cliPath, ['compile'])
115
+
116
+ const lines = stdout.split('\n').map(JSON.parse)
117
+ const expected = [{
118
+ msg: 'Typescript compilation completed successfully.'
119
+ }]
120
+
121
+ for (let i = 0; i < expected.length; i++) {
122
+ assert.deepStrictEqual(lines[i].msg, expected[i].msg)
123
+ }
124
+ })