vitrify 0.11.7 → 0.11.8

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,17 +1,18 @@
1
1
  // import { resolve } from 'import-meta-resolve'
2
2
  import { existsSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
3
4
  export const resolve = (packageName, base, counter = 0) => {
4
5
  const packageUrl = new URL(`./node_modules/${packageName}/`, base);
5
- if (existsSync(packageUrl.pathname)) {
6
+ if (existsSync(fileURLToPath(packageUrl))) {
6
7
  return new URL('./', packageUrl);
7
8
  }
8
9
  if (counter < 10)
9
10
  return resolve(packageName, new URL('../', base), counter + 1);
10
- throw new Error(`Package ${packageName} not found in ${base.pathname}.`);
11
+ throw new Error(`Package ${packageName} not found in ${fileURLToPath(base)}.`);
11
12
  };
12
13
  export const getPkgJsonDir = (dir) => {
13
14
  const pkgJsonPath = new URL('package.json', dir);
14
- if (existsSync(pkgJsonPath.pathname)) {
15
+ if (existsSync(fileURLToPath(pkgJsonPath))) {
15
16
  return new URL('./', pkgJsonPath);
16
17
  }
17
18
  return getPkgJsonDir(new URL('..', dir));
package/dist/bin/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac';
3
+ import { fileURLToPath } from 'url';
3
4
  import { getAppDir, parsePath } from '../app-urls.js';
4
5
  import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
5
6
  const cli = cac('vitrify');
@@ -37,47 +38,45 @@ cli
37
38
  case 'csr':
38
39
  await build({
39
40
  ...args,
40
- outDir: new URL('csr/', baseOutDir).pathname
41
+ outDir: fileURLToPath(new URL('csr/', baseOutDir))
41
42
  });
42
43
  break;
43
44
  case 'fastify':
44
45
  await build({
45
46
  ssr: 'fastify',
46
47
  ...args,
47
- outDir: new URL('server/', baseOutDir).pathname
48
+ outDir: fileURLToPath(new URL('server/', baseOutDir))
48
49
  });
49
50
  break;
50
51
  case 'ssr':
51
52
  await build({
52
53
  ssr: 'client',
53
54
  ...args,
54
- outDir: new URL('ssr/client/', baseOutDir).pathname
55
+ outDir: fileURLToPath(new URL('ssr/client/', baseOutDir))
55
56
  });
56
57
  await build({
57
58
  ssr: 'server',
58
59
  ...args,
59
- outDir: new URL('ssr/server/', baseOutDir).pathname
60
+ outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
60
61
  });
61
62
  break;
62
63
  case 'ssg':
63
64
  await build({
64
65
  ssr: 'client',
65
66
  ...args,
66
- outDir: new URL('static/', baseOutDir).pathname
67
+ outDir: fileURLToPath(new URL('static/', baseOutDir))
67
68
  });
68
69
  await build({
69
70
  ssr: 'server',
70
71
  ...args,
71
- outDir: new URL('ssr/server/', baseOutDir).pathname
72
+ outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
72
73
  });
73
- ({ prerender, onRendered } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
74
+ ({ prerender, onRendered } = await import(fileURLToPath(new URL('ssr/server/prerender.mjs', baseOutDir))));
74
75
  prerender({
75
- outDir: new URL('static/', baseOutDir).pathname,
76
- templatePath: new URL('static/index.html', baseOutDir).pathname,
77
- manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
78
- .pathname,
79
- entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
80
- .pathname,
76
+ outDir: fileURLToPath(new URL('static/', baseOutDir)),
77
+ templatePath: fileURLToPath(new URL('static/index.html', baseOutDir)),
78
+ manifestPath: fileURLToPath(new URL('static/ssr-manifest.json', baseOutDir)),
79
+ entryServerPath: fileURLToPath(new URL('ssr/server/entry-server.mjs', baseOutDir)),
81
80
  onRendered
82
81
  });
83
82
  break;
@@ -102,8 +101,10 @@ cli
102
101
  const { createServer } = await import('./dev.js');
103
102
  const cwd = (await import('../app-urls.js')).getCwd();
104
103
  let app;
105
- const appPath = parsePath(options.app, cwd)?.pathname;
106
- if (appPath) {
104
+ const appURL = parsePath(options.app, cwd);
105
+ let appPath;
106
+ if (appURL) {
107
+ appPath = fileURLToPath(appURL);
107
108
  app = await import(appPath);
108
109
  }
109
110
  switch (options.mode) {
@@ -158,7 +159,7 @@ cli.command('test').action(async (options) => {
158
159
  cli.command('run <file>').action(async (file, options) => {
159
160
  const { run } = await import('./run.js');
160
161
  const filePath = new URL(file, `file://${process.cwd()}/`);
161
- await run(filePath.pathname);
162
+ await run(fileURLToPath(filePath));
162
163
  });
163
164
  // Default
164
165
  cli.command('').action((command, options) => {
package/dist/bin/dev.js CHANGED
@@ -4,6 +4,7 @@ import fastify from 'fastify';
4
4
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
5
5
  import isPortReachable from 'is-port-reachable';
6
6
  import { exitLogs } from '../helpers/logger.js';
7
+ import { fileURLToPath } from 'url';
7
8
  const getFirstOpenPort = async (portNumber) => {
8
9
  if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
9
10
  return portNumber;
@@ -54,9 +55,9 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
54
55
  strict: false,
55
56
  allow: [
56
57
  searchForWorkspaceRoot(process.cwd()),
57
- searchForWorkspaceRoot(appDir.pathname),
58
- searchForWorkspaceRoot(cliDir.pathname),
59
- appDir.pathname
58
+ searchForWorkspaceRoot(fileURLToPath(appDir)),
59
+ searchForWorkspaceRoot(fileURLToPath(cliDir)),
60
+ fileURLToPath(appDir)
60
61
  ]
61
62
  },
62
63
  watch: {
@@ -97,8 +98,8 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
97
98
  console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
98
99
  if (ssr) {
99
100
  const entryUrl = ssr === 'fastify'
100
- ? new URL('src/vite/fastify/entry.ts', cliDir).pathname
101
- : new URL(`src/vite/${framework}/ssr/app.ts`, cliDir).pathname;
101
+ ? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
102
+ : fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
102
103
  ({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl));
103
104
  const app = fastify({
104
105
  logger: {
package/dist/bin/test.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { startVitest } from 'vitest/node';
2
2
  import { baseConfig } from '../index.js';
3
+ import { fileURLToPath } from 'url';
3
4
  export async function test(opts) {
4
5
  const config = await baseConfig({
5
6
  appDir: opts.appDir,
@@ -7,8 +8,8 @@ export async function test(opts) {
7
8
  mode: 'development'
8
9
  });
9
10
  await startVitest('test', [], {
10
- root: opts.appDir.pathname,
11
- dir: opts.appDir.pathname,
11
+ root: fileURLToPath(opts.appDir),
12
+ dir: fileURLToPath(opts.appDir),
12
13
  globals: true,
13
14
  environment: 'happy-dom'
14
15
  }, config);
@@ -1,4 +1,5 @@
1
1
  import fastifyStatic from '@fastify/static';
2
+ import { fileURLToPath } from 'url';
2
3
  const fastifyCsrPlugin = async (fastify, options, done) => {
3
4
  options.vitrifyDir =
4
5
  options.vitrifyDir || (await import('vitrify')).vitrifyDir;
@@ -28,7 +29,7 @@ const fastifyCsrPlugin = async (fastify, options, done) => {
28
29
  else {
29
30
  options.appDir = options.appDir || new URL('../../..', import.meta.url);
30
31
  fastify.register(fastifyStatic, {
31
- root: new URL('./dist/csr', options.appDir).pathname,
32
+ root: fileURLToPath(new URL('./dist/csr', options.appDir)),
32
33
  wildcard: false,
33
34
  index: false,
34
35
  prefix: options.baseUrl
@@ -1,5 +1,6 @@
1
1
  import fastifyStatic from '@fastify/static';
2
2
  import { readFileSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
3
4
  import { addOrReplaceAppDiv, appendToBody, appendToHead } from '../../helpers/utils.js';
4
5
  const fastifySsrPlugin = async (fastify, options, done) => {
5
6
  options.baseUrl = options.baseUrl || '/';
@@ -12,11 +13,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
12
13
  options.vitrifyDir =
13
14
  options.vitrifyDir || (await import('vitrify')).vitrifyDir;
14
15
  const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
15
- // if (!options.vitrifyDir)
16
- // throw new Error('Option vitrifyDir cannot be undefined')
17
- // if (!options.vite) throw new Error('Option vite cannot be undefined')
18
- // const { resolve } = await import('import-meta-resolve')
19
- // const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
20
16
  options.appDir = options.appDir || new URL('../../..', import.meta.url);
21
17
  const { createVitrifyDevServer } = await import('vitrify/dev');
22
18
  const vite = await createVitrifyDevServer({
@@ -26,37 +22,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
26
22
  base: options.baseUrl,
27
23
  host: options.host
28
24
  });
29
- // const { createServer, searchForWorkspaceRoot } = await import('vite')
30
- // const { baseConfig } = await import('vitrify')
31
- // const cliDir = options.vitrifyDir
32
- // const config = await baseConfig({
33
- // ssr: 'server',
34
- // command: 'dev',
35
- // mode: 'development',
36
- // appDir: options.appDir,
37
- // publicDir: options.publicDir || new URL('public', options.appDir)
38
- // })
39
- // config.server = {
40
- // middlewareMode: true,
41
- // fs: {
42
- // allow: [
43
- // searchForWorkspaceRoot(process.cwd()),
44
- // searchForWorkspaceRoot(options.appDir.pathname),
45
- // searchForWorkspaceRoot(cliDir.pathname)
46
- // // appDir.pathname,
47
- // ]
48
- // },
49
- // watch: {
50
- // // During tests we edit the files too fast and sometimes chokidar
51
- // // misses change events, so enforce polling for consistency
52
- // usePolling: true,
53
- // interval: 100
54
- // }
55
- // }
56
- // const vite = await createServer({
57
- // configFile: false,
58
- // ...config
59
- // })
60
25
  if (!('use' in fastify)) {
61
26
  const middie = (await import('@fastify/middie')).default;
62
27
  // @ts-ignore
@@ -74,7 +39,7 @@ const fastifySsrPlugin = async (fastify, options, done) => {
74
39
  };
75
40
  let template = readFileSync(new URL('index.html', frameworkDir)).toString();
76
41
  template = await vite.transformIndexHtml(url, template);
77
- const entryUrl = new URL('ssr/entry-server.ts', frameworkDir).pathname;
42
+ const entryUrl = fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir));
78
43
  const render = (await vite.ssrLoadModule(entryUrl)).render;
79
44
  let manifest;
80
45
  // TODO: https://github.com/vitejs/vite/issues/2282
@@ -133,7 +98,7 @@ const fastifySsrPlugin = async (fastify, options, done) => {
133
98
  else {
134
99
  options.appDir = options.appDir || new URL('../../..', import.meta.url);
135
100
  fastify.register(fastifyStatic, {
136
- root: new URL('./dist/ssr/client', options.appDir).pathname,
101
+ root: fileURLToPath(new URL('./dist/ssr/client', options.appDir)),
137
102
  wildcard: false,
138
103
  index: false,
139
104
  prefix: options.baseUrl
@@ -146,9 +111,9 @@ const fastifySsrPlugin = async (fastify, options, done) => {
146
111
  res,
147
112
  provide
148
113
  };
149
- const template = readFileSync(new URL('./dist/ssr/client/index.html', options.appDir).pathname).toString();
114
+ const template = readFileSync(fileURLToPath(new URL('./dist/ssr/client/index.html', options.appDir))).toString();
150
115
  const manifest = JSON.parse(readFileSync(new URL('./dist/ssr/client/ssr-manifest.json', options.appDir)).toString());
151
- const render = (await import(new URL('./dist/ssr/server/entry-server.mjs', options.appDir).pathname)).render;
116
+ const render = (await import(fileURLToPath(new URL('./dist/ssr/server/entry-server.mjs', options.appDir)))).render;
152
117
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
153
118
  if (!ssrContext.initialState)
154
119
  ssrContext.initialState = {};
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { pathToFileURL } from 'url';
8
8
  import { readFileSync } from 'fs';
9
9
  import builtinModules from 'builtin-modules';
10
10
  import { visualizer } from 'rollup-plugin-visualizer';
11
+ import { fileURLToPath } from 'url';
11
12
  import { resolve } from './app-urls.js';
12
13
  import { addOrReplaceTitle, appendToBody } from './helpers/utils.js';
13
14
  import Components from 'unplugin-vue-components/vite';
@@ -158,15 +159,15 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
158
159
  publicDir = new URL('public/', appDir);
159
160
  let vitrifyConfig;
160
161
  try {
161
- if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
162
- const configPath = new URL('vitrify.config.ts', appDir).pathname;
163
- const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
162
+ if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
163
+ const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir));
164
+ const bundledConfig = await bundleConfigFile(fileURLToPath(new URL('vitrify.config.ts', appDir)));
164
165
  fs.writeFileSync(configPath + '.js', bundledConfig.code);
165
166
  vitrifyConfig = (await import(configPath + '.js')).default;
166
167
  fs.unlinkSync(configPath + '.js');
167
168
  }
168
169
  else {
169
- vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
170
+ vitrifyConfig = (await import(fileURLToPath(new URL('vitrify.config.js', appDir)))).default;
170
171
  }
171
172
  if (typeof vitrifyConfig === 'function')
172
173
  vitrifyConfig = await vitrifyConfig({ mode, command });
@@ -183,7 +184,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
183
184
  const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
184
185
  await (async () => {
185
186
  for (const val of localPackages) {
186
- const pkg = resolvePackageData(val, appDir.pathname);
187
+ const pkg = resolvePackageData(val, fileURLToPath(appDir));
187
188
  if (pkg)
188
189
  packageUrls[val] = new URL(`file://${pkg.dir}/`);
189
190
  }
@@ -197,7 +198,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
197
198
  if (!productName) {
198
199
  try {
199
200
  ;
200
- ({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
201
+ ({ productName } = JSON.parse(readFileSync(fileURLToPath(new URL('package.json', appDir)), {
201
202
  encoding: 'utf-8'
202
203
  })));
203
204
  if (!productName)
@@ -327,13 +328,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
327
328
  export const onSetup = []
328
329
  ${onSetupFiles
329
330
  .map((url, index) => {
330
- const varName = url.pathname
331
+ const varName = fileURLToPath(url)
331
332
  .replaceAll('/', '')
332
333
  .replaceAll('.', '')
333
334
  .replaceAll('-', '')
334
335
  .replaceAll('_', '')
335
336
  .replaceAll('+', '');
336
- return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`;
337
+ return `import ${varName} from '${fileURLToPath(url)}'; onSetup.push(${varName})`;
337
338
  })
338
339
  .join('\n')}`;
339
340
  }
@@ -381,13 +382,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
381
382
  case 'ssg':
382
383
  case 'server':
383
384
  case 'client':
384
- entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
385
+ entry = fileURLToPath(new URL('ssr/entry-client.ts', frameworkDir));
385
386
  break;
386
387
  case 'fastify':
387
- entry = new URL('entry.ts', fastifyDir).pathname;
388
+ entry = fileURLToPath(new URL('entry.ts', fastifyDir));
388
389
  break;
389
390
  default:
390
- entry = new URL('csr/entry.ts', frameworkDir).pathname;
391
+ entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir));
391
392
  }
392
393
  const entryScript = `<script type="module" src="${entry}"></script>`;
393
394
  // html = html.replace('<!--entry-script-->', entryScript)
@@ -420,22 +421,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
420
421
  plugins.push(visualizer());
421
422
  }
422
423
  const alias = [
423
- { find: 'src', replacement: srcDir.pathname },
424
- { find: 'app', replacement: appDir.pathname },
425
- { find: 'cwd', replacement: cwd.pathname },
426
- { find: 'boot', replacement: new URL('boot/', srcDir).pathname },
427
- { find: 'assets', replacement: new URL('assets/', srcDir).pathname },
424
+ { find: 'src', replacement: fileURLToPath(srcDir) },
425
+ { find: 'app', replacement: fileURLToPath(appDir) },
426
+ { find: 'cwd', replacement: fileURLToPath(cwd) },
427
+ { find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
428
+ { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
428
429
  // ...Object.entries(packageUrls).map(([key, value]) => ({
429
430
  // find: key,
430
431
  // replacement: value.pathname
431
432
  // }))
432
433
  {
433
434
  find: new RegExp('^vue$'),
434
- replacement: new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']).pathname
435
+ replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
435
436
  },
436
437
  {
437
438
  find: new RegExp('^vue-router$'),
438
- replacement: new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']).pathname
439
+ replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
439
440
  }
440
441
  ];
441
442
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
@@ -443,7 +444,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
443
444
  if (command === 'test')
444
445
  alias.push({
445
446
  find: 'vitest',
446
- replacement: new URL(await resolve('vitest', cliDir)).pathname
447
+ replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
447
448
  });
448
449
  let rollupOptions = {};
449
450
  let noExternal = [
@@ -454,9 +455,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
454
455
  rollupOptions = {
455
456
  ...rollupOptions,
456
457
  input: [
457
- new URL('ssr/entry-server.ts', frameworkDir).pathname,
458
- new URL('ssr/prerender.ts', frameworkDir).pathname,
459
- new URL('ssr/server.ts', frameworkDir).pathname
458
+ fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
459
+ fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
460
+ fileURLToPath(new URL('ssr/server.ts', frameworkDir))
460
461
  ],
461
462
  external,
462
463
  output: {
@@ -475,7 +476,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
475
476
  else if (ssr === 'fastify') {
476
477
  rollupOptions = {
477
478
  ...rollupOptions,
478
- input: [new URL('server.ts', fastifyDir).pathname],
479
+ input: [fileURLToPath(new URL('server.ts', fastifyDir))],
479
480
  external,
480
481
  output: {
481
482
  minifyInternalExports: false,
@@ -504,10 +505,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
504
505
  };
505
506
  }
506
507
  const config = {
507
- root: appDir.pathname,
508
- publicDir: publicDir.pathname,
508
+ root: fileURLToPath(appDir),
509
+ publicDir: fileURLToPath(publicDir),
509
510
  base,
510
- envDir: appDir.pathname,
511
+ envDir: fileURLToPath(appDir),
511
512
  vitrify: {
512
513
  productName,
513
514
  urls: {
@@ -1,4 +1,5 @@
1
1
  import { resolvePackageData } from 'vite';
2
+ import { fileURLToPath } from 'url';
2
3
  export const injectSsrContext = (html, ssrContext) => html
3
4
  .replace(/(<html[^>]*)(>)/i, (found, start, end) => {
4
5
  let matches;
@@ -51,7 +52,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
51
52
  // const localPackages: string[] = []
52
53
  await (async () => {
53
54
  for (const val of localPackages) {
54
- const pkg = resolvePackageData(val, config.vitrify.urls.app.pathname);
55
+ const pkg = resolvePackageData(val, fileURLToPath(config.vitrify.urls.app));
55
56
  if (pkg)
56
57
  urls.packages[val] = new URL(`file://${pkg.dir}/`);
57
58
  }
@@ -121,7 +122,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
121
122
  alias: [
122
123
  {
123
124
  find: 'quasar/src/',
124
- replacement: new URL('./src/', config.vitrify.urls.packages.quasar).pathname
125
+ replacement: fileURLToPath(new URL('./src/', config.vitrify.urls.packages.quasar))
125
126
  }
126
127
  ]
127
128
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.11.7",
3
+ "version": "0.11.8",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Vite as your Full Stack development tool",
@@ -1,19 +1,20 @@
1
1
  // import { resolve } from 'import-meta-resolve'
2
2
  import { existsSync } from 'fs'
3
+ import { fileURLToPath } from 'url'
3
4
 
4
5
  export const resolve = (packageName: string, base: URL, counter = 0): URL => {
5
6
  const packageUrl = new URL(`./node_modules/${packageName}/`, base)
6
- if (existsSync(packageUrl.pathname)) {
7
+ if (existsSync(fileURLToPath(packageUrl))) {
7
8
  return new URL('./', packageUrl)
8
9
  }
9
10
  if (counter < 10)
10
11
  return resolve(packageName, new URL('../', base), counter + 1)
11
- throw new Error(`Package ${packageName} not found in ${base.pathname}.`)
12
+ throw new Error(`Package ${packageName} not found in ${fileURLToPath(base)}.`)
12
13
  }
13
14
 
14
15
  export const getPkgJsonDir = (dir: URL): URL => {
15
16
  const pkgJsonPath = new URL('package.json', dir)
16
- if (existsSync(pkgJsonPath.pathname)) {
17
+ if (existsSync(fileURLToPath(pkgJsonPath))) {
17
18
  return new URL('./', pkgJsonPath)
18
19
  }
19
20
  return getPkgJsonDir(new URL('..', dir))
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac'
3
+ import { fileURLToPath } from 'url'
3
4
  import { getAppDir, parsePath } from '../app-urls.js'
4
5
  import { printHttpServerUrls, exitLogs } from '../helpers/logger.js'
5
6
  import type { ResolvedConfig } from 'vite'
@@ -48,50 +49,52 @@ cli
48
49
  case 'csr':
49
50
  await build({
50
51
  ...args,
51
- outDir: new URL('csr/', baseOutDir).pathname
52
+ outDir: fileURLToPath(new URL('csr/', baseOutDir))
52
53
  })
53
54
  break
54
55
  case 'fastify':
55
56
  await build({
56
57
  ssr: 'fastify',
57
58
  ...args,
58
- outDir: new URL('server/', baseOutDir).pathname
59
+ outDir: fileURLToPath(new URL('server/', baseOutDir))
59
60
  })
60
61
  break
61
62
  case 'ssr':
62
63
  await build({
63
64
  ssr: 'client',
64
65
  ...args,
65
- outDir: new URL('ssr/client/', baseOutDir).pathname
66
+ outDir: fileURLToPath(new URL('ssr/client/', baseOutDir))
66
67
  })
67
68
  await build({
68
69
  ssr: 'server',
69
70
  ...args,
70
- outDir: new URL('ssr/server/', baseOutDir).pathname
71
+ outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
71
72
  })
72
73
  break
73
74
  case 'ssg':
74
75
  await build({
75
76
  ssr: 'client',
76
77
  ...args,
77
- outDir: new URL('static/', baseOutDir).pathname
78
+ outDir: fileURLToPath(new URL('static/', baseOutDir))
78
79
  })
79
80
  await build({
80
81
  ssr: 'server',
81
82
  ...args,
82
- outDir: new URL('ssr/server/', baseOutDir).pathname
83
+ outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
83
84
  })
84
85
  ;({ prerender, onRendered } = await import(
85
- new URL('ssr/server/prerender.mjs', baseOutDir).pathname
86
+ fileURLToPath(new URL('ssr/server/prerender.mjs', baseOutDir))
86
87
  ))
87
88
 
88
89
  prerender({
89
- outDir: new URL('static/', baseOutDir).pathname,
90
- templatePath: new URL('static/index.html', baseOutDir).pathname,
91
- manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
92
- .pathname,
93
- entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
94
- .pathname,
90
+ outDir: fileURLToPath(new URL('static/', baseOutDir)),
91
+ templatePath: fileURLToPath(new URL('static/index.html', baseOutDir)),
92
+ manifestPath: fileURLToPath(
93
+ new URL('static/ssr-manifest.json', baseOutDir)
94
+ ),
95
+ entryServerPath: fileURLToPath(
96
+ new URL('ssr/server/entry-server.mjs', baseOutDir)
97
+ ),
95
98
  onRendered
96
99
  })
97
100
  break
@@ -121,8 +124,10 @@ cli
121
124
  const { createServer } = await import('./dev.js')
122
125
  const cwd = (await import('../app-urls.js')).getCwd()
123
126
  let app
124
- const appPath = parsePath(options.app, cwd)?.pathname
125
- if (appPath) {
127
+ const appURL = parsePath(options.app, cwd)
128
+ let appPath: string
129
+ if (appURL) {
130
+ appPath = fileURLToPath(appURL)
126
131
  app = await import(appPath)
127
132
  }
128
133
 
@@ -176,7 +181,7 @@ cli.command('test').action(async (options) => {
176
181
  cli.command('run <file>').action(async (file, options) => {
177
182
  const { run } = await import('./run.js')
178
183
  const filePath = new URL(file, `file://${process.cwd()}/`)
179
- await run(filePath.pathname)
184
+ await run(fileURLToPath(filePath))
180
185
  })
181
186
 
182
187
  // Default
@@ -8,6 +8,7 @@ import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
8
8
  import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
9
9
  import isPortReachable from 'is-port-reachable'
10
10
  import { exitLogs } from '../helpers/logger.js'
11
+ import { fileURLToPath } from 'url'
11
12
 
12
13
  const getFirstOpenPort = async (portNumber: number): Promise<number> => {
13
14
  if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
@@ -84,9 +85,9 @@ export async function createVitrifyDevServer({
84
85
  strict: false, // https://github.com/vitejs/vite/issues/8175
85
86
  allow: [
86
87
  searchForWorkspaceRoot(process.cwd()),
87
- searchForWorkspaceRoot(appDir.pathname),
88
- searchForWorkspaceRoot(cliDir.pathname),
89
- appDir.pathname
88
+ searchForWorkspaceRoot(fileURLToPath(appDir)),
89
+ searchForWorkspaceRoot(fileURLToPath(cliDir)),
90
+ fileURLToPath(appDir)
90
91
  ]
91
92
  },
92
93
  watch: {
@@ -154,8 +155,8 @@ export async function createServer({
154
155
  if (ssr) {
155
156
  const entryUrl =
156
157
  ssr === 'fastify'
157
- ? new URL('src/vite/fastify/entry.ts', cliDir).pathname
158
- : new URL(`src/vite/${framework}/ssr/app.ts`, cliDir).pathname
158
+ ? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
159
+ : fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
159
160
 
160
161
  ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
161
162
  const app = fastify({
@@ -1,5 +1,6 @@
1
1
  import { startVitest } from 'vitest/node'
2
2
  import { baseConfig } from '../index.js'
3
+ import { fileURLToPath } from 'url'
3
4
  export async function test(opts: { appDir: URL }) {
4
5
  const config = await baseConfig({
5
6
  appDir: opts.appDir,
@@ -11,8 +12,8 @@ export async function test(opts: { appDir: URL }) {
11
12
  'test',
12
13
  [],
13
14
  {
14
- root: opts.appDir.pathname,
15
- dir: opts.appDir.pathname,
15
+ root: fileURLToPath(opts.appDir),
16
+ dir: fileURLToPath(opts.appDir),
16
17
 
17
18
  globals: true,
18
19
  environment: 'happy-dom'
@@ -5,7 +5,7 @@ import type {
5
5
  } from 'fastify'
6
6
  import fastifyStatic from '@fastify/static'
7
7
  import type { ViteDevServer } from 'vite'
8
-
8
+ import { fileURLToPath } from 'url'
9
9
  export interface FastifySsrOptions {
10
10
  baseUrl?: string
11
11
  provide?: (
@@ -58,7 +58,7 @@ const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
58
58
  } else {
59
59
  options.appDir = options.appDir || new URL('../../..', import.meta.url)
60
60
  fastify.register(fastifyStatic, {
61
- root: new URL('./dist/csr', options.appDir).pathname,
61
+ root: fileURLToPath(new URL('./dist/csr', options.appDir)),
62
62
  wildcard: false,
63
63
  index: false,
64
64
  prefix: options.baseUrl
@@ -5,6 +5,7 @@ import type {
5
5
  } from 'fastify'
6
6
  import fastifyStatic from '@fastify/static'
7
7
  import { readFileSync } from 'fs'
8
+ import { fileURLToPath } from 'url'
8
9
  import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
9
10
  import {
10
11
  addOrReplaceAppDiv,
@@ -48,11 +49,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
48
49
  options.vitrifyDir =
49
50
  options.vitrifyDir || (await import('vitrify')).vitrifyDir
50
51
  const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir)
51
- // if (!options.vitrifyDir)
52
- // throw new Error('Option vitrifyDir cannot be undefined')
53
- // if (!options.vite) throw new Error('Option vite cannot be undefined')
54
- // const { resolve } = await import('import-meta-resolve')
55
- // const cliDir = new URL('../', await resolve('vitrify', import.meta.url))
52
+
56
53
  options.appDir = options.appDir || new URL('../../..', import.meta.url)
57
54
 
58
55
  const { createVitrifyDevServer } = await import('vitrify/dev')
@@ -63,38 +60,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
63
60
  base: options.baseUrl,
64
61
  host: options.host
65
62
  })
66
- // const { createServer, searchForWorkspaceRoot } = await import('vite')
67
- // const { baseConfig } = await import('vitrify')
68
- // const cliDir = options.vitrifyDir
69
- // const config = await baseConfig({
70
- // ssr: 'server',
71
- // command: 'dev',
72
- // mode: 'development',
73
- // appDir: options.appDir,
74
- // publicDir: options.publicDir || new URL('public', options.appDir)
75
- // })
76
-
77
- // config.server = {
78
- // middlewareMode: true,
79
- // fs: {
80
- // allow: [
81
- // searchForWorkspaceRoot(process.cwd()),
82
- // searchForWorkspaceRoot(options.appDir.pathname),
83
- // searchForWorkspaceRoot(cliDir.pathname)
84
- // // appDir.pathname,
85
- // ]
86
- // },
87
- // watch: {
88
- // // During tests we edit the files too fast and sometimes chokidar
89
- // // misses change events, so enforce polling for consistency
90
- // usePolling: true,
91
- // interval: 100
92
- // }
93
- // }
94
- // const vite = await createServer({
95
- // configFile: false,
96
- // ...config
97
- // })
98
63
 
99
64
  if (!('use' in fastify)) {
100
65
  const middie = (await import('@fastify/middie')).default
@@ -120,7 +85,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
120
85
 
121
86
  template = await vite.transformIndexHtml(url!, template)
122
87
 
123
- const entryUrl = new URL('ssr/entry-server.ts', frameworkDir).pathname
88
+ const entryUrl = fileURLToPath(
89
+ new URL('ssr/entry-server.ts', frameworkDir)
90
+ )
124
91
  const render = (await vite!.ssrLoadModule(entryUrl)).render
125
92
  let manifest
126
93
  // TODO: https://github.com/vitejs/vite/issues/2282
@@ -186,7 +153,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
186
153
  } else {
187
154
  options.appDir = options.appDir || new URL('../../..', import.meta.url)
188
155
  fastify.register(fastifyStatic, {
189
- root: new URL('./dist/ssr/client', options.appDir).pathname,
156
+ root: fileURLToPath(new URL('./dist/ssr/client', options.appDir)),
190
157
  wildcard: false,
191
158
  index: false,
192
159
  prefix: options.baseUrl
@@ -202,7 +169,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
202
169
  }
203
170
 
204
171
  const template = readFileSync(
205
- new URL('./dist/ssr/client/index.html', options.appDir).pathname
172
+ fileURLToPath(new URL('./dist/ssr/client/index.html', options.appDir))
206
173
  ).toString()
207
174
  const manifest = JSON.parse(
208
175
  readFileSync(
@@ -211,7 +178,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
211
178
  )
212
179
  const render = (
213
180
  await import(
214
- new URL('./dist/ssr/server/entry-server.mjs', options.appDir).pathname
181
+ fileURLToPath(
182
+ new URL('./dist/ssr/server/entry-server.mjs', options.appDir)
183
+ )
215
184
  )
216
185
  ).render
217
186
 
package/src/node/index.ts CHANGED
@@ -9,6 +9,7 @@ import { pathToFileURL } from 'url'
9
9
  import { readFileSync } from 'fs'
10
10
  import builtinModules from 'builtin-modules'
11
11
  import { visualizer } from 'rollup-plugin-visualizer'
12
+ import { fileURLToPath } from 'url'
12
13
  import type {
13
14
  StaticImports,
14
15
  BootFunction,
@@ -228,17 +229,17 @@ export const baseConfig = async ({
228
229
  let vitrifyConfig: VitrifyConfig | VitrifyConfigAsync
229
230
 
230
231
  try {
231
- if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
232
- const configPath = new URL('vitrify.config.ts', appDir).pathname
232
+ if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
233
+ const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir))
233
234
  const bundledConfig = await bundleConfigFile(
234
- new URL('vitrify.config.ts', appDir).pathname
235
+ fileURLToPath(new URL('vitrify.config.ts', appDir))
235
236
  )
236
237
  fs.writeFileSync(configPath + '.js', bundledConfig.code)
237
238
  vitrifyConfig = (await import(configPath + '.js')).default
238
239
  fs.unlinkSync(configPath + '.js')
239
240
  } else {
240
241
  vitrifyConfig = (
241
- await import(new URL('vitrify.config.js', appDir).pathname)
242
+ await import(fileURLToPath(new URL('vitrify.config.js', appDir)))
242
243
  ).default
243
244
  }
244
245
  if (typeof vitrifyConfig === 'function')
@@ -256,7 +257,7 @@ export const baseConfig = async ({
256
257
  vitrifyConfig.vitrify?.urls?.packages || {}
257
258
  await (async () => {
258
259
  for (const val of localPackages) {
259
- const pkg = resolvePackageData(val, appDir.pathname)
260
+ const pkg = resolvePackageData(val, fileURLToPath(appDir))
260
261
  if (pkg) packageUrls![val] = new URL(`file://${pkg.dir}/`)
261
262
  }
262
263
  })()
@@ -271,7 +272,7 @@ export const baseConfig = async ({
271
272
  if (!productName) {
272
273
  try {
273
274
  ;({ productName } = JSON.parse(
274
- readFileSync(new URL('package.json', appDir).pathname, {
275
+ readFileSync(fileURLToPath(new URL('package.json', appDir)), {
275
276
  encoding: 'utf-8'
276
277
  })
277
278
  ))
@@ -410,13 +411,15 @@ export const baseConfig = async ({
410
411
  export const onSetup = []
411
412
  ${onSetupFiles
412
413
  .map((url, index) => {
413
- const varName = url.pathname
414
+ const varName = fileURLToPath(url)
414
415
  .replaceAll('/', '')
415
416
  .replaceAll('.', '')
416
417
  .replaceAll('-', '')
417
418
  .replaceAll('_', '')
418
419
  .replaceAll('+', '')
419
- return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`
420
+ return `import ${varName} from '${fileURLToPath(
421
+ url
422
+ )}'; onSetup.push(${varName})`
420
423
  })
421
424
  .join('\n')}`
422
425
  } else if (id === 'virtual:static-imports') {
@@ -466,13 +469,15 @@ export const baseConfig = async ({
466
469
  case 'ssg':
467
470
  case 'server':
468
471
  case 'client':
469
- entry = new URL('ssr/entry-client.ts', frameworkDir).pathname
472
+ entry = fileURLToPath(
473
+ new URL('ssr/entry-client.ts', frameworkDir)
474
+ )
470
475
  break
471
476
  case 'fastify':
472
- entry = new URL('entry.ts', fastifyDir).pathname
477
+ entry = fileURLToPath(new URL('entry.ts', fastifyDir))
473
478
  break
474
479
  default:
475
- entry = new URL('csr/entry.ts', frameworkDir).pathname
480
+ entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir))
476
481
  }
477
482
  const entryScript = `<script type="module" src="${entry}"></script>`
478
483
  // html = html.replace('<!--entry-script-->', entryScript)
@@ -506,28 +511,26 @@ export const baseConfig = async ({
506
511
  }
507
512
 
508
513
  const alias: Alias[] = [
509
- { find: 'src', replacement: srcDir.pathname },
510
- { find: 'app', replacement: appDir.pathname },
511
- { find: 'cwd', replacement: cwd.pathname },
512
- { find: 'boot', replacement: new URL('boot/', srcDir).pathname },
513
- { find: 'assets', replacement: new URL('assets/', srcDir).pathname },
514
+ { find: 'src', replacement: fileURLToPath(srcDir) },
515
+ { find: 'app', replacement: fileURLToPath(appDir) },
516
+ { find: 'cwd', replacement: fileURLToPath(cwd) },
517
+ { find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
518
+ { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
514
519
  // ...Object.entries(packageUrls).map(([key, value]) => ({
515
520
  // find: key,
516
521
  // replacement: value.pathname
517
522
  // }))
518
523
  {
519
524
  find: new RegExp('^vue$'),
520
- replacement: new URL(
521
- './dist/vue.runtime.esm-bundler.js',
522
- packageUrls['vue']
523
- ).pathname
525
+ replacement: fileURLToPath(
526
+ new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
527
+ )
524
528
  },
525
529
  {
526
530
  find: new RegExp('^vue-router$'),
527
- replacement: new URL(
528
- './dist/vue-router.esm-bundler.js',
529
- packageUrls['vue-router']
530
- ).pathname
531
+ replacement: fileURLToPath(
532
+ new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router'])
533
+ )
531
534
  }
532
535
  ]
533
536
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
@@ -536,7 +539,7 @@ export const baseConfig = async ({
536
539
  if (command === 'test')
537
540
  alias.push({
538
541
  find: 'vitest',
539
- replacement: new URL(await resolve('vitest', cliDir)).pathname
542
+ replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
540
543
  })
541
544
 
542
545
  let rollupOptions: RollupOptions = {}
@@ -549,9 +552,9 @@ export const baseConfig = async ({
549
552
  rollupOptions = {
550
553
  ...rollupOptions,
551
554
  input: [
552
- new URL('ssr/entry-server.ts', frameworkDir).pathname,
553
- new URL('ssr/prerender.ts', frameworkDir).pathname,
554
- new URL('ssr/server.ts', frameworkDir).pathname
555
+ fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
556
+ fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
557
+ fileURLToPath(new URL('ssr/server.ts', frameworkDir))
555
558
  ],
556
559
  external,
557
560
  output: {
@@ -569,7 +572,7 @@ export const baseConfig = async ({
569
572
  } else if (ssr === 'fastify') {
570
573
  rollupOptions = {
571
574
  ...rollupOptions,
572
- input: [new URL('server.ts', fastifyDir).pathname],
575
+ input: [fileURLToPath(new URL('server.ts', fastifyDir))],
573
576
  external,
574
577
  output: {
575
578
  minifyInternalExports: false,
@@ -598,10 +601,10 @@ export const baseConfig = async ({
598
601
  }
599
602
 
600
603
  const config = {
601
- root: appDir.pathname,
602
- publicDir: publicDir.pathname,
604
+ root: fileURLToPath(appDir),
605
+ publicDir: fileURLToPath(publicDir),
603
606
  base,
604
- envDir: appDir.pathname,
607
+ envDir: fileURLToPath(appDir),
605
608
  vitrify: {
606
609
  productName,
607
610
  urls: {
@@ -1,5 +1,6 @@
1
1
  import type { Plugin } from 'vite'
2
2
  import { resolvePackageData } from 'vite'
3
+ import { fileURLToPath } from 'url'
3
4
  import Components from 'unplugin-vue-components/vite'
4
5
  import type {
5
6
  OnBootHook,
@@ -115,7 +116,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
115
116
  for (const val of localPackages) {
116
117
  const pkg = resolvePackageData(
117
118
  val,
118
- config.vitrify!.urls!.app!.pathname
119
+ fileURLToPath(config.vitrify!.urls!.app!)
119
120
  )
120
121
  if (pkg) urls!.packages![val] = new URL(`file://${pkg.dir}/`)
121
122
  }
@@ -196,10 +197,9 @@ export const QuasarPlugin: VitrifyPlugin = async ({
196
197
  alias: [
197
198
  {
198
199
  find: 'quasar/src/',
199
- replacement: new URL(
200
- './src/',
201
- config.vitrify!.urls!.packages!.quasar
202
- ).pathname
200
+ replacement: fileURLToPath(
201
+ new URL('./src/', config.vitrify!.urls!.packages!.quasar)
202
+ )
203
203
  }
204
204
  ]
205
205
  },