bunchee 4.3.1 → 4.3.2
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 +7 -15
- package/dist/index.js +38 -28
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var path = require('path');
|
|
3
3
|
var arg = require('arg');
|
|
4
|
+
var fs = require('fs');
|
|
4
5
|
var fsp = require('fs/promises');
|
|
5
6
|
var require$$0 = require('tty');
|
|
6
7
|
var bunchee = require('bunchee');
|
|
7
|
-
var fs = require('fs');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
12
|
var arg__default = /*#__PURE__*/_interopDefault(arg);
|
|
13
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
13
14
|
var fsp__default = /*#__PURE__*/_interopDefault(fsp);
|
|
14
15
|
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
15
|
-
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
16
16
|
|
|
17
17
|
const availableExtensions = [
|
|
18
18
|
'js',
|
|
@@ -119,8 +119,8 @@ function exit(err) {
|
|
|
119
119
|
logger.error(err);
|
|
120
120
|
process.exit(1);
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
return
|
|
122
|
+
function hasPackageJson(cwd) {
|
|
123
|
+
return fileExists(path__default.default.resolve(cwd, 'package.json'));
|
|
124
124
|
}
|
|
125
125
|
async function getPackageMeta(cwd) {
|
|
126
126
|
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
@@ -136,21 +136,13 @@ function isTypescriptFile(filename) {
|
|
|
136
136
|
const ext = path__default.default.extname(filename).slice(1);
|
|
137
137
|
return tsExtensions.includes(ext);
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
await fsp__default.default.access(filePath);
|
|
142
|
-
return true;
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (err.code === 'ENOENT') {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
throw err;
|
|
148
|
-
}
|
|
139
|
+
function fileExists(filePath) {
|
|
140
|
+
return fs__default.default.existsSync(filePath);
|
|
149
141
|
}
|
|
150
142
|
const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));
|
|
151
143
|
const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
|
|
152
144
|
|
|
153
|
-
var version = "4.3.
|
|
145
|
+
var version = "4.3.2";
|
|
154
146
|
|
|
155
147
|
function relativify(path) {
|
|
156
148
|
return path.startsWith('.') ? path : `./${path}`;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var fs = require('fs/promises');
|
|
4
|
-
var path = require('path');
|
|
5
3
|
var rollup = require('rollup');
|
|
4
|
+
var fsp = require('fs/promises');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
6
7
|
var module$1 = require('module');
|
|
7
8
|
var require$$0 = require('tty');
|
|
8
9
|
var pluginWasm = require('@rollup/plugin-wasm');
|
|
@@ -18,6 +19,7 @@ var prettyBytes = require('pretty-bytes');
|
|
|
18
19
|
|
|
19
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
21
|
|
|
22
|
+
var fsp__default = /*#__PURE__*/_interopDefault(fsp);
|
|
21
23
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
22
24
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
23
25
|
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
|
@@ -146,22 +148,14 @@ async function getPackageMeta(cwd) {
|
|
|
146
148
|
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
147
149
|
let targetPackageJson = {};
|
|
148
150
|
try {
|
|
149
|
-
targetPackageJson = JSON.parse(await
|
|
151
|
+
targetPackageJson = JSON.parse(await fsp__default.default.readFile(pkgFilePath, {
|
|
150
152
|
encoding: 'utf-8'
|
|
151
153
|
}));
|
|
152
154
|
} catch (_) {}
|
|
153
155
|
return targetPackageJson;
|
|
154
156
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await fs__default.default.access(filePath);
|
|
158
|
-
return true;
|
|
159
|
-
} catch (err) {
|
|
160
|
-
if (err.code === 'ENOENT') {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
throw err;
|
|
164
|
-
}
|
|
157
|
+
function fileExists(filePath) {
|
|
158
|
+
return fs__default.default.existsSync(filePath);
|
|
165
159
|
}
|
|
166
160
|
// . -> pkg name
|
|
167
161
|
// ./lite -> <pkg name>/lite
|
|
@@ -174,14 +168,14 @@ const isNotNull = (n)=>Boolean(n);
|
|
|
174
168
|
function resolveSourceFile(cwd, filename) {
|
|
175
169
|
return path__default.default.resolve(cwd, SRC, filename);
|
|
176
170
|
}
|
|
177
|
-
|
|
171
|
+
function findSourceEntryFile(cwd, exportPath, exportTypeSuffix, ext) {
|
|
178
172
|
const filename = resolveSourceFile(cwd, `${exportPath}${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`);
|
|
179
|
-
if (
|
|
173
|
+
if (fileExists(filename)) {
|
|
180
174
|
return filename;
|
|
181
175
|
}
|
|
182
176
|
const subFolderIndexFilename = resolveSourceFile(cwd, `${exportPath}/index${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`);
|
|
183
177
|
try {
|
|
184
|
-
if (
|
|
178
|
+
if (fileExists(subFolderIndexFilename)) {
|
|
185
179
|
return subFolderIndexFilename;
|
|
186
180
|
}
|
|
187
181
|
} catch {}
|
|
@@ -230,11 +224,11 @@ function resolveTypescript(cwd) {
|
|
|
230
224
|
}
|
|
231
225
|
return ts;
|
|
232
226
|
}
|
|
233
|
-
|
|
227
|
+
function resolveTsConfig(cwd) {
|
|
234
228
|
let tsCompilerOptions = {};
|
|
235
229
|
let tsConfigPath;
|
|
236
230
|
tsConfigPath = path.resolve(cwd, 'tsconfig.json');
|
|
237
|
-
if (
|
|
231
|
+
if (fileExists(tsConfigPath)) {
|
|
238
232
|
const ts = resolveTypescript(cwd);
|
|
239
233
|
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd;
|
|
240
234
|
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
|
|
@@ -1151,6 +1145,8 @@ function relativify(path) {
|
|
|
1151
1145
|
return path.startsWith('.') ? path : `./${path}`;
|
|
1152
1146
|
}
|
|
1153
1147
|
|
|
1148
|
+
// Example: @foo/bar -> bar
|
|
1149
|
+
const removeScope = (exportPath)=>exportPath.replace(/^@[^/]+\//, '');
|
|
1154
1150
|
function createOutputState({ entries }) {
|
|
1155
1151
|
const sizeStats = new Map();
|
|
1156
1152
|
function addSize({ fileName, size, sourceFileName, exportPath }) {
|
|
@@ -1183,7 +1179,7 @@ function createOutputState({ entries }) {
|
|
|
1183
1179
|
}
|
|
1184
1180
|
const size = chunk.code.length;
|
|
1185
1181
|
const sourceFileName = chunk.facadeModuleId || '';
|
|
1186
|
-
const exportPath = reversedMapping.get(sourceFileName) || '.';
|
|
1182
|
+
const exportPath = removeScope(reversedMapping.get(sourceFileName) || '.');
|
|
1187
1183
|
addSize({
|
|
1188
1184
|
fileName: path__default.default.isAbsolute(cwd) ? path__default.default.relative(cwd, filePath) : filePath,
|
|
1189
1185
|
size,
|
|
@@ -1275,7 +1271,7 @@ const getWildcardExports = (exportsCondition)=>{
|
|
|
1275
1271
|
};
|
|
1276
1272
|
const isExportable = async (dirent, pathname)=>{
|
|
1277
1273
|
if (dirent.isDirectory()) {
|
|
1278
|
-
const innerDirents = await
|
|
1274
|
+
const innerDirents = await fsp__default.default.readdir(path__default.default.join(pathname, dirent.name), {
|
|
1279
1275
|
withFileTypes: true
|
|
1280
1276
|
});
|
|
1281
1277
|
return innerDirents.some(({ name })=>name.startsWith('index') && hasAvailableExtension(name));
|
|
@@ -1284,7 +1280,7 @@ const isExportable = async (dirent, pathname)=>{
|
|
|
1284
1280
|
};
|
|
1285
1281
|
async function getExportables(cwd, excludeKeys) {
|
|
1286
1282
|
const pathname = path__default.default.resolve(cwd, SRC);
|
|
1287
|
-
const dirents = await
|
|
1283
|
+
const dirents = await fsp__default.default.readdir(pathname, {
|
|
1288
1284
|
withFileTypes: true
|
|
1289
1285
|
});
|
|
1290
1286
|
const exportables = await Promise.all(dirents.map(async (dirent)=>await isExportable(dirent, pathname) && !excludeKeys.includes(dirent.name) ? dirent.name : undefined));
|
|
@@ -1386,12 +1382,21 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1386
1382
|
}
|
|
1387
1383
|
return runBundle(rollupConfig);
|
|
1388
1384
|
};
|
|
1389
|
-
const hasSpecifiedEntryFile = entryPath ?
|
|
1385
|
+
const hasSpecifiedEntryFile = entryPath ? fs__default.default.existsSync(entryPath) && (await fsp__default.default.stat(entryPath)).isFile() : false;
|
|
1390
1386
|
const hasNoEntry = !hasSpecifiedEntryFile && !isMultiEntries && !hasBin;
|
|
1391
1387
|
if (hasNoEntry) {
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1388
|
+
if (entryPath) {
|
|
1389
|
+
const err = new Error(`Entry file "${entryPath}" does not exist`);
|
|
1390
|
+
err.name = 'NOT_EXISTED';
|
|
1391
|
+
return Promise.reject(err);
|
|
1392
|
+
} else if (cwd) {
|
|
1393
|
+
const hasProjectDir = fs__default.default.existsSync(cwd) && (await fsp__default.default.stat(cwd)).isDirectory();
|
|
1394
|
+
if (!hasProjectDir) {
|
|
1395
|
+
const err = new Error(`Project directory "${cwd}" does not exist`);
|
|
1396
|
+
err.name = 'NOT_EXISTED';
|
|
1397
|
+
return Promise.reject(err);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1395
1400
|
}
|
|
1396
1401
|
const entries = await collectEntries(pkg, entryPath, exportPaths, cwd);
|
|
1397
1402
|
const sizeCollector = createOutputState({
|
|
@@ -1437,7 +1442,8 @@ function runWatch({ input, output }, metadata) {
|
|
|
1437
1442
|
switch(event.code){
|
|
1438
1443
|
case 'ERROR':
|
|
1439
1444
|
{
|
|
1440
|
-
|
|
1445
|
+
logError(event.error);
|
|
1446
|
+
break;
|
|
1441
1447
|
}
|
|
1442
1448
|
case 'START':
|
|
1443
1449
|
{
|
|
@@ -1457,14 +1463,18 @@ function runBundle({ input, output }) {
|
|
|
1457
1463
|
return rollup.rollup(input).then((bundle)=>{
|
|
1458
1464
|
const writeJobs = output.map((options)=>bundle.write(options));
|
|
1459
1465
|
return Promise.all(writeJobs);
|
|
1460
|
-
},
|
|
1466
|
+
}, catchErrorHandler);
|
|
1461
1467
|
}
|
|
1462
|
-
function
|
|
1468
|
+
function logError(error) {
|
|
1463
1469
|
if (!error) return;
|
|
1464
1470
|
// logging source code in format
|
|
1465
1471
|
if (error.frame) {
|
|
1466
1472
|
process.stderr.write(error.frame + '\n');
|
|
1467
1473
|
}
|
|
1474
|
+
}
|
|
1475
|
+
function catchErrorHandler(error) {
|
|
1476
|
+
if (!error) return;
|
|
1477
|
+
logError(error);
|
|
1468
1478
|
// filter out the rollup plugin error information such as loc/frame/code...
|
|
1469
1479
|
const err = new Error(error.message);
|
|
1470
1480
|
err.stack = error.stack;
|