bunchee 4.2.7 → 4.2.9
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/dist/bin/cli.js +1 -1
- package/dist/index.js +240 -216
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
var fs = require('fs/promises');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var rollup = require('rollup');
|
|
6
|
+
var module$1 = require('module');
|
|
7
|
+
var require$$0 = require('tty');
|
|
6
8
|
var pluginWasm = require('@rollup/plugin-wasm');
|
|
7
9
|
var rollupPluginSwc3 = require('rollup-plugin-swc3');
|
|
8
10
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
@@ -12,164 +14,20 @@ var replace = require('@rollup/plugin-replace');
|
|
|
12
14
|
var esmShim = require('@rollup/plugin-esm-shim');
|
|
13
15
|
var preserveDirectives = require('rollup-preserve-directives');
|
|
14
16
|
var pluginutils = require('@rollup/pluginutils');
|
|
15
|
-
var require$$0 = require('tty');
|
|
16
17
|
var prettyBytes = require('pretty-bytes');
|
|
17
|
-
var module$1 = require('module');
|
|
18
18
|
|
|
19
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
20
|
|
|
21
21
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
22
22
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
23
|
+
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
23
24
|
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
24
25
|
var json__default = /*#__PURE__*/_interopDefault(json);
|
|
25
26
|
var replace__default = /*#__PURE__*/_interopDefault(replace);
|
|
26
27
|
var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
|
|
27
28
|
var preserveDirectives__default = /*#__PURE__*/_interopDefault(preserveDirectives);
|
|
28
|
-
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
29
29
|
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
|
|
30
30
|
|
|
31
|
-
function minifyCSS(content) {
|
|
32
|
-
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$|(?:^|\s)(\s+)|\s*([\{\};,:])\s*|\s+(!)\s+/g, (match, p1, p2, p3, p4)=>{
|
|
33
|
-
if (p1) return p1 === ' ' ? '' : p1;
|
|
34
|
-
if (p2) return ' ';
|
|
35
|
-
if (p3) return p3;
|
|
36
|
-
if (p4) return '!';
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const helpers = {
|
|
40
|
-
cssImport: {
|
|
41
|
-
// have to assign r.type = 'text/css' to make it work in Safari
|
|
42
|
-
global: `\
|
|
43
|
-
function __insertCSS(code) {
|
|
44
|
-
if (!code || typeof document == 'undefined') return
|
|
45
|
-
let head = document.head || document.getElementsByTagName('head')[0]
|
|
46
|
-
let style = document.createElement('style')
|
|
47
|
-
style.type = 'text/css'
|
|
48
|
-
head.appendChild(style)
|
|
49
|
-
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
|
|
50
|
-
}
|
|
51
|
-
`,
|
|
52
|
-
create (code) {
|
|
53
|
-
return `__insertCSS(${JSON.stringify(code)});`;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
cssAssertionImport: {
|
|
57
|
-
global: '',
|
|
58
|
-
create (code) {
|
|
59
|
-
return `\
|
|
60
|
-
const sheet = new CSSStyleSheet()
|
|
61
|
-
sheet.replaceSync(${JSON.stringify(code)})
|
|
62
|
-
export default sheet`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
function inlineCss(options) {
|
|
67
|
-
const cssIds = new Set();
|
|
68
|
-
var _options_exclude;
|
|
69
|
-
const filter = pluginutils.createFilter([
|
|
70
|
-
'**/*.css'
|
|
71
|
-
], (_options_exclude = options.exclude) != null ? _options_exclude : []);
|
|
72
|
-
// Follow up for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
|
|
73
|
-
return {
|
|
74
|
-
name: 'inline-css',
|
|
75
|
-
transform (code, id) {
|
|
76
|
-
if (!filter(id)) return;
|
|
77
|
-
if (options.skip) return '';
|
|
78
|
-
const cssCode = minifyCSS(code);
|
|
79
|
-
cssIds.add(id);
|
|
80
|
-
return {
|
|
81
|
-
code: helpers.cssImport.create(cssCode),
|
|
82
|
-
map: {
|
|
83
|
-
mappings: ''
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
renderChunk (code, options) {
|
|
88
|
-
const dependenciesIds = this.getModuleIds();
|
|
89
|
-
let foundCss = false;
|
|
90
|
-
for (const depId of dependenciesIds){
|
|
91
|
-
if (depId && cssIds.has(depId)) {
|
|
92
|
-
foundCss = true;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (!foundCss) return;
|
|
97
|
-
return {
|
|
98
|
-
code: `${helpers.cssImport.global}\n${code}`,
|
|
99
|
-
map: {
|
|
100
|
-
mappings: ''
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function rawContent({ exclude }) {
|
|
108
|
-
const filter = pluginutils.createFilter([
|
|
109
|
-
'**/*.data',
|
|
110
|
-
'**/*.txt'
|
|
111
|
-
], exclude);
|
|
112
|
-
return {
|
|
113
|
-
name: 'string',
|
|
114
|
-
transform (code, id) {
|
|
115
|
-
if (filter(id)) {
|
|
116
|
-
return {
|
|
117
|
-
code: `const data = ${JSON.stringify(code)};\nexport default data;`,
|
|
118
|
-
map: null
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Alias entries to import path
|
|
127
|
-
// e.g.
|
|
128
|
-
// For a resolved file, if it's one of the entries,
|
|
129
|
-
// aliases it as export path, such as <absolute file> -> <pkg>/<export path>
|
|
130
|
-
function aliasEntries({ entries }) {
|
|
131
|
-
return {
|
|
132
|
-
name: 'alias',
|
|
133
|
-
resolveId: {
|
|
134
|
-
async handler (source, importer, options) {
|
|
135
|
-
const resolvedId = await this.resolve(source, importer, options);
|
|
136
|
-
if (resolvedId != null) {
|
|
137
|
-
const aliasedId = entries[resolvedId.id];
|
|
138
|
-
if (aliasedId != null) {
|
|
139
|
-
return {
|
|
140
|
-
id: aliasedId,
|
|
141
|
-
external: true
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function prependDirectives() {
|
|
152
|
-
return {
|
|
153
|
-
name: 'prependDirective',
|
|
154
|
-
transform: {
|
|
155
|
-
order: 'post',
|
|
156
|
-
handler (code, id) {
|
|
157
|
-
var _moduleInfo_meta;
|
|
158
|
-
const moduleInfo = this.getModuleInfo(id);
|
|
159
|
-
if (moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives) {
|
|
160
|
-
const firstDirective = moduleInfo.meta.preserveDirectives.directives[0];
|
|
161
|
-
if (firstDirective) {
|
|
162
|
-
const directive = firstDirective.value;
|
|
163
|
-
const directiveCode = `'${directive}';`;
|
|
164
|
-
return directiveCode + '\n' + code;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
31
|
const availableExtensions = [
|
|
174
32
|
'js',
|
|
175
33
|
'cjs',
|
|
@@ -357,6 +215,186 @@ const nonNullable = (n)=>Boolean(n);
|
|
|
357
215
|
const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));
|
|
358
216
|
const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs';
|
|
359
217
|
|
|
218
|
+
let hasLoggedTsWarning = false;
|
|
219
|
+
function resolveTypescript(cwd) {
|
|
220
|
+
let ts;
|
|
221
|
+
const m = new module$1.Module('', undefined);
|
|
222
|
+
m.paths = module$1.Module._nodeModulePaths(cwd);
|
|
223
|
+
try {
|
|
224
|
+
ts = m.require('typescript');
|
|
225
|
+
} catch (_) {
|
|
226
|
+
console.error(_);
|
|
227
|
+
if (!hasLoggedTsWarning) {
|
|
228
|
+
hasLoggedTsWarning = true;
|
|
229
|
+
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return ts;
|
|
233
|
+
}
|
|
234
|
+
async function resolveTsConfig(cwd) {
|
|
235
|
+
let tsCompilerOptions = {};
|
|
236
|
+
let tsConfigPath;
|
|
237
|
+
tsConfigPath = path.resolve(cwd, 'tsconfig.json');
|
|
238
|
+
if (await fileExists(tsConfigPath)) {
|
|
239
|
+
const ts = resolveTypescript(cwd);
|
|
240
|
+
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd;
|
|
241
|
+
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
|
|
242
|
+
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options;
|
|
243
|
+
} else {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
tsCompilerOptions,
|
|
248
|
+
tsConfigPath
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async function convertCompilerOptions(cwd, json) {
|
|
252
|
+
const ts = resolveTypescript(cwd);
|
|
253
|
+
return ts.convertCompilerOptionsFromJson(json, './');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function minifyCSS(content) {
|
|
257
|
+
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$|(?:^|\s)(\s+)|\s*([\{\};,:])\s*|\s+(!)\s+/g, (match, p1, p2, p3, p4)=>{
|
|
258
|
+
if (p1) return p1 === ' ' ? '' : p1;
|
|
259
|
+
if (p2) return ' ';
|
|
260
|
+
if (p3) return p3;
|
|
261
|
+
if (p4) return '!';
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const helpers = {
|
|
265
|
+
cssImport: {
|
|
266
|
+
// have to assign r.type = 'text/css' to make it work in Safari
|
|
267
|
+
global: `\
|
|
268
|
+
function __insertCSS(code) {
|
|
269
|
+
if (!code || typeof document == 'undefined') return
|
|
270
|
+
let head = document.head || document.getElementsByTagName('head')[0]
|
|
271
|
+
let style = document.createElement('style')
|
|
272
|
+
style.type = 'text/css'
|
|
273
|
+
head.appendChild(style)
|
|
274
|
+
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
|
|
275
|
+
}
|
|
276
|
+
`,
|
|
277
|
+
create (code) {
|
|
278
|
+
return `__insertCSS(${JSON.stringify(code)});`;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
cssAssertionImport: {
|
|
282
|
+
global: '',
|
|
283
|
+
create (code) {
|
|
284
|
+
return `\
|
|
285
|
+
const sheet = new CSSStyleSheet()
|
|
286
|
+
sheet.replaceSync(${JSON.stringify(code)})
|
|
287
|
+
export default sheet`;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
function inlineCss(options) {
|
|
292
|
+
const cssIds = new Set();
|
|
293
|
+
var _options_exclude;
|
|
294
|
+
const filter = pluginutils.createFilter([
|
|
295
|
+
'**/*.css'
|
|
296
|
+
], (_options_exclude = options.exclude) != null ? _options_exclude : []);
|
|
297
|
+
// Follow up for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
|
|
298
|
+
return {
|
|
299
|
+
name: 'inline-css',
|
|
300
|
+
transform (code, id) {
|
|
301
|
+
if (!filter(id)) return;
|
|
302
|
+
if (options.skip) return '';
|
|
303
|
+
const cssCode = minifyCSS(code);
|
|
304
|
+
cssIds.add(id);
|
|
305
|
+
return {
|
|
306
|
+
code: helpers.cssImport.create(cssCode),
|
|
307
|
+
map: {
|
|
308
|
+
mappings: ''
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
renderChunk (code, options) {
|
|
313
|
+
const dependenciesIds = this.getModuleIds();
|
|
314
|
+
let foundCss = false;
|
|
315
|
+
for (const depId of dependenciesIds){
|
|
316
|
+
if (depId && cssIds.has(depId)) {
|
|
317
|
+
foundCss = true;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!foundCss) return;
|
|
322
|
+
return {
|
|
323
|
+
code: `${helpers.cssImport.global}\n${code}`,
|
|
324
|
+
map: {
|
|
325
|
+
mappings: ''
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function rawContent({ exclude }) {
|
|
333
|
+
const filter = pluginutils.createFilter([
|
|
334
|
+
'**/*.data',
|
|
335
|
+
'**/*.txt'
|
|
336
|
+
], exclude);
|
|
337
|
+
return {
|
|
338
|
+
name: 'string',
|
|
339
|
+
transform (code, id) {
|
|
340
|
+
if (filter(id)) {
|
|
341
|
+
return {
|
|
342
|
+
code: `const data = ${JSON.stringify(code)};\nexport default data;`,
|
|
343
|
+
map: null
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Alias entries to import path
|
|
352
|
+
// e.g.
|
|
353
|
+
// For a resolved file, if it's one of the entries,
|
|
354
|
+
// aliases it as export path, such as <absolute file> -> <pkg>/<export path>
|
|
355
|
+
function aliasEntries({ entries }) {
|
|
356
|
+
return {
|
|
357
|
+
name: 'alias',
|
|
358
|
+
resolveId: {
|
|
359
|
+
async handler (source, importer, options) {
|
|
360
|
+
const resolvedId = await this.resolve(source, importer, options);
|
|
361
|
+
if (resolvedId != null) {
|
|
362
|
+
const aliasedId = entries[resolvedId.id];
|
|
363
|
+
if (aliasedId != null) {
|
|
364
|
+
return {
|
|
365
|
+
id: aliasedId,
|
|
366
|
+
external: true
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function prependDirectives() {
|
|
377
|
+
return {
|
|
378
|
+
name: 'prependDirective',
|
|
379
|
+
transform: {
|
|
380
|
+
order: 'post',
|
|
381
|
+
handler (code, id) {
|
|
382
|
+
var _moduleInfo_meta;
|
|
383
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
384
|
+
if (moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives) {
|
|
385
|
+
const firstDirective = moduleInfo.meta.preserveDirectives.directives[0];
|
|
386
|
+
if (firstDirective) {
|
|
387
|
+
const directive = firstDirective.value;
|
|
388
|
+
const directiveCode = `'${directive}';`;
|
|
389
|
+
return directiveCode + '\n' + code;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
360
398
|
function getTypings(pkg) {
|
|
361
399
|
return pkg.types || pkg.typings;
|
|
362
400
|
}
|
|
@@ -397,23 +435,32 @@ function joinRelativePath(...segments) {
|
|
|
397
435
|
}
|
|
398
436
|
return result;
|
|
399
437
|
}
|
|
400
|
-
function findExport(exportPath, exportCondition, paths, packageType) {
|
|
438
|
+
function findExport(exportPath, exportCondition, paths, packageType, currentPath) {
|
|
401
439
|
// Skip `types` field, it cannot be the entry point
|
|
402
440
|
if (exportPath === 'types') return;
|
|
403
441
|
if (isExportLike(exportCondition)) {
|
|
404
442
|
const fullExportCondition = constructFullExportCondition(exportCondition, packageType);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
443
|
+
if (exportPath.startsWith('.')) {
|
|
444
|
+
paths[exportPath] = {
|
|
445
|
+
...paths[exportPath],
|
|
446
|
+
...fullExportCondition
|
|
447
|
+
};
|
|
448
|
+
} else {
|
|
449
|
+
// exportPath is exportType, import, require, ...
|
|
450
|
+
// merge to currentPath
|
|
451
|
+
paths[currentPath] = {
|
|
452
|
+
...paths[currentPath],
|
|
453
|
+
[exportPath]: fullExportCondition.default
|
|
454
|
+
};
|
|
455
|
+
}
|
|
409
456
|
return;
|
|
410
457
|
}
|
|
411
458
|
Object.keys(exportCondition).forEach((subpath)=>{
|
|
412
459
|
if (subpath.startsWith('.')) {
|
|
413
460
|
// subpath is actual export path, ./a, ./b, ...
|
|
414
|
-
const nestedExportPath = joinRelativePath(
|
|
461
|
+
const nestedExportPath = joinRelativePath(currentPath, subpath);
|
|
415
462
|
const nestedExportCondition = exportCondition[subpath];
|
|
416
|
-
findExport(nestedExportPath, nestedExportCondition, paths, packageType);
|
|
463
|
+
findExport(nestedExportPath, nestedExportCondition, paths, packageType, nestedExportPath);
|
|
417
464
|
} else {
|
|
418
465
|
// subpath is exportType, import, require, ...
|
|
419
466
|
const exportType = subpath;
|
|
@@ -421,7 +468,7 @@ function findExport(exportPath, exportCondition, paths, packageType) {
|
|
|
421
468
|
const nestedExportCondition = {
|
|
422
469
|
[exportType]: defaultPath
|
|
423
470
|
};
|
|
424
|
-
findExport(exportPath, nestedExportCondition, paths, packageType);
|
|
471
|
+
findExport(exportPath, nestedExportCondition, paths, packageType, currentPath);
|
|
425
472
|
}
|
|
426
473
|
});
|
|
427
474
|
}
|
|
@@ -451,15 +498,16 @@ function findExport(exportPath, exportCondition, paths, packageType) {
|
|
|
451
498
|
*
|
|
452
499
|
*/ function parseExport(exportsCondition, packageType) {
|
|
453
500
|
const paths = {};
|
|
501
|
+
const initialPath = '.';
|
|
454
502
|
if (typeof exportsCondition === 'string') {
|
|
455
|
-
paths[
|
|
503
|
+
paths[initialPath] = constructFullExportCondition(exportsCondition, packageType);
|
|
456
504
|
} else if (typeof exportsCondition === 'object') {
|
|
457
505
|
if (isExportLike(exportsCondition)) {
|
|
458
|
-
paths[
|
|
506
|
+
paths[initialPath] = constructFullExportCondition(exportsCondition, packageType);
|
|
459
507
|
} else {
|
|
460
508
|
Object.keys(exportsCondition).forEach((key)=>{
|
|
461
509
|
const exportCondition = exportsCondition[key];
|
|
462
|
-
findExport(key, exportCondition, paths, packageType);
|
|
510
|
+
findExport(key, exportCondition, paths, packageType, initialPath);
|
|
463
511
|
});
|
|
464
512
|
}
|
|
465
513
|
}
|
|
@@ -506,13 +554,16 @@ function findExport(exportPath, exportCondition, paths, packageType) {
|
|
|
506
554
|
* pkg.main and pkg.module will be added to ['.'] if exists
|
|
507
555
|
*/ function getExportPaths(pkg, pkgType, resolvedWildcardExports) {
|
|
508
556
|
var _pathsMap_;
|
|
509
|
-
|
|
557
|
+
let pathsMap = {};
|
|
510
558
|
const packageType = pkgType != null ? pkgType : getPackageType(pkg);
|
|
511
559
|
const isEsmPackage = isESModulePackage(packageType);
|
|
512
560
|
const exportsConditions = resolvedWildcardExports != null ? resolvedWildcardExports : pkg.exports;
|
|
513
561
|
if (exportsConditions) {
|
|
514
562
|
const paths = parseExport(exportsConditions, packageType);
|
|
515
|
-
|
|
563
|
+
pathsMap = {
|
|
564
|
+
...pathsMap,
|
|
565
|
+
...paths
|
|
566
|
+
};
|
|
516
567
|
}
|
|
517
568
|
if (isEsmPackage && pkg.main && hasCjsExtension(pkg.main)) {
|
|
518
569
|
exit('Cannot export main field with .cjs extension in ESM package, only .mjs and .js extensions are allowed');
|
|
@@ -528,10 +579,16 @@ function findExport(exportPath, exportCondition, paths, packageType) {
|
|
|
528
579
|
defaultMainExport['require'] = pathsMap['.']['require'];
|
|
529
580
|
}
|
|
530
581
|
// Merge the main export into '.' paths
|
|
531
|
-
const mainExport =
|
|
582
|
+
const mainExport = {
|
|
583
|
+
...pathsMap['.'],
|
|
584
|
+
...defaultMainExport
|
|
585
|
+
};
|
|
532
586
|
// main export is not empty
|
|
533
587
|
if (Object.keys(mainExport).length > 0) {
|
|
534
|
-
pathsMap['.'] =
|
|
588
|
+
pathsMap['.'] = {
|
|
589
|
+
...pathsMap['.'],
|
|
590
|
+
...mainExport
|
|
591
|
+
};
|
|
535
592
|
}
|
|
536
593
|
return pathsMap;
|
|
537
594
|
}
|
|
@@ -739,7 +796,7 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
739
796
|
})
|
|
740
797
|
];
|
|
741
798
|
if (useTypescript) {
|
|
742
|
-
const overrideResolvedTsOptions = {
|
|
799
|
+
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
|
|
743
800
|
declaration: true,
|
|
744
801
|
noEmit: false,
|
|
745
802
|
noEmitOnError: true,
|
|
@@ -747,22 +804,21 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
747
804
|
checkJs: false,
|
|
748
805
|
declarationMap: false,
|
|
749
806
|
skipLibCheck: true,
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
delete mergedOptions.tsBuildInfoFile;
|
|
807
|
+
target: 'ESNext',
|
|
808
|
+
// Some react types required this to be false by default.
|
|
809
|
+
// Some type package like express might need this as it has other dependencies.
|
|
810
|
+
// Let users able to toggle this in tsconfig.
|
|
811
|
+
preserveSymlinks: 'preserveSymlinks' in tsCompilerOptions ? tsCompilerOptions.preserveSymlinks : false,
|
|
812
|
+
...!tsCompilerOptions.jsx ? {
|
|
813
|
+
jsx: 'react-jsx'
|
|
814
|
+
} : undefined,
|
|
815
|
+
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
|
|
816
|
+
// file or when option '--tsBuildInfoFile' is specified.
|
|
817
|
+
incremental: false
|
|
818
|
+
});
|
|
763
819
|
const dtsPlugin = require('rollup-plugin-dts').default({
|
|
764
|
-
tsconfig:
|
|
765
|
-
compilerOptions:
|
|
820
|
+
tsconfig: tsConfigPath,
|
|
821
|
+
compilerOptions: overrideResolvedTsOptions
|
|
766
822
|
});
|
|
767
823
|
typesPlugins.push(dtsPlugin);
|
|
768
824
|
}
|
|
@@ -774,6 +830,7 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
774
830
|
rawContent({
|
|
775
831
|
exclude: /node_modules/
|
|
776
832
|
}),
|
|
833
|
+
esmShim__default.default(),
|
|
777
834
|
preserveDirectives__default.default(),
|
|
778
835
|
prependDirectives(),
|
|
779
836
|
replace__default.default({
|
|
@@ -794,8 +851,7 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
794
851
|
exclude: 'node_modules',
|
|
795
852
|
tsconfig: tsConfigPath,
|
|
796
853
|
...swcOptions
|
|
797
|
-
})
|
|
798
|
-
esmShim__default.default()
|
|
854
|
+
})
|
|
799
855
|
]).filter(isNotNull);
|
|
800
856
|
return {
|
|
801
857
|
input: entry,
|
|
@@ -1021,10 +1077,12 @@ async function buildEntryConfig(entries, pkg, exportPaths, bundleConfig, cwd, ts
|
|
|
1021
1077
|
}
|
|
1022
1078
|
const collectEntriesPromises = Object.keys(exportPaths).map(async (entryExport)=>{
|
|
1023
1079
|
const exportCond = exportPaths[entryExport];
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1080
|
+
if (entryExport.startsWith('.')) {
|
|
1081
|
+
await collectEntry('', exportCond, entryExport);
|
|
1082
|
+
for (const exportType of availableExportConventions){
|
|
1083
|
+
if (exportCond[exportType]) {
|
|
1084
|
+
await collectEntry(exportType, exportCond, entryExport);
|
|
1085
|
+
}
|
|
1028
1086
|
}
|
|
1029
1087
|
}
|
|
1030
1088
|
});
|
|
@@ -1148,40 +1206,6 @@ function logSizeStats(sizeCollector) {
|
|
|
1148
1206
|
});
|
|
1149
1207
|
}
|
|
1150
1208
|
|
|
1151
|
-
let hasLoggedTsWarning = false;
|
|
1152
|
-
function resolveTypescript(cwd) {
|
|
1153
|
-
let ts;
|
|
1154
|
-
const m = new module$1.Module('', undefined);
|
|
1155
|
-
m.paths = module$1.Module._nodeModulePaths(cwd);
|
|
1156
|
-
try {
|
|
1157
|
-
ts = m.require('typescript');
|
|
1158
|
-
} catch (_) {
|
|
1159
|
-
console.error(_);
|
|
1160
|
-
if (!hasLoggedTsWarning) {
|
|
1161
|
-
hasLoggedTsWarning = true;
|
|
1162
|
-
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency');
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
return ts;
|
|
1166
|
-
}
|
|
1167
|
-
async function resolveTsConfig(cwd) {
|
|
1168
|
-
let tsCompilerOptions = {};
|
|
1169
|
-
let tsConfigPath;
|
|
1170
|
-
tsConfigPath = path.resolve(cwd, 'tsconfig.json');
|
|
1171
|
-
if (await fileExists(tsConfigPath)) {
|
|
1172
|
-
const ts = resolveTypescript(cwd);
|
|
1173
|
-
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd;
|
|
1174
|
-
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
|
|
1175
|
-
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options;
|
|
1176
|
-
} else {
|
|
1177
|
-
return null;
|
|
1178
|
-
}
|
|
1179
|
-
return {
|
|
1180
|
-
tsCompilerOptions,
|
|
1181
|
-
tsConfigPath
|
|
1182
|
-
};
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
1209
|
// TODO: support nested wildcard exportsCondition (e.g. './foo/*')
|
|
1186
1210
|
const getWildcardExports = (exportsCondition)=>{
|
|
1187
1211
|
return {
|