Skip to content

Commit

Permalink
refactor: lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Jun 5, 2024
1 parent 0c13727 commit 7a912ef
Show file tree
Hide file tree
Showing 147 changed files with 3,674 additions and 2,858 deletions.
115 changes: 64 additions & 51 deletions .scripts/preconstruct.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,108 @@
import fs from "node:fs/promises";
import path from "node:path";
import { glob } from "fast-glob";
import fs from 'node:fs/promises'
import path from 'node:path'
import { glob } from 'fast-glob'

// Symlinks package sources to dist for local development

console.log("Setting up packages for development.");
console.log('Setting up packages for development.')

async function main() {
// Get all package.json files
const packagePaths = await glob("**/package.json", {
ignore: ["**/dist/**", "**/node_modules/**"],
});
const packagePaths = await glob('**/package.json', {
ignore: ['**/dist/**', '**/node_modules/**'],
})

let count = 0;
let count = 0
for (const packagePath of packagePaths) {
type Package = {
bin?: Record<string, string> | undefined;
exports?: Record<string, { types: string; default: string } | string> | undefined;
name?: string | undefined;
private?: boolean | undefined;
};
const file = await fs.readFile(packagePath, "utf8");
const packageJson = (await JSON.parse(file)) as Package;
bin?: Record<string, string> | undefined
exports?:
| Record<string, { types: string; default: string } | string>
| undefined
name?: string | undefined
private?: boolean | undefined
}
const file = await fs.readFile(packagePath, 'utf8')
const packageJson = (await JSON.parse(file)) as Package

// Skip private packages
if (packageJson.private) continue;
if (!packageJson.exports) continue;
if (packageJson.private) continue
if (!packageJson.exports) continue

count += 1;
console.log(`${packageJson.name}${path.dirname(packagePath)}`);
count += 1
console.log(`${packageJson.name}${path.dirname(packagePath)}`)

const dir = path.resolve(path.dirname(packagePath));
const dir = path.resolve(path.dirname(packagePath))

// Empty dist directory
const distDirName = "dist";
const dist = path.resolve(dir, distDirName);
let files: string[] = [];
const distDirName = 'dist'
const dist = path.resolve(dir, distDirName)
let files: string[] = []
try {
files = await fs.readdir(dist);
files = await fs.readdir(dist)
} catch {
await fs.mkdir(dist);
await fs.mkdir(dist)
}

const promises: Promise<void>[] = [];
const promises: Promise<void>[] = []
for (const file of files) {
promises.push(fs.rm(path.join(dist, file), { recursive: true, force: true }));
promises.push(
fs.rm(path.join(dist, file), { recursive: true, force: true }),
)
}
await Promise.all(promises);
await Promise.all(promises)

// Link exports to dist locations
for (const [key, exports] of Object.entries(packageJson.exports)) {
// Skip `package.json` exports
if (/package\.json$/.test(key)) continue;
if (/package\.json$/.test(key)) continue

let entries: any;
if (typeof exports === "string")
let entries: any
if (typeof exports === 'string')
entries = [
["default", exports],
["types", exports.replace(".js", ".d.ts")],
];
else entries = Object.entries(exports);
['default', exports],
['types', exports.replace('.js', '.d.ts')],
]
else entries = Object.entries(exports)

// Link exports to dist locations
for (const [type, value] of entries as [type: "types" | "default", value: string][]) {
for (const [type, value] of entries as [
type: 'types' | 'default',
value: string,
][]) {
const srcDir = path.resolve(
dir,
path
.dirname(value)
.replace(
`dist${packageJson.name === "@fc-auth/react" ? "" : type === "default" ? "/esm" : `/${type}`}`,
"src",
`dist${
packageJson.name === '@fc-auth/react'
? ''
: type === 'default'
? '/esm'
: `/${type}`
}`,
'src',
),
);
let srcFileName: string;
if (key.endsWith(".css")) continue;
if (key === ".") srcFileName = "index.ts";
else srcFileName = path.basename(`${key}.ts`);
const srcFilePath = path.resolve(srcDir, srcFileName);
)
let srcFileName: string
if (key.endsWith('.css')) continue
if (key === '.') srcFileName = 'index.ts'
else srcFileName = path.basename(`${key}.ts`)
const srcFilePath = path.resolve(srcDir, srcFileName)

const distDir = path.resolve(dir, path.dirname(value));
const distFileName = path.basename(value);
const distFilePath = path.resolve(distDir, distFileName);
const distDir = path.resolve(dir, path.dirname(value))
const distFileName = path.basename(value)
const distFilePath = path.resolve(distDir, distFileName)

await fs.mkdir(distDir, { recursive: true });
await fs.mkdir(distDir, { recursive: true })

// Symlink src to dist file
await fs.symlink(srcFilePath, distFilePath, "file");
await fs.symlink(srcFilePath, distFilePath, 'file')
}
}
}

console.log(`Done. Set up ${count} ${count === 1 ? "package" : "packages"}.`);
console.log(`Done. Set up ${count} ${count === 1 ? 'package' : 'packages'}.`)
}
main();
main()
20 changes: 10 additions & 10 deletions apps/relay/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { Config } from "jest";
import type { Config } from 'jest'

const jestConfig: Config = {
testEnvironment: "node",
coveragePathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/node_modules/"],
testPathIgnorePatterns: ["<rootDir>/build", "<rootDir>/node_modules"],
extensionsToTreatAsEsm: [".ts"],
testEnvironment: 'node',
coveragePathIgnorePatterns: ['<rootDir>/build/', '<rootDir>/node_modules/'],
testPathIgnorePatterns: ['<rootDir>/build', '<rootDir>/node_modules'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
'^(\\.{1,2}/.*)\\.js$': '$1',
},
/**
* For high performance with minimal configuration transform with TS with swc.
* @see https://github.com/farcasterxyz/hub/issues/314
*/
transform: {
"^.+\\.(t|j)sx?$": "@swc/jest",
'^.+\\.(t|j)sx?$': '@swc/jest',
},
maxWorkers: "50%",
};
maxWorkers: '50%',
}

export default jestConfig;
export default jestConfig
Loading

0 comments on commit 7a912ef

Please sign in to comment.