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

Working on swc plugin in rust to implement modulessuffixes #2442

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@
},
"workbench.editor.customLabels.patterns": {
"**/*.interceptor.ts*": "${filename}.${extname} (auto generated)"
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
85 changes: 85 additions & 0 deletions examples/magento-open-source/plugins/TestPluginLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Image } from '@graphcommerce/image'
import type { PluginConfig } from '@graphcommerce/next-config'
import { NextLink, type LogoProps } from '@graphcommerce/next-ui'
import type { SxProps, Theme } from '@mui/material'
import {
Box,
unstable_composeClasses as composeClasses,
generateUtilityClass,
Link,
} from '@mui/material'
import { useRouter } from 'next/router'
import { forwardRef } from 'react'

export const config: PluginConfig = {
module: '@graphcommerce/next-ui',
type: 'replace',
}

/** We're creating some boilerplate */
const name = 'GcLogo'
type LogoClassKey = 'logo' | 'parent'

type LogoClasses = Record<LogoClassKey, string>
type LogoClassProps = { classes?: Partial<LogoClasses> }

const getLogoUtilityClass = (slot: string) => generateUtilityClass(name, slot)

const useUtilityClasses = ({ classes }: LogoClassProps) =>
composeClasses({ logo: ['logo'], parent: ['parent'] }, getLogoUtilityClass, classes)

const commonLogoStyles: SxProps<Theme> = {
height: '100%',
width: 'max-content',
display: 'flex',
alignItems: 'center',
margin: '0 auto',
justifyContent: 'center',
pointerEvents: 'all',
}

function ProBadge() {
return (
<Box
sx={(theme) => ({
borderRadius: 1,
fontWeight: 600,
lineHeight: 1,
p: '2px 4px',
marginTop: '-6px',
ml: '4px',
background: theme.palette.text.primary,
color: theme.palette.background.default,
})}
>
Pro
</Box>
)
}

export const Logo = forwardRef<HTMLAnchorElement, LogoProps>((props, ref) => {
const { href = '/', image, sx } = props
const router = useRouter()
const classes = useUtilityClasses(props)

const shouldRedirect = router.asPath.split('?')[0] !== href

return (
<Link
component={shouldRedirect ? NextLink : 'div'}
href={shouldRedirect ? href : undefined}
ref={ref}
sx={[...(Array.isArray(sx) ? sx : [sx]), commonLogoStyles]}
className={classes.parent}
underline='none'
>
<Image
layout='fixed'
loading='eager'
{...image}
className={`${image.className} ${classes?.logo ?? ''}`}
/>
<ProBadge />
</Link>
)
})
1 change: 0 additions & 1 deletion packages/framer-next-pages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@emotion/react": "11.12.0",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.13.0",
"@graphcommerce/framer-next-pages": "9.0.0-canary.108",
"@graphcommerce/framer-scroller": "9.0.0-canary.108",
"@graphcommerce/framer-utils": "9.0.0-canary.108",
"@graphcommerce/image": "9.0.0-canary.108",
Expand Down
2 changes: 1 addition & 1 deletion packagesDev/next-config/dist/commands/copyFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Found in packages:
Source: ${sourcePath}`);
process.exit(1);
}
console.log(`Creating new file: ${file}`);
console.log(`Creating new file: ${file}\nSource: ${sourcePath}`);
debug('File does not exist yet');
}
// Skip if content is identical (including magic comment)
Expand Down
17 changes: 14 additions & 3 deletions packagesDev/next-config/dist/withGraphCommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const plugin_1 = require("inspectpack/plugin");
const webpack_1 = require("webpack");
const loadConfig_1 = require("./config/loadConfig");
const configToImportMeta_1 = require("./config/utils/configToImportMeta");
const InterceptorPlugin_1 = require("./interceptors/InterceptorPlugin");
const resolveDependenciesSync_1 = require("./utils/resolveDependenciesSync");
let graphcommerceConfig;
function domains(config) {
Expand Down Expand Up @@ -39,13 +38,25 @@ function withGraphCommerce(nextConfig, cwd = process.cwd()) {
...[...(0, resolveDependenciesSync_1.resolveDependenciesSync)().keys()].slice(1),
...(nextConfig.transpilePackages ?? []),
];
console.log((0, resolveDependenciesSync_1.resolveDependenciesSync)());
return {
...nextConfig,
bundlePagesRouterDependencies: true,
experimental: {
...nextConfig.experimental,
scrollRestoration: true,
swcPlugins: [...(nextConfig.experimental?.swcPlugins ?? []), ['@lingui/swc-plugin', {}]],
swcPlugins: [
...(nextConfig.experimental?.swcPlugins ?? []),
['@lingui/swc-plugin', {}],
[
'@graphcommerce/next-interceptors-swc',
{
moduleSuffixes: ['.interceptor', ''],
workspaceRoot: cwd,
packageMapping: Object.fromEntries((0, resolveDependenciesSync_1.resolveDependenciesSync)()),
},
],
],
},
i18n: {
...nextConfig.i18n,
Expand Down Expand Up @@ -155,7 +166,7 @@ function withGraphCommerce(nextConfig, cwd = process.cwd()) {
'@mui/system': '@mui/system/modern',
};
}
config.plugins.push(new InterceptorPlugin_1.InterceptorPlugin(graphcommerceConfig, !options.isServer));
// config.plugins.push(new InterceptorPlugin(graphcommerceConfig, !options.isServer))
return typeof nextConfig.webpack === 'function' ? nextConfig.webpack(config, options) : config;
},
};
Expand Down
17 changes: 15 additions & 2 deletions packagesDev/next-config/src/withGraphCommerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,26 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
...(nextConfig.transpilePackages ?? []),
]

console.log(resolveDependenciesSync())

return {
...nextConfig,
bundlePagesRouterDependencies: true,
experimental: {
...nextConfig.experimental,
scrollRestoration: true,
swcPlugins: [...(nextConfig.experimental?.swcPlugins ?? []), ['@lingui/swc-plugin', {}]],
swcPlugins: [
...(nextConfig.experimental?.swcPlugins ?? []),
['@lingui/swc-plugin', {}],
[
'@graphcommerce/next-interceptors-swc',
{
moduleSuffixes: ['.interceptor', ''],
workspaceRoot: cwd,
packageMapping: Object.fromEntries(resolveDependenciesSync()),
},
],
],
},
i18n: {
...nextConfig.i18n,
Expand Down Expand Up @@ -189,7 +202,7 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
}
}

config.plugins.push(new InterceptorPlugin(graphcommerceConfig, !options.isServer))
// config.plugins.push(new InterceptorPlugin(graphcommerceConfig, !options.isServer))

return typeof nextConfig.webpack === 'function' ? nextConfig.webpack(config, options) : config
},
Expand Down
2 changes: 2 additions & 0 deletions packagesDev/next-interceptors-swc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.wasm
/target
Loading
Loading