Skip to content

Commit

Permalink
Update the benchmark config
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Dec 28, 2023
1 parent f9f54b9 commit 97ebcd1
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 150 deletions.
3 changes: 2 additions & 1 deletion benchmark/benchmarks/krausest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"@simple-dom/document": "^1.4.0",
"@simple-dom/serializer": "^1.4.0",
"@simple-dom/void-map": "^1.4.0",
"@glimmer/compiler": "workspace:^"
"@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

0 comments on commit 97ebcd1

Please sign in to comment.