vitrify 0.11.7 → 0.11.9

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,17 @@ 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
- vitrifyConfig = (await import(configPath + '.js')).default;
166
+ // @ts-ignore
167
+ vitrifyConfig = (await import('file://' + configPath + '.js')).default;
168
+ // vitrifyConfig = (await import(configPath + '.js')).default
166
169
  fs.unlinkSync(configPath + '.js');
167
170
  }
168
171
  else {
169
- vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
172
+ vitrifyConfig = (await import(fileURLToPath(new URL('vitrify.config.js', appDir)))).default;
170
173
  }
171
174
  if (typeof vitrifyConfig === 'function')
172
175
  vitrifyConfig = await vitrifyConfig({ mode, command });
@@ -183,7 +186,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
183
186
  const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
184
187
  await (async () => {
185
188
  for (const val of localPackages) {
186
- const pkg = resolvePackageData(val, appDir.pathname);
189
+ const pkg = resolvePackageData(val, fileURLToPath(appDir));
187
190
  if (pkg)
188
191
  packageUrls[val] = new URL(`file://${pkg.dir}/`);
189
192
  }
@@ -197,7 +200,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
197
200
  if (!productName) {
198
201
  try {
199
202
  ;
200
- ({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
203
+ ({ productName } = JSON.parse(readFileSync(fileURLToPath(new URL('package.json', appDir)), {
201
204
  encoding: 'utf-8'
202
205
  })));
203
206
  if (!productName)
@@ -327,13 +330,18 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
327
330
  export const onSetup = []
328
331
  ${onSetupFiles
329
332
  .map((url, index) => {
330
- const varName = url.pathname
333
+ const varName = fileURLToPath(url)
331
334
  .replaceAll('/', '')
335
+ .replaceAll(':', '')
336
+ .replaceAll('\\', '')
332
337
  .replaceAll('.', '')
333
338
  .replaceAll('-', '')
334
339
  .replaceAll('_', '')
335
340
  .replaceAll('+', '');
336
- return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`;
341
+ return `import ${varName} from '${new URL(url, appDir).pathname}'; onSetup.push(${varName})`;
342
+ // return `import ${varName} from '${fileURLToPath(
343
+ // url
344
+ // )}'; onSetup.push(${varName})`
337
345
  })
338
346
  .join('\n')}`;
339
347
  }
@@ -381,15 +389,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
381
389
  case 'ssg':
382
390
  case 'server':
383
391
  case 'client':
384
- entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
392
+ entry = fileURLToPath(new URL('ssr/entry-client.ts', frameworkDir));
385
393
  break;
386
394
  case 'fastify':
387
- entry = new URL('entry.ts', fastifyDir).pathname;
395
+ entry = fileURLToPath(new URL('entry.ts', fastifyDir));
388
396
  break;
389
397
  default:
390
- entry = new URL('csr/entry.ts', frameworkDir).pathname;
398
+ entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir));
399
+ }
400
+ let entryScript;
401
+ if (process.platform === 'win32') {
402
+ const split = entry.split('node_modules');
403
+ entryScript = `<script type="module" src="node_modules${split.at(-1)}"></script>`;
404
+ }
405
+ else {
406
+ entryScript = `<script type="module" src="${entry}"></script>`;
391
407
  }
392
- const entryScript = `<script type="module" src="${entry}"></script>`;
393
408
  // html = html.replace('<!--entry-script-->', entryScript)
394
409
  html = appendToBody(entryScript, html);
395
410
  if (productName)
@@ -420,22 +435,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
420
435
  plugins.push(visualizer());
421
436
  }
422
437
  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 },
438
+ { find: 'src', replacement: fileURLToPath(srcDir) },
439
+ { find: 'app', replacement: fileURLToPath(appDir) },
440
+ { find: 'cwd', replacement: fileURLToPath(cwd) },
441
+ { find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
442
+ { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
428
443
  // ...Object.entries(packageUrls).map(([key, value]) => ({
429
444
  // find: key,
430
445
  // replacement: value.pathname
431
446
  // }))
432
447
  {
433
448
  find: new RegExp('^vue$'),
434
- replacement: new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']).pathname
449
+ replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
435
450
  },
436
451
  {
437
452
  find: new RegExp('^vue-router$'),
438
- replacement: new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']).pathname
453
+ replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
439
454
  }
440
455
  ];
441
456
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
@@ -443,7 +458,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
443
458
  if (command === 'test')
444
459
  alias.push({
445
460
  find: 'vitest',
446
- replacement: new URL(await resolve('vitest', cliDir)).pathname
461
+ replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
447
462
  });
448
463
  let rollupOptions = {};
449
464
  let noExternal = [
@@ -454,9 +469,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
454
469
  rollupOptions = {
455
470
  ...rollupOptions,
456
471
  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
472
+ fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
473
+ fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
474
+ fileURLToPath(new URL('ssr/server.ts', frameworkDir))
460
475
  ],
461
476
  external,
462
477
  output: {
@@ -475,7 +490,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
475
490
  else if (ssr === 'fastify') {
476
491
  rollupOptions = {
477
492
  ...rollupOptions,
478
- input: [new URL('server.ts', fastifyDir).pathname],
493
+ input: [fileURLToPath(new URL('server.ts', fastifyDir))],
479
494
  external,
480
495
  output: {
481
496
  minifyInternalExports: false,
@@ -504,10 +519,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
504
519
  };
505
520
  }
506
521
  const config = {
507
- root: appDir.pathname,
508
- publicDir: publicDir.pathname,
522
+ root: fileURLToPath(appDir),
523
+ publicDir: fileURLToPath(publicDir),
509
524
  base,
510
- envDir: appDir.pathname,
525
+ envDir: fileURLToPath(appDir),
511
526
  vitrify: {
512
527
  productName,
513
528
  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.9",
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,19 @@ 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
- vitrifyConfig = (await import(configPath + '.js')).default
238
+ // @ts-ignore
239
+ vitrifyConfig = (await import('file://' + configPath + '.js')).default
240
+ // vitrifyConfig = (await import(configPath + '.js')).default
238
241
  fs.unlinkSync(configPath + '.js')
239
242
  } else {
240
243
  vitrifyConfig = (
241
- await import(new URL('vitrify.config.js', appDir).pathname)
244
+ await import(fileURLToPath(new URL('vitrify.config.js', appDir)))
242
245
  ).default
243
246
  }
244
247
  if (typeof vitrifyConfig === 'function')
@@ -256,7 +259,7 @@ export const baseConfig = async ({
256
259
  vitrifyConfig.vitrify?.urls?.packages || {}
257
260
  await (async () => {
258
261
  for (const val of localPackages) {
259
- const pkg = resolvePackageData(val, appDir.pathname)
262
+ const pkg = resolvePackageData(val, fileURLToPath(appDir))
260
263
  if (pkg) packageUrls![val] = new URL(`file://${pkg.dir}/`)
261
264
  }
262
265
  })()
@@ -271,7 +274,7 @@ export const baseConfig = async ({
271
274
  if (!productName) {
272
275
  try {
273
276
  ;({ productName } = JSON.parse(
274
- readFileSync(new URL('package.json', appDir).pathname, {
277
+ readFileSync(fileURLToPath(new URL('package.json', appDir)), {
275
278
  encoding: 'utf-8'
276
279
  })
277
280
  ))
@@ -410,13 +413,22 @@ export const baseConfig = async ({
410
413
  export const onSetup = []
411
414
  ${onSetupFiles
412
415
  .map((url, index) => {
413
- const varName = url.pathname
416
+ const varName = fileURLToPath(url)
414
417
  .replaceAll('/', '')
418
+ .replaceAll(':', '')
419
+ .replaceAll('\\', '')
415
420
  .replaceAll('.', '')
416
421
  .replaceAll('-', '')
417
422
  .replaceAll('_', '')
418
423
  .replaceAll('+', '')
419
- return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`
424
+
425
+ return `import ${varName} from '${
426
+ new URL(url, appDir).pathname
427
+ }'; onSetup.push(${varName})`
428
+
429
+ // return `import ${varName} from '${fileURLToPath(
430
+ // url
431
+ // )}'; onSetup.push(${varName})`
420
432
  })
421
433
  .join('\n')}`
422
434
  } else if (id === 'virtual:static-imports') {
@@ -466,15 +478,25 @@ export const baseConfig = async ({
466
478
  case 'ssg':
467
479
  case 'server':
468
480
  case 'client':
469
- entry = new URL('ssr/entry-client.ts', frameworkDir).pathname
481
+ entry = fileURLToPath(
482
+ new URL('ssr/entry-client.ts', frameworkDir)
483
+ )
470
484
  break
471
485
  case 'fastify':
472
- entry = new URL('entry.ts', fastifyDir).pathname
486
+ entry = fileURLToPath(new URL('entry.ts', fastifyDir))
473
487
  break
474
488
  default:
475
- entry = new URL('csr/entry.ts', frameworkDir).pathname
489
+ entry = fileURLToPath(new URL('csr/entry.ts', frameworkDir))
490
+ }
491
+ let entryScript
492
+ if (process.platform === 'win32') {
493
+ const split = entry.split('node_modules')
494
+ entryScript = `<script type="module" src="node_modules${split.at(
495
+ -1
496
+ )}"></script>`
497
+ } else {
498
+ entryScript = `<script type="module" src="${entry}"></script>`
476
499
  }
477
- const entryScript = `<script type="module" src="${entry}"></script>`
478
500
  // html = html.replace('<!--entry-script-->', entryScript)
479
501
  html = appendToBody(entryScript, html)
480
502
  if (productName) html = addOrReplaceTitle(productName, html)
@@ -506,28 +528,26 @@ export const baseConfig = async ({
506
528
  }
507
529
 
508
530
  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 },
531
+ { find: 'src', replacement: fileURLToPath(srcDir) },
532
+ { find: 'app', replacement: fileURLToPath(appDir) },
533
+ { find: 'cwd', replacement: fileURLToPath(cwd) },
534
+ { find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
535
+ { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
514
536
  // ...Object.entries(packageUrls).map(([key, value]) => ({
515
537
  // find: key,
516
538
  // replacement: value.pathname
517
539
  // }))
518
540
  {
519
541
  find: new RegExp('^vue$'),
520
- replacement: new URL(
521
- './dist/vue.runtime.esm-bundler.js',
522
- packageUrls['vue']
523
- ).pathname
542
+ replacement: fileURLToPath(
543
+ new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
544
+ )
524
545
  },
525
546
  {
526
547
  find: new RegExp('^vue-router$'),
527
- replacement: new URL(
528
- './dist/vue-router.esm-bundler.js',
529
- packageUrls['vue-router']
530
- ).pathname
548
+ replacement: fileURLToPath(
549
+ new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router'])
550
+ )
531
551
  }
532
552
  ]
533
553
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
@@ -536,7 +556,7 @@ export const baseConfig = async ({
536
556
  if (command === 'test')
537
557
  alias.push({
538
558
  find: 'vitest',
539
- replacement: new URL(await resolve('vitest', cliDir)).pathname
559
+ replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
540
560
  })
541
561
 
542
562
  let rollupOptions: RollupOptions = {}
@@ -549,9 +569,9 @@ export const baseConfig = async ({
549
569
  rollupOptions = {
550
570
  ...rollupOptions,
551
571
  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
572
+ fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir)),
573
+ fileURLToPath(new URL('ssr/prerender.ts', frameworkDir)),
574
+ fileURLToPath(new URL('ssr/server.ts', frameworkDir))
555
575
  ],
556
576
  external,
557
577
  output: {
@@ -569,7 +589,7 @@ export const baseConfig = async ({
569
589
  } else if (ssr === 'fastify') {
570
590
  rollupOptions = {
571
591
  ...rollupOptions,
572
- input: [new URL('server.ts', fastifyDir).pathname],
592
+ input: [fileURLToPath(new URL('server.ts', fastifyDir))],
573
593
  external,
574
594
  output: {
575
595
  minifyInternalExports: false,
@@ -598,10 +618,10 @@ export const baseConfig = async ({
598
618
  }
599
619
 
600
620
  const config = {
601
- root: appDir.pathname,
602
- publicDir: publicDir.pathname,
621
+ root: fileURLToPath(appDir),
622
+ publicDir: fileURLToPath(publicDir),
603
623
  base,
604
- envDir: appDir.pathname,
624
+ envDir: fileURLToPath(appDir),
605
625
  vitrify: {
606
626
  productName,
607
627
  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
  },