Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep resolved as absolute path #1580

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading