Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alias/sourcemap/bundle_mode bug #651

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-pears-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

fix: bundle mode with start command should be `development` environment instead of `production`
5 changes: 5 additions & 0 deletions .changeset/plenty-avocados-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

fix: alias is should be working for .d.ts file
5 changes: 5 additions & 0 deletions .changeset/sweet-plums-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

fix: sourcemap option should be working and default should be false for transform
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ packages/*/es/
/packages/**/es2017
/packages/**/cjs
/packages/**/esm
/packages/pkg/tests/fixtures/**/build.config.for-test.mts
**/node_modules
/.pnpm-debug.log
**/pnpm-global
Expand Down
5 changes: 4 additions & 1 deletion packages/pkg/src/helpers/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export async function dtsCompile({ files, alias, rootDir, outputDir }: DtsCompil
// Reason: https://github.com/microsoft/TypeScript/issues/30952#issuecomment-1114225407
const tsConfigLocalPath = path.join(rootDir, 'node_modules/pkg/tsconfig.json');
await fse.ensureFile(tsConfigLocalPath);
await fse.writeJSON(tsConfigLocalPath, tsConfig, { spaces: 2 });
await fse.writeJSON(tsConfigLocalPath, {
...tsConfig,
compilerOptions: tsConfig.options,
}, { spaces: 2 });

const runFile = await prepareSingleFileReplaceTscAliasPaths({
configFile: tsConfigLocalPath,
Expand Down
5 changes: 3 additions & 2 deletions packages/pkg/src/helpers/getBuildTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function getBuildTask(buildTask: BuildTask, context: Context): BuildTask {

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

const mode = command === 'build' ? 'production' : 'development';
config.modes = [mode];

if (config.type === 'bundle') {
const defaultBundleSwcConfig = getDefaultBundleSwcConfig(config, context, taskName);
config.swcCompileOptions = typeof config.modifySwcCompileOptions === 'function' ?
Expand All @@ -38,8 +41,6 @@ function getBuildTask(buildTask: BuildTask, context: Context): BuildTask {
);
} else if (config.type === 'transform') {
config.outputDir = getTransformDefaultOutputDir(rootDir, taskName);
const mode = command === 'build' ? 'production' : 'development';
config.modes = [mode];
const defaultTransformSwcConfig = getDefaultTransformSwcConfig(config, context, taskName, mode);
config.swcCompileOptions = typeof config.modifySwcCompileOptions === 'function' ?
config.modifySwcCompileOptions(defaultTransformSwcConfig) :
Expand Down
7 changes: 6 additions & 1 deletion packages/pkg/src/tasks/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ async function runTransform(
const logger = createLogger(`${taskName}-${mode}`);
const entryDirs = getTransformEntryDirs(rootDir, config.entry as Record<string, string>);

if (config.sourcemap === 'inline') {
logger.warn('The sourcemap "inline" for transform has not fully support.');
XGHeaven marked this conversation as resolved.
Show resolved Hide resolved
}

const files: OutputFile[] = [];

if (updatedFile) {
Expand Down Expand Up @@ -180,7 +184,8 @@ async function runTransform(
}
}

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

fs.writeFileSync(
Expand Down
11 changes: 11 additions & 0 deletions packages/pkg/tests/fixtures/alias/build.config.default.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from '@ice/pkg';

// https://pkg.ice.work/reference/config-list
export default defineConfig({
transform: {
formats: ['cjs', 'esm', 'es2017']
},
alias: {
'@': './src'
},
});
8 changes: 8 additions & 0 deletions packages/pkg/tests/fixtures/alias/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@ice/pkg-tests-fixtures-alias",
"private": true,
"dependencies": {
"@ice/pkg": "workspace:*"
},
"version": null
}
1 change: 1 addition & 0 deletions packages/pkg/tests/fixtures/alias/src/alias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const bar = 2
4 changes: 4 additions & 0 deletions packages/pkg/tests/fixtures/alias/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { bar } from '@/alias.js'

export const foo = 1
export { bar }
8 changes: 8 additions & 0 deletions packages/pkg/tests/fixtures/alias/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.common.json",
"compilerOptions": {
"paths": {
"@": ["./src"]
}
}
}
8 changes: 8 additions & 0 deletions packages/pkg/tests/fixtures/default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@ice/pkg-tests-fixtures-default",
"private": true,
"dependencies": {
"@ice/pkg": "workspace:*"
},
"version": null
}
1 change: 1 addition & 0 deletions packages/pkg/tests/fixtures/default/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 1
5 changes: 5 additions & 0 deletions packages/pkg/tests/fixtures/tsconfig.common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": true
}
}
162 changes: 162 additions & 0 deletions packages/pkg/tests/projects/__snapshots__/alias.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Vitest Snapshot v1

exports[`Run config default > cjs structure 1`] = `
{
"files": [
{
"name": "alias.d.ts",
},
{
"name": "alias.js",
},
{
"name": "index.d.ts",
},
{
"name": "index.js",
},
],
"name": "cjs",
}
`;

exports[`Run config default > dist structure 1`] = `null`;

exports[`Run config default > es2017 structure 1`] = `
{
"files": [
{
"name": "alias.d.ts",
},
{
"name": "alias.js",
},
{
"name": "index.d.ts",
},
{
"name": "index.js",
},
],
"name": "es2017",
}
`;

exports[`Run config default > esm structure 1`] = `
{
"files": [
{
"name": "alias.d.ts",
},
{
"name": "alias.js",
},
{
"name": "index.d.ts",
},
{
"name": "index.js",
},
],
"name": "esm",
}
`;

exports[`Run config default > file content cjs/alias.d.ts 1`] = `
"export declare const bar = 2;
"
`;

exports[`Run config default > file content cjs/alias.js 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
Object.defineProperty(exports, \\"bar\\", {
enumerable: true,
get: function() {
return bar;
}
});
var bar = 2;
"
`;

exports[`Run config default > file content cjs/index.d.ts 1`] = `
"import { bar } from './alias.js';
export declare const foo = 1;
export { bar };
"
`;

exports[`Run config default > file content cjs/index.js 1`] = `
"\\"use strict\\";
Object.defineProperty(exports, \\"__esModule\\", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
foo: function() {
return foo;
},
bar: function() {
return _alias.bar;
}
});
var _alias = require(\\"@/alias.js\\");
var foo = 1;
"
`;

exports[`Run config default > file content es2017/alias.d.ts 1`] = `
"export declare const bar = 2;
"
`;

exports[`Run config default > file content es2017/alias.js 1`] = `
"export const bar = 2;
"
`;

exports[`Run config default > file content es2017/index.d.ts 1`] = `
"import { bar } from './alias.js';
export declare const foo = 1;
export { bar };
"
`;

exports[`Run config default > file content es2017/index.js 1`] = `
"import { bar } from './alias.js';
export const foo = 1;
export { bar };
"
`;

exports[`Run config default > file content esm/alias.d.ts 1`] = `
"export declare const bar = 2;
"
`;

exports[`Run config default > file content esm/alias.js 1`] = `
"export var bar = 2;
"
`;

exports[`Run config default > file content esm/index.d.ts 1`] = `
"import { bar } from './alias.js';
export declare const foo = 1;
export { bar };
"
`;

exports[`Run config default > file content esm/index.js 1`] = `
"import { bar } from \\"./alias.js\\";
export var foo = 1;
export { bar };
"
`;
Loading
Loading