From d9d8c64d01ad4e3dddee8fc3d105f9861298a4e0 Mon Sep 17 00:00:00 2001 From: nyqykk Date: Thu, 18 Dec 2025 17:37:04 +0800 Subject: [PATCH 1/2] fix: skip project which has not define start command --- src/types.ts | 7 +++++++ src/utils.ts | 7 ++++--- src/workspace-dev.ts | 41 ++++++++++++++++++++--------------------- 3 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 src/types.ts diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..61e1b92 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,7 @@ +import type { Package } from '@manypkg/get-packages'; + +export interface PackageWithScripts extends Package { + packageJson: Package['packageJson'] & { + scripts?: Record; + }; +} diff --git a/src/utils.ts b/src/utils.ts index 123613f..2d9a8b6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,8 @@ -import type { Package } from '@manypkg/get-packages'; import fs from 'fs'; import json5 from 'json5'; +import type { PackageWithScripts } from './types.js'; + async function pathExists(path: string) { return fs.promises .access(path) @@ -21,8 +22,8 @@ export const readJson = async (jsonFileAbsPath: string): Promise => { export const readPackageJson = async ( pkgJsonFilePath: string, -): Promise => { - return readJson(pkgJsonFilePath); +): Promise => { + return readJson(pkgJsonFilePath); }; export const isDebug = diff --git a/src/workspace-dev.ts b/src/workspace-dev.ts index 450628a..7b56432 100644 --- a/src/workspace-dev.ts +++ b/src/workspace-dev.ts @@ -1,8 +1,7 @@ -import { getPackagesSync, type Package } from '@manypkg/get-packages'; +import { getPackagesSync } from '@manypkg/get-packages'; import { spawn } from 'child_process'; import graphlib, { Graph } from 'graphlib'; -import path from 'path'; - +import { join } from 'path'; import { MODERN_MODULE_READY_MESSAGE, PACKAGE_JSON, @@ -11,11 +10,12 @@ import { TSUP_READY_MESSAGE, } from './constant.js'; import { debugLog, Logger } from './logger.js'; +import type { PackageWithScripts } from './types.js'; import { readPackageJson } from './utils.js'; interface GraphNode { name: string; - packageJson: Package['packageJson']; + packageJson: PackageWithScripts['packageJson']; path: string; } @@ -37,12 +37,12 @@ export class WorkspaceDevRunner { private options: WorkspaceDevRunnerOptions; private cwd: string; private workspaceFileDir: string; - private packages: Package[] = []; + private packages: PackageWithScripts[] = []; private graph: Graph; private visited: Record; private visiting: Record; private matched: Record; - private metaData!: Package['packageJson']; + private metaData!: PackageWithScripts['packageJson']; constructor(options: WorkspaceDevRunnerOptions) { this.options = { @@ -59,7 +59,7 @@ export class WorkspaceDevRunner { } async init(): Promise { - this.metaData = await readPackageJson(path.join(this.cwd, PACKAGE_JSON)); + this.metaData = await readPackageJson(join(this.cwd, PACKAGE_JSON)); this.buildDependencyGraph(); debugLog( 'Dependency graph:\n' + @@ -77,7 +77,7 @@ export class WorkspaceDevRunner { )!; this.packages = packages; - const initNode = (pkg: Package) => { + const initNode = (pkg: PackageWithScripts) => { const { packageJson, dir } = pkg; const { name, dependencies, devDependencies, peerDependencies } = packageJson; @@ -173,12 +173,15 @@ export class WorkspaceDevRunner { visitNodes(node: string): Promise { return new Promise((resolve) => { - const { name, path } = this.getNode(node); + const { name, path, packageJson } = this.getNode(node); const logger = new Logger({ name, }); + const config = this.options?.projects?.[name]; - if (config?.skip) { + const command = config?.command ? config.command : 'dev'; + const scripts = packageJson.scripts || {}; + if (config?.skip || !scripts[command]) { this.visited[node] = true; this.visiting[node] = false; debugLog(`Skip visit node: ${node}`); @@ -187,18 +190,14 @@ export class WorkspaceDevRunner { } this.visiting[node] = true; - const child = spawn( - 'npm', - ['run', config?.command ? config.command : 'dev'], - { - cwd: path, - env: { - ...process.env, - FORCE_COLOR: '3', - }, - shell: true, + const child = spawn('npm', ['run', command], { + cwd: path, + env: { + ...process.env, + FORCE_COLOR: '3', }, - ); + shell: true, + }); child.stdout.on('data', async (data) => { const stdout = data.toString(); From 8b3d8e7685cc11cb9ddb37117ec0eb2516ebc45f Mon Sep 17 00:00:00 2001 From: nyqykk Date: Mon, 22 Dec 2025 17:35:22 +0800 Subject: [PATCH 2/2] chore: remove default modern module --- src/constant.ts | 1 - src/workspace-dev.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/constant.ts b/src/constant.ts index 7467a33..a75bb78 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -2,5 +2,4 @@ export const PACKAGE_JSON = 'package.json'; export const PLUGIN_LOG_TITLE = '[Rsbuild Workspace Dev Plugin]: '; export const RSLIB_READY_MESSAGE = 'build complete, watching for changes'; -export const MODERN_MODULE_READY_MESSAGE = 'Watching for file changes'; export const TSUP_READY_MESSAGE = 'Watching for changes in'; diff --git a/src/workspace-dev.ts b/src/workspace-dev.ts index 7b56432..82f013f 100644 --- a/src/workspace-dev.ts +++ b/src/workspace-dev.ts @@ -3,7 +3,6 @@ import { spawn } from 'child_process'; import graphlib, { Graph } from 'graphlib'; import { join } from 'path'; import { - MODERN_MODULE_READY_MESSAGE, PACKAGE_JSON, PLUGIN_LOG_TITLE, RSLIB_READY_MESSAGE, @@ -212,7 +211,6 @@ export class WorkspaceDevRunner { const matchResult = match ? match(stdout) : stdout.match(RSLIB_READY_MESSAGE) || - stdout.match(MODERN_MODULE_READY_MESSAGE) || stdout.match(TSUP_READY_MESSAGE); if (matchResult) {