smartbundle 0.7.1 → 0.7.3-alpha.0

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) {
@@ -19,20 +23,20 @@ async function binsTask({
19
23
  if (el.fileName.endsWith(".cjs")) {
20
24
  continue;
21
25
  }
22
- const binsPath = reversedEntrypoints.get(el.facadeModuleId);
23
- if (!binsPath) {
26
+ const binsNames = reversedEntrypoints.get(el.facadeModuleId);
27
+ if (!binsNames) {
24
28
  continue;
25
29
  }
26
- 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);
30
+ for (const binName of binsNames) {
31
+ const totalPath = path.relative(outBinsDir, path.join(outDir, el.fileName));
32
+ const execPath = path.join(outBinsDir, `${binName}.js`);
29
33
  await fs.writeFile(
30
34
  execPath,
31
35
  `#!/usr/bin/env node
32
36
  import("${totalPath}");
33
37
  `
34
38
  );
35
- res.set(path.relative(outDir, execPath), path$1);
39
+ res.set(path.relative(outDir, execPath), binName);
36
40
  }
37
41
  }
38
42
  return res;
@@ -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) {
@@ -17,20 +21,20 @@ async function binsTask({
17
21
  if (el.fileName.endsWith(".cjs")) {
18
22
  continue;
19
23
  }
20
- const binsPath = reversedEntrypoints.get(el.facadeModuleId);
21
- if (!binsPath) {
24
+ const binsNames = reversedEntrypoints.get(el.facadeModuleId);
25
+ if (!binsNames) {
22
26
  continue;
23
27
  }
24
- for (const path of binsPath) {
25
- const totalPath = relative(outInternalsDir, join(outDir, el.fileName));
26
- const execPath = join(outInternalsDir, path);
28
+ for (const binName of binsNames) {
29
+ const totalPath = relative(outBinsDir, join(outDir, el.fileName));
30
+ const execPath = join(outBinsDir, `${binName}.js`);
27
31
  await writeFile(
28
32
  execPath,
29
33
  `#!/usr/bin/env node
30
34
  import("${totalPath}");
31
35
  `
32
36
  );
33
- res.set(relative(outDir, execPath), path);
37
+ res.set(relative(outDir, execPath), binName);
34
38
  }
35
39
  }
36
40
  return res;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "smartbundle",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.3-alpha.0",
5
5
  "bin": {
6
- "smartbundle": "__smartbundle__internals__/smartbundle"
6
+ "smartbundle": "__bin__/smartbundle.js"
7
7
  },
8
8
  "types": "./src/index.d.ts",
9
9
  "module": "./src/index.js",
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 {};