jsshaker 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/README.md CHANGED
@@ -7,7 +7,7 @@ https://github.com/kermanx/jsshaker
7
7
  ## WASM & N-API
8
8
 
9
9
  ```ts
10
- import { shakeSingleModule, shakeMultiModule } from "jsshaker";
10
+ import { shakeSingleModule, shakeMultiModule, shakeFsModule } from "jsshaker";
11
11
  ```
12
12
 
13
13
  ## CLI
@@ -15,35 +15,12 @@ import { shakeSingleModule, shakeMultiModule } from "jsshaker";
15
15
  ```sh
16
16
  pnpx jsshaker ./entry.js
17
17
 
18
- # --preset(-p, optional): "safest" | "recommended" | "smallest" | "disabled"
19
- # --minify(-m, optional): boolean
20
- # --outdir(-o, optional): string
18
+ # --preset(-p, optional): "safest" | "recommended" | "smallest" | "disabled" - Preset configuration (default: "recommended")
19
+ # --minify(-m, optional): boolean - Minify output (default: false)
20
+ # --outdir(-o, optional): string - Output directory (default: ./out)
21
+ # --single(-s, optional): boolean - Shake as a single module (default: ./out.js)
21
22
  ```
22
23
 
23
- ## Vite Plugin
24
+ ## Rollup/Vite/Rolldown Plugin
24
25
 
25
- ```ts
26
- import { defineConfig } from "vite";
27
- import { shakeMultiModule } from "jsshaker";
28
- import * as fs from "fs";
29
-
30
- export default defineConfig({
31
- plugins: [
32
- {
33
- name: "jsshaker",
34
- enforce: "post",
35
- buildEnd() {
36
- const { output, diagnostics } = shakeMultiModule("./dist/index.js", {
37
- minify: true,
38
- })
39
- for (const diag of diagnostics) {
40
- console.error(diag);
41
- }
42
- for (const file in output) {
43
- fs.writeFileSync(file, output[file]);
44
- }
45
- },
46
- },
47
- ],
48
- });
49
- ```
26
+ https://www.npmjs.com/package/rollup-plugin-jsshaker
package/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { parseArgs } = require("node:util");
4
- const { shakeFsModule } = require("./index.js");
5
- const { writeFile, mkdir } = require("node:fs/promises");
4
+ const { shakeFsModule, shakeSingleModule } = require("./index.js");
5
+ const { writeFile, mkdir, readFile } = require("node:fs/promises");
6
6
  const { join, dirname } = require("node:path");
7
7
 
8
8
  (async () => {
@@ -20,6 +20,10 @@ const { join, dirname } = require("node:path");
20
20
  type: "string",
21
21
  short: "o",
22
22
  },
23
+ single: {
24
+ type: "boolean",
25
+ short: "s",
26
+ },
23
27
  },
24
28
  allowPositionals: true,
25
29
  strict: false,
@@ -29,26 +33,34 @@ const { join, dirname } = require("node:path");
29
33
  throw new Error("Must provide exactly one entry js file path.");
30
34
  }
31
35
 
32
- const result = shakeFsModule(
33
- positionals[0],
34
- {
35
- preset: values.preset,
36
- minify: values.minify,
36
+ const options = {
37
+ preset: values.preset,
38
+ minify: values.minify,
39
+ };
40
+
41
+ if (!values.single) {
42
+ const result = shakeFsModule(positionals[0], options);
43
+
44
+ for (const message of result.diagnostics) {
45
+ console.warn(message);
37
46
  }
38
- );
39
47
 
40
- for (const message of result.diagnostics) {
41
- console.warn(message);
42
- }
48
+ for (let [path, { code }] of Object.entries(result.output)) {
49
+ path = join(values.outdir || "./out", path);
50
+ const dir = dirname(path);
51
+ await mkdir(dir, { recursive: true });
52
+ console.log('Writing', path);
53
+ await writeFile(path, code);
54
+ }
55
+ } else {
56
+ const content = await readFile(positionals[0], "utf-8");
57
+ const result = shakeSingleModule(content, options);
43
58
 
44
- for (let [path, { code }] of Object.entries(result.output)) {
45
- if (values.outdir) {
46
- path = join(values.outdir, path);
59
+ for (const message of result.diagnostics) {
60
+ console.warn(message);
47
61
  }
48
- const dir = dirname(path);
49
- await mkdir(dir, { recursive: true });
50
- console.log('Writing', path);
51
- await writeFile(path, code);
62
+
63
+ await writeFile(values.outdir || "out.js", result.output.code);
52
64
  }
53
65
  })().catch((err) => {
54
66
  console.error(err);
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsshaker",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "browser": "browser.js",
@@ -49,11 +49,11 @@
49
49
  "ohash": "^2.0.11"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@jsshaker/binding-linux-x64-gnu": "0.2.3",
53
- "@jsshaker/binding-win32-x64-msvc": "0.2.3",
54
- "@jsshaker/binding-darwin-x64": "0.2.3",
55
- "@jsshaker/binding-darwin-arm64": "0.2.3",
56
- "@jsshaker/binding-wasm32-wasi": "0.2.3"
52
+ "@jsshaker/binding-linux-x64-gnu": "0.2.5",
53
+ "@jsshaker/binding-win32-x64-msvc": "0.2.5",
54
+ "@jsshaker/binding-darwin-x64": "0.2.5",
55
+ "@jsshaker/binding-darwin-arm64": "0.2.5",
56
+ "@jsshaker/binding-wasm32-wasi": "0.2.5"
57
57
  },
58
58
  "scripts": {
59
59
  "artifacts": "napi artifacts",