smartbundle 0.6.0 → 0.7.0-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.
Files changed (52) hide show
  1. package/README.md +7 -1
  2. package/__do_not_import_directly__/createViteConfig.cjs +14 -7
  3. package/__do_not_import_directly__/createViteConfig.js +14 -7
  4. package/__do_not_import_directly__/error.cjs +9 -0
  5. package/__do_not_import_directly__/error.js +9 -0
  6. package/__do_not_import_directly__/errors.cjs +1 -1
  7. package/__do_not_import_directly__/errors.js +1 -1
  8. package/__do_not_import_directly__/packageJson.cjs +32 -1
  9. package/__do_not_import_directly__/packageJson.js +32 -1
  10. package/__do_not_import_directly__/resolveDirs.cjs +2 -1
  11. package/__do_not_import_directly__/resolveDirs.js +2 -1
  12. package/__do_not_import_directly__/smartbundle.cjs +4 -0
  13. package/__do_not_import_directly__/smartbundle.js +3 -0
  14. package/__do_not_import_directly__/tasks/binsTask.cjs +40 -0
  15. package/__do_not_import_directly__/tasks/binsTask.js +40 -0
  16. package/{src/bin.cjs → __do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs} +39 -2
  17. package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js +40 -0
  18. package/__do_not_import_directly__/{buildTypes.cjs → tasks/buildTypesTask/callTypescript.cjs} +3 -26
  19. package/__do_not_import_directly__/{buildTypes.js → tasks/buildTypesTask/callTypescript.js} +3 -4
  20. package/__do_not_import_directly__/{copyStaticFiles.cjs → tasks/copyStaticFilesTask.cjs} +8 -1
  21. package/__do_not_import_directly__/{copyStaticFiles.js → tasks/copyStaticFilesTask.js} +8 -1
  22. package/__do_not_import_directly__/tasks/jsFilesTask.cjs +25 -0
  23. package/__do_not_import_directly__/tasks/jsFilesTask.js +25 -0
  24. package/__do_not_import_directly__/tasks/utils.cjs +12 -0
  25. package/__do_not_import_directly__/tasks/utils.js +12 -0
  26. package/__do_not_import_directly__/writePackageJson.cjs +5 -6
  27. package/__do_not_import_directly__/writePackageJson.js +5 -6
  28. package/__smartbundle__internals__/smartbundle +2 -0
  29. package/package.json +13 -11
  30. package/src/buildVite.d.ts +1 -1
  31. package/src/createViteConfig.d.ts +1 -0
  32. package/src/error.d.ts +4 -0
  33. package/src/errors.d.ts +1 -1
  34. package/src/index.cjs +102 -0
  35. package/src/index.js +102 -0
  36. package/src/packageJson.d.ts +3 -3
  37. package/src/resolveDirs.d.ts +1 -0
  38. package/src/tasks/binsTask.d.ts +9 -0
  39. package/src/tasks/buildTypesTask/buildTypesTask.d.ts +9 -0
  40. package/src/tasks/buildTypesTask/callTypescript.d.ts +8 -0
  41. package/src/tasks/copyStaticFilesTask.d.ts +1 -0
  42. package/src/tasks/jsFilesTask.d.ts +7 -0
  43. package/src/tasks/utils.d.ts +1 -0
  44. package/src/writePackageJson.d.ts +3 -2
  45. package/__do_not_import_directly__/index.cjs +0 -120
  46. package/__do_not_import_directly__/index.js +0 -98
  47. package/src/bin.d.ts +0 -2
  48. package/src/bin.js +0 -2
  49. package/src/buildTypes.d.ts +0 -7
  50. package/src/copyStaticFiles.d.ts +0 -7
  51. package/src/run.cjs +0 -4
  52. package/src/run.js +0 -3
@@ -1,98 +0,0 @@
1
- import { relative } from "node:path";
2
- import { rm, mkdir } from "node:fs/promises";
3
- import { parsePackageJson } from "./packageJson.js";
4
- import { writePackageJson } from "./writePackageJson.js";
5
- import { errors } from "./errors.js";
6
- import { buildTypes } from "./buildTypes.js";
7
- import { buildVite } from "./buildVite.js";
8
- import { copyStaticFiles } from "./copyStaticFiles.js";
9
- import { resolveDirs } from "./resolveDirs.js";
10
- import { createViteConfig } from "./createViteConfig.js";
11
- function reverseMap(map) {
12
- const reversed = /* @__PURE__ */ new Map();
13
- for (const [key, value] of map) {
14
- const arr = reversed.get(value) ?? [];
15
- arr.push(key);
16
- reversed.set(value, arr);
17
- }
18
- return reversed;
19
- }
20
- function setExports(exportsMap, exportName, mapFn) {
21
- const entry = exportsMap.get(exportName) ?? {};
22
- exportsMap.set(exportName, mapFn(entry));
23
- }
24
- async function run(args) {
25
- const dirs = resolveDirs(args);
26
- const { sourceDir, outDir, packagePath } = dirs;
27
- await rm(outDir, { recursive: true, force: true });
28
- await mkdir(outDir, { recursive: true });
29
- const packageJson = await parsePackageJson({ sourceDir, packagePath });
30
- if (Array.isArray(packageJson)) {
31
- console.log(packageJson);
32
- return { error: true, errors: packageJson };
33
- }
34
- const { viteConfig, entrypoints } = createViteConfig({ dirs, packageJson });
35
- const outputs = await buildVite({ viteConfig });
36
- if (outputs.error) {
37
- return { error: true, errors: outputs.errors };
38
- }
39
- const viteOutput = outputs.output;
40
- const exportsMap = /* @__PURE__ */ new Map();
41
- const reversedEntrypoints = reverseMap(entrypoints);
42
- const tsEntrypoints = [...entrypoints.values()].filter(
43
- (entry) => entry.endsWith(".ts")
44
- );
45
- if (tsEntrypoints.length > 0) {
46
- try {
47
- await import("typescript");
48
- } catch {
49
- return { error: true, errors: [errors.typescriptNotFound] };
50
- }
51
- const files = viteOutput.map((el) => el.facadeModuleId ?? "");
52
- const dtsMap = await buildTypes({ sourceDir, files, outDir });
53
- for (const [source, dts] of dtsMap) {
54
- const exportPath = reversedEntrypoints.get(source);
55
- if (!exportPath) {
56
- continue;
57
- }
58
- for (const path of exportPath) {
59
- setExports(exportsMap, path, (entry) => {
60
- entry.dts = "./" + relative(outDir, dts);
61
- return entry;
62
- });
63
- }
64
- }
65
- }
66
- for (const el of viteOutput) {
67
- if (el.facadeModuleId == null) {
68
- continue;
69
- }
70
- const exportPath = reversedEntrypoints.get(el.facadeModuleId);
71
- if (!exportPath) {
72
- continue;
73
- }
74
- for (const path of exportPath) {
75
- setExports(exportsMap, path, (entry) => {
76
- const format = el.fileName.endsWith(".cjs") ? "cjs" : "es";
77
- if (format === "es") {
78
- entry.mjs = "./" + el.fileName;
79
- } else if (format === "cjs") {
80
- entry.cjs = "./" + el.fileName;
81
- }
82
- return entry;
83
- });
84
- }
85
- }
86
- await copyStaticFiles({
87
- relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
88
- sourceDir,
89
- outDir
90
- });
91
- await writePackageJson(outDir, packageJson, {
92
- exportsMap
93
- });
94
- return { error: false };
95
- }
96
- export {
97
- run
98
- };
package/src/bin.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/src/bin.js DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import("smartbundle");
@@ -1,7 +0,0 @@
1
- type BuildTypesOptions = {
2
- sourceDir: string;
3
- files: string[];
4
- outDir: string;
5
- };
6
- export declare function buildTypes({ sourceDir, files, outDir, }: BuildTypesOptions): Promise<Map<string, string>>;
7
- export {};
@@ -1,7 +0,0 @@
1
- type CopyStaticFilesOptions = {
2
- relativeFiles: Set<string>;
3
- sourceDir: string;
4
- outDir: string;
5
- };
6
- export declare function copyStaticFiles({ sourceDir, outDir, relativeFiles, }: CopyStaticFilesOptions): Promise<void>;
7
- export {};
package/src/run.cjs DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- const args = require("../__do_not_import_directly__/args.cjs");
3
- const index = require("../__do_not_import_directly__/index.cjs");
4
- index.run(args.args);
package/src/run.js DELETED
@@ -1,3 +0,0 @@
1
- import { args } from "../__do_not_import_directly__/args.js";
2
- import { run } from "../__do_not_import_directly__/index.js";
3
- run(args);