Skip to content

Commit

Permalink
fix: support modes which is removed in the previous version(1.5.23) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
XGHeaven authored Aug 16, 2024
1 parent 88d0ed0 commit 0ea3f24
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/pkg/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.5.24

### Patch Changes

- support modes which is removed in the previous version(1.5.23)

## 1.5.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/pkg",
"version": "1.5.23",
"version": "1.5.24",
"description": "A fast builder for React components, Node modules and web libraries.",
"type": "module",
"main": "./lib/index.js",
Expand Down
1 change: 0 additions & 1 deletion packages/pkg/src/config/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
function getUserConfig() {
const defaultBundleUserConfig: BundleUserConfig = {
formats: ['esm', 'es2017'],
modes: ['production'],
outputDir: 'dist',
minify: {
js: (mode: string, command: string) => { return mode === 'production' && command === 'build'; },
Expand Down
3 changes: 2 additions & 1 deletion packages/pkg/src/helpers/getBuildTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ 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);
Expand All @@ -39,8 +38,10 @@ function getBuildTask(buildTask: BuildTask, context: Context): BuildTask {
defaultBundleSwcConfig,
config.swcCompileOptions || {},
);
config.modes = config.modes ?? [mode];
} else if (config.type === 'transform') {
config.outputDir = getTransformDefaultOutputDir(rootDir, taskName);
config.modes = [mode];
const defaultTransformSwcConfig = getDefaultTransformSwcConfig(config, context, taskName, mode);
config.swcCompileOptions = typeof config.modifySwcCompileOptions === 'function' ?
config.modifySwcCompileOptions(defaultTransformSwcConfig) :
Expand Down
59 changes: 59 additions & 0 deletions packages/pkg/tests/projects/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,65 @@ exports[`Run config bundle-full > es2017 structure 1`] = `null`;

exports[`Run config bundle-full > esm structure 1`] = `null`;

exports[`Run config bundle-with-dev-mode > cjs structure 1`] = `null`;

exports[`Run config bundle-with-dev-mode > dist structure 1`] = `
{
"files": [
{
"name": "index.esm.es2017.development.js",
},
{
"name": "index.esm.es5.development.js",
},
],
"name": "dist",
}
`;

exports[`Run config bundle-with-dev-mode > es2017 structure 1`] = `null`;

exports[`Run config bundle-with-dev-mode > esm structure 1`] = `null`;

exports[`Run config bundle-with-empty-mode > cjs structure 1`] = `null`;

exports[`Run config bundle-with-empty-mode > dist structure 1`] = `
{
"files": [],
"name": "dist",
}
`;

exports[`Run config bundle-with-empty-mode > es2017 structure 1`] = `null`;

exports[`Run config bundle-with-empty-mode > esm structure 1`] = `null`;

exports[`Run config bundle-with-full-modes > cjs structure 1`] = `null`;

exports[`Run config bundle-with-full-modes > dist structure 1`] = `
{
"files": [
{
"name": "index.esm.es2017.development.js",
},
{
"name": "index.esm.es2017.production.js",
},
{
"name": "index.esm.es5.development.js",
},
{
"name": "index.esm.es5.production.js",
},
],
"name": "dist",
}
`;

exports[`Run config bundle-with-full-modes > es2017 structure 1`] = `null`;

exports[`Run config bundle-with-full-modes > esm structure 1`] = `null`;

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

exports[`Run config default > dist structure 1`] = `null`;
Expand Down
30 changes: 30 additions & 0 deletions packages/pkg/tests/projects/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ runProjectTest('default', [
}
}
},
{
name: 'bundle-with-full-modes',
snapshot: 'structure',
config: {
transform: { formats: [] },
bundle: {
modes: ['development', 'production']
}
}
},
{
name: 'bundle-with-dev-mode',
snapshot: 'structure',
config: {
transform: { formats: [] },
bundle: {
modes: ['development']
}
}
},
{
name: 'bundle-with-empty-mode',
snapshot: 'structure',
config: {
transform: { formats: [] },
bundle: {
modes: []
}
}
},
{
name: 'sourcemap-enable',
snapshot: 'structure',
Expand Down
9 changes: 7 additions & 2 deletions packages/pkg/tests/projects/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface ProjectTestUserConfig {
config?: string | UserConfig
mode?: 'build' | 'start'
snapshot?: 'full' | 'structure'
skip?: boolean
only?: boolean
}

export interface ProjectTestConfig extends Required<ProjectTestUserConfig> {
Expand All @@ -40,7 +42,9 @@ export function runProjectTest(name: string, userConfigs: ProjectTestConfigs) {
name: config.name,
config: config.config,
mode: config?.mode ?? 'build',
snapshot: config?.snapshot ?? 'full'
snapshot: config?.snapshot ?? 'full',
skip: config.skip ?? false,
only: config.only ?? false,
})
}

Expand Down Expand Up @@ -93,7 +97,8 @@ export function runProjectTest(name: string, userConfigs: ProjectTestConfigs) {
})

for (const config of configs) {
it(`Run config ${config.name}`, async () => {
const test = config.only ? it.only : config.skip ? it.skip : it;
test(`Run config ${config.name}`, async () => {
await runBuild(config)
await runSnapshot(config)
}, {
Expand Down

0 comments on commit 0ea3f24

Please sign in to comment.