Skip to content

Commit c3c2a97

Browse files
elrrrrrrrclaude
andcommitted
fix(ci): resolve three ut-install compatibility issues
1. cluster options.test.ts: accept root node_modules/egg as valid framework path under flat hoisting (ut install puts workspace packages at root node_modules instead of package-nested node_modules) 2. utils/import.ts: after import.meta.resolve() returns a path without extension (ESM strict mode doesn't auto-add .js for legacy packages without exports field), fall back to tryToResolveFromFile() to find register.js etc. Fixes ImportResolveError for tsconfig-paths/register 3. ci.yml: remove leading ./ from --workspace ./tools/scripts (ut does not accept ./ prefix in workspace paths) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6c2b11c commit c3c2a97

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ jobs:
257257
- name: Run tests
258258
run: |
259259
ut run build
260-
ut run ci --workspace ./tools/scripts
260+
ut run ci --workspace tools/scripts
261261
262262
- name: Code Coverage
263263
if: ${{ matrix.os != 'windows-latest' }}

packages/cluster/test/options.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,12 @@ describe('test/options.test.ts', () => {
239239
baseDir,
240240
});
241241
const expectPaths = [
242-
// run int workspace root
242+
// run in workspace root
243243
path.join(__dirname, '../../egg'),
244-
// run in project root
244+
// run in project root (pnpm nested)
245245
path.join(__dirname, '../node_modules/egg'),
246+
// run with flat/hoisted node_modules (e.g. ut install)
247+
path.join(__dirname, '../../../node_modules/egg'),
246248
];
247249
assert(
248250
expectPaths.includes(options.framework),

packages/utils/src/import.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,13 @@ export function importResolve(filepath: string, options?: ImportResolveOptions):
359359
debug('[importResolve:importMetaResolveFromPaths] %o => %o', filepath, moduleFilePath);
360360
break;
361361
}
362+
// ESM resolver may omit extensions for legacy packages without "exports"
363+
const withExt = tryToResolveFromFile(resolved);
364+
if (withExt) {
365+
moduleFilePath = withExt;
366+
debug('[importResolve:importMetaResolveFromPaths:withExt] %o => %o', filepath, moduleFilePath);
367+
break;
368+
}
362369
} catch (err) {
363370
lastErr = err as Error;
364371
debug('[importResolve:importMetaResolveFromPaths:error] path %o, %o => %o', p, filepath, err);
@@ -379,7 +386,13 @@ export function importResolve(filepath: string, options?: ImportResolveOptions):
379386
debug('[importResolve] import.meta.resolve %o => %o', filepath, moduleFilePath);
380387
const stat = fs.statSync(moduleFilePath, { throwIfNoEntry: false });
381388
if (!stat?.isFile()) {
382-
throw new TypeError(`Cannot find module ${filepath}, because ${moduleFilePath} does not exists`);
389+
// ESM resolver may omit extensions for legacy packages without "exports"
390+
const withExt = tryToResolveFromFile(moduleFilePath);
391+
if (withExt) {
392+
moduleFilePath = withExt;
393+
} else {
394+
throw new TypeError(`Cannot find module ${filepath}, because ${moduleFilePath} does not exists`);
395+
}
383396
}
384397
}
385398
} else {

0 commit comments

Comments
 (0)