Skip to content

Commit d9d8c64

Browse files
committed
fix: skip project which has not define start command
1 parent 469c319 commit d9d8c64

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Package } from '@manypkg/get-packages';
2+
3+
export interface PackageWithScripts extends Package {
4+
packageJson: Package['packageJson'] & {
5+
scripts?: Record<string, string>;
6+
};
7+
}

src/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { Package } from '@manypkg/get-packages';
21
import fs from 'fs';
32
import json5 from 'json5';
43

4+
import type { PackageWithScripts } from './types.js';
5+
56
async function pathExists(path: string) {
67
return fs.promises
78
.access(path)
@@ -21,8 +22,8 @@ export const readJson = async <T>(jsonFileAbsPath: string): Promise<T> => {
2122

2223
export const readPackageJson = async (
2324
pkgJsonFilePath: string,
24-
): Promise<Package['packageJson']> => {
25-
return readJson<Package['packageJson']>(pkgJsonFilePath);
25+
): Promise<PackageWithScripts['packageJson']> => {
26+
return readJson<PackageWithScripts['packageJson']>(pkgJsonFilePath);
2627
};
2728

2829
export const isDebug =

src/workspace-dev.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { getPackagesSync, type Package } from '@manypkg/get-packages';
1+
import { getPackagesSync } from '@manypkg/get-packages';
22
import { spawn } from 'child_process';
33
import graphlib, { Graph } from 'graphlib';
4-
import path from 'path';
5-
4+
import { join } from 'path';
65
import {
76
MODERN_MODULE_READY_MESSAGE,
87
PACKAGE_JSON,
@@ -11,11 +10,12 @@ import {
1110
TSUP_READY_MESSAGE,
1211
} from './constant.js';
1312
import { debugLog, Logger } from './logger.js';
13+
import type { PackageWithScripts } from './types.js';
1414
import { readPackageJson } from './utils.js';
1515

1616
interface GraphNode {
1717
name: string;
18-
packageJson: Package['packageJson'];
18+
packageJson: PackageWithScripts['packageJson'];
1919
path: string;
2020
}
2121

@@ -37,12 +37,12 @@ export class WorkspaceDevRunner {
3737
private options: WorkspaceDevRunnerOptions;
3838
private cwd: string;
3939
private workspaceFileDir: string;
40-
private packages: Package[] = [];
40+
private packages: PackageWithScripts[] = [];
4141
private graph: Graph;
4242
private visited: Record<string, boolean>;
4343
private visiting: Record<string, boolean>;
4444
private matched: Record<string, boolean>;
45-
private metaData!: Package['packageJson'];
45+
private metaData!: PackageWithScripts['packageJson'];
4646

4747
constructor(options: WorkspaceDevRunnerOptions) {
4848
this.options = {
@@ -59,7 +59,7 @@ export class WorkspaceDevRunner {
5959
}
6060

6161
async init(): Promise<void> {
62-
this.metaData = await readPackageJson(path.join(this.cwd, PACKAGE_JSON));
62+
this.metaData = await readPackageJson(join(this.cwd, PACKAGE_JSON));
6363
this.buildDependencyGraph();
6464
debugLog(
6565
'Dependency graph:\n' +
@@ -77,7 +77,7 @@ export class WorkspaceDevRunner {
7777
)!;
7878
this.packages = packages;
7979

80-
const initNode = (pkg: Package) => {
80+
const initNode = (pkg: PackageWithScripts) => {
8181
const { packageJson, dir } = pkg;
8282
const { name, dependencies, devDependencies, peerDependencies } =
8383
packageJson;
@@ -173,12 +173,15 @@ export class WorkspaceDevRunner {
173173

174174
visitNodes(node: string): Promise<void> {
175175
return new Promise((resolve) => {
176-
const { name, path } = this.getNode(node);
176+
const { name, path, packageJson } = this.getNode(node);
177177
const logger = new Logger({
178178
name,
179179
});
180+
180181
const config = this.options?.projects?.[name];
181-
if (config?.skip) {
182+
const command = config?.command ? config.command : 'dev';
183+
const scripts = packageJson.scripts || {};
184+
if (config?.skip || !scripts[command]) {
182185
this.visited[node] = true;
183186
this.visiting[node] = false;
184187
debugLog(`Skip visit node: ${node}`);
@@ -187,18 +190,14 @@ export class WorkspaceDevRunner {
187190
}
188191
this.visiting[node] = true;
189192

190-
const child = spawn(
191-
'npm',
192-
['run', config?.command ? config.command : 'dev'],
193-
{
194-
cwd: path,
195-
env: {
196-
...process.env,
197-
FORCE_COLOR: '3',
198-
},
199-
shell: true,
193+
const child = spawn('npm', ['run', command], {
194+
cwd: path,
195+
env: {
196+
...process.env,
197+
FORCE_COLOR: '3',
200198
},
201-
);
199+
shell: true,
200+
});
202201

203202
child.stdout.on('data', async (data) => {
204203
const stdout = data.toString();

0 commit comments

Comments
 (0)