bunchee 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +3 -3
- package/dist/index.js +66 -31
- package/package.json +3 -2
package/dist/bin/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var path = require('path');
|
|
3
3
|
var arg = require('arg');
|
|
4
4
|
var fs = require('fs/promises');
|
|
5
|
+
var bunchee = require('bunchee');
|
|
5
6
|
|
|
6
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
|
|
@@ -54,7 +55,7 @@ async function fileExists(filePath) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
var version = "4.2.
|
|
58
|
+
var version = "4.2.1";
|
|
58
59
|
|
|
59
60
|
const helpMessage = `
|
|
60
61
|
Usage: bunchee [options]
|
|
@@ -165,11 +166,10 @@ async function run(args) {
|
|
|
165
166
|
return help();
|
|
166
167
|
}
|
|
167
168
|
const entry = source ? path__default.default.resolve(cwd, source) : '';
|
|
168
|
-
const bundle = require('../index').bundle;
|
|
169
169
|
let timeStart = Date.now();
|
|
170
170
|
let timeEnd;
|
|
171
171
|
try {
|
|
172
|
-
await bundle(entry, bundleConfig);
|
|
172
|
+
await bunchee.bundle(entry, bundleConfig);
|
|
173
173
|
timeEnd = Date.now();
|
|
174
174
|
} catch (err) {
|
|
175
175
|
if (err.name === 'NOT_EXISTED') {
|
package/dist/index.js
CHANGED
|
@@ -591,6 +591,12 @@ function getBuildEnv(envs) {
|
|
|
591
591
|
}
|
|
592
592
|
async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPath, tsCompilerOptions }, pluginContext, dts) {
|
|
593
593
|
const entriesAlias = getEntriesAlias(entries);
|
|
594
|
+
const reversedAlias = {};
|
|
595
|
+
for (const [key, value] of Object.entries(entriesAlias)){
|
|
596
|
+
if (value !== entry) {
|
|
597
|
+
reversedAlias[value] = key;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
594
600
|
const hasNoExternal = options.external === null;
|
|
595
601
|
var _options_external;
|
|
596
602
|
const externals = hasNoExternal ? [] : [
|
|
@@ -631,12 +637,6 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
631
637
|
isModule: true
|
|
632
638
|
};
|
|
633
639
|
const sizePlugin = pluginContext.sizeCollector.plugin(cwd);
|
|
634
|
-
const reversedAlias = {};
|
|
635
|
-
for (const [key, value] of Object.entries(entriesAlias)){
|
|
636
|
-
if (value !== entry) {
|
|
637
|
-
reversedAlias[value] = key;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
640
|
// common plugins for both dts and ts assets that need to be processed
|
|
641
641
|
const commonPlugins = [
|
|
642
642
|
sizePlugin,
|
|
@@ -732,7 +732,8 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
|
|
|
732
732
|
'MIXED_EXPORTS',
|
|
733
733
|
'PREFER_NAMED_EXPORTS',
|
|
734
734
|
'UNRESOLVED_IMPORT',
|
|
735
|
-
'THIS_IS_UNDEFINED'
|
|
735
|
+
'THIS_IS_UNDEFINED',
|
|
736
|
+
'INVALID_ANNOTATION'
|
|
736
737
|
].includes(code)) return;
|
|
737
738
|
// If the circular dependency warning is from node_modules, ignore it
|
|
738
739
|
if (code === 'CIRCULAR_DEPENDENCY' && /Circular dependency: node_modules/.test(warning.message)) {
|
|
@@ -754,26 +755,58 @@ function hasEsmExport(exportPaths, tsCompilerOptions) {
|
|
|
754
755
|
}
|
|
755
756
|
return Boolean(hasEsm || (tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop));
|
|
756
757
|
}
|
|
757
|
-
|
|
758
|
-
const moduleInfo = ctx.getModuleInfo(id);
|
|
759
|
-
if (!moduleInfo) {
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
const moduleMeta = moduleInfo.meta;
|
|
763
|
-
if (!moduleMeta) {
|
|
764
|
-
return;
|
|
765
|
-
}
|
|
758
|
+
function getModuleLater(moduleMeta) {
|
|
766
759
|
const directives = (moduleMeta.preserveDirectives || {
|
|
767
760
|
directives: []
|
|
768
761
|
}).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
|
|
769
762
|
const moduleLayer = directives[0];
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
return
|
|
775
|
-
|
|
776
|
-
|
|
763
|
+
return moduleLayer;
|
|
764
|
+
}
|
|
765
|
+
// dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
|
|
766
|
+
function createSplitChunks(dependencyGraphMap) {
|
|
767
|
+
return function splitChunks(id, ctx) {
|
|
768
|
+
const moduleInfo = ctx.getModuleInfo(id);
|
|
769
|
+
if (!moduleInfo) {
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
const { isEntry } = moduleInfo;
|
|
773
|
+
const moduleMeta = moduleInfo.meta;
|
|
774
|
+
const moduleLayer = getModuleLater(moduleMeta);
|
|
775
|
+
// Collect the sub modules of the entry, if they're having layer, and the same layer with the entry, push them to the dependencyGraphMap.
|
|
776
|
+
if (isEntry) {
|
|
777
|
+
const subModuleIds = ctx.getModuleIds();
|
|
778
|
+
for (const subId of subModuleIds){
|
|
779
|
+
const subModuleInfo = ctx.getModuleInfo(subId);
|
|
780
|
+
if (!subModuleInfo) {
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
783
|
+
const subModuleLayer = getModuleLater(moduleMeta);
|
|
784
|
+
if (subModuleLayer === moduleLayer) {
|
|
785
|
+
if (!dependencyGraphMap.has(subId)) {
|
|
786
|
+
dependencyGraphMap.set(subId, new Set());
|
|
787
|
+
}
|
|
788
|
+
dependencyGraphMap.get(subId).add(id);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
// If current module has a layer, and it's not an entry
|
|
793
|
+
if (moduleLayer && !isEntry) {
|
|
794
|
+
// If the module is imported by the entry:
|
|
795
|
+
// when the module layer is same as entry layer, keep it as part of entry and don't split it;
|
|
796
|
+
// when the module layer is different from entry layer, split the module into a separate chunk as a separate boundary.
|
|
797
|
+
if (dependencyGraphMap.has(id)) {
|
|
798
|
+
const parentModuleLayers = Array.from(dependencyGraphMap.get(id));
|
|
799
|
+
if (parentModuleLayers.every((layer)=>layer === moduleLayer)) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
const chunkName = path__default.default.basename(id, path__default.default.extname(id));
|
|
803
|
+
return `${chunkName}-${moduleLayer}`;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return;
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, pluginContext, dts) {
|
|
777
810
|
const { format } = options;
|
|
778
811
|
// Add esm mark and interop helper if esm export is detected
|
|
779
812
|
const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions);
|
|
@@ -799,7 +832,7 @@ function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { t
|
|
|
799
832
|
freeze: false,
|
|
800
833
|
strict: false,
|
|
801
834
|
sourcemap: options.sourcemap,
|
|
802
|
-
manualChunks:
|
|
835
|
+
manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap),
|
|
803
836
|
chunkFileNames: '[name]-[hash].js',
|
|
804
837
|
// By default in rollup, when creating multiple chunks, transitive imports of entry chunks
|
|
805
838
|
// will be added as empty imports to the entry chunks. Disable to avoid imports hoist outside of boundaries
|
|
@@ -911,18 +944,19 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
911
944
|
...bundleConfig,
|
|
912
945
|
useTypescript
|
|
913
946
|
};
|
|
914
|
-
const
|
|
947
|
+
const entry = exportCondition.source;
|
|
948
|
+
const inputOptions = await buildInputConfig(entry, entries, pkg, options, cwd, tsOptions, pluginContext, dts);
|
|
915
949
|
const outputExports = getExportConditionDist(pkg, exportCondition, cwd);
|
|
916
950
|
let outputConfigs = [];
|
|
917
951
|
// Generate dts job - single config
|
|
918
952
|
if (dts) {
|
|
919
953
|
const typeOutputExports = getExportTypeDist(exportCondition, cwd);
|
|
920
|
-
outputConfigs = typeOutputExports.map((
|
|
954
|
+
outputConfigs = typeOutputExports.map((typeFile)=>buildOutputConfigs(pkg, exportPaths, {
|
|
921
955
|
...bundleConfig,
|
|
922
956
|
format: 'es',
|
|
923
957
|
useTypescript,
|
|
924
|
-
file:
|
|
925
|
-
}, exportCondition, cwd, tsOptions, dts));
|
|
958
|
+
file: typeFile
|
|
959
|
+
}, exportCondition, cwd, tsOptions, pluginContext, dts));
|
|
926
960
|
} else {
|
|
927
961
|
// multi outputs with specified format
|
|
928
962
|
outputConfigs = outputExports.map((exportDist)=>{
|
|
@@ -931,7 +965,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
931
965
|
file: exportDist.file,
|
|
932
966
|
format: exportDist.format,
|
|
933
967
|
useTypescript
|
|
934
|
-
}, exportCondition, cwd, tsOptions, dts);
|
|
968
|
+
}, exportCondition, cwd, tsOptions, pluginContext, dts);
|
|
935
969
|
});
|
|
936
970
|
// CLI output option is always prioritized
|
|
937
971
|
if (file) {
|
|
@@ -943,7 +977,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
|
|
|
943
977
|
file,
|
|
944
978
|
format: bundleConfig.format || fallbackFormat,
|
|
945
979
|
useTypescript
|
|
946
|
-
}, exportCondition, cwd, tsOptions, dts)
|
|
980
|
+
}, exportCondition, cwd, tsOptions, pluginContext, dts)
|
|
947
981
|
];
|
|
948
982
|
}
|
|
949
983
|
}
|
|
@@ -1189,7 +1223,8 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
|
|
|
1189
1223
|
entries
|
|
1190
1224
|
});
|
|
1191
1225
|
const pluginContext = {
|
|
1192
|
-
sizeCollector
|
|
1226
|
+
sizeCollector,
|
|
1227
|
+
moduleDirectiveLayerMap: new Map()
|
|
1193
1228
|
};
|
|
1194
1229
|
const buildConfigs = await buildEntryConfig(entries, pkg, exportPaths, options, cwd, defaultTsOptions, pluginContext, false);
|
|
1195
1230
|
const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -86,7 +86,8 @@
|
|
|
86
86
|
"prettier": "^3.0.0",
|
|
87
87
|
"react": "^18.2.0",
|
|
88
88
|
"tsx": "^4.6.2",
|
|
89
|
-
"typescript": "^5.3.2"
|
|
89
|
+
"typescript": "^5.3.2",
|
|
90
|
+
"bunchee": "link:./"
|
|
90
91
|
},
|
|
91
92
|
"lint-staged": {
|
|
92
93
|
"*.{ts,tsx,js,jsx,md,json,yml}": "prettier --write"
|