@jalvin/webpack-plugin 1.0.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/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +12 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +30 -0
- package/dist/loader.js.map +1 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Compiler, WebpackPluginInstance } from "webpack";
|
|
2
|
+
export interface JalvinWebpackOptions {
|
|
3
|
+
/** Emit TypeScript type annotations. Default: false */
|
|
4
|
+
emitTypes?: boolean;
|
|
5
|
+
/** Runtime package. Default: "@jalvin/runtime" */
|
|
6
|
+
runtimeImport?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class JalvinPlugin implements WebpackPluginInstance {
|
|
9
|
+
private readonly opts;
|
|
10
|
+
constructor(opts?: JalvinWebpackOptions);
|
|
11
|
+
apply(compiler: Compiler): void;
|
|
12
|
+
}
|
|
13
|
+
export default JalvinPlugin;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACnC,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,qBAAa,YAAa,YAAW,qBAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,GAAE,oBAAyB;IAE5D,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAkChC;AAED,eAAe,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// @jalvin/webpack-plugin — Webpack 5 loader + plugin for Jalvin
|
|
4
|
+
//
|
|
5
|
+
// webpack.config.js usage:
|
|
6
|
+
//
|
|
7
|
+
// const JalvinPlugin = require("@jalvin/webpack-plugin");
|
|
8
|
+
//
|
|
9
|
+
// module.exports = {
|
|
10
|
+
// module: {
|
|
11
|
+
// rules: [
|
|
12
|
+
// {
|
|
13
|
+
// test: /\.jalvin$/,
|
|
14
|
+
// use: [
|
|
15
|
+
// // Run ts-loader AFTER jalvin (loaders are applied right-to-left)
|
|
16
|
+
// { loader: "ts-loader", options: { transpileOnly: true } },
|
|
17
|
+
// { loader: "@jalvin/webpack-plugin/loader" },
|
|
18
|
+
// ],
|
|
19
|
+
// },
|
|
20
|
+
// ],
|
|
21
|
+
// },
|
|
22
|
+
// plugins: [new JalvinPlugin()],
|
|
23
|
+
// };
|
|
24
|
+
//
|
|
25
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.JalvinPlugin = void 0;
|
|
28
|
+
class JalvinPlugin {
|
|
29
|
+
opts;
|
|
30
|
+
constructor(opts = {}) {
|
|
31
|
+
this.opts = opts;
|
|
32
|
+
}
|
|
33
|
+
apply(compiler) {
|
|
34
|
+
const PLUGIN_NAME = "JalvinPlugin";
|
|
35
|
+
// Inject the loader for .jalvin files automatically
|
|
36
|
+
compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {
|
|
37
|
+
const rules = compiler.options.module?.rules;
|
|
38
|
+
if (!rules)
|
|
39
|
+
return;
|
|
40
|
+
// Only inject if not already configured manually
|
|
41
|
+
const alreadyConfigured = rules.some((r) => r && typeof r === "object" && "test" in r &&
|
|
42
|
+
r.test instanceof RegExp && r.test.test(".jalvin"));
|
|
43
|
+
if (alreadyConfigured)
|
|
44
|
+
return;
|
|
45
|
+
rules.push({
|
|
46
|
+
test: /\.jalvin$/,
|
|
47
|
+
use: [
|
|
48
|
+
{
|
|
49
|
+
loader: require.resolve("./loader"),
|
|
50
|
+
options: this.opts,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
// Resolve .jalvin without explicit extension
|
|
56
|
+
compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {
|
|
57
|
+
const extensions = compiler.options.resolve?.extensions;
|
|
58
|
+
if (extensions && !extensions.includes(".jalvin")) {
|
|
59
|
+
extensions.push(".jalvin");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.JalvinPlugin = JalvinPlugin;
|
|
65
|
+
exports.default = JalvinPlugin;
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,gEAAgE;AAChE,EAAE;AACF,2BAA2B;AAC3B,EAAE;AACF,4DAA4D;AAC5D,EAAE;AACF,uBAAuB;AACvB,gBAAgB;AAChB,iBAAiB;AACjB,YAAY;AACZ,+BAA+B;AAC/B,mBAAmB;AACnB,gFAAgF;AAChF,yEAAyE;AACzE,2DAA2D;AAC3D,eAAe;AACf,aAAa;AACb,WAAW;AACX,SAAS;AACT,qCAAqC;AACrC,OAAO;AACP,EAAE;AACF,gFAAgF;;;AAWhF,MAAa,YAAY;IACM;IAA7B,YAA6B,OAA6B,EAAE;QAA/B,SAAI,GAAJ,IAAI,CAA2B;IAAG,CAAC;IAEhE,KAAK,CAAC,QAAkB;QACtB,MAAM,WAAW,GAAG,cAAc,CAAC;QAEnC,oDAAoD;QACpD,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE;YACpD,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC;YAC7C,IAAI,CAAC,KAAK;gBAAE,OAAO;YAEnB,iDAAiD;YACjD,MAAM,iBAAiB,GAAG,KAAK,CAAC,IAAI,CAClC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,IAAI,CAAC;gBAC9C,CAAC,CAAC,IAAI,YAAY,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CACrD,CAAC;YACF,IAAI,iBAAiB;gBAAE,OAAO;YAE9B,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,WAAW;gBACjB,GAAG,EAAE;oBACH;wBACE,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;wBACnC,OAAO,EAAE,IAAI,CAAC,IAAI;qBACnB;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,6CAA6C;QAC7C,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE;YACpD,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;YACxD,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArCD,oCAqCC;AAED,kBAAe,YAAY,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JalvinWebpackOptions } from "./index.js";
|
|
2
|
+
interface LoaderContext {
|
|
3
|
+
resourcePath: string;
|
|
4
|
+
getOptions(): JalvinWebpackOptions;
|
|
5
|
+
emitWarning(err: Error): void;
|
|
6
|
+
emitError(err: Error): void;
|
|
7
|
+
async(): (err: Error | null, result?: string) => void;
|
|
8
|
+
addDependency(path: string): void;
|
|
9
|
+
}
|
|
10
|
+
declare function loader(this: LoaderContext, source: string): void;
|
|
11
|
+
export default loader;
|
|
12
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,UAAU,aAAa;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,IAAI,oBAAoB,CAAC;IACnC,WAAW,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAC9B,SAAS,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,iBAAS,MAAM,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA2BzD;AAGD,eAAe,MAAM,CAAC"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// @jalvin/webpack-plugin — raw loader function
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const compiler_1 = require("@jalvin/compiler");
|
|
7
|
+
function loader(source) {
|
|
8
|
+
const callback = this.async();
|
|
9
|
+
const opts = this.getOptions() ?? {};
|
|
10
|
+
const result = (0, compiler_1.compile)(source, this.resourcePath, {
|
|
11
|
+
emitTypes: opts.emitTypes ?? false,
|
|
12
|
+
runtimeImport: opts.runtimeImport ?? "@jalvin/runtime",
|
|
13
|
+
});
|
|
14
|
+
for (const diag of result.diagnostics) {
|
|
15
|
+
if (diag.severity === "error") {
|
|
16
|
+
this.emitError(new Error(`[Jalvin] ${diag.message} [${diag.code}] in ${this.resourcePath}:${diag.span ? diag.span.startLine + 1 : "?"}`));
|
|
17
|
+
}
|
|
18
|
+
else if (diag.severity === "warning") {
|
|
19
|
+
this.emitWarning(new Error(`[Jalvin] ${diag.message} [${diag.code}] in ${this.resourcePath}:${diag.span ? diag.span.startLine + 1 : "?"}`));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!result.ok) {
|
|
23
|
+
callback(new Error(`[Jalvin] Compilation failed for ${this.resourcePath}`));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
callback(null, result.code);
|
|
27
|
+
}
|
|
28
|
+
module.exports = loader;
|
|
29
|
+
exports.default = loader;
|
|
30
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,gFAAgF;;AAEhF,+CAA2C;AAY3C,SAAS,MAAM,CAAsB,MAAc;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;IAErC,MAAM,MAAM,GAAG,IAAA,kBAAO,EAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE;QAChD,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,KAAK;QAClC,aAAa,EAAE,IAAI,CAAC,aAAa,IAAI,iBAAiB;KACvD,CAAC,CAAC;IAEH,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,SAAS,CACZ,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAC1H,CAAC;QACJ,CAAC;aAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACvC,IAAI,CAAC,WAAW,CACd,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAC1H,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,QAAQ,CAAC,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAC5E,OAAO;IACT,CAAC;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;AACxB,kBAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jalvin/webpack-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Webpack loader for the Jalvin language — import .jalvin files directly",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"webpack": ">=5.0.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@jalvin/compiler": "1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"typescript": "^5.4.0",
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"webpack": "^5.0.0",
|
|
29
|
+
"@types/webpack": "^5.0.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
34
|
+
}
|
|
35
|
+
}
|