Skip to content

Commit

Permalink
chore: upgrade deps and fix linting problem
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Dec 12, 2024
1 parent d96e351 commit fdeeb52
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ pnpm-lock.yaml
dist
out
tmp
node-compile-cache
v8-compile-cache-*
tsx-*
17 changes: 17 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @ts-check
// TODO: Remove this file
import { Builder } from "fenge/eslint-config";

export default new Builder()
.enablePackagejson()
.enableJavascript()
.enableTypescript({
omit: [
"@fenge/no-restricted-loops",
"@typescript-eslint/no-floating-promises",
"es-x/no-top-level-await",
"unicorn/no-process-exit",
"no-console",
],
})
.toConfig();
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
"scripts": {
"build": "pnpm -r build",
"install": "pnpm build",
"prepare": "git-validator install",
"prepare": "fenge install",
"release": "changeset publish",
"style": "git-validator",
"style:update": "git-validator -u",
"style": "fenge",
"style:update": "fenge -u",
"test": "pnpm -r test && pnpm style"
},
"devDependencies": {
"@changesets/cli": "2.27.3",
"git-validator": "0.17.5",
"typescript": "5.4.5",
"vitest": "1.6.0"
"@changesets/cli": "2.27.10",
"fenge": "0.2.1",
"typescript": "5.7.2"
},
"packageManager": "pnpm@8.15.4",
"packageManager": "pnpm@9.15.0",
"engines": {
"node": ">=18.0.0",
"pnpm": "^8.0.0"
"pnpm": "^9.0.0"
}
}
5 changes: 3 additions & 2 deletions packages/tscx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"commander": "12.1.0"
},
"devDependencies": {
"@types/node": "20.12.12",
"tsx": "4.11.0"
"@types/node": "22.10.2",
"tsx": "4.19.2",
"vitest": "1.6.0"
},
"peerDependencies": {
"typescript": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/tscx/src/action.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it, type Mock, vi } from "vitest";
import { describe, expect, it, vi, type Mock } from "vitest";
import { Action } from "./action.js";
import { Compiler } from "./compiler.js";

Expand Down
34 changes: 18 additions & 16 deletions packages/tscx/src/cmd/copyfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ import path from "node:path";

/**
* Copy non-ts/non-js files to outDir
* @param rootDir absolute path
* @param outDir absolute path
* @param rootDirectory absolute path
* @param outDirectory absolute path
*/
export async function copyfiles(rootDir: string, outDir: string) {
rootDir = path.resolve(rootDir);
outDir = path.resolve(outDir);
export async function copyfiles(rootDirectory: string, outDirectory: string) {
const rootDir = path.resolve(rootDirectory);
const outDir = path.resolve(outDirectory);
async function walkDir(dir: string, cb: (filepath: string) => Promise<void>) {
await Promise.all(
(await fs.readdir(dir))
.map((filepath) => path.resolve(dir, filepath))
.map(async (filepath) => {
if ((await fs.stat(filepath)).isDirectory()) {
if (
!filepath.startsWith(outDir) &&
!filepath.endsWith(`${path.sep}node_modules`)
) {
await walkDir(filepath, cb);
}
} else {
if (!/\.(js|cjs|mjs|jsx|ts|cts|mts|tsx)$/.test(filepath)) {
await cb(filepath);
}
const stat = await fs.stat(filepath);
if (
stat.isFile() &&
!/\.(js|cjs|mjs|jsx|ts|cts|mts|tsx)$/.test(filepath)
) {
await cb(filepath);
}
if (
stat.isDirectory() &&
!filepath.startsWith(outDir) &&
!filepath.endsWith(`${path.sep}node_modules`)
) {
await walkDir(filepath, cb);
}
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/tscx/src/cmd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function copyfiles(rootDir: string, outDir: string) {

export function script(scr: string) {
console.log("Script", `npm run ${scr}`);
return spawn("npm", "run", scr);
return spawn("npm", "run", scr); // TODO: Use node --run instead of npm run. See https://nodejs.org/api/cli.html#--run
}

export function exec(filepath: string) {
Expand Down
19 changes: 8 additions & 11 deletions packages/tscx/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Compiler {
}

compile() {
const id = Date.now() + "_" + Math.random().toString(36).slice(2);
const id = `${Date.now().toString()}_${Math.random().toString(36).slice(2)}`;
this.id = id;

if (!this.currentSubprocess) {
Expand Down Expand Up @@ -116,7 +116,6 @@ export class Compiler {
);
const cmd = `node ${tscPath} --showConfig --project ${this.options.project}`;
const config: TsConfig = JSON.parse(
// eslint-disable-next-line n/no-sync
childProcess.execSync(cmd).toString("utf8"),
);
if (
Expand All @@ -135,7 +134,7 @@ export class Compiler {
getOutDir() {
const outDir = this.tsconfig.compilerOptions?.outDir;
if (!outDir) {
throw new Error(`"outDir" is not found`);
throw new Error('"outDir" is not found');
}
const absoluteOutDir = path.resolve(process.cwd(), outDir);
if (process.cwd().startsWith(absoluteOutDir)) {
Expand All @@ -148,14 +147,12 @@ export class Compiler {

private getRootDir() {
const rootDir = this.tsconfig.compilerOptions?.rootDir;
if (rootDir) {
return path.resolve(process.cwd(), rootDir);
} else {
return path.resolve(
process.cwd(),
this.getRootDirByFiles(this.tsconfig.files ?? []),
);
}
return rootDir
? path.resolve(process.cwd(), rootDir)
: path.resolve(
process.cwd(),
this.getRootDirByFiles(this.tsconfig.files ?? []),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "git-validator/tsconfig"
"extends": "fenge/tsconfig"
}

0 comments on commit fdeeb52

Please sign in to comment.