@jscutlery/swc-angular 0.12.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,91 @@
1
+ ## 0.12.0 (2024-04-12)
2
+
3
+
4
+ ### 🚀 Features
5
+
6
+ - **swc-angular:** ✨ rename swc-angular packages ([#324](https://github.com/jscutlery/devkit/pull/324))
7
+
8
+
9
+ ### ❤️ Thank You
10
+
11
+ - Younes Jaaidi
12
+
13
+ ## 0.3.0 (2024-04-11)
14
+
15
+
16
+ ### 🚀 Features
17
+
18
+ - **swc-angular-preset:** ✨ fail gracefully if @swc/core is incompatible ([#322](https://github.com/jscutlery/devkit/pull/322))
19
+
20
+
21
+ ### ❤️ Thank You
22
+
23
+ - Younes Jaaidi
24
+
25
+ ## 0.2.2 (2024-04-09)
26
+
27
+
28
+ ### 🩹 Fixes
29
+
30
+ - **swc-angular-preset:** 🐞 fix jest preset typing ([9c6de1c](https://github.com/jscutlery/devkit/commit/9c6de1c))
31
+
32
+
33
+ ### ❤️ Thank You
34
+
35
+ - Younes Jaaidi
36
+
37
+ ## 0.2.1 (2024-04-08)
38
+
39
+
40
+ ### 🩹 Fixes
41
+
42
+ - **swc-plugin-angular:** 🐞 transform async/await ([#313](https://github.com/jscutlery/devkit/pull/313))
43
+
44
+
45
+ ### ❤️ Thank You
46
+
47
+ - Younes Jaaidi
48
+
49
+ ## 0.2.0 (2024-04-04)
50
+
51
+
52
+ ### 🚀 Features
53
+
54
+ - **swc-angular-preset:** ✨ add vite support ([#307](https://github.com/jscutlery/devkit/pull/307))
55
+
56
+
57
+ ### ❤️ Thank You
58
+
59
+ - Younes Jaaidi
60
+
61
+ ## 0.1.2 (2024-04-02)
62
+
63
+ ### 🩹 Fixes
64
+
65
+ - **swc-angular-preset:** 🐞 publish dist artefact
66
+
67
+
68
+ ## 0.1.1 (2024-03-29)
69
+
70
+
71
+ ### 🩹 Fixes
72
+
73
+ - **swc-angular-preset:** 🐞 allow recent versions of swc-plugin-angular ([c715414](https://github.com/jscutlery/devkit/commit/c715414))
74
+
75
+
76
+ ### ❤️ Thank You
77
+
78
+ - Edouard Bozon @edbzn
79
+ - Younes Jaaidi
80
+
81
+ ## 0.1.0 (2024-03-26)
82
+
83
+
84
+ ### 🚀 Features
85
+
86
+ - ✨ add swc-angular-preset and swc-plugin-angular ([#273](https://github.com/jscutlery/devkit/pull/273))
87
+
88
+
89
+ ### ❤️ Thank You
90
+
91
+ - Edouard Bozon @edbzn
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 jscutlery
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # ⚡️ Speed Up Angular Testing with SWC 🦀
2
+
3
+ ## 👀 What is this?
4
+
5
+ This is a set of Angular presets that enable you to use [SWC (Speedy Web Compiler)](https://swc.rs/) with Jest or
6
+ Vitest.
7
+
8
+ **Switching to SWC can speed up your tests by 2x to 5x.**
9
+
10
+ ## 🤔 Context
11
+
12
+ Surprisingly, in most cases, the bottleneck in Jest & Vitest tests is not the test execution time nor the Angular JIT
13
+ (Just-In-Time) compiler but the TypeScript transformer.
14
+
15
+ This is where SWC (Speedy Web Compiler) comes in. SWC is a JavaScript/TypeScript compiler that aims to be extremely
16
+ fast.
17
+
18
+ This package enables you to use SWC with Angular projects by setting the right configuration for SWC and using
19
+ our Angular plugin for SWC [`@jscutlery/swc-angular-plugin`](../swc-angular-plugin)
20
+
21
+ ## 🥇 Benchmark
22
+
23
+ | ts-jest | @swc/jest |
24
+ |---------|---------------------|
25
+ | 85s | 35s _(2.4x faster)_ |
26
+
27
+ 💻 try it yourself: https://github.com/yjaaidi/experiments/tree/angular-jest-swc-benchmark
28
+
29
+ ## 🎭 Setup with Jest
30
+
31
+ ### 1. Install
32
+
33
+ Install this preset and its dependencies via npm:
34
+
35
+ ```sh
36
+ npm install -D @jscutlery/swc-angular @jscutlery/swc-angular-plugin @swc/core @swc/jest
37
+ grep .swc .gitignore || echo .swc >> .gitignore
38
+ ```
39
+
40
+ ### 2. Configure
41
+
42
+ In your Jest configuration file (e.g., `jest.config.ts`), use the `swcAngularJestTransformer` function to
43
+ transform `.ts`, `.js`, and `.mjs` files.
44
+
45
+ ```js
46
+ import { swcAngularJestTransformer } from '@jscutlery/swc-angular';
47
+
48
+ export default {
49
+ // ...
50
+ transform: {
51
+ '^.+\\.(ts|mjs|js)$': swcAngularJestTransformer(),
52
+ '^.+\\.(html)$':
53
+ [
54
+ 'jest-preset-angular',
55
+ {
56
+ tsconfig: '<rootDir>/tsconfig.spec.json',
57
+ stringifyContentPathRegex: '\\.(html|svg)$',
58
+ },
59
+ ],
60
+ },
61
+ transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
62
+ // ...
63
+ };
64
+ ```
65
+
66
+ ### 3. Add `reflect-metadata`
67
+
68
+ In order for constructor injection to work, you need to import `reflect-metadata` in the setup file which is probably
69
+ located at `src/test-setup.ts`.
70
+
71
+ ```ts
72
+ import 'reflect-metadata';
73
+ ```
74
+
75
+ ## ⚡️Setup with Vitest
76
+
77
+ ### 1. Install
78
+
79
+ Install this preset and its dependencies via npm:
80
+
81
+ ```sh
82
+ npm install -D @jscutlery/swc-angular @jscutlery/swc-angular-plugin @swc/core unplugin-swc
83
+ grep .swc .gitignore || echo .swc >> .gitignore
84
+ ```
85
+
86
+ ### 2. Configure
87
+
88
+ In your vite configuration file (e.g., `vite.config.ts`), use the `unplugin-swc` plugin with our
89
+ preset: `swcAngularVitePreset`.
90
+
91
+ ```js
92
+ import { swcAngularUnpluginOptions } from '@jscutlery/swc-angular';
93
+ import swc from 'unplugin-swc';
94
+ import { defineConfig } from 'vite';
95
+
96
+ export default defineConfig({
97
+ // ...
98
+ plugins: [swc.vite(swcAngularUnpluginOptions())]
99
+ // ...
100
+ });
101
+ ```
102
+
103
+ ### 3. Add `reflect-metadata`
104
+
105
+ In order for constructor injection to work, you need to import `reflect-metadata` in the setup file which is probably
106
+ located at `src/test-setup.ts`.
107
+
108
+ ```ts
109
+ import 'reflect-metadata';
110
+ ```
package/index.cjs.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/index";
2
+ export { default } from "./src/index";
package/index.cjs.js ADDED
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@swc/core');
6
+
7
+ function _extends() {
8
+ _extends = Object.assign || function assign(target) {
9
+ for(var i = 1; i < arguments.length; i++){
10
+ var source = arguments[i];
11
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
12
+ }
13
+ return target;
14
+ };
15
+ return _extends.apply(this, arguments);
16
+ }
17
+
18
+ assertCompatibleSwcCoreVersion();
19
+ function swcAngularPreset(options = {}) {
20
+ return {
21
+ jsc: {
22
+ parser: {
23
+ syntax: 'typescript',
24
+ decorators: true,
25
+ dynamicImport: true
26
+ },
27
+ transform: {
28
+ legacyDecorator: true,
29
+ decoratorMetadata: true
30
+ },
31
+ experimental: {
32
+ plugins: [
33
+ [
34
+ '@jscutlery/swc-angular-plugin',
35
+ {
36
+ templateRawSuffix: options.templateRawSuffix
37
+ }
38
+ ]
39
+ ]
40
+ }
41
+ },
42
+ env: {
43
+ include: [
44
+ 'transform-async-to-generator'
45
+ ]
46
+ }
47
+ };
48
+ }
49
+ function swcAngularJestTransformer() {
50
+ return [
51
+ '@swc/jest',
52
+ swcAngularPreset()
53
+ ];
54
+ }
55
+ function swcAngularVitePreset() {
56
+ return swcAngularPreset({
57
+ templateRawSuffix: true
58
+ });
59
+ }
60
+ function swcAngularUnpluginOptions() {
61
+ return _extends({}, swcAngularVitePreset(), {
62
+ /* Since we are using SWC's env option, we need to disable the tsconfigFile option.
63
+ * Otherwise `unpluggin-swc` will try to use the target from the tsconfig's `compilerOptions`,
64
+ * and make SWC produce the following error: "`env` and `jsc.target` cannot be used together".
65
+ *
66
+ * We could have added this extra option to `swcAngularVitePreset`, but forwarding any extra option
67
+ * to SWC will make SWC's configuration parser fail.
68
+ *
69
+ * Cf. https://github.com/unplugin/unplugin-swc/issues/137 */ tsconfigFile: false
70
+ });
71
+ }
72
+ /**
73
+ * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead.
74
+ */ var index = swcAngularPreset();
75
+ function assertCompatibleSwcCoreVersion() {
76
+ if (!core.version.startsWith('1.4.')) {
77
+ console.warn(`
78
+ @swc/core version ${core.version} is incompatible with @jscutlery/swc-angular.
79
+ Please use @swc/core version 1.4.x.
80
+ > npm add -D @swc/core@~1.4.0
81
+ `);
82
+ process.exit(1);
83
+ }
84
+ }
85
+
86
+ exports["default"] = index;
87
+ exports.swcAngularJestTransformer = swcAngularJestTransformer;
88
+ exports.swcAngularPreset = swcAngularPreset;
89
+ exports.swcAngularUnpluginOptions = swcAngularUnpluginOptions;
90
+ exports.swcAngularVitePreset = swcAngularVitePreset;
package/index.esm.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/index";
2
+ export { default } from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,82 @@
1
+ import { version } from '@swc/core';
2
+
3
+ function _extends() {
4
+ _extends = Object.assign || function assign(target) {
5
+ for(var i = 1; i < arguments.length; i++){
6
+ var source = arguments[i];
7
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
8
+ }
9
+ return target;
10
+ };
11
+ return _extends.apply(this, arguments);
12
+ }
13
+
14
+ assertCompatibleSwcCoreVersion();
15
+ function swcAngularPreset(options = {}) {
16
+ return {
17
+ jsc: {
18
+ parser: {
19
+ syntax: 'typescript',
20
+ decorators: true,
21
+ dynamicImport: true
22
+ },
23
+ transform: {
24
+ legacyDecorator: true,
25
+ decoratorMetadata: true
26
+ },
27
+ experimental: {
28
+ plugins: [
29
+ [
30
+ '@jscutlery/swc-angular-plugin',
31
+ {
32
+ templateRawSuffix: options.templateRawSuffix
33
+ }
34
+ ]
35
+ ]
36
+ }
37
+ },
38
+ env: {
39
+ include: [
40
+ 'transform-async-to-generator'
41
+ ]
42
+ }
43
+ };
44
+ }
45
+ function swcAngularJestTransformer() {
46
+ return [
47
+ '@swc/jest',
48
+ swcAngularPreset()
49
+ ];
50
+ }
51
+ function swcAngularVitePreset() {
52
+ return swcAngularPreset({
53
+ templateRawSuffix: true
54
+ });
55
+ }
56
+ function swcAngularUnpluginOptions() {
57
+ return _extends({}, swcAngularVitePreset(), {
58
+ /* Since we are using SWC's env option, we need to disable the tsconfigFile option.
59
+ * Otherwise `unpluggin-swc` will try to use the target from the tsconfig's `compilerOptions`,
60
+ * and make SWC produce the following error: "`env` and `jsc.target` cannot be used together".
61
+ *
62
+ * We could have added this extra option to `swcAngularVitePreset`, but forwarding any extra option
63
+ * to SWC will make SWC's configuration parser fail.
64
+ *
65
+ * Cf. https://github.com/unplugin/unplugin-swc/issues/137 */ tsconfigFile: false
66
+ });
67
+ }
68
+ /**
69
+ * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead.
70
+ */ var index = swcAngularPreset();
71
+ function assertCompatibleSwcCoreVersion() {
72
+ if (!version.startsWith('1.4.')) {
73
+ console.warn(`
74
+ @swc/core version ${version} is incompatible with @jscutlery/swc-angular.
75
+ Please use @swc/core version 1.4.x.
76
+ > npm add -D @swc/core@~1.4.0
77
+ `);
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ export { index as default, swcAngularJestTransformer, swcAngularPreset, swcAngularUnpluginOptions, swcAngularVitePreset };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@jscutlery/swc-angular",
3
+ "version": "0.12.0",
4
+ "repository": {
5
+ "url": "https://github.com/jscutlery/devkit"
6
+ },
7
+ "keywords": [
8
+ "SWC",
9
+ "Angular",
10
+ "Plugin",
11
+ "Testing"
12
+ ],
13
+ "peerDependencies": {
14
+ "@jscutlery/swc-angular-plugin": ">=0.11.0 <1.0.0",
15
+ "@swc/core": "~1.4.0"
16
+ },
17
+ "module": "./index.esm.js",
18
+ "main": "./index.cjs.js"
19
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import type { Config } from '@swc/core';
2
+ export interface AngularPresetOptions {
3
+ templateRawSuffix?: boolean;
4
+ }
5
+ export declare function swcAngularPreset(options?: AngularPresetOptions): {
6
+ jsc: {
7
+ parser: {
8
+ syntax: "typescript";
9
+ decorators: true;
10
+ dynamicImport: true;
11
+ };
12
+ transform: {
13
+ legacyDecorator: true;
14
+ decoratorMetadata: true;
15
+ };
16
+ experimental: {
17
+ plugins: [string, SwcPluginAngularOptions][];
18
+ };
19
+ };
20
+ env: {
21
+ include: string[];
22
+ };
23
+ };
24
+ export declare function swcAngularJestTransformer(): [string, Record<string, unknown>];
25
+ export declare function swcAngularVitePreset(): {
26
+ jsc: {
27
+ parser: {
28
+ syntax: "typescript";
29
+ decorators: true;
30
+ dynamicImport: true;
31
+ };
32
+ transform: {
33
+ legacyDecorator: true;
34
+ decoratorMetadata: true;
35
+ };
36
+ experimental: {
37
+ plugins: [string, SwcPluginAngularOptions][];
38
+ };
39
+ };
40
+ env: {
41
+ include: string[];
42
+ };
43
+ };
44
+ export declare function swcAngularUnpluginOptions(): Config & {
45
+ tsconfigFile?: boolean;
46
+ };
47
+ interface SwcPluginAngularOptions {
48
+ templateRawSuffix?: boolean;
49
+ }
50
+ /**
51
+ * @deprecated Use {@link swcAngularVitePreset}, {@link swcAngularJestTransformer} or {@link swcAngularPreset} instead.
52
+ */
53
+ declare const _default: {
54
+ jsc: {
55
+ parser: {
56
+ syntax: "typescript";
57
+ decorators: true;
58
+ dynamicImport: true;
59
+ };
60
+ transform: {
61
+ legacyDecorator: true;
62
+ decoratorMetadata: true;
63
+ };
64
+ experimental: {
65
+ plugins: [string, SwcPluginAngularOptions][];
66
+ };
67
+ };
68
+ env: {
69
+ include: string[];
70
+ };
71
+ };
72
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};