Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: Better Analysis tool #2098

Draft
wants to merge 9 commits into
base: v2-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.20.0
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"editor.tabSize": 2,
"editor.inlineSuggest.showToolbar": "always",
"biome.enabled": true,
"editor.formatOnSave": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think we'd better not enable this feature in the workspace. It doesn't suit the development habits of all developers. Maybe you could move this setting to the VSCode global settings. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked the task as wip in order to sync my config in different workspace. when the task is ready for check will be remove :D

"editor.defaultFormatter": "biomejs.biome",
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
Expand Down
82 changes: 82 additions & 0 deletions js-plugins/visualizer/client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import path from 'node:path';
import { ParserOptions, transform } from '@babel/core';
import { JsPlugin, defineConfig } from '@farmfe/core';
import postCSSPlugin from '@farmfe/js-plugin-postcss';
import stylexExtendBabelPlugin from '@stylex-extend/babel-plugin';
import stylexBabelPlugin from '@stylexjs/babel-plugin';
// import Pages from 'vite-plugin-pages';
import { visualizer } from './src/server';

const defaultWd = process.cwd();

function stylex() {
return <JsPlugin>{
name: 'stylex',
transform: {
filters: {
moduleTypes: ['ts', 'tsx']
},
executor(param) {
// console.log(param.resolvedPath);
// console.log(param);
if (
param.resolvedPath === 'farmfe_plugin_react_is_react_refresh_boundary'
) {
return param;
}
const plugins: ParserOptions['plugins'] = ['typescript'];
if (param.resolvedPath.endsWith('.tsx')) {
plugins.push('jsx');
}
const res = transform(param.content, {
filename: param.resolvedPath,
parserOpts: {
plugins
},
plugins: [
stylexExtendBabelPlugin.withOptions({
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname
},
transport: 'props'
}),
stylexBabelPlugin.withOptions({
dev: false,
runtimeInjection: false,
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname
}
})
]
});
if (res && 'stylex' in res.metadata) {
if (
Array.isArray(res.metadata.stylex) &&
res.metadata.stylex.length > 0
) {
return {
content: res.code,
sourceMap: res?.map,
moduleType: 'tsx',
ignorePreviousSourceMap: true
};
}
}
return param;
}
}
};
}

export default defineConfig({
root: path.join(defaultWd, './src/client'),
plugins: [stylex(), '@farmfe/plugin-react', postCSSPlugin(), visualizer()]
// vitePlugins: [
// Pages({
// resolver: 'react',
// dirs: path.join(defaultWd, './src/client/pages')
// })
// ]
});
56 changes: 31 additions & 25 deletions js-plugins/visualizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.1.4",
"main": "./build/cjs/index.cjs",
"types": "./build/cjs/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./build/esm/index.mjs",
Expand All @@ -14,41 +13,48 @@
"./package.json": "./package.json"
},
"license": "MIT",
"dependencies": {
"@ant-design/icons-vue": "^7.0.1",
"@guolao/vue-monaco-editor": "^1.5.1",
"@types/ws": "^8.5.4",
"axios": "^1.5.0",
"bufferutil": "^4.0.8",
"core-js": "^3.30.1",
"envinfo": "^7.11.1",
"sirv": "^2.0.3",
"utf-8-validate": "^6.0.3",
"ws": "^8.14.2"
},
"devDependencies": {
"@farmfe/js-plugin-dts": "workspace:*",
"@farmfe/js-plugin-less": "workspace:*",
"@farmfe/js-plugin-postcss": "workspace:*",
"less": "^4.2.2",
"@farmfe/js-plugin-vue": "workspace:*",
"@types/envinfo": "^7.8.3",
"@types/koa": "^2.13.5",
"@vitejs/plugin-vue": "^4.4.0",
"@farmfe/plugin-react": "workspace:*",
"autoprefixer": "^10.4.14",
"vue": "^3.3.4",
"vue-router": "^4.2.1",
"ant-design-vue": "^4.1.2",
"pinia": "^2.1.7",
"koa": "^2.13.4",
"react":"18",
"react-dom":"18",
"react-refresh": "0.14.0",
"@types/react":"18",
"@types/react-dom":"18",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.2"
"tailwindcss": "^3.3.2",
"vite-bundle-analyzer":"^0.17.0",
"squarified": "^0.3.5",
"vite-plugin-pages":"^0.32.4",
"react-router": "^6.22.3",
"react-router-dom": "^6.22.3",
"@jridgewell/source-map": "^0.3.6",
"@stylexjs/postcss-plugin":"^0.10.1",
"@stylexjs/stylex":"^0.10.1",
"@stylexjs/babel-plugin":"^0.10.1",
"@babel/core": "^7.23.9",
"@types/babel__core": "^7.20.5",
"@stylex-extend/babel-plugin":"^0.6.0",
"@stylex-extend/react":"^0.6.0",
"@stylex-extend/core":"^0.6.0",
"clsx": "^2.1.1",
"foxact":"^0.2.29",
"unplugin-icons": "^0.22.0",
"@svgr/core": "^8.1.0",
"@svgr/plugin-jsx": "^8.1.0",
"@iconify-json/ph": "^1.1.12"
},
"scripts": {
"start": "cd src/client && farm start",
"start": "farm start --config ./client.config.ts",
"build": "pnpm build:plugin && cross-env FARM_FORMAT=esm farm build && pnpm build:client",
"build:plugin": "farm build",
"build:client": "cd src/client && farm build",
"preview": "cd src/client && farm preview",
"build:client": "farm build --config ./client.config.ts",
"preview": "farm preview --config ./client.config.ts",
"prepublishOnly": "npm run build"
},
"files": [
Expand Down
44 changes: 44 additions & 0 deletions js-plugins/visualizer/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const styleXPlugin = require("@stylexjs/babel-plugin");
const stylexExtendPlugin = require("@stylex-extend/babel-plugin");

module.exports = {
plugins: {
"@stylexjs/postcss-plugin": {
include: [
"src/client/pages/**/*.{js,jsx,ts,tsx}",
"src/client/themes/**/*.{js,jsx,ts,tsx}",
"src/client/components/**/*.{js,jsx,ts,tsx}",
],
babelConfig: {
parserOpts: {
plugins: ["jsx", "typescript"],
},
plugins: [
[
stylexExtendPlugin,
{
unstable_moduleResolution: {
type: "commonJS",
rootDir: __dirname,
},
transport: "props",
},
],
[
styleXPlugin,
{
runtimeInjection: false,
dev: false,
// Required for CSS variable support
unstable_moduleResolution: {
type: "commonJS",
rootDir: __dirname,
},
},
],
],
},
},
autoprefixer: {},
},
};
6 changes: 0 additions & 6 deletions js-plugins/visualizer/src/client/.postcssrc

This file was deleted.

35 changes: 35 additions & 0 deletions js-plugins/visualizer/src/client/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
ApplicationProvider,
setupTheme,
useApplicationContext
} from './context';
import { NavHead } from './components/nav-head/nav-head';
import './stylex.css';
import './reset.css';
import { useEffect } from 'react';
import { Inspect } from './components/inspect';

export function App() {
const { theme } = useApplicationContext();

useEffect(() => {
setupTheme(theme);
}, []);

return (
<ApplicationProvider key='app'>
<div
stylex={{
height: '100%',
width: '100%',
position: 'relative'
}}
>
<NavHead />
<div id='container' style={{ height: 'calc(100vh - 64px)' }}>
<Inspect />
</div>
</div>
</ApplicationProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Analysis() {
return <div>Analysis</div>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Analysis } from './analysis';
Loading
Loading