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

Have the benchmark code use the same fake-publish process as the linking script #1542

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 8 additions & 4 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ jobs:
fetch-depth: 0
- uses: wyvox/action-setup-pnpm@v3
with:
node-version: '20.1.0'

- name: RUN
run: pnpm run benchmark:setup
node-version: '21.5.0'

- run: pnpm run benchmark:setup

- name: Remove unused artifacts
run: rm -rf ./tracerbench-results/traces && rm -rf ./tracerbench-results/traces.zip
Expand All @@ -52,3 +51,8 @@ jobs:
update-only: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add artifact links to pull request
uses: tonyhallett/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion benchmark/benchmarks/krausest/lib/utils/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function emitDomClickEvent(selector: ButtonSelectors) {

export function waitForIdle() {
return new Promise((resolve) => {
requestIdleCallback(resolve);
requestAnimationFrame(resolve);
});
}

Expand Down
5 changes: 3 additions & 2 deletions benchmark/benchmarks/krausest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
},
"dependencies": {
"@glimmer-workspace/benchmark-env": "workspace:^",
"@glimmer/compiler": "workspace:^",
"@glimmer/interfaces": "workspace:^",
"@simple-dom/document": "^1.4.0",
"@simple-dom/serializer": "^1.4.0",
"@simple-dom/void-map": "^1.4.0"
"@simple-dom/void-map": "^1.4.0",
"@glimmer/compiler": "workspace:^",
"@glimmer/util": "workspace:^"
},
"devDependencies": {
"@types/node": "^20.9.4",
Expand Down
7 changes: 6 additions & 1 deletion benchmark/benchmarks/krausest/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { fileURLToPath } from 'node:url';
const self = import.meta.url;

const currentPath = path.dirname(fileURLToPath(self));
const packagesPath = path.resolve(currentPath, '..', '..', './../packages');
/**
* Only run this vite config via pnpm benchmark:setup at the
* monorepo root
*/
const packagesPath = path.resolve(currentPath, '..', '..', './../');

const packagePath = (name: string) => {
return path.join(packagesPath, name, 'dist/prod/index.js');
Expand All @@ -21,6 +25,7 @@ export default defineConfig({
'@glimmer-workspace/benchmark-env': '@glimmer-workspace/benchmark-env/index.ts',
'@glimmer/debug': packagePath('@glimmer/debug'),
'@glimmer/runtime': packagePath('@glimmer/runtime'),
'@glimmer/util': packagePath('@glimmer/util'),
'@/components': path.join(currentPath, 'lib', 'components'),
'@/utils': path.join(currentPath, 'lib', 'utils'),
},
Expand Down
91 changes: 3 additions & 88 deletions bin/link-all.mts
Original file line number Diff line number Diff line change
@@ -1,98 +1,13 @@
import { readFile, writeFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
import chalk from 'chalk';
import { execa } from 'execa';
import { mkdirp } from 'mkdirp';
import { rimraf } from 'rimraf';
import { x as untar } from 'tar';
import { packages } from './packages.mjs';
import { writeFileSync } from 'node:fs';

import { previewPublish } from './preview-publish.mjs';

const dist = new URL('../dist', import.meta.url).pathname;
const pkgs = packages('@glimmer');

await mkdirp(dist);
await rimraf(dist + '/*.tgz', { glob: true });

const pack = pkgs.map(async (pkg) => {
try {
await execa('pnpm', ['pack', '--pack-destination', dist], {
cwd: pkg.path,
});

console.log(chalk.green(`Successfully packed ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to pack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(pack);

const unpack = pkgs.map(async (pkg) => {
try {
const pkgDest = join(dist, pkg.name);

await mkdirp(pkgDest);
await rimraf(pkgDest + '/**/*');

const tarball = join(dist, pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`);

await untar({
file: tarball,
strip: 1,
cwd: pkgDest,
});

await unlink(tarball);

// https://github.com/pnpm/pnpm/issues/881
const packageJsonPath = join(pkgDest, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
delete packageJson.devDependencies;
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), {
encoding: 'utf8',
});

console.log(chalk.green(`Successfully unpacked ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to unpack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(unpack);

const packageJson = `{
"name": "glimmer-vm",
"private": true,
"overrides": {
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')}
}
}
`;

const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join('');

await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' });
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' });

await execa('pnpm', ['install'], {
cwd: dist,
stdio: 'inherit',
});

console.log(chalk.green(`Successfully installed packages`));
await previewPublish();

// Seems like there are race conditions in pnpm if we try to do these concurrently
for (const pkg of pkgs) {
Expand Down
106 changes: 106 additions & 0 deletions bin/preview-publish.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { readFile, writeFile, unlink } from 'node:fs/promises';
import { join } from 'node:path';
import chalk from 'chalk';
import { execa } from 'execa';
import { mkdirp } from 'mkdirp';
import { rimraf } from 'rimraf';
import { x as untar } from 'tar';
import { packages } from './packages.mjs';
import { writeFileSync } from 'node:fs';

export async function previewPublish() {
const dist = new URL('../dist', import.meta.url).pathname;
const pkgs = packages('@glimmer');

await mkdirp(dist);
await rimraf(dist + '/*.tgz', { glob: true });

const pack = pkgs.map(async (pkg) => {
try {
await execa('pnpm', ['pack', '--pack-destination', dist], {
cwd: pkg.path,
});

console.log(chalk.green(`Successfully packed ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to pack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(pack);

const unpack = pkgs.map(async (pkg) => {
try {
const pkgDest = join(dist, pkg.name);

await mkdirp(pkgDest);
await rimraf(pkgDest + '/**/*');

const tarball = join(
dist,
pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`
);

await untar({
file: tarball,
strip: 1,
cwd: pkgDest,
});

await unlink(tarball);

// https://github.com/pnpm/pnpm/issues/881
const packageJsonPath = join(pkgDest, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
delete packageJson.devDependencies;
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), {
encoding: 'utf8',
});

console.log(chalk.green(`Successfully unpacked ${pkg.name}`));
} catch (error: unknown) {
let message = `Failed to unpack ${pkg.name}`;

if (error instanceof Error) {
message += `\n\n${error.stack}`;
}

throw new Error(message);
}
});

await Promise.all(unpack);

const packageJson = `{
"name": "glimmer-vm",
"private": true,
"overrides": {
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')}
}
}
`;

const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join('');

await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' });
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' });

await execa('pnpm', ['install'], {
cwd: dist,
stdio: 'inherit',
});

console.log(chalk.green(`Successfully installed packages`));
}

if (import.meta.url === 'file://' + process.argv[1]) {
console.log('Previewing Publish...');

await previewPublish();
}
Loading
Loading