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

Fix codegen js generate #1467

Closed
wants to merge 5 commits into from
Closed
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
5 changes: 0 additions & 5 deletions .changeset/chatty-parrots-care.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/clean-timers-peel.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/early-taxis-compete.md

This file was deleted.

14 changes: 0 additions & 14 deletions .changeset/fast-poems-wash.md

This file was deleted.

10 changes: 0 additions & 10 deletions .changeset/forty-houses-taste.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/four-toes-shout.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/fuzzy-singers-check.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changeset/gentle-rabbits-serve.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/orange-socks-shave.md

This file was deleted.

25 changes: 0 additions & 25 deletions .changeset/pink-bottles-bow.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/shy-jokes-flow.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
'@shopify/cli-hydrogen': patch
'@shopify/create-hydrogen': patch
'@shopify/cli-hydrogen': patch
---

Fix codegen commands for generated projects
Fix codegen generation cli command for js projects
17 changes: 0 additions & 17 deletions .changeset/smart-ways-destroy.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/sweet-points-walk.md

This file was deleted.

26 changes: 0 additions & 26 deletions .changeset/tender-teachers-allow.md

This file was deleted.

23 changes: 0 additions & 23 deletions .changeset/unlucky-stingrays-live.md

This file was deleted.

10 changes: 10 additions & 0 deletions examples/customer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# customer-api

## 0.0.1

### Patch Changes

- Updated dependencies [[`81400439`](https://github.com/Shopify/hydrogen/commit/814004397c1d17ef0a53a425ed28a42cf67765cf), [`a6f397b6`](https://github.com/Shopify/hydrogen/commit/a6f397b64dc6a0d856cb7961731ee1f86bf80292), [`3464ec04`](https://github.com/Shopify/hydrogen/commit/3464ec04a084e1ceb30ee19874dc1b9171ce2b34), [`7fc088e2`](https://github.com/Shopify/hydrogen/commit/7fc088e21bea47840788cb7c60f873ce1f253128), [`867e0b03`](https://github.com/Shopify/hydrogen/commit/867e0b033fc9eb04b7250baea97d8fd49d26ccca), [`a4279cc5`](https://github.com/Shopify/hydrogen/commit/a4279cc5be353c24aa3f0881195d2c5ff4f5e8d0), [`ad45656c`](https://github.com/Shopify/hydrogen/commit/ad45656c5f663cc1a60eab5daab4da1dfd0e6cc3), [`58dc68de`](https://github.com/Shopify/hydrogen/commit/58dc68de2f71d12f1275961e160faa740387cdb5), [`f24e3424`](https://github.com/Shopify/hydrogen/commit/f24e3424c8e2b363b181b71fcbd3e45f696fdd3f), [`66a48573`](https://github.com/Shopify/hydrogen/commit/66a4857387148b6a104df5783314c74aca8aada0), [`0ae7cbe2`](https://github.com/Shopify/hydrogen/commit/0ae7cbe280d8351126e11dc13f35d7277d9b2d86), [`ad45656c`](https://github.com/Shopify/hydrogen/commit/ad45656c5f663cc1a60eab5daab4da1dfd0e6cc3)]:
- @shopify/[email protected]
- @shopify/[email protected]
- @shopify/[email protected]
8 changes: 4 additions & 4 deletions examples/customer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "customer-api",
"private": true,
"sideEffects": false,
"version": "0.0.0",
"version": "0.0.1",
"scripts": {
"build": "shopify hydrogen build",
"dev": "shopify hydrogen dev",
Expand All @@ -15,9 +15,9 @@
"dependencies": {
"@remix-run/react": "2.1.0",
"@shopify/cli": "3.50.0",
"@shopify/cli-hydrogen": "^5.4.3",
"@shopify/hydrogen": "^2023.7.11",
"@shopify/remix-oxygen": "^1.1.1",
"@shopify/cli-hydrogen": "^6.0.0",
"@shopify/hydrogen": "^2023.10.0",
"@shopify/remix-oxygen": "^2.0.0",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"isbot": "^3.6.6",
Expand Down
4 changes: 2 additions & 2 deletions examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@remix-run/express": "2.1.0",
"@remix-run/node": "2.1.0",
"@remix-run/react": "2.1.0",
"@shopify/hydrogen": "^2023.7.11",
"@shopify/hydrogen": "^2023.10.0",
"compression": "^1.7.4",
"cross-env": "^7.0.3",
"express": "^4.18.2",
Expand All @@ -28,7 +28,7 @@
"@remix-run/dev": "2.1.0",
"@remix-run/eslint-config": "2.1.0",
"@shopify/cli": "3.50.0",
"@shopify/cli-hydrogen": "^5.4.3",
"@shopify/cli-hydrogen": "^6.0.0",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.17",
"@types/morgan": "^1.9.4",
Expand Down
41 changes: 41 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# @shopify/cli-hydrogen

## 6.0.0

### Major Changes

- Update to Remix v2. Remix is now a peer dependency and its version is no longer pinned. This means that you can upgrade to newer Remix 2.x versions without upgrading Hydrogen. ([#1289](https://github.com/Shopify/hydrogen/pull/1289)) by [@frandiox](https://github.com/frandiox)

### Breaking changes

Please check the [Remix v2 release notes](https://github.com/remix-run/remix/releases/tag/remix%402.0.0) to see what needs to be changed in your app code. Common changes include:

- Renaming types prefixed with `V2_`. For example, `V2_MetaFunction` is now `MetaFunction`.
- Renaming other types like `LoaderArgs` and `ActionArgs`, which are now `LoaderFunctionArgs` and `ActionFunctionArgs` respectively.

If you were not already using v2 flags, follow the official [Remix migration guide](https://remix.run/docs/en/main/start/v2) before upgrading to v2.

### Minor Changes

- The Codegen feature is now considered stable and related dependencies have been updated. Use `--codegen` flag instead of `--codegen-unstable` to generate code from your GraphQL queries. ([#1108](https://github.com/Shopify/hydrogen/pull/1108)) by [@frandiox](https://github.com/frandiox)

### Patch Changes

- Updated internal dependencies to improve terminal output. ([#1456](https://github.com/Shopify/hydrogen/pull/1456)) by [@vincentezw](https://github.com/vincentezw)

Please update the `@shopify/cli` dependency in your app to avoid duplicated subdependencies:

```diff
"dependencies": {
- "@shopify/cli": "3.49.2",
+ "@shopify/cli": "3.50.0",
}
```

- Update Storefront api endpoint to 2023-10 ([#1431](https://github.com/Shopify/hydrogen/pull/1431)) by [@wizardlyhel](https://github.com/wizardlyhel)

- Fix codegen commands for generated projects ([#1464](https://github.com/Shopify/hydrogen/pull/1464)) by [@wizardlyhel](https://github.com/wizardlyhel)

- Updated dependencies [[`a6f397b6`](https://github.com/Shopify/hydrogen/commit/a6f397b64dc6a0d856cb7961731ee1f86bf80292), [`7fc088e2`](https://github.com/Shopify/hydrogen/commit/7fc088e21bea47840788cb7c60f873ce1f253128), [`ad45656c`](https://github.com/Shopify/hydrogen/commit/ad45656c5f663cc1a60eab5daab4da1dfd0e6cc3), [`ad45656c`](https://github.com/Shopify/hydrogen/commit/ad45656c5f663cc1a60eab5daab4da1dfd0e6cc3), [`66a48573`](https://github.com/Shopify/hydrogen/commit/66a4857387148b6a104df5783314c74aca8aada0), [`0ae7cbe2`](https://github.com/Shopify/hydrogen/commit/0ae7cbe280d8351126e11dc13f35d7277d9b2d86), [`ad45656c`](https://github.com/Shopify/hydrogen/commit/ad45656c5f663cc1a60eab5daab4da1dfd0e6cc3)]:
- @shopify/[email protected]
- @shopify/[email protected]
- @shopify/[email protected]

## 5.5.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.5.1",
"version": "6.0.0",
"commands": {
"hydrogen:build": {
"id": "hydrogen:build",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"access": "public",
"@shopify:registry": "https://registry.npmjs.org"
},
"version": "5.5.1",
"version": "6.0.0",
"license": "MIT",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"@graphql-codegen/cli": "5.0.0",
"@oclif/core": "2.11.7",
"@shopify/cli-kit": "3.50.0",
"@shopify/hydrogen-codegen": "^0.0.2",
"@shopify/hydrogen-codegen": "^0.1.0",
"@shopify/mini-oxygen": "^2.2.3",
"@shopify/oxygen-cli": "^2.3.2",
"ansi-escapes": "^6.2.0",
Expand All @@ -60,8 +60,8 @@
"peerDependencies": {
"@remix-run/dev": "^2.1.0",
"@remix-run/react": "^2.1.0",
"@shopify/hydrogen-react": "^2023.7.6",
"@shopify/remix-oxygen": "^1.1.8"
"@shopify/hydrogen-react": "^2023.10.0",
"@shopify/remix-oxygen": "^2.0.0"
},
"peerDependenciesMeta": {
"@remix-run/dev": {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/hydrogen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ export async function runCodegen({

console.log(''); // New line

// Use root file to determine if we're using TypeScript or JavaScript
const rootFile = remixConfig?.routes?.root?.file;

const generatedFiles = await codegen({
...remixConfig,
configFilePath: codegenConfigPath,
forceSfapiVersion,
watch,
isJSProject: /jsx$/.test(rootFile || ''), // Default to false if rootFile is undefined
});

if (!watch) {
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (isStandaloneProcess) {
rootDirectory: process.argv[2]!,
appDirectory: process.argv[3]!,
configFilePath: process.argv[4],
isJSProject: process.argv[5] === 'js',
watch: true,
});
}
Expand Down Expand Up @@ -99,6 +100,7 @@ type CodegenOptions = ProjectDirs & {
watch?: boolean;
configFilePath?: string;
forceSfapiVersion?: string;
isJSProject?: boolean;
};

export async function codegen(options: CodegenOptions) {
Expand Down Expand Up @@ -165,12 +167,13 @@ async function generateTypes({
async function generateDefaultConfig(
{rootDirectory, appDirectory}: ProjectDirs,
forceSfapiVersion?: string,
isJSProject?: boolean,
): Promise<LoadCodegenConfigResult> {
const {schema, preset, pluckConfig} = await import(
'@shopify/hydrogen-codegen'
);

const tsDefaultGlob = '*!(*.d).{ts,tsx}'; // No d.ts files
const defaultGlob = isJSProject ? '*!(*.d).{js,jsx}' : '*!(*.d).{ts,tsx}'; // No d.ts files
const appDirRelative = relativePath(rootDirectory, appDirectory);

return {
Expand All @@ -183,8 +186,8 @@ async function generateDefaultConfig(
preset,
schema,
documents: [
tsDefaultGlob, // E.g. ./server.ts
joinPath(appDirRelative, '**', tsDefaultGlob), // E.g. app/routes/_index.tsx
defaultGlob, // E.g. ./server.(t|j)s
joinPath(appDirRelative, '**', defaultGlob), // E.g. app/routes/_index.(t|j)sx
],

...(!!forceSfapiVersion && {
Expand Down
Loading