Skip to content

Commit

Permalink
fix: keep resolved as absolute path (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Dec 12, 2024
1 parent 6b70b9f commit 97a3bd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/actions/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export abstract class TasksMixin {
}
const generatorNamespace = this.env.namespace(resolved);
const findGenerator = async () => {
const generatorImport = await import(resolved);
const generatorImport = await import(pathToFileURL(resolved).href);
const getFactory = (module: any) =>
module.createGenerator ?? module.default?.createGenerator ?? module.default?.default?.createGenerator;
const factory = getFactory(generatorImport);
Expand Down Expand Up @@ -649,7 +649,7 @@ export abstract class TasksMixin {
if (!generatorResolvedFile) {
// Resolve the generator file.
// Use import.resolve when stable.
generatorResolvedFile = pathToFileURL(createRequire(import.meta.url).resolve(generatorFile)).href;
generatorResolvedFile = createRequire(import.meta.url).resolve(generatorFile);
}

return generatorResolvedFile;
Expand Down
6 changes: 3 additions & 3 deletions test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs, { mkdirSync, rmSync } from 'node:fs';
import os from 'node:os';
import path, { dirname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import process from 'node:process';
import { Buffer } from 'node:buffer';
Expand Down Expand Up @@ -897,7 +897,7 @@ describe('Base', () => {
assert.equal(spy.firstCall.thisValue.options.namespace, 'mocha');
assert.equal(
spy.firstCall.thisValue.options.resolved,
pathToFileURL(createRequire(import.meta.url).resolve(stubPath)).href,
createRequire(import.meta.url).resolve(stubPath),
);
});

Expand Down Expand Up @@ -950,7 +950,7 @@ describe('Base', () => {
spy = sinonSpy();
dummy.resolved = _filename;
stubPath = './fixtures/generator-mocha';
resolvedStub = pathToFileURL(require.resolve(stubPath)).href;
resolvedStub = require.resolve(stubPath);
const module = await import(resolvedStub);
LocalDummy = module.default;
LocalDummy.prototype.exec = spy;
Expand Down

0 comments on commit 97a3bd6

Please sign in to comment.