smartbundle 0.4.1 → 0.5.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/__do_not_import_directly__/buildVite.cjs +2 -67
- package/__do_not_import_directly__/buildVite.js +2 -67
- package/__do_not_import_directly__/createViteConfig.cjs +80 -0
- package/__do_not_import_directly__/createViteConfig.js +80 -0
- package/__do_not_import_directly__/index.cjs +6 -27
- package/__do_not_import_directly__/index.js +7 -28
- package/__do_not_import_directly__/packageJson.cjs +9 -17
- package/__do_not_import_directly__/packageJson.js +9 -17
- package/__do_not_import_directly__/resolveDirs.cjs +19 -0
- package/__do_not_import_directly__/resolveDirs.js +19 -0
- package/__do_not_import_directly__/writePackageJson.cjs +6 -1
- package/__do_not_import_directly__/writePackageJson.js +6 -1
- package/package.json +6 -2
- package/src/buildVite.d.ts +3 -6
- package/src/createViteConfig.d.ts +11 -0
- package/src/index.d.ts +2 -6
- package/src/packageJson.d.ts +24 -44
- package/src/resolveDirs.d.ts +11 -0
@@ -1,76 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const vite = require("vite");
|
4
|
-
const path = require("node:path");
|
5
4
|
const errors = require("./errors.cjs");
|
6
|
-
function mapToObject(map) {
|
7
|
-
const obj = {};
|
8
|
-
for (const [key, value] of map) {
|
9
|
-
obj[key] = value;
|
10
|
-
}
|
11
|
-
return obj;
|
12
|
-
}
|
13
5
|
async function buildVite({
|
14
|
-
|
15
|
-
packageJson,
|
16
|
-
sourceDir,
|
17
|
-
outDir
|
6
|
+
viteConfig
|
18
7
|
}) {
|
19
|
-
const outputs = await vite.build(
|
20
|
-
publicDir: false,
|
21
|
-
build: {
|
22
|
-
outDir,
|
23
|
-
write: true,
|
24
|
-
minify: false,
|
25
|
-
emptyOutDir: true,
|
26
|
-
assetsInlineLimit: 0,
|
27
|
-
terserOptions: {
|
28
|
-
compress: false,
|
29
|
-
mangle: false
|
30
|
-
},
|
31
|
-
lib: {
|
32
|
-
entry: mapToObject(entrypoints),
|
33
|
-
formats: ["es", "cjs"],
|
34
|
-
fileName: (format, entryName) => {
|
35
|
-
const entrypoint = entrypoints.get(entryName);
|
36
|
-
if (!entrypoint) {
|
37
|
-
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
38
|
-
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".js" : ".cjs");
|
39
|
-
}
|
40
|
-
const relativePath = path.relative(sourceDir, entrypoint);
|
41
|
-
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
42
|
-
if (format === "es") {
|
43
|
-
return `${noExt}.js`;
|
44
|
-
}
|
45
|
-
if (format === "cjs") {
|
46
|
-
return `${noExt}.cjs`;
|
47
|
-
}
|
48
|
-
return noExt;
|
49
|
-
}
|
50
|
-
},
|
51
|
-
rollupOptions: {
|
52
|
-
external: (id, parentId, isResolved) => {
|
53
|
-
if (id === packageJson.name) {
|
54
|
-
return true;
|
55
|
-
}
|
56
|
-
if (id.startsWith("node:")) {
|
57
|
-
return true;
|
58
|
-
}
|
59
|
-
if (id in (packageJson.dependencies ?? {})) {
|
60
|
-
return true;
|
61
|
-
}
|
62
|
-
if (id in (packageJson.optionalDependencies ?? {})) {
|
63
|
-
return true;
|
64
|
-
}
|
65
|
-
return false;
|
66
|
-
},
|
67
|
-
output: {
|
68
|
-
exports: "named",
|
69
|
-
preserveModules: true
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
});
|
8
|
+
const outputs = await vite.build(viteConfig);
|
74
9
|
if (!Array.isArray(outputs)) {
|
75
10
|
return {
|
76
11
|
error: true,
|
@@ -1,74 +1,9 @@
|
|
1
1
|
import { build } from "vite";
|
2
|
-
import { relative } from "node:path";
|
3
2
|
import { errors } from "./errors.js";
|
4
|
-
function mapToObject(map) {
|
5
|
-
const obj = {};
|
6
|
-
for (const [key, value] of map) {
|
7
|
-
obj[key] = value;
|
8
|
-
}
|
9
|
-
return obj;
|
10
|
-
}
|
11
3
|
async function buildVite({
|
12
|
-
|
13
|
-
packageJson,
|
14
|
-
sourceDir,
|
15
|
-
outDir
|
4
|
+
viteConfig
|
16
5
|
}) {
|
17
|
-
const outputs = await build(
|
18
|
-
publicDir: false,
|
19
|
-
build: {
|
20
|
-
outDir,
|
21
|
-
write: true,
|
22
|
-
minify: false,
|
23
|
-
emptyOutDir: true,
|
24
|
-
assetsInlineLimit: 0,
|
25
|
-
terserOptions: {
|
26
|
-
compress: false,
|
27
|
-
mangle: false
|
28
|
-
},
|
29
|
-
lib: {
|
30
|
-
entry: mapToObject(entrypoints),
|
31
|
-
formats: ["es", "cjs"],
|
32
|
-
fileName: (format, entryName) => {
|
33
|
-
const entrypoint = entrypoints.get(entryName);
|
34
|
-
if (!entrypoint) {
|
35
|
-
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
36
|
-
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".js" : ".cjs");
|
37
|
-
}
|
38
|
-
const relativePath = relative(sourceDir, entrypoint);
|
39
|
-
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
40
|
-
if (format === "es") {
|
41
|
-
return `${noExt}.js`;
|
42
|
-
}
|
43
|
-
if (format === "cjs") {
|
44
|
-
return `${noExt}.cjs`;
|
45
|
-
}
|
46
|
-
return noExt;
|
47
|
-
}
|
48
|
-
},
|
49
|
-
rollupOptions: {
|
50
|
-
external: (id, parentId, isResolved) => {
|
51
|
-
if (id === packageJson.name) {
|
52
|
-
return true;
|
53
|
-
}
|
54
|
-
if (id.startsWith("node:")) {
|
55
|
-
return true;
|
56
|
-
}
|
57
|
-
if (id in (packageJson.dependencies ?? {})) {
|
58
|
-
return true;
|
59
|
-
}
|
60
|
-
if (id in (packageJson.optionalDependencies ?? {})) {
|
61
|
-
return true;
|
62
|
-
}
|
63
|
-
return false;
|
64
|
-
},
|
65
|
-
output: {
|
66
|
-
exports: "named",
|
67
|
-
preserveModules: true
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
});
|
6
|
+
const outputs = await build(viteConfig);
|
72
7
|
if (!Array.isArray(outputs)) {
|
73
8
|
return {
|
74
9
|
error: true,
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const path = require("node:path");
|
4
|
+
const vite = require("vite");
|
5
|
+
function mapToObject(map) {
|
6
|
+
const obj = {};
|
7
|
+
for (const [key, value] of map) {
|
8
|
+
obj[key] = value;
|
9
|
+
}
|
10
|
+
return obj;
|
11
|
+
}
|
12
|
+
function createViteConfig({ dirs, packageJson }) {
|
13
|
+
const { sourceDir, outDir } = dirs;
|
14
|
+
const entrypoints = /* @__PURE__ */ new Map();
|
15
|
+
if (packageJson.exports) {
|
16
|
+
const mainEntry = path.join(sourceDir, packageJson.exports);
|
17
|
+
entrypoints.set(".", mainEntry);
|
18
|
+
}
|
19
|
+
if (packageJson.bin) {
|
20
|
+
const binEntry = path.join(sourceDir, packageJson.bin);
|
21
|
+
entrypoints.set("__bin__", binEntry);
|
22
|
+
}
|
23
|
+
const viteConfig = vite.defineConfig({
|
24
|
+
publicDir: false,
|
25
|
+
build: {
|
26
|
+
outDir,
|
27
|
+
write: true,
|
28
|
+
minify: false,
|
29
|
+
emptyOutDir: true,
|
30
|
+
assetsInlineLimit: 0,
|
31
|
+
terserOptions: {
|
32
|
+
compress: false,
|
33
|
+
mangle: false
|
34
|
+
},
|
35
|
+
lib: {
|
36
|
+
entry: mapToObject(entrypoints),
|
37
|
+
formats: ["es", "cjs"],
|
38
|
+
fileName: (format, entryName) => {
|
39
|
+
const entrypoint = entrypoints.get(entryName);
|
40
|
+
if (!entrypoint) {
|
41
|
+
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
42
|
+
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".js" : ".cjs");
|
43
|
+
}
|
44
|
+
const relativePath = path.relative(sourceDir, entrypoint);
|
45
|
+
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
46
|
+
if (format === "es") {
|
47
|
+
return `${noExt}.js`;
|
48
|
+
}
|
49
|
+
if (format === "cjs") {
|
50
|
+
return `${noExt}.cjs`;
|
51
|
+
}
|
52
|
+
return noExt;
|
53
|
+
}
|
54
|
+
},
|
55
|
+
rollupOptions: {
|
56
|
+
external: (id, parentId, isResolved) => {
|
57
|
+
if (id === packageJson.name) {
|
58
|
+
return true;
|
59
|
+
}
|
60
|
+
if (id.startsWith("node:")) {
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
if (id in (packageJson.dependencies ?? {})) {
|
64
|
+
return true;
|
65
|
+
}
|
66
|
+
if (id in (packageJson.optionalDependencies ?? {})) {
|
67
|
+
return true;
|
68
|
+
}
|
69
|
+
return false;
|
70
|
+
},
|
71
|
+
output: {
|
72
|
+
exports: "named",
|
73
|
+
preserveModules: true
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return { viteConfig, entrypoints };
|
79
|
+
}
|
80
|
+
exports.createViteConfig = createViteConfig;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { join, relative } from "node:path";
|
2
|
+
import { defineConfig } from "vite";
|
3
|
+
function mapToObject(map) {
|
4
|
+
const obj = {};
|
5
|
+
for (const [key, value] of map) {
|
6
|
+
obj[key] = value;
|
7
|
+
}
|
8
|
+
return obj;
|
9
|
+
}
|
10
|
+
function createViteConfig({ dirs, packageJson }) {
|
11
|
+
const { sourceDir, outDir } = dirs;
|
12
|
+
const entrypoints = /* @__PURE__ */ new Map();
|
13
|
+
if (packageJson.exports) {
|
14
|
+
const mainEntry = join(sourceDir, packageJson.exports);
|
15
|
+
entrypoints.set(".", mainEntry);
|
16
|
+
}
|
17
|
+
if (packageJson.bin) {
|
18
|
+
const binEntry = join(sourceDir, packageJson.bin);
|
19
|
+
entrypoints.set("__bin__", binEntry);
|
20
|
+
}
|
21
|
+
const viteConfig = defineConfig({
|
22
|
+
publicDir: false,
|
23
|
+
build: {
|
24
|
+
outDir,
|
25
|
+
write: true,
|
26
|
+
minify: false,
|
27
|
+
emptyOutDir: true,
|
28
|
+
assetsInlineLimit: 0,
|
29
|
+
terserOptions: {
|
30
|
+
compress: false,
|
31
|
+
mangle: false
|
32
|
+
},
|
33
|
+
lib: {
|
34
|
+
entry: mapToObject(entrypoints),
|
35
|
+
formats: ["es", "cjs"],
|
36
|
+
fileName: (format, entryName) => {
|
37
|
+
const entrypoint = entrypoints.get(entryName);
|
38
|
+
if (!entrypoint) {
|
39
|
+
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
40
|
+
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".js" : ".cjs");
|
41
|
+
}
|
42
|
+
const relativePath = relative(sourceDir, entrypoint);
|
43
|
+
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
44
|
+
if (format === "es") {
|
45
|
+
return `${noExt}.js`;
|
46
|
+
}
|
47
|
+
if (format === "cjs") {
|
48
|
+
return `${noExt}.cjs`;
|
49
|
+
}
|
50
|
+
return noExt;
|
51
|
+
}
|
52
|
+
},
|
53
|
+
rollupOptions: {
|
54
|
+
external: (id, parentId, isResolved) => {
|
55
|
+
if (id === packageJson.name) {
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
if (id.startsWith("node:")) {
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
if (id in (packageJson.dependencies ?? {})) {
|
62
|
+
return true;
|
63
|
+
}
|
64
|
+
if (id in (packageJson.optionalDependencies ?? {})) {
|
65
|
+
return true;
|
66
|
+
}
|
67
|
+
return false;
|
68
|
+
},
|
69
|
+
output: {
|
70
|
+
exports: "named",
|
71
|
+
preserveModules: true
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
});
|
76
|
+
return { viteConfig, entrypoints };
|
77
|
+
}
|
78
|
+
export {
|
79
|
+
createViteConfig
|
80
|
+
};
|
@@ -30,12 +30,8 @@ const errors = require("./errors.cjs");
|
|
30
30
|
const buildTypes = require("./buildTypes.cjs");
|
31
31
|
const buildVite = require("./buildVite.cjs");
|
32
32
|
const copyStaticFiles = require("./copyStaticFiles.cjs");
|
33
|
-
|
34
|
-
|
35
|
-
return path2;
|
36
|
-
}
|
37
|
-
return path.join(path1, path2);
|
38
|
-
}
|
33
|
+
const resolveDirs = require("./resolveDirs.cjs");
|
34
|
+
const createViteConfig = require("./createViteConfig.cjs");
|
39
35
|
function reverseMap(map) {
|
40
36
|
const reversed = /* @__PURE__ */ new Map();
|
41
37
|
for (const [key, value] of map) {
|
@@ -50,12 +46,8 @@ function setExports(exportsMap, exportName, mapFn) {
|
|
50
46
|
exportsMap.set(exportName, mapFn(entry));
|
51
47
|
}
|
52
48
|
async function run(args) {
|
53
|
-
const
|
54
|
-
const packagePath =
|
55
|
-
sourceDir,
|
56
|
-
args.packagePath ?? "./package.json"
|
57
|
-
);
|
58
|
-
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
49
|
+
const dirs = resolveDirs.resolveDirs(args);
|
50
|
+
const { sourceDir, outDir, packagePath } = dirs;
|
59
51
|
await fs.rm(outDir, { recursive: true, force: true });
|
60
52
|
await fs.mkdir(outDir, { recursive: true });
|
61
53
|
const packageJson$1 = await packageJson.parsePackageJson({ sourceDir, packagePath });
|
@@ -63,21 +55,8 @@ async function run(args) {
|
|
63
55
|
console.log(packageJson$1);
|
64
56
|
return { error: true, errors: packageJson$1 };
|
65
57
|
}
|
66
|
-
const entrypoints =
|
67
|
-
|
68
|
-
const mainEntry = path.join(sourceDir, packageJson$1.exports);
|
69
|
-
entrypoints.set(".", mainEntry);
|
70
|
-
}
|
71
|
-
if (packageJson$1.bin) {
|
72
|
-
const binEntry = path.join(sourceDir, packageJson$1.bin);
|
73
|
-
entrypoints.set("__bin__", binEntry);
|
74
|
-
}
|
75
|
-
const outputs = await buildVite.buildVite({
|
76
|
-
entrypoints,
|
77
|
-
packageJson: packageJson$1,
|
78
|
-
sourceDir,
|
79
|
-
outDir
|
80
|
-
});
|
58
|
+
const { viteConfig, entrypoints } = createViteConfig.createViteConfig({ dirs, packageJson: packageJson$1 });
|
59
|
+
const outputs = await buildVite.buildVite({ viteConfig });
|
81
60
|
if (outputs.error) {
|
82
61
|
return { error: true, errors: outputs.errors };
|
83
62
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { relative } from "node:path";
|
2
2
|
import { rm, mkdir } from "node:fs/promises";
|
3
3
|
import { parsePackageJson } from "./packageJson.js";
|
4
4
|
import { writePackageJson } from "./writePackageJson.js";
|
@@ -6,12 +6,8 @@ import { errors } from "./errors.js";
|
|
6
6
|
import { buildTypes } from "./buildTypes.js";
|
7
7
|
import { buildVite } from "./buildVite.js";
|
8
8
|
import { copyStaticFiles } from "./copyStaticFiles.js";
|
9
|
-
|
10
|
-
|
11
|
-
return path2;
|
12
|
-
}
|
13
|
-
return join(path1, path2);
|
14
|
-
}
|
9
|
+
import { resolveDirs } from "./resolveDirs.js";
|
10
|
+
import { createViteConfig } from "./createViteConfig.js";
|
15
11
|
function reverseMap(map) {
|
16
12
|
const reversed = /* @__PURE__ */ new Map();
|
17
13
|
for (const [key, value] of map) {
|
@@ -26,12 +22,8 @@ function setExports(exportsMap, exportName, mapFn) {
|
|
26
22
|
exportsMap.set(exportName, mapFn(entry));
|
27
23
|
}
|
28
24
|
async function run(args) {
|
29
|
-
const
|
30
|
-
const packagePath =
|
31
|
-
sourceDir,
|
32
|
-
args.packagePath ?? "./package.json"
|
33
|
-
);
|
34
|
-
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
25
|
+
const dirs = resolveDirs(args);
|
26
|
+
const { sourceDir, outDir, packagePath } = dirs;
|
35
27
|
await rm(outDir, { recursive: true, force: true });
|
36
28
|
await mkdir(outDir, { recursive: true });
|
37
29
|
const packageJson = await parsePackageJson({ sourceDir, packagePath });
|
@@ -39,21 +31,8 @@ async function run(args) {
|
|
39
31
|
console.log(packageJson);
|
40
32
|
return { error: true, errors: packageJson };
|
41
33
|
}
|
42
|
-
const entrypoints =
|
43
|
-
|
44
|
-
const mainEntry = join(sourceDir, packageJson.exports);
|
45
|
-
entrypoints.set(".", mainEntry);
|
46
|
-
}
|
47
|
-
if (packageJson.bin) {
|
48
|
-
const binEntry = join(sourceDir, packageJson.bin);
|
49
|
-
entrypoints.set("__bin__", binEntry);
|
50
|
-
}
|
51
|
-
const outputs = await buildVite({
|
52
|
-
entrypoints,
|
53
|
-
packageJson,
|
54
|
-
sourceDir,
|
55
|
-
outDir
|
56
|
-
});
|
34
|
+
const { viteConfig, entrypoints } = createViteConfig({ dirs, packageJson });
|
35
|
+
const outputs = await buildVite({ viteConfig });
|
57
36
|
if (outputs.error) {
|
58
37
|
return { error: true, errors: outputs.errors };
|
59
38
|
}
|
@@ -48,29 +48,17 @@ function createPackageJsonSchema(sourceDir) {
|
|
48
48
|
dependencies: dependencies(errors.errors.dependenciesInvalid),
|
49
49
|
optionalDependencies: dependencies(errors.errors.optionalDependenciesInvalid),
|
50
50
|
bin: z.string({ message: errors.errors.binString }).optional(),
|
51
|
-
repository: z.
|
52
|
-
z.string({ message: errors.errors.repositoryInvalid }),
|
53
|
-
z.object({
|
54
|
-
type: z.string(),
|
55
|
-
url: z.string()
|
56
|
-
}, { message: errors.errors.repositoryInvalid })
|
57
|
-
]).optional(),
|
51
|
+
repository: z.any().optional(),
|
58
52
|
keywords: z.array(z.string(), { message: errors.errors.keywordsInvalid }).optional(),
|
59
|
-
author: z.
|
60
|
-
|
61
|
-
z.object({
|
62
|
-
name: z.string({ message: errors.errors.authorInvalid }).optional(),
|
63
|
-
email: z.string({ message: errors.errors.authorInvalid }).optional(),
|
64
|
-
url: z.string({ message: errors.errors.authorInvalid }).optional()
|
65
|
-
}, { message: errors.errors.authorInvalid })
|
66
|
-
]).optional(),
|
53
|
+
author: z.any().optional(),
|
54
|
+
maintainers: z.any().optional(),
|
67
55
|
contributors: z.array(
|
68
56
|
z.union([
|
69
57
|
z.string({ message: errors.errors.contributorsInvalid }),
|
70
58
|
z.object({}, { message: errors.errors.contributorsInvalid })
|
71
59
|
])
|
72
60
|
).optional(),
|
73
|
-
license: z.
|
61
|
+
license: z.any().optional(),
|
74
62
|
devDependencies: dependencies(errors.errors.devDependenciesInvalid),
|
75
63
|
peerDependencies: dependencies(errors.errors.peerDependenciesInvalid),
|
76
64
|
engines: z.record(z.string(), { message: errors.errors.enginesInvalid }).optional(),
|
@@ -78,12 +66,16 @@ function createPackageJsonSchema(sourceDir) {
|
|
78
66
|
z.string({ message: errors.errors.browserInvalid }),
|
79
67
|
z.record(z.string(), { message: errors.errors.browserInvalid })
|
80
68
|
]).optional(),
|
69
|
+
bugs: z.any().optional(),
|
81
70
|
funding: z.union([
|
82
71
|
z.string({ message: errors.errors.fundingInvalid }),
|
83
72
|
z.object({}, { message: errors.errors.fundingInvalid })
|
84
73
|
]).optional(),
|
85
74
|
os: z.array(z.string(), { message: errors.errors.osInvalid }).optional(),
|
86
|
-
cpu: z.array(z.string(), { message: errors.errors.cpuInvalid }).optional()
|
75
|
+
cpu: z.array(z.string(), { message: errors.errors.cpuInvalid }).optional(),
|
76
|
+
sideEffects: z.any().optional(),
|
77
|
+
unpkg: z.any().optional(),
|
78
|
+
homepage: z.any().optional()
|
87
79
|
});
|
88
80
|
}
|
89
81
|
async function parsePackageJson({
|
@@ -29,29 +29,17 @@ function createPackageJsonSchema(sourceDir) {
|
|
29
29
|
dependencies: dependencies(errors.dependenciesInvalid),
|
30
30
|
optionalDependencies: dependencies(errors.optionalDependenciesInvalid),
|
31
31
|
bin: z.string({ message: errors.binString }).optional(),
|
32
|
-
repository: z.
|
33
|
-
z.string({ message: errors.repositoryInvalid }),
|
34
|
-
z.object({
|
35
|
-
type: z.string(),
|
36
|
-
url: z.string()
|
37
|
-
}, { message: errors.repositoryInvalid })
|
38
|
-
]).optional(),
|
32
|
+
repository: z.any().optional(),
|
39
33
|
keywords: z.array(z.string(), { message: errors.keywordsInvalid }).optional(),
|
40
|
-
author: z.
|
41
|
-
|
42
|
-
z.object({
|
43
|
-
name: z.string({ message: errors.authorInvalid }).optional(),
|
44
|
-
email: z.string({ message: errors.authorInvalid }).optional(),
|
45
|
-
url: z.string({ message: errors.authorInvalid }).optional()
|
46
|
-
}, { message: errors.authorInvalid })
|
47
|
-
]).optional(),
|
34
|
+
author: z.any().optional(),
|
35
|
+
maintainers: z.any().optional(),
|
48
36
|
contributors: z.array(
|
49
37
|
z.union([
|
50
38
|
z.string({ message: errors.contributorsInvalid }),
|
51
39
|
z.object({}, { message: errors.contributorsInvalid })
|
52
40
|
])
|
53
41
|
).optional(),
|
54
|
-
license: z.
|
42
|
+
license: z.any().optional(),
|
55
43
|
devDependencies: dependencies(errors.devDependenciesInvalid),
|
56
44
|
peerDependencies: dependencies(errors.peerDependenciesInvalid),
|
57
45
|
engines: z.record(z.string(), { message: errors.enginesInvalid }).optional(),
|
@@ -59,12 +47,16 @@ function createPackageJsonSchema(sourceDir) {
|
|
59
47
|
z.string({ message: errors.browserInvalid }),
|
60
48
|
z.record(z.string(), { message: errors.browserInvalid })
|
61
49
|
]).optional(),
|
50
|
+
bugs: z.any().optional(),
|
62
51
|
funding: z.union([
|
63
52
|
z.string({ message: errors.fundingInvalid }),
|
64
53
|
z.object({}, { message: errors.fundingInvalid })
|
65
54
|
]).optional(),
|
66
55
|
os: z.array(z.string(), { message: errors.osInvalid }).optional(),
|
67
|
-
cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional()
|
56
|
+
cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),
|
57
|
+
sideEffects: z.any().optional(),
|
58
|
+
unpkg: z.any().optional(),
|
59
|
+
homepage: z.any().optional()
|
68
60
|
});
|
69
61
|
}
|
70
62
|
async function parsePackageJson({
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const path = require("node:path");
|
4
|
+
function myResolve(path1, path2) {
|
5
|
+
if (path.isAbsolute(path2)) {
|
6
|
+
return path2;
|
7
|
+
}
|
8
|
+
return path.join(path1, path2);
|
9
|
+
}
|
10
|
+
function resolveDirs(args) {
|
11
|
+
const sourceDir = myResolve(process.cwd(), args.sourceDir ?? ".");
|
12
|
+
const packagePath = myResolve(
|
13
|
+
sourceDir,
|
14
|
+
args.packagePath ?? "./package.json"
|
15
|
+
);
|
16
|
+
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
17
|
+
return { sourceDir, packagePath, outDir };
|
18
|
+
}
|
19
|
+
exports.resolveDirs = resolveDirs;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
2
|
+
function myResolve(path1, path2) {
|
3
|
+
if (isAbsolute(path2)) {
|
4
|
+
return path2;
|
5
|
+
}
|
6
|
+
return join(path1, path2);
|
7
|
+
}
|
8
|
+
function resolveDirs(args) {
|
9
|
+
const sourceDir = myResolve(process.cwd(), args.sourceDir ?? ".");
|
10
|
+
const packagePath = myResolve(
|
11
|
+
sourceDir,
|
12
|
+
args.packagePath ?? "./package.json"
|
13
|
+
);
|
14
|
+
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
15
|
+
return { sourceDir, packagePath, outDir };
|
16
|
+
}
|
17
|
+
export {
|
18
|
+
resolveDirs
|
19
|
+
};
|
@@ -53,7 +53,12 @@ async function writePackageJson(outDir, parsed, { exportsMap }) {
|
|
53
53
|
browser: parsed.browser,
|
54
54
|
funding: parsed.funding,
|
55
55
|
os: parsed.os,
|
56
|
-
cpu: parsed.cpu
|
56
|
+
cpu: parsed.cpu,
|
57
|
+
maintainers: parsed.maintainers,
|
58
|
+
bugs: parsed.bugs,
|
59
|
+
sideEffects: parsed.sideEffects,
|
60
|
+
unpkg: parsed.unpkg,
|
61
|
+
homepage: parsed.homepage
|
57
62
|
};
|
58
63
|
await fs.writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));
|
59
64
|
}
|
@@ -51,7 +51,12 @@ async function writePackageJson(outDir, parsed, { exportsMap }) {
|
|
51
51
|
browser: parsed.browser,
|
52
52
|
funding: parsed.funding,
|
53
53
|
os: parsed.os,
|
54
|
-
cpu: parsed.cpu
|
54
|
+
cpu: parsed.cpu,
|
55
|
+
maintainers: parsed.maintainers,
|
56
|
+
bugs: parsed.bugs,
|
57
|
+
sideEffects: parsed.sideEffects,
|
58
|
+
unpkg: parsed.unpkg,
|
59
|
+
homepage: parsed.homepage
|
55
60
|
};
|
56
61
|
await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));
|
57
62
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "smartbundle",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.5.0",
|
5
5
|
"bin": "./src/bin.js",
|
6
6
|
"types": "./src/run.d.ts",
|
7
7
|
"module": "./src/run.js",
|
@@ -54,5 +54,9 @@
|
|
54
54
|
"typescript": "^5.5.3",
|
55
55
|
"vitest": "^2.0.4",
|
56
56
|
"vitest-directory-snapshot": "^0.2.2"
|
57
|
-
}
|
57
|
+
},
|
58
|
+
"bugs": {
|
59
|
+
"url": "https://github.com/xavescor/smartbundle/issues"
|
60
|
+
},
|
61
|
+
"homepage": "https://github.com/xavescor/smartbundle"
|
58
62
|
}
|
package/src/buildVite.d.ts
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { UserConfig } from "vite";
|
2
2
|
import { Rollup } from "vite";
|
3
3
|
type BuildViteOptions = {
|
4
|
-
|
5
|
-
packageJson: PackageJson;
|
6
|
-
entrypoints: Map<string, string>;
|
7
|
-
outDir: string;
|
4
|
+
viteConfig: UserConfig;
|
8
5
|
};
|
9
6
|
type BuildSuccess = {
|
10
7
|
error: false;
|
@@ -15,5 +12,5 @@ type BuildError = {
|
|
15
12
|
errors: Array<string>;
|
16
13
|
};
|
17
14
|
type BuildResult = BuildSuccess | BuildError;
|
18
|
-
export declare function buildVite({
|
15
|
+
export declare function buildVite({ viteConfig, }: BuildViteOptions): Promise<BuildResult>;
|
19
16
|
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type Dirs } from "./resolveDirs.js";
|
2
|
+
import { type PackageJson } from "./packageJson.js";
|
3
|
+
type CreateViteConfigParam = {
|
4
|
+
dirs: Dirs;
|
5
|
+
packageJson: PackageJson;
|
6
|
+
};
|
7
|
+
export declare function createViteConfig({ dirs, packageJson }: CreateViteConfigParam): {
|
8
|
+
viteConfig: import("vite").UserConfig;
|
9
|
+
entrypoints: Map<string, string>;
|
10
|
+
};
|
11
|
+
export {};
|
package/src/index.d.ts
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
type Args
|
2
|
-
|
3
|
-
packagePath?: string;
|
4
|
-
outputDir?: string;
|
5
|
-
};
|
1
|
+
import { type Args } from "./resolveDirs.js";
|
2
|
+
export declare function defineViteConfig(args?: Args): Promise<import("vite").UserConfig>;
|
6
3
|
export declare function run(args: Args): Promise<{
|
7
4
|
error: boolean;
|
8
5
|
errors: string[];
|
@@ -10,4 +7,3 @@ export declare function run(args: Args): Promise<{
|
|
10
7
|
error: boolean;
|
11
8
|
errors?: undefined;
|
12
9
|
}>;
|
13
|
-
export {};
|
package/src/packageJson.d.ts
CHANGED
@@ -8,39 +8,23 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
8
8
|
dependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
9
9
|
optionalDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
10
10
|
bin: z.ZodOptional<z.ZodString>;
|
11
|
-
repository: z.ZodOptional<z.
|
12
|
-
type: z.ZodString;
|
13
|
-
url: z.ZodString;
|
14
|
-
}, "strip", z.ZodTypeAny, {
|
15
|
-
type?: string;
|
16
|
-
url?: string;
|
17
|
-
}, {
|
18
|
-
type?: string;
|
19
|
-
url?: string;
|
20
|
-
}>]>>;
|
11
|
+
repository: z.ZodOptional<z.ZodAny>;
|
21
12
|
keywords: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
22
|
-
author: z.ZodOptional<z.
|
23
|
-
|
24
|
-
email: z.ZodOptional<z.ZodString>;
|
25
|
-
url: z.ZodOptional<z.ZodString>;
|
26
|
-
}, "strip", z.ZodTypeAny, {
|
27
|
-
name?: string;
|
28
|
-
url?: string;
|
29
|
-
email?: string;
|
30
|
-
}, {
|
31
|
-
name?: string;
|
32
|
-
url?: string;
|
33
|
-
email?: string;
|
34
|
-
}>]>>;
|
13
|
+
author: z.ZodOptional<z.ZodAny>;
|
14
|
+
maintainers: z.ZodOptional<z.ZodAny>;
|
35
15
|
contributors: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>, "many">>;
|
36
|
-
license: z.ZodOptional<z.
|
16
|
+
license: z.ZodOptional<z.ZodAny>;
|
37
17
|
devDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
38
18
|
peerDependencies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
39
19
|
engines: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
40
20
|
browser: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
21
|
+
bugs: z.ZodOptional<z.ZodAny>;
|
41
22
|
funding: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>]>>;
|
42
23
|
os: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
43
24
|
cpu: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
25
|
+
sideEffects: z.ZodOptional<z.ZodAny>;
|
26
|
+
unpkg: z.ZodOptional<z.ZodAny>;
|
27
|
+
homepage: z.ZodOptional<z.ZodAny>;
|
44
28
|
}, "strip", z.ZodTypeAny, {
|
45
29
|
exports?: string;
|
46
30
|
name?: string;
|
@@ -50,18 +34,11 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
50
34
|
dependencies?: Record<string, string>;
|
51
35
|
optionalDependencies?: Record<string, string>;
|
52
36
|
bin?: string;
|
53
|
-
repository?:
|
54
|
-
type?: string;
|
55
|
-
url?: string;
|
56
|
-
};
|
37
|
+
repository?: any;
|
57
38
|
keywords?: string[];
|
58
|
-
author?:
|
59
|
-
name?: string;
|
60
|
-
url?: string;
|
61
|
-
email?: string;
|
62
|
-
};
|
39
|
+
author?: any;
|
63
40
|
contributors?: (string | {})[];
|
64
|
-
license?:
|
41
|
+
license?: any;
|
65
42
|
devDependencies?: Record<string, string>;
|
66
43
|
peerDependencies?: Record<string, string>;
|
67
44
|
engines?: Record<string, string>;
|
@@ -69,6 +46,11 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
69
46
|
funding?: string | {};
|
70
47
|
os?: string[];
|
71
48
|
cpu?: string[];
|
49
|
+
maintainers?: any;
|
50
|
+
bugs?: any;
|
51
|
+
sideEffects?: any;
|
52
|
+
unpkg?: any;
|
53
|
+
homepage?: any;
|
72
54
|
}, {
|
73
55
|
exports?: string;
|
74
56
|
name?: string;
|
@@ -78,18 +60,11 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
78
60
|
dependencies?: Record<string, string>;
|
79
61
|
optionalDependencies?: Record<string, string>;
|
80
62
|
bin?: string;
|
81
|
-
repository?:
|
82
|
-
type?: string;
|
83
|
-
url?: string;
|
84
|
-
};
|
63
|
+
repository?: any;
|
85
64
|
keywords?: string[];
|
86
|
-
author?:
|
87
|
-
name?: string;
|
88
|
-
url?: string;
|
89
|
-
email?: string;
|
90
|
-
};
|
65
|
+
author?: any;
|
91
66
|
contributors?: (string | {})[];
|
92
|
-
license?:
|
67
|
+
license?: any;
|
93
68
|
devDependencies?: Record<string, string>;
|
94
69
|
peerDependencies?: Record<string, string>;
|
95
70
|
engines?: Record<string, string>;
|
@@ -97,6 +72,11 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
97
72
|
funding?: string | {};
|
98
73
|
os?: string[];
|
99
74
|
cpu?: string[];
|
75
|
+
maintainers?: any;
|
76
|
+
bugs?: any;
|
77
|
+
sideEffects?: any;
|
78
|
+
unpkg?: any;
|
79
|
+
homepage?: any;
|
100
80
|
}>;
|
101
81
|
type PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;
|
102
82
|
export type PackageJson = z.infer<PackageJsonSchema>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export type Args = {
|
2
|
+
sourceDir?: string;
|
3
|
+
packagePath?: string;
|
4
|
+
outputDir?: string;
|
5
|
+
};
|
6
|
+
export declare function resolveDirs(args: Args): {
|
7
|
+
sourceDir: string;
|
8
|
+
packagePath: string;
|
9
|
+
outDir: string;
|
10
|
+
};
|
11
|
+
export type Dirs = ReturnType<typeof resolveDirs>;
|