@sweetener/webpack-loader 0.1.0-alpha.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jimmy Miller
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,22 @@
1
+ # @sweetener/webpack-loader
2
+
3
+ A webpack, Rspack, and Turbopack loader for Sweetener sources.
4
+
5
+ Part of [Sweetener](https://github.com/sweetener-ts/sweetener), hygienic
6
+ declarative macros for TypeScript. Alpha: the language version is 1 and the
7
+ package interfaces may still change.
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ module.exports = {
13
+ module: {
14
+ rules: [
15
+ { test: /\.sts$/, use: [{ loader: "@sweetener/webpack-loader" }] },
16
+ ],
17
+ },
18
+ };
19
+ ```
20
+
21
+ It emits JavaScript. Pass `options.emit: "typescript"` when a loader
22
+ after this one should strip the types instead.
@@ -0,0 +1,18 @@
1
+ import type { LoaderContext } from "webpack";
2
+ export interface SweetenerLoaderOptions {
3
+ readonly configFile?: string | undefined;
4
+ /**
5
+ * What to hand the next step in the chain. Defaults to `"javascript"`.
6
+ *
7
+ * Expansion produces TypeScript, and webpack's own parser cannot read it:
8
+ * the documented single-loader rule failed on the first annotated
9
+ * declaration with `Module parse failed: Unexpected token`, which names
10
+ * neither Sweetener nor types. Stripping here is what makes that rule work
11
+ * on its own. Choose `"typescript"` when a loader after this one should do
12
+ * the stripping — to control its target, or because the host, like
13
+ * Turbopack's `as: "*.ts"`, is expecting TypeScript.
14
+ */
15
+ readonly emit?: "javascript" | "typescript" | undefined;
16
+ }
17
+ export default function sweetenerLoader(this: LoaderContext<SweetenerLoaderOptions>, source: string): void;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS,CAAC;CACzD;AAgBD,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,IAAI,EAAE,aAAa,CAAC,sBAAsB,CAAC,EAC3C,MAAM,EAAE,MAAM,GACb,IAAI,CA0CN"}
@@ -0,0 +1,50 @@
1
+ import { createSweetenerSession, describeDiagnostics, stripTypes, } from "@sweetener/compiler";
2
+ const sessions = new WeakMap();
3
+ function sessionFor(context) {
4
+ const owner = context._compiler ?? context;
5
+ const existing = sessions.get(owner);
6
+ if (existing !== undefined)
7
+ return existing;
8
+ const session = createSweetenerSession();
9
+ sessions.set(owner, session);
10
+ return session;
11
+ }
12
+ export default function sweetenerLoader(source) {
13
+ const callback = this.async();
14
+ const options = this.getOptions?.() ?? {};
15
+ void sessionFor(this)
16
+ .transform({
17
+ code: source,
18
+ filename: this.resourcePath,
19
+ configFile: options.configFile,
20
+ mode: this.mode === "production" ? "production" : "development",
21
+ })
22
+ // `.then(onFulfilled, onRejected)` only catches a rejection of the promise
23
+ // before it, so a throw from inside the success branch escaped as an
24
+ // unhandled rejection with the callback never called — which takes the
25
+ // whole dev server down rather than reporting a macro error.
26
+ .then((result) => {
27
+ for (const dependency of result.dependencies)
28
+ this.addDependency(dependency);
29
+ if (result.diagnostics.length > 0) {
30
+ callback(new Error(describeDiagnostics(result.diagnostics)));
31
+ return;
32
+ }
33
+ const emitted = options.emit === "typescript"
34
+ ? { code: result.code, map: undefined }
35
+ : stripTypes(result, {
36
+ filename: this.resourcePath,
37
+ configFile: options.configFile,
38
+ });
39
+ const map = emitted.map ?? result.map;
40
+ callback(null, emitted.code, {
41
+ ...map,
42
+ file: map.file ?? result.virtualFilename,
43
+ sources: [...map.sources],
44
+ sourcesContent: (map.sourcesContent ?? []).map((content) => content ?? ""),
45
+ names: [...map.names],
46
+ });
47
+ })
48
+ .catch((error) => callback(error instanceof Error ? error : new Error(String(error))));
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,UAAU,GACX,MAAM,qBAAqB,CAAC;AAmB7B,MAAM,QAAQ,GAAG,IAAI,OAAO,EAGzB,CAAC;AAEJ,SAAS,UAAU,CAAC,OAA8C;IAChE,MAAM,KAAK,GAAI,OAAO,CAAC,SAAgC,IAAI,OAAO,CAAC;IACnE,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO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U;aAC/B,CAAC,CAAC;QACT,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC;QACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;YAC3B,GAAG,GAAG;YACN,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,eAAe;YACxC,OAAO,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC;YACzB,cAAc,EAAE,CAAC,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,GAAG,CAC5C,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,CAC3B;YACD,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;SACtB,CAAC,CAAC;IACL,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CACxB,QAAQ,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CACpE,CAAC;AACN,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@sweetener/webpack-loader",
3
+ "version": "0.1.0-alpha.0",
4
+ "description": "Sweetener alpha package: webpack-loader",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/src/index.d.ts",
9
+ "import": "./dist/src/index.js",
10
+ "default": "./dist/src/index.js"
11
+ }
12
+ },
13
+ "peerDependencies": {
14
+ "webpack": ">=5"
15
+ },
16
+ "peerDependenciesMeta": {
17
+ "webpack": {
18
+ "optional": true
19
+ }
20
+ },
21
+ "license": "MIT",
22
+ "author": "Jimmy Miller <jimmyhmiller@gmail.com>",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/sweetener-ts/sweetener.git",
26
+ "directory": "packages/webpack-loader"
27
+ },
28
+ "homepage": "https://github.com/sweetener-ts/sweetener/tree/main/packages/webpack-loader#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/sweetener-ts/sweetener/issues"
31
+ },
32
+ "keywords": [
33
+ "sweetener",
34
+ "macros",
35
+ "typescript",
36
+ "hygienic",
37
+ "syntax",
38
+ "webpack",
39
+ "loader",
40
+ "nextjs",
41
+ "turbopack"
42
+ ],
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "dependencies": {
47
+ "@sweetener/compiler": "0.1.0-alpha.0"
48
+ },
49
+ "engines": {
50
+ "node": ">=24"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }