Skip to content

Commit

Permalink
fix import module at windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 16, 2023
1 parent 6bacec6 commit 5279fb9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
createYoRcTransform,
createYoResolveTransform
} = require('./util/transform');
const {requireOrImport} = require('./util/esm');

const {isFilePending} = FileEditor.State;

Expand Down Expand Up @@ -564,13 +565,15 @@ class Environment extends Base {
return;
}

// eslint-disable-next-line node/no-unsupported-features/es-syntax
const importModule = async () => import(meta.resolved);
const instantiate = async (args, options) => this.instantiate(await this._findGeneratorClass(await meta.importGenerator()), args, options);
const {importGenerator, resolved} = meta;
const importModule = async () => requireOrImport(resolved);
const importGeneratorClass = async () => this._findGeneratorClass(await importGenerator(), meta);
const instantiate = async (args, options) => this.instantiate(await importGeneratorClass(), args, options);
const instantiateHelp = async () => instantiate([], {help: true});
const newMeta = {
...meta,
importModule,
importGeneratorClass,
instantiate,
instantiateHelp
};
Expand Down
32 changes: 32 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,38 @@ describe('Environment', () => {
});
});

describe.only('#getGeneratorMeta{}', () => {
it('importGenerator should return a class', async function () {
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
const meta = this.env.getGeneratorMeta('fixtures:generator-module');
assert.equal(typeof await meta.importGeneratorClass(), 'function');
});
it('importModule should return the generator module', async function () {
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
const meta = this.env.getGeneratorMeta('fixtures:generator-module');
const Generator = await meta.importGeneratorClass();
const module = await meta.importModule();
assert.strictEqual(Generator, module.default);
});
it('intantiate should return an instance', async function () {
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
const meta = this.env.getGeneratorMeta('fixtures:generator-module');
const Generator = await meta.importGeneratorClass();
const generator = await meta.instantiate();
assert.ok(generator instanceof Generator);
});
it('intantiateHelp should return an instance with help option', async function () {
this.env
.register(path.join(__dirname, './fixtures/generator-module/generators/app'), 'fixtures:generator-module');
const meta = this.env.getGeneratorMeta('fixtures:generator-module');
const generator = await meta.instantiateHelp();
assert.strictEqual(generator.options.help, true);
});
});

describe('#run() a ts generator', () => {
beforeEach(function () {
this.env
Expand Down

0 comments on commit 5279fb9

Please sign in to comment.