Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions scripts/bench/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference lib="dom" />
// eslint-disable-next-line depend/ban-dependencies
import { ensureDir, readJSON, readdir, writeJSON } from 'fs-extra';
import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';

import { join } from 'path';
import type { Page } from 'playwright-core';

Expand All @@ -19,17 +19,23 @@ export const saveBench = async (
) => {
const dirName = join(options.rootDir || process.cwd(), 'bench');
const fileName = `${key}.json`;
const existing = await ensureDir(dirName).then(() => {
return readJSON(join(dirName, fileName)).catch(() => ({}));
});
await writeJSON(join(dirName, fileName), { ...existing, ...data }, { spaces: 2 });
await mkdir(dirName, { recursive: true });

const filePath = join(dirName, fileName);
const existing = await readFile(filePath, 'utf8')
.then((txt) => JSON.parse(txt))
.catch(() => ({}));

const merged = { ...existing, ...data };
await writeFile(filePath, JSON.stringify(merged, null, 2), 'utf8');
};

export const loadBench = async (options: SaveBenchOptions): Promise<Partial<BenchResults>> => {
const dirName = join(options.rootDir || process.cwd(), 'bench');
const files = await readdir(dirName);
return files.reduce(async (acc, fileName) => {
const data = await readJSON(join(dirName, fileName));
const content = await readFile(join(dirName, fileName), 'utf8');
const data = JSON.parse(content);
return { ...(await acc), ...data };
}, Promise.resolve({}));
// return readJSON(join(dirname, `bench.json`));
Expand Down
10 changes: 4 additions & 6 deletions scripts/build-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
*
* When you pass no package names, you will be prompted to select which packages to build.
*/
import { readFile } from 'node:fs/promises';

import { exec } from 'child_process';
import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
// eslint-disable-next-line depend/ban-dependencies
import { readJSON } from 'fs-extra';
import { posix, resolve, sep } from 'path';
import picocolors from 'picocolors';
import prompts from 'prompts';
Expand Down Expand Up @@ -166,9 +165,8 @@ async function run() {
let lastName = '';

selection.forEach(async (v) => {
const command = (await readJSON(resolve('../code', v.location, 'package.json'))).scripts?.prep
.split(posix.sep)
.join(sep);
const content = await readFile(resolve('../code', v.location, 'package.json'), 'utf-8');
const command = JSON.parse(content).scripts?.prep.split(posix.sep).join(sep);

if (!command) {
console.log(`No prep script found for ${v.name}`);
Expand Down
7 changes: 4 additions & 3 deletions scripts/check-package.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// This script makes sure that we can support type checking,
// without having to build dts files for all packages in the monorepo.
// It is not implemented yet for angular, svelte and vue.
import { readFile } from 'node:fs/promises';

import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { readJSON } from 'fs-extra';
import { resolve } from 'path';
import picocolors from 'picocolors';
import prompts from 'prompts';
Expand Down Expand Up @@ -113,7 +113,8 @@ async function run() {
}

selection?.filter(Boolean).forEach(async (v) => {
const command = (await readJSON(resolve('../code', v.location, 'package.json'))).scripts.check;
const content = await readFile(resolve('../code', v.location, 'package.json'), 'utf-8');
const command = JSON.parse(content).scripts.check;
const cwd = resolve(__dirname, '..', 'code', v.location);
const sub = execaCommand(`${command}${watchMode ? ' --watch' : ''}`, {
cwd,
Expand Down
4 changes: 2 additions & 2 deletions scripts/combine-compodoc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Compodoc does not follow symlinks (it ignores them and their contents entirely)
// So, we need to run a separate compodoc process on every symlink inside the project,
// then combine the results into one large documentation.json
import { lstat, readFile, realpath, writeFile } from 'node:fs/promises';

// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { lstat, readFile, realpath, writeFile } from 'fs-extra';
// eslint-disable-next-line depend/ban-dependencies
import { globSync } from 'glob';
import { join, resolve } from 'path';

Expand Down
7 changes: 4 additions & 3 deletions scripts/get-report-message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile } from 'node:fs/promises';

// eslint-disable-next-line depend/ban-dependencies
import { execaCommand } from 'execa';
// eslint-disable-next-line depend/ban-dependencies
import { readJson } from 'fs-extra';
import { join } from 'path';

import { CODE_DIRECTORY } from './utils/constants';
Expand All @@ -17,7 +17,8 @@ const getFooter = async (branch: Branch, workflow: Workflow, job: string) => {

// The CI workflows can run on release branches and we should display the version number
if (branch === 'next-release' || branch === 'latest-release') {
const packageJson = await readJson(join(CODE_DIRECTORY, 'package.json'));
const content = await readFile(join(CODE_DIRECTORY, 'package.json'), 'utf8');
const packageJson = JSON.parse(content);

// running in alpha branch we should just show the version which failed
return `\n**Version: ${packageJson.version}**`;
Expand Down
20 changes: 14 additions & 6 deletions scripts/get-template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { access, readFile, readdir } from 'node:fs/promises';

import { program } from 'commander';
// eslint-disable-next-line depend/ban-dependencies
import { pathExists, readFile } from 'fs-extra';
import { readdir } from 'fs/promises';
import picocolors from 'picocolors';
import { dedent } from 'ts-dedent';
import yaml from 'yaml';
Expand All @@ -28,6 +27,15 @@ async function getDirectories(source: string) {
.map((entry) => entry.name);
}

async function pathExists(path: string) {
try {
await access(path);
return true;
} catch {
return false;
}
}

export async function getTemplate(
cadence: Cadence,
scriptName: string,
Expand Down Expand Up @@ -62,12 +70,12 @@ export async function getTemplate(

if (potentialTemplateKeys.length !== total) {
throw new Error(dedent`Circle parallelism set incorrectly.

Parallelism is set to ${total}, but there are ${
potentialTemplateKeys.length
} templates to run for the "${scriptName}" task:
${potentialTemplateKeys.map((v) => `- ${v}`).join('\n')}

${await checkParallelism(cadence)}
`);
}
Expand Down Expand Up @@ -176,7 +184,7 @@ async function run({ cadence, task, check }: RunOptions) {
if (check) {
if (task && !tasks.includes(task)) {
throw new Error(
dedent`The "${task}" task you provided is not valid. Valid tasks (found in .circleci/config.yml) are:
dedent`The "${task}" task you provided is not valid. Valid tasks (found in .circleci/config.yml) are:
${tasks.map((v) => `- ${v}`).join('\n')}`
);
}
Expand Down
2 changes: 0 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"@types/detect-port": "^1.3.5",
"@types/ejs": "^3.1.5",
"@types/escodegen": "^0.0.6",
"@types/fs-extra": "^11.0.4",
"@types/http-server": "^0.12.4",
"@types/jest": "^29.5.12",
"@types/node": "^22.0.0",
Expand Down Expand Up @@ -128,7 +127,6 @@
"fast-folder-size": "^2.2.0",
"fast-glob": "^3.3.2",
"find-up": "^5.0.0",
"fs-extra": "^11.2.0",
"github-release-from-changelog": "^2.1.1",
"glob": "^10.4.5",
"http-server": "^14.1.1",
Expand Down
11 changes: 5 additions & 6 deletions scripts/release/__tests__/is-pr-frozen.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as fspImp from 'node:fs/promises';
import { join } from 'node:path';

import { describe, expect, it, vi } from 'vitest';

// eslint-disable-next-line depend/ban-dependencies
import * as fsExtraImp from 'fs-extra';
import * as simpleGitImp from 'simple-git';

import type * as MockedFSExtra from '../../../code/__mocks__/fs-extra';
import type * as MockedFSPExtra from '../../../code/__mocks__/fs/promises';
import type * as MockedSimpleGit from '../../__mocks__/simple-git';
import { CODE_DIRECTORY } from '../../utils/constants';
import { run as isPrFrozen } from '../is-pr-frozen';
Expand All @@ -15,13 +14,13 @@ import { getPullInfoFromCommit } from '../utils/get-github-info';

vi.mock('../utils/get-github-info');
vi.mock('simple-git');
vi.mock('fs-extra', async () => import('../../../code/__mocks__/fs-extra'));
const fsExtra = fsExtraImp as unknown as typeof MockedFSExtra;
vi.mock('node:fs/promises', async () => import('../../../code/__mocks__/fs/promises'));
const fsp = fspImp as unknown as typeof MockedFSPExtra;
const simpleGit = simpleGitImp as unknown as typeof MockedSimpleGit;

const CODE_PACKAGE_JSON_PATH = join(CODE_DIRECTORY, 'package.json');

fsExtra.__setMockFiles({
fsp.__setMockFiles({
[CODE_PACKAGE_JSON_PATH]: JSON.stringify({ version: '1.0.0' }),
});

Expand Down
Loading