Skip to content

Commit

Permalink
Merge pull request #168 from CrowdStrike/turbo-and-sync-pnpm
Browse files Browse the repository at this point in the history
Turbo and sync pnpm
  • Loading branch information
joelamb authored May 22, 2023
2 parents cd03204 + 3e471a7 commit f594c15
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ node_modules/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/.turbo
/yarn-error.log

# ember-try
Expand Down
1 change: 1 addition & 0 deletions docs-app/.ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false,
"port": 4201,

/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
Expand Down
3 changes: 1 addition & 2 deletions docs-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ You will need the following things properly installed on your computer.
## Running / Development

* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).
* Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).
* Visit your app at [http://localhost:4201](http://localhost:4201).

### Code Generators

Expand Down
10 changes: 6 additions & 4 deletions docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "docs-app",
"version": "0.0.0",
"private": true,
"description": "Small description for docs-app goes here",
"description": "Documentation for the ember-headless-table addon",
"repository": "",
"license": "MIT",
"author": "",
Expand All @@ -19,7 +19,8 @@
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test:ember": "ember test"
"test:ember": "ember test",
"_syncPnpm": "pnpm sync-pnpm"
},
"devDependencies": {
"@babel/core": "^7.21.8",
Expand Down Expand Up @@ -103,7 +104,8 @@
"prettier": "^2.7.1",
"qunit": "^2.19.4",
"qunit-dom": "^2.0.0",
"tailwindcss": "^3.3.2",
"sync-pnpm": "workspace:*",
"tailwindcss": "^3.2.4",
"typescript": "^4.9.5",
"webpack": "^5.83.1"
},
Expand All @@ -120,7 +122,7 @@
"dompurify": "^2.4.5",
"ember-browser-services": "^4.0.4",
"ember-cached-decorator-polyfill": "^1.0.1",
"ember-headless-table": "workspace:../ember-headless-table",
"ember-headless-table": "workspace:*",
"ember-modifier": "^4.1.0",
"ember-resources": "^6.0.0",
"highlight.js": "^11.7.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();
62 changes: 62 additions & 0 deletions internal/sync-pnpm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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, remove } from 'fs-extra/esm';
import { hardLinkDir } from '@pnpm/fs.hard-link-dir';
import resolvePackagePath from 'resolve-package-path';
import Debug from 'debug';
import lockfile from 'proper-lockfile';

const require = createRequire(import.meta.url);
const debug = Debug('sync-pnpm');

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)) {
let releaseLock;
try {
releaseLock = await lockfile.lock(syncTo, { realpath: false });
debug(`lockfile created for syncing to ${syncTo}`);
} catch (e) {
debug(
`lockfile already exists for syncing to ${syncTo}, some other sync process is already handling this directory, so skipping...`
);
continue;
}

if (await pathExists(syncTo)) {
await remove(syncTo);
debug(`removed ${syncTo} before syncing`);
}

debug(`syncing from ${syncFrom} to ${syncTo}`);
await hardLinkDir(syncFrom, [syncTo]);
releaseLock();
}
}
}
21 changes: 21 additions & 0 deletions internal/sync-pnpm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "sync-pnpm",
"version": "0.0.0",
"private": true,
"description": "Sync build artifacts of workspace packages to pnpm injected/hard linked copies",
"repository": "https://github.com/CrowdStrike/ember-headless-table.git",
"license": "MIT",
"author": "CrowdStrike UX Team",
"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": "^2.0.0",
"debug": "^4.3.4",
"fs-extra": "^11.1.0",
"proper-lockfile": "^4.1.2",
"resolve-package-path": "^4.0.3"
}
}
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"name": "ember-headless-table-monorepo",
"name": "ember-headless-table",
"version": "0.0.0",
"private": true,
"repository": "",
"repository": "https://github.com/CrowdStrike/ember-headless-table.git",
"license": "MIT",
"author": "",
"author": "CrowdStrike UX Team",
"scripts": {
"release": "changeset publish",
"build": "pnpm --filter ember-headless-table build",
"build:docs": "pnpm build:docs-app && pnpm build:docs-api && cp ./docs-api/dist ./docs-app/dist/api -r",
"build:docs-app": "pnpm --filter docs-app build",
"build:docs-api": "pnpm --filter docs-api docs:build",
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
"start:tests": "pnpm --filter test-app start",
"start:docs": "pnpm turbo --filter docs-app start",
"start:tests": "pnpm turbo --filter test-app start",
"start:addon": "pnpm --filter ember-headless-table start --no-watch.clearScreen",
"start:docs-api": "pnpm --filter 'docs-api' docs:watch --preserveWatchOutput",
"start:docs-app": "pnpm --filter 'docs-app' start -p 4201",
"build": "pnpm turbo build",
"build:docs-app": "pnpm turbo --filter docs-app build",
"build:docs-api": "pnpm turbo --filter docs-api docs:build",
"ci:update": "npx ember-ci-update",
"test": "pnpm --filter test-app test",
"lint": "pnpm --filter '*' lint",
"test": "pnpm turbo --filter test-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.2"
"prettier": "^2.8.2",
"turbo": "^1.7.4"
},
"pnpm": {
"overrides": {
Expand All @@ -51,4 +52,4 @@
"volta": {
"node": "18.16.0"
}
}
}
Loading

0 comments on commit f594c15

Please sign in to comment.