smartbundle 0.14.0 → 0.15.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 +110 -70
- package/__compiled__/cjs/src/errors.js +1 -5
- package/__compiled__/cjs/src/errors.js.map +1 -1
- package/__compiled__/cjs/src/packageJson.d.ts +57 -1
- package/__compiled__/cjs/src/packageJson.js +10 -1
- package/__compiled__/cjs/src/packageJson.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js +1 -3
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js.map +1 -1
- package/__compiled__/cjs/src/writePackageJson.js +33 -0
- package/__compiled__/cjs/src/writePackageJson.js.map +1 -1
- package/__compiled__/esm/src/errors.mjs +1 -5
- package/__compiled__/esm/src/errors.mjs.map +1 -1
- package/__compiled__/esm/src/packageJson.d.mts +57 -1
- package/__compiled__/esm/src/packageJson.mjs +10 -1
- package/__compiled__/esm/src/packageJson.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs +1 -3
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs.map +1 -1
- package/__compiled__/esm/src/writePackageJson.mjs +33 -0
- package/__compiled__/esm/src/writePackageJson.mjs.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
@@ -1,92 +1,129 @@
|
|
1
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
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
9
|
-
|
10
|
-
|
11
|
-
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
<div align="center">
|
4
|
+
<h3>The Library Bundler That Respects Your Time</h3>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<a href="#getting-started">Getting Started</a> •
|
8
|
+
<a href="#features">Features</a> •
|
9
|
+
<a href="#compatibility">Compatibility</a> •
|
10
|
+
<a href="#tool-integration">Tool Integration</a> •
|
11
|
+
<a href="#advanced-usage">Advanced Usage</a> •
|
12
|
+
<a href="#faq">FAQ</a>
|
13
|
+
</p>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
Build your library for any JavaScript environment without the complexity
|
17
|
+
|
18
|
+
## Getting Started
|
19
|
+
|
20
|
+
SmartBundle makes it easy to bundle your library for any JavaScript environment. Just create a minimal package.json (see below), install SmartBundle, and run the build command.
|
21
|
+
|
17
22
|
```json5
|
18
23
|
{
|
19
|
-
|
20
|
-
"
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
+
// Your package name
|
25
|
+
"name": "my-package",
|
26
|
+
// Package version
|
27
|
+
"version": "1.0.0",
|
28
|
+
// Must be true to avoid accidental publishing
|
29
|
+
"private": true,
|
30
|
+
// SmartBundle supports only ES modules
|
31
|
+
"type": "module",
|
32
|
+
// Entry point used by SmartBundle
|
33
|
+
"exports": "./src/index.js",
|
34
|
+
"scripts": {
|
35
|
+
// Run this to build your package
|
36
|
+
"build": "smartbundle"
|
37
|
+
}
|
24
38
|
}
|
25
39
|
```
|
26
|
-
|
40
|
+
|
41
|
+
Need more details? See our [package.json guide](./docs/package-json.md) for a full explanation of each field. If you plan to use TypeScript, check out our [TS guide](./docs/ts-guide.md) for tailored advice.
|
42
|
+
|
43
|
+
To build your package:
|
44
|
+
|
45
|
+
1) Create the package.json as shown above
|
46
|
+
2) Install SmartBundle:
|
47
|
+
```bash
|
48
|
+
npm install --save-dev smartbundle@latest
|
49
|
+
```
|
50
|
+
3) Build your package:
|
27
51
|
```bash
|
28
|
-
|
52
|
+
npm run build
|
29
53
|
```
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
|
48
|
-
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
56
|
-
|
54
|
+
4) Your built files (including an auto-generated package.json) will be in the ./dist folder
|
55
|
+
|
56
|
+
## Features
|
57
|
+
|
58
|
+
- **Zero Configuration** - Point to your entry file and build
|
59
|
+
- **Universal Output** - ESM and CommonJS bundles generated automatically
|
60
|
+
- **TypeScript Ready** - Full TypeScript support with type definitions
|
61
|
+
- **React Support** - Automatic JSX transformations for modern and legacy modes
|
62
|
+
- **Developer Friendly** - Source maps included for better debugging
|
63
|
+
- **Broad Compatibility** - Works with Node.js, Webpack, Vite, Rollup, Bun, and more
|
64
|
+
|
65
|
+
|
66
|
+
## Compatibility
|
67
|
+
|
68
|
+
Every bundled package is tested in real environments - from Node.js and Bun to Webpack and Metro - to ensure it just works.
|
69
|
+
|
70
|
+
### Runtimes
|
71
|
+
| Runtime | Version | Supported | E2E Tests |
|
72
|
+
|------------|-----------|:---------:|:---------:|
|
73
|
+
| Node.js | ^18.0.0 | ✔ | ✔ |
|
74
|
+
| | ^20.0.0 | ✔ | ✔ |
|
75
|
+
| | ^22.0.0 | ✔ | ✔ |
|
76
|
+
| | ^23.0.0 | ✔ | ✔ |
|
77
|
+
| Bun | ^1.0.0 | ✔ | ✔ |
|
78
|
+
| Deno | ^2.0.0 | ✔ | - |
|
79
|
+
|
80
|
+
### Bundlers
|
81
|
+
| Bundler | Version | Supported | E2E Tests |
|
82
|
+
|-------------------|-----------|:---------:|:---------:|
|
83
|
+
| Webpack | ^4.47.0 | ✔ | ✔ |
|
84
|
+
| | ^5.95.0 | ✔ | ✔ |
|
85
|
+
| Rspack | ^1.0.0 | ✔ | ✔ |
|
86
|
+
| Vite | ^5.0.0 | ✔ | - |
|
87
|
+
| Rollup | ^4.0.0 | ✔ | - |
|
88
|
+
| Parcel | ^2.0.0 | ✔ | - |
|
89
|
+
| Browserify | ^17.0.0 | ✔ | - |
|
90
|
+
| Esbuild | ^0.24.0 | ✔ | - |
|
91
|
+
| Metro | ^0.81.0 | ✔ | ✔ |
|
92
|
+
| Next.js/Turbopack| ^13.0.0 | ✔ | - |
|
93
|
+
|
94
|
+
### TypeScript Module Resolution
|
95
|
+
| Strategy | Supported | E2E Tests |
|
96
|
+
|-------------|:---------:|:---------:|
|
97
|
+
| bundler | ✔ | ✔ |
|
98
|
+
| node10 | ✔ | ✔ |
|
99
|
+
| node16es | ✔ | ✔ |
|
100
|
+
| node16cjs | ✔ | ✔ |
|
57
101
|
|
58
102
|
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.
|
59
103
|
|
60
|
-
##
|
61
|
-
|
62
|
-
|
104
|
+
## Tool Integration
|
105
|
+
|
106
|
+
SmartBundle automatically detects and integrates with your tools - just add what you need to your project.
|
107
|
+
|
108
|
+
### TypeScript
|
109
|
+
Add `typescript@^5.0.0` as a dev dependency and start creating `.ts` files. SmartBundle will handle the rest.
|
63
110
|
|
64
111
|
### Babel
|
65
|
-
|
112
|
+
Add `@babel/core@^7.0.0` as a dev dependency and create a Babel configuration file in your project root. SmartBundle will automatically apply your transformations.
|
66
113
|
|
67
114
|
### React
|
68
|
-
|
115
|
+
Add `react` to your dependencies. SmartBundle automatically detects React and configures JSX transformations. Both modern and legacy modes are supported.
|
69
116
|
|
70
|
-
|
71
|
-
To reduce potential errors and ensure smooth package generation, we follow a stricter configuration for `package.json`.
|
117
|
+
For detailed React configuration options, see our [React guide](./docs/react.md).
|
72
118
|
|
73
|
-
|
74
|
-
#### `files`
|
75
|
-
SmartBundle calculates the import graph and includes all necessary files, making `files` unnecessary and potentially confusing.
|
76
|
-
#### `main`, `module`, `browser`, `types`
|
77
|
-
We rely on the `exports` field for entry points. These fields are redundant and automatically generated in `./dist/package.json`.
|
119
|
+
## Advanced Usage
|
78
120
|
|
79
|
-
|
80
|
-
|
81
|
-
|
121
|
+
SmartBundle enforces certain package.json conventions to ensure reliable builds. For detailed information about:
|
122
|
+
- Required and banned fields
|
123
|
+
- Configuration limitations
|
124
|
+
- Package.json best practices
|
82
125
|
|
83
|
-
|
84
|
-
#### `type`
|
85
|
-
We currently support only the `module` type for packages, with plans to support `commonjs` in future releases.
|
86
|
-
#### `exports`
|
87
|
-
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.
|
88
|
-
#### `bin`
|
89
|
-
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.
|
126
|
+
See our [package.json guide](./docs/package-json.md).
|
90
127
|
|
91
128
|
## FAQ
|
92
129
|
### SmartBundle have an issue
|
@@ -97,3 +134,6 @@ Minification is typically needed only for production. During development, readab
|
|
97
134
|
|
98
135
|
### Why do you require third-party tools for building?
|
99
136
|
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.
|
137
|
+
|
138
|
+
### Community and Support
|
139
|
+
If you need assistance or wish to contribute, please check out our [discussion forum](https://github.com/your-org/smartbundle/discussions) and [issue tracker](https://github.com/your-org/smartbundle/issues).
|
@@ -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
|
4
|
+
exportsRequired: "The `exports` or `bin` field is required. 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',
|
@@ -13,13 +13,9 @@ const errors = {
|
|
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
|
-
typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
|
17
16
|
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",
|
18
|
-
repositoryInvalid: "The `repository` field must be an object with 'type' and 'url' properties or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository",
|
19
17
|
keywordsInvalid: "The `keywords` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#keywords",
|
20
|
-
authorInvalid: "The `author` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors",
|
21
18
|
contributorsInvalid: "The `contributors` field must be an array of objects or strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors",
|
22
|
-
licenseInvalid: "The `license` field must be a string specifying the license. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license",
|
23
19
|
devDependenciesInvalid: "The `devDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#devdependencies",
|
24
20
|
peerDependenciesInvalid: "The `peerDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies",
|
25
21
|
enginesInvalid: "The `engines` field must be an object specifying version requirements. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"errors.js","sources":["../../../../src/errors.ts"],"sourcesContent":["export const errors = {\n exportsRequired:\n \"The `exports` field is
|
1
|
+
{"version":3,"file":"errors.js","sources":["../../../../src/errors.ts"],"sourcesContent":["export const errors = {\n exportsRequired:\n \"The `exports` or `bin` field is required. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points\",\n exportsInvalid:\n \"The `exports` field must be a path to entrypoint. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points\",\n nameRequired:\n \"The `name` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name\",\n nameMinLength:\n 'Min length of \"name\" is 1 character. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',\n nameMaxLength:\n 'Max length of \"name\" is 214 characters. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',\n nameStartsIllegalChars:\n \"Name cannot start with `_` or `.` if it is not a scoped package. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name\",\n versionRequired:\n \"The `version` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#version\",\n privateIsTrue:\n \"The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private\",\n descriptionString:\n \"The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description\",\n dependenciesInvalid:\n \"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\",\n binFiled:\n \"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\",\n rollupError:\n \"An error occurred while building the package. Please, report it to the issues on GitHub\",\n typescriptNotFound:\n \"The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0\",\n optionalDependenciesInvalid:\n \"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\",\n repositoryInvalid:\n \"The `repository` field must be an object with 'type' and 'url' properties or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository\",\n keywordsInvalid:\n \"The `keywords` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#keywords\",\n authorInvalid:\n \"The `author` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors\",\n contributorsInvalid:\n \"The `contributors` field must be an array of objects or strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors\",\n licenseInvalid:\n \"The `license` field must be a string specifying the license. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license\",\n devDependenciesInvalid:\n \"The `devDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#devdependencies\",\n peerDependenciesInvalid:\n \"The `peerDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies\",\n enginesInvalid:\n \"The `engines` field must be an object specifying version requirements. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines\",\n browserInvalid:\n \"The `browser` field must be a string or an object. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#browser\",\n fundingInvalid:\n \"The `funding` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#funding\",\n osInvalid:\n \"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\",\n cpuInvalid:\n \"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\",\n};\n"],"names":[],"mappings":";;AAAO,MAAM,SAAS;AAAA,EACpB,iBACE;AAAA,EACF,gBACE;AAAA,EACF,cACE;AAAA,EACF,eACE;AAAA,EACF,eACE;AAAA,EACF,wBACE;AAAA,EACF,iBACE;AAAA,EACF,eACE;AAAA,EACF,mBACE;AAAA,EACF,qBACE;AAAA,EACF,UACE;AAAA,EACF,aACE;AAAA,EAGF,6BACE;AAAA,EAGF,iBACE;AAAA,EAGF,qBACE;AAAA,EAGF,wBACE;AAAA,EACF,yBACE;AAAA,EACF,gBACE;AAAA,EACF,gBACE;AAAA,EACF,gBACE;AAAA,EACF,WACE;AAAA,EACF,YACE;AACJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
2
|
+
declare function createPackageJsonSchema(sourceDir: string): z.ZodEffects<z.ZodObject<{
|
3
3
|
exports: z.ZodOptional<z.ZodEffects<z.ZodUnion<[
|
4
4
|
z.ZodEffects<z.ZodString, Map<string, string>, string>,
|
5
5
|
z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Map<string, string>, Record<string, string>>
|
@@ -98,6 +98,62 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
98
98
|
homepage?: any;
|
99
99
|
babel?: any;
|
100
100
|
peerDependenciesMeta?: any;
|
101
|
+
}>, {
|
102
|
+
exports?: Map<string, string>;
|
103
|
+
name?: string;
|
104
|
+
version?: string;
|
105
|
+
private?: boolean;
|
106
|
+
description?: string;
|
107
|
+
dependencies?: Record<string, string>;
|
108
|
+
optionalDependencies?: Record<string, string>;
|
109
|
+
bin?: Map<string, string>;
|
110
|
+
repository?: any;
|
111
|
+
keywords?: string[];
|
112
|
+
author?: any;
|
113
|
+
contributors?: (string | {})[];
|
114
|
+
license?: any;
|
115
|
+
devDependencies?: Record<string, string>;
|
116
|
+
peerDependencies?: Record<string, string>;
|
117
|
+
engines?: Record<string, string>;
|
118
|
+
browser?: string | Record<string, string>;
|
119
|
+
funding?: string | {};
|
120
|
+
os?: string[];
|
121
|
+
cpu?: string[];
|
122
|
+
maintainers?: any;
|
123
|
+
bugs?: any;
|
124
|
+
sideEffects?: any;
|
125
|
+
unpkg?: any;
|
126
|
+
homepage?: any;
|
127
|
+
babel?: any;
|
128
|
+
peerDependenciesMeta?: any;
|
129
|
+
}, {
|
130
|
+
exports?: string | Record<string, string>;
|
131
|
+
name?: string;
|
132
|
+
version?: string;
|
133
|
+
private?: boolean;
|
134
|
+
description?: string;
|
135
|
+
dependencies?: Record<string, string>;
|
136
|
+
optionalDependencies?: Record<string, string>;
|
137
|
+
bin?: string | Record<string, string>;
|
138
|
+
repository?: any;
|
139
|
+
keywords?: string[];
|
140
|
+
author?: any;
|
141
|
+
contributors?: (string | {})[];
|
142
|
+
license?: any;
|
143
|
+
devDependencies?: Record<string, string>;
|
144
|
+
peerDependencies?: Record<string, string>;
|
145
|
+
engines?: Record<string, string>;
|
146
|
+
browser?: string | Record<string, string>;
|
147
|
+
funding?: string | {};
|
148
|
+
os?: string[];
|
149
|
+
cpu?: string[];
|
150
|
+
maintainers?: any;
|
151
|
+
bugs?: any;
|
152
|
+
sideEffects?: any;
|
153
|
+
unpkg?: any;
|
154
|
+
homepage?: any;
|
155
|
+
babel?: any;
|
156
|
+
peerDependenciesMeta?: any;
|
101
157
|
}>;
|
102
158
|
type PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;
|
103
159
|
export type PackageJson = z.infer<PackageJsonSchema>;
|
@@ -50,7 +50,7 @@ function fillPackageJson(packageJson) {
|
|
50
50
|
}
|
51
51
|
function createPackageJsonSchema(sourceDir) {
|
52
52
|
const pathValidator = createPathValidator(sourceDir);
|
53
|
-
|
53
|
+
const schema = z.object({
|
54
54
|
exports: z.union(
|
55
55
|
[
|
56
56
|
z.string().transform((path2) => /* @__PURE__ */ new Map([[".", path2]])),
|
@@ -130,6 +130,15 @@ function createPackageJsonSchema(sourceDir) {
|
|
130
130
|
babel: z.any().optional(),
|
131
131
|
peerDependenciesMeta: z.any().optional()
|
132
132
|
});
|
133
|
+
return schema.superRefine((data, ctx) => {
|
134
|
+
if (!data.exports && !data.bin) {
|
135
|
+
ctx.addIssue({
|
136
|
+
code: "custom",
|
137
|
+
message: errors.errors.exportsRequired,
|
138
|
+
path: ["exports"]
|
139
|
+
});
|
140
|
+
}
|
141
|
+
});
|
133
142
|
}
|
134
143
|
async function parsePackageJson({
|
135
144
|
sourceDir,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"packageJson.js","sources":["../../../../src/packageJson.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport z from \"zod\";\nimport { errors } from \"./errors.js\";\nimport { join } from \"node:path\";\n\n// <region>\n// For AI completion. Don't remove.\nconst allPackageJsonFields = [\n \"exports\",\n \"name\",\n \"version\",\n \"private\",\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n\nconst requiredFields = [\"exports\", \"name\", \"version\", \"private\"];\n\nconst optionalFields = [\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n// </region>\n\nasync function fileExists(filePath: string) {\n try {\n const stats = await fs.stat(filePath);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\nfunction dependencies(errorText: string) {\n return z\n .record(z.string({ message: errorText }), { message: errorText })\n .optional();\n}\n\nfunction createPathValidator(sourceDir: string) {\n return (path: string) => {\n const finalPath = join(sourceDir, path);\n return fileExists(finalPath);\n };\n}\n\nconst PackageJsonNameField: string = \"___NAME___\";\nfunction fillPackageJson(packageJson: PackageJson) {\n if (packageJson.bin) {\n const binName = packageJson.bin.get(PackageJsonNameField);\n if (binName) {\n packageJson.bin.set(packageJson.name, binName);\n packageJson.bin.delete(PackageJsonNameField);\n }\n }\n}\n\nfunction createPackageJsonSchema(sourceDir: string) {\n const pathValidator = createPathValidator(sourceDir);\n\n return z.object({\n exports: z\n .union(\n [\n z.string().transform((path) => new Map([[\".\", path]])),\n z.record(z.string()).transform((obj) => new Map(Object.entries(obj))),\n ],\n {\n errorMap() {\n return { message: errors.exportsRequired };\n },\n },\n )\n .refine(async (obj) => {\n for (const [key, value] of obj.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n }, errors.exportsInvalid)\n .optional(),\n name: z\n .string({ message: errors.nameRequired })\n .min(1, errors.nameMinLength)\n .max(214, errors.nameMaxLength)\n .refine(\n (name) => [\"_\", \".\"].every((start) => !name.startsWith(start)),\n errors.nameStartsIllegalChars,\n ),\n version: z.string({ message: errors.versionRequired }),\n private: z\n .boolean({ message: errors.privateIsTrue })\n .refine((value) => value, errors.privateIsTrue),\n description: z.string({ message: errors.descriptionString }).optional(),\n dependencies: dependencies(errors.dependenciesInvalid),\n optionalDependencies: dependencies(errors.optionalDependenciesInvalid),\n bin: z\n .union(\n [\n z\n .string()\n .transform((value) => new Map([[PackageJsonNameField, value]])),\n z\n .record(z.string())\n .transform((record) => new Map(Object.entries(record))),\n ],\n {\n errorMap() {\n return { message: errors.binFiled };\n },\n },\n )\n .refine(\n async (map) => {\n for (const [key, value] of map.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n },\n { message: errors.binFiled },\n )\n .optional(),\n repository: z.any().optional(),\n keywords: z\n .array(z.string(), { message: errors.keywordsInvalid })\n .optional(),\n author: z.any().optional(),\n maintainers: z.any().optional(),\n contributors: z\n .array(\n z.union([\n z.string({ message: errors.contributorsInvalid }),\n z.object({}, { message: errors.contributorsInvalid }),\n ]),\n )\n .optional(),\n license: z.any().optional(),\n devDependencies: dependencies(errors.devDependenciesInvalid),\n peerDependencies: dependencies(errors.peerDependenciesInvalid),\n engines: z\n .record(z.string(), { message: errors.enginesInvalid })\n .optional(),\n browser: z\n .union([\n z.string({ message: errors.browserInvalid }),\n z.record(z.string(), { message: errors.browserInvalid }),\n ])\n .optional(),\n bugs: z.any().optional(),\n funding: z\n .union([\n z.string({ message: errors.fundingInvalid }),\n z.object({}, { message: errors.fundingInvalid }),\n ])\n .optional(),\n os: z.array(z.string(), { message: errors.osInvalid }).optional(),\n cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),\n sideEffects: z.any().optional(),\n unpkg: z.any().optional(),\n homepage: z.any().optional(),\n babel: z.any().optional(),\n peerDependenciesMeta: z.any().optional(),\n });\n}\ntype PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;\n\nexport type PackageJson = z.infer<PackageJsonSchema>;\ntype Errors = Array<string>;\n\ntype ParsePackageJsonArg = {\n packagePath: string;\n sourceDir: string;\n};\n\nexport async function parsePackageJson({\n sourceDir,\n packagePath,\n}: ParsePackageJsonArg): Promise<PackageJson | Errors> {\n const packageString = await fs.readFile(packagePath, \"utf-8\");\n const rawJson = JSON.parse(packageString);\n\n const packageJsonSchema = createPackageJsonSchema(sourceDir);\n const packageJson = await packageJsonSchema.safeParseAsync(rawJson);\n if (!packageJson.success) {\n return packageJson.error.errors.map((error) => error.message);\n }\n\n fillPackageJson(packageJson.data);\n return packageJson.data;\n}\n"],"names":["fs","path","join","errors"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAoDA,eAAe,WAAW,UAAkB;AACtC,MAAA;AACF,UAAM,QAAQ,MAAMA,cAAG,KAAK,QAAQ;AACpC,WAAO,MAAM,OAAO;AAAA,WACb,OAAO;AACP,WAAA;AAAA,EAAA;AAEX;AAEA,SAAS,aAAa,WAAmB;AACvC,SAAO,EACJ,OAAO,EAAE,OAAO,EAAE,SAAS,UAAW,CAAA,GAAG,EAAE,SAAS,UAAW,CAAA,EAC/D,SAAS;AACd;AAEA,S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AC3B,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,IACxB,sBAAsB,EAAE,IAAI,EAAE,SAAS;AAAA,EAAA,CACxC;AACH;AAWA,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAAuD;AACrD,QAAM,gBAAgB,MAAMH,cAAG,SAAS,aAAa,OAAO;AACtD,QAAA,UAAU,KAAK,MAAM,aAAa;AAElC,QAAA,oBAAoB,wBAAwB,SAAS;AAC3D,QAAM,cAAc,MAAM,kBAAkB,eAAe,OAAO;AAC9D,MAAA,CAAC,YAAY,SAAS;AACxB,WAAO,YAAY,MAAM,OAAO,IAAI,CAAC,UAAU,MAAM,OAAO;AAAA,EAAA;AAG9D,kBAAgB,YAAY,IAAI;AAChC,SAAO,YAAY;AACrB;;"}
|
1
|
+
{"version":3,"file":"packageJson.js","sources":["../../../../src/packageJson.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport z from \"zod\";\nimport { errors } from \"./errors.js\";\nimport { join } from \"node:path\";\n\n// <region>\n// For AI completion. Don't remove.\nconst allPackageJsonFields = [\n \"exports\",\n \"name\",\n \"version\",\n \"private\",\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n\nconst requiredFields = [\"exports\", \"name\", \"version\", \"private\"];\n\nconst optionalFields = [\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n// </region>\n\nasync function fileExists(filePath: string) {\n try {\n const stats = await fs.stat(filePath);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\nfunction dependencies(errorText: string) {\n return z\n .record(z.string({ message: errorText }), { message: errorText })\n .optional();\n}\n\nfunction createPathValidator(sourceDir: string) {\n return (path: string) => {\n const finalPath = join(sourceDir, path);\n return fileExists(finalPath);\n };\n}\n\nconst PackageJsonNameField: string = \"___NAME___\";\nfunction fillPackageJson(packageJson: PackageJson) {\n if (packageJson.bin) {\n const binName = packageJson.bin.get(PackageJsonNameField);\n if (binName) {\n packageJson.bin.set(packageJson.name, binName);\n packageJson.bin.delete(PackageJsonNameField);\n }\n }\n}\n\nfunction createPackageJsonSchema(sourceDir: string) {\n const pathValidator = createPathValidator(sourceDir);\n\n const schema = z.object({\n exports: z\n .union(\n [\n z.string().transform((path) => new Map([[\".\", path]])),\n z.record(z.string()).transform((obj) => new Map(Object.entries(obj))),\n ],\n {\n errorMap() {\n return { message: errors.exportsRequired };\n },\n },\n )\n .refine(async (obj) => {\n for (const [key, value] of obj.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n }, errors.exportsInvalid)\n .optional(),\n name: z\n .string({ message: errors.nameRequired })\n .min(1, errors.nameMinLength)\n .max(214, errors.nameMaxLength)\n .refine(\n (name) => [\"_\", \".\"].every((start) => !name.startsWith(start)),\n errors.nameStartsIllegalChars,\n ),\n version: z.string({ message: errors.versionRequired }),\n private: z\n .boolean({ message: errors.privateIsTrue })\n .refine((value) => value, errors.privateIsTrue),\n description: z.string({ message: errors.descriptionString }).optional(),\n dependencies: dependencies(errors.dependenciesInvalid),\n optionalDependencies: dependencies(errors.optionalDependenciesInvalid),\n bin: z\n .union(\n [\n z\n .string()\n .transform((value) => new Map([[PackageJsonNameField, value]])),\n z\n .record(z.string())\n .transform((record) => new Map(Object.entries(record))),\n ],\n {\n errorMap() {\n return { message: errors.binFiled };\n },\n },\n )\n .refine(\n async (map) => {\n for (const [key, value] of map.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n },\n { message: errors.binFiled },\n )\n .optional(),\n repository: z.any().optional(),\n keywords: z\n .array(z.string(), { message: errors.keywordsInvalid })\n .optional(),\n author: z.any().optional(),\n maintainers: z.any().optional(),\n contributors: z\n .array(\n z.union([\n z.string({ message: errors.contributorsInvalid }),\n z.object({}, { message: errors.contributorsInvalid }),\n ]),\n )\n .optional(),\n license: z.any().optional(),\n devDependencies: dependencies(errors.devDependenciesInvalid),\n peerDependencies: dependencies(errors.peerDependenciesInvalid),\n engines: z\n .record(z.string(), { message: errors.enginesInvalid })\n .optional(),\n browser: z\n .union([\n z.string({ message: errors.browserInvalid }),\n z.record(z.string(), { message: errors.browserInvalid }),\n ])\n .optional(),\n bugs: z.any().optional(),\n funding: z\n .union([\n z.string({ message: errors.fundingInvalid }),\n z.object({}, { message: errors.fundingInvalid }),\n ])\n .optional(),\n os: z.array(z.string(), { message: errors.osInvalid }).optional(),\n cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),\n sideEffects: z.any().optional(),\n unpkg: z.any().optional(),\n homepage: z.any().optional(),\n babel: z.any().optional(),\n peerDependenciesMeta: z.any().optional(),\n });\n\n // Add custom logic so that at least one of exports or bin is provided\n return schema.superRefine((data, ctx) => {\n if (!data.exports && !data.bin) {\n ctx.addIssue({\n code: \"custom\",\n message: errors.exportsRequired,\n path: [\"exports\"],\n });\n }\n });\n}\ntype PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;\n\nexport type PackageJson = z.infer<PackageJsonSchema>;\ntype Errors = Array<string>;\n\ntype ParsePackageJsonArg = {\n packagePath: string;\n sourceDir: string;\n};\n\nexport async function parsePackageJson({\n sourceDir,\n packagePath,\n}: ParsePackageJsonArg): Promise<PackageJson | Errors> {\n const packageString = await fs.readFile(packagePath, \"utf-8\");\n const rawJson = JSON.parse(packageString);\n\n const packageJsonSchema = createPackageJsonSchema(sourceDir);\n const packageJson = await packageJsonSchema.safeParseAsync(rawJson);\n if (!packageJson.success) {\n return packageJson.error.errors.map((error) => error.message);\n }\n\n fillPackageJson(packageJson.data);\n return packageJson.data;\n}\n"],"names":["fs","path","join","errors"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A,SAAS;AAAA,IACZ,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,SAASA,OAAO,OAAA,UAAW,CAAA,EAAE,SAAS;AAAA,IAChE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,SAASA,OAAO,OAAA,WAAY,CAAA,EAAE,SAAS;AAAA,IAClE,aAAa,EAAE,IAAI,EAAE,SAAS;AAAA,IAC9B,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,IACxB,UAAU,EAAE,IAAI,EAAE,SAAS;AAAA,IAC3B,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,IACxB,sBAAsB,EAAE,IAAI,EAAE,SAAS;AAAA,EAAA,CACxC;AAGD,SAAO,OAAO,YAAY,CAAC,MAAM,QAAQ;AACvC,QAAI,CAAC,KAAK,WAAW,CAAC,KAAK,KAAK;AAC9B,UAAI,SAAS;AAAA,QACX,MAAM;AAAA,QACN,SAASA,OAAO,OAAA;AAAA,QAChB,MAAM,CAAC,SAAS;AAAA,MAAA,CACjB;AAAA,IAAA;AAAA,EACH,CACD;AACH;AAWA,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAAuD;AACrD,QAAM,gBAAgB,MAAMH,cAAG,SAAS,aAAa,OAAO;AACtD,QAAA,UAAU,KAAK,MAAM,aAAa;AAElC,QAAA,oBAAoB,wBAAwB,SAAS;AAC3D,QAAM,cAAc,MAAM,kBAAkB,eAAe,OAAO;AAC9D,MAAA,CAAC,YAAY,SAAS;AACxB,WAAO,YAAY,MAAM,OAAO,IAAI,CAAC,UAAU,MAAM,OAAO;AAAA,EAAA;AAG9D,kBAAgB,YAAY,IAAI;AAChC,SAAO,YAAY;AACrB;;"}
|
@@ -13,7 +13,6 @@ async function buildTypesTask({
|
|
13
13
|
packageJson,
|
14
14
|
modules
|
15
15
|
}) {
|
16
|
-
const { outDir } = dirs;
|
17
16
|
const tsEntrypoints = [...entrypoints.values()].filter(
|
18
17
|
(entry) => entry.endsWith(".ts") || entry.endsWith(".tsx")
|
19
18
|
);
|
@@ -32,8 +31,7 @@ async function buildTypesTask({
|
|
32
31
|
ts: modules.ts,
|
33
32
|
dirs,
|
34
33
|
packageJson,
|
35
|
-
tsEntrypoints
|
36
|
-
outDir
|
34
|
+
tsEntrypoints
|
37
35
|
});
|
38
36
|
for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {
|
39
37
|
const entrypoints2 = reversedEntrypoints.get(source);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildTypesTask.js","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["reverseMap","callTypescript","entrypoints","okLog"],"mappings":";;;;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;
|
1
|
+
{"version":3,"file":"buildTypesTask.js","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["reverseMap","callTypescript","entrypoints","okLog"],"mappings":";;;;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AAEvB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;AACM,QAAA,sBAAsBA,iBAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAMC,8BAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EAEF,CAAC;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CC,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGFC,MAAAA,MAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;;"}
|
@@ -13,6 +13,28 @@ function extractValue(value) {
|
|
13
13
|
}
|
14
14
|
return value.default;
|
15
15
|
}
|
16
|
+
const monorepoPostfix = "-sbsources";
|
17
|
+
const monorepoPostfixRegex = new RegExp(`${monorepoPostfix}$`);
|
18
|
+
function walkOverMonorepoDepsToRemovePostfix(deps) {
|
19
|
+
if (!deps) {
|
20
|
+
return void 0;
|
21
|
+
}
|
22
|
+
const res = {};
|
23
|
+
for (const [key, value] of Object.entries(deps)) {
|
24
|
+
if (key.endsWith(monorepoPostfix)) {
|
25
|
+
res[key.replace(monorepoPostfixRegex, "")] = value;
|
26
|
+
} else {
|
27
|
+
res[key] = value;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return res;
|
31
|
+
}
|
32
|
+
const allDepsClauses = [
|
33
|
+
"dependencies",
|
34
|
+
"optionalDependencies",
|
35
|
+
"peerDependencies",
|
36
|
+
"devDependencies"
|
37
|
+
];
|
16
38
|
async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
17
39
|
const allExports = {};
|
18
40
|
for (const [key, value] of exportsMap) {
|
@@ -38,6 +60,17 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
|
38
60
|
allExports["./package.json"] = "./package.json";
|
39
61
|
const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
|
40
62
|
const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
|
63
|
+
if (parsed.name.endsWith(monorepoPostfix)) {
|
64
|
+
const originalName = parsed.name;
|
65
|
+
parsed.name = parsed.name.replace(monorepoPostfix, "");
|
66
|
+
for (const depClause of allDepsClauses) {
|
67
|
+
parsed[depClause] = walkOverMonorepoDepsToRemovePostfix(
|
68
|
+
parsed[depClause]
|
69
|
+
);
|
70
|
+
}
|
71
|
+
parsed.devDependencies = parsed.devDependencies ?? {};
|
72
|
+
parsed.devDependencies[originalName] = "*";
|
73
|
+
}
|
41
74
|
const res = {
|
42
75
|
name: parsed.name,
|
43
76
|
type: "commonjs",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"writePackageJson.js","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":["writeFile","okLog"],"mappings":";;;;;;AA0BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AAEvB,eAAA,OAAO,UAAU,MAAM;AAAA,IAAA;AAElC,QAAI,MAAM,KAAK;AACb,eAAS,UAAU,CAAC;AACpB,UAAI,MAAM,MAAM;AACL,iBAAA,QAAQ,QAAQ,MAAM;AAAA,MAAA;AAExB,eAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAI1B,aAAA,QAAQ,MAAM,QAAQ,MAAM;AAGrC,aAAS,UAAU,MAAM;AAEzB,eAAW,GAAG,IAAI;AAAA,EAAA;AAEpB,aAAW,gBAAgB,IAAI;AAE/B,QAAM,MAAM,QAAQ,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI;AAEvD,QAAA,aACJ,OAAO,WAAW,GAAG,MAAM,WAAW,WAAW,GAAG,IAAI;
|
1
|
+
{"version":3,"file":"writePackageJson.js","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nconst monorepoPostfix = \"-sbsources\";\nconst monorepoPostfixRegex = new RegExp(`${monorepoPostfix}$`);\n\nfunction walkOverMonorepoDepsToRemovePostfix(\n deps: Record<string, string> | undefined,\n) {\n if (!deps) {\n return undefined;\n }\n\n const res: Record<string, string> = {};\n for (const [key, value] of Object.entries(deps)) {\n if (key.endsWith(monorepoPostfix)) {\n res[key.replace(monorepoPostfixRegex, \"\")] = value;\n } else {\n res[key] = value;\n }\n }\n return res;\n}\n\nconst allDepsClauses = [\n \"dependencies\",\n \"optionalDependencies\",\n \"peerDependencies\",\n \"devDependencies\",\n] as const;\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n\n if (parsed.name.endsWith(monorepoPostfix)) {\n const originalName = parsed.name;\n parsed.name = parsed.name.replace(monorepoPostfix, \"\");\n\n for (const depClause of allDepsClauses) {\n parsed[depClause] = walkOverMonorepoDepsToRemovePostfix(\n parsed[depClause],\n );\n }\n\n // add the sources to the devDeps to create a wire between source and dist\n parsed.devDependencies = parsed.devDependencies ?? {};\n parsed.devDependencies[originalName] = \"*\";\n }\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":["writeFile","okLog"],"mappings":";;;;;;AA0BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB,IAAI,OAAO,GAAG,eAAe,GAAG;AAE7D,SAAS,oCACP,MACA;AACA,MAAI,CAAC,MAAM;AACF,WAAA;AAAA,EAAA;AAGT,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC3C,QAAA,IAAI,SAAS,eAAe,GAAG;AACjC,UAAI,IAAI,QAAQ,sBAAsB,EAAE,CAAC,IAAI;AAAA,IAAA,OACxC;AACL,UAAI,GAAG,IAAI;AAAA,IAAA;AAAA,EACb;AAEK,SAAA;AACT;AAEA,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AA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SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,MAAM,OAAO;AAAA,IACb,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,EAC/B;AAEM,QAAAA,aAAU,GAAG,MAAM,iBAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAEtEC,MAAAA,MAAM,cAAc;AACtB;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const errors = {
|
2
|
-
exportsRequired: "The `exports` field is
|
2
|
+
exportsRequired: "The `exports` or `bin` field is required. 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',
|
@@ -11,13 +11,9 @@ const errors = {
|
|
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
|
-
typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
|
15
14
|
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",
|
16
|
-
repositoryInvalid: "The `repository` field must be an object with 'type' and 'url' properties or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository",
|
17
15
|
keywordsInvalid: "The `keywords` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#keywords",
|
18
|
-
authorInvalid: "The `author` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors",
|
19
16
|
contributorsInvalid: "The `contributors` field must be an array of objects or strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors",
|
20
|
-
licenseInvalid: "The `license` field must be a string specifying the license. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license",
|
21
17
|
devDependenciesInvalid: "The `devDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#devdependencies",
|
22
18
|
peerDependenciesInvalid: "The `peerDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies",
|
23
19
|
enginesInvalid: "The `engines` field must be an object specifying version requirements. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"errors.mjs","sources":["../../../../src/errors.ts"],"sourcesContent":["export const errors = {\n exportsRequired:\n \"The `exports` field is
|
1
|
+
{"version":3,"file":"errors.mjs","sources":["../../../../src/errors.ts"],"sourcesContent":["export const errors = {\n exportsRequired:\n \"The `exports` or `bin` field is required. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points\",\n exportsInvalid:\n \"The `exports` field must be a path to entrypoint. Please, verify the value. More info: https://nodejs.org/api/packages.html#package-entry-points\",\n nameRequired:\n \"The `name` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name\",\n nameMinLength:\n 'Min length of \"name\" is 1 character. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',\n nameMaxLength:\n 'Max length of \"name\" is 214 characters. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name',\n nameStartsIllegalChars:\n \"Name cannot start with `_` or `.` if it is not a scoped package. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name\",\n versionRequired:\n \"The `version` field is required string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#version\",\n privateIsTrue:\n \"The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private\",\n descriptionString:\n \"The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description\",\n dependenciesInvalid:\n \"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\",\n binFiled:\n \"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\",\n rollupError:\n \"An error occurred while building the package. Please, report it to the issues on GitHub\",\n typescriptNotFound:\n \"The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0\",\n optionalDependenciesInvalid:\n \"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\",\n repositoryInvalid:\n \"The `repository` field must be an object with 'type' and 'url' properties or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository\",\n keywordsInvalid:\n \"The `keywords` field must be an array of strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#keywords\",\n authorInvalid:\n \"The `author` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors\",\n contributorsInvalid:\n \"The `contributors` field must be an array of objects or strings. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors\",\n licenseInvalid:\n \"The `license` field must be a string specifying the license. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#license\",\n devDependenciesInvalid:\n \"The `devDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#devdependencies\",\n peerDependenciesInvalid:\n \"The `peerDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies\",\n enginesInvalid:\n \"The `engines` field must be an object specifying version requirements. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines\",\n browserInvalid:\n \"The `browser` field must be a string or an object. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#browser\",\n fundingInvalid:\n \"The `funding` field must be an object or a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#funding\",\n osInvalid:\n \"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\",\n cpuInvalid:\n \"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\",\n};\n"],"names":[],"mappings":"AAAO,MAAM,SAAS;AAAA,EACpB,iBACE;AAAA,EACF,gBACE;AAAA,EACF,cACE;AAAA,EACF,eACE;AAAA,EACF,eACE;AAAA,EACF,wBACE;AAAA,EACF,iBACE;AAAA,EACF,eACE;AAAA,EACF,mBACE;AAAA,EACF,qBACE;AAAA,EACF,UACE;AAAA,EACF,aACE;AAAA,EAGF,6BACE;AAAA,EAGF,iBACE;AAAA,EAGF,qBACE;AAAA,EAGF,wBACE;AAAA,EACF,yBACE;AAAA,EACF,gBACE;AAAA,EACF,gBACE;AAAA,EACF,gBACE;AAAA,EACF,WACE;AAAA,EACF,YACE;AACJ;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
2
|
+
declare function createPackageJsonSchema(sourceDir: string): z.ZodEffects<z.ZodObject<{
|
3
3
|
exports: z.ZodOptional<z.ZodEffects<z.ZodUnion<[
|
4
4
|
z.ZodEffects<z.ZodString, Map<string, string>, string>,
|
5
5
|
z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Map<string, string>, Record<string, string>>
|
@@ -98,6 +98,62 @@ declare function createPackageJsonSchema(sourceDir: string): z.ZodObject<{
|
|
98
98
|
homepage?: any;
|
99
99
|
babel?: any;
|
100
100
|
peerDependenciesMeta?: any;
|
101
|
+
}>, {
|
102
|
+
exports?: Map<string, string>;
|
103
|
+
name?: string;
|
104
|
+
version?: string;
|
105
|
+
private?: boolean;
|
106
|
+
description?: string;
|
107
|
+
dependencies?: Record<string, string>;
|
108
|
+
optionalDependencies?: Record<string, string>;
|
109
|
+
bin?: Map<string, string>;
|
110
|
+
repository?: any;
|
111
|
+
keywords?: string[];
|
112
|
+
author?: any;
|
113
|
+
contributors?: (string | {})[];
|
114
|
+
license?: any;
|
115
|
+
devDependencies?: Record<string, string>;
|
116
|
+
peerDependencies?: Record<string, string>;
|
117
|
+
engines?: Record<string, string>;
|
118
|
+
browser?: string | Record<string, string>;
|
119
|
+
funding?: string | {};
|
120
|
+
os?: string[];
|
121
|
+
cpu?: string[];
|
122
|
+
maintainers?: any;
|
123
|
+
bugs?: any;
|
124
|
+
sideEffects?: any;
|
125
|
+
unpkg?: any;
|
126
|
+
homepage?: any;
|
127
|
+
babel?: any;
|
128
|
+
peerDependenciesMeta?: any;
|
129
|
+
}, {
|
130
|
+
exports?: string | Record<string, string>;
|
131
|
+
name?: string;
|
132
|
+
version?: string;
|
133
|
+
private?: boolean;
|
134
|
+
description?: string;
|
135
|
+
dependencies?: Record<string, string>;
|
136
|
+
optionalDependencies?: Record<string, string>;
|
137
|
+
bin?: string | Record<string, string>;
|
138
|
+
repository?: any;
|
139
|
+
keywords?: string[];
|
140
|
+
author?: any;
|
141
|
+
contributors?: (string | {})[];
|
142
|
+
license?: any;
|
143
|
+
devDependencies?: Record<string, string>;
|
144
|
+
peerDependencies?: Record<string, string>;
|
145
|
+
engines?: Record<string, string>;
|
146
|
+
browser?: string | Record<string, string>;
|
147
|
+
funding?: string | {};
|
148
|
+
os?: string[];
|
149
|
+
cpu?: string[];
|
150
|
+
maintainers?: any;
|
151
|
+
bugs?: any;
|
152
|
+
sideEffects?: any;
|
153
|
+
unpkg?: any;
|
154
|
+
homepage?: any;
|
155
|
+
babel?: any;
|
156
|
+
peerDependenciesMeta?: any;
|
101
157
|
}>;
|
102
158
|
type PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;
|
103
159
|
export type PackageJson = z.infer<PackageJsonSchema>;
|
@@ -31,7 +31,7 @@ function fillPackageJson(packageJson) {
|
|
31
31
|
}
|
32
32
|
function createPackageJsonSchema(sourceDir) {
|
33
33
|
const pathValidator = createPathValidator(sourceDir);
|
34
|
-
|
34
|
+
const schema = z.object({
|
35
35
|
exports: z.union(
|
36
36
|
[
|
37
37
|
z.string().transform((path) => /* @__PURE__ */ new Map([[".", path]])),
|
@@ -111,6 +111,15 @@ function createPackageJsonSchema(sourceDir) {
|
|
111
111
|
babel: z.any().optional(),
|
112
112
|
peerDependenciesMeta: z.any().optional()
|
113
113
|
});
|
114
|
+
return schema.superRefine((data, ctx) => {
|
115
|
+
if (!data.exports && !data.bin) {
|
116
|
+
ctx.addIssue({
|
117
|
+
code: "custom",
|
118
|
+
message: errors.exportsRequired,
|
119
|
+
path: ["exports"]
|
120
|
+
});
|
121
|
+
}
|
122
|
+
});
|
114
123
|
}
|
115
124
|
async function parsePackageJson({
|
116
125
|
sourceDir,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"packageJson.mjs","sources":["../../../../src/packageJson.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport z from \"zod\";\nimport { errors } from \"./errors.js\";\nimport { join } from \"node:path\";\n\n// <region>\n// For AI completion. Don't remove.\nconst allPackageJsonFields = [\n \"exports\",\n \"name\",\n \"version\",\n \"private\",\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n\nconst requiredFields = [\"exports\", \"name\", \"version\", \"private\"];\n\nconst optionalFields = [\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n// </region>\n\nasync function fileExists(filePath: string) {\n try {\n const stats = await fs.stat(filePath);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\nfunction dependencies(errorText: string) {\n return z\n .record(z.string({ message: errorText }), { message: errorText })\n .optional();\n}\n\nfunction createPathValidator(sourceDir: string) {\n return (path: string) => {\n const finalPath = join(sourceDir, path);\n return fileExists(finalPath);\n };\n}\n\nconst PackageJsonNameField: string = \"___NAME___\";\nfunction fillPackageJson(packageJson: PackageJson) {\n if (packageJson.bin) {\n const binName = packageJson.bin.get(PackageJsonNameField);\n if (binName) {\n packageJson.bin.set(packageJson.name, binName);\n packageJson.bin.delete(PackageJsonNameField);\n }\n }\n}\n\nfunction createPackageJsonSchema(sourceDir: string) {\n const pathValidator = createPathValidator(sourceDir);\n\n return z.object({\n exports: z\n .union(\n [\n z.string().transform((path) => new Map([[\".\", path]])),\n z.record(z.string()).transform((obj) => new Map(Object.entries(obj))),\n ],\n {\n errorMap() {\n return { message: errors.exportsRequired };\n },\n },\n )\n .refine(async (obj) => {\n for (const [key, value] of obj.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n }, errors.exportsInvalid)\n .optional(),\n name: z\n .string({ message: errors.nameRequired })\n .min(1, errors.nameMinLength)\n .max(214, errors.nameMaxLength)\n .refine(\n (name) => [\"_\", \".\"].every((start) => !name.startsWith(start)),\n errors.nameStartsIllegalChars,\n ),\n version: z.string({ message: errors.versionRequired }),\n private: z\n .boolean({ message: errors.privateIsTrue })\n .refine((value) => value, errors.privateIsTrue),\n description: z.string({ message: errors.descriptionString }).optional(),\n dependencies: dependencies(errors.dependenciesInvalid),\n optionalDependencies: dependencies(errors.optionalDependenciesInvalid),\n bin: z\n .union(\n [\n z\n .string()\n .transform((value) => new Map([[PackageJsonNameField, value]])),\n z\n .record(z.string())\n .transform((record) => new Map(Object.entries(record))),\n ],\n {\n errorMap() {\n return { message: errors.binFiled };\n },\n },\n )\n .refine(\n async (map) => {\n for (const [key, value] of map.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n },\n { message: errors.binFiled },\n )\n .optional(),\n repository: z.any().optional(),\n keywords: z\n .array(z.string(), { message: errors.keywordsInvalid })\n .optional(),\n author: z.any().optional(),\n maintainers: z.any().optional(),\n contributors: z\n .array(\n z.union([\n z.string({ message: errors.contributorsInvalid }),\n z.object({}, { message: errors.contributorsInvalid }),\n ]),\n )\n .optional(),\n license: z.any().optional(),\n devDependencies: dependencies(errors.devDependenciesInvalid),\n peerDependencies: dependencies(errors.peerDependenciesInvalid),\n engines: z\n .record(z.string(), { message: errors.enginesInvalid })\n .optional(),\n browser: z\n .union([\n z.string({ message: errors.browserInvalid }),\n z.record(z.string(), { message: errors.browserInvalid }),\n ])\n .optional(),\n bugs: z.any().optional(),\n funding: z\n .union([\n z.string({ message: errors.fundingInvalid }),\n z.object({}, { message: errors.fundingInvalid }),\n ])\n .optional(),\n os: z.array(z.string(), { message: errors.osInvalid }).optional(),\n cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),\n sideEffects: z.any().optional(),\n unpkg: z.any().optional(),\n homepage: z.any().optional(),\n babel: z.any().optional(),\n peerDependenciesMeta: z.any().optional(),\n });\n}\ntype PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;\n\nexport type PackageJson = z.infer<PackageJsonSchema>;\ntype Errors = Array<string>;\n\ntype ParsePackageJsonArg = {\n packagePath: string;\n sourceDir: string;\n};\n\nexport async function parsePackageJson({\n sourceDir,\n packagePath,\n}: ParsePackageJsonArg): Promise<PackageJson | Errors> {\n const packageString = await fs.readFile(packagePath, \"utf-8\");\n const rawJson = JSON.parse(packageString);\n\n const packageJsonSchema = createPackageJsonSchema(sourceDir);\n const packageJson = await packageJsonSchema.safeParseAsync(rawJson);\n if (!packageJson.success) {\n return packageJson.error.errors.map((error) => error.message);\n }\n\n fillPackageJson(packageJson.data);\n return packageJson.data;\n}\n"],"names":[],"mappings":";;;;AAoDA,eAAe,WAAW,UAAkB;AACtC,MAAA;AACF,UAAM,QAAQ,MAAM,GAAG,KAAK,QAAQ;AACpC,WAAO,MAAM,OAAO;AAAA,WACb,OAAO;AACP,WAAA;AAAA,EAAA;AAEX;AAEA,SAAS,aAAa,WAAmB;AACvC,SAAO,EACJ,OAAO,EAAE,OAAO,EAAE,SAAS,UAAW,CAAA,GAAG,EAAE,SAAS,UAAW,CAAA,EAC/D,SAAS;AACd;AAEA,SAAS,oBAAoB,WAAmB;AAC9C,SAAO,CAAC,SAAiB;AACjB,UAAA,YAAY,KAAK,WAAW,IAAI;AACtC,WAAO,WAAW,SAAS;AAAA,EAC7B;AACF;AAEA,MAAM,uBAA+B;AACrC,SAAS,gBAAgB,aAA0B;AACjD,MAAI,YAAY,KAAK;AACnB,UAAM,UAAU,YAAY,IAAI,IAAI,oBAAoB;AACxD,QAAI,SAAS;AACX,kBAAY,IAAI,IAAI,YAAY,MAAM,OAAO;AACjC,kBAAA,IAAI,OAAO,oBAAoB;AAAA,IAAA;AAAA,EAC7C;AAEJ;AAEA,SAAS,wBAAwB,WAAmB;AAC5C,QAAA,gBAAgB,oBAAoB,SAAS;AAEnD,SAAO,EAAE,OAAO;AAAA,I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AAS,OAAO,eAAgB,CAAA;AAAA,IACxD,CAAA,EACA,SAAS;AAAA,IACZ,MAAM,EAAE,IAAI,EAAE,SAAS;AAAA,IACvB,SAAS,EACN,MAAM;AAAA,MACL,EAAE,OAAO,EAAE,SAAS,OAAO,gBAAgB;AAAA,MAC3C,EAAE,OAAO,CAAC,GAAG,EAAE,SAAS,OAAO,eAAgB,CAAA;AAAA,IAChD,CAAA,EACA,SAAS;AAAA,IACZ,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,SAAS,OAAO,UAAW,CAAA,EAAE,SAAS;AAAA,IAChE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,SAAS,OAAO,WAAY,CAAA,EAAE,SAAS;AAAA,IAClE,aAAa,EAAE,IAAI,EAAE,SAAS;AAAA,IAC9B,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,IACxB,UAAU,EAAE,IAAI,EAAE,SAAS;AAAA,IAC3B,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,IACxB,sBAAsB,EAAE,IAAI,EAAE,SAAS;AAAA,EAAA,CACxC;AACH;AAWA,eAAsB,iBAAiB;AAAA,EACrC;AAAA,EACA;AACF,GAAuD;AACrD,QAAM,gBAAgB,MAAM,GAAG,SAAS,aAAa,OAAO;AACtD,QAAA,UAAU,KAAK,MAAM,aAAa;AAElC,QAAA,oBAAoB,wBAAwB,SAAS;AAC3D,QAAM,cAAc,MAAM,kBAAkB,eAAe,OAAO;AAC9D,MAAA,CAAC,YAAY,SAAS;AACxB,WAAO,YAAY,MAAM,OAAO,IAAI,CAAC,UAAU,MAAM,OAAO;AAAA,EAAA;AAG9D,kBAAgB,YAAY,IAAI;AAChC,SAAO,YAAY;AACrB;"}
|
1
|
+
{"version":3,"file":"packageJson.mjs","sources":["../../../../src/packageJson.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport z from \"zod\";\nimport { errors } from \"./errors.js\";\nimport { join } from \"node:path\";\n\n// <region>\n// For AI completion. Don't remove.\nconst allPackageJsonFields = [\n \"exports\",\n \"name\",\n \"version\",\n \"private\",\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n\nconst requiredFields = [\"exports\", \"name\", \"version\", \"private\"];\n\nconst optionalFields = [\n \"description\",\n \"dependencies\",\n \"optionalDependencies\",\n \"bin\",\n \"repository\",\n \"keywords\",\n \"author\",\n \"contributors\",\n \"license\",\n \"devDependencies\",\n \"peerDependencies\",\n \"engines\",\n \"browser\",\n \"funding\",\n \"os\",\n \"cpu\",\n];\n// </region>\n\nasync function fileExists(filePath: string) {\n try {\n const stats = await fs.stat(filePath);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\nfunction dependencies(errorText: string) {\n return z\n .record(z.string({ message: errorText }), { message: errorText })\n .optional();\n}\n\nfunction createPathValidator(sourceDir: string) {\n return (path: string) => {\n const finalPath = join(sourceDir, path);\n return fileExists(finalPath);\n };\n}\n\nconst PackageJsonNameField: string = \"___NAME___\";\nfunction fillPackageJson(packageJson: PackageJson) {\n if (packageJson.bin) {\n const binName = packageJson.bin.get(PackageJsonNameField);\n if (binName) {\n packageJson.bin.set(packageJson.name, binName);\n packageJson.bin.delete(PackageJsonNameField);\n }\n }\n}\n\nfunction createPackageJsonSchema(sourceDir: string) {\n const pathValidator = createPathValidator(sourceDir);\n\n const schema = z.object({\n exports: z\n .union(\n [\n z.string().transform((path) => new Map([[\".\", path]])),\n z.record(z.string()).transform((obj) => new Map(Object.entries(obj))),\n ],\n {\n errorMap() {\n return { message: errors.exportsRequired };\n },\n },\n )\n .refine(async (obj) => {\n for (const [key, value] of obj.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n }, errors.exportsInvalid)\n .optional(),\n name: z\n .string({ message: errors.nameRequired })\n .min(1, errors.nameMinLength)\n .max(214, errors.nameMaxLength)\n .refine(\n (name) => [\"_\", \".\"].every((start) => !name.startsWith(start)),\n errors.nameStartsIllegalChars,\n ),\n version: z.string({ message: errors.versionRequired }),\n private: z\n .boolean({ message: errors.privateIsTrue })\n .refine((value) => value, errors.privateIsTrue),\n description: z.string({ message: errors.descriptionString }).optional(),\n dependencies: dependencies(errors.dependenciesInvalid),\n optionalDependencies: dependencies(errors.optionalDependenciesInvalid),\n bin: z\n .union(\n [\n z\n .string()\n .transform((value) => new Map([[PackageJsonNameField, value]])),\n z\n .record(z.string())\n .transform((record) => new Map(Object.entries(record))),\n ],\n {\n errorMap() {\n return { message: errors.binFiled };\n },\n },\n )\n .refine(\n async (map) => {\n for (const [key, value] of map.entries()) {\n if (!(await pathValidator(value))) {\n return false;\n }\n }\n return true;\n },\n { message: errors.binFiled },\n )\n .optional(),\n repository: z.any().optional(),\n keywords: z\n .array(z.string(), { message: errors.keywordsInvalid })\n .optional(),\n author: z.any().optional(),\n maintainers: z.any().optional(),\n contributors: z\n .array(\n z.union([\n z.string({ message: errors.contributorsInvalid }),\n z.object({}, { message: errors.contributorsInvalid }),\n ]),\n )\n .optional(),\n license: z.any().optional(),\n devDependencies: dependencies(errors.devDependenciesInvalid),\n peerDependencies: dependencies(errors.peerDependenciesInvalid),\n engines: z\n .record(z.string(), { message: errors.enginesInvalid })\n .optional(),\n browser: z\n .union([\n z.string({ message: errors.browserInvalid }),\n z.record(z.string(), { message: errors.browserInvalid }),\n ])\n .optional(),\n bugs: z.any().optional(),\n funding: z\n .union([\n z.string({ message: errors.fundingInvalid }),\n z.object({}, { message: errors.fundingInvalid }),\n ])\n .optional(),\n os: z.array(z.string(), { message: errors.osInvalid }).optional(),\n cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),\n sideEffects: z.any().optional(),\n unpkg: z.any().optional(),\n homepage: z.any().optional(),\n babel: z.any().optional(),\n peerDependenciesMeta: z.any().optional(),\n });\n\n // Add custom logic so that at least one of exports or bin is provided\n return schema.superRefine((data, ctx) => {\n if (!data.exports && !data.bin) {\n ctx.addIssue({\n code: \"custom\",\n message: errors.exportsRequired,\n path: [\"exports\"],\n });\n }\n });\n}\ntype PackageJsonSchema = ReturnType<typeof createPackageJsonSchema>;\n\nexport type PackageJson = z.infer<PackageJsonSchema>;\ntype Errors = Array<string>;\n\ntype ParsePackageJsonArg = {\n packagePath: string;\n sourceDir: string;\n};\n\nexport async function parsePackageJson({\n sourceDir,\n packagePath,\n}: ParsePackageJsonArg): Promise<PackageJson | Errors> {\n const packageString = await fs.readFile(packagePath, \"utf-8\");\n const rawJson = JSON.parse(packageString);\n\n const packageJsonSchema = createPackageJsonSchema(sourceDir);\n const packageJson = await packageJsonSchema.safeParseAsync(rawJson);\n if (!packageJson.success) {\n return packageJson.error.errors.map((error) => error.message);\n }\n\n fillPackageJson(packageJson.data);\n return packageJson.data;\n}\n"],"names":[],"mappings":";;;;AAoDA,eAAe,WAAW,UAAkB;AACtC,MAAA;AACF,UAAM,QAAQ,MAAM,GAAG,KAAK,QAAQ;AACpC,WAAO,MAAM,OAAO;AAAA,WACb,OAAO;AACP,WAAA;AAAA,EAAA;AAEX;AAEA,SAAS,aAAa,WAAmB;AACvC,SAAO,EACJ,OAAO,EAAE,OAAO,EAAE,SAAS,UAAW,CAAA,GAAG,EAAE,SAAS,UAAW,CAAA,EAC/D,SAAS;AACd;AAEA,SAAS,oBAAoB,WAAmB;AAC9C,SAAO,CAAC,SAAiB;AACjB,UAAA,YAAY,KAAK,WAAW,IAAI;AACtC,WAAO,WAAW,SAAS;AAAA,EAC7B;AACF;AAEA,MAAM,uBAA+B;AACrC,SAAS,gBAAgB,aAA0B;AACjD,MAAI,YAAY,KAAK;AACnB,UAAM,UAAU,YAAY,IAAI,IAAI,oBAAoB;AACxD,QAAI,SAAS;AACX,kBAAY,IAAI,IAAI,YAAY,MAAM,OAAO;AACjC,kBAAA,IAAI,OAAO,oBAAoB;AAAA,IAAA;AAAA,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AAM,kBAAkB,eAAe,OAAO;AAC9D,MAAA,CAAC,YAAY,SAAS;AACxB,WAAO,YAAY,MAAM,OAAO,IAAI,CAAC,UAAU,MAAM,OAAO;AAAA,EAAA;AAG9D,kBAAgB,YAAY,IAAI;AAChC,SAAO,YAAY;AACrB;"}
|
@@ -11,7 +11,6 @@ async function buildTypesTask({
|
|
11
11
|
packageJson,
|
12
12
|
modules
|
13
13
|
}) {
|
14
|
-
const { outDir } = dirs;
|
15
14
|
const tsEntrypoints = [...entrypoints.values()].filter(
|
16
15
|
(entry) => entry.endsWith(".ts") || entry.endsWith(".tsx")
|
17
16
|
);
|
@@ -30,8 +29,7 @@ async function buildTypesTask({
|
|
30
29
|
ts: modules.ts,
|
31
30
|
dirs,
|
32
31
|
packageJson,
|
33
|
-
tsEntrypoints
|
34
|
-
outDir
|
32
|
+
tsEntrypoints
|
35
33
|
});
|
36
34
|
for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {
|
37
35
|
const entrypoints2 = reversedEntrypoints.get(source);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;
|
1
|
+
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AAEvB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EAEF,CAAC;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
|
@@ -11,6 +11,28 @@ function extractValue(value) {
|
|
11
11
|
}
|
12
12
|
return value.default;
|
13
13
|
}
|
14
|
+
const monorepoPostfix = "-sbsources";
|
15
|
+
const monorepoPostfixRegex = new RegExp(`${monorepoPostfix}$`);
|
16
|
+
function walkOverMonorepoDepsToRemovePostfix(deps) {
|
17
|
+
if (!deps) {
|
18
|
+
return void 0;
|
19
|
+
}
|
20
|
+
const res = {};
|
21
|
+
for (const [key, value] of Object.entries(deps)) {
|
22
|
+
if (key.endsWith(monorepoPostfix)) {
|
23
|
+
res[key.replace(monorepoPostfixRegex, "")] = value;
|
24
|
+
} else {
|
25
|
+
res[key] = value;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return res;
|
29
|
+
}
|
30
|
+
const allDepsClauses = [
|
31
|
+
"dependencies",
|
32
|
+
"optionalDependencies",
|
33
|
+
"peerDependencies",
|
34
|
+
"devDependencies"
|
35
|
+
];
|
14
36
|
async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
15
37
|
const allExports = {};
|
16
38
|
for (const [key, value] of exportsMap) {
|
@@ -36,6 +58,17 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
|
36
58
|
allExports["./package.json"] = "./package.json";
|
37
59
|
const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
|
38
60
|
const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
|
61
|
+
if (parsed.name.endsWith(monorepoPostfix)) {
|
62
|
+
const originalName = parsed.name;
|
63
|
+
parsed.name = parsed.name.replace(monorepoPostfix, "");
|
64
|
+
for (const depClause of allDepsClauses) {
|
65
|
+
parsed[depClause] = walkOverMonorepoDepsToRemovePostfix(
|
66
|
+
parsed[depClause]
|
67
|
+
);
|
68
|
+
}
|
69
|
+
parsed.devDependencies = parsed.devDependencies ?? {};
|
70
|
+
parsed.devDependencies[originalName] = "*";
|
71
|
+
}
|
39
72
|
const res = {
|
40
73
|
name: parsed.name,
|
41
74
|
type: "commonjs",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"writePackageJson.mjs","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":[],"mappings":";;;;AA0BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AAEvB,eAAA,OAAO,UAAU,MAAM;AAAA,IAAA;AAElC,QAAI,MAAM,KAAK;AACb,eAAS,UAAU,CAAC;AACpB,UAAI,MAAM,MAAM;AACL,iBAAA,QAAQ,QAAQ,MAAM;AAAA,MAAA;AAExB,eAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAI1B,aAAA,QAAQ,MAAM,QAAQ,MAAM;AAGrC,aAAS,UAAU,MAAM;AAEzB,eAAW,GAAG,IAAI;AAAA,EAAA;AAEpB,aAAW,gBAAgB,IAAI;AAE/B,QAAM,MAAM,QAAQ,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI;AAEvD,QAAA,aACJ,OAAO,WAAW,GAAG,MAAM,WAAW,WAAW,GAAG,IAAI;
|
1
|
+
{"version":3,"file":"writePackageJson.mjs","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nconst monorepoPostfix = \"-sbsources\";\nconst monorepoPostfixRegex = new RegExp(`${monorepoPostfix}$`);\n\nfunction walkOverMonorepoDepsToRemovePostfix(\n deps: Record<string, string> | undefined,\n) {\n if (!deps) {\n return undefined;\n }\n\n const res: Record<string, string> = {};\n for (const [key, value] of Object.entries(deps)) {\n if (key.endsWith(monorepoPostfix)) {\n res[key.replace(monorepoPostfixRegex, \"\")] = value;\n } else {\n res[key] = value;\n }\n }\n return res;\n}\n\nconst allDepsClauses = [\n \"dependencies\",\n \"optionalDependencies\",\n \"peerDependencies\",\n \"devDependencies\",\n] as const;\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n\n if (parsed.name.endsWith(monorepoPostfix)) {\n const originalName = parsed.name;\n parsed.name = parsed.name.replace(monorepoPostfix, \"\");\n\n for (const depClause of allDepsClauses) {\n parsed[depClause] = walkOverMonorepoDepsToRemovePostfix(\n parsed[depClause],\n );\n }\n\n // add the sources to the devDeps to create a wire between source and dist\n parsed.devDependencies = parsed.devDependencies ?? {};\n parsed.devDependencies[originalName] = \"*\";\n }\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":[],"mappings":";;;;AA0BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,MAAM,kBAAkB;AACxB,MAAM,uBAAuB,IAAI,OAAO,GAAG,eAAe,GAAG;AAE7D,SAAS,oCACP,MACA;AACA,MAAI,CAAC,MAAM;AACF,WAAA;AAAA,EAAA;AAGT,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC3C,QAAA,IAAI,SAAS,eAAe,GAAG;AACjC,UAAI,IAAI,QAAQ,sBAAsB,EAAE,CAAC,IAAI;AAAA,IAAA,OACxC;AACL,UAAI,GAAG,IAAI;AAAA,IAAA;AAAA,EACb;AAEK,SAAA;AACT;AAEA,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;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CAAY,OAAO;AAAA,IACtC,aAAa,OAAO,eAAe;AAAA,IACnC,SAAS;AAAA,IACT,cAAc,OAAO,gBAAgB;AAAA,IACrC,sBAAsB,OAAO,wBAAwB;AAAA,IACrD,YAAY,OAAO;AAAA,IACnB,UAAU,OAAO;AAAA,IACjB,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,kBAAkB,OAAO;AAAA,IACzB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,MAAM,OAAO;AAAA,IACb,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,EAC/B;AAEM,QAAA,UAAU,GAAG,MAAM,iBAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAEtE,QAAM,cAAc;AACtB;"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "smartbundle",
|
3
3
|
"type": "commonjs",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.15.0-alpha.0",
|
5
5
|
"bin": {
|
6
6
|
"smartbundle": "__bin__/smartbundle.js"
|
7
7
|
},
|
@@ -25,11 +25,11 @@
|
|
25
25
|
"./package.json": "./package.json"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"semver": "^7.
|
29
|
-
"vite": "^6.
|
28
|
+
"semver": "^7.7.1",
|
29
|
+
"vite": "^6.2.4",
|
30
30
|
"yargs": "^17.7.2",
|
31
|
-
"youch": "4.1.0-beta.
|
32
|
-
"zod": "^3.24.
|
31
|
+
"youch": "4.1.0-beta.6",
|
32
|
+
"zod": "^3.24.2"
|
33
33
|
},
|
34
34
|
"repository": {
|
35
35
|
"type": "git",
|
@@ -60,14 +60,14 @@
|
|
60
60
|
"homepage": "https://github.com/xavescor/smartbundle",
|
61
61
|
"devDependencies": {
|
62
62
|
"@types/babel__core": "^7.20.5",
|
63
|
-
"@types/node": "^22.
|
64
|
-
"@types/semver": "^7.
|
63
|
+
"@types/node": "^22.13.14",
|
64
|
+
"@types/semver": "^7.7.0",
|
65
65
|
"@types/yargs": "^17.0.33",
|
66
|
-
"prettier": "^3.
|
67
|
-
"typescript": "^5.
|
68
|
-
"vitest": "^3.
|
69
|
-
"vitest-directory-snapshot": "^0.
|
70
|
-
"zx": "^8.
|
66
|
+
"prettier": "^3.5.3",
|
67
|
+
"typescript": "^5.8.2",
|
68
|
+
"vitest": "^3.1.1",
|
69
|
+
"vitest-directory-snapshot": "^0.5.0",
|
70
|
+
"zx": "^8.4.1"
|
71
71
|
},
|
72
72
|
"peerDependenciesMeta": {
|
73
73
|
"@babel/core": {
|