smartbundle 0.7.3 → 0.8.0-alpha.1
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 +62 -28
- package/__bin__/smartbundle.js +1 -1
- package/__do_not_import_directly__/args.js +23 -6
- package/__do_not_import_directly__/args.mjs +18 -0
- package/__do_not_import_directly__/buildVite.js +7 -7
- package/__do_not_import_directly__/buildVite.mjs +20 -0
- package/__do_not_import_directly__/createViteConfig.js +14 -14
- package/__do_not_import_directly__/{createViteConfig.cjs → createViteConfig.mjs} +14 -14
- package/__do_not_import_directly__/error.js +3 -3
- package/__do_not_import_directly__/error.mjs +9 -0
- package/__do_not_import_directly__/errors.js +3 -3
- package/__do_not_import_directly__/{errors.cjs → errors.mjs} +3 -3
- package/__do_not_import_directly__/packageJson.js +52 -35
- package/__do_not_import_directly__/packageJson.mjs +129 -0
- package/__do_not_import_directly__/resolveDirs.js +6 -6
- package/__do_not_import_directly__/{resolveDirs.cjs → resolveDirs.mjs} +6 -6
- package/__do_not_import_directly__/smartbundle.js +4 -3
- package/__do_not_import_directly__/smartbundle.mjs +3 -0
- package/__do_not_import_directly__/tasks/binsTask.js +16 -13
- package/__do_not_import_directly__/tasks/{binsTask.cjs → binsTask.mjs} +16 -13
- package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js +34 -12
- package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.mjs +40 -0
- package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.js +33 -12
- package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.mjs +53 -0
- package/__do_not_import_directly__/tasks/copyStaticFilesTask.js +9 -9
- package/__do_not_import_directly__/tasks/{copyStaticFilesTask.cjs → copyStaticFilesTask.mjs} +9 -9
- package/__do_not_import_directly__/tasks/jsFilesTask.js +6 -6
- package/__do_not_import_directly__/tasks/{jsFilesTask.cjs → jsFilesTask.mjs} +6 -6
- package/__do_not_import_directly__/tasks/utils.js +3 -3
- package/__do_not_import_directly__/tasks/{utils.cjs → utils.mjs} +3 -3
- package/__do_not_import_directly__/writePackageJson.js +23 -15
- package/__do_not_import_directly__/{writePackageJson.cjs → writePackageJson.mjs} +23 -15
- package/package.json +9 -8
- package/src/args.d.cts +9 -0
- package/src/buildVite.d.cts +16 -0
- package/src/createViteConfig.d.cts +12 -0
- package/src/error.d.cts +4 -0
- package/src/errors.d.cts +28 -0
- package/src/index.d.cts +9 -0
- package/src/index.js +48 -43
- package/src/index.mjs +105 -0
- package/src/packageJson.d.cts +89 -0
- package/src/resolveDirs.d.cts +12 -0
- package/src/run.d.cts +1 -0
- package/src/tasks/binsTask.d.cts +9 -0
- package/src/tasks/buildTypesTask/buildTypesTask.d.cts +9 -0
- package/src/tasks/buildTypesTask/callTypescript.d.cts +8 -0
- package/src/tasks/copyStaticFilesTask.d.cts +1 -0
- package/src/tasks/jsFilesTask.d.cts +7 -0
- package/src/tasks/utils.d.cts +1 -0
- package/src/writePackageJson.d.cts +14 -0
- package/src/writePackageJson.d.ts +1 -0
- package/__do_not_import_directly__/args.cjs +0 -35
- package/__do_not_import_directly__/buildVite.cjs +0 -20
- package/__do_not_import_directly__/error.cjs +0 -9
- package/__do_not_import_directly__/packageJson.cjs +0 -146
- package/__do_not_import_directly__/smartbundle.cjs +0 -4
- package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs +0 -62
- package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.cjs +0 -68
- package/src/index.cjs +0 -100
package/README.md
CHANGED
@@ -1,47 +1,81 @@
|
|
1
|
-
# SmartBundle
|
1
|
+
# SmartBundle
|
2
|
+
SmartBundle is a zero-config bundler tailored for library authors and package maintainers looking for simplicity and broad compatibility without the need for complex setup.
|
3
|
+
|
4
|
+
## Features
|
5
|
+
`SmartBundle` aims to make the build process seamless and distraction-free. Key features include:
|
6
|
+
- Configuration-free setup via `package.json`
|
7
|
+
- Compatibility with popular bundlers and runtimes
|
8
|
+
- Support for ESM and CJS compatibility
|
9
|
+
- TypeScript typings generation
|
10
|
+
- Harmless bin scripts
|
11
|
+
- Source maps generation for easier debugging
|
12
|
+
|
13
|
+
We've also optimized several aspects to ensure the resulting package is as smooth to use as possible.
|
2
14
|
|
3
15
|
## How to use
|
4
|
-
1) Create package.json like
|
5
|
-
```
|
16
|
+
1) Create a `package.json` file like the following:
|
17
|
+
```json5
|
6
18
|
{
|
7
19
|
"name": "my-package",
|
8
20
|
"version": "1.0.0",
|
9
|
-
"private": true, //
|
21
|
+
"private": true, // prevents accidental publishing
|
10
22
|
"type": "module",
|
11
|
-
"exports":
|
12
|
-
".": "./src/index.ts" // entrypoint list for building the package
|
13
|
-
}
|
23
|
+
"exports": "./src/index.ts" // entrypoint for building the package
|
14
24
|
}
|
15
25
|
```
|
16
26
|
2) Run
|
17
27
|
```bash
|
18
|
-
npx smartbundle
|
28
|
+
npx smartbundle@latest
|
19
29
|
```
|
20
|
-
|
30
|
+
The built files will appear in the `./dist` folder, including an auto-generated `package.json` file.
|
31
|
+
3) Navigate to the `./dist` folder and publish your package to the npm registry.
|
21
32
|
|
22
33
|
## Supported targets
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
34
|
+
| Target | Supported | Tested |
|
35
|
+
|---------------------------|-----------|---------|
|
36
|
+
| Bun ^1.0.0 | ✔ | ✔ |
|
37
|
+
| Node ^18.0.0 | ✔ | ✔ |
|
38
|
+
| Node ^20.0.0 | ✔ | ✔ |
|
39
|
+
| Node ^22.0.0 | ✔ | ✔ |
|
40
|
+
| Node ^23.0.0 | ✔ | ✔ |
|
41
|
+
| Webpack ^4.47.0 | ✔ | ✔ |
|
42
|
+
| Webpack ^5.95.0 | ✔ | ✔ |
|
43
|
+
| Rspack ^1.0.0 | ✔ | ✔ |
|
44
|
+
| Vite ^5.0.0 | ✔ | not yet |
|
45
|
+
| Rollup ^4.0.0 | ✔ | not yet |
|
46
|
+
| Deno ^2.0.0 | ✔ | not yet |
|
47
|
+
| Parcel ^2.0.0 | ✔ | not yet |
|
48
|
+
| Browserify ^17.0.0 | ✔ | not yet |
|
49
|
+
| Esbuild ^0.24.0 | ✔ | not yet |
|
50
|
+
| Metro ^0.81.0 | ✔ | ✔ |
|
51
|
+
| Next.js/Turbopack ^13.0.0 | ✔ | not yet |
|
27
52
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
- but if you need to use them, you can use them by creating them manually like for the parcel bundler
|
33
|
-
- generate esm and cjs entrypoints for the package
|
34
|
-
- generate typescript typings for the package
|
35
|
-
- require only minimal package.json fields
|
53
|
+
We aim to support as many bundlers and runtimes as possible. If the bundled package doesn't work with your bundler, please let us know.
|
54
|
+
|
55
|
+
## `package.json` limitations
|
56
|
+
To reduce potential errors and ensure smooth package generation, we follow a stricter configuration for `package.json`.
|
36
57
|
|
37
|
-
|
38
|
-
|
39
|
-
|
58
|
+
### Banned fields
|
59
|
+
#### `files`
|
60
|
+
SmartBundle calculates the import graph and includes all necessary files, making `files` unnecessary and potentially confusing.
|
61
|
+
#### `main`, `module`, `browser`, `types`
|
62
|
+
We rely on the `exports` field for entry points. These fields are redundant and automatically generated in `./dist/package.json`.
|
40
63
|
|
41
|
-
|
64
|
+
### Required fields
|
65
|
+
#### `private`
|
66
|
+
Setting `"private": true` avoids accidental publishing of the source package by ensuring it is not mistakenly published to npm.
|
42
67
|
|
43
|
-
|
68
|
+
### Stricter fields
|
69
|
+
#### `type`
|
70
|
+
We currently support only the `module` type for packages, with plans to support `commonjs` in future releases.
|
71
|
+
#### `exports`
|
72
|
+
Only ESM/TS entry points are currently supported in exports. While [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) are not yet available, they’re planned for an upcoming release.
|
73
|
+
#### `bin`
|
74
|
+
Currently, we support all `bin` [specifications](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin) except for `sh` files. Also, we guarantee that the bin files will execute as expected.
|
44
75
|
|
45
|
-
|
76
|
+
### FAQ
|
77
|
+
#### Why don't you minify the output?
|
78
|
+
Minification is typically needed only for production. During development, readable, unminified output helps with debugging.
|
46
79
|
|
47
|
-
|
80
|
+
#### Why do you require third-party tools for building?
|
81
|
+
We prioritize keeping the `node_modules` size manageable and avoid unnecessary dependencies. If your package does not require TypeScript, for instance, you don’t need to install those specific tools.
|
package/__bin__/smartbundle.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import("../__do_not_import_directly__/smartbundle.
|
2
|
+
import("../__do_not_import_directly__/smartbundle.mjs");
|
@@ -1,6 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const yargs = require("yargs");
|
4
|
+
const process = require("node:process");
|
5
|
+
function _interopNamespaceDefault(e) {
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
7
|
+
if (e) {
|
8
|
+
for (const k in e) {
|
9
|
+
if (k !== "default") {
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
12
|
+
enumerable: true,
|
13
|
+
get: () => e[k]
|
14
|
+
});
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
n.default = e;
|
19
|
+
return Object.freeze(n);
|
20
|
+
}
|
21
|
+
const process__namespace = /* @__PURE__ */ _interopNamespaceDefault(process);
|
22
|
+
const args = yargs(process__namespace.argv.slice(2)).option("sourceDir", {
|
4
23
|
alias: "s",
|
5
24
|
type: "string",
|
6
25
|
describe: "path to the project directory. Default: current working directory"
|
@@ -13,6 +32,4 @@ const args = yargs(process.argv.slice(2)).option("sourceDir", {
|
|
13
32
|
type: "string",
|
14
33
|
describe: "path to the output directory. Default: cwd()/dist"
|
15
34
|
}).help("help").parseSync();
|
16
|
-
|
17
|
-
args
|
18
|
-
};
|
35
|
+
exports.args = args;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import yargs from "yargs";
|
2
|
+
import * as process from "node:process";
|
3
|
+
const args = yargs(process.argv.slice(2)).option("sourceDir", {
|
4
|
+
alias: "s",
|
5
|
+
type: "string",
|
6
|
+
describe: "path to the project directory. Default: current working directory"
|
7
|
+
}).option("packagePath", {
|
8
|
+
alias: "p",
|
9
|
+
type: "string",
|
10
|
+
describe: "path to the package.json. Default: cwd()/package.json"
|
11
|
+
}).option("outputDir", {
|
12
|
+
alias: "o",
|
13
|
+
type: "string",
|
14
|
+
describe: "path to the output directory. Default: cwd()/dist"
|
15
|
+
}).help("help").parseSync();
|
16
|
+
export {
|
17
|
+
args
|
18
|
+
};
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const vite = require("vite");
|
4
|
+
const errors = require("./errors.js");
|
3
5
|
async function buildVite({
|
4
6
|
viteConfig
|
5
7
|
}) {
|
6
|
-
const outputs = await build(viteConfig);
|
8
|
+
const outputs = await vite.build(viteConfig);
|
7
9
|
if (!Array.isArray(outputs)) {
|
8
10
|
return {
|
9
11
|
error: true,
|
10
|
-
errors: [errors.rollupError]
|
12
|
+
errors: [errors.errors.rollupError]
|
11
13
|
};
|
12
14
|
}
|
13
15
|
return {
|
@@ -15,6 +17,4 @@ async function buildVite({
|
|
15
17
|
output: outputs.flatMap((x) => x.output.filter((x2) => x2.type === "chunk"))
|
16
18
|
};
|
17
19
|
}
|
18
|
-
|
19
|
-
buildVite
|
20
|
-
};
|
20
|
+
exports.buildVite = buildVite;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { build } from "vite";
|
2
|
+
import { errors } from "./errors.mjs";
|
3
|
+
async function buildVite({
|
4
|
+
viteConfig
|
5
|
+
}) {
|
6
|
+
const outputs = await build(viteConfig);
|
7
|
+
if (!Array.isArray(outputs)) {
|
8
|
+
return {
|
9
|
+
error: true,
|
10
|
+
errors: [errors.rollupError]
|
11
|
+
};
|
12
|
+
}
|
13
|
+
return {
|
14
|
+
error: false,
|
15
|
+
output: outputs.flatMap((x) => x.output.filter((x2) => x2.type === "chunk"))
|
16
|
+
};
|
17
|
+
}
|
18
|
+
export {
|
19
|
+
buildVite
|
20
|
+
};
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const path = require("node:path");
|
4
|
+
require("node:fs/promises");
|
5
|
+
require("zod");
|
6
|
+
const vite = require("vite");
|
5
7
|
function mapToObject(map, bins) {
|
6
8
|
const obj = {};
|
7
9
|
for (const [key, value] of map) {
|
@@ -45,18 +47,18 @@ function createViteConfig({ dirs, packageJson }) {
|
|
45
47
|
const entrypoints = /* @__PURE__ */ new Map();
|
46
48
|
if (packageJson.exports) {
|
47
49
|
for (const [key, value] of packageJson.exports) {
|
48
|
-
const entry = join(sourceDir, value);
|
50
|
+
const entry = path.join(sourceDir, value);
|
49
51
|
entrypoints.set(key, entry);
|
50
52
|
}
|
51
53
|
}
|
52
54
|
const bins = /* @__PURE__ */ new Map();
|
53
55
|
if (packageJson.bin) {
|
54
56
|
for (const [key, value] of packageJson.bin) {
|
55
|
-
bins.set(key, join(sourceDir, value));
|
57
|
+
bins.set(key, path.join(sourceDir, value));
|
56
58
|
}
|
57
59
|
}
|
58
60
|
const depsValidator = createExternalDepValidator(packageJson);
|
59
|
-
const viteConfig = defineConfig({
|
61
|
+
const viteConfig = vite.defineConfig({
|
60
62
|
publicDir: false,
|
61
63
|
build: {
|
62
64
|
outDir,
|
@@ -75,15 +77,15 @@ function createViteConfig({ dirs, packageJson }) {
|
|
75
77
|
const entrypoint = entrypoints.get(entryName);
|
76
78
|
if (!entrypoint) {
|
77
79
|
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
78
|
-
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".
|
80
|
+
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".mjs" : ".js");
|
79
81
|
}
|
80
|
-
const relativePath = relative(sourceDir, entrypoint);
|
82
|
+
const relativePath = path.relative(sourceDir, entrypoint);
|
81
83
|
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
82
84
|
if (format === "es") {
|
83
|
-
return `${noExt}.
|
85
|
+
return `${noExt}.mjs`;
|
84
86
|
}
|
85
87
|
if (format === "cjs") {
|
86
|
-
return `${noExt}.
|
88
|
+
return `${noExt}.js`;
|
87
89
|
}
|
88
90
|
return noExt;
|
89
91
|
}
|
@@ -99,6 +101,4 @@ function createViteConfig({ dirs, packageJson }) {
|
|
99
101
|
});
|
100
102
|
return { viteConfig, entrypoints, bins };
|
101
103
|
}
|
102
|
-
|
103
|
-
createViteConfig
|
104
|
-
};
|
104
|
+
exports.createViteConfig = createViteConfig;
|
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require("zod");
|
6
|
-
const vite = require("vite");
|
1
|
+
import { join, relative } from "node:path";
|
2
|
+
import "node:fs/promises";
|
3
|
+
import "zod";
|
4
|
+
import { defineConfig } from "vite";
|
7
5
|
function mapToObject(map, bins) {
|
8
6
|
const obj = {};
|
9
7
|
for (const [key, value] of map) {
|
@@ -47,18 +45,18 @@ function createViteConfig({ dirs, packageJson }) {
|
|
47
45
|
const entrypoints = /* @__PURE__ */ new Map();
|
48
46
|
if (packageJson.exports) {
|
49
47
|
for (const [key, value] of packageJson.exports) {
|
50
|
-
const entry =
|
48
|
+
const entry = join(sourceDir, value);
|
51
49
|
entrypoints.set(key, entry);
|
52
50
|
}
|
53
51
|
}
|
54
52
|
const bins = /* @__PURE__ */ new Map();
|
55
53
|
if (packageJson.bin) {
|
56
54
|
for (const [key, value] of packageJson.bin) {
|
57
|
-
bins.set(key,
|
55
|
+
bins.set(key, join(sourceDir, value));
|
58
56
|
}
|
59
57
|
}
|
60
58
|
const depsValidator = createExternalDepValidator(packageJson);
|
61
|
-
const viteConfig =
|
59
|
+
const viteConfig = defineConfig({
|
62
60
|
publicDir: false,
|
63
61
|
build: {
|
64
62
|
outDir,
|
@@ -77,15 +75,15 @@ function createViteConfig({ dirs, packageJson }) {
|
|
77
75
|
const entrypoint = entrypoints.get(entryName);
|
78
76
|
if (!entrypoint) {
|
79
77
|
const noExt2 = entryName.replace(/\.[^.]+$/, "");
|
80
|
-
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".
|
78
|
+
return "__do_not_import_directly__/" + noExt2 + (format === "es" ? ".mjs" : ".js");
|
81
79
|
}
|
82
|
-
const relativePath =
|
80
|
+
const relativePath = relative(sourceDir, entrypoint);
|
83
81
|
const noExt = relativePath.replace(/\.[^.]+$/, "");
|
84
82
|
if (format === "es") {
|
85
|
-
return `${noExt}.
|
83
|
+
return `${noExt}.mjs`;
|
86
84
|
}
|
87
85
|
if (format === "cjs") {
|
88
|
-
return `${noExt}.
|
86
|
+
return `${noExt}.js`;
|
89
87
|
}
|
90
88
|
return noExt;
|
91
89
|
}
|
@@ -101,4 +99,6 @@ function createViteConfig({ dirs, packageJson }) {
|
|
101
99
|
});
|
102
100
|
return { viteConfig, entrypoints, bins };
|
103
101
|
}
|
104
|
-
|
102
|
+
export {
|
103
|
+
createViteConfig
|
104
|
+
};
|
@@ -1,3 +1,5 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
1
3
|
const errors = {
|
2
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",
|
3
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",
|
@@ -26,6 +28,4 @@ const errors = {
|
|
26
28
|
osInvalid: "The `os` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#os",
|
27
29
|
cpuInvalid: "The `cpu` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#cpu"
|
28
30
|
};
|
29
|
-
|
30
|
-
errors
|
31
|
-
};
|
31
|
+
exports.errors = errors;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
1
|
const errors = {
|
4
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",
|
5
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",
|
@@ -28,4 +26,6 @@ const errors = {
|
|
28
26
|
osInvalid: "The `os` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#os",
|
29
27
|
cpuInvalid: "The `cpu` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#cpu"
|
30
28
|
};
|
31
|
-
|
29
|
+
export {
|
30
|
+
errors
|
31
|
+
};
|
@@ -1,10 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const fs = require("node:fs/promises");
|
4
|
+
const z = require("zod");
|
5
|
+
const errors = require("./errors.js");
|
6
|
+
const path = require("node:path");
|
7
|
+
function _interopNamespaceDefault(e) {
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
9
|
+
if (e) {
|
10
|
+
for (const k in e) {
|
11
|
+
if (k !== "default") {
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
14
|
+
enumerable: true,
|
15
|
+
get: () => e[k]
|
16
|
+
});
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
n.default = e;
|
21
|
+
return Object.freeze(n);
|
22
|
+
}
|
23
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
5
24
|
async function fileExists(filePath) {
|
6
25
|
try {
|
7
|
-
const stats = await
|
26
|
+
const stats = await fs__namespace.stat(filePath);
|
8
27
|
return stats.isFile();
|
9
28
|
} catch (error) {
|
10
29
|
return false;
|
@@ -14,8 +33,8 @@ function dependencies(errorText) {
|
|
14
33
|
return z.record(z.string({ message: errorText }), { message: errorText }).optional();
|
15
34
|
}
|
16
35
|
function createPathValidator(sourceDir) {
|
17
|
-
return (path) => {
|
18
|
-
const finalPath = join(sourceDir, path);
|
36
|
+
return (path$1) => {
|
37
|
+
const finalPath = path.join(sourceDir, path$1);
|
19
38
|
return fileExists(finalPath);
|
20
39
|
};
|
21
40
|
}
|
@@ -34,12 +53,12 @@ function createPackageJsonSchema(sourceDir) {
|
|
34
53
|
return z.object({
|
35
54
|
exports: z.union(
|
36
55
|
[
|
37
|
-
z.string().transform((
|
56
|
+
z.string().transform((path2) => /* @__PURE__ */ new Map([[".", path2]])),
|
38
57
|
z.record(z.string()).transform((obj) => new Map(Object.entries(obj)))
|
39
58
|
],
|
40
59
|
{
|
41
60
|
errorMap() {
|
42
|
-
return { message: errors.exportsRequired };
|
61
|
+
return { message: errors.errors.exportsRequired };
|
43
62
|
}
|
44
63
|
}
|
45
64
|
).refine(async (obj) => {
|
@@ -49,16 +68,16 @@ function createPackageJsonSchema(sourceDir) {
|
|
49
68
|
}
|
50
69
|
}
|
51
70
|
return true;
|
52
|
-
}, errors.exportsInvalid).optional(),
|
53
|
-
name: z.string({ message: errors.nameRequired }).min(1, errors.nameMinLength).max(214, errors.nameMaxLength).refine(
|
71
|
+
}, errors.errors.exportsInvalid).optional(),
|
72
|
+
name: z.string({ message: errors.errors.nameRequired }).min(1, errors.errors.nameMinLength).max(214, errors.errors.nameMaxLength).refine(
|
54
73
|
(name) => ["_", "."].every((start) => !name.startsWith(start)),
|
55
|
-
errors.nameStartsIllegalChars
|
74
|
+
errors.errors.nameStartsIllegalChars
|
56
75
|
),
|
57
|
-
version: z.string({ message: errors.versionRequired }),
|
58
|
-
private: z.boolean({ message: errors.privateIsTrue }).refine((value) => value, errors.privateIsTrue),
|
59
|
-
description: z.string({ message: errors.descriptionString }).optional(),
|
60
|
-
dependencies: dependencies(errors.dependenciesInvalid),
|
61
|
-
optionalDependencies: dependencies(errors.optionalDependenciesInvalid),
|
76
|
+
version: z.string({ message: errors.errors.versionRequired }),
|
77
|
+
private: z.boolean({ message: errors.errors.privateIsTrue }).refine((value) => value, errors.errors.privateIsTrue),
|
78
|
+
description: z.string({ message: errors.errors.descriptionString }).optional(),
|
79
|
+
dependencies: dependencies(errors.errors.dependenciesInvalid),
|
80
|
+
optionalDependencies: dependencies(errors.errors.optionalDependenciesInvalid),
|
62
81
|
bin: z.union(
|
63
82
|
[
|
64
83
|
z.string().transform((value) => /* @__PURE__ */ new Map([[PackageJsonNameField, value]])),
|
@@ -66,7 +85,7 @@ function createPackageJsonSchema(sourceDir) {
|
|
66
85
|
],
|
67
86
|
{
|
68
87
|
errorMap() {
|
69
|
-
return { message: errors.binFiled };
|
88
|
+
return { message: errors.errors.binFiled };
|
70
89
|
}
|
71
90
|
}
|
72
91
|
).refine(
|
@@ -78,33 +97,33 @@ function createPackageJsonSchema(sourceDir) {
|
|
78
97
|
}
|
79
98
|
return true;
|
80
99
|
},
|
81
|
-
{ message: errors.binFiled }
|
100
|
+
{ message: errors.errors.binFiled }
|
82
101
|
).optional(),
|
83
102
|
repository: z.any().optional(),
|
84
|
-
keywords: z.array(z.string(), { message: errors.keywordsInvalid }).optional(),
|
103
|
+
keywords: z.array(z.string(), { message: errors.errors.keywordsInvalid }).optional(),
|
85
104
|
author: z.any().optional(),
|
86
105
|
maintainers: z.any().optional(),
|
87
106
|
contributors: z.array(
|
88
107
|
z.union([
|
89
|
-
z.string({ message: errors.contributorsInvalid }),
|
90
|
-
z.object({}, { message: errors.contributorsInvalid })
|
108
|
+
z.string({ message: errors.errors.contributorsInvalid }),
|
109
|
+
z.object({}, { message: errors.errors.contributorsInvalid })
|
91
110
|
])
|
92
111
|
).optional(),
|
93
112
|
license: z.any().optional(),
|
94
|
-
devDependencies: dependencies(errors.devDependenciesInvalid),
|
95
|
-
peerDependencies: dependencies(errors.peerDependenciesInvalid),
|
96
|
-
engines: z.record(z.string(), { message: errors.enginesInvalid }).optional(),
|
113
|
+
devDependencies: dependencies(errors.errors.devDependenciesInvalid),
|
114
|
+
peerDependencies: dependencies(errors.errors.peerDependenciesInvalid),
|
115
|
+
engines: z.record(z.string(), { message: errors.errors.enginesInvalid }).optional(),
|
97
116
|
browser: z.union([
|
98
|
-
z.string({ message: errors.browserInvalid }),
|
99
|
-
z.record(z.string(), { message: errors.browserInvalid })
|
117
|
+
z.string({ message: errors.errors.browserInvalid }),
|
118
|
+
z.record(z.string(), { message: errors.errors.browserInvalid })
|
100
119
|
]).optional(),
|
101
120
|
bugs: z.any().optional(),
|
102
121
|
funding: z.union([
|
103
|
-
z.string({ message: errors.fundingInvalid }),
|
104
|
-
z.object({}, { message: errors.fundingInvalid })
|
122
|
+
z.string({ message: errors.errors.fundingInvalid }),
|
123
|
+
z.object({}, { message: errors.errors.fundingInvalid })
|
105
124
|
]).optional(),
|
106
|
-
os: z.array(z.string(), { message: errors.osInvalid }).optional(),
|
107
|
-
cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),
|
125
|
+
os: z.array(z.string(), { message: errors.errors.osInvalid }).optional(),
|
126
|
+
cpu: z.array(z.string(), { message: errors.errors.cpuInvalid }).optional(),
|
108
127
|
sideEffects: z.any().optional(),
|
109
128
|
unpkg: z.any().optional(),
|
110
129
|
homepage: z.any().optional()
|
@@ -114,7 +133,7 @@ async function parsePackageJson({
|
|
114
133
|
sourceDir,
|
115
134
|
packagePath
|
116
135
|
}) {
|
117
|
-
const packageString = await
|
136
|
+
const packageString = await fs__namespace.readFile(packagePath, "utf-8");
|
118
137
|
const rawJson = JSON.parse(packageString);
|
119
138
|
const packageJsonSchema = createPackageJsonSchema(sourceDir);
|
120
139
|
const packageJson = await packageJsonSchema.safeParseAsync(rawJson);
|
@@ -124,6 +143,4 @@ async function parsePackageJson({
|
|
124
143
|
fillPackageJson(packageJson.data);
|
125
144
|
return packageJson.data;
|
126
145
|
}
|
127
|
-
|
128
|
-
parsePackageJson
|
129
|
-
};
|
146
|
+
exports.parsePackageJson = parsePackageJson;
|