fix(js): use script dir not running cwd

This commit is contained in:
Erica Marigold 2024-06-19 18:27:12 +05:30
parent 531a9ffdf5
commit cff721880b
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
8 changed files with 46 additions and 27 deletions

View file

@ -1 +1,3 @@
npm/
npm/
lune
lune.exe

View file

@ -1,8 +1,10 @@
# Deno/Node Packages
This package exports [lune](https://github.com/lune-org/lune), the standalone luau runtime as a JS package to be used as a dependency in a JS project.
This package exports [lune](https://github.com/lune-org/lune), the standalone
luau runtime as a JS package to be used as a dependency in a JS project.
To install the package, run one of the following in your project, substituting `{VERSION}` with the version of lune you want to install:
To install the package, run one of the following in your project, substituting
`{VERSION}` with the version of lune you want to install:
```sh
# Install from NPM for node
@ -12,4 +14,6 @@ npm install lune@{VERSION}
deno install https://raw.githubusercontent.com/CompeyDev/lune-packaging/v{VERSION}/package/js/bin/lune.ts
```
> **Note**: Only lune versions starting from lune v0.8.5 are supported for NPM. Pinned deno versions are currently not supported, so you would need to omit the version portion from the script link.
> **Note**: Only lune versions starting from lune v0.8.5 are supported for NPM.
> Pinned deno versions are currently not supported, so you would need to replace
> the version portion from the script link with main.

View file

@ -1,3 +1,5 @@
import consts, { BASE_PATH } from "../consts.ts";
import * as path from "jsr:@std/path";
import { checkAndInstallLune, EXE_EXTENSION } from "../install.ts";
// Install lune, if unavailable
@ -8,7 +10,7 @@ await checkAndInstallLune();
dnt does not support Deno.Command yet, but once they do, this would
like so:
new Deno.Command(Deno.cwd() + "/lune" + EXE_EXTENSION, {
new Deno.Command(path.join(BASE_PATH, "lune" + EXE_EXTENSION), {
args: Deno.args,
stdout: "inherit",
stderr: "inherit",
@ -17,10 +19,13 @@ await checkAndInstallLune();
*/
// deno-lint-ignore no-deprecated-deno-api
const luneStatus = await Deno.run({
cmd: [Deno.cwd() + "/lune" + EXE_EXTENSION, ...Deno.args],
cmd: [
path.join(BASE_PATH, consts.version, "lune" + EXE_EXTENSION),
...Deno.args,
],
stdout: "inherit",
stderr: "inherit",
stdin: "inherit"
}).status()
stdin: "inherit",
}).status();
Deno.exit(luneStatus.signal)
Deno.exit(luneStatus.signal);

View file

@ -14,7 +14,7 @@ await build({
outDir: "./npm",
shims: {
deno: true,
// undici: true,
undici: true,
},
package: {
name: consts.name,
@ -34,5 +34,5 @@ await build({
Deno.copyFileSync("README.md", "npm/README.md");
Deno.copyFileSync("consts.toml", "npm/consts.toml");
},
typeCheck: false // FIXME: This is a problem on dnt's end while importing things
typeCheck: false, // FIXME: This is a problem on dnt's end while importing things
});

View file

@ -1,6 +1,11 @@
import { parse as parseToml } from "jsr:@std/toml";
import * as path from "jsr:@std/path";
export default parseToml(Deno.readTextFileSync("consts.toml")) as {
export const BASE_PATH = path.dirname(path.fromFileUrl(import.meta.url));
export default parseToml(
Deno.readTextFileSync(path.join(BASE_PATH, "consts.toml")),
) as {
name: string;
api_url: string;
version: string;

View file

@ -1,6 +1,6 @@
{
"tasks": {
"lune": "deno run --allow-all lune.ts",
"lune": "deno run --allow-all bin/lune.ts",
"build": "deno run --allow-all build.ts"
}
}

View file

@ -13,6 +13,7 @@
"jsr:@std/fs@0.218.2": "jsr:@std/fs@0.218.2",
"jsr:@std/fs@^0.218.2": "jsr:@std/fs@0.218.2",
"jsr:@std/io@^0.218.2": "jsr:@std/io@0.218.2",
"jsr:@std/path": "jsr:@std/path@0.218.2",
"jsr:@std/path@0.218.2": "jsr:@std/path@0.218.2",
"jsr:@std/path@^0.218.2": "jsr:@std/path@0.218.2",
"jsr:@std/toml": "jsr:@std/toml@0.224.0",

View file

@ -1,16 +1,16 @@
// import { decompress as unzip } from "jsr:@fakoua/zip-ts@^1.3.1";
import * as path from "jsr:@std/path";
import { unzip } from "https://deno.land/x/nzip@v1.2.1/mod.ts";
import { fetchLuneReleases } from "./github.ts";
import consts from "./consts.ts";
import consts, { BASE_PATH } from "./consts.ts";
export const LUNE_VERSION = consts.version;
export const EXE_EXTENSION = Deno.build.os == "windows" ? ".exe" : "";
async function installLune() {
let ghAuthToken;
let ghAuthToken: string | undefined;
try {
/*
/*
Ideally, this would look like this:
new TextDecoder().decode(
@ -19,14 +19,16 @@ async function installLune() {
stdout: "piped",
}).output()).stdout,
);
However, dnt is yet to support Deno.command
*/
// deno-lint-ignore no-deprecated-deno-api
ghAuthToken = new TextDecoder().decode(await Deno.run({
cmd: ["gh", "auth", "token"],
stdout: "piped"
}).output())
ghAuthToken = new TextDecoder().decode(
// deno-lint-ignore no-deprecated-deno-api
await Deno.run({
cmd: ["gh", "auth", "token"],
stdout: "piped",
}).output(),
);
} catch (_) {
// Don't use an auth token, be subjected to GitHub ratelimit
}
@ -52,7 +54,7 @@ async function installLune() {
}
const zipFile = await Deno.makeTempFile({ suffix: ".zip" });
const finalDest = Deno.cwd();
const finalDestDir = path.join(BASE_PATH, consts.version);
const binaryBlob = resp.body!;
await binaryBlob.pipeTo(
@ -62,15 +64,15 @@ async function installLune() {
)).writable,
);
const binaryPaths = await unzip(zipFile, finalDest, {
const binaryPaths = await unzip(zipFile, finalDestDir, {
useWebWorkers: true,
});
if (Deno.build.os !== "windows") await Deno.chmod(binaryPaths[0], 0o777)
if (Deno.build.os !== "windows") await Deno.chmod(binaryPaths[0], 0o777);
}
export async function checkAndInstallLune() {
const luneExePath = Deno.cwd() + "/lune" + EXE_EXTENSION;
const luneExePath = path.join(BASE_PATH, consts.version, "lune" + EXE_EXTENSION);
const luneExists = await Deno.lstat(luneExePath).then(
(stat) => {