Skip to content

Commit

Permalink
feat: set experimentalDecorators and emitDecoratorMetadata via ts…
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
Repraance authored Feb 28, 2023
1 parent 9d1eb89 commit 0933cfb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
12 changes: 3 additions & 9 deletions packages/service/src/analysis/events/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ export type Feature =
| 'swcReactRemoveProperties'
| 'swcJsxImportSource'
| 'swcStyledComponents'
| 'swcEmotion'
| 'swcExperimentalDecorators'
| 'swcEmitDecoratorMetadata';
| 'swcEmotion';

const BUILD_FEATURES: Array<Feature> = [
'shuvi/lightningCss',
Expand All @@ -110,9 +108,7 @@ const BUILD_FEATURES: Array<Feature> = [
'swcReactRemoveProperties',
'swcJsxImportSource',
'swcStyledComponents',
'swcEmotion',
'swcExperimentalDecorators',
'swcEmitDecoratorMetadata'
'swcEmotion'
];

export type EventBuildFeatureUsage = {
Expand All @@ -137,9 +133,7 @@ export function eventBuildFeatureUsage({
['swcReactRemoveProperties', !!compiler?.reactRemoveProperties],
['swcJsxImportSource', !!compiler?.jsxImportSource],
['swcStyledComponents', !!compiler?.styledComponents],
['swcEmotion', !!compiler?.emotion],
['swcExperimentalDecorators', !!compiler?.experimentalDecorators],
['swcEmitDecoratorMetadata', !!compiler?.emitDecoratorMetadata]
['swcEmotion', !!compiler?.emotion]
].filter<[Feature, boolean]>(Boolean as any)
);
return BUILD_FEATURES.map(featureName => {
Expand Down
13 changes: 10 additions & 3 deletions packages/service/src/bundler/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createBrowserWebpackChain,
createNodeWebpackChain
} from '@shuvi/toolpack/lib/webpack/config';
import { CompilerOptions } from '@shuvi/toolpack/lib/webpack/loaders/shuvi-swc-loader';
import { IPluginContext } from '../core';
import { getJavaScriptInfo } from './typescript';

Expand Down Expand Up @@ -43,12 +44,18 @@ export function createWebpackConfig(
];
const lightningCss = !!config.experimental.lightningCss;
const experimental = config.experimental;
const compiler = {
const jsConfig = getJavaScriptInfo();
const compiler: CompilerOptions = {
...config.compiler,
modularizeImports: experimental.modularizeImports,
swcPlugins: experimental.swcPlugins
swcPlugins: experimental.swcPlugins,
experimentalDecorators: Boolean(
jsConfig?.compilerOptions?.experimentalDecorators
),
emitDecoratorMetadata: Boolean(
jsConfig?.compilerOptions?.emitDecoratorMetadata
)
};
const jsConfig = getJavaScriptInfo();

if (opts.node) {
chain = createNodeWebpackChain({
Expand Down
4 changes: 0 additions & 4 deletions packages/service/src/core/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ export interface CompilerConfig {
// third-party libraries
styledComponents?: CompilerOptions['styledComponents'];
emotion?: CompilerOptions['emotion'];

// legacy decrator
experimentalDecorators?: CompilerOptions['experimentalDecorators'];
emitDecoratorMetadata?: CompilerOptions['emitDecoratorMetadata'];
}

export interface InternalConfig {
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/compiler/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"moduleResolution": "node16",
"baseUrl": "./",
"paths": {
"@shuvi/runtime": [".shuvi/app/runtime"],
"@shuvi/runtime/*": [".shuvi/app/runtime/*"]
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": [".shuvi/app/shuvi-app.d.ts", "src"],
"exclude": ["node_modules"]
}
4 changes: 1 addition & 3 deletions test/fixtures/compiler/shuvi.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export default {
sourceMap: true,
autoLabel: 'dev-only',
labelFormat: 'custom--[local]'
},
experimentalDecorators: true,
emitDecoratorMetadata: true
}
},
experimental: {
modularizeImports: {
Expand Down

0 comments on commit 0933cfb

Please sign in to comment.