Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(npm): update npm distribution to have
getPath
export instead
- Loading branch information
Showing
8 changed files
with
34 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/target | ||
**/*.rs.bk | ||
sourcemap | ||
deployment/npm/buffer.generated.js | ||
deployment/npm/plugin.wasm | ||
deployment/npm/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/** Gets a buffer representing the WASM module. */ | ||
export function getBuffer(): ArrayBuffer; | ||
/** Gets an absolute path to the WASM module. */ | ||
export function getPath(): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,11 @@ | ||
/** | ||
* Gets a buffer representing the WASM module. | ||
* @returns {ArrayBuffer} | ||
* Gets the path to the Wasm module. | ||
* @returns {string} | ||
*/ | ||
function getBuffer() { | ||
const encodedBuffer = require("./buffer.generated").encodedBuffer; | ||
return decodeEncodedBuffer(encodedBuffer); | ||
} | ||
|
||
/** | ||
* @param {string} encodedBuffer | ||
* @returns {ArrayBuffer} | ||
*/ | ||
function decodeEncodedBuffer(encodedBuffer) { | ||
// https://stackoverflow.com/a/51473757/188246 | ||
const binaryString = toBinaryString(); | ||
const bytes = new Uint8Array(binaryString.length); | ||
for (let i = 0; i < binaryString.length; i++) { | ||
bytes[i] = binaryString.charCodeAt(i); | ||
} | ||
return bytes.buffer; | ||
|
||
function toBinaryString() { | ||
if (typeof atob === "function") { | ||
return atob(encodedBuffer); | ||
} else { | ||
return Buffer.from(encodedBuffer, "base64").toString("binary"); | ||
} | ||
} | ||
function getPath() { | ||
return require("path").join(__dirname, "plugin.wasm"); | ||
} | ||
|
||
module.exports = { | ||
getBuffer, | ||
getPath, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
// @ts-check | ||
const assert = require("assert"); | ||
const createFromBuffer = require("@dprint/formatter").createFromBuffer; | ||
const getBuffer = require("./index").getBuffer; | ||
const getPath = require("./index").getPath; | ||
|
||
const formatter = createFromBuffer(getBuffer()); | ||
const buffer = require("fs").readFileSync(getPath()); | ||
const formatter = createFromBuffer(buffer); | ||
const result = formatter.formatText("file.ts", "const t = 5"); | ||
|
||
assert.strictEqual(result, "const t = 5;\n"); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters