🐛 copy over xhr-sync-worker for jsdom
This commit is contained in:
parent
15fd7ae331
commit
8140600a8c
4 changed files with 27 additions and 21 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { Readability } from "@mozilla/readability";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { Chunk } from "../..";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants";
|
||||
import { cleanFragment, cleanHeader } from "../chunk/markdown";
|
||||
import { PageData } from "./crawl"
|
||||
import { PageData } from "./crawl";
|
||||
|
||||
export type ArticleComponent = {
|
||||
title: string;
|
||||
|
|
@ -96,7 +97,6 @@ export function chunkArticle(articleResult: Article): Chunk[] {
|
|||
async function extractTitlesAndBodies(
|
||||
html: string,
|
||||
): Promise<ArticleComponent[]> {
|
||||
const { JSDOM } = await import("jsdom");
|
||||
const dom = new JSDOM(html);
|
||||
const document = dom.window.document;
|
||||
|
||||
|
|
@ -123,7 +123,6 @@ export async function stringToArticle(
|
|||
subpath: string,
|
||||
): Promise<Article | undefined> {
|
||||
try {
|
||||
const { JSDOM } = await import("jsdom");
|
||||
const dom = new JSDOM(htmlContent);
|
||||
let reader = new Readability(dom.window.document);
|
||||
let article = reader.parse();
|
||||
|
|
@ -133,7 +132,7 @@ export async function stringToArticle(
|
|||
}
|
||||
|
||||
let article_components = await extractTitlesAndBodies(article.content);
|
||||
|
||||
|
||||
return {
|
||||
url,
|
||||
subpath,
|
||||
|
|
@ -147,7 +146,7 @@ export async function stringToArticle(
|
|||
}
|
||||
|
||||
export async function pageToArticle(
|
||||
page: PageData
|
||||
page: PageData,
|
||||
): Promise<Article | undefined> {
|
||||
try {
|
||||
return stringToArticle(page.url, page.html, page.path);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const esbuildConfig = {
|
|||
entryPoints: ["src/extension.ts"],
|
||||
bundle: true,
|
||||
outfile: "out/extension.js",
|
||||
external: ["vscode", "esbuild", "jsdom"],
|
||||
external: ["vscode", "esbuild"],
|
||||
format: "cjs",
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
|
|
|
|||
|
|
@ -317,13 +317,7 @@ if (args[2] === "--target") {
|
|||
});
|
||||
|
||||
// Copy node_modules for pre-built binaries
|
||||
const NODE_MODULES_TO_COPY = [
|
||||
"esbuild",
|
||||
"@esbuild",
|
||||
"@lancedb",
|
||||
"@vscode",
|
||||
"jsdom",
|
||||
];
|
||||
const NODE_MODULES_TO_COPY = ["esbuild", "@esbuild", "@lancedb", "@vscode"];
|
||||
fs.mkdirSync("out/node_modules", { recursive: true });
|
||||
|
||||
await Promise.all(
|
||||
|
|
@ -346,5 +340,12 @@ if (args[2] === "--target") {
|
|||
}),
|
||||
),
|
||||
);
|
||||
|
||||
console.log(`[info] Copied ${NODE_MODULES_TO_COPY.join(", ")}`);
|
||||
|
||||
// Copy over any worker files
|
||||
fs.cpSync(
|
||||
"node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js",
|
||||
"out/xhr-sync-worker.js",
|
||||
);
|
||||
})();
|
||||
|
|
|
|||
22
pkg/build.js
22
pkg/build.js
|
|
@ -7,7 +7,7 @@ const esbuildOutputFile = "out/index.js";
|
|||
const platforms = ["darwin", "linux", "win32"];
|
||||
const architectures = ["x64", "arm64"];
|
||||
let targets = platforms.flatMap((platform) =>
|
||||
architectures.map((arch) => `${platform}-${arch}`)
|
||||
architectures.map((arch) => `${platform}-${arch}`),
|
||||
);
|
||||
|
||||
let esbuildOnly = false;
|
||||
|
|
@ -57,7 +57,7 @@ const targetToLanceDb = {
|
|||
} else {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
ncp(
|
||||
`node_modules/${mod}`,
|
||||
|
|
@ -69,10 +69,10 @@ const targetToLanceDb = {
|
|||
} else {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
);
|
||||
console.log(`[info] Copied ${DYNAMIC_IMPORTS.join(", ")}`);
|
||||
|
||||
|
|
@ -105,6 +105,12 @@ const targetToLanceDb = {
|
|||
define: { "import.meta.url": "importMetaUrl" },
|
||||
});
|
||||
|
||||
// Copy over any worker files
|
||||
fs.cpSync(
|
||||
"../core/node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js",
|
||||
"out/xhr-sync-worker.js",
|
||||
);
|
||||
|
||||
if (esbuildOnly) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -114,7 +120,7 @@ const targetToLanceDb = {
|
|||
const targetDir = `bin/${target}`;
|
||||
console.log(`[info] Building ${target}...`);
|
||||
execSync(
|
||||
`npx pkg --no-bytecode --public-packages "*" --public pkgJson/${target} --out-path ${targetDir}`
|
||||
`npx pkg --no-bytecode --public-packages "*" --public pkgJson/${target} --out-path ${targetDir}`,
|
||||
);
|
||||
|
||||
// Download and unzip prebuilt sqlite3 binary for the target
|
||||
|
|
@ -125,7 +131,7 @@ const targetToLanceDb = {
|
|||
execSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
|
||||
fs.copyFileSync(
|
||||
`${targetDir}/build/Release/node_sqlite3.node`,
|
||||
`${targetDir}/node_sqlite3.node`
|
||||
`${targetDir}/node_sqlite3.node`,
|
||||
);
|
||||
fs.unlinkSync(`${targetDir}/build.tar.gz`);
|
||||
fs.rmSync(`${targetDir}/build`, {
|
||||
|
|
@ -136,7 +142,7 @@ const targetToLanceDb = {
|
|||
// Download and unzip prebuilt esbuild binary for the target
|
||||
console.log(`[info] Downloading esbuild for ${target}...`);
|
||||
execSync(
|
||||
`curl -o ${targetDir}/esbuild.tgz https://registry.npmjs.org/@esbuild/${target}/-/${target}-0.19.11.tgz`
|
||||
`curl -o ${targetDir}/esbuild.tgz https://registry.npmjs.org/@esbuild/${target}/-/${target}-0.19.11.tgz`,
|
||||
);
|
||||
execSync(`tar -xzvf ${targetDir}/esbuild.tgz -C ${targetDir}`);
|
||||
if (target.startsWith("win32")) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue