Skip to content

Commit cd68282

Browse files
authored
allow to run generators using relative paths. (#507)
1 parent 94f554c commit cd68282

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/environment-full.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createHash } from 'node:crypto';
2-
import { join } from 'node:path';
2+
import { join, resolve } from 'node:path';
33
import type { BaseGeneratorConstructor, InputOutputAdapter } from '@yeoman/types';
44
import { type YeomanNamespace, requireNamespace, toNamespace } from '@yeoman/namespace';
55
import { flyImport } from 'fly-import';
@@ -343,11 +343,15 @@ class FullEnvironment extends EnvironmentBase {
343343
args = Array.isArray(args) ? args : splitArgsFromString(args as unknown as string);
344344
options = { ...options };
345345

346-
const name = args.shift();
346+
let name = args.shift();
347347
if (!name) {
348348
throw new Error('Must provide at least one argument, the generator namespace to invoke.');
349349
}
350350

351+
if (name.startsWith('.')) {
352+
name = resolve(name);
353+
}
354+
351355
this.loadEnvironmentOptions(options);
352356

353357
if (this.experimental && !this.getGeneratorMeta(name)) {

‎test/environment.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import events from 'node:events';
33
import fs from 'node:fs';
44
import path, { dirname, join } from 'node:path';
5+
import process from 'node:process';
56
import util from 'node:util';
67
import { fileURLToPath } from 'node:url';
78
import { createRequire } from 'node:module';
@@ -381,6 +382,20 @@ for (const generatorVersion of allVersions) {
381382
});
382383
});
383384

385+
describe('using relative paths', () => {
386+
let oldCwd;
387+
before(() => {
388+
oldCwd = process.cwd();
389+
process.chdir(dirname(fileURLToPath(import.meta.url)));
390+
});
391+
after(() => {
392+
process.chdir(oldCwd);
393+
});
394+
it('runs a generator', async function () {
395+
return this.env.run(['./fixtures/generator-esm/generators/app/index.js']);
396+
});
397+
});
398+
384399
it('runs a registered writing generator with bail option', async function () {
385400
if (isLegacyVersion(generatorVersion)) {
386401
this.skip();

0 commit comments

Comments
 (0)