smartbundle 0.7.0 → 0.7.2

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.
@@ -14,7 +14,7 @@ function resolveDirs(args) {
14
14
  args.packagePath ?? "./package.json"
15
15
  );
16
16
  const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
17
- const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
18
- return { sourceDir, packagePath, outDir, outInternalsDir };
17
+ const outBinsDir = myResolve(outDir, "__bin__");
18
+ return { sourceDir, packagePath, outDir, outBinsDir };
19
19
  }
20
20
  exports.resolveDirs = resolveDirs;
@@ -12,8 +12,8 @@ function resolveDirs(args) {
12
12
  args.packagePath ?? "./package.json"
13
13
  );
14
14
  const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
15
- const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
16
- return { sourceDir, packagePath, outDir, outInternalsDir };
15
+ const outBinsDir = myResolve(outDir, "__bin__");
16
+ return { sourceDir, packagePath, outDir, outBinsDir };
17
17
  }
18
18
  export {
19
19
  resolveDirs
@@ -7,9 +7,13 @@ const utils = require("./utils.cjs");
7
7
  async function binsTask({
8
8
  buildOutput,
9
9
  bins,
10
- outInternalsDir,
10
+ outBinsDir,
11
11
  outDir
12
12
  }) {
13
+ if (bins.size === 0) {
14
+ return /* @__PURE__ */ new Map();
15
+ }
16
+ await fs.mkdir(outBinsDir, { recursive: true });
13
17
  const reversedEntrypoints = utils.reverseMap(bins);
14
18
  const res = /* @__PURE__ */ new Map();
15
19
  for (const el of buildOutput) {
@@ -24,8 +28,8 @@ async function binsTask({
24
28
  continue;
25
29
  }
26
30
  for (const path$1 of binsPath) {
27
- const totalPath = path.relative(outInternalsDir, path.join(outDir, el.fileName));
28
- const execPath = path.join(outInternalsDir, path$1);
31
+ const totalPath = path.relative(outBinsDir, path.join(outDir, el.fileName));
32
+ const execPath = path.join(outBinsDir, path$1);
29
33
  await fs.writeFile(
30
34
  execPath,
31
35
  `#!/usr/bin/env node
@@ -1,13 +1,17 @@
1
- import { writeFile } from "node:fs/promises";
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
2
  import { relative, join } from "node:path";
3
3
  import "vite";
4
4
  import { reverseMap } from "./utils.js";
5
5
  async function binsTask({
6
6
  buildOutput,
7
7
  bins,
8
- outInternalsDir,
8
+ outBinsDir,
9
9
  outDir
10
10
  }) {
11
+ if (bins.size === 0) {
12
+ return /* @__PURE__ */ new Map();
13
+ }
14
+ await mkdir(outBinsDir, { recursive: true });
11
15
  const reversedEntrypoints = reverseMap(bins);
12
16
  const res = /* @__PURE__ */ new Map();
13
17
  for (const el of buildOutput) {
@@ -22,8 +26,8 @@ async function binsTask({
22
26
  continue;
23
27
  }
24
28
  for (const path of binsPath) {
25
- const totalPath = relative(outInternalsDir, join(outDir, el.fileName));
26
- const execPath = join(outInternalsDir, path);
29
+ const totalPath = relative(outBinsDir, join(outDir, el.fileName));
30
+ const execPath = join(outBinsDir, path);
27
31
  await writeFile(
28
32
  execPath,
29
33
  `#!/usr/bin/env node
@@ -56,7 +56,8 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
56
56
  bugs: parsed.bugs,
57
57
  sideEffects: parsed.sideEffects,
58
58
  unpkg: parsed.unpkg,
59
- homepage: parsed.homepage
59
+ homepage: parsed.homepage,
60
+ devDependencies: parsed.devDependencies
60
61
  };
61
62
  await fs.writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));
62
63
  }
@@ -54,7 +54,8 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
54
54
  bugs: parsed.bugs,
55
55
  sideEffects: parsed.sideEffects,
56
56
  unpkg: parsed.unpkg,
57
- homepage: parsed.homepage
57
+ homepage: parsed.homepage,
58
+ devDependencies: parsed.devDependencies
58
59
  };
59
60
  await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));
60
61
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "smartbundle",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "bin": {
6
- "smartbundle": "__smartbundle__internals__/smartbundle"
6
+ "smartbundle": "__bin__/smartbundle"
7
7
  },
8
8
  "types": "./src/index.d.ts",
9
9
  "module": "./src/index.js",
@@ -52,5 +52,14 @@
52
52
  "bugs": {
53
53
  "url": "https://github.com/xavescor/smartbundle/issues"
54
54
  },
55
- "homepage": "https://github.com/xavescor/smartbundle"
55
+ "homepage": "https://github.com/xavescor/smartbundle",
56
+ "devDependencies": {
57
+ "@types/node": "^20.14.11",
58
+ "@types/yargs": "^17.0.33",
59
+ "prettier": "^3.3.3",
60
+ "typescript": "^5.6.3",
61
+ "vitest": "^2.1.3",
62
+ "vitest-directory-snapshot": "^0.2.2",
63
+ "zx": "^8.1.9"
64
+ }
56
65
  }
package/src/index.cjs CHANGED
@@ -18,10 +18,9 @@ function setExports(exportsMap, exportName, mapFn) {
18
18
  }
19
19
  async function defineViteConfig(args = {}) {
20
20
  const dirs = resolveDirs.resolveDirs(args);
21
- const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
21
+ const { sourceDir, outDir, packagePath } = dirs;
22
22
  await fs.rm(outDir, { recursive: true, force: true });
23
23
  await fs.mkdir(outDir, { recursive: true });
24
- await fs.mkdir(outInternalsDir, { recursive: true });
25
24
  const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
26
25
  if (Array.isArray(packageJson$1)) {
27
26
  console.error(packageJson$1);
@@ -32,7 +31,7 @@ async function defineViteConfig(args = {}) {
32
31
  }
33
32
  async function run(args) {
34
33
  const dirs = resolveDirs.resolveDirs(args);
35
- const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
34
+ const { sourceDir, outDir, packagePath, outBinsDir } = dirs;
36
35
  await fs.rm(outDir, { recursive: true, force: true });
37
36
  await fs.mkdir(outDir, { recursive: true });
38
37
  const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
@@ -48,7 +47,6 @@ async function run(args) {
48
47
  if (outputs.error) {
49
48
  return { error: true, errors: outputs.errors };
50
49
  }
51
- await fs.mkdir(outInternalsDir, { recursive: true });
52
50
  const viteOutput = outputs.output;
53
51
  const exportsMap = /* @__PURE__ */ new Map();
54
52
  const binsMap = /* @__PURE__ */ new Map();
@@ -80,7 +78,7 @@ async function run(args) {
80
78
  });
81
79
  }
82
80
  }),
83
- binsTask.binsTask({ outInternalsDir, bins, buildOutput: viteOutput, outDir }).then(
81
+ binsTask.binsTask({ outBinsDir, bins, buildOutput: viteOutput, outDir }).then(
84
82
  (res) => {
85
83
  for (const [value, key] of res) {
86
84
  binsMap.set(key, value);
package/src/index.js CHANGED
@@ -16,10 +16,9 @@ function setExports(exportsMap, exportName, mapFn) {
16
16
  }
17
17
  async function defineViteConfig(args = {}) {
18
18
  const dirs = resolveDirs(args);
19
- const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
19
+ const { sourceDir, outDir, packagePath } = dirs;
20
20
  await rm(outDir, { recursive: true, force: true });
21
21
  await mkdir(outDir, { recursive: true });
22
- await mkdir(outInternalsDir, { recursive: true });
23
22
  const packageJson = await parsePackageJson({ sourceDir, packagePath });
24
23
  if (Array.isArray(packageJson)) {
25
24
  console.error(packageJson);
@@ -30,7 +29,7 @@ async function defineViteConfig(args = {}) {
30
29
  }
31
30
  async function run(args) {
32
31
  const dirs = resolveDirs(args);
33
- const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
32
+ const { sourceDir, outDir, packagePath, outBinsDir } = dirs;
34
33
  await rm(outDir, { recursive: true, force: true });
35
34
  await mkdir(outDir, { recursive: true });
36
35
  const packageJson = await parsePackageJson({ sourceDir, packagePath });
@@ -46,7 +45,6 @@ async function run(args) {
46
45
  if (outputs.error) {
47
46
  return { error: true, errors: outputs.errors };
48
47
  }
49
- await mkdir(outInternalsDir, { recursive: true });
50
48
  const viteOutput = outputs.output;
51
49
  const exportsMap = /* @__PURE__ */ new Map();
52
50
  const binsMap = /* @__PURE__ */ new Map();
@@ -78,7 +76,7 @@ async function run(args) {
78
76
  });
79
77
  }
80
78
  }),
81
- binsTask({ outInternalsDir, bins, buildOutput: viteOutput, outDir }).then(
79
+ binsTask({ outBinsDir, bins, buildOutput: viteOutput, outDir }).then(
82
80
  (res) => {
83
81
  for (const [value, key] of res) {
84
82
  binsMap.set(key, value);
@@ -7,6 +7,6 @@ export declare function resolveDirs(args: Args): {
7
7
  sourceDir: string;
8
8
  packagePath: string;
9
9
  outDir: string;
10
- outInternalsDir: string;
10
+ outBinsDir: string;
11
11
  };
12
12
  export type Dirs = ReturnType<typeof resolveDirs>;
@@ -2,8 +2,8 @@ import { type Rollup } from "vite";
2
2
  type BinsTaskOption = {
3
3
  buildOutput: Rollup.OutputChunk[];
4
4
  bins: Map<string, string>;
5
- outInternalsDir: string;
5
+ outBinsDir: string;
6
6
  outDir: string;
7
7
  };
8
- export declare function binsTask({ buildOutput, bins, outInternalsDir, outDir, }: BinsTaskOption): Promise<Map<string, string>>;
8
+ export declare function binsTask({ buildOutput, bins, outBinsDir, outDir, }: BinsTaskOption): Promise<Map<string, string>>;
9
9
  export {};