Skip to content

Commit

Permalink
fix: dts lint --write-file should not ouput abs path (#120)
Browse files Browse the repository at this point in the history
* fix: dts lint --write-file outputs absolute path

fixes #118

* chore: add tests for issue 118
  • Loading branch information
aladdin-add committed Dec 30, 2021
1 parent ce64c0a commit 7371abe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/createEslintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export async function createEslintConfig({
}

const file = path.join(rootDir, '.eslintrc.js');
// if the path is an abs path(e.g. "/Users/user/my-project/.eslintrc.js"),
// need to convert a rel path to app root.
config.extends = config.extends.map((it) =>
/^\//u.test(it) ? path.relative(rootDir, it) : it
);
try {
await fs.writeFile(
file,
Expand Down
18 changes: 15 additions & 3 deletions test/e2e/dts-lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as shell from 'shelljs';

import shell from 'shelljs';
import path from 'path';
import * as util from '../utils/fixture';

shell.config.silent = true;
Expand Down Expand Up @@ -100,10 +100,22 @@ describe('dts lint', () => {
util.setupStageWithFixture(testDir, stageName, 'build-default');
});

it('should create the file', () => {
it('should create a valid eslint config file', () => {
const cwd = shell.pwd().stdout;

const output = shell.exec(`node ../dist/index.js lint --write-file`);
expect(shell.test('-f', '.eslintrc.js')).toBeTruthy();
expect(output.code).toBe(0);

// https://github.com/weiran-zsd/dts-cli/issues/118
const eslintrc: { extends: any[] } = require(path.join(
cwd,
'.eslintrc.js'
));
const configs: string[] = eslintrc.extends;
configs.map((item) =>
expect(typeof item === 'string' && !item.startsWith('/')).toBe(true)
);
});

afterAll(() => {
Expand Down

0 comments on commit 7371abe

Please sign in to comment.