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

Setup turborepo, second try #52

Merged
merged 5 commits into from
Feb 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 0 additions & 41 deletions .github/actions/assert-build/action.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/actions/download-built-package/action.yml

This file was deleted.

10 changes: 9 additions & 1 deletion .github/actions/pnpm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ runs:
cache: 'pnpm'
- name: 'Install dependencies'
shell: 'bash'
run: pnpm install
run: |
pnpm -v
pnpm install --fix-lockfile
git_diff=$(git diff)
if [[ "$git_diff" -eq "" ]]; then
echo "Success: no lockfile differences" ;
else
echo "Error: lockfile differences detected";
fi
82 changes: 40 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,34 @@ concurrency:

env:
CI: true
# dist: ember-headless-form/dist
TURBO_API: http://127.0.0.1:9080
TURBO_TOKEN: foo-123
TURBO_TEAM: foo

jobs:
install_dependencies:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm

# build:
# name: Build Tests
# needs: [install_dependencies]
# timeout-minutes: 5
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: ./.github/actions/pnpm
# - uses: ./.github/actions/assert-build

lint:
name: Lint
runs-on: ubuntu-latest
needs:
- install_dependencies
# - build
steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
- run: pnpm build && pnpm i -f
# To be able to run glint, we need the dist directory
# - uses: ./.github/actions/download-built-package
- name: Lint + Format + Glint
run: pnpm lint

Expand All @@ -54,7 +50,6 @@ jobs:
timeout-minutes: 3
needs:
- install_dependencies
# - build
continue-on-error: true
strategy:
fail-fast: true
Expand All @@ -65,47 +60,48 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
# - uses: ./.github/actions/download-built-package
- run: pnpm build && pnpm i -f
- name: 'Change TS to ${{ matrix.typescript-scenario }}'
run: 'pnpm add --save-dev ${{ matrix.typescript-scenario}}'
working-directory: ./test-app
- name: 'Type checking'
run: |
pnpm --filter test-app exec tsc -v;
pnpm --filter test-app exec glint --version;
pnpm --filter test-app exec glint;
run: pnpm turbo typecheck

default_tests:
name: Default Tests
timeout-minutes: 5
runs-on: ubuntu-latest
needs:
- install_dependencies
# - build
steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
- run: pnpm build && pnpm i -f
# - uses: ./.github/actions/download-built-package
- run: pnpm --filter test-app test:ember
- run: pnpm test

floating_tests:
name: Floating Deps Test
timeout-minutes: 5
runs-on: ubuntu-latest
needs:
- install_dependencies
# - build
steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
- name: Install Dependencies (without lockfile)
run: rm pnpm-lock.yaml && pnpm install
- run: pnpm build && pnpm i -f
# - uses: ./.github/actions/download-built-package
- run: pnpm --filter test-app test:ember
- run: pnpm test

try_scenarios:
name: ${{ matrix.try-scenario }}
Expand All @@ -128,14 +124,14 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
- run: pnpm build && pnpm i -f
# - uses: ./.github/actions/download-built-package
- name: Run Tests
working-directory: ./test-app
run: >-
node_modules/.bin/ember try:one ${{ matrix.try-scenario }}
--skip-cleanup
run: node_modules/.bin/ember try:one ${{matrix.try-scenario}} --skip-cleanup --- pnpm turbo test

# https://github.com/changesets/action
release:
Expand All @@ -153,9 +149,12 @@ jobs:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: TurboRepo local server
uses: felixmosh/turborepo-gh-artifacts@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pnpm
- run: pnpm build && pnpm i -f
# - uses: ./.github/actions/download-built-package
- run: pnpm build
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
Expand All @@ -170,7 +169,8 @@ jobs:
publishDocs:
name: Publish Docs to Cloudflare Pages
runs-on: ubuntu-latest
# needs: build
needs:
- install_dependencies
permissions:
contents: read
deployments: write
Expand All @@ -180,9 +180,7 @@ jobs:
with:
persist-credentials: false
- uses: ./.github/actions/pnpm
- run: pnpm build && pnpm i -f
# - uses: ./.github/actions/download-built-package
- run: pnpm build:docs-app
- run: pnpm build:docs
- name: Publish to Cloudflare Pages
id: publishStep
uses: cloudflare/pages-action@1
Expand All @@ -198,4 +196,4 @@ jobs:
## Preview URLs
Env: ${{ steps.publishStep.outputs.environment }}
Docs: ${{ steps.publishStep.outputs.url }}
# # api docs: ${{ steps.publishStep.outputs.url }}/api/modules.html
# # api docs: ${{ steps.publishStep.outputs.url }}/api/modules.html
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist/
node_modules/

# misc
.turbo/
/.env*
/.pnp*
/.pnpm-debug.log
Expand Down
4 changes: 3 additions & 1 deletion docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"start": "ember serve",
"test:ember": "ember test"
"test:ember": "ember test",
"_syncPnpm": "pnpm sync-pnpm"
},
"devDependencies": {
"@babel/core": "^7.19.6",
Expand Down Expand Up @@ -103,6 +104,7 @@
"prettier-plugin-ember-template-tag": "^0.3.0",
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"sync-pnpm": "workspace:*",
"tailwindcss": "^3.1.8",
"typescript": "^4.8.4",
"webpack": "^5.74.0"
Expand Down
3 changes: 3 additions & 0 deletions internal/sync-pnpm/bin/sync-pnpm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import syncPnpm from '../index.js';

await syncPnpm();
41 changes: 41 additions & 0 deletions internal/sync-pnpm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { join, dirname } from 'node:path';
import { createRequire } from 'node:module';

import { getPackages } from '@manypkg/get-packages';
import { findRoot } from '@manypkg/find-root';
import { readJson, pathExists } from 'fs-extra/esm';
import { hardLinkDir } from '@pnpm/fs.hard-link-dir';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhhh - this is interesting!

Hard link (or copy if linking fails) all files from a directory to several target directories.

So essentially this sync file forces pnpm to hard link the dependencies one way or another so that we don't have to continually pnpm i -f anytime we make a change in the addon source and want to see it in the test-app/docs-app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. Also it does only this, it does not try to re-install/shuffle things around.

In an earlier attempt, I tried to just use pnpm i -f in a turbo step, but when things run in parallel, this would lead to weird errors, as pnpm i -f would temporarily remove things from node_modules and add them back moments later, but in the meantime some parallel build would just fail as it would miss some dependencies in node_modules.

So this does just adds back the missing hard links of our /dist folder, and nothing else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing!!

So is the current development process now (for something like docs-app):

  1. make a change in ember-headless-form
  2. pnpm build
  3. see the update in the docs-app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly, that should work (assuming you have pnpm start or pnpm start:docs running, to continuously rebuild the app).

It is a bit of a regression compared to other v2 addon setups (e.g. using yarn), where this injected thing does not exist (but instead other peer dependency related problems), so you could just run start and it would watch the addon and the test-app. But not a regression compared to the previous state of this addon, because we had to run pnpm i -f again and again, so this should make it better at least!

Copy link
Contributor

Choose a reason for hiding this comment

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

(Definitely copying this for toucan-core)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just realized that the pnpm build script does too much for this use case, as it builds the addons and the apps (test and docs). Will need another iteration!

import resolvePackagePath from 'resolve-package-path';

const require = createRequire(import.meta.url);

const syncDir = './dist';

export default async function syncPnpm(dir = process.cwd()) {
const root = await findRoot(dir);
const ownPackageJson = await readJson(join(dir, 'package.json'));
const ownDependencies = [
...Object.keys(ownPackageJson.dependencies ?? {}),
...Object.keys(ownPackageJson.devDependencies ?? {}),
];

const localPackages = (await getPackages(root.rootDir)).packages;

const packagesToSync = localPackages.filter(
(p) =>
p.packageJson.name !== 'sync-pnpm' &&
ownDependencies.includes(p.packageJson.name)
);

for (const pkg of packagesToSync) {
const syncFrom = join(pkg.dir, syncDir);
const resolvedPackagePath = dirname(
resolvePackagePath(pkg.packageJson.name, dir)
);
const syncTo = join(resolvedPackagePath, syncDir);

if (await pathExists(syncFrom)) {
await hardLinkDir(syncFrom, [syncTo]);
}
}
}
19 changes: 19 additions & 0 deletions internal/sync-pnpm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "sync-pnpm",
"version": "0.0.0",
"private": true,
"description": "Sync build artifacts of workspace packages to pnpm injected/hard linked copies",
"repository": "",
"license": "MIT",
"author": "",
"main": "index.js",
"bin": "bin/sync-pnpm.js",
"type": "module",
"dependencies": {
"@manypkg/find-root": "^2.1.0",
"@manypkg/get-packages": "^2.1.0",
"@pnpm/fs.hard-link-dir": "^1.0.3",
"fs-extra": "^11.1.0",
"resolve-package-path": "^4.0.3"
}
}
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
"author": "CrowdStrike UX Team",
"scripts": {
"release": "changeset publish",
"prepare": "pnpm build",
"build": "pnpm --filter ember-headless-form build && pnpm --filter '@ember-headless-form/*' build",
"build:docs-app": "pnpm --filter 'docs-app' build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:tests": "pnpm --filter test-app start",
"build:docs": "pnpm turbo build --filter docs-app",
"start": "pnpm start:tests",
"start:docs": "pnpm turbo --filter docs-app start",
"start:tests": "pnpm turbo --filter test-app start",
"start:addon": "pnpm --filter !test-app start --no-watch.clearScreen",
"test": "pnpm --filter test-app test",
"lint": "pnpm --filter '*' lint",
"build": "pnpm turbo build",
"test": "pnpm turbo --filter test-app test",
"test:docs": "pnpm turbo --filter docs-app test",
"lint": "pnpm turbo lint",
"lint:fix": "pnpm --filter '*' lint:fix"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"concurrently": "^7.6.0",
"prettier": "^2.8.3"
"prettier": "^2.8.3",
"turbo": "^1.7.4"
},
"pnpm": {
"overrides": {
Expand Down