@workleap/swc-configs 2.2.3 → 2.2.5

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +22 -10
  2. package/README.md +2 -2
  3. package/dist/applyTransformers.d.ts +4 -7
  4. package/dist/applyTransformers.js +47 -4
  5. package/dist/applyTransformers.js.map +1 -0
  6. package/dist/applyTransformers.mjs +9 -1
  7. package/dist/applyTransformers.mjs.map +1 -0
  8. package/dist/browserslistToSwc.d.ts +4 -7
  9. package/dist/browserslistToSwc.js +187 -67
  10. package/dist/browserslistToSwc.js.map +1 -0
  11. package/dist/browserslistToSwc.mjs +140 -1
  12. package/dist/browserslistToSwc.mjs.map +1 -0
  13. package/dist/build.d.ts +6 -9
  14. package/dist/build.js +94 -53
  15. package/dist/build.js.map +1 -0
  16. package/dist/build.mjs +54 -2
  17. package/dist/build.mjs.map +1 -0
  18. package/dist/dev.d.ts +6 -9
  19. package/dist/dev.js +92 -52
  20. package/dist/dev.js.map +1 -0
  21. package/dist/dev.mjs +52 -2
  22. package/dist/dev.mjs.map +1 -0
  23. package/dist/index.d.ts +7 -7
  24. package/dist/index.js +120 -222
  25. package/dist/index.js.map +1 -0
  26. package/dist/index.mjs +13 -5
  27. package/dist/index.mjs.map +1 -0
  28. package/dist/jest.d.ts +6 -9
  29. package/dist/jest.js +84 -44
  30. package/dist/jest.js.map +1 -0
  31. package/dist/jest.mjs +44 -2
  32. package/dist/jest.mjs.map +1 -0
  33. package/package.json +24 -24
  34. package/src/applyTransformers.ts +11 -0
  35. package/src/browserslistToSwc.ts +155 -0
  36. package/src/build.ts +64 -0
  37. package/src/dev.ts +64 -0
  38. package/src/index.ts +9 -0
  39. package/src/jest.ts +58 -0
  40. package/dist/applyTransformers.d.mts +0 -9
  41. package/dist/browserslistToSwc.d.mts +0 -9
  42. package/dist/build.d.mts +0 -12
  43. package/dist/chunk-3UBBOKDF.mjs +0 -6
  44. package/dist/chunk-G3VHSALI.mjs +0 -53
  45. package/dist/chunk-JXCM6TQ3.mjs +0 -45
  46. package/dist/chunk-MGMFB3UY.mjs +0 -73
  47. package/dist/chunk-OLWWFWTT.mjs +0 -54
  48. package/dist/dev.d.mts +0 -13
  49. package/dist/index.d.mts +0 -7
  50. package/dist/jest.d.mts +0 -13
package/dist/jest.mjs CHANGED
@@ -1,2 +1,44 @@
1
- export { defineJestConfig } from './chunk-JXCM6TQ3.mjs';
2
- import './chunk-3UBBOKDF.mjs';
1
+ import * as __WEBPACK_EXTERNAL_MODULE__applyTransformers_mjs_b5d980dd__ from "./applyTransformers.mjs";
2
+
3
+ ;// CONCATENATED MODULE: external "./applyTransformers.mjs"
4
+
5
+ ;// CONCATENATED MODULE: ./src/jest.ts?__rslib_entry__
6
+
7
+ function defineJestConfig(options = {}) {
8
+ const { baseUrl, parser = "typescript", paths, react = false, transformers = [] } = options;
9
+ const config = {
10
+ jsc: {
11
+ baseUrl,
12
+ paths,
13
+ parser: parser === "ecmascript" ? {
14
+ syntax: "ecmascript",
15
+ jsx: react
16
+ } : {
17
+ syntax: "typescript",
18
+ tsx: react
19
+ },
20
+ // The output environment that the code will be compiled for.
21
+ target: "esnext",
22
+ transform: react ? {
23
+ react: {
24
+ // Use "react/jsx-runtime".
25
+ runtime: "automatic",
26
+ // Use the native "Object.assign()" instead of "_extends".
27
+ useBuiltins: true
28
+ }
29
+ } : undefined
30
+ },
31
+ module: {
32
+ // The output module resolution system that the code will be compiled for.
33
+ type: "es6"
34
+ }
35
+ };
36
+ const transformedConfig = (0,__WEBPACK_EXTERNAL_MODULE__applyTransformers_mjs_b5d980dd__.applyTransformers)(config, transformers, {
37
+ environment: "jest"
38
+ });
39
+ return transformedConfig;
40
+ }
41
+
42
+ export { defineJestConfig };
43
+
44
+ //# sourceMappingURL=jest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.mjs","sources":["webpack://@workleap/swc-configs/./src/jest.ts"],"sourcesContent":["import type { Config as SwcConfig } from \"@swc/core\";\nimport { applyTransformers, type SwcConfigTransformer } from \"./applyTransformers.ts\";\n\nexport interface DefineJestConfigOptions {\n baseUrl?: NonNullable<SwcConfig[\"jsc\"]>[\"baseUrl\"];\n parser?: \"ecmascript\" | \"typescript\";\n paths?: NonNullable<SwcConfig[\"jsc\"]>[\"paths\"];\n react?: boolean;\n transformers?: SwcConfigTransformer[];\n}\n\nexport function defineJestConfig(options: DefineJestConfigOptions = {}) {\n const {\n baseUrl,\n parser = \"typescript\",\n paths,\n react = false,\n transformers = []\n } = options;\n\n const config: SwcConfig = {\n jsc: {\n baseUrl,\n paths,\n parser: parser === \"ecmascript\"\n ? {\n syntax: \"ecmascript\",\n jsx: react\n }\n : {\n syntax: \"typescript\",\n tsx: react\n },\n // The output environment that the code will be compiled for.\n target: \"esnext\",\n transform: react\n ? {\n react: {\n // Use \"react/jsx-runtime\".\n runtime: \"automatic\",\n // Use the native \"Object.assign()\" instead of \"_extends\".\n useBuiltins: true\n }\n }\n : undefined\n },\n module: {\n // The output module resolution system that the code will be compiled for.\n type: \"es6\"\n }\n };\n\n const transformedConfig = applyTransformers(config, transformers, {\n environment: \"jest\"\n });\n\n return transformedConfig;\n}\n"],"names":["applyTransformers","defineJestConfig","options","baseUrl","parser","paths","react","transformers","config","undefined","transformedConfig"],"mappings":";;;;;AACsF;AAU/E,SAASC,iBAAiBC,UAAmC,CAAC,CAAC;IAClE,MAAM,EACFC,OAAO,EACPC,SAAS,YAAY,EACrBC,KAAK,EACLC,QAAQ,KAAK,EACbC,eAAe,EAAE,EACpB,GAAGL;IAEJ,MAAMM,SAAoB;QACtB,KAAK;YACDL;YACAE;YACA,QAAQD,WAAW,eACb;gBACE,QAAQ;gBACR,KAAKE;YACT,IACE;gBACE,QAAQ;gBACR,KAAKA;YACT;YACJ,6DAA6D;YAC7D,QAAQ;YACR,WAAWA,QACL;gBACE,OAAO;oBACH,2BAA2B;oBAC3B,SAAS;oBACT,0DAA0D;oBAC1D,aAAa;gBACjB;YACJ,IACEG;QACV;QACA,QAAQ;YACJ,0EAA0E;YAC1E,MAAM;QACV;IACJ;IAEA,MAAMC,oBAAoBV,iFAAiBA,CAACQ,QAAQD,cAAc;QAC9D,aAAa;IACjB;IAEA,OAAOG;AACX"}
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@workleap/swc-configs",
3
- "description": "Workleap recommended SWC configs.",
4
- "version": "2.2.3",
3
+ "description": "Workleap recommended SWC configurations.",
4
+ "version": "2.2.5",
5
5
  "license": "Apache-2.0",
6
- "keywords": [
7
- "workleap",
8
- "swc",
9
- "config"
10
- ],
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "provenance": true
9
+ },
11
10
  "exports": {
12
11
  ".": {
13
12
  "require": {
@@ -15,20 +14,21 @@
15
14
  "default": "./dist/index.js"
16
15
  },
17
16
  "import": {
18
- "types": "./dist/index.d.mts",
17
+ "types": "./dist/index.d.ts",
19
18
  "default": "./dist/index.mjs"
20
19
  }
21
20
  }
22
21
  },
23
22
  "types": "./dist/index.d.ts",
24
23
  "files": [
24
+ "src",
25
25
  "dist",
26
26
  "CHANGELOG.md",
27
27
  "README.md"
28
28
  ],
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "git+https://github.com/gsoft-inc/wl-web-configs.git",
31
+ "url": "git+https://github.com/workleap/wl-web-configs.git",
32
32
  "directory": "packages/swc-configs"
33
33
  },
34
34
  "peerDependencies": {
@@ -46,23 +46,23 @@
46
46
  }
47
47
  },
48
48
  "devDependencies": {
49
- "@swc/core": "1.4.6",
50
- "@swc/jest": "0.2.36",
51
- "@types/jest": "29.5.12",
52
- "browserslist": "4.23.0",
53
- "jest": "29.7.0",
54
- "ts-node": "10.9.2",
55
- "tsup": "8.0.2",
56
- "typescript": "5.4.2",
57
- "@workleap/eslint-plugin": "3.1.0",
58
- "@workleap/tsup-configs": "3.0.4",
49
+ "@rsbuild/core": "1.2.19",
50
+ "@rslib/core": "0.5.4",
51
+ "@swc/core": "1.11.11",
52
+ "@swc/helpers": "0.5.15",
53
+ "@swc/jest": "0.2.37",
54
+ "@typescript-eslint/parser": "8.26.1",
55
+ "eslint": "8.57.0",
56
+ "typescript": "5.8.2",
57
+ "vitest": "3.0.9",
58
+ "@workleap/eslint-plugin": "3.3.1",
59
+ "@workleap/rslib-configs": "1.0.3",
59
60
  "@workleap/typescript-configs": "3.0.2"
60
61
  },
61
- "publishConfig": {
62
- "access": "public",
63
- "provenance": true
64
- },
65
62
  "scripts": {
66
- "build": "tsup"
63
+ "build": "rslib build -c rslib.config.ts",
64
+ "eslint": "eslint . --max-warnings=-0 --cache --cache-location node_modules/.cache/eslint",
65
+ "typecheck": "tsc",
66
+ "test": "vitest --config vitest.config.ts --no-watch"
67
67
  }
68
68
  }
@@ -0,0 +1,11 @@
1
+ import type { Config as SwcConfig } from "@swc/core";
2
+
3
+ export interface SwcConfigTransformerContext {
4
+ environment: "dev" | "build" | "jest";
5
+ }
6
+
7
+ export type SwcConfigTransformer = (config: SwcConfig, context: SwcConfigTransformerContext) => SwcConfig;
8
+
9
+ export function applyTransformers(config: SwcConfig, transformers: SwcConfigTransformer[], context: SwcConfigTransformerContext) {
10
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
11
+ }
@@ -0,0 +1,155 @@
1
+ // Inspired by https://github.com/marcofugaro/browserslist-to-esbuild/blob/main/src/index.js.
2
+ //
3
+ // This function exist because browserslist-rs (which is used under the hood by SWC) doesn't support browserslist "extends" syntax: https://github.com/browserslist/browserslist-rs#limitations.
4
+ // Therefore, we must parse ourself the ".browserslistrc" file to extract the browser entries and transform them into valid SWC "env.targets".
5
+ //
6
+ // The function will convert an array of browserslist entries from:
7
+ //
8
+ // ['and_chr 115', 'and_ff 115', 'and_qq 13.1',
9
+ // 'and_uc 15.5', 'android 115', 'baidu 13.18',
10
+ // 'bb 10', 'bb 7', 'chrome 116',
11
+ // 'chrome 115', 'chrome 114', 'chrome 113',
12
+ // 'chrome 112', 'chrome 111', 'chrome 110',
13
+ // 'chrome 109', 'chrome 108', 'chrome 107',
14
+ // 'edge 115', 'edge 114', 'edge 113',
15
+ // 'edge 112', 'edge 111', 'edge 110',
16
+ // 'edge 109', 'edge 108', 'edge 107',
17
+ // 'edge 106', 'firefox 116', 'firefox 115',
18
+ // 'firefox 114', 'firefox 113', 'firefox 112',
19
+ // 'firefox 111', 'firefox 110', 'firefox 109',
20
+ // 'firefox 108', 'firefox 107', 'ie 11',
21
+ // 'ie 10', 'ie 9', 'ie 8',
22
+ // 'ie 7', 'ie 6', 'ie 5.5',
23
+ // 'ie_mob 11', 'ie_mob 10', 'ios_saf 16.5',
24
+ // 'ios_saf 16.4', 'ios_saf 16.3', 'ios_saf 16.2',
25
+ // 'ios_saf 16.1', 'ios_saf 16.0', 'ios_saf 15.6-15.7',
26
+ // 'ios_saf 15.5', 'ios_saf 15.4', 'ios_saf 15.2-15.3',
27
+ // 'kaios 3.0-3.1', 'kaios 2.5', 'op_mini all',
28
+ // 'op_mob 73', 'opera 101', 'opera 100',
29
+ // 'opera 99', 'opera 98', 'opera 97',
30
+ // 'opera 96', 'opera 95', 'opera 94',
31
+ // 'opera 93', 'opera 92', 'safari 16.5',
32
+ // 'safari 16.4', 'safari 16.3', 'safari 16.2',
33
+ // 'safari 16.1', 'safari 16.0', 'safari 15.6',
34
+ // 'safari 15.5', 'safari 15.4', 'safari 15.2-15.3',
35
+ // 'samsung 21', 'samsung 20', 'samsung 19.0',
36
+ // 'samsung 18.0', 'samsung 17.0', 'samsung 16.0',
37
+ // 'samsung 15.0', 'samsung 14.0', 'samsung 13.0',
38
+ // 'samsung 12.0']
39
+ //
40
+ // To an object literal of SWC "env.targets":
41
+ //
42
+ // {
43
+ // chrome: '107',
44
+ // firefox: '107',
45
+ // android: '115',
46
+ // edge: '106',
47
+ // ie: '5.5',
48
+ // opera: '73',
49
+ // safari: '15.2',
50
+ // samsung: '12'
51
+ // }
52
+
53
+ import browserslist from "browserslist";
54
+
55
+ // Original browserslist-rs supported browsers (https://github.com/browserslist/browserslist-rs/blob/99a3244fc8c0e631a80a9cae5c41dca6c5a2aae5/build.rs#L10)
56
+ // minus the browsers that are discarted by SWC (https://github.com/swc-project/swc/blob/main/crates/preset_env_base/src/lib.rs#L105).
57
+ const SwcSupportedBrowsers = [
58
+ "ie",
59
+ "edge",
60
+ "firefox",
61
+ "chrome",
62
+ "safari",
63
+ "opera",
64
+ "ios",
65
+ "android",
66
+ "op_mob",
67
+ "and_chr",
68
+ "and_ff",
69
+ "ie_mob",
70
+ "samsung"
71
+ ] as const;
72
+
73
+ // SWC browsers aliases (https://github.com/swc-project/swc/blob/main/crates/preset_env_base/src/lib.rs#L90).
74
+ const SwcMobileBrowserAliases: Record<string, string> = {
75
+ "and_chr": "chrome",
76
+ "and_ff": "firefox",
77
+ "ie_mob": "ie",
78
+ "ios_saf": "ios",
79
+ "op_mob": "opera"
80
+ };
81
+
82
+ function parseBrowserslistEntry(entry: string) {
83
+ // "chrome 11" --> ["chrome", "11"]
84
+ const values = entry.split(" ");
85
+
86
+ let browser = values[0];
87
+ let version = values[1];
88
+
89
+ // "and_chr" --> "chrome"
90
+ if (SwcMobileBrowserAliases[browser]) {
91
+ browser = SwcMobileBrowserAliases[browser];
92
+ }
93
+
94
+ // "11.0-12.0" --> "11.0"
95
+ if (version.includes("-")) {
96
+ version = version.slice(0, version.indexOf("-"));
97
+ }
98
+
99
+ // "11.0" --> "11"
100
+ if (version.endsWith(".0")) {
101
+ version = version.slice(0, -2);
102
+ }
103
+
104
+ return {
105
+ browser,
106
+ version
107
+ };
108
+ }
109
+
110
+ export function createSwcTargetsFromBrowserslistEntries(entries: string[]) {
111
+ return entries.reduce((acc, x: string) => {
112
+ const { browser, version } = parseBrowserslistEntry(x);
113
+
114
+ // Exclude browsers that are not supported by SWC.
115
+ if (((SwcSupportedBrowsers as unknown) as string[]).indexOf(browser) === -1) {
116
+ return acc;
117
+ }
118
+
119
+ // Let's make TS happy as we are now certain that the browser is part
120
+ // of the supported browsers list.
121
+ const _browser = browser as keyof typeof SwcSupportedBrowsers;
122
+
123
+ // SWC "env.targets" only support a single entry per target (browser).
124
+ // Therefore, we loop through the browser versions to keep only the oldest one.
125
+ if (acc[_browser]) {
126
+ if (parseFloat(acc[_browser]) > parseFloat(version)) {
127
+ acc[_browser] = version;
128
+ }
129
+ } else {
130
+ acc[_browser] = version;
131
+ }
132
+
133
+ return acc;
134
+ }, {} as Record<keyof typeof SwcSupportedBrowsers, string>);
135
+ }
136
+
137
+ export interface BrowserslistToSwcOptions extends Omit<browserslist.Options, "path"> {
138
+ queries?: string | string[];
139
+ }
140
+
141
+ export function browserslistToSwc(options: BrowserslistToSwcOptions = {}) {
142
+ const {
143
+ queries,
144
+ ...browserlistsOptions
145
+ } = options;
146
+
147
+ // Will return the entries matching the "queries" prop when provided, otherwise,
148
+ // the function will load the closest ".browserslistrc" file.
149
+ const entries = browserslist(queries, {
150
+ path: "./browserslistrc",
151
+ ...browserlistsOptions
152
+ });
153
+
154
+ return createSwcTargetsFromBrowserslistEntries(entries);
155
+ }
package/src/build.ts ADDED
@@ -0,0 +1,64 @@
1
+ import type { Config as SwcConfig } from "@swc/core";
2
+ import { applyTransformers, type SwcConfigTransformer } from "./applyTransformers.ts";
3
+
4
+ export interface DefineBuildConfigOptions {
5
+ baseUrl?: NonNullable<SwcConfig["jsc"]>["baseUrl"];
6
+ parser?: "ecmascript" | "typescript";
7
+ paths?: NonNullable<SwcConfig["jsc"]>["paths"];
8
+ transformers?: SwcConfigTransformer[];
9
+ }
10
+
11
+ export function defineBuildConfig(targets: Record<string, string>, options: DefineBuildConfigOptions = {}) {
12
+ const {
13
+ baseUrl,
14
+ parser = "typescript",
15
+ paths,
16
+ transformers = []
17
+ } = options;
18
+
19
+ const config: SwcConfig = {
20
+ jsc: {
21
+ baseUrl,
22
+ paths,
23
+ parser: parser === "ecmascript"
24
+ ? {
25
+ syntax: "ecmascript",
26
+ jsx: true
27
+ }
28
+ : {
29
+ syntax: "typescript",
30
+ tsx: true
31
+ },
32
+ // View https://swc.rs/docs/configuration/minification for options.
33
+ minify: {
34
+ compress: true,
35
+ mangle: true
36
+ },
37
+ transform: {
38
+ react: {
39
+ // Use "react/jsx-runtime".
40
+ runtime: "automatic",
41
+ // Use the native "Object.assign()" instead of "_extends".
42
+ useBuiltins: true
43
+ }
44
+ },
45
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
46
+ // Requires to add "@swc/helpers" as a project dependency.
47
+ externalHelpers: true
48
+ },
49
+ module: {
50
+ // The output module resolution system that the code will be compiled for.
51
+ type: "es6"
52
+ },
53
+ env: {
54
+ // jsc.target is not provided because the provided targets takes precedence.
55
+ targets
56
+ }
57
+ };
58
+
59
+ const transformedConfig = applyTransformers(config, transformers, {
60
+ environment: "build"
61
+ });
62
+
63
+ return transformedConfig;
64
+ }
package/src/dev.ts ADDED
@@ -0,0 +1,64 @@
1
+ import type { Config as SwcConfig } from "@swc/core";
2
+ import { applyTransformers, type SwcConfigTransformer } from "./applyTransformers.ts";
3
+
4
+ export interface DefineDevConfigOptions {
5
+ baseUrl?: NonNullable<SwcConfig["jsc"]>["baseUrl"];
6
+ fastRefresh?: boolean;
7
+ parser?: "ecmascript" | "typescript";
8
+ paths?: NonNullable<SwcConfig["jsc"]>["paths"];
9
+ transformers?: SwcConfigTransformer[];
10
+ }
11
+
12
+ export function defineDevConfig(targets: Record<string, string>, options: DefineDevConfigOptions = {}) {
13
+ const {
14
+ baseUrl,
15
+ fastRefresh = true,
16
+ parser = "typescript",
17
+ paths,
18
+ transformers = []
19
+ } = options;
20
+
21
+ const config: SwcConfig = {
22
+ jsc: {
23
+ baseUrl,
24
+ paths,
25
+ parser: parser === "ecmascript"
26
+ ? {
27
+ syntax: "ecmascript",
28
+ jsx: true
29
+ }
30
+ : {
31
+ syntax: "typescript",
32
+ tsx: true
33
+ },
34
+ transform: {
35
+ react: {
36
+ // Use "react/jsx-runtime".
37
+ runtime: "automatic",
38
+ // Use the native "Object.assign()" instead of "_extends".
39
+ useBuiltins: true,
40
+ // Enable React experimental "fast-refresh" feature.
41
+ // Also need to install @pmmmwh/react-refresh-webpack-plugin.
42
+ refresh: fastRefresh
43
+ }
44
+ },
45
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
46
+ // Requires to add "@swc/helpers" as a project dependency.
47
+ externalHelpers: true
48
+ },
49
+ module: {
50
+ // The output module resolution system that the code will be compiled for.
51
+ type: "es6"
52
+ },
53
+ env: {
54
+ // jsc.target is not provided because the provided targets takes precedence.
55
+ targets
56
+ }
57
+ };
58
+
59
+ const transformedConfig = applyTransformers(config, transformers, {
60
+ environment: "dev"
61
+ });
62
+
63
+ return transformedConfig;
64
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { Config as SwcConfig } from "@swc/core";
2
+
3
+ export type { SwcConfigTransformer, SwcConfigTransformerContext } from "./applyTransformers.ts";
4
+ export * from "./browserslistToSwc.ts";
5
+ export * from "./build.ts";
6
+ export * from "./dev.ts";
7
+ export * from "./jest.ts";
8
+ export type { SwcConfig };
9
+
package/src/jest.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { Config as SwcConfig } from "@swc/core";
2
+ import { applyTransformers, type SwcConfigTransformer } from "./applyTransformers.ts";
3
+
4
+ export interface DefineJestConfigOptions {
5
+ baseUrl?: NonNullable<SwcConfig["jsc"]>["baseUrl"];
6
+ parser?: "ecmascript" | "typescript";
7
+ paths?: NonNullable<SwcConfig["jsc"]>["paths"];
8
+ react?: boolean;
9
+ transformers?: SwcConfigTransformer[];
10
+ }
11
+
12
+ export function defineJestConfig(options: DefineJestConfigOptions = {}) {
13
+ const {
14
+ baseUrl,
15
+ parser = "typescript",
16
+ paths,
17
+ react = false,
18
+ transformers = []
19
+ } = options;
20
+
21
+ const config: SwcConfig = {
22
+ jsc: {
23
+ baseUrl,
24
+ paths,
25
+ parser: parser === "ecmascript"
26
+ ? {
27
+ syntax: "ecmascript",
28
+ jsx: react
29
+ }
30
+ : {
31
+ syntax: "typescript",
32
+ tsx: react
33
+ },
34
+ // The output environment that the code will be compiled for.
35
+ target: "esnext",
36
+ transform: react
37
+ ? {
38
+ react: {
39
+ // Use "react/jsx-runtime".
40
+ runtime: "automatic",
41
+ // Use the native "Object.assign()" instead of "_extends".
42
+ useBuiltins: true
43
+ }
44
+ }
45
+ : undefined
46
+ },
47
+ module: {
48
+ // The output module resolution system that the code will be compiled for.
49
+ type: "es6"
50
+ }
51
+ };
52
+
53
+ const transformedConfig = applyTransformers(config, transformers, {
54
+ environment: "jest"
55
+ });
56
+
57
+ return transformedConfig;
58
+ }
@@ -1,9 +0,0 @@
1
- import { Config } from '@swc/core';
2
-
3
- interface SwcConfigTransformerContext {
4
- environment: "dev" | "build" | "jest";
5
- }
6
- type SwcConfigTransformer = (config: Config, context: SwcConfigTransformerContext) => Config;
7
- declare function applyTransformers(config: Config, transformers: SwcConfigTransformer[], context: SwcConfigTransformerContext): Config;
8
-
9
- export { type SwcConfigTransformer, type SwcConfigTransformerContext, applyTransformers };
@@ -1,9 +0,0 @@
1
- import browserslist from 'browserslist';
2
-
3
- declare function createSwcTargetsFromBrowserslistEntries(entries: string[]): Record<keyof readonly ["ie", "edge", "firefox", "chrome", "safari", "opera", "ios", "android", "op_mob", "and_chr", "and_ff", "ie_mob", "samsung"], string>;
4
- interface BrowserslistToSwcOptions extends Omit<browserslist.Options, "path"> {
5
- queries?: string | string[];
6
- }
7
- declare function browserslistToSwc(options?: BrowserslistToSwcOptions): Record<keyof readonly ["ie", "edge", "firefox", "chrome", "safari", "opera", "ios", "android", "op_mob", "and_chr", "and_ff", "ie_mob", "samsung"], string>;
8
-
9
- export { type BrowserslistToSwcOptions, browserslistToSwc, createSwcTargetsFromBrowserslistEntries };
package/dist/build.d.mts DELETED
@@ -1,12 +0,0 @@
1
- import { Config } from '@swc/core';
2
- import { SwcConfigTransformer } from './applyTransformers.mjs';
3
-
4
- interface DefineBuildConfigOptions {
5
- baseUrl?: NonNullable<Config["jsc"]>["baseUrl"];
6
- parser?: "ecmascript" | "typescript";
7
- paths?: NonNullable<Config["jsc"]>["paths"];
8
- transformers?: SwcConfigTransformer[];
9
- }
10
- declare function defineBuildConfig(targets: Record<string, string>, options?: DefineBuildConfigOptions): Config;
11
-
12
- export { type DefineBuildConfigOptions, defineBuildConfig };
@@ -1,6 +0,0 @@
1
- // src/applyTransformers.ts
2
- function applyTransformers(config, transformers, context) {
3
- return transformers.reduce((acc, transformer) => transformer(acc, context), config);
4
- }
5
-
6
- export { applyTransformers };
@@ -1,53 +0,0 @@
1
- import { applyTransformers } from './chunk-3UBBOKDF.mjs';
2
-
3
- // src/dev.ts
4
- function defineDevConfig(targets, options = {}) {
5
- const {
6
- baseUrl,
7
- fastRefresh = true,
8
- parser = "typescript",
9
- paths,
10
- transformers = []
11
- } = options;
12
- const config = {
13
- jsc: {
14
- baseUrl,
15
- paths,
16
- parser: parser === "ecmascript" ? {
17
- syntax: "ecmascript",
18
- jsx: true
19
- } : {
20
- syntax: "typescript",
21
- tsx: true
22
- },
23
- transform: {
24
- react: {
25
- // Use "react/jsx-runtime".
26
- runtime: "automatic",
27
- // Use the native "Object.assign()" instead of "_extends".
28
- useBuiltins: true,
29
- // Enable React experimental "fast-refresh" feature.
30
- // Also need to install @pmmmwh/react-refresh-webpack-plugin.
31
- refresh: fastRefresh
32
- }
33
- },
34
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
35
- // Requires to add "@swc/helpers" as a project dependency.
36
- externalHelpers: true
37
- },
38
- module: {
39
- // The output module resolution system that the code will be compiled for.
40
- type: "es6"
41
- },
42
- env: {
43
- // jsc.target is not provided because the provided targets takes precedence.
44
- targets
45
- }
46
- };
47
- const transformedConfig = applyTransformers(config, transformers, {
48
- environment: "dev"
49
- });
50
- return transformedConfig;
51
- }
52
-
53
- export { defineDevConfig };
@@ -1,45 +0,0 @@
1
- import { applyTransformers } from './chunk-3UBBOKDF.mjs';
2
-
3
- // src/jest.ts
4
- function defineJestConfig(options = {}) {
5
- const {
6
- baseUrl,
7
- parser = "typescript",
8
- paths,
9
- react = false,
10
- transformers = []
11
- } = options;
12
- const config = {
13
- jsc: {
14
- baseUrl,
15
- paths,
16
- parser: parser === "ecmascript" ? {
17
- syntax: "ecmascript",
18
- jsx: react
19
- } : {
20
- syntax: "typescript",
21
- tsx: react
22
- },
23
- // The output environment that the code will be compiled for.
24
- target: "esnext",
25
- transform: react ? {
26
- react: {
27
- // Use "react/jsx-runtime".
28
- runtime: "automatic",
29
- // Use the native "Object.assign()" instead of "_extends".
30
- useBuiltins: true
31
- }
32
- } : void 0
33
- },
34
- module: {
35
- // The output module resolution system that the code will be compiled for.
36
- type: "es6"
37
- }
38
- };
39
- const transformedConfig = applyTransformers(config, transformers, {
40
- environment: "jest"
41
- });
42
- return transformedConfig;
43
- }
44
-
45
- export { defineJestConfig };