Skip to content

Commit

Permalink
Misc/fix nx (#3581)
Browse files Browse the repository at this point in the history
## Description
  • Loading branch information
samijaber committed Sep 26, 2024
1 parent c6b7a8c commit f6a5bc4
Show file tree
Hide file tree
Showing 54 changed files with 92 additions and 264 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
run: yarn workspace @builder.io/sdks eslint

- name: Typecheck
run: yarn nx typecheck @builder.io/sdks
run: yarn g:nx typecheck @builder.io/sdks

- name: Run tests
run: yarn nx test @builder.io/sdks
run: yarn g:nx test @builder.io/sdks

- name: Lint changesets
run: yarn g:changeset version
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
cache-install-state: true

- name: Run E2E tests
run: yarn nx test @e2e/${{ matrix.e2e-server }}
run: yarn g:nx test @e2e/${{ matrix.e2e-server }}

- name: Upload Playwright Report
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
cache-install-state: true

- name: Run snippets tests
run: yarn nx test @snippet/${{ matrix.snippet }}
run: yarn g:nx test @snippet/${{ matrix.snippet }}

- name: Upload Playwright Report
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
cache-install-state: true

- name: Build Core
run: yarn nx build @builder.io/sdk
run: yarn g:nx build @builder.io/sdk

gen1-react-sdk:
name: Gen 1 React SDK
Expand All @@ -200,7 +200,7 @@ jobs:
cache-install-state: true

- name: Run E2E tests
run: yarn nx test @e2e/${{ matrix.e2e-server }}
run: yarn g:nx test @e2e/${{ matrix.e2e-server }}

build:
runs-on: ubuntu-latest
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"ci:lint": "prettier --check '**/*.{js,jsx,ts,tsx}'",
"lint:fix": "prettier --write '**/*.{js,jsx,ts,tsx}'",
"update-npm-dependency": "zx ./scripts/update-npm-dependency.mjs",
"g:changeset": "changeset"
"g:changeset": "changeset",
"g:nx": "nx"
},
"engines": {
"yarn": ">= 3.0.0"
Expand All @@ -42,5 +43,13 @@
"@builder.io/react": "workspace:*",
"@builder.io/sdk": "workspace:*",
"react-native-builder-bob@^0.21.3": "patch:react-native-builder-bob@npm%3A0.21.3#./.yarn/patches/react-native-builder-bob-npm-0.21.3-71f7168ad6.patch"
},
"dependenciesMeta": {
"nx": {
"built": false
},
"nx-cloud": {
"built": false
}
}
}
2 changes: 0 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"glob": "^7.2.3",
"glob-promise": "^4.2.2",
"jest": "27.4.7",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"rollup": "^2.38.5",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-commonjs": "^10.1.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
"scripts": {
"ci:changeset": "changeset status --since=main",
"fix-core-version": "yarn workspace @builder.io/react fix-core-version",
"build:sdks": "yarn nx run-many --skip-nx-cache -t build [email protected]/sdk-\\*,@builder.io/react",
"build:sdks": "yarn g:nx run-many --skip-nx-cache -t build [email protected]/sdk-\\*,@builder.io/react",
"ci:release": "yarn build:sdks && yarn run fix-core-version && yarn g:changeset publish"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0"
"@changesets/cli": "^2.27.1"
}
}
4 changes: 1 addition & 3 deletions packages/react-tests/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "SERVER_NAME=gen1-next yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=gen1-next yarn g:nx test:e2e @sdk/tests",
"serve": "yarn start"
},
"dependencies": {
Expand All @@ -23,8 +23,6 @@
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"typescript": "^5"
},
"nx": {
Expand Down
4 changes: 1 addition & 3 deletions packages/react-tests/react-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "remix build",
"dev": "remix dev",
"serve": "remix-serve build",
"test": "SERVER_NAME=gen1-remix yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=gen1-remix yarn g:nx test:e2e @sdk/tests",
"typecheck": "tsc"
},
"dependencies": {
Expand All @@ -16,8 +16,6 @@
"@remix-run/serve": "^1.14.3",
"@sdk/tests": "workspace:*",
"isbot": "^3.6.5",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/react-tests/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
"tsc": "tsc",
"build": "tsc && vite build",
"serve": "vite preview",
"test": "SERVER_NAME=gen1-react yarn nx test:e2e @sdk/tests"
"test": "SERVER_NAME=gen1-react yarn g:nx test:e2e @sdk/tests"
},
"dependencies": {
"@builder.io/react": "workspace:*",
"@builder.io/widgets": "^1.2.24",
"@sdk/tests": "workspace:*",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
2 changes: 0 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"cross-env": "^5.0.1",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"prettier": "^3.2.5",
"prompt": "^1.0.0",
"react": ">=16.8.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/sdks-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
"typescript": "^5.1.6"
},
"dependencies": {
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"traverse": "^0.6.7",
"zod": "^3.20.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/sdks-tests/scripts/build-servers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

if [ $SERVER_NAME = 'all' ]; then
echo "Building all \"@$TEST_TYPE/*\" servers"
yarn nx run-many -p @$TEST_TYPE/* -t build
yarn g:nx run-many -p @$TEST_TYPE/* -t build
else
SERVERS=$(echo $SERVER_NAME | tr ',' '\n' | xargs -I _ echo @$TEST_TYPE/_ | tr '\n' ',')
echo "Building servers: $SERVERS"
yarn nx run-many -p $SERVERS -t build
yarn g:nx run-many -p $SERVERS -t build
fi
4 changes: 2 additions & 2 deletions packages/sdks/PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The SDKs are meant to be published using the Changeset+Github Action workflow, a
When testing something, you are free to publish `dev` versions for just one SDK and skip everything mentioned here. Go to the SDK folder of your choice and:

- `yarn version prerelease` to bump the version to the next prerelease (e.g. `0.5.9-1`)
- `yarn nx release --tag=dev` to build and release the SDK
- `yarn g:nx release --tag=dev` to build and release the SDK

# Steps

Expand Down Expand Up @@ -45,7 +45,7 @@ yarn g:changeset version
- release the packages:

```bash
yarn nx ci:release
yarn g:nx ci:release
```

## 5- Update examples (optional)
Expand Down
6 changes: 3 additions & 3 deletions packages/sdks/docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ The root of the yarn monorepo is the same as the github repo and called `@builde

## Nx

Nx is a tool that handles the complexity of building your monorepo when there are a ton of inter-dependencies. By calling `yarn nx build` (instead of `yarn build`), Nx will run all pre-requisite steps so that your `build` command is up-to-date. This vastly simplifies local development & testing.
Nx is a tool that handles the complexity of building your monorepo when there are a ton of inter-dependencies. By calling `yarn g:nx build` (instead of `yarn build`), Nx will run all pre-requisite steps so that your `build` command is up-to-date. This vastly simplifies local development & testing.

It will also cache the results of each step, so that if you run `yarn nx build` again, it will only run the steps that have changed.
It will also cache the results of each step, so that if you run `yarn g:nx build` again, it will only run the steps that have changed.

# Gen2 SDKs

Expand All @@ -37,7 +37,7 @@ Here is the overall picture of what happens during the gen2 SDKs build process:
- Each individual gen2 SDK is then built using its own build tooling (some use Vite/Rollup, other require more specialized libraries specific to the intended framework).
- Finally, the integration tests are built and run. Those depend on the SDKs being built first, and also the integration tests (which live under `package/sdks-tests`).

You can visualize all of these relationships by using the Nx graph feature: run `yarn nx graph` anywhere in the mono-repo to launch the graph viewer.
You can visualize all of these relationships by using the Nx graph feature: run `yarn g:nx graph` anywhere in the mono-repo to launch the graph viewer.

### SDKs multi bundles

Expand Down
20 changes: 10 additions & 10 deletions packages/sdks/docs/DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

## Build an SDK

`yarn nx build @builder.io/sdk-svelte` (replace `svelte` with the SDK you want to build)
`yarn g:nx build @builder.io/sdk-svelte` (replace `svelte` with the SDK you want to build)

For Gen1 React SDK, that would be `yarn nx build @builder.io/react`.
For Gen1 React SDK, that would be `yarn g:nx build @builder.io/react`.

## Integration Testing

Expand All @@ -28,32 +28,32 @@ This new test will run against every SDK & framework combination.
If you want to run the integration tests locally, you can do so by doing the following:

- Go to the server of your choice in [`packages/sdks/e2e`](https://github.com/BuilderIO/builder/tree/main/packages/sdks/e2e) (or [`packages/react-tests`](https://github.com/BuilderIO/builder/tree/main/packages/react-tests) for gen1 react sdk)
- Run the Playwright tests: `yarn nx test`
- Run the Playwright tests: `yarn g:nx test`

Alternatively, you can call `yarn nx test @e2e/svelte` from anywhere in the mono-repo (replace `@e2e/svelte` with the name of the server you want to run).
Alternatively, you can call `yarn g:nx test @e2e/svelte` from anywhere in the mono-repo (replace `@e2e/svelte` with the name of the server you want to run).

NOTE: if you want to run multiple tests, you can call the underlying test command and provide it a comma-separated list of servers to test:

```bash
SERVER_NAME=svelte,react,nuxt yarn nx test:e2e @sdk/tests
SERVER_NAME=svelte,react,nuxt yarn g:nx test:e2e @sdk/tests
```

For convenience, there are `yarn nx e2e:run:*` commands that you can use to build and run the tests for a specific SDK.
For convenience, there are `yarn g:nx e2e:run:*` commands that you can use to build and run the tests for a specific SDK.

### Snippet tests

Snippet tests are similar to e2e tests:

- servers are located in [`packages/sdks/snippets`](https://github.com/BuilderIO/builder/tree/main/packages/sdks/snippets)
- tests are located in [`tests/src/snippet-tests`](https://github.com/BuilderIO/builder/tree/main/tests/src/snippet-tests)
- can be run with `SERVER_NAME=svelte,react,nuxt yarn nx test:snippet @sdk/tests`
- can be run with `SERVER_NAME=svelte,react,nuxt yarn g:nx test:snippet @sdk/tests`

Snippet tests make real network requests to the Builder API. This means they are flaky and might fail. We prefer to do this so that the snippets can be shared with customers as-is,
without having to re-write the data-fetching logic.

### Debug tests

By adding the `--debug` flag (e.g. `yarn nx e2e @e2e/svelte --debug`), you can run the tests in a browser window with an interactive Playwright. This is useful for debugging.
By adding the `--debug` flag (e.g. `yarn g:nx e2e @e2e/svelte --debug`), you can run the tests in a browser window with an interactive Playwright. This is useful for debugging.

When using the debug flag, it is recommended to add `.only` to the tests you want to debug, so that the others are temporarily ignored by playwright. See:

Expand All @@ -64,15 +64,15 @@ When using the debug flag, it is recommended to add `.only` to the tests you wan

If you want to run the integration server locally _without_ running any of the Playwright tests, you can do so by running:

- `yarn nx serve @e2e/sveltekit` (replace `@e2e/sveltekit` with the name of the server you want to run)
- `yarn g:nx serve @e2e/sveltekit` (replace `@e2e/sveltekit` with the name of the server you want to run)

### Live/real data testing

You can fetch real data from the Builder API instead of using the JSON mock files. Go to your e2e server, find the `getProps` call, and add `data: "real"` as an argument.

## sym-linking the SDK to your own project

- `yarn nx build` in your SDK folder (e.g. `packages/sdks/output/svelte`, or `packages/react` for gen1 React SDK)
- `yarn g:nx build` in your SDK folder (e.g. `packages/sdks/output/svelte`, or `packages/react` for gen1 React SDK)
- `npm link` in your SDK folder
- `npm link @builder.io/sdk-svelte` in your project folder (e.g. `examples/sveltekit`)

Expand Down
4 changes: 1 addition & 3 deletions packages/sdks/e2e/angular-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "ng run angular-app:serve-ssr",
"serve": "node dist/angular-app/server/main.js",
"build": "ng build && ng run angular-app:server",
"test": "SERVER_NAME=angular-ssr yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=angular-ssr yarn g:nx test:e2e @sdk/tests",
"prerender": "ng run angular-app:prerender"
},
"private": true,
Expand Down Expand Up @@ -44,8 +44,6 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"typescript": "~5.1.3"
}
}
4 changes: 1 addition & 3 deletions packages/sdks/e2e/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"serve": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "SERVER_NAME=angular yarn nx test:e2e @sdk/tests"
"test": "SERVER_NAME=angular yarn g:nx test:e2e @sdk/tests"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -35,8 +35,6 @@
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"typescript": "~5.1.3"
}
}
4 changes: 1 addition & 3 deletions packages/sdks/e2e/hydrogen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "shopify hydrogen dev",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"test": "SERVER_NAME=hydrogen yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=hydrogen yarn g:nx test:e2e @sdk/tests",
"serve": "shopify hydrogen preview",
"codegen": "shopify hydrogen codegen"
},
Expand Down Expand Up @@ -42,8 +42,6 @@
"@types/react-dom": "^18.2.7",
"eslint": "^8.20.0",
"eslint-plugin-hydrogen": "0.12.2",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"prettier": "^2.8.4",
"typescript": "^5.2.2",
"vite": "^5.1.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/sdks/e2e/nextjs-sdk-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "SERVER_NAME=nextjs-sdk-next-app yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=nextjs-sdk-next-app yarn g:nx test:e2e @sdk/tests",
"serve": "yarn start"
},
"dependencies": {
Expand All @@ -22,8 +22,6 @@
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.0.3",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"typescript": "^5"
},
"nx": {
Expand Down
6 changes: 2 additions & 4 deletions packages/sdks/e2e/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"generate": "nuxt generate",
"serve": "nuxt preview",
"postinstall": "nuxt prepare",
"test": "SERVER_NAME=nuxt yarn nx test:e2e @sdk/tests"
"test": "SERVER_NAME=nuxt yarn g:nx test:e2e @sdk/tests"
},
"dependencies": {
"@builder.io/sdk-vue": "workspace:*",
Expand All @@ -17,9 +17,7 @@
},
"devDependencies": {
"@types/node": "^18",
"nuxt": "^3.8.1",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0"
"nuxt": "^3.8.1"
},
"nx": {
"targets": {
Expand Down
4 changes: 1 addition & 3 deletions packages/sdks/e2e/qwik-city/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
"preview": "qwik build preview && vite preview --open",
"start": "vite --open --mode ssr",
"qwik": "qwik",
"test": "SERVER_NAME=qwik-city yarn nx test:e2e @sdk/tests",
"test": "SERVER_NAME=qwik-city yarn g:nx test:e2e @sdk/tests",
"serve": "yarn run dev"
},
"devDependencies": {
"@builder.io/qwik": "^1.5.1",
"@builder.io/qwik-city": "^1.2.19",
"@types/node": "^18.11.18",
"node-fetch": "3.3.0",
"nx": "^19.6.5",
"nx-cloud": "^19.0.0",
"typescript": "^5.1.6",
"vite": "^4.0.3",
"vite-tsconfig-paths": "3.5.0"
Expand Down
Loading

0 comments on commit f6a5bc4

Please sign in to comment.