Skip to content

Commit

Permalink
fix: Resolve paths in option files according to the config directory
Browse files Browse the repository at this point in the history
Fixes #1598
Fixes #1442
  • Loading branch information
Gerrit0 committed Jun 15, 2021
1 parent 858b231 commit 3f39508
Show file tree
Hide file tree
Showing 14 changed files with 559 additions and 356 deletions.
18 changes: 7 additions & 11 deletions src/lib/converter/plugins/PackagePlugin.ts
Expand Up @@ -6,6 +6,7 @@ import { Converter } from "../converter";
import { Context } from "../context";
import { BindOption, readFile } from "../../utils";
import { getCommonDirectory } from "../../utils/fs";
import { join } from "path";

/**
* A handler that tries to find the package.json and readme.md files of the
Expand Down Expand Up @@ -46,12 +47,11 @@ export class PackagePlugin extends ConverterComponent {
this.readmeFile = undefined;
this.packageFile = undefined;

let readme = this.readme;
const noReadmeFile = readme === "none";
if (!noReadmeFile && readme) {
readme = Path.resolve(readme);
if (FS.existsSync(readme)) {
this.readmeFile = readme;
// Path will be resolved already. This is kind of ugly, but...
const noReadmeFile = this.readme == join(process.cwd(), "none");
if (!noReadmeFile && this.readme) {
if (FS.existsSync(this.readme)) {
this.readmeFile = this.readme;
}
}

Expand All @@ -61,11 +61,7 @@ export class PackagePlugin extends ConverterComponent {
dirName === Path.resolve(Path.join(dirName, ".."));

let dirName = Path.resolve(
getCommonDirectory(
this.application.options
.getValue("entryPoints")
.map((path) => Path.resolve(path))
)
getCommonDirectory(this.application.options.getValue("entryPoints"))
);
this.application.logger.verbose(`Begin readme search at ${dirName}`);
while (!packageAndReadmeFound() && !reachedTopDirectory(dirName)) {
Expand Down
21 changes: 12 additions & 9 deletions src/lib/output/plugins/MarkedPlugin.ts
Expand Up @@ -200,28 +200,31 @@ output file :

delete this.includes;
if (this.includeSource) {
const includes = Path.resolve(this.includeSource);
if (
fs.existsSync(includes) &&
fs.statSync(includes).isDirectory()
fs.existsSync(this.includeSource) &&
fs.statSync(this.includeSource).isDirectory()
) {
this.includes = includes;
this.includes = this.includeSource;
} else {
this.application.logger.warn(
"Could not find provided includes directory: " + includes
"Could not find provided includes directory: " +
this.includeSource
);
}
}

if (this.mediaSource) {
const media = Path.resolve(this.mediaSource);
if (fs.existsSync(media) && fs.statSync(media).isDirectory()) {
if (
fs.existsSync(this.mediaSource) &&
fs.statSync(this.mediaSource).isDirectory()
) {
this.mediaDirectory = Path.join(event.outputDirectory, "media");
copySync(media, this.mediaDirectory);
copySync(this.mediaSource, this.mediaDirectory);
} else {
this.mediaDirectory = undefined;
this.application.logger.warn(
"Could not find provided media directory: " + media
"Could not find provided media directory: " +
this.mediaSource
);
}
}
Expand Down

0 comments on commit 3f39508

Please sign in to comment.