@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.
- package/README.md +47 -0
- package/lib/index.qwik.cjs +4 -0
- package/lib/index.qwik.mjs +4 -0
- package/lib/kit/constants.qwik.cjs +4 -0
- package/lib/kit/constants.qwik.mjs +4 -0
- package/lib/kit/context.qwik.cjs +16 -0
- package/lib/kit/context.qwik.mjs +16 -0
- package/lib/kit/globals.qwik.cjs +6 -0
- package/lib/kit/globals.qwik.mjs +6 -0
- package/lib/kit/server.qwik.cjs +18 -0
- package/lib/kit/server.qwik.mjs +18 -0
- package/lib/kit/shared.qwik.cjs +4 -0
- package/lib/kit/shared.qwik.mjs +4 -0
- package/lib/plugin/assets/index.qwik.cjs +67 -0
- package/lib/plugin/assets/index.qwik.mjs +67 -0
- package/lib/plugin/index.qwik.cjs +49 -0
- package/lib/plugin/index.qwik.mjs +49 -0
- package/lib/plugin/npm/index.qwik.cjs +19 -0
- package/lib/plugin/npm/index.qwik.mjs +19 -0
- package/lib/plugin/routes/index.qwik.cjs +17 -0
- package/lib/plugin/routes/index.qwik.mjs +17 -0
- package/lib/plugin/rpc/index.qwik.cjs +14 -0
- package/lib/plugin/rpc/index.qwik.mjs +14 -0
- package/lib-types/devtools.d.ts +1 -0
- package/lib-types/entry.dev.d.ts +2 -0
- package/lib-types/entry.ssr.d.ts +2 -0
- package/lib-types/index.d.ts +1 -0
- package/lib-types/kit/client.d.ts +2 -0
- package/lib-types/kit/constants.d.ts +1 -0
- package/lib-types/kit/context.d.ts +10 -0
- package/lib-types/kit/globals.d.ts +20 -0
- package/lib-types/kit/index.d.ts +4 -0
- package/lib-types/kit/server.d.ts +2 -0
- package/lib-types/kit/shared.d.ts +1 -0
- package/lib-types/kit/types.d.ts +33 -0
- package/lib-types/plugin/assets/index.d.ts +5 -0
- package/lib-types/plugin/components/index.d.ts +0 -0
- package/lib-types/plugin/index.d.ts +2 -0
- package/lib-types/plugin/npm/index.d.ts +5 -0
- package/lib-types/plugin/routes/index.d.ts +5 -0
- package/lib-types/plugin/rpc/index.d.ts +3 -0
- package/lib-types/plugin/types/index.d.ts +5 -0
- package/lib-types/root.d.ts +2 -0
- package/package.json +70 -0
- package/src/devtools.css +558 -0
- package/src/devtools.tsx +411 -0
- package/src/entry.dev.tsx +17 -0
- package/src/entry.ssr.tsx +25 -0
- package/src/index.ts +1 -0
- package/src/kit/client.ts +21 -0
- package/src/kit/constants.ts +1 -0
- package/src/kit/context.ts +42 -0
- package/src/kit/globals.ts +22 -0
- package/src/kit/index.ts +4 -0
- package/src/kit/server.ts +21 -0
- package/src/kit/shared.ts +11 -0
- package/src/kit/types.ts +48 -0
- package/src/plugin/assets/index.ts +126 -0
- package/src/plugin/components/index.ts +0 -0
- package/src/plugin/index.ts +50 -0
- package/src/plugin/npm/index.ts +24 -0
- package/src/plugin/routes/index.ts +16 -0
- package/src/plugin/rpc/index.ts +14 -0
- package/src/plugin/types/index.ts +6 -0
- 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
|
+
}
|