@reteps/dockerfmt 0.2.3 → 0.2.4
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/dist/format.d.ts +2 -2
- package/dist/format.js +16 -5
- package/dist/format.wasm +0 -0
- package/package.json +2 -2
- /package/dist/{wasm_exec.cjs → wasm_exec.js} +0 -0
package/dist/format.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import './wasm_exec.
|
|
1
|
+
import './wasm_exec.js';
|
|
2
2
|
interface FormatOptions {
|
|
3
3
|
indent: number;
|
|
4
4
|
trailingNewline: boolean;
|
|
5
5
|
}
|
|
6
6
|
declare const formatDockerfile: (fileName: string, options: FormatOptions) => Promise<string>;
|
|
7
7
|
declare const formatDockerfileContents: (fileContents: string, options: FormatOptions, getWasm?: () => Promise<Buffer>) => Promise<string>;
|
|
8
|
-
export { formatDockerfile, formatDockerfileContents };
|
|
8
|
+
export { formatDockerfile, formatDockerfileContents, FormatOptions };
|
package/dist/format.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
1
|
+
import './wasm_exec.js';
|
|
2
|
+
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
5
3
|
const formatDockerfile = async (fileName, options) => {
|
|
4
|
+
if (!isNode) {
|
|
5
|
+
throw new Error('formatDockerfile is only supported in Node.js');
|
|
6
|
+
}
|
|
7
|
+
const fs = require('node:fs/promises');
|
|
6
8
|
// This would only work in Node.js, so we don't add a wasmDownload function
|
|
7
9
|
const fileBuffer = await fs.readFile(fileName);
|
|
8
10
|
const fileContents = fileBuffer.toString();
|
|
9
11
|
return formatDockerfileContents(fileContents, options);
|
|
10
12
|
};
|
|
11
|
-
const getWasmModule = () =>
|
|
13
|
+
const getWasmModule = () => {
|
|
14
|
+
if (isNode) {
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const url = require('node:url');
|
|
17
|
+
const fs = require('node:fs/promises');
|
|
18
|
+
return fs.readFile(path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), 'format.wasm'));
|
|
19
|
+
}
|
|
20
|
+
// In the browser, we need to fetch the wasm module
|
|
21
|
+
throw new Error('WASM module not found. Please provide a function to fetch the WASM module.');
|
|
22
|
+
};
|
|
12
23
|
const formatDockerfileContents = async (fileContents, options, getWasm = getWasmModule) => {
|
|
13
24
|
const go = new Go(); // Defined in wasm_exec.js
|
|
14
25
|
const encoder = new TextEncoder();
|
package/dist/format.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reteps/dockerfmt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
7
|
"//": "Requires tinygo 0.38.0 or later",
|
|
8
8
|
"build-go": "tinygo build -o format.wasm -target wasm --no-debug",
|
|
9
|
-
"build-js": "tsc && cp format.wasm wasm_exec.
|
|
9
|
+
"build-js": "tsc && cp format.wasm wasm_exec.js dist",
|
|
10
10
|
"build": "npm run build-go && npm run build-js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
File without changes
|