Skip to content

Commit

Permalink
Merge branch 'v2.3.1' into V2
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Apr 6, 2024
2 parents 05711bf + 85107de commit d367ad6
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 44 deletions.
7 changes: 6 additions & 1 deletion e2e/fileList.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test.describe("FileList", () => {
lameta = new LametaE2ERunner();
page = await lameta.launch();
await lameta.cancelRegistration();
project = await createNewProject(lameta, "FileList");
project = await createNewProject(lameta, "FileList[don't break]");
fileList = new E2eFileList(lameta, page, project.projectDirectory);
});
test.afterAll(async ({}) => {
Expand All @@ -31,6 +31,11 @@ test.describe("FileList", () => {
await project.goToPeople();
await project.goToSessions();
await expect(match()).toBeVisible();
// the "[don't break]" in the path would break after a reload in lameta 2.3 due to changes in glob behavior
await lameta.softReload();
await project.goToSessions();
await expect(match()).toBeVisible();

// NOT POSSIBLE YET
//await project.deleteFile("foo.txt");
//await expect(match()).toBeUndefined();
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"main": "dist/src/mainProcess/main.js",
"name": "lameta",
"productName": "lameta",
"version": "2.3.0-alpha",
"version": "2.3.1-alpha",
"author": {
"name": "lameta",
"email": "[email protected]"
Expand Down Expand Up @@ -146,7 +146,6 @@
"@types/filesize": "^5.0.0",
"@types/fluent-ffmpeg": "^2.1.8",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^5.0.33",
"@types/image-size": "^0.0.29",
"@types/json5": "^2.2.0",
"@types/lodash": "^4.14.165",
Expand Down Expand Up @@ -195,7 +194,7 @@
"fold-to-ascii": "^5.0.0",
"font-awesome": "^4.7.0",
"fs-extra": "^11.1.0",
"glob": "^7.1.2",
"glob": "^9.3.3",
"graceful-fs": "^4.2.4",
"history": "^4.6.1",
"hotkeys-js": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/export/GenericCsvExporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("people csv export", () => {
it("should contain expected notes", () => {
expect(people(1, "notes")).toBe("");
});
it("should contain expected notes", () => {
it("should contain expected education", () => {
expect(people(1, "education")).toBe("Grade 2");
});
it("should not contain internal fields", () => {
Expand Down
22 changes: 15 additions & 7 deletions src/export/ImdiGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ export default class ImdiGenerator {
const languages = session.getSubjectLanguageCodes();
if (languages.length > 0) {
languages.forEach((code) => {
const langName = this.project.languageFinder.findOneLanguageNameFromCode_Or_ReturnCode(
code
);
const langName =
this.project.languageFinder.findOneLanguageNameFromCode_Or_ReturnCode(
code
);
this.addSessionLanguage(code, langName, "Subject Language");
});
} else {
Expand All @@ -256,9 +257,10 @@ export default class ImdiGenerator {
const workingLanguages = session.getWorkingLanguageCodes();
if (workingLanguages.length > 0) {
workingLanguages.forEach((code) => {
const langName = this.project.languageFinder.findOneLanguageNameFromCode_Or_ReturnCode(
code
);
const langName =
this.project.languageFinder.findOneLanguageNameFromCode_Or_ReturnCode(
code
);
this.addSessionLanguage(code, langName, "Working Language");
});
} else {
Expand Down Expand Up @@ -511,7 +513,13 @@ export default class ImdiGenerator {
}

private resourcesOfType(folder: Folder, type: string) {
folder.files.forEach((f: File) => {
const sortedByFileNames = folder.files.sort((a, b) =>
a.getRelativePathForExportingTheActualFile() <
b.getRelativePathForExportingTheActualFile()
? -1
: 1
);
sortedByFileNames.forEach((f: File) => {
if (ImdiGenerator.shouldIncludeFile(f.getActualFilePath())) {
if (getStatusOfFile(f).missing) {
// At the moment we're not even exporting metadata if the file is
Expand Down
20 changes: 16 additions & 4 deletions src/export/sessionImdi-edolo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ describe("session imdi export", () => {
});
it("should contain Session/Name", () => {
expect(count("METATRANSCRIPT/Session/Name")).toBe(1);
});

it("should contain Session/Name", () => {
expect(value("METATRANSCRIPT/Session/Name")).toBe("ETR009");
});

it("should contain Session/Title", () => {
expect(count("METATRANSCRIPT/Session/Title")).toBe(1);
});
Expand Down Expand Up @@ -106,7 +104,21 @@ it("should contain Actors", () => {
});
it("should contain MediaFiles", () => {
expect(count("METATRANSCRIPT/Session/Resources/MediaFile")).toBe(4);
expect("METATRANSCRIPT/Session/Resources/MediaFile/Type").toMatch("Audio"); // ELAR needs upper case
expect(
count(
"METATRANSCRIPT/Session/Resources/MediaFile[ResourceLink='ETR009/ETR009_Careful.mp3' and Type='Audio']"
)
).toBe(1); // ELAR needs upper case
expect(
count(
"METATRANSCRIPT/Session/Resources/MediaFile[ResourceLink='ETR009/SceneAroundCamera.JPG' and Type='Image']"
)
).toBe(1);
expect(
count(
"METATRANSCRIPT/Session/Resources/MediaFile[ResourceLink='ETR009/ETR009_Tiny.mp4' and Type='Video']"
)
).toBe(1);
});
it("should give a good record for an ELAN file", () => {
expect("METATRANSCRIPT/Session/Resources/WrittenResource[2]/Type").toMatch(
Expand Down
9 changes: 6 additions & 3 deletions src/model/Folder/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
} from "../../components/Notify";
import * as fs from "fs-extra";
import * as Path from "path";
import * as glob from "glob";
import { FieldSet } from "../field/FieldSet";
import assert from "assert";
import { asyncTrash } from "../../other/crossPlatformUtilities";
import {
asyncTrash,
getAllFilesSync
} from "../../other/crossPlatformUtilities";
import { EncounteredVocabularyRegistry } from "../Project/EncounteredVocabularyRegistry";
import { CopyManager, getExtension } from "../../other/CopyManager";
import { sanitizeForArchive } from "../../other/sanitizeForArchive";
Expand Down Expand Up @@ -343,7 +345,8 @@ export abstract class Folder {
files.push(folderMetaDataFile);

//collect the other files and the metdata files they are paired with
const filePaths = glob.sync(Path.join(directory, "*.*"));
// get all the files in the directory without using glob
const filePaths = getAllFilesSync(directory);
filePaths.forEach((path) => {
if (path !== folderMetaDataFile.metadataFilePath) {
// We don't explicitly do anything with the the .meta companion files here,
Expand Down
5 changes: 3 additions & 2 deletions src/model/Project/ProjectDocuments.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Folder, IFolderType } from "../Folder/Folder";
import { File, OtherFile } from "../file/File";
import * as Path from "path";
import * as glob from "glob";
import { globSync } from "glob";
import CustomFieldsTable from "../../components/CustomFieldsTable";
import { EncounteredVocabularyRegistry } from "./EncounteredVocabularyRegistry";
import { getAllFilesSync } from "../../other/crossPlatformUtilities";

export class ProjectDocuments extends Folder {
public get displayName(): string {
Expand All @@ -29,7 +30,7 @@ export class ProjectDocuments extends Folder {
): ProjectDocuments {
const directory = Path.join(rootDirectory, subDirectory);
const files = new Array<File>();
const filePaths = glob.sync(Path.join(directory, "*.*"));
const filePaths = getAllFilesSync(directory);
filePaths.forEach((path) => {
const file = new OtherFile(
path,
Expand Down
8 changes: 2 additions & 6 deletions src/model/file/File.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SessionMetadataFile } from "../Project/Session/Session";
import { ProjectMetadataFile } from "../Project/Project";
import { EncounteredVocabularyRegistry } from "../Project/EncounteredVocabularyRegistry";
import { setResultXml, xexpect as expect } from "../../other/xmlUnitTestUtils";
import { describe, it } from "vitest";

function getPretendAudioFile(): string {
const path = temp.path({ suffix: ".mp3" }) as string;
Expand Down Expand Up @@ -34,10 +35,7 @@ function writeSessionFile(contents: string): {
}

function runTestsOnMetadataFile(contents: string, tests: () => any) {
let sessionFolder;
let filePath;
let tmpFolder;
({ tmpFolder, sessionFolder, filePath } = writeSessionFile(contents));
const { tmpFolder, sessionFolder, filePath } = writeSessionFile(contents);

// note, we are using a session to run these just because we need something
// concrete. It would be an improvement to do it in some more generic way.
Expand Down Expand Up @@ -92,9 +90,7 @@ describe("file", () => {
);
expect(f2.getTextField("notes").text).toBe(notes);
});
});

describe("file", () => {
it("should roundtrip custom field", () => {
const mediaFilePath = getPretendAudioFile();
const f = new OtherFile(mediaFilePath, new EncounteredVocabularyRegistry());
Expand Down
21 changes: 20 additions & 1 deletion src/other/crossPlatformUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from "fs-extra";
import { PatientFS } from "./patientFile";
import { t } from "@lingui/macro";
import { mainProcessApi } from "../mainProcess/MainProcessApiAccess";
import { globSync } from "glob";

export function showInExplorer(path: string) {
if (process.platform === "win32") {
Expand All @@ -12,7 +13,7 @@ export function showInExplorer(path: string) {
electron.shell.showItemInFolder(path);
}
export async function asyncTrash(path: string) {
return asyncTrashWithContext<null>(path, null);
return await asyncTrashWithContext<null>(path, null);
}
export async function asyncTrashWithContext<T>(
path: string,
Expand Down Expand Up @@ -90,3 +91,21 @@ export function copyDirSync(src, dest) {
}
}
}

// this is "safe" because it escapes all characters that glob might interpret and works on windows
// this is "limited" because it does not allow for things like [ and ] in the path
function globSyncSaferAndLimited(pattern: string): string[] {
let p;
if (process.platform === "win32") {
p = pattern.replace(/\\/g, "/"); // deal with windows paths
} else {
p = pattern;
}
// escape() does not work, at least on windows and glob 9.3 const safeDirectory = escape(pattern);
p = p.replace(/\[/g, "\\[").replace(/\]/g, "\\]"); // deal with brackets in the path
return globSync(p);
}

export function getAllFilesSync(directory: string): string[] {
return globSyncSaferAndLimited(Path.join(directory, "*.*"));
}
2 changes: 1 addition & 1 deletion src/other/xmlUnitTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ expect.extend({
pass: true
};
} else {
//console.log(resultXml);
console.log(resultXml);
return {
message: () =>
`expected ${xpath} to be '${expectedValue}' but it was '${value(
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default defineConfig({
renderer({
nodeIntegration: true,
optimizeDeps: {
include: ["xml2js", "glob", "fs-extra", "graceful-fs"]
include: ["xml2js", /*"glob",*/ "fs-extra", "graceful-fs"]
}
}),
dsv() // for importing csv
Expand Down
50 changes: 36 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3343,14 +3343,6 @@
"@types/minimatch" "^5.1.2"
"@types/node" "*"

"@types/glob@^5.0.33":
version "5.0.38"
resolved "https://registry.npmjs.org/@types/glob/-/glob-5.0.38.tgz#20e29f3c6332f6b3329f34711ebb31a03dd74a51"
integrity sha512-rTtf75rwyP9G2qO5yRpYtdJ6aU1QqEhWbtW55qEgquEDa6bXW0s2TWZfDm02GuppjEozOWG/F2UnPq5hAQb+gw==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.npmjs.org/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
Expand Down Expand Up @@ -9556,7 +9548,7 @@ glob@^6.0.4:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.0, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.2.3:
glob@^7.0.0, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.2.3:
version "7.2.3"
resolved "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==
Expand All @@ -9568,6 +9560,16 @@ glob@^7.0.0, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6, glob@^7.2.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^9.3.3:
version "9.3.5"
resolved "https://registry.npmjs.org/glob/-/glob-9.3.5.tgz#ca2ed8ca452781a3009685607fdf025a899dfe21"
integrity sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==
dependencies:
fs.realpath "^1.0.0"
minimatch "^8.0.2"
minipass "^4.2.4"
path-scurry "^1.6.1"

glob@~7.1.1:
version "7.1.7"
resolved "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90"
Expand Down Expand Up @@ -11962,6 +11964,11 @@ [email protected], lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

lru-cache@^10.2.0, "lru-cache@^9.1.1 || ^10.0.0":
version "10.2.0"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3"
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==

lru-cache@^4.0.1:
version "4.1.5"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
Expand All @@ -11977,11 +11984,6 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

"lru-cache@^9.1.1 || ^10.0.0":
version "10.2.0"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3"
integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==

magic-string@^0.30.1:
version "0.30.7"
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.30.7.tgz#0cecd0527d473298679da95a2d7aeb8c64048505"
Expand Down Expand Up @@ -12491,6 +12493,13 @@ minimatch@^5.0.1, minimatch@^5.1.0, minimatch@^5.1.1:
dependencies:
brace-expansion "^2.0.1"

minimatch@^8.0.2:
version "8.0.4"
resolved "https://registry.npmjs.org/minimatch/-/minimatch-8.0.4.tgz#847c1b25c014d4e9a7f68aaf63dedd668a626229"
integrity sha512-W0Wvr9HyFXZRGIDgCicunpQ299OKXs9RgZfaukz4qAW/pJhcpUfupc9c+OObPOFueNy8VSrZgEmDtk6Kh4WzDA==
dependencies:
brace-expansion "^2.0.1"

minimatch@~3.0.2:
version "3.0.8"
resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz#5e6a59bd11e2ab0de1cfb843eb2d82e546c321c1"
Expand Down Expand Up @@ -12544,6 +12553,11 @@ minipass@^3.0.0, minipass@^3.1.1:
dependencies:
yallist "^4.0.0"

minipass@^4.2.4:
version "4.2.8"
resolved "https://registry.npmjs.org/minipass/-/minipass-4.2.8.tgz#f0010f64393ecfc1d1ccb5f582bcaf45f48e1a3a"
integrity sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==

minipass@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz#3e9788ffb90b694a5d0ec94479a45b5d8738133d"
Expand Down Expand Up @@ -13590,6 +13604,14 @@ path-scurry@^1.10.1:
lru-cache "^9.1.1 || ^10.0.0"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"

path-scurry@^1.6.1:
version "1.10.2"
resolved "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz#8f6357eb1239d5fa1da8b9f70e9c080675458ba7"
integrity sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==
dependencies:
lru-cache "^10.2.0"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"

[email protected]:
version "0.1.7"
resolved "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
Expand Down

0 comments on commit d367ad6

Please sign in to comment.