@reteps/dockerfmt 0.2.4 → 0.2.6

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 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 formatDockerfile: (fileName: string, options: FormatOptions) => Promise<string>;
7
- declare const formatDockerfileContents: (fileContents: string, options: FormatOptions, getWasm?: () => Promise<Buffer>) => Promise<string>;
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 isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
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();
@@ -31,7 +10,7 @@ const formatDockerfileContents = async (fileContents, options, getWasm = getWasm
31
10
  * Do not await this promise, because it only resolves once the go main()
32
11
  * function has exited. But we need the main function to stay alive to be
33
12
  * able to call the `parse` and `print` function.
34
- */
13
+ */
35
14
  go.run(wasm.instance);
36
15
  const { memory, malloc, free, formatBytes } = wasm.instance.exports;
37
16
  const fileBufferBytes = encoder.encode(fileContents);
@@ -46,4 +25,6 @@ const formatDockerfileContents = async (fileContents, options, getWasm = getWasm
46
25
  free(filePointer);
47
26
  return result;
48
27
  };
49
- export { formatDockerfile, formatDockerfileContents };
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,27 +1,39 @@
1
1
  {
2
2
  "name": "@reteps/dockerfmt",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1",
7
- "//": "Requires tinygo 0.38.0 or later",
8
- "build-go": "tinygo build -o format.wasm -target wasm --no-debug",
9
- "build-js": "tsc && cp format.wasm wasm_exec.js dist",
10
- "build": "npm run build-go && npm run build-js"
5
+ "description": "",
6
+ "repository": "git+https://github.com/reteps/dockerfmt/tree/main/js",
7
+ "author": "Peter Stenger <pete@stenger.io>",
8
+ "license": "MIT",
9
+ "main": "dist/node.js",
10
+ "types": "dist/node.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/node.d.ts",
14
+ "browser": "./dist/format.js",
15
+ "default": "./dist/node.js"
16
+ },
17
+ "./format.wasm": "./dist/format.wasm",
18
+ "./package.json": "./package.json",
19
+ "./wasm_exec": "./dist/wasm_exec.js",
20
+ "./wasm_exec.js": "./dist/wasm_exec.js"
11
21
  },
22
+ "browser": "dist/format.js",
12
23
  "files": [
13
24
  "dist"
14
25
  ],
15
- "main": "dist/format.js",
16
- "types": "dist/format.d.ts",
17
- "author": "Peter Stenger <pete@stenger.io>",
18
- "repository": "git+https://github.com/reteps/dockerfmt/tree/main/js",
19
- "license": "MIT",
20
- "description": "",
21
- "devDependencies": {
22
- "@types/node": "^22.14.0"
26
+ "scripts": {
27
+ "//": "Requires tinygo 0.38.0 or later",
28
+ "build": "npm run build-go && npm run build-js",
29
+ "build-go": "tinygo build -o format.wasm -target wasm --no-debug -scheduler=none",
30
+ "build-js": "tsc && cp format.wasm wasm_exec.js dist",
31
+ "format": "prettier --write \"**/*.{js,ts,json}\""
23
32
  },
24
- "dependencies": {
33
+ "devDependencies": {
34
+ "@types/node": "^22.14.0",
35
+ "prettier": "^3.5.3",
36
+ "prettier-plugin-pkg": "^0.19.0",
25
37
  "typescript": "^5.8.3"
26
38
  }
27
39
  }