@workleap/swc-configs 1.0.0 → 1.0.1

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.
package/dist/index.js CHANGED
@@ -1,168 +1,157 @@
1
1
  'use strict';
2
2
 
3
- // src/cloneObjectExceptFunctions.ts
4
- function cloneObjectExceptFunctions(obj) {
5
- return JSON.parse(JSON.stringify(obj));
6
- }
7
-
8
- // src/resolveOverrides.ts
9
- function resolveOverrides(config, configOverride) {
10
- if (typeof configOverride === "function") {
11
- return {
12
- ...config,
13
- ...configOverride(config)
14
- };
15
- }
16
- if (configOverride) {
17
- return {
18
- ...config,
19
- ...configOverride
20
- };
21
- }
22
- return config;
3
+ // src/applyTransformers.ts
4
+ function applyTransformers(config, transformers, context) {
5
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
23
6
  }
24
7
 
25
8
  // src/build.ts
26
- var DefaultBuildConfig = {
27
- jsc: {
28
- parser: {
29
- syntax: "typescript",
30
- tsx: true
31
- },
32
- // The output environment that the code will be compiled for.
33
- target: "es2022",
34
- // View https://swc.rs/docs/configuration/minification for options.
35
- minify: {
36
- compress: true,
37
- mangle: true
9
+ function defineBuildConfig(options) {
10
+ const {
11
+ browsers,
12
+ parser = "typescript",
13
+ transformers = []
14
+ } = options;
15
+ const config = {
16
+ jsc: {
17
+ parser: parser === "ecmascript" ? {
18
+ syntax: "ecmascript",
19
+ jsx: true
20
+ } : {
21
+ syntax: "typescript",
22
+ tsx: true
23
+ },
24
+ // The output environment that the code will be compiled for.
25
+ target: "es2022",
26
+ // View https://swc.rs/docs/configuration/minification for options.
27
+ minify: {
28
+ compress: true,
29
+ mangle: true
30
+ },
31
+ transform: {
32
+ react: {
33
+ // Use "react/jsx-runtime".
34
+ runtime: "automatic",
35
+ // Use the native "Object.assign()" instead of "_extends".
36
+ useBuiltins: true
37
+ }
38
+ },
39
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
40
+ // Requires to add "@swc/helpers" as a project dependency.
41
+ externalHelpers: true
38
42
  },
39
- transform: {
40
- react: {
41
- // Use "react/jsx-runtime".
42
- runtime: "automatic",
43
- // Use the native "Object.assign()" instead of "_extends".
44
- useBuiltins: true
45
- }
43
+ module: {
44
+ // The output module resolution system that the code will be compiled for.
45
+ type: "es6",
46
+ // Prevent SWC from exporting the `__esModule` property.
47
+ strict: true,
48
+ // Preserve dynamic imports.
49
+ ignoreDynamic: true
46
50
  },
47
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
48
- // Requires to add "@swc/helpers" as a project dependency
49
- externalHelpers: true
50
- },
51
- module: {
52
- // The output module resolution system that the code will be compiled for.
53
- type: "es6",
54
- // Prevent SWC from exporting the `__esModule` property.
55
- strict: true,
56
- // Preserve dynamic imports.
57
- ignoreDynamic: true
58
- }
59
- };
60
- function defineBuildConfig({ parser, configOverride } = {}) {
61
- const config = cloneObjectExceptFunctions(DefaultBuildConfig);
62
- if (parser === "ecmascript") {
63
- config.jsc.parser = {
64
- syntax: "ecmascript",
65
- jsx: true
66
- };
67
- }
68
- return resolveOverrides(config, configOverride);
51
+ env: {
52
+ targets: browsers
53
+ }
54
+ };
55
+ const transformedConfig = applyTransformers(config, transformers, {
56
+ environment: "build"
57
+ });
58
+ return transformedConfig;
69
59
  }
70
60
 
71
61
  // src/dev.ts
72
- var DefaultDevConfig = {
73
- jsc: {
74
- parser: {
75
- syntax: "typescript",
76
- tsx: true
62
+ function defineDevConfig(options) {
63
+ const {
64
+ browsers,
65
+ fastRefresh = false,
66
+ parser = "typescript",
67
+ transformers = []
68
+ } = options;
69
+ const config = {
70
+ jsc: {
71
+ parser: parser === "ecmascript" ? {
72
+ syntax: "ecmascript",
73
+ jsx: true
74
+ } : {
75
+ syntax: "typescript",
76
+ tsx: true
77
+ },
78
+ // The output environment that the code will be compiled for.
79
+ target: "es2022",
80
+ transform: {
81
+ react: {
82
+ // Use "react/jsx-runtime".
83
+ runtime: "automatic",
84
+ // Use the native "Object.assign()" instead of "_extends".
85
+ useBuiltins: true,
86
+ // Enable React experimental "fast-refresh" feature.
87
+ // Also need to install @pmmmwh/react-refresh-webpack-plugin.
88
+ refresh: fastRefresh
89
+ }
90
+ },
91
+ // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
92
+ // Requires to add "@swc/helpers" as a project dependency.
93
+ externalHelpers: true
77
94
  },
78
- // The output environment that the code will be compiled for.
79
- target: "es2022",
80
- transform: {
81
- react: {
82
- // Use "react/jsx-runtime".
83
- runtime: "automatic",
84
- // Use the native "Object.assign()" instead of "_extends".
85
- useBuiltins: true,
86
- // Enable React experimental "fast-refresh" feature.
87
- // Also need to install @pmmmwh/react-refresh-webpack-plugin.
88
- refresh: false
89
- }
95
+ module: {
96
+ // The output module resolution system that the code will be compiled for.
97
+ type: "es6",
98
+ // Prevent SWC from exporting the `__esModule` property.
99
+ strict: true,
100
+ // Preserve dynamic imports.
101
+ ignoreDynamic: true
90
102
  },
91
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
92
- // Requires to add "@swc/helpers" as a project dependency
93
- externalHelpers: true
94
- },
95
- module: {
96
- // The output module resolution system that the code will be compiled for.
97
- type: "es6",
98
- // Prevent SWC from exporting the `__esModule` property.
99
- strict: true,
100
- // Preserve dynamic imports.
101
- ignoreDynamic: true
102
- }
103
- };
104
- function defineDevConfig({ fastRefresh, parser, configOverride } = {}) {
105
- const config = cloneObjectExceptFunctions(DefaultDevConfig);
106
- if (fastRefresh) {
107
- config.jsc.transform.react.refresh = true;
108
- }
109
- if (parser === "ecmascript") {
110
- config.jsc.parser = {
111
- syntax: "ecmascript",
112
- jsx: true
113
- };
114
- }
115
- return resolveOverrides(config, configOverride);
103
+ env: {
104
+ targets: browsers
105
+ }
106
+ };
107
+ const transformedConfig = applyTransformers(config, transformers, {
108
+ environment: "dev"
109
+ });
110
+ return transformedConfig;
116
111
  }
117
112
 
118
113
  // src/jest.ts
119
- var DefaultJestConfig = {
120
- jsc: {
121
- parser: {
122
- syntax: "typescript"
114
+ function defineJestConfig(options = {}) {
115
+ const {
116
+ react = false,
117
+ parser = "typescript",
118
+ transformers = []
119
+ } = options;
120
+ const config = {
121
+ jsc: {
122
+ parser: parser === "ecmascript" ? {
123
+ syntax: "ecmascript",
124
+ jsx: react
125
+ } : {
126
+ syntax: "typescript",
127
+ tsx: react
128
+ },
129
+ // The output environment that the code will be compiled for.
130
+ target: "es2022",
131
+ transform: react ? {
132
+ react: {
133
+ // Use "react/jsx-runtime".
134
+ runtime: "automatic",
135
+ // Use the native "Object.assign()" instead of "_extends".
136
+ useBuiltins: true
137
+ }
138
+ } : void 0
123
139
  },
124
- // The output environment that the code will be compiled for.
125
- target: "es2022",
126
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
127
- // Requires to add "@swc/helpers" as a project dependency
128
- externalHelpers: true
129
- },
130
- module: {
131
- // The output module resolution system that the code will be compiled for.
132
- type: "es6",
133
- // Prevent SWC from exporting the `__esModule` property.
134
- strict: true,
135
- // Preserve dynamic imports.
136
- ignoreDynamic: true
137
- }
138
- };
139
- function defineJestConfig({ react, parser, configOverride } = {}) {
140
- const config = cloneObjectExceptFunctions(DefaultJestConfig);
141
- if (react) {
142
- config.jsc.transform = {
143
- react: {
144
- // Use "react/jsx-runtime".
145
- runtime: "automatic",
146
- // Use the native "Object.assign()" instead of "_extends".
147
- useBuiltins: true
148
- }
149
- };
150
- }
151
- if (parser === "ecmascript") {
152
- const parserConfig = { syntax: "ecmascript" };
153
- if (react) {
154
- parserConfig.jsx = true;
140
+ module: {
141
+ // The output module resolution system that the code will be compiled for.
142
+ type: "es6",
143
+ // Prevent SWC from exporting the `__esModule` property.
144
+ strict: true,
145
+ // Preserve dynamic imports.
146
+ ignoreDynamic: true
155
147
  }
156
- config.jsc.parser = parserConfig;
157
- } else if (react) {
158
- config.jsc.parser.tsx = true;
159
- }
160
- return resolveOverrides(config, configOverride);
148
+ };
149
+ const transformedConfig = applyTransformers(config, transformers, {
150
+ environment: "jest"
151
+ });
152
+ return transformedConfig;
161
153
  }
162
154
 
163
- exports.DefaultBuildConfig = DefaultBuildConfig;
164
- exports.DefaultDevConfig = DefaultDevConfig;
165
- exports.DefaultJestConfig = DefaultJestConfig;
166
155
  exports.defineBuildConfig = defineBuildConfig;
167
156
  exports.defineDevConfig = defineDevConfig;
168
157
  exports.defineJestConfig = defineJestConfig;
package/dist/index.mjs CHANGED
@@ -1,5 +1,4 @@
1
- export { DefaultBuildConfig, defineBuildConfig } from './chunk-JW562DWU.mjs';
2
- export { DefaultDevConfig, defineDevConfig } from './chunk-4XYHUSOR.mjs';
3
- export { DefaultJestConfig, defineJestConfig } from './chunk-5HQ4FWBC.mjs';
4
- import './chunk-XCGQZSNA.mjs';
5
- import './chunk-4LXCYXR5.mjs';
1
+ export { defineBuildConfig } from './chunk-UFEY2RGG.mjs';
2
+ export { defineDevConfig } from './chunk-LPGVRYUE.mjs';
3
+ export { defineJestConfig } from './chunk-6PUKUTDM.mjs';
4
+ import './chunk-3UBBOKDF.mjs';
package/dist/jest.d.ts CHANGED
@@ -1,25 +1,11 @@
1
1
  import { Config } from '@swc/core';
2
- import { ConfigOverride } from './resolveOverrides.js';
2
+ import { SwcConfigTransformer } from './applyTransformers.js';
3
3
 
4
- declare const DefaultJestConfig: {
5
- jsc: {
6
- parser: {
7
- syntax: "typescript";
8
- };
9
- target: "es2022";
10
- externalHelpers: true;
11
- };
12
- module: {
13
- type: "es6";
14
- strict: true;
15
- ignoreDynamic: true;
16
- };
17
- };
18
4
  interface DefineJestConfigOptions {
19
5
  react?: boolean;
20
- parser?: "ecmascript";
21
- configOverride?: ConfigOverride;
6
+ parser?: "ecmascript" | "typescript";
7
+ transformers?: SwcConfigTransformer[];
22
8
  }
23
- declare function defineJestConfig({ react, parser, configOverride }?: DefineJestConfigOptions): Config;
9
+ declare function defineJestConfig(options?: DefineJestConfigOptions): Config;
24
10
 
25
- export { DefaultJestConfig, DefineJestConfigOptions, defineJestConfig };
11
+ export { DefineJestConfigOptions, defineJestConfig };
package/dist/jest.js CHANGED
@@ -1,71 +1,50 @@
1
1
  'use strict';
2
2
 
3
- // src/cloneObjectExceptFunctions.ts
4
- function cloneObjectExceptFunctions(obj) {
5
- return JSON.parse(JSON.stringify(obj));
6
- }
7
-
8
- // src/resolveOverrides.ts
9
- function resolveOverrides(config, configOverride) {
10
- if (typeof configOverride === "function") {
11
- return {
12
- ...config,
13
- ...configOverride(config)
14
- };
15
- }
16
- if (configOverride) {
17
- return {
18
- ...config,
19
- ...configOverride
20
- };
21
- }
22
- return config;
3
+ // src/applyTransformers.ts
4
+ function applyTransformers(config, transformers, context) {
5
+ return transformers.reduce((acc, transformer) => transformer(acc, context), config);
23
6
  }
24
7
 
25
8
  // src/jest.ts
26
- var DefaultJestConfig = {
27
- jsc: {
28
- parser: {
29
- syntax: "typescript"
9
+ function defineJestConfig(options = {}) {
10
+ const {
11
+ react = false,
12
+ parser = "typescript",
13
+ transformers = []
14
+ } = options;
15
+ const config = {
16
+ jsc: {
17
+ parser: parser === "ecmascript" ? {
18
+ syntax: "ecmascript",
19
+ jsx: react
20
+ } : {
21
+ syntax: "typescript",
22
+ tsx: react
23
+ },
24
+ // The output environment that the code will be compiled for.
25
+ target: "es2022",
26
+ transform: react ? {
27
+ react: {
28
+ // Use "react/jsx-runtime".
29
+ runtime: "automatic",
30
+ // Use the native "Object.assign()" instead of "_extends".
31
+ useBuiltins: true
32
+ }
33
+ } : void 0
30
34
  },
31
- // The output environment that the code will be compiled for.
32
- target: "es2022",
33
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
34
- // Requires to add "@swc/helpers" as a project dependency
35
- externalHelpers: true
36
- },
37
- module: {
38
- // The output module resolution system that the code will be compiled for.
39
- type: "es6",
40
- // Prevent SWC from exporting the `__esModule` property.
41
- strict: true,
42
- // Preserve dynamic imports.
43
- ignoreDynamic: true
44
- }
45
- };
46
- function defineJestConfig({ react, parser, configOverride } = {}) {
47
- const config = cloneObjectExceptFunctions(DefaultJestConfig);
48
- if (react) {
49
- config.jsc.transform = {
50
- react: {
51
- // Use "react/jsx-runtime".
52
- runtime: "automatic",
53
- // Use the native "Object.assign()" instead of "_extends".
54
- useBuiltins: true
55
- }
56
- };
57
- }
58
- if (parser === "ecmascript") {
59
- const parserConfig = { syntax: "ecmascript" };
60
- if (react) {
61
- parserConfig.jsx = true;
35
+ module: {
36
+ // The output module resolution system that the code will be compiled for.
37
+ type: "es6",
38
+ // Prevent SWC from exporting the `__esModule` property.
39
+ strict: true,
40
+ // Preserve dynamic imports.
41
+ ignoreDynamic: true
62
42
  }
63
- config.jsc.parser = parserConfig;
64
- } else if (react) {
65
- config.jsc.parser.tsx = true;
66
- }
67
- return resolveOverrides(config, configOverride);
43
+ };
44
+ const transformedConfig = applyTransformers(config, transformers, {
45
+ environment: "jest"
46
+ });
47
+ return transformedConfig;
68
48
  }
69
49
 
70
- exports.DefaultJestConfig = DefaultJestConfig;
71
50
  exports.defineJestConfig = defineJestConfig;
package/dist/jest.mjs CHANGED
@@ -1,3 +1,2 @@
1
- export { DefaultJestConfig, defineJestConfig } from './chunk-5HQ4FWBC.mjs';
2
- import './chunk-XCGQZSNA.mjs';
3
- import './chunk-4LXCYXR5.mjs';
1
+ export { defineJestConfig } from './chunk-6PUKUTDM.mjs';
2
+ import './chunk-3UBBOKDF.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workleap/swc-configs",
3
3
  "description": "Workleap recommended SWC configs.",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
7
7
  "workleap",
@@ -12,7 +12,8 @@
12
12
  ".": {
13
13
  "require": "./dist/index.js",
14
14
  "import": "./dist/index.mjs",
15
- "types": "./dist/index.d.ts"
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.mjs"
16
17
  }
17
18
  },
18
19
  "files": [
@@ -22,7 +23,7 @@
22
23
  ],
23
24
  "repository": {
24
25
  "type": "git",
25
- "url": "git+https://github.com/workleap/wl-web-configs.git",
26
+ "url": "git+https://github.com/gsoft-inc/wl-web-configs.git",
26
27
  "directory": "packages/swc-configs"
27
28
  },
28
29
  "devDependencies": {
@@ -34,9 +35,9 @@
34
35
  "ts-node": "10.9.1",
35
36
  "tsup": "6.7.0",
36
37
  "typescript": "5.0.4",
37
- "@workleap/eslint-plugin": "1.8.2",
38
- "@workleap/tsup-configs": "2.0.0",
39
- "@workleap/typescript-configs": "2.3.2"
38
+ "@workleap/eslint-plugin": "1.8.3",
39
+ "@workleap/tsup-configs": "2.0.1",
40
+ "@workleap/typescript-configs": "2.3.3"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "@swc/core": "*",
@@ -1,18 +0,0 @@
1
- // src/resolveOverrides.ts
2
- function resolveOverrides(config, configOverride) {
3
- if (typeof configOverride === "function") {
4
- return {
5
- ...config,
6
- ...configOverride(config)
7
- };
8
- }
9
- if (configOverride) {
10
- return {
11
- ...config,
12
- ...configOverride
13
- };
14
- }
15
- return config;
16
- }
17
-
18
- export { resolveOverrides };
@@ -1,51 +0,0 @@
1
- import { cloneObjectExceptFunctions } from './chunk-XCGQZSNA.mjs';
2
- import { resolveOverrides } from './chunk-4LXCYXR5.mjs';
3
-
4
- // src/dev.ts
5
- var DefaultDevConfig = {
6
- jsc: {
7
- parser: {
8
- syntax: "typescript",
9
- tsx: true
10
- },
11
- // The output environment that the code will be compiled for.
12
- target: "es2022",
13
- transform: {
14
- react: {
15
- // Use "react/jsx-runtime".
16
- runtime: "automatic",
17
- // Use the native "Object.assign()" instead of "_extends".
18
- useBuiltins: true,
19
- // Enable React experimental "fast-refresh" feature.
20
- // Also need to install @pmmmwh/react-refresh-webpack-plugin.
21
- refresh: false
22
- }
23
- },
24
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
25
- // Requires to add "@swc/helpers" as a project dependency
26
- externalHelpers: true
27
- },
28
- module: {
29
- // The output module resolution system that the code will be compiled for.
30
- type: "es6",
31
- // Prevent SWC from exporting the `__esModule` property.
32
- strict: true,
33
- // Preserve dynamic imports.
34
- ignoreDynamic: true
35
- }
36
- };
37
- function defineDevConfig({ fastRefresh, parser, configOverride } = {}) {
38
- const config = cloneObjectExceptFunctions(DefaultDevConfig);
39
- if (fastRefresh) {
40
- config.jsc.transform.react.refresh = true;
41
- }
42
- if (parser === "ecmascript") {
43
- config.jsc.parser = {
44
- syntax: "ecmascript",
45
- jsx: true
46
- };
47
- }
48
- return resolveOverrides(config, configOverride);
49
- }
50
-
51
- export { DefaultDevConfig, defineDevConfig };
@@ -1,49 +0,0 @@
1
- import { cloneObjectExceptFunctions } from './chunk-XCGQZSNA.mjs';
2
- import { resolveOverrides } from './chunk-4LXCYXR5.mjs';
3
-
4
- // src/jest.ts
5
- var DefaultJestConfig = {
6
- jsc: {
7
- parser: {
8
- syntax: "typescript"
9
- },
10
- // The output environment that the code will be compiled for.
11
- target: "es2022",
12
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
13
- // Requires to add "@swc/helpers" as a project dependency
14
- externalHelpers: true
15
- },
16
- module: {
17
- // The output module resolution system that the code will be compiled for.
18
- type: "es6",
19
- // Prevent SWC from exporting the `__esModule` property.
20
- strict: true,
21
- // Preserve dynamic imports.
22
- ignoreDynamic: true
23
- }
24
- };
25
- function defineJestConfig({ react, parser, configOverride } = {}) {
26
- const config = cloneObjectExceptFunctions(DefaultJestConfig);
27
- if (react) {
28
- config.jsc.transform = {
29
- react: {
30
- // Use "react/jsx-runtime".
31
- runtime: "automatic",
32
- // Use the native "Object.assign()" instead of "_extends".
33
- useBuiltins: true
34
- }
35
- };
36
- }
37
- if (parser === "ecmascript") {
38
- const parserConfig = { syntax: "ecmascript" };
39
- if (react) {
40
- parserConfig.jsx = true;
41
- }
42
- config.jsc.parser = parserConfig;
43
- } else if (react) {
44
- config.jsc.parser.tsx = true;
45
- }
46
- return resolveOverrides(config, configOverride);
47
- }
48
-
49
- export { DefaultJestConfig, defineJestConfig };
@@ -1,50 +0,0 @@
1
- import { cloneObjectExceptFunctions } from './chunk-XCGQZSNA.mjs';
2
- import { resolveOverrides } from './chunk-4LXCYXR5.mjs';
3
-
4
- // src/build.ts
5
- var DefaultBuildConfig = {
6
- jsc: {
7
- parser: {
8
- syntax: "typescript",
9
- tsx: true
10
- },
11
- // The output environment that the code will be compiled for.
12
- target: "es2022",
13
- // View https://swc.rs/docs/configuration/minification for options.
14
- minify: {
15
- compress: true,
16
- mangle: true
17
- },
18
- transform: {
19
- react: {
20
- // Use "react/jsx-runtime".
21
- runtime: "automatic",
22
- // Use the native "Object.assign()" instead of "_extends".
23
- useBuiltins: true
24
- }
25
- },
26
- // Import shims from an external module rather than inlining them in bundle files to greatly reduce the bundles size.
27
- // Requires to add "@swc/helpers" as a project dependency
28
- externalHelpers: true
29
- },
30
- module: {
31
- // The output module resolution system that the code will be compiled for.
32
- type: "es6",
33
- // Prevent SWC from exporting the `__esModule` property.
34
- strict: true,
35
- // Preserve dynamic imports.
36
- ignoreDynamic: true
37
- }
38
- };
39
- function defineBuildConfig({ parser, configOverride } = {}) {
40
- const config = cloneObjectExceptFunctions(DefaultBuildConfig);
41
- if (parser === "ecmascript") {
42
- config.jsc.parser = {
43
- syntax: "ecmascript",
44
- jsx: true
45
- };
46
- }
47
- return resolveOverrides(config, configOverride);
48
- }
49
-
50
- export { DefaultBuildConfig, defineBuildConfig };