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.
- 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
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
function reverseMap(map) {
|
4
|
+
const reversed = /* @__PURE__ */ new Map();
|
5
|
+
for (const [key, value] of map) {
|
6
|
+
const arr = reversed.get(value) ?? [];
|
7
|
+
arr.push(key);
|
8
|
+
reversed.set(value, arr);
|
9
|
+
}
|
10
|
+
return reversed;
|
11
|
+
}
|
12
|
+
exports.reverseMap = reverseMap;
|
@@ -1,13 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const fs = require("node:fs/promises");
|
4
|
-
|
5
|
-
|
4
|
+
require("zod");
|
5
|
+
require("node:path");
|
6
|
+
async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
6
7
|
const allExports = {};
|
7
8
|
for (const [key, value] of exportsMap) {
|
8
|
-
if (key === "__bin__") {
|
9
|
-
continue;
|
10
|
-
}
|
11
9
|
const anExport = {};
|
12
10
|
if (value.dts) {
|
13
11
|
anExport.types = value.dts;
|
@@ -30,12 +28,13 @@ async function writePackageJson(outDir, parsed, { exportsMap }) {
|
|
30
28
|
allExports[key] = anExport;
|
31
29
|
}
|
32
30
|
allExports["./package.json"] = "./package.json";
|
31
|
+
const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
|
33
32
|
const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
|
34
33
|
const res = {
|
35
34
|
name: parsed.name,
|
36
35
|
type: "module",
|
37
36
|
version: parsed.version,
|
38
|
-
bin
|
37
|
+
bin,
|
39
38
|
types: rootExport == null ? void 0 : rootExport.types,
|
40
39
|
module: rootExport == null ? void 0 : rootExport.default,
|
41
40
|
description: parsed.description ?? "",
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import { writeFile } from "node:fs/promises";
|
2
|
-
|
3
|
-
|
2
|
+
import "zod";
|
3
|
+
import "node:path";
|
4
|
+
async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
4
5
|
const allExports = {};
|
5
6
|
for (const [key, value] of exportsMap) {
|
6
|
-
if (key === "__bin__") {
|
7
|
-
continue;
|
8
|
-
}
|
9
7
|
const anExport = {};
|
10
8
|
if (value.dts) {
|
11
9
|
anExport.types = value.dts;
|
@@ -28,12 +26,13 @@ async function writePackageJson(outDir, parsed, { exportsMap }) {
|
|
28
26
|
allExports[key] = anExport;
|
29
27
|
}
|
30
28
|
allExports["./package.json"] = "./package.json";
|
29
|
+
const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
|
31
30
|
const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
|
32
31
|
const res = {
|
33
32
|
name: parsed.name,
|
34
33
|
type: "module",
|
35
34
|
version: parsed.version,
|
36
|
-
bin
|
35
|
+
bin,
|
37
36
|
types: rootExport == null ? void 0 : rootExport.types,
|
38
37
|
module: rootExport == null ? void 0 : rootExport.default,
|
39
38
|
description: parsed.description ?? "",
|
package/package.json
CHANGED
@@ -1,28 +1,30 @@
|
|
1
1
|
{
|
2
2
|
"name": "smartbundle",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
5
|
-
"bin":
|
6
|
-
|
7
|
-
|
4
|
+
"version": "0.7.0-alpha.0",
|
5
|
+
"bin": {
|
6
|
+
"smartbundle": "__smartbundle__internals__/smartbundle"
|
7
|
+
},
|
8
|
+
"types": "./src/index.d.ts",
|
9
|
+
"module": "./src/index.js",
|
8
10
|
"description": "zero-config bundler for npm packages",
|
9
11
|
"exports": {
|
10
12
|
".": {
|
11
|
-
"types": "./src/
|
13
|
+
"types": "./src/index.d.ts",
|
12
14
|
"import": {
|
13
|
-
"types": "./src/
|
14
|
-
"default": "./src/
|
15
|
+
"types": "./src/index.d.ts",
|
16
|
+
"default": "./src/index.js"
|
15
17
|
},
|
16
18
|
"require": {
|
17
|
-
"types": "./src/
|
18
|
-
"default": "./src/
|
19
|
+
"types": "./src/index.d.ts",
|
20
|
+
"default": "./src/index.cjs"
|
19
21
|
},
|
20
|
-
"default": "./src/
|
22
|
+
"default": "./src/index.js"
|
21
23
|
},
|
22
24
|
"./package.json": "./package.json"
|
23
25
|
},
|
24
26
|
"dependencies": {
|
25
|
-
"vite": "^5.
|
27
|
+
"vite": "^5.4.9",
|
26
28
|
"yargs": "^17.7.2",
|
27
29
|
"zod": "^3.23.8"
|
28
30
|
},
|
package/src/buildVite.d.ts
CHANGED
package/src/error.d.ts
ADDED
package/src/errors.d.ts
CHANGED
package/src/index.cjs
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const path = require("node:path");
|
4
|
+
const fs = require("node:fs/promises");
|
5
|
+
const packageJson = require("../__do_not_import_directly__/packageJson.cjs");
|
6
|
+
const writePackageJson = require("../__do_not_import_directly__/writePackageJson.cjs");
|
7
|
+
const buildVite = require("../__do_not_import_directly__/buildVite.cjs");
|
8
|
+
const resolveDirs = require("../__do_not_import_directly__/resolveDirs.cjs");
|
9
|
+
const createViteConfig = require("../__do_not_import_directly__/createViteConfig.cjs");
|
10
|
+
const copyStaticFilesTask = require("../__do_not_import_directly__/tasks/copyStaticFilesTask.cjs");
|
11
|
+
const buildTypesTask = require("../__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs");
|
12
|
+
const error = require("../__do_not_import_directly__/error.cjs");
|
13
|
+
const jsFilesTask = require("../__do_not_import_directly__/tasks/jsFilesTask.cjs");
|
14
|
+
const binsTask = require("../__do_not_import_directly__/tasks/binsTask.cjs");
|
15
|
+
function setExports(exportsMap, exportName, mapFn) {
|
16
|
+
const entry = exportsMap.get(exportName) ?? {};
|
17
|
+
exportsMap.set(exportName, mapFn(entry));
|
18
|
+
}
|
19
|
+
async function defineViteConfig(args = {}) {
|
20
|
+
const dirs = resolveDirs.resolveDirs(args);
|
21
|
+
const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
|
22
|
+
await fs.rm(outDir, { recursive: true, force: true });
|
23
|
+
await fs.mkdir(outDir, { recursive: true });
|
24
|
+
await fs.mkdir(outInternalsDir, { recursive: true });
|
25
|
+
const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
|
26
|
+
if (Array.isArray(packageJson$1)) {
|
27
|
+
console.error(packageJson$1);
|
28
|
+
throw new Error("Failed to parse package.json");
|
29
|
+
}
|
30
|
+
const { viteConfig } = createViteConfig.createViteConfig({ dirs, packageJson: packageJson$1 });
|
31
|
+
return viteConfig;
|
32
|
+
}
|
33
|
+
async function run(args) {
|
34
|
+
const dirs = resolveDirs.resolveDirs(args);
|
35
|
+
const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
|
36
|
+
await fs.rm(outDir, { recursive: true, force: true });
|
37
|
+
await fs.mkdir(outDir, { recursive: true });
|
38
|
+
const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
|
39
|
+
if (Array.isArray(packageJson$1)) {
|
40
|
+
console.log(packageJson$1);
|
41
|
+
return { error: true, errors: packageJson$1 };
|
42
|
+
}
|
43
|
+
const { viteConfig, entrypoints, bins } = createViteConfig.createViteConfig({
|
44
|
+
dirs,
|
45
|
+
packageJson: packageJson$1
|
46
|
+
});
|
47
|
+
const outputs = await buildVite.buildVite({ viteConfig });
|
48
|
+
if (outputs.error) {
|
49
|
+
return { error: true, errors: outputs.errors };
|
50
|
+
}
|
51
|
+
await fs.mkdir(outInternalsDir, { recursive: true });
|
52
|
+
const viteOutput = outputs.output;
|
53
|
+
const exportsMap = /* @__PURE__ */ new Map();
|
54
|
+
const binsMap = /* @__PURE__ */ new Map();
|
55
|
+
const tasksRes = await Promise.allSettled([
|
56
|
+
copyStaticFilesTask.copyStaticFilesTask(sourceDir, outDir),
|
57
|
+
buildTypesTask.buildTypesTask({
|
58
|
+
sourceDir,
|
59
|
+
outDir,
|
60
|
+
entrypoints,
|
61
|
+
buildOutput: viteOutput
|
62
|
+
}).then((res) => {
|
63
|
+
for (const [value, key] of res) {
|
64
|
+
setExports(exportsMap, key, (entry) => {
|
65
|
+
entry.dts = "./" + path.relative(outDir, value);
|
66
|
+
return entry;
|
67
|
+
});
|
68
|
+
}
|
69
|
+
}),
|
70
|
+
jsFilesTask.jsFilesTask({ buildOutput: viteOutput, entrypoints }).then((res) => {
|
71
|
+
for (const [value, key] of res) {
|
72
|
+
setExports(exportsMap, key, (entry) => {
|
73
|
+
const format = value.endsWith(".cjs") ? "cjs" : "es";
|
74
|
+
if (format === "es") {
|
75
|
+
entry.mjs = "./" + value;
|
76
|
+
} else if (format === "cjs") {
|
77
|
+
entry.cjs = "./" + value;
|
78
|
+
}
|
79
|
+
return entry;
|
80
|
+
});
|
81
|
+
}
|
82
|
+
}),
|
83
|
+
binsTask.binsTask({ outInternalsDir, bins, buildOutput: viteOutput, outDir }).then(
|
84
|
+
(res) => {
|
85
|
+
for (const [value, key] of res) {
|
86
|
+
binsMap.set(key, value);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
)
|
90
|
+
]);
|
91
|
+
const errors = tasksRes.filter((res) => res.status === "rejected").map((res) => res.reason).filter((res) => res instanceof error.BuildError).map((res) => res.error);
|
92
|
+
if (errors.length > 0) {
|
93
|
+
return { error: true, errors };
|
94
|
+
}
|
95
|
+
await writePackageJson.writePackageJson(outDir, packageJson$1, {
|
96
|
+
exportsMap,
|
97
|
+
binsMap
|
98
|
+
});
|
99
|
+
return { error: false };
|
100
|
+
}
|
101
|
+
exports.defineViteConfig = defineViteConfig;
|
102
|
+
exports.run = run;
|
package/src/index.js
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
import { relative } from "node:path";
|
2
|
+
import { rm, mkdir } from "node:fs/promises";
|
3
|
+
import { parsePackageJson } from "../__do_not_import_directly__/packageJson.js";
|
4
|
+
import { writePackageJson } from "../__do_not_import_directly__/writePackageJson.js";
|
5
|
+
import { buildVite } from "../__do_not_import_directly__/buildVite.js";
|
6
|
+
import { resolveDirs } from "../__do_not_import_directly__/resolveDirs.js";
|
7
|
+
import { createViteConfig } from "../__do_not_import_directly__/createViteConfig.js";
|
8
|
+
import { copyStaticFilesTask } from "../__do_not_import_directly__/tasks/copyStaticFilesTask.js";
|
9
|
+
import { buildTypesTask } from "../__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js";
|
10
|
+
import { BuildError } from "../__do_not_import_directly__/error.js";
|
11
|
+
import { jsFilesTask } from "../__do_not_import_directly__/tasks/jsFilesTask.js";
|
12
|
+
import { binsTask } from "../__do_not_import_directly__/tasks/binsTask.js";
|
13
|
+
function setExports(exportsMap, exportName, mapFn) {
|
14
|
+
const entry = exportsMap.get(exportName) ?? {};
|
15
|
+
exportsMap.set(exportName, mapFn(entry));
|
16
|
+
}
|
17
|
+
async function defineViteConfig(args = {}) {
|
18
|
+
const dirs = resolveDirs(args);
|
19
|
+
const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
|
20
|
+
await rm(outDir, { recursive: true, force: true });
|
21
|
+
await mkdir(outDir, { recursive: true });
|
22
|
+
await mkdir(outInternalsDir, { recursive: true });
|
23
|
+
const packageJson = await parsePackageJson({ sourceDir, packagePath });
|
24
|
+
if (Array.isArray(packageJson)) {
|
25
|
+
console.error(packageJson);
|
26
|
+
throw new Error("Failed to parse package.json");
|
27
|
+
}
|
28
|
+
const { viteConfig } = createViteConfig({ dirs, packageJson });
|
29
|
+
return viteConfig;
|
30
|
+
}
|
31
|
+
async function run(args) {
|
32
|
+
const dirs = resolveDirs(args);
|
33
|
+
const { sourceDir, outDir, packagePath, outInternalsDir } = dirs;
|
34
|
+
await rm(outDir, { recursive: true, force: true });
|
35
|
+
await mkdir(outDir, { recursive: true });
|
36
|
+
const packageJson = await parsePackageJson({ sourceDir, packagePath });
|
37
|
+
if (Array.isArray(packageJson)) {
|
38
|
+
console.log(packageJson);
|
39
|
+
return { error: true, errors: packageJson };
|
40
|
+
}
|
41
|
+
const { viteConfig, entrypoints, bins } = createViteConfig({
|
42
|
+
dirs,
|
43
|
+
packageJson
|
44
|
+
});
|
45
|
+
const outputs = await buildVite({ viteConfig });
|
46
|
+
if (outputs.error) {
|
47
|
+
return { error: true, errors: outputs.errors };
|
48
|
+
}
|
49
|
+
await mkdir(outInternalsDir, { recursive: true });
|
50
|
+
const viteOutput = outputs.output;
|
51
|
+
const exportsMap = /* @__PURE__ */ new Map();
|
52
|
+
const binsMap = /* @__PURE__ */ new Map();
|
53
|
+
const tasksRes = await Promise.allSettled([
|
54
|
+
copyStaticFilesTask(sourceDir, outDir),
|
55
|
+
buildTypesTask({
|
56
|
+
sourceDir,
|
57
|
+
outDir,
|
58
|
+
entrypoints,
|
59
|
+
buildOutput: viteOutput
|
60
|
+
}).then((res) => {
|
61
|
+
for (const [value, key] of res) {
|
62
|
+
setExports(exportsMap, key, (entry) => {
|
63
|
+
entry.dts = "./" + relative(outDir, value);
|
64
|
+
return entry;
|
65
|
+
});
|
66
|
+
}
|
67
|
+
}),
|
68
|
+
jsFilesTask({ buildOutput: viteOutput, entrypoints }).then((res) => {
|
69
|
+
for (const [value, key] of res) {
|
70
|
+
setExports(exportsMap, key, (entry) => {
|
71
|
+
const format = value.endsWith(".cjs") ? "cjs" : "es";
|
72
|
+
if (format === "es") {
|
73
|
+
entry.mjs = "./" + value;
|
74
|
+
} else if (format === "cjs") {
|
75
|
+
entry.cjs = "./" + value;
|
76
|
+
}
|
77
|
+
return entry;
|
78
|
+
});
|
79
|
+
}
|
80
|
+
}),
|
81
|
+
binsTask({ outInternalsDir, bins, buildOutput: viteOutput, outDir }).then(
|
82
|
+
(res) => {
|
83
|
+
for (const [value, key] of res) {
|
84
|
+
binsMap.set(key, value);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
)
|
88
|
+
]);
|
89
|
+
const errors = tasksRes.filter((res) => res.status === "rejected").map((res) => res.reason).filter((res) => res instanceof BuildError).map((res) => res.error);
|
90
|
+
if (errors.length > 0) {
|
91
|
+
return { error: true, errors };
|
92
|
+
}
|
93
|
+
await writePackageJson(outDir, packageJson, {
|
94
|
+
exportsMap,
|
95
|
+
binsMap
|
96
|
+
});
|
97
|
+
return { error: false };
|
98
|
+
}
|
99
|
+
export {
|
100
|
+
defineViteConfig,
|
101
|
+
run
|
102
|
+
};
|
package/src/packageJson.d.ts
CHANGED
@@ -7,7 +7,7 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
7
7
|
description: z.ZodOptional<z.ZodString>;
|
8
8
|
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
9
9
|
optionalDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
10
|
-
bin: z.ZodOptional<z.ZodString
|
10
|
+
bin: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodString, Map<string, string>, string>, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Map<string, string>, Record<string, string>>]>, Map<string, string>, string | Record<string, string>>>;
|
11
11
|
repository: z.ZodOptional<z.ZodAny>;
|
12
12
|
keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
13
13
|
author: z.ZodOptional<z.ZodAny>;
|
@@ -33,7 +33,7 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
33
33
|
description?: string;
|
34
34
|
dependencies?: Record<string, string>;
|
35
35
|
optionalDependencies?: Record<string, string>;
|
36
|
-
bin?: string
|
36
|
+
bin?: Map<string, string>;
|
37
37
|
repository?: any;
|
38
38
|
keywords?: string[];
|
39
39
|
author?: any;
|
@@ -59,7 +59,7 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
59
59
|
description?: string;
|
60
60
|
dependencies?: Record<string, string>;
|
61
61
|
optionalDependencies?: Record<string, string>;
|
62
|
-
bin?: string
|
62
|
+
bin?: string | Record<string, string>;
|
63
63
|
repository?: any;
|
64
64
|
keywords?: string[];
|
65
65
|
author?: any;
|
package/src/resolveDirs.d.ts
CHANGED
@@ -0,0 +1,9 @@
|
|
1
|
+
import { type Rollup } from "vite";
|
2
|
+
type BinsTaskOption = {
|
3
|
+
buildOutput: Rollup.OutputChunk[];
|
4
|
+
bins: Map<string, string>;
|
5
|
+
outInternalsDir: string;
|
6
|
+
outDir: string;
|
7
|
+
};
|
8
|
+
export declare function binsTask({ buildOutput, bins, outInternalsDir, outDir, }: BinsTaskOption): Promise<Map<string, string>>;
|
9
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { type Rollup } from "vite";
|
2
|
+
type BuildTypesTaskOption = {
|
3
|
+
buildOutput: Rollup.OutputChunk[];
|
4
|
+
entrypoints: Map<string, string>;
|
5
|
+
sourceDir: string;
|
6
|
+
outDir: string;
|
7
|
+
};
|
8
|
+
export declare function buildTypesTask({ buildOutput, entrypoints, sourceDir, outDir, }: BuildTypesTaskOption): Promise<Map<string, string>>;
|
9
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function copyStaticFilesTask(sourceDir: string, outDir: string): Promise<void>;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { type Rollup } from "vite";
|
2
|
+
type JsFilesTaskOption = {
|
3
|
+
buildOutput: Rollup.OutputChunk[];
|
4
|
+
entrypoints: Map<string, string>;
|
5
|
+
};
|
6
|
+
export declare function jsFilesTask({ buildOutput, entrypoints, }: JsFilesTaskOption): Promise<Map<string, string>>;
|
7
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function reverseMap(map: Map<string, string>): Map<string, Array<string>>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PackageJson } from "./packageJson.js";
|
1
|
+
import { type PackageJson } from "./packageJson.js";
|
2
2
|
export type ExportsObject = {
|
3
3
|
mjs?: string;
|
4
4
|
dts?: string;
|
@@ -7,6 +7,7 @@ export type ExportsObject = {
|
|
7
7
|
};
|
8
8
|
type BuildResult = {
|
9
9
|
exportsMap: Map<string, ExportsObject>;
|
10
|
+
binsMap: Map<string, string>;
|
10
11
|
};
|
11
|
-
export declare function writePackageJson(outDir: string, parsed: PackageJson, { exportsMap }: BuildResult): Promise<void>;
|
12
|
+
export declare function writePackageJson(outDir: string, parsed: PackageJson, { exportsMap, binsMap }: BuildResult): Promise<void>;
|
12
13
|
export {};
|
@@ -1,120 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
-
for (let key of __getOwnPropNames(from))
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
-
}
|
14
|
-
return to;
|
15
|
-
};
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
-
mod
|
23
|
-
));
|
24
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
25
|
-
const path = require("node:path");
|
26
|
-
const fs = require("node:fs/promises");
|
27
|
-
const packageJson = require("./packageJson.cjs");
|
28
|
-
const writePackageJson = require("./writePackageJson.cjs");
|
29
|
-
const errors = require("./errors.cjs");
|
30
|
-
const buildTypes = require("./buildTypes.cjs");
|
31
|
-
const buildVite = require("./buildVite.cjs");
|
32
|
-
const copyStaticFiles = require("./copyStaticFiles.cjs");
|
33
|
-
const resolveDirs = require("./resolveDirs.cjs");
|
34
|
-
const createViteConfig = require("./createViteConfig.cjs");
|
35
|
-
function reverseMap(map) {
|
36
|
-
const reversed = /* @__PURE__ */ new Map();
|
37
|
-
for (const [key, value] of map) {
|
38
|
-
const arr = reversed.get(value) ?? [];
|
39
|
-
arr.push(key);
|
40
|
-
reversed.set(value, arr);
|
41
|
-
}
|
42
|
-
return reversed;
|
43
|
-
}
|
44
|
-
function setExports(exportsMap, exportName, mapFn) {
|
45
|
-
const entry = exportsMap.get(exportName) ?? {};
|
46
|
-
exportsMap.set(exportName, mapFn(entry));
|
47
|
-
}
|
48
|
-
async function run(args) {
|
49
|
-
const dirs = resolveDirs.resolveDirs(args);
|
50
|
-
const { sourceDir, outDir, packagePath } = dirs;
|
51
|
-
await fs.rm(outDir, { recursive: true, force: true });
|
52
|
-
await fs.mkdir(outDir, { recursive: true });
|
53
|
-
const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
|
54
|
-
if (Array.isArray(packageJson$1)) {
|
55
|
-
console.log(packageJson$1);
|
56
|
-
return { error: true, errors: packageJson$1 };
|
57
|
-
}
|
58
|
-
const { viteConfig, entrypoints } = createViteConfig.createViteConfig({ dirs, packageJson: packageJson$1 });
|
59
|
-
const outputs = await buildVite.buildVite({ viteConfig });
|
60
|
-
if (outputs.error) {
|
61
|
-
return { error: true, errors: outputs.errors };
|
62
|
-
}
|
63
|
-
const viteOutput = outputs.output;
|
64
|
-
const exportsMap = /* @__PURE__ */ new Map();
|
65
|
-
const reversedEntrypoints = reverseMap(entrypoints);
|
66
|
-
const tsEntrypoints = [...entrypoints.values()].filter(
|
67
|
-
(entry) => entry.endsWith(".ts")
|
68
|
-
);
|
69
|
-
if (tsEntrypoints.length > 0) {
|
70
|
-
try {
|
71
|
-
await import("typescript");
|
72
|
-
} catch {
|
73
|
-
return { error: true, errors: [errors.errors.typescriptNotFound] };
|
74
|
-
}
|
75
|
-
const files = viteOutput.map((el) => el.facadeModuleId ?? "");
|
76
|
-
const dtsMap = await buildTypes.buildTypes({ sourceDir, files, outDir });
|
77
|
-
for (const [source, dts] of dtsMap) {
|
78
|
-
const exportPath = reversedEntrypoints.get(source);
|
79
|
-
if (!exportPath) {
|
80
|
-
continue;
|
81
|
-
}
|
82
|
-
for (const path$1 of exportPath) {
|
83
|
-
setExports(exportsMap, path$1, (entry) => {
|
84
|
-
entry.dts = "./" + path.relative(outDir, dts);
|
85
|
-
return entry;
|
86
|
-
});
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}
|
90
|
-
for (const el of viteOutput) {
|
91
|
-
if (el.facadeModuleId == null) {
|
92
|
-
continue;
|
93
|
-
}
|
94
|
-
const exportPath = reversedEntrypoints.get(el.facadeModuleId);
|
95
|
-
if (!exportPath) {
|
96
|
-
continue;
|
97
|
-
}
|
98
|
-
for (const path2 of exportPath) {
|
99
|
-
setExports(exportsMap, path2, (entry) => {
|
100
|
-
const format = el.fileName.endsWith(".cjs") ? "cjs" : "es";
|
101
|
-
if (format === "es") {
|
102
|
-
entry.mjs = "./" + el.fileName;
|
103
|
-
} else if (format === "cjs") {
|
104
|
-
entry.cjs = "./" + el.fileName;
|
105
|
-
}
|
106
|
-
return entry;
|
107
|
-
});
|
108
|
-
}
|
109
|
-
}
|
110
|
-
await copyStaticFiles.copyStaticFiles({
|
111
|
-
relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
|
112
|
-
sourceDir,
|
113
|
-
outDir
|
114
|
-
});
|
115
|
-
await writePackageJson.writePackageJson(outDir, packageJson$1, {
|
116
|
-
exportsMap
|
117
|
-
});
|
118
|
-
return { error: false };
|
119
|
-
}
|
120
|
-
exports.run = run;
|