Skip to content

Commit c251e9c

Browse files
committed
fixup! fixup! fixup! fixup! fixup! fixup! feat(core): split exports by browser/server for bundle size
1 parent 95fb240 commit c251e9c

6 files changed

Lines changed: 40 additions & 6 deletions

File tree

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
makeSucrasePlugin,
2222
} from './plugins/index.mjs';
2323
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
24-
import { mergePlugins } from './utils.mjs';
24+
import { mergeExternals, mergePlugins } from './utils.mjs';
2525

2626
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2727

@@ -115,7 +115,11 @@ export function makeBaseNPMConfig(options = {}) {
115115

116116
return deepMerge(defaultBaseConfig, packageSpecificConfig, {
117117
// Plugins have to be in the correct order or everything breaks, so when merging we have to manually re-order them
118-
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
118+
customMerge: key => {
119+
if (key === 'plugins') return mergePlugins;
120+
if (key === 'external') return mergeExternals;
121+
return undefined;
122+
},
119123
});
120124
}
121125

dev-packages/rollup-utils/utils.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ export const insertAt = (arr, index, ...insertees) => {
1010
return newArr;
1111
};
1212

13+
/**
14+
* Turn a list of module IDs into a test function
15+
* Includes submodule exports by checking that it starts with the name
16+
* plus a / character.
17+
*/
18+
function toFilterFunction(list) {
19+
return Array.isArray(list) ? id => list.some(test => id === test || test.startsWith(`${id}/`)) : list;
20+
}
21+
22+
/**
23+
* Merge two external configs (function or array), returning a function that handles both.
24+
*/
25+
export function mergeExternals(base, specific) {
26+
const baseFn = toFilterFunction(base);
27+
const specificFn = toFilterFunction(specific);
28+
return id => baseFn(id) || specificFn(id);
29+
}
30+
1331
/**
1432
* Merge two arrays of plugins, making sure they're sorted in the correct order.
1533
*/

packages/effect/rollup.npm.config.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ const baseConfig = makeBaseNPMConfig({
99
},
1010
});
1111

12-
const defaultExternal = baseConfig.external || [];
12+
const defaultExternal = baseConfig.external;
13+
const isDefaultExternal = typeof defaultExternal === 'function'
14+
? defaultExternal
15+
: id => (defaultExternal || []).includes(id);
1316
baseConfig.external = id => {
14-
if (defaultExternal.includes(id)) {
17+
if (isDefaultExternal(id)) {
1518
return true;
1619
}
1720

packages/hono/rollup.npm.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const baseConfig = makeBaseNPMConfig({
1111

1212
const defaultExternal = baseConfig.external;
1313
baseConfig.external = id => {
14-
if (defaultExternal.includes(id)) {
14+
if (defaultExternal(id)) {
1515
return true;
1616
}
1717
// Mark all hono subpaths as external

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"scripts": {
103103
"build": "run-p build:transpile build:types",
104104
"build:dev": "yarn build",
105-
"build:transpile": "ts-node scripts/buildRollup.ts",
105+
"build:transpile": "ts-node --project tsconfig.tsnode.json scripts/buildRollup.ts",
106106
"build:types": "run-s build:types:core build:types:downlevel",
107107
"build:types:core": "tsc -p tsconfig.types.json",
108108
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
4+
"include": ["src/**/*"],
5+
6+
"compilerOptions": {
7+
// package-specific options
8+
}
9+
}

0 commit comments

Comments
 (0)