@astral/pack 1.9.1 → 2.0.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 +104 -24
- package/commands/generatePackageJson/generatePackageJson.js +59 -8
- package/config/ConfigService/ConfigService.d.ts +0 -1
- package/config/ConfigService/ConfigService.js +0 -3
- package/config/ConfigService/validation.js +0 -22
- package/config/types.d.ts +0 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,6 +20,59 @@ yarn add @astral/utils
|
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
+
## Migration Guide v1 -> v2
|
|
24
|
+
|
|
25
|
+
### Удалено свойство `packageExports` из конфигурации
|
|
26
|
+
|
|
27
|
+
**v1**
|
|
28
|
+
```js
|
|
29
|
+
// pack.config.js
|
|
30
|
+
module.exports = defineConfig({
|
|
31
|
+
packageExports: {
|
|
32
|
+
'./components/Button': {
|
|
33
|
+
module: './components/Button/index.js',
|
|
34
|
+
require: './node/components/Button/index.js',
|
|
35
|
+
types: './components/Button/index.d.ts',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**v2**
|
|
42
|
+
|
|
43
|
+
Теперь экспорты задаются через исходный `package.json`:
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"exports": {
|
|
47
|
+
"./components/Button": "./components/Button/index.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Строковые экспорты автоматически расширяются в полные объекты с учетом настроек `format` и `lang` из `pack.config.js`:
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"module": "./index.js",
|
|
58
|
+
"require": "./node/index.js",
|
|
59
|
+
"types": "./index.d.ts",
|
|
60
|
+
"default": "./index.js",
|
|
61
|
+
"import": "./index.js"
|
|
62
|
+
},
|
|
63
|
+
"./components/Button": {
|
|
64
|
+
"module": "./components/Button/index.js",
|
|
65
|
+
"require": "./node/components/Button/index.js",
|
|
66
|
+
"types": "./components/Button/index.d.ts",
|
|
67
|
+
"default": "./components/Button/index.js",
|
|
68
|
+
"import": "./components/Button/index.js"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
23
76
|
## Build
|
|
24
77
|
|
|
25
78
|
`pack.config.js`
|
|
@@ -36,14 +89,6 @@ module.exports = defineConfig({
|
|
|
36
89
|
filter: ['src/**/*.d.ts'],
|
|
37
90
|
ignoreSrc: true,
|
|
38
91
|
},
|
|
39
|
-
// Добавит к root exports дополнительный
|
|
40
|
-
packageExports: {
|
|
41
|
-
'./server': {
|
|
42
|
-
module: './server/index.js',
|
|
43
|
-
require: './node/server/index.js',
|
|
44
|
-
types: './server/index.d.ts',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
92
|
});
|
|
48
93
|
```
|
|
49
94
|
|
|
@@ -74,27 +119,62 @@ pack create-release
|
|
|
74
119
|
## Exports
|
|
75
120
|
|
|
76
121
|
По-дефолту добавляет exports вида:
|
|
77
|
-
```
|
|
122
|
+
```json
|
|
78
123
|
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
"exports": {
|
|
125
|
+
".": {
|
|
126
|
+
"module": "./index.js",
|
|
127
|
+
"require": "./node/index.js",
|
|
128
|
+
"types": "./index.d.ts",
|
|
129
|
+
"default": "./index.js",
|
|
130
|
+
"import": "./index.js"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
84
133
|
}
|
|
85
134
|
```
|
|
86
135
|
|
|
87
|
-
Для добавления
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
136
|
+
Для добавления дополнительных exports укажите их в исходном `package.json`:
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"exports": {
|
|
140
|
+
"./server": "./server/index.js",
|
|
141
|
+
"./components/Button": "./components/Button/index.js"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Строковые экспорты автоматически расширяются в полные объекты с учетом настроек `format` и `lang`:
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"exports": {
|
|
150
|
+
".": {
|
|
151
|
+
"module": "./index.js",
|
|
152
|
+
"require": "./node/index.js",
|
|
153
|
+
"types": "./index.d.ts",
|
|
154
|
+
"default": "./index.js",
|
|
155
|
+
"import": "./index.js"
|
|
95
156
|
},
|
|
96
|
-
|
|
97
|
-
|
|
157
|
+
"./server": {
|
|
158
|
+
"module": "./server/index.js",
|
|
159
|
+
"require": "./node/server/index.js",
|
|
160
|
+
"types": "./server/index.d.ts",
|
|
161
|
+
"default": "./server/index.js",
|
|
162
|
+
"import": "./server/index.js"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Если нужен полный контроль, можно указать объект напрямую:
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"exports": {
|
|
172
|
+
"./custom": {
|
|
173
|
+
"module": "./custom/special.js",
|
|
174
|
+
"require": "./custom/special.cjs"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
98
178
|
```
|
|
99
179
|
|
|
100
180
|
## Настройка веток для semantic-release
|
|
@@ -39,15 +39,49 @@ const initUpdatingReleaseGroup = (config, packageVersion) => (originPackageJson)
|
|
|
39
39
|
}, dependencies),
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Преобразует строковый экспорт в полный объект экспорта
|
|
44
|
+
*/
|
|
45
|
+
const expandStringExport = (value, format, lang) => {
|
|
46
|
+
const exportItem = {};
|
|
47
|
+
if (format.includes('esm')) {
|
|
48
|
+
exportItem.module = value;
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
if (format.includes('cjs')) {
|
|
51
|
+
// Добавляем ./node/ перед путем для require
|
|
52
|
+
exportItem.require = value.startsWith('./')
|
|
53
|
+
? `./node/${value.slice(2)}`
|
|
54
|
+
: `./node/${value}`;
|
|
55
|
+
}
|
|
56
|
+
if (lang === 'ts') {
|
|
57
|
+
// Заменяем .js на .d.ts для типов
|
|
58
|
+
exportItem.types = value.replace(/\.js$/, '.d.ts');
|
|
50
59
|
}
|
|
60
|
+
exportItem.default = value;
|
|
61
|
+
exportItem.import = value;
|
|
62
|
+
return exportItem;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Обрабатывает и расширяет экспорты из объекта
|
|
66
|
+
*/
|
|
67
|
+
const expandExportsObject = (exports, format, lang) => {
|
|
68
|
+
return Object.entries(exports).reduce((acc, [key, value]) => {
|
|
69
|
+
// Пропускаем корневой экспорт '.'
|
|
70
|
+
if (key === '.') {
|
|
71
|
+
return acc;
|
|
72
|
+
}
|
|
73
|
+
acc[key] =
|
|
74
|
+
typeof value === 'string'
|
|
75
|
+
? expandStringExport(value, format, lang)
|
|
76
|
+
: value;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Создает корневой экспорт для package.json
|
|
82
|
+
*/
|
|
83
|
+
const createRootExport = (format, lang) => {
|
|
84
|
+
const rootExports = {};
|
|
51
85
|
if (format.includes('esm')) {
|
|
52
86
|
rootExports.module = './index.js';
|
|
53
87
|
}
|
|
@@ -59,11 +93,28 @@ const initExportsGenerator = ({ packageExports, format, lang }) => (originPackag
|
|
|
59
93
|
}
|
|
60
94
|
rootExports.default = './index.js';
|
|
61
95
|
rootExports.import = './index.js';
|
|
96
|
+
return rootExports;
|
|
97
|
+
};
|
|
98
|
+
const initExportsGenerator = ({ format, lang }) => (originPackageJson) => {
|
|
99
|
+
if (format.length === 1 && format.includes('cjs')) {
|
|
100
|
+
const { exports, ...packageJson } = originPackageJson;
|
|
101
|
+
return packageJson;
|
|
102
|
+
}
|
|
103
|
+
const rootExports = createRootExport(format, lang);
|
|
104
|
+
if (typeof rootExports === 'string') {
|
|
105
|
+
return originPackageJson;
|
|
106
|
+
}
|
|
107
|
+
const originExports = originPackageJson.exports &&
|
|
108
|
+
typeof originPackageJson.exports === 'object' &&
|
|
109
|
+
!Array.isArray(originPackageJson.exports)
|
|
110
|
+
? originPackageJson.exports
|
|
111
|
+
: {};
|
|
112
|
+
const expandedOriginExports = expandExportsObject(originExports, format, lang);
|
|
62
113
|
return {
|
|
63
114
|
...originPackageJson,
|
|
64
115
|
exports: {
|
|
65
116
|
'.': rootExports,
|
|
66
|
-
...
|
|
117
|
+
...expandedOriginExports,
|
|
67
118
|
},
|
|
68
119
|
};
|
|
69
120
|
};
|
|
@@ -28,7 +28,6 @@ export declare class ConfigService {
|
|
|
28
28
|
releaseGroup?: string[];
|
|
29
29
|
releaseBranches?: import("semantic-release").BranchSpec[];
|
|
30
30
|
};
|
|
31
|
-
get packageExports(): import("../types").PackageExports | undefined;
|
|
32
31
|
get omitPackageJsonProps(): string[] | undefined;
|
|
33
32
|
get overridePackageJson(): Record<string, unknown> | undefined;
|
|
34
33
|
parseOriginPackageJson: ({ ignoreMain, }?: {
|
|
@@ -54,28 +54,6 @@ exports.validateConfig = v.object({
|
|
|
54
54
|
prerelease: v.optional(v.or(v.string(), v.boolean())),
|
|
55
55
|
}))))),
|
|
56
56
|
}),
|
|
57
|
-
packageExports: (value) => {
|
|
58
|
-
if (!value) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
const objectError = v.optional(v.object({}))(value);
|
|
62
|
-
if (objectError) {
|
|
63
|
-
return objectError;
|
|
64
|
-
}
|
|
65
|
-
const errors = Object.values(value)
|
|
66
|
-
.map((exportValue) => {
|
|
67
|
-
if (typeof exportValue === 'string') {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
return v.object({
|
|
71
|
-
require: v.string(),
|
|
72
|
-
module: v.string(),
|
|
73
|
-
types: v.string(),
|
|
74
|
-
})(exportValue);
|
|
75
|
-
})
|
|
76
|
-
.filter(Boolean);
|
|
77
|
-
return errors[0];
|
|
78
|
-
},
|
|
79
57
|
omitPackageJsonProps: v.optional(v.array(v.arrayItem(v.string()))),
|
|
80
58
|
overridePackageJson: v.optional(v.object({})),
|
|
81
59
|
});
|
package/config/types.d.ts
CHANGED
|
@@ -70,10 +70,6 @@ export type PackConfig = {
|
|
|
70
70
|
*/
|
|
71
71
|
tsConfigName?: string;
|
|
72
72
|
semanticRelease: SemanticReleaseConfig;
|
|
73
|
-
/**
|
|
74
|
-
* exports свойство package.json
|
|
75
|
-
*/
|
|
76
|
-
packageExports?: PackageExports;
|
|
77
73
|
/**
|
|
78
74
|
* Удаляет указанные props в сгенерированном package.json
|
|
79
75
|
*/
|