Skip to content

Commit

Permalink
Backport changes to @dqbd/tiktoken
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Jan 28, 2024
1 parent de6d1c7 commit 4491997
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"workspaces": [
"js",
"wasm",
"wasm/alias",
"static"
],
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions wasm/alias/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@dqbd/tiktoken",
"version": "1.0.12",
"repository": {
"type": "git",
"url": "https://github.com/dqbd/tiktoken"
},
"publishConfig": {
"directory": "./dist",
"access": "public"
}
}
3 changes: 2 additions & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"license": "MIT",
"scripts": {
"build": "run-s build:*",
"build:cleanup": "rm -rf dist/",
"build:cleanup": "rm -rf dist/ && rm -rf alias/dist/",
"build:wasm": "run-s wasm:*",
"build:postprocess": "tsx scripts/postprocess.ts",
"build:alias": "tsx scripts/alias.ts",
"wasm:bundler": "wasm-pack build --target bundler --weak-refs --release --out-dir dist && rm -rf dist/.gitignore dist/README.md dist/package.json",
"wasm:lite": "wasm-pack build --target bundler --weak-refs --release --out-dir dist/lite --no-default-features && rm -rf dist/lite/.gitignore dist/lite/README.md dist/lite/package.json",
"test": "yarn vitest run"
Expand Down
20 changes: 20 additions & 0 deletions wasm/scripts/alias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as fs from "node:fs/promises";
import * as path from "node:path";

async function createAlias() {
const srcDist = path.resolve(__dirname, "../dist");
const targetDist = path.resolve(__dirname, "../alias/dist");

await fs.cp(srcDist, targetDist, { recursive: true });

const pkgPath = path.resolve(srcDist, "package.json");

const pkg = JSON.parse(await fs.readFile(pkgPath, { encoding: "utf-8" }));
pkg["name"] = "@dqbd/tiktoken";

await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), {
encoding: "utf-8",
});
}

createAlias();

0 comments on commit 4491997

Please sign in to comment.