Skip to content

Commit a0ff005

Browse files
committed
Fix topo sort trying to read from packages that aren't within the repository
1 parent ed1fe71 commit a0ff005

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.github/actions/src/info/__tests__/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const mockDirectory: Record<string, string | Record<string, unknown>> = {
3939
'package.json': JSON.stringify({
4040
name: '@sourceacademy/bundle-bundle0',
4141
devDependencies: {
42-
'@sourceacademy/modules-lib': 'workspace:^'
42+
'@sourceacademy/modules-lib': 'workspace:^',
4343
}
4444
})
4545
},
@@ -49,7 +49,8 @@ const mockDirectory: Record<string, string | Record<string, unknown>> = {
4949
'package.json': JSON.stringify({
5050
name: '@sourceacademy/tab-Tab0',
5151
dependencies: {
52-
'@sourceacademy/bundle-bundle0': 'workspace:^'
52+
lodash: '^4.1.1',
53+
'@sourceacademy/bundle-bundle0': 'workspace:^',
5354
},
5455
devDependencies: {
5556
playwright: '^1.54.0'

.github/actions/src/info/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const packageNameRE = /^@sourceacademy\/(.+?)-(.+)$/u;
1616
export async function getRawPackages(gitRoot: string, maxDepth?: number) {
1717
const output: Record<string, RawPackageRecord> = {};
1818

19+
/**
20+
* Search the given directory for package.json files
21+
*/
1922
async function recurser(currentDir: string, currentDepth: number) {
2023
const items = await fs.readdir(currentDir, { withFileTypes: true });
2124
await Promise.all(items.map(async item => {
@@ -93,16 +96,18 @@ export function processRawPackages(topoOrder: string[], packages: Record<string,
9396
if (!packageInfo.hasChanges) {
9497
if (packageInfo.package.dependencies) {
9598
for (const name of Object.keys(packageInfo.package.dependencies)) {
96-
if (packages[name].hasChanges) {
99+
if (packages[name]?.hasChanges) {
97100
packageInfo.hasChanges = true;
98101
break;
99102
}
100103
}
101104
}
102105

106+
// If hasChanges still hasn't been set yet, we can proceed to iterate
107+
// through devDependencies as well
103108
if (!packageInfo.hasChanges && packageInfo.package.devDependencies) {
104109
for (const name of Object.keys(packageInfo.package.devDependencies)) {
105-
if (packages[name].hasChanges) {
110+
if (packages[name]?.hasChanges) {
106111
packageInfo.hasChanges = true;
107112
break;
108113
}
@@ -269,6 +274,6 @@ if (process.env.GITHUB_ACTIONS) {
269274
try {
270275
await main();
271276
} catch (error: any) {
272-
core.setFailed(error.message);
277+
core.setFailed(error);
273278
}
274279
}

0 commit comments

Comments
 (0)