@platformatic/service 0.15.1 → 0.17.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/fixtures/hello/no-server-logger.json +2 -2
- package/fixtures/hello/platformatic.service.json +2 -2
- package/fixtures/options/platformatic.service.yml +5 -4
- package/index.js +64 -66
- package/lib/compile.js +64 -91
- package/lib/config.js +2 -5
- package/lib/load-config.js +6 -2
- package/lib/sandbox-wrapper.js +26 -0
- package/lib/schema.js +37 -48
- package/lib/start.mjs +97 -68
- package/lib/utils.js +7 -4
- package/package.json +19 -19
- package/service.mjs +2 -2
- package/test/autoload.test.js +33 -21
- package/test/cli/compile.test.mjs +45 -3
- package/test/cli/gen-schema.test.mjs +4 -2
- package/test/cli/watch.test.mjs +59 -15
- package/test/config.test.js +70 -50
- package/test/fixtures/bad-typescript-plugin/dist/tsconfig.tsbuildinfo +1 -0
- package/test/fixtures/bad-typescript-plugin/platformatic.service.json +3 -5
- package/test/fixtures/directories/platformatic.service.json +2 -2
- package/test/fixtures/not-load.service.json +2 -3
- package/test/fixtures/typescript-plugin/platformatic.service.json +3 -5
- package/test/fixtures/typescript-plugin-nocompile/platformatic.service.json +3 -6
- package/test/load-and-reload-files.test.js +20 -20
- package/test/routes.test.js +3 -13
- package/test/schema.test.js +12 -0
- package/test/tmp/typescript-plugin-clone-1/platformatic.service.json +3 -5
- package/test/tmp/typescript-plugin-clone-2/platformatic.service.json +3 -6
- package/test/tmp/typescript-plugin-clone-3/dist/tsconfig.tsbuildinfo +1 -0
- package/test/tmp/typescript-plugin-clone-3/platformatic.service.json +3 -5
- package/test/tmp/typescript-plugin-clone-4/dist/plugin.js +18 -0
- package/test/tmp/typescript-plugin-clone-4/dist/plugin.js.map +1 -0
- package/test/tmp/typescript-plugin-clone-4/dist/tsconfig.tsbuildinfo +1 -0
- package/test/tmp/typescript-plugin-clone-4/platformatic.service.json +3 -5
- package/test/tmp/typescript-plugin-clone-4/tsconfig.json +22 -0
- package/test/tmp/typescript-plugin-clone-5/platformatic.service.json +3 -5
- package/test/tmp/typescript-plugin-clone-6/platformatic.service.json +3 -6
- package/test/utils.test.js +10 -3
- package/lib/autoload-wrapper.js +0 -11
package/lib/start.mjs
CHANGED
|
@@ -9,88 +9,114 @@ import { addLoggerToTheConfig } from './utils.js'
|
|
|
9
9
|
// TODO make sure coverage is reported for Windows
|
|
10
10
|
// Currently C8 is not reporting it
|
|
11
11
|
/* c8 ignore start */
|
|
12
|
-
async function start (_args) {
|
|
13
|
-
const { configManager } = await loadConfig({}, _args, { watch: true })
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
export function buildStart (_loadConfig, _buildServer) {
|
|
14
|
+
return async function start (_args) {
|
|
15
|
+
const { configManager, args } = await _loadConfig({}, _args, { watch: true })
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
addLoggerToTheConfig(config)
|
|
17
|
+
const config = configManager.current
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
config
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
// Set the logger if not present
|
|
20
|
+
addLoggerToTheConfig(config)
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
config.plugins?.typescript &&
|
|
24
|
+
config.plugins?.watch !== false
|
|
25
|
+
) {
|
|
26
|
+
try {
|
|
27
|
+
await compileWatch(dirname(configManager.fullPath))
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// TODO route this to a logger
|
|
30
|
+
console.error(error)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
|
-
} else if (config.plugin?.typescript !== undefined && config.plugin?.typescript?.build === false) {
|
|
31
|
-
// we don't have the logger here, shall we create one just for this message?
|
|
32
|
-
console.log(`TS build is disabled, expecting compiled js files in ${config.plugin.typescript.outDir} folder`)
|
|
33
|
-
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
const server = await buildServer({
|
|
37
|
-
...config,
|
|
38
|
-
configManager
|
|
39
|
-
})
|
|
35
|
+
let server = null
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
// Disable hot reload from the CLI
|
|
38
|
+
if (args.hotReload === false && configManager.current.plugins) {
|
|
39
|
+
configManager.current.plugins.hotReload = false
|
|
40
|
+
}
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
try {
|
|
43
|
+
// Set the location of the config
|
|
44
|
+
server = await _buildServer({
|
|
45
|
+
...config,
|
|
46
|
+
configManager
|
|
47
|
+
})
|
|
48
|
+
} catch (err) {
|
|
49
|
+
// TODO route this to a logger
|
|
50
|
+
console.error(err)
|
|
51
|
+
process.exit(1)
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
server.app.platformatic.configManager = configManager
|
|
55
|
+
server.app.platformatic.config = config
|
|
56
|
+
configManager.on('update', (newConfig) => {
|
|
57
|
+
if (args.hotReload === false && configManager.current.plugins) {
|
|
58
|
+
configManager.current.plugins.hotReload = false
|
|
59
|
+
}
|
|
60
|
+
onConfigUpdated(newConfig, server)
|
|
61
|
+
})
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
if (
|
|
64
|
+
config.plugins !== undefined &&
|
|
65
|
+
config.watch !== false
|
|
66
|
+
) {
|
|
67
|
+
await startFileWatching(server, args.hotReload)
|
|
68
|
+
}
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
try {
|
|
71
|
+
await server.listen()
|
|
72
|
+
} catch (err) {
|
|
73
|
+
server.app.log.error({ err })
|
|
74
|
+
process.exit(1)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
configManager.on('error', function (err) {
|
|
78
|
+
server.app.log.error({
|
|
79
|
+
err
|
|
80
|
+
}, 'error reloading the configuration')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
// Ignore from CI because SIGUSR2 is not available
|
|
84
|
+
// on Windows
|
|
85
|
+
process.on('SIGUSR2', function () {
|
|
86
|
+
server.app.log.info('reloading configuration')
|
|
87
|
+
server.restart()
|
|
88
|
+
.catch((err) => {
|
|
89
|
+
server.app.log.error({
|
|
90
|
+
err: {
|
|
91
|
+
message: err.message,
|
|
92
|
+
stack: err.stack
|
|
93
|
+
}
|
|
94
|
+
}, 'failed to restart')
|
|
95
|
+
})
|
|
96
|
+
return false
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
close(async ({ signal, err }) => {
|
|
100
|
+
// Windows does not support trapping signals
|
|
101
|
+
if (err) {
|
|
66
102
|
server.app.log.error({
|
|
67
103
|
err: {
|
|
68
104
|
message: err.message,
|
|
69
105
|
stack: err.stack
|
|
70
106
|
}
|
|
71
|
-
}, '
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
close(async ({ signal, err }) => {
|
|
77
|
-
// Windows does not support trapping signals
|
|
78
|
-
if (err) {
|
|
79
|
-
server.app.log.error({
|
|
80
|
-
err: {
|
|
81
|
-
message: err.message,
|
|
82
|
-
stack: err.stack
|
|
83
|
-
}
|
|
84
|
-
}, 'exiting')
|
|
85
|
-
} else if (signal) {
|
|
86
|
-
server.app.log.info({ signal }, 'received signal')
|
|
87
|
-
}
|
|
107
|
+
}, 'exiting')
|
|
108
|
+
} else if (signal) {
|
|
109
|
+
server.app.log.info({ signal }, 'received signal')
|
|
110
|
+
}
|
|
88
111
|
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
await server.stop()
|
|
113
|
+
})
|
|
114
|
+
}
|
|
91
115
|
}
|
|
92
116
|
|
|
93
|
-
|
|
117
|
+
const start = buildStart(loadConfig, buildServer)
|
|
118
|
+
|
|
119
|
+
async function startFileWatching (server, hotReload) {
|
|
94
120
|
const configManager = server.app.platformatic.configManager
|
|
95
121
|
const config = configManager.current
|
|
96
122
|
|
|
@@ -100,7 +126,7 @@ async function startFileWatching (server) {
|
|
|
100
126
|
watchIgnore: config.watch?.ignore
|
|
101
127
|
})
|
|
102
128
|
fileWatcher.on('update', () => {
|
|
103
|
-
onFilesUpdated(server)
|
|
129
|
+
onFilesUpdated(server, hotReload)
|
|
104
130
|
})
|
|
105
131
|
fileWatcher.startWatching()
|
|
106
132
|
|
|
@@ -137,21 +163,24 @@ async function onConfigUpdated (newConfig, server) {
|
|
|
137
163
|
}, 'failed to reload config')
|
|
138
164
|
} finally {
|
|
139
165
|
if (
|
|
140
|
-
newConfig.
|
|
141
|
-
newConfig.
|
|
166
|
+
newConfig.plugins !== undefined &&
|
|
167
|
+
newConfig.plugins.watch !== false
|
|
142
168
|
) {
|
|
143
169
|
await startFileWatching(server)
|
|
144
170
|
}
|
|
145
171
|
}
|
|
146
172
|
}
|
|
147
173
|
|
|
148
|
-
async function onFilesUpdated (server) {
|
|
174
|
+
async function onFilesUpdated (server, hotReload) {
|
|
149
175
|
// Reload the config as well, otherwise we will have problems
|
|
150
176
|
// in case the files watcher triggers the config watcher too
|
|
151
177
|
const configManager = server.app.platformatic.configManager
|
|
152
178
|
try {
|
|
153
179
|
server.app.log.debug('files changed')
|
|
154
180
|
await configManager.parse()
|
|
181
|
+
if (hotReload === false && configManager.current.plugins) {
|
|
182
|
+
configManager.current.plugins.hotReload = false
|
|
183
|
+
}
|
|
155
184
|
await server.restart(configManager.current)
|
|
156
185
|
} catch (err) {
|
|
157
186
|
// TODO: test this
|
package/lib/utils.js
CHANGED
|
@@ -41,14 +41,17 @@ function addLoggerToTheConfig (config) {
|
|
|
41
41
|
}
|
|
42
42
|
/* c8 ignore stop */
|
|
43
43
|
|
|
44
|
-
function getJSPluginPath (tsPluginPath, compileDir) {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
function getJSPluginPath (configPath, tsPluginPath, compileDir) {
|
|
45
|
+
if (tsPluginPath.endsWith('js')) {
|
|
46
|
+
return tsPluginPath
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tsPluginRelativePath = relative(dirname(configPath), tsPluginPath)
|
|
47
50
|
const jsPluginRelativePath = join(
|
|
48
51
|
dirname(tsPluginRelativePath),
|
|
49
52
|
basename(tsPluginRelativePath, '.ts') + '.js'
|
|
50
53
|
)
|
|
51
|
-
return join(
|
|
54
|
+
return join(compileDir, jsPluginRelativePath)
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Matteo Collina <hello@matteocollina.com>",
|
|
@@ -15,27 +15,27 @@
|
|
|
15
15
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"bindings": "^1.5.0",
|
|
18
|
-
"c8": "^7.
|
|
18
|
+
"c8": "^7.13.0",
|
|
19
19
|
"snazzy": "^9.0.0",
|
|
20
20
|
"split2": "^4.1.0",
|
|
21
21
|
"standard": "^17.0.0",
|
|
22
22
|
"strip-ansi": "^7.0.1",
|
|
23
|
-
"tap": "^16.3.
|
|
24
|
-
"typescript": "^4.9.
|
|
25
|
-
"undici": "^5.
|
|
26
|
-
"vscode-json-languageservice": "^5.
|
|
23
|
+
"tap": "^16.3.4",
|
|
24
|
+
"typescript": "^4.9.5",
|
|
25
|
+
"undici": "^5.20.0",
|
|
26
|
+
"vscode-json-languageservice": "^5.3.0",
|
|
27
27
|
"why-is-node-running": "^2.2.2",
|
|
28
|
-
"yaml": "^2.1
|
|
28
|
+
"yaml": "^2.2.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@fastify/accepts": "^4.1.0",
|
|
32
|
-
"@fastify/autoload": "^5.
|
|
32
|
+
"@fastify/autoload": "^5.7.1",
|
|
33
33
|
"@fastify/basic-auth": "^5.0.0",
|
|
34
34
|
"@fastify/cors": "^8.2.0",
|
|
35
35
|
"@fastify/deepmerge": "^1.3.0",
|
|
36
36
|
"@fastify/restartable": "^1.4.0",
|
|
37
|
-
"@fastify/static": "^6.
|
|
38
|
-
"@fastify/swagger": "^8.
|
|
37
|
+
"@fastify/static": "^6.9.0",
|
|
38
|
+
"@fastify/swagger": "^8.3.1",
|
|
39
39
|
"@fastify/under-pressure": "^8.2.0",
|
|
40
40
|
"close-with-grace": "^1.1.0",
|
|
41
41
|
"commist": "^3.2.0",
|
|
@@ -43,19 +43,19 @@
|
|
|
43
43
|
"env-schema": "^5.2.0",
|
|
44
44
|
"es-main": "^1.2.0",
|
|
45
45
|
"execa": "^7.0.0",
|
|
46
|
-
"fastify": "^4.
|
|
47
|
-
"fastify-metrics": "^10.0.
|
|
48
|
-
"fastify-plugin": "^4.
|
|
46
|
+
"fastify": "^4.13.0",
|
|
47
|
+
"fastify-metrics": "^10.0.3",
|
|
48
|
+
"fastify-plugin": "^4.5.0",
|
|
49
49
|
"fastify-sandbox": "^0.11.0",
|
|
50
50
|
"graphql": "^16.6.0",
|
|
51
51
|
"help-me": "^4.2.0",
|
|
52
|
-
"minimist": "^1.2.
|
|
53
|
-
"pino": "^8.
|
|
54
|
-
"pino-pretty": "^9.
|
|
52
|
+
"minimist": "^1.2.8",
|
|
53
|
+
"pino": "^8.11.0",
|
|
54
|
+
"pino-pretty": "^9.3.0",
|
|
55
55
|
"rfdc": "^1.3.0",
|
|
56
|
-
"ua-parser-js": "^1.0.
|
|
57
|
-
"@platformatic/config": "0.
|
|
58
|
-
"@platformatic/utils": "0.
|
|
56
|
+
"ua-parser-js": "^1.0.33",
|
|
57
|
+
"@platformatic/config": "0.17.0",
|
|
58
|
+
"@platformatic/utils": "0.17.0"
|
|
59
59
|
},
|
|
60
60
|
"standard": {
|
|
61
61
|
"ignore": [
|
package/service.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { join } from 'desm'
|
|
|
9
9
|
import { generateJsonSchemaConfig } from './lib/gen-schema.js'
|
|
10
10
|
|
|
11
11
|
import start from './lib/start.mjs'
|
|
12
|
-
import {
|
|
12
|
+
import { compileCmd } from './lib/compile.js'
|
|
13
13
|
|
|
14
14
|
const help = helpMe({
|
|
15
15
|
dir: join(import.meta.url, 'help'),
|
|
@@ -23,7 +23,7 @@ program.register('help', help.toStdout)
|
|
|
23
23
|
program.register('help start', help.toStdout.bind(null, ['start']))
|
|
24
24
|
|
|
25
25
|
program.register('start', start)
|
|
26
|
-
program.register('compile',
|
|
26
|
+
program.register('compile', compileCmd)
|
|
27
27
|
program.register('schema config', generateJsonSchemaConfig)
|
|
28
28
|
program.register('schema', help.toStdout.bind(null, ['schema']))
|
|
29
29
|
|
package/test/autoload.test.js
CHANGED
|
@@ -12,8 +12,8 @@ test('autoload & filesystem based routing / watch disabled', async ({ teardown,
|
|
|
12
12
|
hostname: '127.0.0.1',
|
|
13
13
|
port: 0
|
|
14
14
|
},
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
plugins: {
|
|
16
|
+
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
17
17
|
},
|
|
18
18
|
watch: false,
|
|
19
19
|
metrics: false
|
|
@@ -51,8 +51,8 @@ test('autoload & filesystem based routing / watch enabled', async ({ teardown, e
|
|
|
51
51
|
hostname: '127.0.0.1',
|
|
52
52
|
port: 0
|
|
53
53
|
},
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
plugins: {
|
|
55
|
+
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
56
56
|
},
|
|
57
57
|
watch: true,
|
|
58
58
|
metrics: false
|
|
@@ -90,11 +90,13 @@ test('multiple files', async ({ teardown, equal }) => {
|
|
|
90
90
|
hostname: '127.0.0.1',
|
|
91
91
|
port: 0
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
plugins: {
|
|
94
|
+
paths: [{
|
|
95
|
+
path: join(__dirname, 'fixtures', 'directories', 'plugins')
|
|
96
|
+
}, {
|
|
97
|
+
path: join(__dirname, 'fixtures', 'directories', 'routes')
|
|
98
|
+
}]
|
|
99
|
+
},
|
|
98
100
|
watch: true,
|
|
99
101
|
metrics: false
|
|
100
102
|
}
|
|
@@ -138,11 +140,13 @@ test('multiple files / watch false', async ({ teardown, equal }) => {
|
|
|
138
140
|
hostname: '127.0.0.1',
|
|
139
141
|
port: 0
|
|
140
142
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
plugins: {
|
|
144
|
+
paths: [{
|
|
145
|
+
path: join(__dirname, 'fixtures', 'directories', 'plugins')
|
|
146
|
+
}, {
|
|
147
|
+
path: join(__dirname, 'fixtures', 'directories', 'routes')
|
|
148
|
+
}]
|
|
149
|
+
},
|
|
146
150
|
watch: false,
|
|
147
151
|
metrics: false
|
|
148
152
|
}
|
|
@@ -186,7 +190,9 @@ test('autoload & filesystem based routing / watch disabled / no object', async (
|
|
|
186
190
|
hostname: '127.0.0.1',
|
|
187
191
|
port: 0
|
|
188
192
|
},
|
|
189
|
-
|
|
193
|
+
plugins: {
|
|
194
|
+
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
195
|
+
},
|
|
190
196
|
watch: false,
|
|
191
197
|
metrics: false
|
|
192
198
|
}
|
|
@@ -223,7 +229,9 @@ test('autoload & filesystem based routing / watch enabled / no object', async ({
|
|
|
223
229
|
hostname: '127.0.0.1',
|
|
224
230
|
port: 0
|
|
225
231
|
},
|
|
226
|
-
|
|
232
|
+
plugins: {
|
|
233
|
+
paths: [join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
234
|
+
},
|
|
227
235
|
watch: true,
|
|
228
236
|
metrics: false
|
|
229
237
|
}
|
|
@@ -260,7 +268,9 @@ test('multiple files / no object', async ({ teardown, equal }) => {
|
|
|
260
268
|
hostname: '127.0.0.1',
|
|
261
269
|
port: 0
|
|
262
270
|
},
|
|
263
|
-
|
|
271
|
+
plugins: {
|
|
272
|
+
paths: [join(__dirname, 'fixtures', 'directories', 'plugins'), join(__dirname, 'fixtures', 'directories', 'routes')]
|
|
273
|
+
},
|
|
264
274
|
watch: true,
|
|
265
275
|
metrics: false
|
|
266
276
|
}
|
|
@@ -304,10 +314,12 @@ test('multiple files / watch false / no object', async ({ teardown, equal }) =>
|
|
|
304
314
|
hostname: '127.0.0.1',
|
|
305
315
|
port: 0
|
|
306
316
|
},
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
317
|
+
plugins: {
|
|
318
|
+
paths: [
|
|
319
|
+
join(__dirname, 'fixtures', 'directories', 'plugins'),
|
|
320
|
+
join(__dirname, 'fixtures', 'directories', 'routes')
|
|
321
|
+
]
|
|
322
|
+
},
|
|
311
323
|
watch: false,
|
|
312
324
|
metrics: false
|
|
313
325
|
}
|
|
@@ -37,7 +37,7 @@ t.test('should compile typescript plugin', async (t) => {
|
|
|
37
37
|
t.pass()
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
t.test('should compile typescript plugin even if
|
|
40
|
+
t.test('should compile typescript plugin even if typescript is `false`', async (t) => {
|
|
41
41
|
const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
|
|
42
42
|
const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-2')
|
|
43
43
|
|
|
@@ -84,8 +84,10 @@ t.test('should compile typescript plugin with start command', async (t) => {
|
|
|
84
84
|
|
|
85
85
|
const splitter = split()
|
|
86
86
|
child.stdout.pipe(splitter)
|
|
87
|
+
child.stderr.pipe(process.stderr)
|
|
87
88
|
|
|
88
89
|
for await (const data of splitter) {
|
|
90
|
+
console.log(data)
|
|
89
91
|
const sanitized = stripAnsi(data)
|
|
90
92
|
if (sanitized.includes('Typescript plugin loaded')) {
|
|
91
93
|
t.pass()
|
|
@@ -102,6 +104,8 @@ t.test('should not compile bad typescript plugin', async (t) => {
|
|
|
102
104
|
await execa('node', [cliPath, 'compile'], { cwd })
|
|
103
105
|
t.fail('should not compile bad typescript plugin')
|
|
104
106
|
} catch (err) {
|
|
107
|
+
t.comment(err.stdout)
|
|
108
|
+
t.comment(err.stderr)
|
|
105
109
|
t.equal(err.stdout.includes('Found 1 error in plugin.ts'), true)
|
|
106
110
|
}
|
|
107
111
|
|
|
@@ -129,6 +133,8 @@ t.test('missing tsconfig file', async (t) => {
|
|
|
129
133
|
await execa('node', [cliPath, 'compile'], { cwd })
|
|
130
134
|
t.fail('should not compile typescript plugin')
|
|
131
135
|
} catch (err) {
|
|
136
|
+
t.comment(err.stdout)
|
|
137
|
+
t.comment(err.stderr)
|
|
132
138
|
t.equal(err.stdout.includes('The tsconfig.json file was not found.'), true)
|
|
133
139
|
}
|
|
134
140
|
|
|
@@ -148,7 +154,7 @@ t.test('start command should not compile typescript plugin with errors', async (
|
|
|
148
154
|
await childProcess
|
|
149
155
|
t.fail('should not compile bad typescript plugin')
|
|
150
156
|
} catch (err) {
|
|
151
|
-
t.equal(err.
|
|
157
|
+
t.equal(err.stderr.includes('Found 1 error'), true)
|
|
152
158
|
childProcess.kill('SIGINT')
|
|
153
159
|
}
|
|
154
160
|
|
|
@@ -177,11 +183,12 @@ t.test('should not compile typescript plugin with start without tsconfig', async
|
|
|
177
183
|
t.teardown(() => child.kill('SIGINT'))
|
|
178
184
|
t.fail('should not compile typescript plugin with start without tsconfig')
|
|
179
185
|
} catch (err) {
|
|
186
|
+
t.comment(err.stdout)
|
|
180
187
|
t.equal(err.stdout.includes('The tsconfig.json file was not found.'), true)
|
|
181
188
|
}
|
|
182
189
|
})
|
|
183
190
|
|
|
184
|
-
t.test('start command should not compile typescript if `
|
|
191
|
+
t.test('start command should not compile typescript if `typescript` is false', async (t) => {
|
|
185
192
|
const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin-nocompile')
|
|
186
193
|
const cwd = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-6')
|
|
187
194
|
|
|
@@ -211,3 +218,38 @@ t.test('start command should not compile typescript if `build` is false', async
|
|
|
211
218
|
t.pass()
|
|
212
219
|
}
|
|
213
220
|
})
|
|
221
|
+
|
|
222
|
+
t.test('should compile typescript plugin with start command with different cwd', async (t) => {
|
|
223
|
+
const testDir = path.join(urlDirname(import.meta.url), '..', 'fixtures', 'typescript-plugin')
|
|
224
|
+
const dest = path.join(urlDirname(import.meta.url), '..', 'tmp', 'typescript-plugin-clone-4')
|
|
225
|
+
|
|
226
|
+
await cp(testDir, dest, { recursive: true })
|
|
227
|
+
|
|
228
|
+
const child = execa('node', [cliPath, 'start', '-c', path.join(dest, 'platformatic.service.json')])
|
|
229
|
+
|
|
230
|
+
t.teardown(async () => {
|
|
231
|
+
if (os.platform() === 'win32') {
|
|
232
|
+
try {
|
|
233
|
+
await execa('taskkill', ['/pid', child.pid, '/f', '/t'])
|
|
234
|
+
} catch (err) {
|
|
235
|
+
console.error(`Failed to kill process ${child.pid})`)
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
child.kill('SIGINT')
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const splitter = split()
|
|
243
|
+
child.stdout.pipe(splitter)
|
|
244
|
+
child.stderr.pipe(process.stderr)
|
|
245
|
+
|
|
246
|
+
for await (const data of splitter) {
|
|
247
|
+
console.log(data)
|
|
248
|
+
const sanitized = stripAnsi(data)
|
|
249
|
+
if (sanitized.includes('Typescript plugin loaded')) {
|
|
250
|
+
t.pass()
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
t.fail('should compile typescript plugin with start command')
|
|
255
|
+
})
|
|
@@ -6,6 +6,8 @@ import { generateJsonSchemaConfig } from '../../lib/gen-schema.js'
|
|
|
6
6
|
import { join } from 'path'
|
|
7
7
|
import jsonLanguageService from 'vscode-json-languageservice'
|
|
8
8
|
|
|
9
|
+
const pkg = JSON.parse(await fs.readFile('../../package.json', 'utf8'))
|
|
10
|
+
|
|
9
11
|
test('generateJsonSchemaConfig generates the file', async (t) => {
|
|
10
12
|
const tmpDir = await mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
|
|
11
13
|
process.chdir(tmpDir)
|
|
@@ -17,7 +19,7 @@ test('generateJsonSchemaConfig generates the file', async (t) => {
|
|
|
17
19
|
t.has(required, ['server'])
|
|
18
20
|
t.has(additionalProperties, { watch: {} })
|
|
19
21
|
const { $id, type } = schema
|
|
20
|
-
t.equal($id,
|
|
22
|
+
t.equal($id, `https://platformatic.dev/schemas/v${pkg.version}/service`)
|
|
21
23
|
t.equal(type, 'object')
|
|
22
24
|
|
|
23
25
|
const languageservice = jsonLanguageService.getLanguageService({
|
|
@@ -29,7 +31,7 @@ test('generateJsonSchemaConfig generates the file', async (t) => {
|
|
|
29
31
|
languageservice.configure({ allowComments: false, schemas: [{ fileMatch: ['*.data.json'], uri: $id }] })
|
|
30
32
|
|
|
31
33
|
const jsonContent = `{
|
|
32
|
-
"$schema": "https://
|
|
34
|
+
"$schema": "https://platformatic.dev/schemas/v${pkg.version}/service",
|
|
33
35
|
"server": {
|
|
34
36
|
"hostname": "127.0.0.1",
|
|
35
37
|
"port": 3000
|