Skip to content
Merged
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
2 changes: 1 addition & 1 deletion packages/nx-plugin/src/connection/serve-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const addTargetToServeLocal = async (
await applyGritQL(
tree,
runtimeConfigProvider,
`\`if ($cond) { $stmts }\` => raw\`if ($cond) {\n $stmts\n runtimeConfig.apis.${className} = '${options.url}';\n }\` where { $cond <: contains \`'serve-local'\`, $stmts <: within \`const applyOverrides = $_\` }`,
`\`if ($cond) { $stmts }\` => raw\`if ($cond) {\n $stmts\n runtimeConfig.apis.${className} = '${options.url}';\n }\` where { $cond <: contains \`'serve-local'\`, $stmts <: within \`const applyOverrides = $_\`, $stmts <: not contains \`runtimeConfig.apis.${className}\` }`,
);
}
};
38 changes: 11 additions & 27 deletions packages/nx-plugin/src/trpc/react/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ReactGeneratorSchema } from './schema';
import { runtimeConfigGenerator } from '../../ts/react-website/runtime-config/generator';
import { toScopeAlias } from '../../utils/npm-scope';
import { withVersions } from '../../utils/versions';
import { addSingleImport, applyGritQL, matchGritQL } from '../../utils/ast';
import { addSingleImport, applyGritQL } from '../../utils/ast';
import { toClassName } from '../../utils/names';
import { formatFilesInSubtree } from '../../utils/format';
import {
Expand Down Expand Up @@ -117,34 +117,18 @@ export async function reactGenerator(
);

// Wrap <App /> in QueryClientProvider if not already present
if (
!(await matchGritQL(
tree,
mainTsxPath,
'`<QueryClientProvider>$_</QueryClientProvider>`',
))
) {
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>`',
);
}
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>` where { $program <: not contains `<QueryClientProvider>$_</QueryClientProvider>` }',
);

// Wrap <App /> in the tRPC client provider if not already present
if (
!(await matchGritQL(
tree,
mainTsxPath,
`\`<${clientProviderName}>$_</${clientProviderName}>\``,
))
) {
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${clientProviderName}><App /></${clientProviderName}>\``,
);
}
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${clientProviderName}><App /></${clientProviderName}>\` where { $program <: not contains \`<${clientProviderName}>$_</${clientProviderName}>\` }`,
);

await addTargetToServeLocal(
tree,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-plugin/src/ts/nx-generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const tsNxGeneratorGenerator = async (
await applyGritQL(
tree,
joinPathFragments('docs', 'astro.config.mjs'),
`\`items: [$items]\` where { $items <: within \`sidebar: [$_]\`, $items <: contains \`'ts#project'\`, $items += \`, { label: '${name}', link: '/guides/${enhancedOptions.nameKebabCase}' }\` }`,
`\`items: [$items]\` where { $items <: within \`sidebar: [$_]\`, $items <: contains \`'ts#project'\`, $items <: not contains \`'/guides/${enhancedOptions.nameKebabCase}'\`, $items += \`, { label: '${name}', link: '/guides/${enhancedOptions.nameKebabCase}' }\` }`,
);
} else {
// Local generator in a project other than nx-plugin-for-aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { runtimeConfigGenerator } from '../../react-website/runtime-config/generator';
import { toScopeAlias } from '../../../utils/npm-scope';
import { withVersions } from '../../../utils/versions';
import { addSingleImport, applyGritQL, matchGritQL } from '../../../utils/ast';
import { addSingleImport, applyGritQL } from '../../../utils/ast';
import { toClassName } from '../../../utils/names';
import { formatFilesInSubtree } from '../../../utils/format';
import {
Expand Down Expand Up @@ -130,34 +130,18 @@ export async function tsStrandsAgentReactConnectionGenerator(
);

// Wrap <App /> in QueryClientProvider if not already present
if (
!(await matchGritQL(
tree,
mainTsxPath,
'`<QueryClientProvider>$_</QueryClientProvider>`',
))
) {
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>`',
);
}
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>` where { $program <: not contains `<QueryClientProvider>$_</QueryClientProvider>` }',
);

// Wrap <App /> in the agent client provider if not already present
if (
!(await matchGritQL(
tree,
mainTsxPath,
`\`<${clientProviderName}>$_</${clientProviderName}>\``,
))
) {
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${clientProviderName}><App /></${clientProviderName}>\``,
);
}
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${clientProviderName}><App /></${clientProviderName}>\` where { $program <: not contains \`<${clientProviderName}>$_</${clientProviderName}>\` }`,
);

await addStrandsAgentTargetToServeLocal(
tree,
Expand Down
62 changes: 23 additions & 39 deletions packages/nx-plugin/src/utils/connection/open-api/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { kebabCase, toClassName } from '../../names';
import { sortObjectKeys } from '../../object';
import { updateGitIgnore } from '../../git';
import runtimeConfigGenerator from '../../../ts/react-website/runtime-config/generator';
import { addSingleImport, applyGritQL, matchGritQL } from '../../ast';
import { addSingleImport, applyGritQL } from '../../ast';
import { addTargetToServeLocal } from '../../../connection/serve-local';
import { withVersions } from '../../versions';

Expand Down Expand Up @@ -210,47 +210,31 @@ export const addOpenApiReactClient = async (
);

// Add the query client provider if it doesn't exist already
if (
!(await matchGritQL(
tree,
mainTsxPath,
'`<QueryClientProvider>$_</QueryClientProvider>`',
))
) {
await addSingleImport(
tree,
mainTsxPath,
'QueryClientProvider',
'./components/QueryClientProvider',
);
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>`',
);
}
await addSingleImport(
tree,
mainTsxPath,
'QueryClientProvider',
'./components/QueryClientProvider',
);
await applyGritQL(
tree,
mainTsxPath,
'`<App />` => `<QueryClientProvider><App /></QueryClientProvider>` where { $program <: not contains `<QueryClientProvider>$_</QueryClientProvider>` }',
);

// Add the api provider if it does not exist
const providerName = `${apiNameClassName}Provider`;
if (
!(await matchGritQL(
tree,
mainTsxPath,
`\`<${providerName}>$_</${providerName}>\``,
))
) {
await addSingleImport(
tree,
mainTsxPath,
providerName,
`./components/${providerName}`,
);
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${providerName}><App /></${providerName}>\``,
);
}
await addSingleImport(
tree,
mainTsxPath,
providerName,
`./components/${providerName}`,
);
await applyGritQL(
tree,
mainTsxPath,
`\`<App />\` => \`<${providerName}><App /></${providerName}>\` where { $program <: not contains \`<${providerName}>$_</${providerName}>\` }`,
);

// Update serve-local on the website to use our local server.
// Callers that handle serve-local separately (e.g. agent connections) set skipServeLocal.
Expand Down
15 changes: 3 additions & 12 deletions packages/nx-plugin/src/utils/shared-shadcn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import tsProjectGenerator from '../ts/lib/generator';
import { configureTsProject } from '../ts/lib/ts-project-utils';
import { formatFilesInSubtree } from './format';
import { getNpmScopePrefix, toScopeAlias } from './npm-scope';
import { applyGritQL, matchGritQL } from './ast';
import { applyGritQL } from './ast';
import {
PACKAGES_DIR,
SHARED_SHADCN_DIR,
Expand Down Expand Up @@ -68,20 +68,11 @@ const addSharedShadcnEslintRules = async (

// shadcn generates aliased imports from components.json, which conflict with our
// relative-import lint rule. This rule is therefore disabled for common-shadcn.
const hasRule = await matchGritQL(
tree,
eslintConfigPath,
'`@nx/enforce-module-boundaries`',
);
if (hasRule) {
return;
}

// Append rule config to the exports array (no leading comma — GritQL handles it)
// The `not contains` guard makes this idempotent.
await applyGritQL(
tree,
eslintConfigPath,
"`export default [$items]` where { $items += `{ files: ['**/*.{ts,tsx,js,jsx}'], rules: { '@nx/enforce-module-boundaries': 'off' } }` }",
"`export default [$items]` where { $items <: not contains `@nx/enforce-module-boundaries`, $items += `{ files: ['**/*.{ts,tsx,js,jsx}'], rules: { '@nx/enforce-module-boundaries': 'off' } }` }",
);
};

Expand Down
Loading