@reteps/dockerfmt 0.2.3 → 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 CHANGED
@@ -1,8 +1,7 @@
1
- import './wasm_exec.cjs';
2
- interface FormatOptions {
1
+ import './wasm_exec.js';
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 };
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,15 +1,5 @@
1
- import fs from 'node:fs/promises';
2
- import './wasm_exec.cjs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'url';
5
- const formatDockerfile = async (fileName, options) => {
6
- // This would only work in Node.js, so we don't add a wasmDownload function
7
- const fileBuffer = await fs.readFile(fileName);
8
- const fileContents = fileBuffer.toString();
9
- return formatDockerfileContents(fileContents, options);
10
- };
11
- const getWasmModule = () => fs.readFile(path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'format.wasm'));
12
- const formatDockerfileContents = async (fileContents, options, getWasm = getWasmModule) => {
1
+ import './wasm_exec.js';
2
+ export const formatDockerfileContents = async (fileContents, options, getWasm) => {
13
3
  const go = new Go(); // Defined in wasm_exec.js
14
4
  const encoder = new TextEncoder();
15
5
  const decoder = new TextDecoder();
@@ -35,4 +25,6 @@ const formatDockerfileContents = async (fileContents, options, getWasm = getWasm
35
25
  free(filePointer);
36
26
  return result;
37
27
  };
38
- 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
+ };
@@ -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,19 +1,30 @@
1
1
  {
2
2
  "name": "@reteps/dockerfmt",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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.cjs dist",
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": [
13
13
  "dist"
14
14
  ],
15
- "main": "dist/format.js",
16
- "types": "dist/format.d.ts",
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",