smartbundle 0.6.0 → 0.7.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.
- package/README.md +7 -1
- package/__do_not_import_directly__/createViteConfig.cjs +14 -7
- package/__do_not_import_directly__/createViteConfig.js +14 -7
- package/__do_not_import_directly__/error.cjs +9 -0
- package/__do_not_import_directly__/error.js +9 -0
- package/__do_not_import_directly__/errors.cjs +1 -1
- package/__do_not_import_directly__/errors.js +1 -1
- package/__do_not_import_directly__/packageJson.cjs +32 -1
- package/__do_not_import_directly__/packageJson.js +32 -1
- package/__do_not_import_directly__/resolveDirs.cjs +2 -1
- package/__do_not_import_directly__/resolveDirs.js +2 -1
- package/__do_not_import_directly__/smartbundle.cjs +4 -0
- package/__do_not_import_directly__/smartbundle.js +3 -0
- package/__do_not_import_directly__/tasks/binsTask.cjs +40 -0
- package/__do_not_import_directly__/tasks/binsTask.js +40 -0
- package/{src/bin.cjs → __do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs} +39 -2
- package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js +40 -0
- package/__do_not_import_directly__/{buildTypes.cjs → tasks/buildTypesTask/callTypescript.cjs} +3 -26
- package/__do_not_import_directly__/{buildTypes.js → tasks/buildTypesTask/callTypescript.js} +3 -4
- package/__do_not_import_directly__/{copyStaticFiles.cjs → tasks/copyStaticFilesTask.cjs} +8 -1
- package/__do_not_import_directly__/{copyStaticFiles.js → tasks/copyStaticFilesTask.js} +8 -1
- package/__do_not_import_directly__/tasks/jsFilesTask.cjs +25 -0
- package/__do_not_import_directly__/tasks/jsFilesTask.js +25 -0
- package/__do_not_import_directly__/tasks/utils.cjs +12 -0
- package/__do_not_import_directly__/tasks/utils.js +12 -0
- package/__do_not_import_directly__/writePackageJson.cjs +5 -6
- package/__do_not_import_directly__/writePackageJson.js +5 -6
- package/__smartbundle__internals__/smartbundle +2 -0
- package/package.json +13 -11
- package/src/buildVite.d.ts +1 -1
- package/src/createViteConfig.d.ts +1 -0
- package/src/error.d.ts +4 -0
- package/src/errors.d.ts +1 -1
- package/src/index.cjs +102 -0
- package/src/index.js +102 -0
- package/src/packageJson.d.ts +3 -3
- package/src/resolveDirs.d.ts +1 -0
- package/src/tasks/binsTask.d.ts +9 -0
- package/src/tasks/buildTypesTask/buildTypesTask.d.ts +9 -0
- package/src/tasks/buildTypesTask/callTypescript.d.ts +8 -0
- package/src/tasks/copyStaticFilesTask.d.ts +1 -0
- package/src/tasks/jsFilesTask.d.ts +7 -0
- package/src/tasks/utils.d.ts +1 -0
- package/src/writePackageJson.d.ts +3 -2
- package/__do_not_import_directly__/index.cjs +0 -120
- package/__do_not_import_directly__/index.js +0 -98
- package/src/bin.d.ts +0 -2
- package/src/bin.js +0 -2
- package/src/buildTypes.d.ts +0 -7
- package/src/copyStaticFiles.d.ts +0 -7
- package/src/run.cjs +0 -4
- 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
package/src/bin.js
DELETED
package/src/buildTypes.d.ts
DELETED
package/src/copyStaticFiles.d.ts
DELETED
package/src/run.cjs
DELETED
package/src/run.js
DELETED