vitrify 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/dev.js CHANGED
@@ -2,6 +2,13 @@ import { searchForWorkspaceRoot } from 'vite';
2
2
  import { baseConfig } from '../index.js';
3
3
  import fastify from 'fastify';
4
4
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
5
+ import isPortReachable from 'is-port-reachable';
6
+ const getFirstOpenPort = async (portNumber) => {
7
+ if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
8
+ return portNumber;
9
+ }
10
+ return getFirstOpenPort(portNumber + 1);
11
+ };
5
12
  export async function createVitrifyDevServer({ port = 3000, logLevel = 'info',
6
13
  // mode = 'csr',
7
14
  ssr, framework = 'vue', host, appDir, publicDir, base }) {
@@ -29,7 +36,7 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
29
36
  https: config.server?.https,
30
37
  hmr: {
31
38
  protocol: config.server?.https ? 'wss' : 'ws',
32
- port: 24678
39
+ port: await getFirstOpenPort(24678)
33
40
  },
34
41
  port,
35
42
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
@@ -2,9 +2,6 @@ import fastifyStatic from '@fastify/static';
2
2
  import { readFileSync } from 'fs';
3
3
  import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js';
4
4
  const fastifySsrPlugin = async (fastify, options, done) => {
5
- options.vitrifyDir =
6
- options.vitrifyDir || (await import('vitrify')).vitrifyDir;
7
- const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
8
5
  options.baseUrl = options.baseUrl || '/';
9
6
  options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
10
7
  options.appDir = options.appDir || new URL('../../..', import.meta.url);
@@ -12,6 +9,9 @@ const fastifySsrPlugin = async (fastify, options, done) => {
12
9
  options.baseUrl.charAt(0) !== '/')
13
10
  throw new Error('baseUrl should start and end with a /');
14
11
  if (options.mode === 'development') {
12
+ options.vitrifyDir =
13
+ options.vitrifyDir || (await import('vitrify')).vitrifyDir;
14
+ const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir);
15
15
  // if (!options.vitrifyDir)
16
16
  // throw new Error('Option vitrifyDir cannot be undefined')
17
17
  // if (!options.vite) throw new Error('Option vite cannot be undefined')
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import builtinModules from 'builtin-modules';
10
10
  // import { resolve } from 'import-meta-resolve'
11
11
  import { visualizer } from 'rollup-plugin-visualizer';
12
12
  import { resolve } from './app-urls.js';
13
+ import envPlugin from '@vitrify/plugin-env';
13
14
  const internalServerModules = [
14
15
  'util',
15
16
  'vitrify',
@@ -196,6 +197,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
196
197
  ];
197
198
  const plugins = [
198
199
  vuePlugin(),
200
+ envPlugin(),
199
201
  ...frameworkPlugins,
200
202
  {
201
203
  name: 'vitrify-setup',
@@ -38,12 +38,12 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
38
38
  name: 'vite-plugin-quasar-transform',
39
39
  enforce: 'pre',
40
40
  transform: (code, id, options) => {
41
- const { ssr: transformSsr } = options || {};
41
+ const { ssr } = options || {};
42
42
  code = code
43
43
  .replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
44
- .replaceAll('__QUASAR_SSR_SERVER__', ssr === 'server' ? 'import.meta.env.SSR' : 'false')
45
- .replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '!import.meta.env.SSR' : 'false')
46
- .replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '!import.meta.env.SSR' : 'false');
44
+ .replaceAll('__QUASAR_SSR_SERVER__', ssr ? '(import.meta.env.SSR === true)' : 'false')
45
+ .replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '(import.meta.env.SSR === false)' : 'false')
46
+ .replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '(import.meta.env.SSR === false)' : 'false');
47
47
  return code;
48
48
  }
49
49
  },
@@ -52,7 +52,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
52
52
  enforce: 'pre',
53
53
  config: async (config, env) => {
54
54
  const { vitrify: { urls } = {}, quasar } = config;
55
- const globalCss = quasar?.extras.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
55
+ const globalCss = quasar?.extras?.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
56
56
  const localPackages = ['@quasar/extras', 'quasar'];
57
57
  // const localPackages: string[] = []
58
58
  await (async () => {
@@ -77,10 +77,13 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
77
77
  const directives = await import('virtual:quasar-directives');
78
78
  // @ts-ignore
79
79
  const { default: lang } = await import('virtual:quasar-lang');
80
+ // @ts-ignore
81
+ const { default: iconSet } = await import('virtual:quasar-iconSet');
80
82
  app.use(staticImports?.Quasar, {
81
83
  plugins: quasarPlugins,
82
84
  directives,
83
- lang
85
+ lang,
86
+ iconSet
84
87
  }, ssrContext);
85
88
  }
86
89
  ];
@@ -163,6 +166,8 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
163
166
  return 'virtual:quasar-directives';
164
167
  case 'virtual:quasar-lang':
165
168
  return 'virtual:quasar-lang';
169
+ case 'virtual:quasar-iconSet':
170
+ return 'virtual:quasar-iconSet';
166
171
  case 'virtual:quasar':
167
172
  return { id: 'virtual:quasar', moduleSideEffects: false };
168
173
  default:
@@ -179,6 +184,10 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
179
184
  else if (id === 'virtual:quasar-lang') {
180
185
  return `import lang from 'quasar/lang/${quasarConf?.framework?.lang || 'en-US'}';
181
186
  export default lang`;
187
+ }
188
+ else if (id === 'virtual:quasar-iconSet') {
189
+ return `import iconSet from 'quasar/icon-set/${quasarConf?.framework.iconSet || 'material-icons'}';
190
+ export default iconSet`;
182
191
  }
183
192
  else if (id === 'virtual:quasar') {
184
193
  return `export * from 'quasar/src/plugins.js';
@@ -8,6 +8,7 @@ export interface QuasarConf {
8
8
  directives?: string[];
9
9
  plugins?: string[];
10
10
  lang?: string;
11
+ iconSet?: string;
11
12
  };
12
13
  animations: string[];
13
14
  extras: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -60,6 +60,7 @@
60
60
  "@fastify/static": "^6.5.0",
61
61
  "@quasar/extras": "^1.15.1",
62
62
  "@vitejs/plugin-vue": "^3.0.1",
63
+ "@vitrify/plugin-env": "^0.1.0",
63
64
  "builtin-modules": "^3.3.0",
64
65
  "cac": "^6.7.12",
65
66
  "chalk": "^5.0.1",
@@ -69,6 +70,7 @@
69
70
  "fastify": "^4.3.0",
70
71
  "glob": "^8.0.3",
71
72
  "happy-dom": "^6.0.4",
73
+ "is-port-reachable": "^4.0.0",
72
74
  "magic-string": "^0.26.2",
73
75
  "merge-deep": "^3.0.3",
74
76
  "readline": "^1.3.0",
@@ -6,6 +6,14 @@ import fastify from 'fastify'
6
6
  import type { FastifyServerOptions } from 'fastify'
7
7
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
8
8
  import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
9
+ import isPortReachable from 'is-port-reachable'
10
+
11
+ const getFirstOpenPort = async (portNumber: number): Promise<number> => {
12
+ if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
13
+ return portNumber
14
+ }
15
+ return getFirstOpenPort(portNumber + 1)
16
+ }
9
17
 
10
18
  export async function createVitrifyDevServer({
11
19
  port = 3000,
@@ -55,7 +63,7 @@ export async function createVitrifyDevServer({
55
63
  https: config.server?.https,
56
64
  hmr: {
57
65
  protocol: config.server?.https ? 'wss' : 'ws',
58
- port: 24678
66
+ port: await getFirstOpenPort(24678)
59
67
  },
60
68
  port,
61
69
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
@@ -30,9 +30,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
30
30
  options,
31
31
  done
32
32
  ) => {
33
- options.vitrifyDir =
34
- options.vitrifyDir || (await import('vitrify')).vitrifyDir
35
- const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir)
36
33
  options.baseUrl = options.baseUrl || '/'
37
34
  options.mode = options.mode || process.env.MODE || import.meta.env.MODE
38
35
  options.appDir = options.appDir || new URL('../../..', import.meta.url)
@@ -43,6 +40,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
43
40
  )
44
41
  throw new Error('baseUrl should start and end with a /')
45
42
  if (options.mode === 'development') {
43
+ options.vitrifyDir =
44
+ options.vitrifyDir || (await import('vitrify')).vitrifyDir
45
+ const frameworkDir = new URL('src/vite/vue/', options.vitrifyDir)
46
46
  // if (!options.vitrifyDir)
47
47
  // throw new Error('Option vitrifyDir cannot be undefined')
48
48
  // if (!options.vite) throw new Error('Option vite cannot be undefined')
package/src/node/index.ts CHANGED
@@ -23,6 +23,7 @@ import type { VitrifyContext } from './bin/run.js'
23
23
  import type { VitrifyPlugin } from './plugins/index.js'
24
24
  import { resolve } from './app-urls.js'
25
25
  import type { ManualChunksOption, RollupOptions } from 'rollup'
26
+ import envPlugin from '@vitrify/plugin-env'
26
27
 
27
28
  const internalServerModules = [
28
29
  'util',
@@ -269,6 +270,7 @@ export const baseConfig = async ({
269
270
 
270
271
  const plugins: UserConfig['plugins'] = [
271
272
  vuePlugin(),
273
+ envPlugin(),
272
274
  ...frameworkPlugins,
273
275
  {
274
276
  name: 'vitrify-setup',
@@ -17,6 +17,7 @@ export interface QuasarConf {
17
17
  directives?: string[]
18
18
  plugins?: string[]
19
19
  lang?: string
20
+ iconSet?: string
20
21
  }
21
22
  animations: string[]
22
23
  extras: string[]
@@ -84,20 +85,20 @@ export const QuasarPlugin: VitrifyPlugin = async ({
84
85
  name: 'vite-plugin-quasar-transform',
85
86
  enforce: 'pre',
86
87
  transform: (code, id, options) => {
87
- const { ssr: transformSsr } = options || {}
88
+ const { ssr } = options || {}
88
89
  code = code
89
90
  .replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
90
91
  .replaceAll(
91
92
  '__QUASAR_SSR_SERVER__',
92
- ssr === 'server' ? 'import.meta.env.SSR' : 'false'
93
+ ssr ? '(import.meta.env.SSR === true)' : 'false'
93
94
  )
94
95
  .replaceAll(
95
96
  '__QUASAR_SSR_CLIENT__',
96
- ssr ? '!import.meta.env.SSR' : 'false'
97
+ ssr ? '(import.meta.env.SSR === false)' : 'false'
97
98
  )
98
99
  .replaceAll(
99
100
  '__QUASAR_SSR_PWA__',
100
- ssr && pwa ? '!import.meta.env.SSR' : 'false'
101
+ ssr && pwa ? '(import.meta.env.SSR === false)' : 'false'
101
102
  )
102
103
 
103
104
  return code
@@ -109,7 +110,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
109
110
  config: async (config: VitrifyConfig, env): Promise<VitrifyConfig> => {
110
111
  const { vitrify: { urls } = {}, quasar } = config
111
112
 
112
- const globalCss = quasar?.extras.map(
113
+ const globalCss = quasar?.extras?.map(
113
114
  (extra) => `@quasar/extras/${extra}/${extra}.css`
114
115
  )
115
116
 
@@ -143,13 +144,16 @@ export const QuasarPlugin: VitrifyPlugin = async ({
143
144
  const directives = await import('virtual:quasar-directives')
144
145
  // @ts-ignore
145
146
  const { default: lang } = await import('virtual:quasar-lang')
147
+ // @ts-ignore
148
+ const { default: iconSet } = await import('virtual:quasar-iconSet')
146
149
 
147
150
  app.use(
148
151
  staticImports?.Quasar,
149
152
  {
150
153
  plugins: quasarPlugins,
151
154
  directives,
152
- lang
155
+ lang,
156
+ iconSet
153
157
  },
154
158
  ssrContext
155
159
  )
@@ -239,6 +243,8 @@ export const QuasarPlugin: VitrifyPlugin = async ({
239
243
  return 'virtual:quasar-directives'
240
244
  case 'virtual:quasar-lang':
241
245
  return 'virtual:quasar-lang'
246
+ case 'virtual:quasar-iconSet':
247
+ return 'virtual:quasar-iconSet'
242
248
  case 'virtual:quasar':
243
249
  return { id: 'virtual:quasar', moduleSideEffects: false }
244
250
  default:
@@ -255,6 +261,11 @@ export const QuasarPlugin: VitrifyPlugin = async ({
255
261
  quasarConf?.framework?.lang || 'en-US'
256
262
  }';
257
263
  export default lang`
264
+ } else if (id === 'virtual:quasar-iconSet') {
265
+ return `import iconSet from 'quasar/icon-set/${
266
+ quasarConf?.framework.iconSet || 'material-icons'
267
+ }';
268
+ export default iconSet`
258
269
  } else if (id === 'virtual:quasar') {
259
270
  return `export * from 'quasar/src/plugins.js';
260
271
  export * from 'quasar/src/components.js';
@@ -23,4 +23,5 @@ export const setupApp = async () => {
23
23
  })
24
24
  }
25
25
 
26
+ export { default as vitrifyConfig } from 'virtual:vitrify-config'
26
27
  export { onRendered }