Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/sandcastle/scripts/buildGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,31 @@ export async function buildGalleryList(options = {}) {
return condition;
};

const galleryFiles = await globby(
galleryFilesPattern.map((pattern) => join(rootDirectory, pattern, "**/*")),
);
const galleryFilesGlobbyPatterns = galleryFilesPattern.map((pattern) => {
// The join function will return the path in a form that is normalized
// for the OS, meaning that it contains backslashes "\" on Windows
const baseGlobbyPattern = join(rootDirectory, pattern, "**/*");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javagl I think the better solution is to just swap this for posix.join as suggested by the globby docs. Did you try that? any reason not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tied it quickly, and I think that I just stubled over some issue with how to write the import properly 😊 There are a few things that I'd look into (e.g. does posix.join("foo/bar", "baz/buz") result in "foo/bar\baz/buz", or does it also replace the /'s from the existing parts?), but iff it performs some normalization (i.e. that 'replace-all'), then that's probably more idiomatic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now you could just do import { basename, dirname, join, relative, posix } from "node:path"; for it. Maybe a better way long term, just wanted to know if it worked. I believe the last time I looked into windows path issues it did do the normalization inside existing paths. easy to verify but I'm not on windows to test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the import: I think that I was trying to avoid importing posix, because we only need join, and was looking for something along the lines of
import { ..., posix.join as posixJoin } from "node:path";
or some sort of
import { join as posixJoin } from "node:path:posix";
or so, but... that's not really important.


What's more important: posix.join does not do a normalization. For example, when using posix.join for the joining, the output for me is

Create globby pattern
rootDirectory  C:\Develop\CesiumGS\cesium\packages\sandcastle
pattern  gallery
baseGlobbyPattern  C:\Develop\CesiumGS\cesium\packages\sandcastle/gallery/**/*
globbyPattern  C:/Develop/CesiumGS/cesium/packages/sandcastle/gallery/**/*
Successfully built gallery list.

So the join itself does insert the / between sandcastle and gallery, but the prefix is still wrong. (There might be some alternative to the replace call, maybe some normalize or whatnot, but I used replace mainly to check that it works when ~"something like this is done" (no matter how...)).


// From the globby documentation:
// > Note that glob patterns can only contain forward-slashes, not
// > backward-slashes, so if you want to construct a glob pattern
// > from path components, you need to use path.posix.join()
// > instead of path.join().
// However, just do the usual "replace '\' with '/'" here:
const globbyPattern = baseGlobbyPattern.replace(/\\/g, "/");
console.log("Create globby pattern");
console.log("rootDirectory ", rootDirectory);
console.log("pattern ", pattern);
console.log("baseGlobbyPattern ", baseGlobbyPattern);
console.log("globbyPattern ", globbyPattern);
return globbyPattern;
});
const galleryFiles = await globby(galleryFilesGlobbyPatterns);
if (galleryFiles.length === 0) {
// TODO Warn about this and handle it somehow...
console.warn("Did not find any gallery files");
}

const yamlFiles = galleryFiles.filter((path) =>
basename(path).match(galleryItemConfig),
);
Expand Down