@gi-tcg/gts-esbuild-plugin 0.1.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.js +31 -0
- package/package.json +26 -0
- package/src/index.ts +35 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { transpile } from "@gi-tcg/gts-transpiler";
|
|
5
|
+
function gts(option = {}) {
|
|
6
|
+
return {
|
|
7
|
+
name: "esbuild-plugin-gaming-ts",
|
|
8
|
+
setup(build) {
|
|
9
|
+
build.onLoad({ filter: /\.gts$/ }, async (args) => {
|
|
10
|
+
try {
|
|
11
|
+
const sourceCode = await fs.readFile(args.path, "utf8");
|
|
12
|
+
const { code, sourceMap } = transpile(sourceCode, args.path, option);
|
|
13
|
+
const mappingUrl = sourceMap.toUrl();
|
|
14
|
+
return {
|
|
15
|
+
contents: `${code}
|
|
16
|
+
//# sourceMappingURL=${mappingUrl}`,
|
|
17
|
+
loader: "js",
|
|
18
|
+
resolveDir: path.dirname(args.path)
|
|
19
|
+
};
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return {
|
|
22
|
+
errors: [{ text: error.message }]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
gts
|
|
31
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gi-tcg/gts-esbuild-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"bun": "./src/index.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "bun build --outdir=dist --target=node --format=esm --conditions='bun' --packages=external src/index.ts",
|
|
18
|
+
"prepublishOnly": "bun run build"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"esbuild": "~0.27.2"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@gi-tcg/gts-transpiler": "0.1.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { transpile, type TranspileOption } from "@gi-tcg/gts-transpiler";
|
|
5
|
+
import type { Plugin } from "esbuild";
|
|
6
|
+
|
|
7
|
+
export function gts(option: TranspileOption = {}): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: "esbuild-plugin-gaming-ts",
|
|
10
|
+
setup(build) {
|
|
11
|
+
// 1. Filter: Tell esbuild to listen for files ending in .my-lang
|
|
12
|
+
build.onLoad({ filter: /\.gts$/ }, async (args) => {
|
|
13
|
+
try {
|
|
14
|
+
// 2. Read: Manually read the file (esbuild doesn't pass content automatically)
|
|
15
|
+
const sourceCode = await fs.readFile(args.path, "utf8");
|
|
16
|
+
|
|
17
|
+
// 3. Transpile: Call your API
|
|
18
|
+
const { code, sourceMap } = transpile(sourceCode, args.path, option);
|
|
19
|
+
const mappingUrl = sourceMap.toUrl();
|
|
20
|
+
|
|
21
|
+
// 4. Return: Specify the contents and the loader type ('js')
|
|
22
|
+
return {
|
|
23
|
+
contents: `${code}\n//# sourceMappingURL=${mappingUrl}`,
|
|
24
|
+
loader: "js", // Tells esbuild to treat the output as JavaScript
|
|
25
|
+
resolveDir: path.dirname(args.path), // Helps resolve imports inside the new JS
|
|
26
|
+
};
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return {
|
|
29
|
+
errors: [{ text: (error as Error).message }],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|