Skip to content

Commit

Permalink
Merge pull request #62 from bmish/windows-import
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Oct 5, 2022
2 parents c8968bd + 60a3f0f commit 553f870
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/config-resolution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { existsSync } from 'node:fs';
import { importAbs } from './import.js';
import type { Plugin, Config, Rules, ConfigsToRules } from './types.js';

/**
Expand Down Expand Up @@ -31,7 +32,7 @@ async function resolveConfigRules(config: Config): Promise<Rules> {
continue;
}

const { default: config } = await import(extend);
const { default: config } = await importAbs(extend);
const nestedRules = await resolveConfigRules(config);
Object.assign(rules, nestedRules);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { pathToFileURL } from 'node:url';

/**
* Ensure that we import absolute paths correctly in Windows.
* https://github.com/nodejs/node/issues/31710
*/
export function importAbs(path: string) {
const urlHref = pathToFileURL(path).href;
return import(urlHref);
}
3 changes: 2 additions & 1 deletion lib/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
import { importAbs } from './import.js';
import type { Plugin } from './types.js';
import type { PackageJson } from 'type-fest';

Expand Down Expand Up @@ -28,7 +29,7 @@ export async function loadPlugin(path: string): Promise<Plugin> {
pluginPackageJson.main ?? 'index.js', // This is NPM's default value for this field.
pluginPackageJson.main?.endsWith('/') ? 'index.js' : ''
);
const { default: plugin } = await import(pluginEntryPoint);
const { default: plugin } = await importAbs(pluginEntryPoint);
if (!plugin.rules) {
throw new Error('Could not find exported `rules` object in ESLint plugin.');
}
Expand Down

0 comments on commit 553f870

Please sign in to comment.