Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type { Config } from "jest";

const config: Config = {
transformIgnorePatterns: [],
// globby v16 is ESM-only. Jest resolves its `unicorn-magic/node` subpath
// import to the ESM entry, which babel-jest cannot load.
moduleNameMapper: {
"^unicorn-magic/node$":
"<rootDir>/node_modules/unicorn-magic/node.js",
"^unicorn-magic/node$": "<rootDir>/node_modules/unicorn-magic/node.js",
},
maxWorkers: 1,
verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/ditto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ const main = async () => {
}
};

export type * from "./src/scan/types";
export type * from "@dittowords/text-extract";

main();
14 changes: 12 additions & 2 deletions lib/src/commands/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { prompt } from "enquirer";
import open from "open";

import logger from "../utils/logger";
import { DittoScanExtractSummary, runExtract } from "../scan/extract";
import { DittoScanCandidate } from "../scan/types";
import {
DittoScanCandidate,
DittoScanExtractSummary,
runExtract,
} from "@dittowords/text-extract";
import { quit } from "../utils/quit";
import initAPIToken from "../services/apiToken/initAPIToken";
import appContext from "../utils/appContext";
Expand Down Expand Up @@ -91,6 +94,13 @@ function logExtractSummary(
` files.skipped_minified: ${summary.filesSkippedMinified}\n`
);
}
// A failed file is dropped from the results, so its strings are missing.
if (summary.filesFailed > 0) {
process.stderr.write(` files.failed: ${summary.filesFailed}\n`);
for (const f of summary.failures) {
process.stderr.write(` ${f.file} (${f.language}): ${f.message}\n`);
}
}
process.stderr.write(
`[ditto-cli scan][extract] emitted ${
summary.candidatesEmitted
Expand Down
2 changes: 1 addition & 1 deletion lib/src/http/scan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { AxiosError } from "axios";
import getHttpClient from "./client";
import { IInitiateScanResponse, ZInitiateScanResponse } from "./types";
import { DittoScanCandidate } from "../scan/types";
import { DittoScanCandidate } from "@dittowords/text-extract";
import DittoError, { ErrorType } from "../utils/DittoError";
import { Blob } from "buffer";

Expand Down
28 changes: 28 additions & 0 deletions lib/src/scan/extract.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from "path";

import { runExtract } from "@dittowords/text-extract";

// The extraction itself is the library's to test. This only checks that the
// CLI resolves the package and gets usable candidates back from a real
// directory, so a bad dependency or a changed entry point fails here.
describe("runExtract", () => {
const testfiles = path.resolve(__dirname, "../../../testfiles");

it("extracts candidates from the test fixtures", async () => {
const { candidates, summary } = await runExtract({ inputPath: testfiles });

expect(summary.filesFailed).toBe(0);
expect(summary.filesScanned).toBeGreaterThan(0);
expect(candidates.length).toBe(summary.candidatesEmitted);

const values = candidates.map((c) => c.value_raw);
expect(values).toContain("Hello World!");

// Every candidate carries the fields the CLI reads downstream.
for (const c of candidates) {
expect(typeof c.id).toBe("string");
expect(c.location.file).not.toBe("");
expect(path.isAbsolute(c.location.file)).toBe(false);
}
});
});
311 changes: 0 additions & 311 deletions lib/src/scan/extract.ts

This file was deleted.

Loading
Loading