@qwik.dev/devtools 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +47 -0
  2. package/lib/index.qwik.cjs +4 -0
  3. package/lib/index.qwik.mjs +4 -0
  4. package/lib/kit/constants.qwik.cjs +4 -0
  5. package/lib/kit/constants.qwik.mjs +4 -0
  6. package/lib/kit/context.qwik.cjs +16 -0
  7. package/lib/kit/context.qwik.mjs +16 -0
  8. package/lib/kit/globals.qwik.cjs +6 -0
  9. package/lib/kit/globals.qwik.mjs +6 -0
  10. package/lib/kit/server.qwik.cjs +18 -0
  11. package/lib/kit/server.qwik.mjs +18 -0
  12. package/lib/kit/shared.qwik.cjs +4 -0
  13. package/lib/kit/shared.qwik.mjs +4 -0
  14. package/lib/plugin/assets/index.qwik.cjs +67 -0
  15. package/lib/plugin/assets/index.qwik.mjs +67 -0
  16. package/lib/plugin/index.qwik.cjs +49 -0
  17. package/lib/plugin/index.qwik.mjs +49 -0
  18. package/lib/plugin/npm/index.qwik.cjs +19 -0
  19. package/lib/plugin/npm/index.qwik.mjs +19 -0
  20. package/lib/plugin/routes/index.qwik.cjs +17 -0
  21. package/lib/plugin/routes/index.qwik.mjs +17 -0
  22. package/lib/plugin/rpc/index.qwik.cjs +14 -0
  23. package/lib/plugin/rpc/index.qwik.mjs +14 -0
  24. package/lib-types/devtools.d.ts +1 -0
  25. package/lib-types/entry.dev.d.ts +2 -0
  26. package/lib-types/entry.ssr.d.ts +2 -0
  27. package/lib-types/index.d.ts +1 -0
  28. package/lib-types/kit/client.d.ts +2 -0
  29. package/lib-types/kit/constants.d.ts +1 -0
  30. package/lib-types/kit/context.d.ts +10 -0
  31. package/lib-types/kit/globals.d.ts +20 -0
  32. package/lib-types/kit/index.d.ts +4 -0
  33. package/lib-types/kit/server.d.ts +2 -0
  34. package/lib-types/kit/shared.d.ts +1 -0
  35. package/lib-types/kit/types.d.ts +33 -0
  36. package/lib-types/plugin/assets/index.d.ts +5 -0
  37. package/lib-types/plugin/components/index.d.ts +0 -0
  38. package/lib-types/plugin/index.d.ts +2 -0
  39. package/lib-types/plugin/npm/index.d.ts +5 -0
  40. package/lib-types/plugin/routes/index.d.ts +5 -0
  41. package/lib-types/plugin/rpc/index.d.ts +3 -0
  42. package/lib-types/plugin/types/index.d.ts +5 -0
  43. package/lib-types/root.d.ts +2 -0
  44. package/package.json +70 -0
  45. package/src/devtools.css +558 -0
  46. package/src/devtools.tsx +411 -0
  47. package/src/entry.dev.tsx +17 -0
  48. package/src/entry.ssr.tsx +25 -0
  49. package/src/index.ts +1 -0
  50. package/src/kit/client.ts +21 -0
  51. package/src/kit/constants.ts +1 -0
  52. package/src/kit/context.ts +42 -0
  53. package/src/kit/globals.ts +22 -0
  54. package/src/kit/index.ts +4 -0
  55. package/src/kit/server.ts +21 -0
  56. package/src/kit/shared.ts +11 -0
  57. package/src/kit/types.ts +48 -0
  58. package/src/plugin/assets/index.ts +126 -0
  59. package/src/plugin/components/index.ts +0 -0
  60. package/src/plugin/index.ts +50 -0
  61. package/src/plugin/npm/index.ts +24 -0
  62. package/src/plugin/routes/index.ts +16 -0
  63. package/src/plugin/rpc/index.ts +14 -0
  64. package/src/plugin/types/index.ts +6 -0
  65. package/src/root.tsx +15 -0
@@ -0,0 +1,126 @@
1
+ import fsp from 'node:fs/promises';
2
+ import fg from 'fast-glob';
3
+ import { resolve, relative, join } from 'node:path/posix';
4
+ import { ServerContext } from '../types';
5
+ import { AssetType, AssetInfo } from '../../kit/types';
6
+
7
+ // const defaultAllowedExtensions = [
8
+ // 'png',
9
+ // 'jpg',
10
+ // 'jpeg',
11
+ // 'gif',
12
+ // 'svg',
13
+ // 'webp',
14
+ // 'ico',
15
+ // 'mp4',
16
+ // 'ogg',
17
+ // 'mp3',
18
+ // 'wav',
19
+ // 'mov',
20
+ // 'mkv',
21
+ // 'mpg',
22
+ // 'txt',
23
+ // 'ttf',
24
+ // 'woff',
25
+ // 'woff2',
26
+ // 'eot',
27
+ // 'json',
28
+ // 'js',
29
+ // 'jsx',
30
+ // 'ts',
31
+ // 'tsx',
32
+ // 'md',
33
+ // 'mdx',
34
+ // 'vue',
35
+ // 'webm',
36
+ // ];
37
+
38
+ export function getAssetsFunctions({ config }: ServerContext) {
39
+ let cache: AssetInfo[] | null = null;
40
+
41
+ async function getAssetsFromPublicDir() {
42
+ const dir = resolve(config.root);
43
+ const baseURL = config.base;
44
+
45
+ // publicDir in ResolvedConfig is an absolute path
46
+ const publicDir = config.publicDir;
47
+ const relativePublicDir =
48
+ publicDir === '' ? '' : `${relative(dir, publicDir)}/`;
49
+
50
+ const files = await fg(
51
+ [
52
+ // image
53
+ '**/*.(png|jpg|jpeg|gif|svg|webp|avif|ico|bmp|tiff)',
54
+ // video
55
+ '**/*.(mp4|webm|ogv|mov|avi|flv|wmv|mpg|mpeg|mkv|3gp|3g2|m2ts|vob|ogm|ogx|rm|rmvb|asf|amv|divx|m4v|svi|viv|f4v|f4p|f4a|f4b)',
56
+ // audio
57
+ '**/*.(mp3|wav|ogg|flac|aac|wma|alac|ape|ac3|dts|tta|opus|amr|aiff|au|mid|midi|ra|rm|wv|weba|dss|spx|vox|tak|dsf|dff|dsd|cda)',
58
+ // font
59
+ '**/*.(woff2?|eot|ttf|otf|ttc|pfa|pfb|pfm|afm)',
60
+ // text
61
+ '**/*.(json|json5|jsonc|txt|text|tsx|jsx|md|mdx|mdc|markdown|yaml|yml|toml)',
62
+ // wasm
63
+ '**/*.wasm',
64
+ ],
65
+ {
66
+ cwd: publicDir,
67
+ onlyFiles: true,
68
+ caseSensitiveMatch: false,
69
+ ignore: [
70
+ '**/node_modules/**',
71
+ '**/dist/**',
72
+ '**/package-lock.*',
73
+ '**/pnpm-lock.*',
74
+ '**/pnpm-workspace.*',
75
+ ],
76
+ },
77
+ );
78
+
79
+ cache = await Promise.all(
80
+ files.map(async (relativePath) => {
81
+ const filePath = resolve(publicDir, relativePath);
82
+ const stat = await fsp.lstat(filePath);
83
+ // remove public prefix to resolve vite assets warning
84
+ const path = relativePath.replace(relativePublicDir, '');
85
+ return {
86
+ path,
87
+ relativePath,
88
+ publicPath: join(baseURL, path),
89
+ filePath,
90
+ type: guessType(relativePath),
91
+ size: stat.size,
92
+ mtime: stat.mtimeMs,
93
+ };
94
+ }),
95
+ );
96
+ return cache;
97
+ }
98
+
99
+ return {
100
+ getAssetsFromPublicDir,
101
+ };
102
+ }
103
+
104
+ function guessType(path: string): AssetType {
105
+ if (/\.(?:png|jpe?g|jxl|gif|svg|webp|avif|ico|bmp|tiff?)$/i.test(path))
106
+ return 'image';
107
+ if (
108
+ /\.(?:mp4|webm|ogv|mov|avi|flv|wmv|mpg|mpeg|mkv|3gp|3g2|ts|mts|m2ts|vob|ogm|ogx|rm|rmvb|asf|amv|divx|m4v|svi|viv|f4v|f4p|f4a|f4b)$/i.test(
109
+ path,
110
+ )
111
+ )
112
+ return 'video';
113
+ if (
114
+ /\.(?:mp3|wav|ogg|flac|aac|wma|alac|ape|ac3|dts|tta|opus|amr|aiff|au|mid|midi|ra|rm|wv|weba|dss|spx|vox|tak|dsf|dff|dsd|cda)$/i.test(
115
+ path,
116
+ )
117
+ )
118
+ return 'audio';
119
+ if (/\.(?:woff2?|eot|ttf|otf|ttc|pfa|pfb|pfm|afm)/i.test(path)) return 'font';
120
+ if (
121
+ /\.(?:json[5c]?|te?xt|[mc]?[jt]sx?|md[cx]?|markdown|ya?ml|toml)/i.test(path)
122
+ )
123
+ return 'text';
124
+ if (/\.wasm/i.test(path)) return 'wasm';
125
+ return 'other';
126
+ }
File without changes
@@ -0,0 +1,50 @@
1
+ import { ResolvedConfig, type Plugin } from 'vite';
2
+ import { getServerFunctions } from './rpc';
3
+ import { createServerRpc, setViteServerContext } from '../kit';
4
+
5
+ export function qwikDevtools(): Plugin {
6
+ let _config: ResolvedConfig;
7
+ return {
8
+ name: 'vite-plugin-qwik-devtools',
9
+ apply: 'serve',
10
+ configResolved(viteConfig) {
11
+ _config = viteConfig;
12
+ },
13
+ transform: {
14
+ order: 'pre',
15
+ handler(code, id) {
16
+ // Only transform the root component file
17
+ if (id.endsWith('root.tsx')) {
18
+ // Check if QwikDevtools import already exists
19
+ if (!code.includes('@qwik.dev/devtools/component')) {
20
+ // Add import for QwikDevtools using the correct package name
21
+ code = `import { QwikDevtools } from '@qwik.dev/devtools/component';\n${code}`;
22
+ }
23
+
24
+ // Find the closing body tag and inject the QwikDevtools component before it
25
+ const match = code.match(/<body[^>]*>([\s\S]*?)<\/body>/);
26
+ if (match) {
27
+ const bodyContent = match[1];
28
+ const newBodyContent = bodyContent.replace(
29
+ /{!isDev && <ServiceWorkerRegister \/>}/,
30
+ `{!isDev && <ServiceWorkerRegister />}\n {isDev && <QwikDevtools />}`,
31
+ );
32
+ code = code.replace(bodyContent, newBodyContent);
33
+ }
34
+
35
+ return {
36
+ code,
37
+ map: null,
38
+ };
39
+ }
40
+ },
41
+ },
42
+ configureServer(server) {
43
+ setViteServerContext(server);
44
+
45
+ const rpcFunctions = getServerFunctions({ server, config: _config });
46
+
47
+ createServerRpc(rpcFunctions);
48
+ },
49
+ };
50
+ }
@@ -0,0 +1,24 @@
1
+ import { ServerContext } from '../types';
2
+ import fsp from 'node:fs/promises';
3
+ import { NpmInfo } from '../../kit/types';
4
+
5
+ export function getNpmFunctions({ config }: ServerContext) {
6
+ return {
7
+ async getQwikPackages(): Promise<NpmInfo> {
8
+ const pathToPackageJson = config.configFileDependencies.find((file) =>
9
+ file.endsWith('package.json'),
10
+ );
11
+ if (!pathToPackageJson) return [];
12
+
13
+ try {
14
+ const pkgJson = await fsp.readFile(pathToPackageJson, 'utf-8');
15
+ const pkg = JSON.parse(pkgJson);
16
+ return Object.entries<string>(pkg.devDependencies).filter(([key]) =>
17
+ /@qwik/i.test(key),
18
+ );
19
+ } catch (error) {
20
+ return [];
21
+ }
22
+ },
23
+ };
24
+ }
@@ -0,0 +1,16 @@
1
+ import { RoutesInfo } from '../../kit/types';
2
+ import { ServerContext } from '../types';
3
+ import { scanAsync } from 'dree';
4
+
5
+ export function getRouteFunctions({ config }: ServerContext) {
6
+ const routesDir = `${config.root}/src/routes`;
7
+ return {
8
+ getRoutes: async (): Promise<RoutesInfo> => {
9
+ const routes = await scanAsync(routesDir, {
10
+ extensions: ['tsx'],
11
+ });
12
+
13
+ return routes;
14
+ },
15
+ };
16
+ }
@@ -0,0 +1,14 @@
1
+ import { ServerFunctions } from '../../kit/types';
2
+ import { getAssetsFunctions } from '../assets';
3
+ import { ServerContext } from '../types';
4
+ import { getRouteFunctions } from '../routes';
5
+ import { getNpmFunctions } from '../npm';
6
+
7
+ export function getServerFunctions(ctx: ServerContext): ServerFunctions {
8
+ return {
9
+ healthCheck: () => true,
10
+ ...getAssetsFunctions(ctx),
11
+ ...getRouteFunctions(ctx),
12
+ ...getNpmFunctions(ctx),
13
+ };
14
+ }
@@ -0,0 +1,6 @@
1
+ import { ViteDevServer, ResolvedConfig } from 'vite';
2
+
3
+ export interface ServerContext {
4
+ server: ViteDevServer;
5
+ config: ResolvedConfig;
6
+ }
package/src/root.tsx ADDED
@@ -0,0 +1,15 @@
1
+ import { QwikDevtools } from './devtools';
2
+
3
+ export default () => {
4
+ return (
5
+ <>
6
+ <head>
7
+ <meta charset="utf-8" />
8
+ <title>Qwik Blank App</title>
9
+ </head>
10
+ <body>
11
+ <QwikDevtools />
12
+ </body>
13
+ </>
14
+ );
15
+ };