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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules/
work/
.DS_Store
.idea/
.vscode/settings.json
72 changes: 16 additions & 56 deletions bin/check-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import chalk from 'chalk';
import { promises as fs } from 'fs';
import path from 'path';
import yargs from 'yargs';
import { readJsonFileForCli } from '~/src/readJsonFileForCli';
import { PackageInfo, PackageManifest } from '~/src/types';

const input = yargs
.option('h', {
Expand Down Expand Up @@ -45,54 +47,12 @@ function log(msg: string) {
console.log(msg);
}

async function readJsonFile<T>(file: string): Promise<T | undefined> {
let contents: string;
try {
contents = await fs.readFile(file, { encoding: 'utf8' });
} catch (err) {
log(
chalk.yellow(
`Error reading ${chalk.bold(file)}. ${err.toString()} (skipping)`
)
);
return undefined;
}

let obj;
try {
obj = JSON.parse(contents);
} catch (err) {
log(
chalk.yellow(
`Error parsing ${chalk.bold(file)}. ${err.toString()} (skipping)`
)
);
return undefined;
}

return obj;
}

type PackageManifest = {
name?: string;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
};

type TSConfig = {
references?: {
path?: string;
}[];
};

type PackageInfo = {
packageName: string;
dir: string;
dirName: string;
packageFile: string;
packageObj: PackageManifest;
};

type CheckTSConfigStats = {
problemFileCount: number;
};
Expand Down Expand Up @@ -203,7 +163,7 @@ async function checkMonorepo() {
chalk.yellow(
`Unable to read monorepo packages at ${chalk.bold(
packagesDir
)} (probably not a monrepo). Error: ${err.toString()} (skipping)`
)} (probably not a monrepo). Error: ${String(err)} (skipping)`
)
);
process.exitCode = 3;
Expand All @@ -218,12 +178,12 @@ async function checkMonorepo() {
}

const packageFile = path.join(packageDir, 'package.json');
const packageObj = await readJsonFile<PackageManifest>(packageFile);
if (!packageObj) {
const packageManifest = await readJsonFileForCli<PackageManifest>(packageFile, log);
if (!packageManifest) {
continue;
}

const packageName = packageObj.name;
const packageName = packageManifest.name;
if (!packageName) {
log(
chalk.yellow(
Expand All @@ -250,7 +210,7 @@ async function checkMonorepo() {
dir: packageDir,
dirName: packageDirName,
packageFile,
packageObj,
packageManifest,
};

knownPackages[packageName] = packageInfo;
Expand All @@ -261,10 +221,10 @@ async function checkMonorepo() {
log(`\nChecking ${chalk.bold(packageInfo.dirName)}...`);

const tsconfigDistFile = path.join(packageInfo.dir, 'tsconfig.dist.json');
const tsconfigDistObj = await readJsonFile<TSConfig>(tsconfigDistFile);
const tsconfigDistObj = await readJsonFileForCli<TSConfig>(tsconfigDistFile, log);

const tsconfigFile = path.join(packageInfo.dir, 'tsconfig.json');
const tsconfigObj = await readJsonFile<TSConfig>(tsconfigFile);
const tsconfigObj = await readJsonFileForCli<TSConfig>(tsconfigFile, log);

if (!tsconfigObj && !tsconfigDistObj) {
console.log(
Expand All @@ -285,12 +245,12 @@ async function checkMonorepo() {
}
};

if (packageInfo.packageObj.dependencies) {
processDependencies(Object.keys(packageInfo.packageObj.dependencies));
if (packageInfo.packageManifest.dependencies) {
processDependencies(Object.keys(packageInfo.packageManifest.dependencies));
}

if (packageInfo.packageObj.devDependencies) {
processDependencies(Object.keys(packageInfo.packageObj.devDependencies));
if (packageInfo.packageManifest.devDependencies) {
processDependencies(Object.keys(packageInfo.packageManifest.devDependencies));
}

const requiredDependencies = [...requiredDependenciesSet];
Expand Down Expand Up @@ -376,7 +336,7 @@ async function run() {
}

run().catch((err) => {
console.error(
chalk.red(chalk.bold('Error occurred. ') + (err.stack || err.toString()))
);
const message =
err instanceof Error ? err.stack ?? String(err) : String(err);
console.error(chalk.red(chalk.bold('Error occurred. ') + message));
});
4 changes: 3 additions & 1 deletion bin/yalc-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ async function run() {
}

run().catch((err) => {
console.error('Error occurred! ' + (err.stack || err.toString()));
const message =
err instanceof Error ? err.stack ?? String(err) : String(err);
console.error('Error occurred! ' + message);
});
9 changes: 6 additions & 3 deletions bin/yalc-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import os from 'os';

import yargs from 'yargs';
import { readJsonFileForCli } from '~/src/readJsonFileForCli';
import { PackageManifest } from '~/src/types';

const input = yargs
.option('h', {
Expand Down Expand Up @@ -94,7 +95,7 @@ async function publishSinglePackage() {
const packageDir = process.cwd();

const packageFile = path.join(packageDir, 'package.json');
const packageManifest = await readJsonFileForCli(packageFile, console.log);
const packageManifest = await readJsonFileForCli<PackageManifest>(packageFile, console.log);
if (!packageManifest) {
process.exitCode = 1;
return;
Expand All @@ -110,7 +111,7 @@ async function publishSinglePackage() {
`You can now run the following in other projects to use this package:\n`
);
console.log(
` ${chalk.bold('>')} ${chalk.blue(`npx yalc add ${packageManifest.name}`)}`
` ${chalk.bold('>')} ${chalk.blue(`npx yalc add ${String(packageManifest.name)}`)}`
);
console.log('');
}
Expand All @@ -128,5 +129,7 @@ async function run() {
}

run().catch((err) => {
console.error('Error occurred! ' + (err.stack || err.toString()));
const message =
err instanceof Error ? err.stack ?? String(err) : String(err);
console.error('Error occurred! ' + message);
});
1 change: 1 addition & 0 deletions config/typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"alwaysStrict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"useUnknownInCatchVariables": true,
"allowJs": true,
"module": "CommonJS",
"moduleResolution": "node",
Expand Down
56 changes: 16 additions & 40 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import { fileURLToPath } from 'url';
import path from 'path';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createConfig } from '@jupiterone/eslint-config/flat';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
// Global ignores (replaces .eslintignore and ignorePatterns)
{
ignores: [
'*.js',
'!eslint.config.js',
'index.js',
'config/**',
'test/fixtures/**/*',
'dist/**',
'node_modules/**',
],
},

// Use FlatCompat to bridge the legacy @jupiterone/eslint-config
...compat.extends('@jupiterone/eslint-config/node18'),

// TypeScript-specific configuration
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
export default createConfig({
tsconfigRootDir: import.meta.dirname ?? dirname(fileURLToPath(import.meta.url)),
additionalConfigs: [
{
ignores: [
'*.js',
'*.mjs',
'index.js',
'config/**',
'test/fixtures/**/*',
],
},
},
];
],
});
Loading
Loading