Skip to content

Commit f28e19b

Browse files
committed
fix: move types correctly for the bundled pkges
1 parent 56604df commit f28e19b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,23 @@ export function makeBaseNPMConfig(options = {}) {
109109
external: [...builtinModules.filter(m => !bundledBuiltins.includes(m)), ...externalWithSubpaths],
110110
});
111111

112-
return deepMerge(defaultBaseConfig, packageSpecificConfig, {
112+
const baseConfig = deepMerge(defaultBaseConfig, packageSpecificConfig, {
113113
// Plugins have to be in the correct order or everything breaks, so when merging we have to manually re-order them
114114
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
115115
});
116+
117+
if (hasBundles) {
118+
// @ts-expect-error - this is a private property that we use to determine if the package has bundles
119+
baseConfig.__sentry_internal_hasBundles = true;
120+
}
121+
122+
return baseConfig;
116123
}
117124

118125
export function makeNPMConfigVariants(baseConfig, options = {}) {
119126
const { emitEsm = true, emitCjs = true, splitDevProd = false } = options;
120127

128+
const hasBundles = baseConfig.__sentry_internal_hasBundles;
121129
const variantSpecificConfigs = [];
122130

123131
if (emitCjs) {
@@ -139,6 +147,9 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
139147
tsgo: true,
140148
});
141149

150+
const moveDtsDir = hasBundles ? 'build/npm/esm' : 'build/esm';
151+
const moveDtsOutputDir = hasBundles ? 'build/npm/types' : 'build/types';
152+
142153
if (splitDevProd) {
143154
variantSpecificConfigs.push({
144155
output: {
@@ -153,7 +164,11 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
153164
output: {
154165
format: 'esm',
155166
dir: path.join(baseConfig.output.dir, 'esm/prod'),
156-
plugins: [makeProductionReplacePlugin(), makePackageNodeEsm(), makeMoveDtsPlugin()],
167+
plugins: [
168+
makeProductionReplacePlugin(),
169+
makePackageNodeEsm(),
170+
makeMoveDtsPlugin(`${moveDtsDir}/prod`, moveDtsOutputDir),
171+
],
157172
},
158173
});
159174
} else {
@@ -162,12 +177,13 @@ export function makeNPMConfigVariants(baseConfig, options = {}) {
162177
output: {
163178
format: 'esm',
164179
dir: path.join(baseConfig.output.dir, 'esm'),
165-
plugins: [makePackageNodeEsm(), makeMoveDtsPlugin()],
180+
plugins: [makePackageNodeEsm(), makeMoveDtsPlugin(moveDtsDir, moveDtsOutputDir)],
166181
},
167182
});
168183
}
169184
}
170185

186+
// @ts-expect-error -TODO: Not properly typed at the moment
171187
return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant));
172188
}
173189

dev-packages/rollup-utils/plugins/move-dts-plugin.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import path from 'node:path';
77
* This preserves the directory structure within the types directory.
88
* Optimized for speed with parallel file operations.
99
*/
10-
export function makeMoveDtsPlugin() {
10+
export function makeMoveDtsPlugin(searchDir = 'build/esm', outputDir = 'build/types') {
1111
return {
1212
name: 'move-dts-files',
1313
async writeBundle() {
14-
const buildEsmDir = path.resolve(process.cwd(), 'build/esm');
15-
const buildTypesDir = path.resolve(process.cwd(), 'build/types');
14+
const buildEsmDir = path.resolve(process.cwd(), searchDir);
15+
const buildTypesDir = path.resolve(process.cwd(), outputDir);
1616

1717
// Check if build/esm exists
1818
if (!fs.existsSync(buildEsmDir)) {

0 commit comments

Comments
 (0)