Skip to content

Commit

Permalink
fix: denon.config.ts file:// is now correctly resolved
Browse files Browse the repository at this point in the history
fix: denon.config.ts file:// is now correctly resolved
  • Loading branch information
Qu4k committed Jun 11, 2020
2 parents ab31495 + bf64a29 commit e29d18e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Denon provides most of the features you would expect of a file watcher and more.
To install denon simply enter the following into a terminal:

```bash
$ deno install --allow-read --allow-run --allow-write -f --unstable https://deno.land/x/denon/denon.ts
$ deno install --allow-read --allow-run --allow-write --allow-net -f --unstable https://deno.land/x/denon/denon.ts
```

> 鈿狅笍 Make sure you are using `deno` version `^1.0.1` to install this executable. You can upgrade running `deno upgrade`.
Expand Down
11 changes: 9 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ import { Watcher } from "./watcher.ts";
* - *read*, used to correctly load a configuration file and
* to monitor for filesystem changes in the directory `denon`
* is executed to reload scripts.
* - *write*, write configuration templates.
* - *run*, used to run scripts as child processes.
* - *write*, download configuration templates and import
* `denon.config.ts` file.
*/
const PERMISSIONS: Deno.PermissionDescriptor[] = [
export const PERMISSIONS: Deno.PermissionDescriptor[] = [
{ name: "read" },
{ name: "write" },
{ name: "run" },
{ name: "net" },
];

/**
* These permissions are required on specific situations,
* `denon` should not be installed with this permissions
* but you should be granting them when they are required.
*/
const PERMISSION_OPTIONAL: { [key: string]: Deno.PermissionDescriptor[] } = {
export const PERMISSION_OPTIONAL: {
[key: string]: Deno.PermissionDescriptor[];
} = {
initializeConfig: [{ name: "write" }, { name: "net" }],
upgradeExe: [{ name: "net" }],
};
Expand Down
16 changes: 2 additions & 14 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,17 @@ async function readYaml(file: string): Promise<unknown> {
});
}

/**
* from: deno-nessie
*/
export const parsePath = (...path: string[]): string => {
if (
path.length === 1 &&
(path[0]?.startsWith("http://") || path[0]?.startsWith("https://"))
) {
return path[0];
}
return "file://" + resolve(...path);
};

/**
* Safe import a TypeScript file
*/
async function importConfig(
file: string,
): Promise<Partial<DenonConfig> | undefined> {
try {
const configRaw = await import(parsePath(file));
const configRaw = await import(`file://${resolve(file)}`);
return configRaw.default as Partial<DenonConfig>;
} catch (error) {
log.error(error.message ?? "Error opening ts config config");
return;
}
}
Expand Down

0 comments on commit e29d18e

Please sign in to comment.