Skip to content

Commit f9cdaa9

Browse files
committed
remove Deno.realPathSync from our codebase (keep monkey-patched version because deno's stdlib calls into it)
1 parent fe88aa4 commit f9cdaa9

40 files changed

+174
-124
lines changed

src/command/preview/cmd.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { isHtmlOutput } from "../../config/format.ts";
4141
import { renderProject } from "../render/project.ts";
4242
import { renderServices } from "../render/render-shared.ts";
4343
import { parseFormatString } from "../../core/pandoc/pandoc-formats.ts";
44+
import { normalizePath } from "../../core/path.ts";
4445
export const previewCommand = new Command()
4546
.name("preview")
4647
.stopEarly()
@@ -249,7 +250,7 @@ export const previewCommand = new Command()
249250
// in the project input list -- in this case allow things to proceed
250251
// without a render
251252
const format = await previewFormat(file, flags.to, project);
252-
const filePath = Deno.realPathSync(file);
253+
const filePath = normalizePath(file);
253254
if (!project.files.input.includes(filePath)) {
254255
if (extname(file) === ".md" && projectPreviewServe(project)) {
255256
setPreviewFormat(format, flags, args);

src/command/preview/preview.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
} from "../../project/types.ts";
7373
import { projectOutputDir } from "../../project/project-shared.ts";
7474
import { projectContext } from "../../project/project-context.ts";
75-
import { pathWithForwardSlashes } from "../../core/path.ts";
75+
import { normalizePath, pathWithForwardSlashes } from "../../core/path.ts";
7676
import {
7777
isJupyterHubServer,
7878
isRStudioServer,
@@ -168,7 +168,7 @@ export async function preview(
168168
const handler = isPdfContent(result.outputFile)
169169
? pdfFileRequestHandler(
170170
result.outputFile,
171-
Deno.realPathSync(file),
171+
normalizePath(file),
172172
flags,
173173
result.format,
174174
options.port!,
@@ -178,15 +178,15 @@ export async function preview(
178178
: project
179179
? projectHtmlFileRequestHandler(
180180
project,
181-
Deno.realPathSync(file),
181+
normalizePath(file),
182182
flags,
183183
result.format,
184184
reloader,
185185
changeHandler.render,
186186
)
187187
: htmlFileRequestHandler(
188188
result.outputFile,
189-
Deno.realPathSync(file),
189+
normalizePath(file),
190190
flags,
191191
result.format,
192192
reloader,
@@ -368,7 +368,7 @@ async function renderForPreview(
368368
// determine files to watch for reload -- take the resource
369369
// files detected during render, chase down additional references
370370
// in css files, then fitler out the _files dir
371-
file = Deno.realPathSync(file);
371+
file = normalizePath(file);
372372
const filesDir = join(dirname(file), inputFilesDir(file));
373373
const resourceFiles = renderResult.files.reduce(
374374
(resourceFiles: string[], file: RenderResultFile) => {
@@ -399,7 +399,7 @@ async function renderForPreview(
399399
if (!isAbsolute(extensionFile)) {
400400
const extensionFullPath = join(dirname(file.input), extensionFile);
401401
if (existsSync(extensionFullPath)) {
402-
extensionFiles.push(Deno.realPathSync(extensionFullPath));
402+
extensionFiles.push(normalizePath(extensionFullPath));
403403
}
404404
}
405405
});
@@ -522,7 +522,7 @@ function previewWatcher(watches: Watch[]): Watcher {
522522
return {
523523
...watch,
524524
files: watch.files.filter(existsSync).map((file) => {
525-
return Deno.realPathSync(file);
525+
return normalizePath(file);
526526
}),
527527
};
528528
});
@@ -635,7 +635,7 @@ function htmlFileRequestHandlerOptions(
635635
if (
636636
prevReq &&
637637
existsSync(prevReq.path) &&
638-
Deno.realPathSync(prevReq.path) === Deno.realPathSync(inputFile) &&
638+
normalizePath(prevReq.path) === normalizePath(inputFile) &&
639639
await previewRenderRequestIsCompatible(prevReq, flags)
640640
) {
641641
// don't wait for the promise so the

src/command/render/cleanup.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { dirname, extname, isAbsolute, join } from "path/mod.ts";
1010

1111
import * as ld from "../../core/lodash.ts";
1212

13-
import { removeIfEmptyDir, removeIfExists } from "../../core/path.ts";
13+
import {
14+
normalizePath,
15+
removeIfEmptyDir,
16+
removeIfExists,
17+
} from "../../core/path.ts";
1418
import { figuresDir, inputFilesDir } from "../../core/render.ts";
1519

1620
import { Format } from "../../config/types.ts";
@@ -53,7 +57,7 @@ export function renderCleanup(
5357
filesDirLibDir(input),
5458
);
5559
if (existsSync(libDir)) {
56-
supporting.push(Deno.realPathSync(libDir));
60+
supporting.push(normalizePath(libDir));
5761
}
5862
// narrow supporting to figures dir for non-html formats
5963
} else {
@@ -62,7 +66,7 @@ export function renderCleanup(
6266
inputFilesDir(input),
6367
);
6468
if (existsSync(filesDir)) {
65-
filesDir = Deno.realPathSync(filesDir);
69+
filesDir = normalizePath(filesDir);
6670
}
6771
supporting = supporting.map((supportingDir) => {
6872
if (filesDir === supportingDir) {

src/command/render/flags.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { RenderFlags, RenderOptions } from "./types.ts";
3131
import * as ld from "../../core/lodash.ts";
3232

3333
import { isAbsolute, SEP_PATTERN } from "path/mod.ts";
34+
import { normalizePath } from "../../core/path.ts";
3435

3536
export const kStdOut = "-";
3637

@@ -218,7 +219,7 @@ export async function parseRenderFlags(args: string[]) {
218219
if (isAbsolute(arg)) {
219220
flags.executeDir = arg;
220221
} else {
221-
flags.executeDir = Deno.realPathSync(arg);
222+
flags.executeDir = normalizePath(arg);
222223
}
223224
}
224225

src/command/render/freeze.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import { cloneDeep } from "../../core/lodash.ts";
2020
import { inputFilesDir } from "../../core/render.ts";
2121
import { TempContext } from "../../core/temp.ts";
2222
import { md5Hash } from "../../core/hash.ts";
23-
import { removeIfEmptyDir, removeIfExists, safeRemoveIfExists } from "../../core/path.ts";
23+
import {
24+
normalizePath,
25+
removeIfEmptyDir,
26+
removeIfExists,
27+
safeRemoveIfExists,
28+
} from "../../core/path.ts";
2429

2530
import {
2631
kIncludeAfterBody,
@@ -63,7 +68,7 @@ export function freezeExecuteResult(
6368
// make the supporting dirs relative to the input file dir
6469
result.supporting = result.supporting.map((file) => {
6570
if (isAbsolute(file)) {
66-
return relative(Deno.realPathSync(dirname(input)), file);
71+
return relative(normalizePath(dirname(input)), file);
6772
} else {
6873
return file;
6974
}
@@ -101,7 +106,7 @@ export function defrostExecuteResult(
101106
if (force || hash === freezeInputHash(source)) {
102107
// full path to supporting
103108
result.supporting = result.supporting.map((file) =>
104-
join(Deno.realPathSync(dirname(source)), file)
109+
join(normalizePath(dirname(source)), file)
105110
);
106111

107112
// convert includes to files
@@ -135,7 +140,7 @@ export function projectFreezerDir(dir: string, hidden: boolean) {
135140
? projectScratchPath(dir, kProjectFreezeDir)
136141
: join(dir, kProjectFreezeDir);
137142
ensureDirSync(freezeDir);
138-
return Deno.realPathSync(freezeDir);
143+
return normalizePath(freezeDir);
139144
}
140145

141146
export function copyToProjectFreezer(

src/command/render/output-tex.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ export function texToPdfOutputRecipe(
109109

110110
// final output needs to either absolute or input dir relative
111111
// (however it may be working dir relative when it is passed in)
112-
return normalizePath(input, finalOutput);
112+
return texNormalizePath(input, finalOutput);
113113
} else {
114-
return normalizePath(input, pdfOutput);
114+
return texNormalizePath(input, pdfOutput);
115115
}
116116
};
117117

118118
const pdfOutput = finalOutput
119-
? finalOutput === kStdOut ? undefined : normalizePath(input, finalOutput)
120-
: normalizePath(input, pdfGenerator.computePath(input, format));
119+
? finalOutput === kStdOut ? undefined : texNormalizePath(input, finalOutput)
120+
: texNormalizePath(input, pdfGenerator.computePath(input, format));
121121

122122
// tweak writer if it's pdf
123123
const to = format.pandoc.to === "pdf" ? pdfIntermediateTo : format.pandoc.to;
@@ -210,7 +210,7 @@ export function contextPdfOutputRecipe(
210210
);
211211
}
212212

213-
const normalizePath = (input: string, output: string) => {
213+
const texNormalizePath = (input: string, output: string) => {
214214
if (isAbsolute(output)) {
215215
return output;
216216
} else {

src/command/render/pandoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as ld from "../../core/lodash.ts";
1919
import { Document } from "../../core/deno-dom.ts";
2020

2121
import { execProcess } from "../../core/process.ts";
22-
import { dirAndStem } from "../../core/path.ts";
22+
import { dirAndStem, normalizePath } from "../../core/path.ts";
2323
import { mergeConfigs } from "../../core/config.ts";
2424

2525
import {
@@ -468,7 +468,7 @@ export async function runPandoc(
468468

469469
// The user partials (if any)
470470
const userPartials = readPartials(options.format.metadata, cwd);
471-
const inputDir = Deno.realPathSync(cwd);
471+
const inputDir = normalizePath(cwd);
472472
const resolvePath = (path: string) => {
473473
if (isAbsolute(path)) {
474474
return path;

src/command/render/project.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
projectOutputDir,
6262
} from "../../project/project-shared.ts";
6363
import { asArray } from "../../core/array.ts";
64+
import { normalizePath } from "../../core/path.ts";
6465

6566
export async function renderProject(
6667
context: ProjectContext,
@@ -73,7 +74,7 @@ export async function renderProject(
7374
const projOutputDir = projectOutputDir(context);
7475

7576
// get real path to the project
76-
const projDir = Deno.realPathSync(context.dir);
77+
const projDir = normalizePath(context.dir);
7778

7879
// is this an incremental render?
7980
const incremental = !!files;
@@ -90,7 +91,7 @@ export async function renderProject(
9091
if (!existsSync(target)) {
9192
throw new Error("Render target does not exist: " + file);
9293
}
93-
return Deno.realPathSync(target);
94+
return normalizePath(target);
9495
});
9596
};
9697

@@ -167,9 +168,9 @@ export async function renderProject(
167168
(options.flags?.clean == true) && (projType.cleanOutputDir === true)
168169
) {
169170
// ouptut dir
170-
const realProjectDir = Deno.realPathSync(context.dir);
171+
const realProjectDir = normalizePath(context.dir);
171172
if (existsSync(projOutputDir)) {
172-
const realOutputDir = Deno.realPathSync(projOutputDir);
173+
const realOutputDir = normalizePath(projOutputDir);
173174
if (
174175
(realOutputDir !== realProjectDir) &&
175176
realOutputDir.startsWith(realProjectDir)

src/command/render/render-files.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ import * as ld from "../../core/lodash.ts";
6262
import { basename, dirname, join, relative } from "path/mod.ts";
6363
import { Format } from "../../config/types.ts";
6464
import { figuresDir, inputFilesDir } from "../../core/render.ts";
65-
import { removeIfEmptyDir, removeIfExists } from "../../core/path.ts";
65+
import {
66+
normalizePath,
67+
removeIfEmptyDir,
68+
removeIfExists,
69+
} from "../../core/path.ts";
6670
import { resourcePath } from "../../core/resources.ts";
6771
import { YAMLValidationError } from "../../core/yaml.ts";
6872
import { resolveParams } from "./flags.ts";
@@ -198,7 +202,7 @@ export async function renderExecute(
198202
libDir: context.libDir,
199203
format: context.format,
200204
projectDir: context.project?.dir,
201-
cwd: flags.executeDir || dirname(Deno.realPathSync(context.target.source)),
205+
cwd: flags.executeDir || dirname(normalizePath(context.target.source)),
202206
params: resolveParams(flags.params, flags.paramsFile),
203207
quiet: flags.quiet,
204208
previewServer: context.options.previewServer,

src/command/render/render-shared.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { execProcess } from "../../core/process.ts";
4646
import { createExtensionContext } from "../../extension/extension.ts";
4747
import { createTempContext } from "../../core/temp.ts";
4848
import { createNamedLifetime, getNamedLifetime } from "../../core/lifetimes.ts";
49+
import { normalizePath } from "../../core/path.ts";
4950

5051
export async function render(
5152
path: string,
@@ -68,8 +69,8 @@ export async function render(
6869
// a files list that is only those files in the subdirectory
6970
let files: string[] | undefined;
7071
if (context) {
71-
const renderDir = Deno.realPathSync(path);
72-
const projectDir = Deno.realPathSync(context.dir);
72+
const renderDir = normalizePath(path);
73+
const projectDir = normalizePath(context.dir);
7374
if (renderDir !== projectDir) {
7475
files = context.files.input.filter((file) =>
7576
file.startsWith(renderDir)

0 commit comments

Comments
 (0)