Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
feat: make Deno declaration file read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Mar 6, 2020
1 parent 5794907 commit fba8d89
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ connection.onInitialized(async () => {
const currentDenoTypesContent = await deno.getTypes();
const denoDtsFile = getDenoDts();
const isExistDtsFile = await pathExists(denoDtsFile);
const fileOptions = { encoding: "utf8" };

// if dst file not exist. then create a new one
if (!isExistDtsFile) {
await fs.writeFile(denoDtsFile, currentDenoTypesContent, fileOptions);
await fs.writeFile(denoDtsFile, currentDenoTypesContent, { mode: 0o444 });
} else {
const typesContent = await fs.readFile(denoDtsFile, fileOptions);
// set it to writable
await fs.chmod(denoDtsFile, 0o666);

const typesContent = await fs.readFile(denoDtsFile, { encoding: "utf8" });

if (typesContent.toString() !== currentDenoTypesContent.toString()) {
await fs.writeFile(denoDtsFile, currentDenoTypesContent, fileOptions);
await fs.writeFile(denoDtsFile, currentDenoTypesContent, {
mode: 0o444
});

// set to readonly
await fs.chmod(denoDtsFile, 0o444);
}
}
} catch (err) {
Expand Down

0 comments on commit fba8d89

Please sign in to comment.