@veryfront/ext-bundler-swc 0.1.1252-bootstrap.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Veryfront Code
2
+ Copyright 2026 Veryfront GmbH
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @veryfront/ext-bundler-swc
2
+
3
+ > **Category:** Build | **Contract:** `Bundler` | **Explicit**
4
+
5
+ Adds an opt-in SWC TypeScript transform before Veryfront's esbuild graph
6
+ bundler. Use it for libraries that require legacy TypeScript decorator metadata,
7
+ such as class-validator, TypeORM, and constructor-based dependency injection.
8
+
9
+ The default Veryfront bundler remains esbuild. Projects that do not select this
10
+ extension keep the existing output and standard decorator behavior.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ deno add npm:@veryfront/ext-bundler-swc
16
+ ```
17
+
18
+ ```bash
19
+ npm install @veryfront/ext-bundler-swc
20
+ ```
21
+
22
+ ## Configure
23
+
24
+ Register the extension explicitly in `veryfront.config.ts`:
25
+
26
+ ```ts
27
+ import { defineConfig } from "veryfront";
28
+ import extSwc from "@veryfront/ext-bundler-swc";
29
+
30
+ export default defineConfig({
31
+ extensions: [extSwc()],
32
+ });
33
+ ```
34
+
35
+ Enable both legacy decorator flags in `tsconfig.json`:
36
+
37
+ ```json
38
+ {
39
+ "compilerOptions": {
40
+ "experimentalDecorators": true,
41
+ "emitDecoratorMetadata": true
42
+ }
43
+ }
44
+ ```
45
+
46
+ Veryfront follows inherited TypeScript configuration. The extension embeds
47
+ `reflect-metadata` before an opted-in decorated module runs, including prepared
48
+ worker modules and compiled runtime routes.
49
+
50
+ Trusted host execution can follow configuration outside the project directory.
51
+ Isolated preparation accepts parent and package configuration only when it stays
52
+ inside the project boundary, including project-owned `node_modules`. Copy an
53
+ external shared configuration into the project before using it in an isolated
54
+ runtime.
55
+
56
+ If `experimentalDecorators` is false or absent, the extension delegates source
57
+ unchanged to esbuild when Veryfront already needs a bundle or transform. Local
58
+ Deno routes keep their normal direct-import path. If only
59
+ `experimentalDecorators` is true, SWC emits legacy decorators without runtime
60
+ type metadata.
61
+
62
+ ## What changes when you enable it
63
+
64
+ `experimentalDecorators: true` switches the TypeScript transform for the whole
65
+ project boundary, not just for decorated files. Every `.ts` and `.tsx` module in
66
+ the build graph is compiled by SWC instead of esbuild, so the emitted JavaScript
67
+ can differ in places that have nothing to do with decorators. Examples include
68
+ enum declaration merging and class-field initialization.
69
+
70
+ The extension reads only `experimentalDecorators` and
71
+ `emitDecoratorMetadata` from `tsconfig.json`. Veryfront bundle settings still
72
+ control the target and JSX transform. Other TypeScript emit settings, such as
73
+ `useDefineForClassFields`, are not forwarded to SWC.
74
+
75
+ The legacy SWC path does not compose source maps yet. A bundle or transform
76
+ that enables legacy decorators and requests a source map fails with an
77
+ actionable error instead of returning a map to generated JavaScript. Flags-off
78
+ calls continue to delegate source maps to esbuild.
79
+
80
+ When legacy decorators are enabled, local Deno API routes use per-route bundles
81
+ so their source passes through SWC. Two route bundles do not share module-level
82
+ state from a common imported project file. Put shared clients, pools, caches,
83
+ and registries behind a framework service or extension instead of relying on a
84
+ cross-route module singleton.
85
+
86
+ Treat turning the flag on as a transform swap, not as an addition. Re-run your
87
+ test suite after enabling it. Leaving `experimentalDecorators` false or absent
88
+ does not force local routes through bundling and keeps existing bundler calls on
89
+ the esbuild delegate.
90
+
91
+ ## Runtime and packaging
92
+
93
+ The extension uses `@swc/wasm`, so one package works across Deno, Node.js, Bun,
94
+ and supported compiled binaries. It delegates module resolution, plugins,
95
+ incremental contexts, and final output generation to
96
+ `@veryfront/ext-bundler-esbuild`.
97
+
98
+ The WASM and reflection runtime stay in this explicit extension package. They
99
+ do not become dependencies of core or the default `veryfront` package. The SWC
100
+ WASM asset is about 20 MB, so distributions and compiled binaries that embed
101
+ the explicit extension must account for that size.
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
3
+ * but instead of using npm to install additional dependencies,
4
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
5
+ *
6
+ * Note that this code might be imported multiple times
7
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
8
+ * or Node.js might dynamically clear the cache and then force a require).
9
+ * Therefore, it's important to avoid redundant writes to global objects.
10
+ * Additionally, consider that commonjs is used alongside esm,
11
+ * so the two ponyfill functions are stored independently in two separate global objects.
12
+ */
13
+ import { createRequire } from "node:module";
14
+ import { type URL } from "node:url";
15
+ declare global {
16
+ interface ImportMeta {
17
+ /** A string representation of the fully qualified module URL. When the
18
+ * module is loaded locally, the value will be a file URL (e.g.
19
+ * `file:///path/module.ts`).
20
+ *
21
+ * You can also parse the string as a URL to determine more information about
22
+ * how the current module was loaded. For example to determine if a module was
23
+ * local or not:
24
+ *
25
+ * ```ts
26
+ * const url = new URL(import.meta.url);
27
+ * if (url.protocol === "file:") {
28
+ * console.log("this module was loaded locally");
29
+ * }
30
+ * ```
31
+ */
32
+ url: string;
33
+ /**
34
+ * A function that returns resolved specifier as if it would be imported
35
+ * using `import(specifier)`.
36
+ *
37
+ * ```ts
38
+ * console.log(import.meta.resolve("./foo.js"));
39
+ * // file:///dev/foo.js
40
+ * ```
41
+ *
42
+ * @param specifier The module specifier to resolve relative to `parent`.
43
+ * @param parent The absolute parent module URL to resolve from.
44
+ * @returns The absolute (`file:`) URL string for the resolved module.
45
+ */
46
+ resolve(specifier: string, parent?: string | URL | undefined): string;
47
+ /** A flag that indicates if the current module is the main module that was
48
+ * called when starting the program under Deno.
49
+ *
50
+ * ```ts
51
+ * if (import.meta.main) {
52
+ * // this was loaded as the main module, maybe do some bootstrapping
53
+ * }
54
+ * ```
55
+ */
56
+ main: boolean;
57
+ /** The absolute path of the current module.
58
+ *
59
+ * This property is only provided for local modules (ie. using `file://` URLs).
60
+ *
61
+ * Example:
62
+ * ```
63
+ * // Unix
64
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
65
+ *
66
+ * // Windows
67
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
68
+ * ```
69
+ */
70
+ filename: string;
71
+ /** The absolute path of the directory containing the current module.
72
+ *
73
+ * This property is only provided for local modules (ie. using `file://` URLs).
74
+ *
75
+ * * Example:
76
+ * ```
77
+ * // Unix
78
+ * console.log(import.meta.dirname); // /home/alice
79
+ *
80
+ * // Windows
81
+ * console.log(import.meta.dirname); // C:\alice
82
+ * ```
83
+ */
84
+ dirname: string;
85
+ }
86
+ }
87
+ type NodeRequest = ReturnType<typeof createRequire>;
88
+ type NodeModule = NonNullable<NodeRequest["main"]>;
89
+ interface ImportMetaPonyfillCommonjs {
90
+ (require: NodeRequest, module: NodeModule): ImportMeta;
91
+ }
92
+ interface ImportMetaPonyfillEsmodule {
93
+ (importMeta: ImportMeta): ImportMeta;
94
+ }
95
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
96
+ }
97
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
98
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
99
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
100
+ export {};
101
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA+DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
3
+ * but instead of using npm to install additional dependencies,
4
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
5
+ *
6
+ * Note that this code might be imported multiple times
7
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
8
+ * or Node.js might dynamically clear the cache and then force a require).
9
+ * Therefore, it's important to avoid redundant writes to global objects.
10
+ * Additionally, consider that commonjs is used alongside esm,
11
+ * so the two ponyfill functions are stored independently in two separate global objects.
12
+ */
13
+ //@ts-ignore
14
+ import { createRequire } from "node:module";
15
+ //@ts-ignore
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ //@ts-ignore
18
+ import { dirname } from "node:path";
19
+ const defineGlobalPonyfill = (symbolFor, fn) => {
20
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
21
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
22
+ configurable: true,
23
+ get() {
24
+ return fn;
25
+ },
26
+ });
27
+ }
28
+ };
29
+ export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
30
+ (() => {
31
+ const moduleImportMetaWM = new WeakMap();
32
+ return (require, module) => {
33
+ let importMetaCache = moduleImportMetaWM.get(module);
34
+ if (importMetaCache == null) {
35
+ const importMeta = Object.assign(Object.create(null), {
36
+ url: pathToFileURL(module.filename).href,
37
+ main: require.main == module,
38
+ resolve: (specifier, parentURL = importMeta.url) => {
39
+ return pathToFileURL((importMeta.url === parentURL
40
+ ? require
41
+ : createRequire(parentURL))
42
+ .resolve(specifier)).href;
43
+ },
44
+ filename: module.filename,
45
+ dirname: module.path,
46
+ });
47
+ moduleImportMetaWM.set(module, importMeta);
48
+ importMetaCache = importMeta;
49
+ }
50
+ return importMetaCache;
51
+ };
52
+ })());
53
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
54
+ export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
55
+ ((importMeta) => {
56
+ const resolveFunStr = String(importMeta.resolve);
57
+ const shimWs = new WeakSet();
58
+ //@ts-ignore
59
+ const mainUrl = ("file:///" + (process.argv[1] ?? "").replace(/\\/g, "/"))
60
+ .replace(/\/{3,}/, "///");
61
+ const commonShim = (importMeta) => {
62
+ if (typeof importMeta.main !== "boolean") {
63
+ importMeta.main = importMeta.url === mainUrl;
64
+ }
65
+ if (typeof importMeta.filename !== "string") {
66
+ importMeta.filename = fileURLToPath(importMeta.url);
67
+ importMeta.dirname = dirname(importMeta.filename);
68
+ }
69
+ };
70
+ if (
71
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
72
+ resolveFunStr === "undefined" ||
73
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
74
+ resolveFunStr.startsWith("async")
75
+ // enable by --experimental-import-meta-resolve flag
76
+ ) {
77
+ import_meta_ponyfill_esmodule = (importMeta) => {
78
+ if (!shimWs.has(importMeta)) {
79
+ shimWs.add(importMeta);
80
+ const importMetaUrlRequire = {
81
+ url: importMeta.url,
82
+ require: createRequire(importMeta.url),
83
+ };
84
+ // note: the parameter types must be explicitly annotated because
85
+ // `@types/node` also declares `ImportMeta.resolve`, which makes
86
+ // the contextual type an overload set that provides no inference
87
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
88
+ return pathToFileURL((importMetaUrlRequire.url === parentURL
89
+ ? importMetaUrlRequire.require
90
+ : createRequire(parentURL)).resolve(specifier)).href;
91
+ };
92
+ commonShim(importMeta);
93
+ }
94
+ return importMeta;
95
+ };
96
+ }
97
+ else {
98
+ /// native support
99
+ import_meta_ponyfill_esmodule = (importMeta) => {
100
+ if (!shimWs.has(importMeta)) {
101
+ shimWs.add(importMeta);
102
+ commonShim(importMeta);
103
+ }
104
+ return importMeta;
105
+ };
106
+ }
107
+ return import_meta_ponyfill_esmodule(importMeta);
108
+ }));
109
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
110
+ export let import_meta_ponyfill = ((...args) => {
111
+ const _MODULE = (() => {
112
+ if (typeof require === "function" && typeof module === "object") {
113
+ return "commonjs";
114
+ }
115
+ else {
116
+ // eval("typeof import.meta");
117
+ return "esmodule";
118
+ }
119
+ })();
120
+ if (_MODULE === "commonjs") {
121
+ //@ts-ignore
122
+ import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
123
+ }
124
+ else {
125
+ //@ts-ignore
126
+ import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
127
+ }
128
+ //@ts-ignore
129
+ return import_meta_ponyfill(...args);
130
+ });
package/esm/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Opt-in SWC decorator-metadata transform extension.
3
+ *
4
+ * @module extensions/ext-bundler-swc
5
+ */
6
+ import "./_dnt.polyfills.js";
7
+ import type { ExtensionFactory } from "veryfront/extensions";
8
+ import { SwcBundler } from "./swc-bundler.js";
9
+ declare const extSwc: ExtensionFactory;
10
+ export default extSwc;
11
+ export { SwcBundler };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,QAAA,MAAM,MAAM,EAAE,gBAcb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Opt-in SWC decorator-metadata transform extension.
3
+ *
4
+ * @module extensions/ext-bundler-swc
5
+ */
6
+ import "./_dnt.polyfills.js";
7
+ import { SwcBundler } from "./swc-bundler.js";
8
+ const extSwc = () => {
9
+ const bundler = new SwcBundler();
10
+ return {
11
+ name: "ext-bundler-swc",
12
+ version: "0.1.0",
13
+ contracts: { provides: ["Bundler"] },
14
+ capabilities: [{ type: "fs:read" }],
15
+ setup(ctx) {
16
+ ctx.provide("Bundler", bundler);
17
+ },
18
+ teardown() {
19
+ return bundler.stop();
20
+ },
21
+ };
22
+ };
23
+ export default extSwc;
24
+ export { SwcBundler };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,18 @@
1
+ import type { BuildContext, BundleOptions, Bundler, BundleResult, TransformOptions, TransformResult, TypeScriptDecoratorOptions } from "veryfront/extensions/bundler";
2
+ /**
3
+ * SWC-backed legacy TypeScript transform with esbuild graph bundling.
4
+ *
5
+ * SWC runs only when `experimentalDecorators` is enabled. All other source is
6
+ * delegated unchanged, which keeps standard decorators on the default esbuild
7
+ * behavior even when a project has selected this extension.
8
+ */
9
+ export declare class SwcBundler implements Bundler {
10
+ #private;
11
+ constructor();
12
+ shouldBundleTypeScript(options: TypeScriptDecoratorOptions): boolean;
13
+ bundle(options: BundleOptions): Promise<BundleResult>;
14
+ transform(options: TransformOptions): Promise<TransformResult>;
15
+ context(options: BundleOptions): Promise<BuildContext>;
16
+ stop(): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=swc-bundler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swc-bundler.d.ts","sourceRoot":"","sources":["../src/swc-bundler.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,OAAO,EACP,YAAY,EAIZ,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AA+VtC;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,OAAO;;;IAOxC,sBAAsB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO;IAI9D,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAYrD,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;IA4B9D,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IActD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
@@ -0,0 +1,306 @@
1
+ import { transform as transformWithSwc } from "@swc/wasm";
2
+ import { EsbuildBundler } from "@veryfront/ext-bundler-esbuild";
3
+ import { parseExtensionManifest } from "veryfront/extensions";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createRequire } from "node:module";
6
+ import { basename, extname, isAbsolute, join, resolve } from "node:path";
7
+ import process from "node:process";
8
+ import { readTypeScriptDecoratorOptions } from "veryfront/extensions/bundler";
9
+ const REFLECT_METADATA_SPECIFIER = "veryfront:swc-reflect-metadata";
10
+ const textDecoder = new TextDecoder();
11
+ const require = createRequire(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url);
12
+ let reflectMetadataSourcePromise;
13
+ function rawDecoratorOptions(value) {
14
+ if (typeof value === "string") {
15
+ value = parseExtensionManifest(value, "jsonc", "tsconfigRaw");
16
+ }
17
+ if (value === null || typeof value !== "object")
18
+ return undefined;
19
+ const compilerOptionsDescriptor = Reflect.getOwnPropertyDescriptor(value, "compilerOptions");
20
+ const compilerOptions = compilerOptionsDescriptor?.value;
21
+ if (compilerOptions === null || typeof compilerOptions !== "object") {
22
+ return {
23
+ experimentalDecorators: false,
24
+ emitDecoratorMetadata: false,
25
+ };
26
+ }
27
+ const experimentalDecorators = Reflect.getOwnPropertyDescriptor(compilerOptions, "experimentalDecorators")?.value;
28
+ const emitDecoratorMetadata = Reflect.getOwnPropertyDescriptor(compilerOptions, "emitDecoratorMetadata")?.value;
29
+ return {
30
+ experimentalDecorators: experimentalDecorators === true,
31
+ emitDecoratorMetadata: emitDecoratorMetadata === true,
32
+ };
33
+ }
34
+ function workingDirectory(options) {
35
+ const explicit = options.absWorkingDir;
36
+ if (typeof explicit === "string" && explicit.length > 0)
37
+ return explicit;
38
+ if ("stdin" in options) {
39
+ const resolveDir = options.stdin?.resolveDir;
40
+ if (typeof resolveDir === "string" && resolveDir.length > 0)
41
+ return resolveDir;
42
+ }
43
+ return process.cwd();
44
+ }
45
+ async function decoratorOptions(options) {
46
+ if ("typescriptDecoratorOptions" in options) {
47
+ const resolved = rawDecoratorOptions({
48
+ compilerOptions: options.typescriptDecoratorOptions,
49
+ });
50
+ if (resolved)
51
+ return resolved;
52
+ }
53
+ const raw = rawDecoratorOptions(options.tsconfigRaw);
54
+ if (raw)
55
+ return raw;
56
+ const configPath = typeof options.tsconfig === "string"
57
+ ? isAbsolute(options.tsconfig)
58
+ ? options.tsconfig
59
+ : resolve(workingDirectory(options), options.tsconfig)
60
+ : join(workingDirectory(options), "tsconfig.json");
61
+ return await readTypeScriptDecoratorOptions({ configPath });
62
+ }
63
+ function isTypeScriptLoader(loader) {
64
+ return loader === "ts" || loader === "tsx";
65
+ }
66
+ function transformedLoader(loader, options) {
67
+ return loader === "tsx" && options.jsx === "preserve" ? "jsx" : "js";
68
+ }
69
+ function assertLegacyDecoratorSourceMapsDisabled(options) {
70
+ if (!options.sourcemap)
71
+ return;
72
+ throw new TypeError("The SWC legacy decorator transform does not support source maps. " +
73
+ "Disable source maps or use the default esbuild transform.");
74
+ }
75
+ function loaderForPath(path) {
76
+ const extension = extname(path).toLowerCase();
77
+ if (extension === ".ts" || extension === ".mts" || extension === ".cts")
78
+ return "ts";
79
+ if (extension === ".tsx")
80
+ return "tsx";
81
+ return undefined;
82
+ }
83
+ function sourceText(contents) {
84
+ return typeof contents === "string" ? contents : textDecoder.decode(contents);
85
+ }
86
+ function diagnosticFilename(filename) {
87
+ return basename(filename.replaceAll("\\", "/")) || "source.ts";
88
+ }
89
+ function swcTarget(target) {
90
+ const value = Array.isArray(target) ? target[0] : target;
91
+ if (value === "es3" || value === "es5" || value === "es2015" ||
92
+ value === "es2016" || value === "es2017" || value === "es2018" ||
93
+ value === "es2019" || value === "es2020" || value === "es2021" ||
94
+ value === "es2022")
95
+ return value;
96
+ return "es2022";
97
+ }
98
+ function reactTransform(options) {
99
+ const runtime = options.jsx === "preserve"
100
+ ? "preserve"
101
+ : options.jsx === "automatic"
102
+ ? "automatic"
103
+ : "classic";
104
+ return {
105
+ legacyDecorator: true,
106
+ decoratorMetadata: true,
107
+ react: {
108
+ runtime,
109
+ importSource: options.jsxImportSource,
110
+ },
111
+ };
112
+ }
113
+ async function transformTypeScript(code, loader, filename, flags, options) {
114
+ const transform = reactTransform(options);
115
+ transform.decoratorMetadata = flags.emitDecoratorMetadata;
116
+ const moduleType = extname(filename).toLowerCase() === ".cts" ? "commonjs" : "es6";
117
+ const result = await transformWithSwc(code, {
118
+ filename: diagnosticFilename(filename),
119
+ swcrc: false,
120
+ configFile: false,
121
+ sourceMaps: false,
122
+ module: { type: moduleType },
123
+ jsc: {
124
+ parser: {
125
+ syntax: "typescript",
126
+ tsx: loader === "tsx",
127
+ decorators: true,
128
+ dynamicImport: true,
129
+ },
130
+ target: swcTarget(options.target),
131
+ keepClassNames: options.keepNames === true,
132
+ transform,
133
+ },
134
+ });
135
+ return result.code;
136
+ }
137
+ async function reflectMetadataSource() {
138
+ reflectMetadataSourcePromise ??= readFile(require.resolve("reflect-metadata/lite"), "utf8");
139
+ return await reflectMetadataSourcePromise;
140
+ }
141
+ async function withReflectionRuntime(source, flags, options) {
142
+ if (!flags.emitDecoratorMetadata)
143
+ return source;
144
+ if (options.bundle === true) {
145
+ return `import "${REFLECT_METADATA_SPECIFIER}";\n${source}`;
146
+ }
147
+ return `${await reflectMetadataSource()}\n${source}`;
148
+ }
149
+ function wrapPlugin(plugin, flags, options) {
150
+ return {
151
+ name: plugin.name,
152
+ setup(build) {
153
+ const wrappedBuild = {
154
+ onResolve: build.onResolve.bind(build),
155
+ onDispose: build.onDispose.bind(build),
156
+ onLoad(loadOptions, callback) {
157
+ build.onLoad(loadOptions, async (args) => {
158
+ const result = await callback(args);
159
+ if (!result?.contents)
160
+ return result;
161
+ // An explicit non-TypeScript loader is the plugin's decision. Only
162
+ // infer from the path when the plugin left the loader unset.
163
+ const loader = result.loader === undefined
164
+ ? loaderForPath(args.path)
165
+ : isTypeScriptLoader(result.loader)
166
+ ? result.loader
167
+ : undefined;
168
+ if (!loader)
169
+ return result;
170
+ return {
171
+ ...result,
172
+ contents: await withReflectionRuntime(await transformTypeScript(sourceText(result.contents), loader, args.path, flags, options), flags, options),
173
+ loader: transformedLoader(loader, options),
174
+ };
175
+ });
176
+ },
177
+ };
178
+ return plugin.setup(wrappedBuild);
179
+ },
180
+ };
181
+ }
182
+ function createReflectMetadataPlugin() {
183
+ return {
184
+ name: "veryfront-swc-reflect-metadata",
185
+ setup(build) {
186
+ build.onResolve({ filter: /^veryfront:swc-reflect-metadata$/ }, () => ({
187
+ path: REFLECT_METADATA_SPECIFIER,
188
+ namespace: "veryfront-swc-reflect-metadata",
189
+ }));
190
+ build.onLoad({ filter: /.*/, namespace: "veryfront-swc-reflect-metadata" }, async () => ({ contents: await reflectMetadataSource(), loader: "js" }));
191
+ },
192
+ };
193
+ }
194
+ function createSwcFallbackPlugin(flags, options) {
195
+ return {
196
+ name: "veryfront-swc-typescript",
197
+ setup(build) {
198
+ build.onLoad({ filter: /\.(?:[cm]?ts|tsx)$/ }, async (args) => {
199
+ const loader = loaderForPath(args.path);
200
+ if (!loader)
201
+ return undefined;
202
+ options.signal?.throwIfAborted();
203
+ const code = await readFile(args.path, "utf8");
204
+ const contents = await withReflectionRuntime(await transformTypeScript(code, loader, args.path, flags, options), flags, options);
205
+ options.signal?.throwIfAborted();
206
+ return { contents, loader: transformedLoader(loader, options) };
207
+ });
208
+ },
209
+ };
210
+ }
211
+ function delegateBundleOptions(options) {
212
+ if (!("typescriptDecoratorOptions" in options))
213
+ return options;
214
+ const { typescriptDecoratorOptions: _typescriptDecoratorOptions, ...delegateOptions } = options;
215
+ return delegateOptions;
216
+ }
217
+ function delegateTransformOptions(options) {
218
+ if (!("absWorkingDir" in options) &&
219
+ !("tsconfig" in options) &&
220
+ !("typescriptDecoratorOptions" in options))
221
+ return options;
222
+ const { absWorkingDir: _absWorkingDir, tsconfig: _tsconfig, typescriptDecoratorOptions: _typescriptDecoratorOptions, ...delegateOptions } = options;
223
+ return delegateOptions;
224
+ }
225
+ async function prepareLegacyDecoratorBundle(options, flags) {
226
+ const stdin = options.stdin;
227
+ let transformedStdin = stdin;
228
+ if (stdin && isTypeScriptLoader(stdin.loader)) {
229
+ options.signal?.throwIfAborted();
230
+ const contents = await withReflectionRuntime(await transformTypeScript(stdin.contents, stdin.loader, stdin.sourcefile ?? "stdin.ts", flags, options), flags, options);
231
+ options.signal?.throwIfAborted();
232
+ transformedStdin = {
233
+ ...stdin,
234
+ contents,
235
+ loader: transformedLoader(stdin.loader, options),
236
+ };
237
+ }
238
+ const plugins = [
239
+ createReflectMetadataPlugin(),
240
+ ...(options.plugins ?? []).map((plugin) => wrapPlugin(plugin, flags, options)),
241
+ createSwcFallbackPlugin(flags, options),
242
+ ];
243
+ return {
244
+ ...delegateBundleOptions(options),
245
+ stdin: transformedStdin,
246
+ plugins,
247
+ };
248
+ }
249
+ /**
250
+ * SWC-backed legacy TypeScript transform with esbuild graph bundling.
251
+ *
252
+ * SWC runs only when `experimentalDecorators` is enabled. All other source is
253
+ * delegated unchanged, which keeps standard decorators on the default esbuild
254
+ * behavior even when a project has selected this extension.
255
+ */
256
+ export class SwcBundler {
257
+ #delegate;
258
+ constructor() {
259
+ this.#delegate = new EsbuildBundler();
260
+ }
261
+ shouldBundleTypeScript(options) {
262
+ return options.experimentalDecorators;
263
+ }
264
+ async bundle(options) {
265
+ const flags = await decoratorOptions(options);
266
+ if (!flags.experimentalDecorators) {
267
+ return await this.#delegate.bundle(delegateBundleOptions(options));
268
+ }
269
+ assertLegacyDecoratorSourceMapsDisabled(options);
270
+ return await this.#delegate.bundle(await prepareLegacyDecoratorBundle(options, flags));
271
+ }
272
+ async transform(options) {
273
+ if (!isTypeScriptLoader(options.loader)) {
274
+ return await this.#delegate.transform(delegateTransformOptions(options));
275
+ }
276
+ const flags = await decoratorOptions(options);
277
+ if (!flags.experimentalDecorators) {
278
+ return await this.#delegate.transform(delegateTransformOptions(options));
279
+ }
280
+ assertLegacyDecoratorSourceMapsDisabled(options);
281
+ let code = await transformTypeScript(options.code, options.loader, typeof options.sourcefile === "string" ? options.sourcefile : "stdin.ts", flags, options);
282
+ if (flags.emitDecoratorMetadata) {
283
+ code = `${await reflectMetadataSource()}\n${code}`;
284
+ }
285
+ const delegateOptions = delegateTransformOptions(options);
286
+ return await this.#delegate.transform({
287
+ ...delegateOptions,
288
+ code,
289
+ loader: transformedLoader(options.loader, options),
290
+ });
291
+ }
292
+ async context(options) {
293
+ if (!this.#delegate.context) {
294
+ throw new Error("The SWC bundler delegate does not support incremental builds");
295
+ }
296
+ const flags = await decoratorOptions(options);
297
+ if (!flags.experimentalDecorators) {
298
+ return await this.#delegate.context(delegateBundleOptions(options));
299
+ }
300
+ assertLegacyDecoratorSourceMapsDisabled(options);
301
+ return await this.#delegate.context(await prepareLegacyDecoratorBundle(options, flags));
302
+ }
303
+ async stop() {
304
+ await this.#delegate.stop?.();
305
+ }
306
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@veryfront/ext-bundler-swc",
3
+ "version": "0.1.1252-bootstrap.0",
4
+ "description": "Veryfront first-party extension package for ext-bundler-swc",
5
+ "keywords": [
6
+ "veryfront",
7
+ "extension",
8
+ "ext-bundler-swc"
9
+ ],
10
+ "author": "Veryfront",
11
+ "homepage": "https://github.com/veryfront/veryfront-code/tree/main/extensions/ext-bundler-swc",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/veryfront/veryfront-code.git",
15
+ "directory": "extensions/ext-bundler-swc"
16
+ },
17
+ "license": "Apache-2.0",
18
+ "bugs": {
19
+ "url": "https://github.com/veryfront/veryfront-code/issues"
20
+ },
21
+ "module": "./esm/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./esm/index.js",
25
+ "types": "./esm/index.d.ts"
26
+ }
27
+ },
28
+ "scripts": {},
29
+ "engines": {
30
+ "node": ">=22.3.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "veryfront": {
36
+ "extension": true,
37
+ "activation": "explicit",
38
+ "contracts": {
39
+ "provides": [
40
+ "Bundler"
41
+ ]
42
+ },
43
+ "capabilities": [
44
+ {
45
+ "type": "fs:read"
46
+ }
47
+ ]
48
+ },
49
+ "dependencies": {
50
+ "@swc/wasm": "1.16.1",
51
+ "@veryfront/ext-bundler-esbuild": "0.1.1252-rc",
52
+ "reflect-metadata": "0.2.2"
53
+ },
54
+ "peerDependencies": {
55
+ "veryfront": "^0.1.1252-rc"
56
+ },
57
+ "type": "module",
58
+ "types": "./esm/index.d.ts",
59
+ "files": [
60
+ "esm",
61
+ "LICENSE",
62
+ "NOTICE",
63
+ "README.md"
64
+ ]
65
+ }