Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
1.74k stars 95 forks source link

[Typescript] Bun build fails to resolve types #377

Closed happyori closed 2 months ago

happyori commented 2 months ago

Hi, I am trying to use the ags with typescript using the method wiki shows but I am getting the following error.

$ ags
1 | import hyprland from "types/service/hyprland";
                                        ^
error: Could not resolve: "types/service/hyprland". Maybe you need to "bun install"?
    at /home/happy/.config/ags/ts/hyprland/workspaces.ts:1:22

here is my config.js

const entry = App.configDir + "/ts/main.ts";
const outDir = "/tmp/ags/js";

try {
  // @ts-ignore
  await Utils.execAsync([
    "bun",
    "build",
    entry,
    "--outdir",
    outDir,
    "--external",
    "resourse://*",
    "--external",
    "gi://*",
    "--external",
    "file://*",
  ]);
  // @ts-ignore
  await import(`file://${outDir}/main.js`);
} catch (error) {
  printerr(error);
  App.quit();
}

and my tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "lib": ["ES2022"],
    "allowJs": true,
    "checkJs": true,
    "strict": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "typeRoots": ["./types"],
    "skipLibCheck": true
  }
}

here is the workspaces file that fails, but any import into the types/* folder fail similarly

import hyprland from "types/service/hyprland";

export const Workspaces = () => {
  const self = Widget.Box({});
  const workspaces = hyprland.workspaces;

  return self;
};

I also ran the ags --init and have correctly linked types folder. LSP also is working right. Anytime I try to import anything from ags it fails.

happyori commented 2 months ago

Nvm I didn't realize I had to use Service.import instead of importing normally

Aylur commented 2 months ago

You can still do static import https://aylur.github.io/ags-docs/config/services/#list-of-builtin-services Your issue was that you were importing the type and not the actual object