@reteps/dockerfmt 0.2.0 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@reteps/dockerfmt`
2
2
 
3
- Bindings around the Golang `dockerfmt` tooling.
3
+ Bindings around the Golang `dockerfmt` tooling. It uses [tinygo](https://github.com/tinygo-org/tinygo) to compile the Go code to WebAssembly, which is then used in the JS bindings.
4
4
 
5
5
 
6
6
  ```js
package/dist/format.d.ts CHANGED
@@ -4,5 +4,5 @@ interface FormatOptions {
4
4
  trailingNewline: boolean;
5
5
  }
6
6
  declare const formatDockerfile: (fileName: string, options: FormatOptions) => Promise<string>;
7
- declare const formatDockerfileContents: (fileContents: string, options: FormatOptions) => Promise<string>;
7
+ declare const formatDockerfileContents: (fileContents: string, options: FormatOptions, getWasm?: () => Promise<Buffer>) => Promise<string>;
8
8
  export { formatDockerfile, formatDockerfileContents };
package/dist/format.js CHANGED
@@ -3,16 +3,18 @@ import './wasm_exec.cjs';
3
3
  import path from 'node:path';
4
4
  import { fileURLToPath } from 'url';
5
5
  const formatDockerfile = async (fileName, options) => {
6
+ // This would only work in Node.js, so we don't add a wasmDownload function
6
7
  const fileBuffer = await fs.readFile(fileName);
7
8
  const fileContents = fileBuffer.toString();
8
9
  return formatDockerfileContents(fileContents, options);
9
10
  };
10
- const formatDockerfileContents = async (fileContents, options) => {
11
+ const getWasmModule = () => fs.readFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'format.wasm'));
12
+ const formatDockerfileContents = async (fileContents, options, getWasm = getWasmModule) => {
11
13
  const go = new Go(); // Defined in wasm_exec.js
12
14
  const encoder = new TextEncoder();
13
15
  const decoder = new TextDecoder();
14
16
  // get current working directory
15
- const wasmBuffer = await fs.readFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'format.wasm'));
17
+ const wasmBuffer = await getWasm();
16
18
  const wasm = await WebAssembly.instantiate(wasmBuffer, go.importObject);
17
19
  /**
18
20
  * Do not await this promise, because it only resolves once the go main()
package/dist/format.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reteps/dockerfmt",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",