@platformatic/vite 2.2.1 → 2.3.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.
Files changed (3) hide show
  1. package/index.js +45 -39
  2. package/package.json +7 -7
  3. package/schema.json +1 -1
package/index.js CHANGED
@@ -125,29 +125,14 @@ export class ViteStackable extends BaseStackable {
125
125
  }
126
126
 
127
127
  getMeta () {
128
- let composer = { prefix: this.servicePrefix, wantsAbsoluteUrls: true, needsRootRedirect: true }
129
-
130
- if (this.isProduction) {
131
- composer = {
132
- tcp: typeof this.url !== 'undefined',
133
- url: this.url,
134
- prefix: (this.subprocessConfig?.base ?? this.#basePath).replace(/(^\/)|(\/$)/g, ''),
135
- wantsAbsoluteUrls: true,
136
- needsRootRedirect: true
137
- }
138
- } else if (this.url) {
139
- if (!this.#basePath) {
140
- const config = this.subprocessConfig ?? this.#app.config
141
- this.#basePath = config.base.replace(/(^\/)|(\/$)/g, '')
142
- }
143
-
144
- composer = {
145
- tcp: true,
146
- url: this.url,
147
- prefix: this.#basePath.replace(/(^\/)|(\/$)/g, ''),
148
- wantsAbsoluteUrls: true,
149
- needsRootRedirect: true
150
- }
128
+ const config = this.subprocessConfig ?? this.#app?.config
129
+
130
+ const composer = {
131
+ tcp: typeof this.url !== 'undefined',
132
+ url: this.url,
133
+ prefix: this.basePath ?? config?.base ?? this.#basePath,
134
+ wantsAbsoluteUrls: true,
135
+ needsRootRedirect: true
151
136
  }
152
137
 
153
138
  return { composer }
@@ -165,6 +150,14 @@ export class ViteStackable extends BaseStackable {
165
150
  ? ensureTrailingSlash(cleanBasePath(config.application?.basePath))
166
151
  : undefined
167
152
 
153
+ this.registerGlobals({
154
+ id: this.id,
155
+ // Always use URL to avoid serialization problem in Windows
156
+ root: pathToFileURL(this.root).toString(),
157
+ basePath: this.#basePath,
158
+ logLevel: this.logger.level
159
+ })
160
+
168
161
  if (command) {
169
162
  return this.startWithCommand(command)
170
163
  }
@@ -218,6 +211,13 @@ export class ViteStackable extends BaseStackable {
218
211
  ? ensureTrailingSlash(cleanBasePath(config.application?.basePath))
219
212
  : undefined
220
213
 
214
+ this.registerGlobals({
215
+ id: this.id,
216
+ // Always use URL to avoid serialization problem in Windows
217
+ root: pathToFileURL(this.root).toString(),
218
+ basePath: this.#basePath,
219
+ logLevel: this.logger.level
220
+ })
221
221
  if (command) {
222
222
  return this.startWithCommand(command)
223
223
  }
@@ -300,9 +300,19 @@ export class ViteSSRStackable extends NodeStackable {
300
300
 
301
301
  if (this.isProduction) {
302
302
  const clientDirectory = config.vite.ssr.clientDirectory
303
- this.verifyOutputDirectory(
304
- resolve(this.root, clientDirectory, config.application.outputDirectory, clientDirectory)
305
- )
303
+ const clientOutDir = resolve(this.root, clientDirectory, config.application.outputDirectory, clientDirectory)
304
+
305
+ this.verifyOutputDirectory(clientOutDir)
306
+
307
+ const buildInfoPath = resolve(clientOutDir, '.platformatic-build.json')
308
+ if (!this.#basePath && existsSync(buildInfoPath)) {
309
+ try {
310
+ const buildInfo = JSON.parse(await readFile(buildInfoPath, 'utf-8'))
311
+ this.#basePath = buildInfo.basePath
312
+ } catch (e) {
313
+ console.log(e)
314
+ }
315
+ }
306
316
  }
307
317
 
308
318
  await super.start({ listen })
@@ -370,20 +380,16 @@ export class ViteSSRStackable extends NodeStackable {
370
380
  getMeta () {
371
381
  let composer = { prefix: this.servicePrefix, wantsAbsoluteUrls: true, needsRootRedirect: true }
372
382
 
373
- if (this.url) {
374
- if (!this.#basePath) {
375
- const application = this._getApplication()
376
- const config = application.vite.devServer?.config ?? application.vite.config.vite
377
- this.#basePath = (config.base ?? '').replace(/(^\/)|(\/$)/g, '')
378
- }
383
+ const vite = this._getApplication()?.vite
384
+ const config = vite?.devServer?.config ?? vite?.config.vite
385
+ const applicationBasePath = config?.base
379
386
 
380
- composer = {
381
- tcp: true,
382
- url: this.url,
383
- prefix: this.#basePath ?? this.servicePrefix,
384
- wantsAbsoluteUrls: true,
385
- needsRootRedirect: true
386
- }
387
+ composer = {
388
+ tcp: typeof this.url !== 'undefined',
389
+ url: this.url,
390
+ prefix: this.basePath ?? applicationBasePath ?? this.#basePath,
391
+ wantsAbsoluteUrls: true,
392
+ needsRootRedirect: true
387
393
  }
388
394
 
389
395
  return { composer }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/vite",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "Platformatic Vite Stackable",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -18,10 +18,10 @@
18
18
  "@fastify/static": "^8.0.0",
19
19
  "fastify": "^5.0.0",
20
20
  "semver": "^7.6.3",
21
- "@platformatic/basic": "2.2.1",
22
- "@platformatic/config": "2.2.1",
23
- "@platformatic/node": "2.2.1",
24
- "@platformatic/utils": "2.2.1"
21
+ "@platformatic/basic": "2.3.0",
22
+ "@platformatic/config": "2.3.0",
23
+ "@platformatic/node": "2.3.0",
24
+ "@platformatic/utils": "2.3.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@fastify/vite": "^7.0.1",
@@ -34,8 +34,8 @@
34
34
  "typescript": "^5.5.4",
35
35
  "vite": "^5.4.0",
36
36
  "ws": "^8.18.0",
37
- "@platformatic/composer": "2.2.1",
38
- "@platformatic/service": "2.2.1"
37
+ "@platformatic/service": "2.3.0",
38
+ "@platformatic/composer": "2.3.0"
39
39
  },
40
40
  "scripts": {
41
41
  "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/vite/2.2.1.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/vite/2.3.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Vite Stackable",
5
5
  "type": "object",