Skip to content

Commit fabaecb

Browse files
authored
fix: alias/sourcemap/bundle_mode bug (#651)
* fix: bundle mode with start command should be development environment instead of production * fix: alias is should be working for .d.ts file * fix: sourcemap option should be working and default should be false for transform
1 parent 2e4042f commit fabaecb

22 files changed

+653
-178
lines changed

.changeset/new-pears-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ice/pkg': patch
3+
---
4+
5+
fix: bundle mode with start command should be `development` environment instead of `production`

.changeset/plenty-avocados-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ice/pkg': patch
3+
---
4+
5+
fix: alias is should be working for .d.ts file

.changeset/sweet-plums-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ice/pkg': patch
3+
---
4+
5+
fix: sourcemap option should be working and default should be false for transform

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ packages/*/es/
3333
/packages/**/es2017
3434
/packages/**/cjs
3535
/packages/**/esm
36+
/packages/pkg/tests/fixtures/**/build.config.for-test.mts
3637
**/node_modules
3738
/.pnpm-debug.log
3839
**/pnpm-global

packages/pkg/src/helpers/dts.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ export async function dtsCompile({ files, alias, rootDir, outputDir }: DtsCompil
127127
// Reason: https://github.com/microsoft/TypeScript/issues/30952#issuecomment-1114225407
128128
const tsConfigLocalPath = path.join(rootDir, 'node_modules/pkg/tsconfig.json');
129129
await fse.ensureFile(tsConfigLocalPath);
130-
await fse.writeJSON(tsConfigLocalPath, tsConfig, { spaces: 2 });
130+
await fse.writeJSON(tsConfigLocalPath, {
131+
...tsConfig,
132+
compilerOptions: tsConfig.options,
133+
}, { spaces: 2 });
131134

132135
const runFile = await prepareSingleFileReplaceTscAliasPaths({
133136
configFile: tsConfigLocalPath,

packages/pkg/src/helpers/getBuildTasks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function getBuildTask(buildTask: BuildTask, context: Context): BuildTask {
2828

2929
config.sourcemap = config.sourcemap ?? command === 'start';
3030

31+
const mode = command === 'build' ? 'production' : 'development';
32+
config.modes = [mode];
33+
3134
if (config.type === 'bundle') {
3235
const defaultBundleSwcConfig = getDefaultBundleSwcConfig(config, context, taskName);
3336
config.swcCompileOptions = typeof config.modifySwcCompileOptions === 'function' ?
@@ -38,8 +41,6 @@ function getBuildTask(buildTask: BuildTask, context: Context): BuildTask {
3841
);
3942
} else if (config.type === 'transform') {
4043
config.outputDir = getTransformDefaultOutputDir(rootDir, taskName);
41-
const mode = command === 'build' ? 'production' : 'development';
42-
config.modes = [mode];
4344
const defaultTransformSwcConfig = getDefaultTransformSwcConfig(config, context, taskName, mode);
4445
config.swcCompileOptions = typeof config.modifySwcCompileOptions === 'function' ?
4546
config.modifySwcCompileOptions(defaultTransformSwcConfig) :

packages/pkg/src/tasks/transform.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ async function runTransform(
9494
const logger = createLogger(`${taskName}-${mode}`);
9595
const entryDirs = getTransformEntryDirs(rootDir, config.entry as Record<string, string>);
9696

97+
if (config.sourcemap === 'inline') {
98+
logger.warn('The sourcemap "inline" for transform has not fully supported.');
99+
}
100+
97101
const files: OutputFile[] = [];
98102

99103
if (updatedFile) {
@@ -180,7 +184,8 @@ async function runTransform(
180184
}
181185
}
182186

183-
if (map) {
187+
// IMPROVE: should disable sourcemap generation in the transform step for speed.
188+
if (map && config.sourcemap !== false) {
184189
const standardizedMap = typeof map === 'string' ? map : JSON.stringify(map);
185190

186191
fs.writeFileSync(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from '@ice/pkg';
2+
3+
// https://pkg.ice.work/reference/config-list
4+
export default defineConfig({
5+
transform: {
6+
formats: ['cjs', 'esm', 'es2017']
7+
},
8+
alias: {
9+
'@': './src'
10+
},
11+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "@ice/pkg-tests-fixtures-alias",
3+
"private": true,
4+
"dependencies": {
5+
"@ice/pkg": "workspace:*"
6+
},
7+
"version": null
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const bar = 2

0 commit comments

Comments
 (0)