vitrify 0.25.5 → 0.25.7

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/dist/app-urls.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // import { resolve } from 'import-meta-resolve'
2
2
  import { existsSync } from 'fs';
3
- import { fileURLToPath } from 'url';
3
+ import { fileURLToPath, pathToFileURL } from 'url';
4
4
  export const resolve = (packageName, base, counter = 0) => {
5
5
  const packageUrl = new URL(`./node_modules/${packageName}/`, base);
6
6
  if (existsSync(fileURLToPath(packageUrl))) {
@@ -17,7 +17,7 @@ export const getPkgJsonDir = (dir) => {
17
17
  }
18
18
  return getPkgJsonDir(new URL('..', dir));
19
19
  };
20
- export const getAppDir = (dir) => getPkgJsonDir(dir ?? new URL(`file://${process.cwd()}/`));
20
+ export const getAppDir = (dir) => getPkgJsonDir(dir ?? pathToFileURL(`${process.cwd()}/`));
21
21
  export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url));
22
22
  export const getCliViteDir = (cliDir) => new URL('src/vite/', cliDir);
23
23
  export const getSrcDir = (appDir) => new URL('src/', appDir);
package/dist/bin/cli.js CHANGED
@@ -73,7 +73,7 @@ cli
73
73
  ...args,
74
74
  outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
75
75
  });
76
- ({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
76
+ ({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).href));
77
77
  const { template, manifest, render, getRoutes, onAppRendered, onTemplateRendered } = await loadSSRAssets({
78
78
  mode: 'ssg',
79
79
  distDir: baseOutDir
package/dist/bin/dev.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { resolveConfig } from 'vite';
1
2
  import { baseConfig } from '../index.js';
2
3
  import fastify from 'fastify';
3
4
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
@@ -22,7 +23,8 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
22
23
  ssrMode = 'server';
23
24
  if (ssr === 'fastify')
24
25
  ssrMode = 'fastify';
25
- config = await baseConfig({
26
+ const wsPort = await getFirstOpenPort(24678);
27
+ const configBase = await baseConfig({
26
28
  framework,
27
29
  ssr: ssrMode,
28
30
  command: 'dev',
@@ -31,11 +33,23 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
31
33
  publicDir,
32
34
  base
33
35
  });
34
- const wsPort = await getFirstOpenPort(24678);
36
+ config = await resolveConfig({
37
+ ...configBase,
38
+ server: {
39
+ ...configBase.server,
40
+ host,
41
+ port
42
+ // hmr: {
43
+ // protocol: config.server?.https ? 'wss' : 'ws',
44
+ // port: wsPort
45
+ // }
46
+ }
47
+ }, 'serve');
35
48
  if (config.server?.https) {
36
49
  exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
37
50
  }
38
51
  const vitrifyDevServer = await (await import('vite')).createServer({
52
+ // @ts-expect-error configFile is defined more than once
39
53
  configFile: false,
40
54
  ...config,
41
55
  logLevel,
package/dist/bin/run.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import readline from 'readline';
3
3
  import { getAppDir, getCliDir, getProjectURLs } from '../app-urls.js';
4
+ import { fileURLToPath } from 'url';
4
5
  const rl = readline.createInterface({
5
6
  input: process.stdin,
6
7
  output: process.stdout
@@ -10,7 +11,7 @@ export async function run(filePath) {
10
11
  const appDir = getAppDir();
11
12
  const cliDir = getCliDir();
12
13
  const projectURLs = getProjectURLs(appDir, cliDir);
13
- const pkg = JSON.parse((await fs.readFile(projectURLs.cli('package.json'), 'utf-8')).toString());
14
+ const pkg = JSON.parse((await fs.readFile(fileURLToPath(projectURLs.cli('package.json')), 'utf-8')).toString());
14
15
  if (!run)
15
16
  throw new Error(`${filePath} does not have an export named run. Aborting...`);
16
17
  rl.question(`
@@ -1,6 +1,7 @@
1
1
  import { existsSync, promises as fs, mkdirSync } from 'fs';
2
2
  import { routesToPaths } from '../../helpers/routes.js';
3
3
  import { renderHtml } from './fastify-ssr-plugin.js';
4
+ import { fileURLToPath } from 'url';
4
5
  export const prerender = async ({ outDir, template, manifest, render, routes, onTemplateRendered }) => {
5
6
  const promises = [];
6
7
  const paths = routesToPaths(routes).filter((i) => !i.includes(':') && !i.includes('*'));
@@ -13,8 +14,8 @@ export const prerender = async ({ outDir, template, manifest, render, routes, on
13
14
  });
14
15
  for (const url of paths) {
15
16
  const directoryUrl = new URL(url.split('/').slice(0, -1).join('/'), `file://${outDir}`);
16
- if (!existsSync(directoryUrl.pathname)) {
17
- mkdirSync(directoryUrl.pathname, { recursive: true });
17
+ if (!existsSync(fileURLToPath(directoryUrl))) {
18
+ mkdirSync(fileURLToPath(directoryUrl), { recursive: true });
18
19
  }
19
20
  const filename = (url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html';
20
21
  console.log(`Generating ${filename}`);
package/dist/index.js CHANGED
@@ -43,7 +43,10 @@ const moduleChunks = {
43
43
  'vue-router',
44
44
  'pinia',
45
45
  '@pinia/colada',
46
- '@vue/devtools-api'
46
+ '@vue/devtools-api',
47
+ '@vueuse/core',
48
+ '@vueuse/metadata',
49
+ '@vueuse/shared'
47
50
  ],
48
51
  quasar: ['quasar'],
49
52
  atQuasar: ['@quasar']
@@ -149,7 +152,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
149
152
  fs.unlinkSync(configPath + '.js');
150
153
  }
151
154
  else {
152
- rawVitrifyConfig = (await import(fileURLToPath(new URL('vitrify.config.js', appDir)))).default;
155
+ rawVitrifyConfig = (await import(new URL('vitrify.config.js', appDir).href)).default;
153
156
  }
154
157
  if (typeof rawVitrifyConfig === 'function') {
155
158
  vitrifyConfig = await rawVitrifyConfig({ mode, command });
@@ -333,7 +336,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
333
336
  .replaceAll('-', '')
334
337
  .replaceAll('_', '')
335
338
  .replaceAll('+', '');
336
- return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppMounted.push(${varName});`;
339
+ return `import ${varName} from '${new URL(url, appDir).href}'; onAppMounted.push(${varName});`;
337
340
  })
338
341
  .join('\n')}
339
342
  export const onAppRendered = [${onAppRenderedHooks
@@ -349,7 +352,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
349
352
  .replaceAll('-', '')
350
353
  .replaceAll('_', '')
351
354
  .replaceAll('+', '');
352
- return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppRendered.push(${varName});`;
355
+ return `import ${varName} from '${new URL(url, appDir).href}'; onAppRendered.push(${varName});`;
353
356
  })
354
357
  .join('\n')}
355
358
  export const onTemplateRendered = [${onTemplateRenderedHooks
@@ -365,7 +368,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
365
368
  .replaceAll('-', '')
366
369
  .replaceAll('_', '')
367
370
  .replaceAll('+', '');
368
- return `import ${varName} from '${new URL(url, appDir).pathname}'; onTemplateRendered.push(${varName});`;
371
+ return `import ${varName} from '${new URL(url, appDir).href}'; onTemplateRendered.push(${varName});`;
369
372
  })
370
373
  .join('\n')}
371
374
  export const onAppCreated = [${OnAppCreatedHooks.map((fn) => `${String(fn)}`).join(', ')}]
@@ -379,7 +382,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
379
382
  .replaceAll('-', '')
380
383
  .replaceAll('_', '')
381
384
  .replaceAll('+', '');
382
- return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppCreated.push(${varName});`;
385
+ return `import ${varName} from '${new URL(url, appDir).href}'; onAppCreated.push(${varName});`;
383
386
  })
384
387
  .join('\n')}
385
388
  export const onSetup = []
@@ -393,7 +396,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
393
396
  .replaceAll('-', '')
394
397
  .replaceAll('_', '')
395
398
  .replaceAll('+', '');
396
- return `import ${varName} from '${new URL(url, appDir).pathname}'; onSetup.push(${varName});`;
399
+ return `import ${varName} from '${new URL(url, appDir).href}'; onSetup.push(${varName});`;
397
400
  })
398
401
  .join('\n')}`;
399
402
  }
@@ -480,14 +483,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
480
483
  default:
481
484
  entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir));
482
485
  }
483
- let entryScript;
484
- if (process.platform === 'win32') {
485
- const split = entry.split('node_modules');
486
- entryScript = `<script type="module" src="node_modules${split.at(-1)}"></script>`;
487
- }
488
- else {
489
- entryScript = `<script type="module" src="${entry}"></script>`;
490
- }
486
+ const entryScript = `<script type="module" src="${entry}"></script>`;
491
487
  html = appendToBody(entryScript, html);
492
488
  if (productName)
493
489
  html = addOrReplaceTitle(productName, html);
@@ -657,7 +653,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
657
653
  // environments: {
658
654
  // },
659
655
  server: {
660
- https: vitrifyConfig.server?.https,
656
+ // https: vitrifyConfig.server?.https,
661
657
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
662
658
  middlewareMode: ssr ? true : false,
663
659
  fs: {
@@ -1,4 +1,4 @@
1
- import type { LogLevel, ViteDevServer } from 'vite';
1
+ import { type LogLevel, type ViteDevServer, ResolvedConfig } from 'vite';
2
2
  import type { Server } from 'net';
3
3
  import type { FastifyInstance } from 'fastify';
4
4
  declare module 'vite' {
@@ -28,6 +28,6 @@ export declare function createServer({ port, logLevel, ssr, framework, host, app
28
28
  }): Promise<{
29
29
  app: FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> | undefined;
30
30
  server: Server;
31
- config: import("vite").ResolvedConfig;
31
+ config: ResolvedConfig;
32
32
  vite: ViteDevServer;
33
33
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.25.5",
3
+ "version": "0.25.7",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Vite as your Full Stack development tool",
@@ -1,6 +1,6 @@
1
1
  // import { resolve } from 'import-meta-resolve'
2
2
  import { existsSync } from 'fs'
3
- import { fileURLToPath } from 'url'
3
+ import { fileURLToPath, pathToFileURL } from 'url'
4
4
 
5
5
  export const resolve = (packageName: string, base: URL, counter = 0): URL => {
6
6
  const packageUrl = new URL(`./node_modules/${packageName}/`, base)
@@ -20,7 +20,7 @@ export const getPkgJsonDir = (dir: URL): URL => {
20
20
  return getPkgJsonDir(new URL('..', dir))
21
21
  }
22
22
  export const getAppDir = (dir?: URL) =>
23
- getPkgJsonDir(dir ?? new URL(`file://${process.cwd()}/`))
23
+ getPkgJsonDir(dir ?? pathToFileURL(`${process.cwd()}/`))
24
24
  export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url))
25
25
  export const getCliViteDir = (cliDir: URL) => new URL('src/vite/', cliDir)
26
26
  export const getSrcDir = (appDir: URL) => new URL('src/', appDir)
@@ -30,7 +30,6 @@ cli
30
30
  } else {
31
31
  appDir = getAppDir()
32
32
  }
33
-
34
33
  const baseOutDir =
35
34
  parsePath(options.outDir, appDir) || new URL('dist/', appDir)
36
35
 
@@ -86,7 +85,7 @@ cli
86
85
  outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
87
86
  })
88
87
  ;({ prerender } = await import(
89
- new URL('ssr/server/prerender.mjs', baseOutDir).pathname
88
+ new URL('ssr/server/prerender.mjs', baseOutDir).href
90
89
  ))
91
90
 
92
91
  const {
@@ -1,4 +1,10 @@
1
- import type { LogLevel, InlineConfig, ViteDevServer } from 'vite'
1
+ import {
2
+ type LogLevel,
3
+ type InlineConfig,
4
+ type ViteDevServer,
5
+ resolveConfig,
6
+ ResolvedConfig
7
+ } from 'vite'
2
8
  import { baseConfig } from '../index.js'
3
9
  import type { Server } from 'net'
4
10
  import fastify from 'fastify'
@@ -53,11 +59,14 @@ export async function createVitrifyDevServer({
53
59
  )
54
60
 
55
61
  if (!appDir) appDir = getAppDir()
56
- let config: InlineConfig = {}
62
+ let config: InlineConfig | ResolvedConfig = {}
57
63
  let ssrMode: 'server' | 'fastify' | undefined
58
64
  if (ssr === 'ssr') ssrMode = 'server'
59
65
  if (ssr === 'fastify') ssrMode = 'fastify'
60
- config = await baseConfig({
66
+
67
+ const wsPort = await getFirstOpenPort(24678)
68
+
69
+ const configBase = await baseConfig({
61
70
  framework,
62
71
  ssr: ssrMode,
63
72
  command: 'dev',
@@ -66,8 +75,22 @@ export async function createVitrifyDevServer({
66
75
  publicDir,
67
76
  base
68
77
  })
78
+ config = await resolveConfig(
79
+ {
80
+ ...configBase,
81
+ server: {
82
+ ...configBase.server,
83
+ host,
84
+ port
85
+ // hmr: {
86
+ // protocol: config.server?.https ? 'wss' : 'ws',
87
+ // port: wsPort
88
+ // }
89
+ }
90
+ },
91
+ 'serve'
92
+ )
69
93
 
70
- const wsPort = await getFirstOpenPort(24678)
71
94
  if (config.server?.https) {
72
95
  exitLogs.push(
73
96
  `[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
@@ -77,6 +100,7 @@ export async function createVitrifyDevServer({
77
100
  const vitrifyDevServer = await (
78
101
  await import('vite')
79
102
  ).createServer({
103
+ // @ts-expect-error configFile is defined more than once
80
104
  configFile: false,
81
105
  ...config,
82
106
  logLevel,
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from 'fs'
2
2
  import readline from 'readline'
3
3
  import { getAppDir, getCliDir, getProjectURLs } from '../app-urls.js'
4
+ import { fileURLToPath } from 'url'
4
5
 
5
6
  const rl = readline.createInterface({
6
7
  input: process.stdin,
@@ -20,7 +21,9 @@ export async function run(filePath: string) {
20
21
  const cliDir = getCliDir()
21
22
  const projectURLs = getProjectURLs(appDir, cliDir)
22
23
  const pkg = JSON.parse(
23
- (await fs.readFile(projectURLs.cli('package.json'), 'utf-8')).toString()
24
+ (
25
+ await fs.readFile(fileURLToPath(projectURLs.cli('package.json')), 'utf-8')
26
+ ).toString()
24
27
  )
25
28
 
26
29
  if (!run)
@@ -3,6 +3,7 @@ import type { OnTemplateRenderedHook } from 'src/node/vitrify-config.js'
3
3
  import { routesToPaths } from '../../helpers/routes.js'
4
4
  import { renderHtml } from './fastify-ssr-plugin.js'
5
5
  import { type RouteRecordRaw } from 'vue-router'
6
+ import { fileURLToPath } from 'url'
6
7
 
7
8
  export const prerender = async ({
8
9
  outDir,
@@ -36,8 +37,8 @@ export const prerender = async ({
36
37
  url.split('/').slice(0, -1).join('/'),
37
38
  `file://${outDir}`
38
39
  )
39
- if (!existsSync(directoryUrl.pathname)) {
40
- mkdirSync(directoryUrl.pathname, { recursive: true })
40
+ if (!existsSync(fileURLToPath(directoryUrl))) {
41
+ mkdirSync(fileURLToPath(directoryUrl), { recursive: true })
41
42
  }
42
43
 
43
44
  const filename =
package/src/node/index.ts CHANGED
@@ -73,7 +73,10 @@ const moduleChunks = {
73
73
  'vue-router',
74
74
  'pinia',
75
75
  '@pinia/colada',
76
- '@vue/devtools-api'
76
+ '@vue/devtools-api',
77
+ '@vueuse/core',
78
+ '@vueuse/metadata',
79
+ '@vueuse/shared'
77
80
  ],
78
81
  quasar: ['quasar'],
79
82
  atQuasar: ['@quasar']
@@ -220,7 +223,7 @@ export const baseConfig = async ({
220
223
  fs.unlinkSync(configPath + '.js')
221
224
  } else {
222
225
  rawVitrifyConfig = (
223
- await import(fileURLToPath(new URL('vitrify.config.js', appDir)))
226
+ await import(new URL('vitrify.config.js', appDir).href)
224
227
  ).default
225
228
  }
226
229
  if (typeof rawVitrifyConfig === 'function') {
@@ -424,7 +427,7 @@ export const baseConfig = async ({
424
427
  .replaceAll('+', '')
425
428
 
426
429
  return `import ${varName} from '${
427
- new URL(url, appDir).pathname
430
+ new URL(url, appDir).href
428
431
  }'; onAppMounted.push(${varName});`
429
432
  })
430
433
  .join('\n')}
@@ -443,7 +446,7 @@ export const baseConfig = async ({
443
446
  .replaceAll('+', '')
444
447
 
445
448
  return `import ${varName} from '${
446
- new URL(url, appDir).pathname
449
+ new URL(url, appDir).href
447
450
  }'; onAppRendered.push(${varName});`
448
451
  })
449
452
  .join('\n')}
@@ -462,7 +465,7 @@ export const baseConfig = async ({
462
465
  .replaceAll('+', '')
463
466
 
464
467
  return `import ${varName} from '${
465
- new URL(url, appDir).pathname
468
+ new URL(url, appDir).href
466
469
  }'; onTemplateRendered.push(${varName});`
467
470
  })
468
471
  .join('\n')}
@@ -481,7 +484,7 @@ export const baseConfig = async ({
481
484
  .replaceAll('+', '')
482
485
 
483
486
  return `import ${varName} from '${
484
- new URL(url, appDir).pathname
487
+ new URL(url, appDir).href
485
488
  }'; onAppCreated.push(${varName});`
486
489
  })
487
490
  .join('\n')}
@@ -498,7 +501,7 @@ export const baseConfig = async ({
498
501
  .replaceAll('+', '')
499
502
 
500
503
  return `import ${varName} from '${
501
- new URL(url, appDir).pathname
504
+ new URL(url, appDir).href
502
505
  }'; onSetup.push(${varName});`
503
506
  })
504
507
  .join('\n')}`
@@ -597,15 +600,7 @@ export const baseConfig = async ({
597
600
  default:
598
601
  entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir))
599
602
  }
600
- let entryScript
601
- if (process.platform === 'win32') {
602
- const split = entry.split('node_modules')
603
- entryScript = `<script type="module" src="node_modules${split.at(
604
- -1
605
- )}"></script>`
606
- } else {
607
- entryScript = `<script type="module" src="${entry}"></script>`
608
- }
603
+ const entryScript = `<script type="module" src="${entry}"></script>`
609
604
  html = appendToBody(entryScript, html)
610
605
  if (productName) html = addOrReplaceTitle(productName, html)
611
606
  return html
@@ -790,7 +785,7 @@ export const baseConfig = async ({
790
785
  // environments: {
791
786
  // },
792
787
  server: {
793
- https: vitrifyConfig.server?.https,
788
+ // https: vitrifyConfig.server?.https,
794
789
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
795
790
  middlewareMode: ssr ? true : false,
796
791
  fs: {