smartbundle 0.5.4 → 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 +17 -8
- package/__do_not_import_directly__/createViteConfig.js +17 -8
- 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 +2 -2
- package/__do_not_import_directly__/errors.js +2 -2
- package/__do_not_import_directly__/packageJson.cjs +56 -4
- package/__do_not_import_directly__/packageJson.js +56 -4
- 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 +6 -6
- 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
package/README.md
CHANGED
@@ -19,6 +19,12 @@ npx smartbundle
|
|
19
19
|
```
|
20
20
|
3) Go to the `dist` folder and publish your package to the npm registry. The total package.json will be generated automatically.
|
21
21
|
|
22
|
+
## Supported targets
|
23
|
+
- Bun 1+
|
24
|
+
- Node ^18.0.0, ^20.0.0, ^22.0.0, ^23.0.0
|
25
|
+
- Webpack ^4.47.0, ^5.95.0
|
26
|
+
- Rspack ^1.0.0
|
27
|
+
|
22
28
|
## Features
|
23
29
|
- generate the most compatible package.json for any bundlers(webpack, rollup, esbuild, vite, etc) or runtimes(node, bun, deno, etc)
|
24
30
|
- validate package.json for common errors
|
@@ -38,4 +44,4 @@ Almost every npm package have the same build pipeline: build code, generate type
|
|
38
44
|
|
39
45
|
I really like the [microbundle](https://github.com/developit/microbundle) project, but it requires a lot of extra configuration and is not zero-config. And more, the project is not maintained and does not support a lot of modern js features.
|
40
46
|
|
41
|
-
So I decided to create my own project to automate the build pipeline and save the developer's time for building packages.
|
47
|
+
So I decided to create my own project to automate the build pipeline and save the developer's time for building packages.
|
@@ -1,12 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const path = require("node:path");
|
4
|
+
require("node:fs/promises");
|
5
|
+
require("zod");
|
4
6
|
const vite = require("vite");
|
5
|
-
function mapToObject(map) {
|
7
|
+
function mapToObject(map, bins) {
|
6
8
|
const obj = {};
|
7
9
|
for (const [key, value] of map) {
|
8
10
|
obj[key] = value;
|
9
11
|
}
|
12
|
+
for (const [key, value] of bins) {
|
13
|
+
obj[key] = value;
|
14
|
+
}
|
10
15
|
return obj;
|
11
16
|
}
|
12
17
|
function createExternalDepValidator(packageJson) {
|
@@ -41,12 +46,16 @@ function createViteConfig({ dirs, packageJson }) {
|
|
41
46
|
const { sourceDir, outDir } = dirs;
|
42
47
|
const entrypoints = /* @__PURE__ */ new Map();
|
43
48
|
if (packageJson.exports) {
|
44
|
-
const
|
45
|
-
|
49
|
+
for (const [key, value] of packageJson.exports) {
|
50
|
+
const entry = path.join(sourceDir, value);
|
51
|
+
entrypoints.set(key, entry);
|
52
|
+
}
|
46
53
|
}
|
54
|
+
const bins = /* @__PURE__ */ new Map();
|
47
55
|
if (packageJson.bin) {
|
48
|
-
const
|
49
|
-
|
56
|
+
for (const [key, value] of packageJson.bin) {
|
57
|
+
bins.set(key, path.join(sourceDir, value));
|
58
|
+
}
|
50
59
|
}
|
51
60
|
const depsValidator = createExternalDepValidator(packageJson);
|
52
61
|
const viteConfig = vite.defineConfig({
|
@@ -55,14 +64,14 @@ function createViteConfig({ dirs, packageJson }) {
|
|
55
64
|
outDir,
|
56
65
|
write: true,
|
57
66
|
minify: false,
|
58
|
-
emptyOutDir:
|
67
|
+
emptyOutDir: false,
|
59
68
|
assetsInlineLimit: 0,
|
60
69
|
terserOptions: {
|
61
70
|
compress: false,
|
62
71
|
mangle: false
|
63
72
|
},
|
64
73
|
lib: {
|
65
|
-
entry: mapToObject(entrypoints),
|
74
|
+
entry: mapToObject(entrypoints, bins),
|
66
75
|
formats: ["es", "cjs"],
|
67
76
|
fileName: (format, entryName) => {
|
68
77
|
const entrypoint = entrypoints.get(entryName);
|
@@ -90,6 +99,6 @@ function createViteConfig({ dirs, packageJson }) {
|
|
90
99
|
}
|
91
100
|
}
|
92
101
|
});
|
93
|
-
return { viteConfig, entrypoints };
|
102
|
+
return { viteConfig, entrypoints, bins };
|
94
103
|
}
|
95
104
|
exports.createViteConfig = createViteConfig;
|
@@ -1,10 +1,15 @@
|
|
1
1
|
import { join, relative } from "node:path";
|
2
|
+
import "node:fs/promises";
|
3
|
+
import "zod";
|
2
4
|
import { defineConfig } from "vite";
|
3
|
-
function mapToObject(map) {
|
5
|
+
function mapToObject(map, bins) {
|
4
6
|
const obj = {};
|
5
7
|
for (const [key, value] of map) {
|
6
8
|
obj[key] = value;
|
7
9
|
}
|
10
|
+
for (const [key, value] of bins) {
|
11
|
+
obj[key] = value;
|
12
|
+
}
|
8
13
|
return obj;
|
9
14
|
}
|
10
15
|
function createExternalDepValidator(packageJson) {
|
@@ -39,12 +44,16 @@ function createViteConfig({ dirs, packageJson }) {
|
|
39
44
|
const { sourceDir, outDir } = dirs;
|
40
45
|
const entrypoints = /* @__PURE__ */ new Map();
|
41
46
|
if (packageJson.exports) {
|
42
|
-
const
|
43
|
-
|
47
|
+
for (const [key, value] of packageJson.exports) {
|
48
|
+
const entry = join(sourceDir, value);
|
49
|
+
entrypoints.set(key, entry);
|
50
|
+
}
|
44
51
|
}
|
52
|
+
const bins = /* @__PURE__ */ new Map();
|
45
53
|
if (packageJson.bin) {
|
46
|
-
const
|
47
|
-
|
54
|
+
for (const [key, value] of packageJson.bin) {
|
55
|
+
bins.set(key, join(sourceDir, value));
|
56
|
+
}
|
48
57
|
}
|
49
58
|
const depsValidator = createExternalDepValidator(packageJson);
|
50
59
|
const viteConfig = defineConfig({
|
@@ -53,14 +62,14 @@ function createViteConfig({ dirs, packageJson }) {
|
|
53
62
|
outDir,
|
54
63
|
write: true,
|
55
64
|
minify: false,
|
56
|
-
emptyOutDir:
|
65
|
+
emptyOutDir: false,
|
57
66
|
assetsInlineLimit: 0,
|
58
67
|
terserOptions: {
|
59
68
|
compress: false,
|
60
69
|
mangle: false
|
61
70
|
},
|
62
71
|
lib: {
|
63
|
-
entry: mapToObject(entrypoints),
|
72
|
+
entry: mapToObject(entrypoints, bins),
|
64
73
|
formats: ["es", "cjs"],
|
65
74
|
fileName: (format, entryName) => {
|
66
75
|
const entrypoint = entrypoints.get(entryName);
|
@@ -88,7 +97,7 @@ function createViteConfig({ dirs, packageJson }) {
|
|
88
97
|
}
|
89
98
|
}
|
90
99
|
});
|
91
|
-
return { viteConfig, entrypoints };
|
100
|
+
return { viteConfig, entrypoints, bins };
|
92
101
|
}
|
93
102
|
export {
|
94
103
|
createViteConfig
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const errors = {
|
4
|
-
exportsRequired: "The `exports` field is string
|
4
|
+
exportsRequired: "The `exports` field is string or Record<string, string>. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points",
|
5
5
|
exportsInvalid: "The `exports` field must be a path to entrypoint. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points",
|
6
6
|
nameRequired: "The `name` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name",
|
7
7
|
nameMinLength: 'Min length of "name" is 1 character. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',
|
@@ -11,7 +11,7 @@ const errors = {
|
|
11
11
|
privateIsTrue: "The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private",
|
12
12
|
descriptionString: "The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description",
|
13
13
|
dependenciesInvalid: "The `dependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies",
|
14
|
-
|
14
|
+
binFiled: "The `bin` field must be a path or Record<string, FilePath>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
|
15
15
|
rollupError: "An error occurred while building the package. Please, report it to the issues on GitHub",
|
16
16
|
typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
|
17
17
|
optionalDependenciesInvalid: "The `optionalDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const errors = {
|
2
|
-
exportsRequired: "The `exports` field is string
|
2
|
+
exportsRequired: "The `exports` field is string or Record<string, string>. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points",
|
3
3
|
exportsInvalid: "The `exports` field must be a path to entrypoint. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points",
|
4
4
|
nameRequired: "The `name` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name",
|
5
5
|
nameMinLength: 'Min length of "name" is 1 character. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',
|
@@ -9,7 +9,7 @@ const errors = {
|
|
9
9
|
privateIsTrue: "The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private",
|
10
10
|
descriptionString: "The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description",
|
11
11
|
dependenciesInvalid: "The `dependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies",
|
12
|
-
|
12
|
+
binFiled: "The `bin` field must be a path or Record<string, FilePath>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
|
13
13
|
rollupError: "An error occurred while building the package. Please, report it to the issues on GitHub",
|
14
14
|
typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
|
15
15
|
optionalDependenciesInvalid: "The `optionalDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies",
|
@@ -32,11 +32,42 @@ async function fileExists(filePath) {
|
|
32
32
|
function dependencies(errorText) {
|
33
33
|
return z.record(z.string({ message: errorText }), { message: errorText }).optional();
|
34
34
|
}
|
35
|
+
function createPathValidator(sourceDir) {
|
36
|
+
return (path$1) => {
|
37
|
+
const finalPath = path.join(sourceDir, path$1);
|
38
|
+
return fileExists(finalPath);
|
39
|
+
};
|
40
|
+
}
|
41
|
+
const PackageJsonNameField = "___NAME___";
|
42
|
+
function fillPackageJson(packageJson) {
|
43
|
+
if (packageJson.bin) {
|
44
|
+
const binName = packageJson.bin.get(PackageJsonNameField);
|
45
|
+
if (binName) {
|
46
|
+
packageJson.bin.set(packageJson.name, binName);
|
47
|
+
packageJson.bin.delete(PackageJsonNameField);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
35
51
|
function createPackageJsonSchema(sourceDir) {
|
52
|
+
const pathValidator = createPathValidator(sourceDir);
|
36
53
|
return z.object({
|
37
|
-
exports: z.
|
38
|
-
|
39
|
-
|
54
|
+
exports: z.union(
|
55
|
+
[
|
56
|
+
z.string().transform((path2) => /* @__PURE__ */ new Map([[".", path2]])),
|
57
|
+
z.record(z.string()).transform((obj) => new Map(Object.entries(obj)))
|
58
|
+
],
|
59
|
+
{
|
60
|
+
errorMap() {
|
61
|
+
return { message: errors.errors.exportsRequired };
|
62
|
+
}
|
63
|
+
}
|
64
|
+
).refine(async (obj) => {
|
65
|
+
for (const [key, value] of obj.entries()) {
|
66
|
+
if (!await pathValidator(value)) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return true;
|
40
71
|
}, errors.errors.exportsInvalid).optional(),
|
41
72
|
name: z.string({ message: errors.errors.nameRequired }).min(1, errors.errors.nameMinLength).max(214, errors.errors.nameMaxLength).refine(
|
42
73
|
(name) => ["_", "."].every((start) => !name.startsWith(start)),
|
@@ -47,7 +78,27 @@ function createPackageJsonSchema(sourceDir) {
|
|
47
78
|
description: z.string({ message: errors.errors.descriptionString }).optional(),
|
48
79
|
dependencies: dependencies(errors.errors.dependenciesInvalid),
|
49
80
|
optionalDependencies: dependencies(errors.errors.optionalDependenciesInvalid),
|
50
|
-
bin: z.
|
81
|
+
bin: z.union(
|
82
|
+
[
|
83
|
+
z.string().transform((value) => /* @__PURE__ */ new Map([[PackageJsonNameField, value]])),
|
84
|
+
z.record(z.string()).transform((record) => new Map(Object.entries(record)))
|
85
|
+
],
|
86
|
+
{
|
87
|
+
errorMap() {
|
88
|
+
return { message: errors.errors.binFiled };
|
89
|
+
}
|
90
|
+
}
|
91
|
+
).refine(
|
92
|
+
async (map) => {
|
93
|
+
for (const [key, value] of map.entries()) {
|
94
|
+
if (!await pathValidator(value)) {
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
return true;
|
99
|
+
},
|
100
|
+
{ message: errors.errors.binFiled }
|
101
|
+
).optional(),
|
51
102
|
repository: z.any().optional(),
|
52
103
|
keywords: z.array(z.string(), { message: errors.errors.keywordsInvalid }).optional(),
|
53
104
|
author: z.any().optional(),
|
@@ -89,6 +140,7 @@ async function parsePackageJson({
|
|
89
140
|
if (!packageJson.success) {
|
90
141
|
return packageJson.error.errors.map((error) => error.message);
|
91
142
|
}
|
143
|
+
fillPackageJson(packageJson.data);
|
92
144
|
return packageJson.data;
|
93
145
|
}
|
94
146
|
exports.parsePackageJson = parsePackageJson;
|
@@ -13,11 +13,42 @@ async function fileExists(filePath) {
|
|
13
13
|
function dependencies(errorText) {
|
14
14
|
return z.record(z.string({ message: errorText }), { message: errorText }).optional();
|
15
15
|
}
|
16
|
+
function createPathValidator(sourceDir) {
|
17
|
+
return (path) => {
|
18
|
+
const finalPath = join(sourceDir, path);
|
19
|
+
return fileExists(finalPath);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
const PackageJsonNameField = "___NAME___";
|
23
|
+
function fillPackageJson(packageJson) {
|
24
|
+
if (packageJson.bin) {
|
25
|
+
const binName = packageJson.bin.get(PackageJsonNameField);
|
26
|
+
if (binName) {
|
27
|
+
packageJson.bin.set(packageJson.name, binName);
|
28
|
+
packageJson.bin.delete(PackageJsonNameField);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
16
32
|
function createPackageJsonSchema(sourceDir) {
|
33
|
+
const pathValidator = createPathValidator(sourceDir);
|
17
34
|
return z.object({
|
18
|
-
exports: z.
|
19
|
-
|
20
|
-
|
35
|
+
exports: z.union(
|
36
|
+
[
|
37
|
+
z.string().transform((path) => /* @__PURE__ */ new Map([[".", path]])),
|
38
|
+
z.record(z.string()).transform((obj) => new Map(Object.entries(obj)))
|
39
|
+
],
|
40
|
+
{
|
41
|
+
errorMap() {
|
42
|
+
return { message: errors.exportsRequired };
|
43
|
+
}
|
44
|
+
}
|
45
|
+
).refine(async (obj) => {
|
46
|
+
for (const [key, value] of obj.entries()) {
|
47
|
+
if (!await pathValidator(value)) {
|
48
|
+
return false;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return true;
|
21
52
|
}, errors.exportsInvalid).optional(),
|
22
53
|
name: z.string({ message: errors.nameRequired }).min(1, errors.nameMinLength).max(214, errors.nameMaxLength).refine(
|
23
54
|
(name) => ["_", "."].every((start) => !name.startsWith(start)),
|
@@ -28,7 +59,27 @@ function createPackageJsonSchema(sourceDir) {
|
|
28
59
|
description: z.string({ message: errors.descriptionString }).optional(),
|
29
60
|
dependencies: dependencies(errors.dependenciesInvalid),
|
30
61
|
optionalDependencies: dependencies(errors.optionalDependenciesInvalid),
|
31
|
-
bin: z.
|
62
|
+
bin: z.union(
|
63
|
+
[
|
64
|
+
z.string().transform((value) => /* @__PURE__ */ new Map([[PackageJsonNameField, value]])),
|
65
|
+
z.record(z.string()).transform((record) => new Map(Object.entries(record)))
|
66
|
+
],
|
67
|
+
{
|
68
|
+
errorMap() {
|
69
|
+
return { message: errors.binFiled };
|
70
|
+
}
|
71
|
+
}
|
72
|
+
).refine(
|
73
|
+
async (map) => {
|
74
|
+
for (const [key, value] of map.entries()) {
|
75
|
+
if (!await pathValidator(value)) {
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return true;
|
80
|
+
},
|
81
|
+
{ message: errors.binFiled }
|
82
|
+
).optional(),
|
32
83
|
repository: z.any().optional(),
|
33
84
|
keywords: z.array(z.string(), { message: errors.keywordsInvalid }).optional(),
|
34
85
|
author: z.any().optional(),
|
@@ -70,6 +121,7 @@ async function parsePackageJson({
|
|
70
121
|
if (!packageJson.success) {
|
71
122
|
return packageJson.error.errors.map((error) => error.message);
|
72
123
|
}
|
124
|
+
fillPackageJson(packageJson.data);
|
73
125
|
return packageJson.data;
|
74
126
|
}
|
75
127
|
export {
|
@@ -14,6 +14,7 @@ function resolveDirs(args) {
|
|
14
14
|
args.packagePath ?? "./package.json"
|
15
15
|
);
|
16
16
|
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
17
|
-
|
17
|
+
const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
|
18
|
+
return { sourceDir, packagePath, outDir, outInternalsDir };
|
18
19
|
}
|
19
20
|
exports.resolveDirs = resolveDirs;
|
@@ -12,7 +12,8 @@ function resolveDirs(args) {
|
|
12
12
|
args.packagePath ?? "./package.json"
|
13
13
|
);
|
14
14
|
const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
|
15
|
-
|
15
|
+
const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
|
16
|
+
return { sourceDir, packagePath, outDir, outInternalsDir };
|
16
17
|
}
|
17
18
|
export {
|
18
19
|
resolveDirs
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const fs = require("node:fs/promises");
|
4
|
+
const path = require("node:path");
|
5
|
+
require("vite");
|
6
|
+
const utils = require("./utils.cjs");
|
7
|
+
async function binsTask({
|
8
|
+
buildOutput,
|
9
|
+
bins,
|
10
|
+
outInternalsDir,
|
11
|
+
outDir
|
12
|
+
}) {
|
13
|
+
const reversedEntrypoints = utils.reverseMap(bins);
|
14
|
+
const res = /* @__PURE__ */ new Map();
|
15
|
+
for (const el of buildOutput) {
|
16
|
+
if (el.facadeModuleId == null) {
|
17
|
+
continue;
|
18
|
+
}
|
19
|
+
if (el.fileName.endsWith(".cjs")) {
|
20
|
+
continue;
|
21
|
+
}
|
22
|
+
const binsPath = reversedEntrypoints.get(el.facadeModuleId);
|
23
|
+
if (!binsPath) {
|
24
|
+
continue;
|
25
|
+
}
|
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);
|
29
|
+
await fs.writeFile(
|
30
|
+
execPath,
|
31
|
+
`#!/usr/bin/env node
|
32
|
+
import("${totalPath}");
|
33
|
+
`
|
34
|
+
);
|
35
|
+
res.set(path.relative(outDir, execPath), path$1);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
return res;
|
39
|
+
}
|
40
|
+
exports.binsTask = binsTask;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
2
|
+
import { relative, join } from "node:path";
|
3
|
+
import "vite";
|
4
|
+
import { reverseMap } from "./utils.js";
|
5
|
+
async function binsTask({
|
6
|
+
buildOutput,
|
7
|
+
bins,
|
8
|
+
outInternalsDir,
|
9
|
+
outDir
|
10
|
+
}) {
|
11
|
+
const reversedEntrypoints = reverseMap(bins);
|
12
|
+
const res = /* @__PURE__ */ new Map();
|
13
|
+
for (const el of buildOutput) {
|
14
|
+
if (el.facadeModuleId == null) {
|
15
|
+
continue;
|
16
|
+
}
|
17
|
+
if (el.fileName.endsWith(".cjs")) {
|
18
|
+
continue;
|
19
|
+
}
|
20
|
+
const binsPath = reversedEntrypoints.get(el.facadeModuleId);
|
21
|
+
if (!binsPath) {
|
22
|
+
continue;
|
23
|
+
}
|
24
|
+
for (const path of binsPath) {
|
25
|
+
const totalPath = relative(outInternalsDir, join(outDir, el.fileName));
|
26
|
+
const execPath = join(outInternalsDir, path);
|
27
|
+
await writeFile(
|
28
|
+
execPath,
|
29
|
+
`#!/usr/bin/env node
|
30
|
+
import("${totalPath}");
|
31
|
+
`
|
32
|
+
);
|
33
|
+
res.set(relative(outDir, execPath), path);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return res;
|
37
|
+
}
|
38
|
+
export {
|
39
|
+
binsTask
|
40
|
+
};
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
1
|
"use strict";
|
3
2
|
var __create = Object.create;
|
4
3
|
var __defProp = Object.defineProperty;
|
@@ -22,4 +21,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
22
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
23
22
|
mod
|
24
23
|
));
|
25
|
-
|
24
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
25
|
+
require("vite");
|
26
|
+
const errors = require("../../errors.cjs");
|
27
|
+
const callTypescript = require("./callTypescript.cjs");
|
28
|
+
const utils = require("../utils.cjs");
|
29
|
+
async function buildTypesTask({
|
30
|
+
buildOutput,
|
31
|
+
entrypoints,
|
32
|
+
sourceDir,
|
33
|
+
outDir
|
34
|
+
}) {
|
35
|
+
const reversedEntrypoints = utils.reverseMap(entrypoints);
|
36
|
+
const tsEntrypoints = [...entrypoints.values()].filter(
|
37
|
+
(entry) => entry.endsWith(".ts")
|
38
|
+
);
|
39
|
+
if (tsEntrypoints.length === 0) {
|
40
|
+
return /* @__PURE__ */ new Map();
|
41
|
+
}
|
42
|
+
let ts;
|
43
|
+
try {
|
44
|
+
ts = await import("typescript");
|
45
|
+
} catch {
|
46
|
+
throw errors.errors.typescriptNotFound;
|
47
|
+
}
|
48
|
+
const files = buildOutput.map((el) => el.facadeModuleId ?? "");
|
49
|
+
const dtsMap = await callTypescript.callTypescript({ ts, sourceDir, files, outDir });
|
50
|
+
const result = /* @__PURE__ */ new Map();
|
51
|
+
for (const [source, dts] of dtsMap) {
|
52
|
+
const exportPath = reversedEntrypoints.get(source);
|
53
|
+
if (!exportPath) {
|
54
|
+
continue;
|
55
|
+
}
|
56
|
+
for (const path of exportPath) {
|
57
|
+
result.set(dts, path);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
return result;
|
61
|
+
}
|
62
|
+
exports.buildTypesTask = buildTypesTask;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import "vite";
|
2
|
+
import { errors } from "../../errors.js";
|
3
|
+
import { callTypescript } from "./callTypescript.js";
|
4
|
+
import { reverseMap } from "../utils.js";
|
5
|
+
async function buildTypesTask({
|
6
|
+
buildOutput,
|
7
|
+
entrypoints,
|
8
|
+
sourceDir,
|
9
|
+
outDir
|
10
|
+
}) {
|
11
|
+
const reversedEntrypoints = reverseMap(entrypoints);
|
12
|
+
const tsEntrypoints = [...entrypoints.values()].filter(
|
13
|
+
(entry) => entry.endsWith(".ts")
|
14
|
+
);
|
15
|
+
if (tsEntrypoints.length === 0) {
|
16
|
+
return /* @__PURE__ */ new Map();
|
17
|
+
}
|
18
|
+
let ts;
|
19
|
+
try {
|
20
|
+
ts = await import("typescript");
|
21
|
+
} catch {
|
22
|
+
throw errors.typescriptNotFound;
|
23
|
+
}
|
24
|
+
const files = buildOutput.map((el) => el.facadeModuleId ?? "");
|
25
|
+
const dtsMap = await callTypescript({ ts, sourceDir, files, outDir });
|
26
|
+
const result = /* @__PURE__ */ new Map();
|
27
|
+
for (const [source, dts] of dtsMap) {
|
28
|
+
const exportPath = reversedEntrypoints.get(source);
|
29
|
+
if (!exportPath) {
|
30
|
+
continue;
|
31
|
+
}
|
32
|
+
for (const path of exportPath) {
|
33
|
+
result.set(dts, path);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return result;
|
37
|
+
}
|
38
|
+
export {
|
39
|
+
buildTypesTask
|
40
|
+
};
|
package/__do_not_import_directly__/{buildTypes.cjs → tasks/buildTypesTask/callTypescript.cjs}
RENAMED
@@ -1,26 +1,4 @@
|
|
1
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
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
25
3
|
const path = require("node:path");
|
26
4
|
const fs = require("node:fs");
|
@@ -42,13 +20,12 @@ function _interopNamespaceDefault(e) {
|
|
42
20
|
}
|
43
21
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
44
22
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
45
|
-
async function
|
23
|
+
async function callTypescript({
|
24
|
+
ts,
|
46
25
|
sourceDir,
|
47
26
|
files,
|
48
27
|
outDir
|
49
28
|
}) {
|
50
|
-
const importedTs = await import("typescript");
|
51
|
-
const ts = importedTs.default ?? importedTs;
|
52
29
|
const configPath = path__namespace.join(sourceDir, "tsconfig.json");
|
53
30
|
const configFile = ts.readConfigFile(
|
54
31
|
configPath,
|
@@ -88,4 +65,4 @@ async function buildTypes({
|
|
88
65
|
});
|
89
66
|
return sourceToDtsMap;
|
90
67
|
}
|
91
|
-
exports.
|
68
|
+
exports.callTypescript = callTypescript;
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import * as path from "node:path";
|
2
2
|
import * as fs from "node:fs";
|
3
|
-
async function
|
3
|
+
async function callTypescript({
|
4
|
+
ts,
|
4
5
|
sourceDir,
|
5
6
|
files,
|
6
7
|
outDir
|
7
8
|
}) {
|
8
|
-
const importedTs = await import("typescript");
|
9
|
-
const ts = importedTs.default ?? importedTs;
|
10
9
|
const configPath = path.join(sourceDir, "tsconfig.json");
|
11
10
|
const configFile = ts.readConfigFile(
|
12
11
|
configPath,
|
@@ -47,5 +46,5 @@ async function buildTypes({
|
|
47
46
|
return sourceToDtsMap;
|
48
47
|
}
|
49
48
|
export {
|
50
|
-
|
49
|
+
callTypescript
|
51
50
|
};
|
@@ -2,6 +2,13 @@
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const path = require("node:path");
|
4
4
|
const fs = require("node:fs/promises");
|
5
|
+
async function copyStaticFilesTask(sourceDir, outDir) {
|
6
|
+
return copyStaticFiles({
|
7
|
+
relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
|
8
|
+
sourceDir,
|
9
|
+
outDir
|
10
|
+
});
|
11
|
+
}
|
5
12
|
async function copyStaticFiles({
|
6
13
|
sourceDir,
|
7
14
|
outDir,
|
@@ -24,4 +31,4 @@ async function copyStaticFiles({
|
|
24
31
|
}
|
25
32
|
}
|
26
33
|
}
|
27
|
-
exports.
|
34
|
+
exports.copyStaticFilesTask = copyStaticFilesTask;
|