@shuvi/toolpack 2.0.0-dev.37 → 2.0.0-dev.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import type { EnvConfig, JscConfig, JscTarget, Options, ParserConfig, TransformConfig } from '@swc/types';
|
|
1
2
|
type Obj = Record<string, any>;
|
|
2
3
|
export interface CompilerOptions {
|
|
3
4
|
removeConsole?: boolean;
|
|
4
5
|
useDefineForClassFields?: boolean;
|
|
5
6
|
reactRemoveProperties?: boolean;
|
|
6
7
|
jsxImportSource?: string;
|
|
7
|
-
jscTarget?:
|
|
8
|
+
jscTarget?: JscTarget;
|
|
9
|
+
/**
|
|
10
|
+
* swc `env` options for client build, e.g. `{ targets, mode: 'usage', coreJs }`.
|
|
11
|
+
* When set, `jscTarget` is ignored because swc does not allow `env` and `jsc.target` together.
|
|
12
|
+
*/
|
|
13
|
+
env?: EnvConfig;
|
|
8
14
|
emotion?: boolean | {
|
|
9
15
|
sourceMap?: boolean;
|
|
10
16
|
autoLabel?: 'dev-only' | 'always' | 'never';
|
|
@@ -43,99 +49,62 @@ export type SWCLoaderOptions = {
|
|
|
43
49
|
development: boolean;
|
|
44
50
|
minify: boolean | Obj;
|
|
45
51
|
hasReactRefresh: boolean;
|
|
46
|
-
supportedBrowsers
|
|
52
|
+
supportedBrowsers?: string[] | false;
|
|
47
53
|
swcCacheDir: string;
|
|
48
54
|
compiler: CompilerOptions;
|
|
49
55
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
compiler: Obj;
|
|
53
|
-
}): {
|
|
54
|
-
syntax: string;
|
|
55
|
-
dynamicImport: boolean;
|
|
56
|
-
decorators: boolean;
|
|
57
|
-
importAssertions: boolean;
|
|
56
|
+
type ShuviParserConfig = ParserConfig & {
|
|
57
|
+
importAssertions?: boolean;
|
|
58
58
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
externalHelpers: boolean;
|
|
63
|
-
parser: {
|
|
64
|
-
syntax: string;
|
|
65
|
-
dynamicImport: boolean;
|
|
66
|
-
decorators: boolean;
|
|
67
|
-
importAssertions: boolean;
|
|
68
|
-
};
|
|
69
|
-
experimental: {
|
|
70
|
-
keepImportAssertions: boolean;
|
|
71
|
-
plugins: any[][];
|
|
72
|
-
cacheRoot: string;
|
|
73
|
-
};
|
|
74
|
-
transform: {
|
|
75
|
-
legacyDecorator: boolean;
|
|
76
|
-
decoratorMetadata: boolean;
|
|
77
|
-
useDefineForClassFields: boolean;
|
|
78
|
-
react: {
|
|
79
|
-
importSource: string;
|
|
80
|
-
runtime: string;
|
|
81
|
-
pragma: string;
|
|
82
|
-
pragmaFrag: string;
|
|
83
|
-
throwIfNamespace: boolean;
|
|
84
|
-
development: boolean;
|
|
85
|
-
useBuiltins: boolean;
|
|
86
|
-
refresh: boolean;
|
|
87
|
-
};
|
|
88
|
-
optimizer: {
|
|
89
|
-
simplify: boolean;
|
|
90
|
-
globals: {
|
|
91
|
-
typeofs: {
|
|
92
|
-
window: string;
|
|
93
|
-
};
|
|
94
|
-
envs: {
|
|
95
|
-
NODE_ENV: string;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
regenerator: {
|
|
100
|
-
importPath: string;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
59
|
+
interface ShuviTransformConfig extends TransformConfig {
|
|
60
|
+
regenerator?: {
|
|
61
|
+
importPath?: string;
|
|
103
62
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
63
|
+
}
|
|
64
|
+
interface ShuviJscConfig extends Omit<JscConfig, 'parser' | 'transform'> {
|
|
65
|
+
parser?: ShuviParserConfig;
|
|
66
|
+
transform?: ShuviTransformConfig;
|
|
67
|
+
}
|
|
68
|
+
export interface ShuviSWCOptions extends Omit<Options, 'jsc' | 'minify'> {
|
|
69
|
+
jsc: ShuviJscConfig;
|
|
70
|
+
minify?: boolean | Obj;
|
|
71
|
+
isDevelopment?: boolean;
|
|
72
|
+
isServer?: boolean;
|
|
73
|
+
isPageFile?: boolean;
|
|
74
|
+
pagePickLoader?: boolean;
|
|
75
|
+
cssModuleFlag?: string;
|
|
76
|
+
removeConsole?: CompilerOptions['removeConsole'];
|
|
77
|
+
reactRemoveProperties?: CompilerOptions['reactRemoveProperties'];
|
|
78
|
+
modularizeImports?: CompilerOptions['modularizeImports'];
|
|
79
|
+
styledComponents?: ReturnType<typeof getStyledComponentsOptions>;
|
|
80
|
+
emotion?: ReturnType<typeof getEmotionOptions>;
|
|
81
|
+
}
|
|
82
|
+
export declare function getParserOptions({ filename, compiler }: {
|
|
83
|
+
filename: string;
|
|
84
|
+
compiler: CompilerOptions;
|
|
85
|
+
}): ShuviParserConfig;
|
|
86
|
+
declare function getStyledComponentsOptions(compiler: CompilerOptions, development: boolean): {
|
|
87
|
+
displayName: boolean;
|
|
88
|
+
topLevelImportPaths?: string[];
|
|
89
|
+
ssr?: boolean;
|
|
90
|
+
fileName?: boolean;
|
|
91
|
+
meaninglessFileNames?: string[];
|
|
92
|
+
minify?: boolean;
|
|
93
|
+
transpileTemplateLiterals?: boolean;
|
|
94
|
+
namespace?: string;
|
|
95
|
+
pure?: boolean;
|
|
96
|
+
cssProp?: boolean;
|
|
97
|
+
} | null;
|
|
98
|
+
declare function getEmotionOptions(compiler: CompilerOptions, development: boolean): {
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
autoLabel: boolean;
|
|
101
|
+
sourcemap: boolean;
|
|
102
|
+
labelFormat?: undefined;
|
|
103
|
+
} | {
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
autoLabel: boolean;
|
|
106
|
+
labelFormat: string | undefined;
|
|
107
|
+
sourcemap: boolean;
|
|
108
|
+
} | null;
|
|
109
|
+
export default function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, pagePickLoader, hasReactRefresh, compiler, supportedBrowsers, swcCacheDir }: SWCLoaderOptions): ShuviSWCOptions;
|
|
141
110
|
export {};
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.getParserOptions = getParserOptions;
|
|
15
4
|
exports.default = getLoaderSWCOptions;
|
|
16
|
-
function getParserOptions(
|
|
17
|
-
var { filename, compiler } = _a, rest = __rest(_a, ["filename", "compiler"]);
|
|
5
|
+
function getParserOptions({ filename, compiler }) {
|
|
18
6
|
const isTSFile = filename.endsWith('.ts');
|
|
19
7
|
const isTypeScript = isTSFile || filename.endsWith('.tsx');
|
|
20
8
|
const enableDecorators = Boolean(compiler === null || compiler === void 0 ? void 0 : compiler.experimentalDecorators);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
// Exclude regular TypeScript files from React transformation to prevent e.g. generic parameters and angle-bracket type assertion from being interpreted as JSX tags.
|
|
10
|
+
if (isTypeScript) {
|
|
11
|
+
return {
|
|
12
|
+
syntax: 'typescript',
|
|
13
|
+
dynamicImport: true,
|
|
14
|
+
decorators: enableDecorators,
|
|
15
|
+
tsx: !isTSFile,
|
|
16
|
+
importAssertions: true
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
syntax: 'ecmascript',
|
|
21
|
+
dynamicImport: true,
|
|
22
|
+
decorators: enableDecorators,
|
|
23
|
+
jsx: true,
|
|
24
|
+
importAssertions: true
|
|
25
|
+
};
|
|
24
26
|
}
|
|
25
27
|
function getBaseSWCOptions({ filename, isPageFile, pagePickLoader, minify, development, hasReactRefresh, isServer, compiler, swcCacheDir }) {
|
|
26
28
|
var _a, _b;
|
|
@@ -132,7 +134,8 @@ function getEmotionOptions(compiler, development) {
|
|
|
132
134
|
};
|
|
133
135
|
}
|
|
134
136
|
function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFile, pagePickLoader, hasReactRefresh, compiler, supportedBrowsers, swcCacheDir }) {
|
|
135
|
-
|
|
137
|
+
var _a;
|
|
138
|
+
const baseOptions = getBaseSWCOptions({
|
|
136
139
|
filename,
|
|
137
140
|
isPageFile,
|
|
138
141
|
pagePickLoader,
|
|
@@ -152,12 +155,16 @@ function getLoaderSWCOptions({ filename, development, isServer, minify, isPageFi
|
|
|
152
155
|
};
|
|
153
156
|
}
|
|
154
157
|
else {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const env = (_a = compiler === null || compiler === void 0 ? void 0 : compiler.env) !== null && _a !== void 0 ? _a : (supportedBrowsers && supportedBrowsers.length > 0
|
|
159
|
+
? { targets: supportedBrowsers }
|
|
160
|
+
: undefined);
|
|
161
|
+
if (env) {
|
|
162
|
+
// swc throws "`env` and `jsc.target` cannot be used together"
|
|
163
|
+
baseOptions.env = env;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Matches default @babel/preset-env behavior
|
|
167
|
+
baseOptions.jsc.target = (compiler === null || compiler === void 0 ? void 0 : compiler.jscTarget) || 'es5';
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
return baseOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/toolpack",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.39",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
"@babel/runtime": "7.12.5",
|
|
36
36
|
"@rspack/cli": "^1.4.2",
|
|
37
37
|
"@rspack/core": "^1.4.2",
|
|
38
|
-
"@shuvi/compiler": "2.0.0-dev.
|
|
39
|
-
"@shuvi/shared": "2.0.0-dev.
|
|
40
|
-
"@shuvi/utils": "2.0.0-dev.
|
|
38
|
+
"@shuvi/compiler": "2.0.0-dev.39",
|
|
39
|
+
"@shuvi/shared": "2.0.0-dev.39",
|
|
40
|
+
"@shuvi/utils": "2.0.0-dev.39",
|
|
41
41
|
"@swc/helpers": "^0.4.37",
|
|
42
|
+
"@swc/types": "^0.1.23",
|
|
42
43
|
"babel-loader": "8.2.2",
|
|
43
44
|
"babel-plugin-syntax-jsx": "6.18.0",
|
|
44
45
|
"babel-plugin-transform-define": "2.0.0",
|