Skip to content

Commit 8cbc654

Browse files
committed
fix: support for windows
1 parent 0b4d455 commit 8cbc654

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

scripts/tools/copyPackageSet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const copyPackageSet = async (): Promise<void> => {
1313
const libDir = "lib";
1414
const publishPackageJson = path.join(libDir, "package.json");
1515
pkg.private = undefined;
16-
pkg.main = path.relative(libDir, pkg.main);
17-
pkg.module = path.relative(libDir, pkg.module);
18-
pkg.types = path.relative(libDir, pkg.types);
16+
pkg.main = path.posix.relative(libDir, pkg.main);
17+
pkg.module = path.posix.relative(libDir, pkg.module);
18+
pkg.types = path.posix.relative(libDir, pkg.types);
1919
pkg.directories = undefined;
2020
pkg.files = undefined;
2121
fs.writeFileSync(publishPackageJson, JSON.stringify(pkg, null, 2), {

src/Converter/v3/TypeNodeContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface ReferencePathSet {
1616
const generatePath = (entryPoint: string, currentPoint: string, referencePath: string): ReferencePathSet => {
1717
const ext = Path.extname(currentPoint); // .yml
1818
const from = Path.relative(Path.dirname(entryPoint), currentPoint).replace(ext, ""); // components/schemas/A/B
19-
const base = Path.dirname(from);
20-
const result = Path.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
19+
const base = Path.dirname(from).replace(Path.sep, "/");
20+
const result = Path.posix.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
2121
const pathArray = result.split("/");
2222
return {
2323
pathArray,
@@ -29,7 +29,7 @@ const calculateReferencePath = (store: Store.Type, base: string, pathArray: stri
2929
let names: string[] = [];
3030
let unresolvedPaths: string[] = [];
3131
pathArray.reduce((previous, lastPath, index) => {
32-
const current = Path.join(previous, lastPath);
32+
const current = Path.posix.join(previous, lastPath);
3333
// ディレクトリが深い場合は相対パスが`..`を繰り返す可能性があり、
3434
// その場合はすでに登録されたnamesを削除する
3535
if (lastPath === ".." && names.length > 0) {

src/Converter/v3/components/Reference.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const generateLocalReference = (reference: OpenApi.Reference): LocalRefer
100100
return;
101101
}
102102
const name = reference.$ref.split(localReferencePattern)[1];
103-
const localPath = path.join(localReferenceComponents[localReferencePattern], name);
103+
const localPath = path.posix.join(localReferenceComponents[localReferencePattern], name);
104104
if (!localPath.startsWith("components")) {
105105
throw new DevelopmentError(`localPath is not start "components":\n${localPath}`);
106106
}
@@ -138,7 +138,7 @@ export const generate = <T>(entryPoint: string, currentPoint: string, reference:
138138

139139
const relativePathFromEntryPoint = path.relative(path.dirname(entryPoint), referencePoint); // components/hoge/fuga.yml
140140
const ext = path.extname(relativePathFromEntryPoint); // .yml
141-
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split("/"); // ["components", "hoge", "fuga"]
141+
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split(path.sep); // ["components", "hoge", "fuga"]
142142
const targetPath: string = pathArray.join("/"); // components/hoge/fuga
143143
const schemaName = pathArray[pathArray.length - 1]; // fuga
144144
const componentName = pathArray[0] === "components" ? pathArray[1] : "";

src/Converter/v3/components/Response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const generateReferenceNamespace = (
7777
kind: "namespace",
7878
name: nameWithStatusCode,
7979
});
80-
const headerNamespace = store.getStatement(path.join(responseReference.path, "Header"), "namespace");
80+
const headerNamespace = store.getStatement(path.posix.join(responseReference.path, "Header"), "namespace");
8181
if (headerNamespace) {
8282
store.addStatement(`${basePath}/Header`, {
8383
kind: "namespace",

src/Converter/v3/components/Responses.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const generateNamespace = (
4141
reference.referencePoint,
4242
store,
4343
factory,
44-
path.dirname(reference.path), // referencePoint basename === namespace name
44+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
4545
reference.name,
4646
reference.data,
4747
context,
@@ -94,7 +94,7 @@ export const generateNamespaceWithStatusCode = (
9494
reference.referencePoint,
9595
store,
9696
factory,
97-
path.dirname(reference.path), // referencePoint basename === namespace name
97+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
9898
reference.name,
9999
reference.data,
100100
context,
@@ -157,7 +157,7 @@ export const generateInterfacesWithStatusCode = (
157157
reference.referencePoint,
158158
store,
159159
factory,
160-
path.dirname(reference.path), // referencePoint basename === namespace name
160+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
161161
reference.name,
162162
reference.data,
163163
context,

src/Converter/v3/store/Store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { relative } from "path";
1+
import * as Path from "path";
22

33
import { Tree } from "@himenon/path-oriented-data-structure";
44
import Dot from "dot-prop";
@@ -87,11 +87,11 @@ export const create = (factory: Factory.Type, rootDocument: OpenApi.Document): T
8787
if (!path.startsWith("components")) {
8888
throw new UnSupportError(`componentsから始まっていません。path=${path}`);
8989
}
90-
const targetPath = relative("components", path);
90+
const targetPath = Path.posix.relative("components", path);
9191
operator.set(targetPath, Structure.createInstance(statement));
9292
},
9393
getStatement: <T extends Structure.DataStructure.Kind>(path: string, kind: T): Structure.DataStructure.GetChild<T> | undefined => {
94-
const targetPath = relative("components", path);
94+
const targetPath = Path.posix.relative("components", path);
9595
return getChildByPaths(targetPath, kind);
9696
},
9797
getRootStatements,

0 commit comments

Comments
 (0)