Skip to content

Commit

Permalink
Use enhanced-resolve for node resolution (#36)
Browse files Browse the repository at this point in the history
This moves to using `enhanced-resolve` for resolving reporters in the
CLI. Primarily because it is more up to date with the node resolution
algorithm, but seems we dropped a few deep dependencies along the way
too (which is good).
  • Loading branch information
43081j authored Oct 10, 2024
1 parent a0f0088 commit fa83ce9
Show file tree
Hide file tree
Showing 4 changed files with 1,193 additions and 1,023 deletions.
6 changes: 4 additions & 2 deletions fixtures/custom-reporter/node_modules/dual/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import fs from 'fs';
import resolve from 'resolve';
import resolve from 'enhanced-resolve';
import { command as createCommand, Error as CliError } from 'clap';
import * as reporters from './reporter/index.js';
import { validatePath, validateString } from './helpers.js';
Expand Down Expand Up @@ -29,6 +29,10 @@ function printResult(result, reporter) {
}
}

const nodeResolver = resolve.create.sync({
conditionNames: ['node', 'import']
});

const command = createCommand('csstree-validate [fileOrDir]')
.version(version)
.option(
Expand All @@ -43,7 +47,7 @@ const command = createCommand('csstree-validate [fileOrDir]')

if (!hasOwnProperty.call(reporters, nameOrFile)) {
try {
const resolvedPath = resolve.sync(nameOrFile, { basedir: process.cwd() });
const resolvedPath = nodeResolver(process.cwd(), nameOrFile);
return import(resolvedPath);
} catch (e) {}

Expand Down
Loading

0 comments on commit fa83ce9

Please sign in to comment.