@reteps/dockerfmt 0.2.4 → 0.2.5
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 +3 -4
- package/dist/format.js +4 -23
- package/dist/format.wasm +0 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +15 -0
- package/dist/wasm_exec.js +0 -22
- package/package.json +14 -3
package/dist/format.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import './wasm_exec.js';
|
|
2
|
-
interface FormatOptions {
|
|
2
|
+
export interface FormatOptions {
|
|
3
3
|
indent: number;
|
|
4
4
|
trailingNewline: boolean;
|
|
5
5
|
}
|
|
6
|
-
declare const
|
|
7
|
-
declare const
|
|
8
|
-
export { formatDockerfile, formatDockerfileContents, FormatOptions };
|
|
6
|
+
export declare const formatDockerfileContents: (fileContents: string, options: FormatOptions, getWasm: () => Promise<Buffer>) => Promise<string>;
|
|
7
|
+
export declare const formatDockerfile: () => never;
|
package/dist/format.js
CHANGED
|
@@ -1,26 +1,5 @@
|
|
|
1
1
|
import './wasm_exec.js';
|
|
2
|
-
const
|
|
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');
|
|
8
|
-
// This would only work in Node.js, so we don't add a wasmDownload function
|
|
9
|
-
const fileBuffer = await fs.readFile(fileName);
|
|
10
|
-
const fileContents = fileBuffer.toString();
|
|
11
|
-
return formatDockerfileContents(fileContents, options);
|
|
12
|
-
};
|
|
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
|
-
};
|
|
23
|
-
const formatDockerfileContents = async (fileContents, options, getWasm = getWasmModule) => {
|
|
2
|
+
export const formatDockerfileContents = async (fileContents, options, getWasm) => {
|
|
24
3
|
const go = new Go(); // Defined in wasm_exec.js
|
|
25
4
|
const encoder = new TextEncoder();
|
|
26
5
|
const decoder = new TextDecoder();
|
|
@@ -46,4 +25,6 @@ const formatDockerfileContents = async (fileContents, options, getWasm = getWasm
|
|
|
46
25
|
free(filePointer);
|
|
47
26
|
return result;
|
|
48
27
|
};
|
|
49
|
-
export
|
|
28
|
+
export const formatDockerfile = () => {
|
|
29
|
+
throw new Error('`formatDockerfile` is not implemented in the browser. Use `formatDockerfileContents` instead.');
|
|
30
|
+
};
|
package/dist/format.wasm
CHANGED
|
Binary file
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FormatOptions } from "./format.js";
|
|
2
|
+
export declare const formatDockerfileContents: (fileContents: string, options: FormatOptions) => Promise<string>;
|
|
3
|
+
export declare const formatDockerfile: (fileName: string, options: FormatOptions) => Promise<string>;
|
|
4
|
+
export { FormatOptions };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { formatDockerfileContents as formatDockerfileContents_ } from "./format.js";
|
|
5
|
+
const getWasm = () => {
|
|
6
|
+
return fs.readFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'format.wasm'));
|
|
7
|
+
};
|
|
8
|
+
export const formatDockerfileContents = async (fileContents, options) => {
|
|
9
|
+
return formatDockerfileContents_(fileContents, options, getWasm);
|
|
10
|
+
};
|
|
11
|
+
export const formatDockerfile = async (fileName, options) => {
|
|
12
|
+
const fileBuffer = await fs.readFile(fileName);
|
|
13
|
+
const fileContents = fileBuffer.toString();
|
|
14
|
+
return formatDockerfileContents(fileContents, options);
|
|
15
|
+
};
|
package/dist/wasm_exec.js
CHANGED
|
@@ -529,26 +529,4 @@
|
|
|
529
529
|
};
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
global.require &&
|
|
535
|
-
global.require.main === module &&
|
|
536
|
-
global.process &&
|
|
537
|
-
global.process.versions &&
|
|
538
|
-
!global.process.versions.electron
|
|
539
|
-
) {
|
|
540
|
-
if (process.argv.length != 3) {
|
|
541
|
-
console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
|
|
542
|
-
process.exit(1);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
const go = new Go();
|
|
546
|
-
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then(async (result) => {
|
|
547
|
-
let exitCode = await go.run(result.instance);
|
|
548
|
-
process.exit(exitCode);
|
|
549
|
-
}).catch((err) => {
|
|
550
|
-
console.error(err);
|
|
551
|
-
process.exit(1);
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
532
|
})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reteps/dockerfmt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -12,8 +12,19 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"browser": "dist/format.js",
|
|
16
|
+
"main": "dist/node.js",
|
|
17
|
+
"types": "dist/node.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/node.d.ts",
|
|
21
|
+
"browser": "./dist/format.js",
|
|
22
|
+
"default": "./dist/node.js"
|
|
23
|
+
},
|
|
24
|
+
"./format.wasm": "./dist/format.wasm",
|
|
25
|
+
"./wasm_exec": "./dist/wasm_exec.js",
|
|
26
|
+
"./wasm_exec.js": "./dist/wasm_exec.js"
|
|
27
|
+
},
|
|
17
28
|
"author": "Peter Stenger <pete@stenger.io>",
|
|
18
29
|
"repository": "git+https://github.com/reteps/dockerfmt/tree/main/js",
|
|
19
30
|
"license": "MIT",
|