mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-10 04:21:20 +00:00
fix: fix ignore file on windows when used with linux then (#432)
This commit is contained in:
@@ -5,6 +5,8 @@ jest.mock('node-fetch');
|
|||||||
jest.mock('@redocly/openapi-core');
|
jest.mock('@redocly/openapi-core');
|
||||||
jest.mock('../../utils');
|
jest.mock('../../utils');
|
||||||
|
|
||||||
|
jest.requireMock('@redocly/openapi-core').slash = jest.fn(); // for some reason slash is not mocked, mocking explicitly
|
||||||
|
|
||||||
describe('push', () => {
|
describe('push', () => {
|
||||||
const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
|
const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,7 @@
|
|||||||
import { isSubdir, slash } from '../utils';
|
import { isSubdir } from '../utils';
|
||||||
|
|
||||||
jest.mock("os");
|
jest.mock("os");
|
||||||
|
|
||||||
|
|
||||||
describe('slash path', () => {
|
|
||||||
it('can correctly slash path', () => {
|
|
||||||
[
|
|
||||||
['foo\\bar', 'foo/bar'],
|
|
||||||
['foo/bar', 'foo/bar'],
|
|
||||||
['foo\\中文', 'foo/中文'],
|
|
||||||
['foo/中文', 'foo/中文'],
|
|
||||||
].forEach(([path, expectRes]) => {
|
|
||||||
expect(slash(path)).toBe(expectRes);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not modify extended length paths', () => {
|
|
||||||
const extended = '\\\\?\\some\\path';
|
|
||||||
expect(slash(extended)).toBe(extended);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isSubdir', () => {
|
describe('isSubdir', () => {
|
||||||
it('can correctly determine if subdir', () => {
|
it('can correctly determine if subdir', () => {
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { performance } from 'perf_hooks';
|
|||||||
import { yellow, green, blue } from 'colorette';
|
import { yellow, green, blue } from 'colorette';
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
|
|
||||||
import { bundle, Config, loadConfig, RedoclyClient, IGNORE_FILE, BundleOutputFormat, getTotals } from '@redocly/openapi-core';
|
import { bundle, Config, loadConfig, RedoclyClient, IGNORE_FILE, BundleOutputFormat, getTotals, slash } from '@redocly/openapi-core';
|
||||||
import {
|
import {
|
||||||
promptUser,
|
promptUser,
|
||||||
exitWithError,
|
exitWithError,
|
||||||
@@ -13,7 +13,6 @@ import {
|
|||||||
getFallbackEntryPointsOrExit,
|
getFallbackEntryPointsOrExit,
|
||||||
pluralize,
|
pluralize,
|
||||||
dumpBundle,
|
dumpBundle,
|
||||||
slash
|
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
type Source = {
|
type Source = {
|
||||||
|
|||||||
@@ -286,19 +286,6 @@ export function exitWithError(message: string) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
|
|
||||||
*/
|
|
||||||
export function slash(path: string): string {
|
|
||||||
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
|
|
||||||
if (isExtendedLengthPath) {
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.replace(/\\/g, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if dir is subdir of parent
|
* Checks if dir is subdir of parent
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { pickObjectProps, omitObjectProps } from '../utils';
|
import { pickObjectProps, omitObjectProps, slash } from '../utils';
|
||||||
|
|
||||||
describe('utils', () => {
|
describe('utils', () => {
|
||||||
const testObject = {
|
const testObject = {
|
||||||
@@ -53,4 +53,22 @@ describe('utils', () => {
|
|||||||
expect(omitObjectProps({}, ['d', 'e'])).toStrictEqual({});
|
expect(omitObjectProps({}, ['d', 'e'])).toStrictEqual({});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('slash path', () => {
|
||||||
|
it('can correctly slash path', () => {
|
||||||
|
[
|
||||||
|
['foo\\bar', 'foo/bar'],
|
||||||
|
['foo/bar', 'foo/bar'],
|
||||||
|
['foo\\中文', 'foo/中文'],
|
||||||
|
['foo/中文', 'foo/中文'],
|
||||||
|
].forEach(([path, expectRes]) => {
|
||||||
|
expect(slash(path)).toBe(expectRes);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not modify extended length paths', () => {
|
||||||
|
const extended = '\\\\?\\some\\path';
|
||||||
|
expect(slash(extended)).toBe(extended);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { dirname } from 'path';
|
|||||||
import { red, blue } from 'colorette';
|
import { red, blue } from 'colorette';
|
||||||
|
|
||||||
import { parseYaml, stringifyYaml } from '../js-yaml';
|
import { parseYaml, stringifyYaml } from '../js-yaml';
|
||||||
import { notUndefined } from '../utils';
|
import { notUndefined, slash } from '../utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
OasVersion,
|
OasVersion,
|
||||||
@@ -211,7 +211,7 @@ export class LintConfig {
|
|||||||
const ignoreFile = path.join(dir, IGNORE_FILE);
|
const ignoreFile = path.join(dir, IGNORE_FILE);
|
||||||
const mapped: Record<string, any> = {};
|
const mapped: Record<string, any> = {};
|
||||||
for (const absFileName of Object.keys(this.ignore)) {
|
for (const absFileName of Object.keys(this.ignore)) {
|
||||||
const ignoredRules = (mapped[path.relative(dir, absFileName)] = this.ignore[absFileName]);
|
const ignoredRules = (mapped[slash(path.relative(dir, absFileName))] = this.ignore[absFileName]);
|
||||||
for (const ruleId of Object.keys(ignoredRules)) {
|
for (const ruleId of Object.keys(ignoredRules)) {
|
||||||
ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]) as any;
|
ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]) as any;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export { BundleOutputFormat, readFileFromUrl } from './utils';
|
export { BundleOutputFormat, readFileFromUrl, slash } from './utils';
|
||||||
export { Oas3_1Types } from './types/oas3_1';
|
export { Oas3_1Types } from './types/oas3_1';
|
||||||
export { Oas3Types } from './types/oas3';
|
export { Oas3Types } from './types/oas3';
|
||||||
export { Oas2Types } from './types/oas2';
|
export { Oas2Types } from './types/oas2';
|
||||||
|
|||||||
@@ -147,3 +147,16 @@ export function readFileAsStringSync(filePath: string) {
|
|||||||
export function isPathParameter(pathSegment: string) {
|
export function isPathParameter(pathSegment: string) {
|
||||||
return pathSegment.startsWith('{') && pathSegment.endsWith('{');
|
return pathSegment.startsWith('{') && pathSegment.endsWith('{');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
|
||||||
|
*/
|
||||||
|
export function slash(path: string): string {
|
||||||
|
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
|
||||||
|
if (isExtendedLengthPath) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.replace(/\\/g, '/');
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user