Page MenuHomeSealhub

No OneTemporary

diff --git a/esbuild.cjs b/esbuild.cjs
index d90b07d..b8641e2 100644
--- a/esbuild.cjs
+++ b/esbuild.cjs
@@ -1,23 +1,54 @@
const { build } = require("esbuild");
const glob = require("tiny-glob");
+const { promises: fs } = require("node:fs");
+const { extname, resolve, relative } = require("node:path");
const watch = process.argv.at(-1) === "--watch";
+// plugin that rewrites the import paths so in typescript we can use
+//
+// import smth from src/index.ts
+//
+// instead of providing relative paths
+const handle_absolute_paths = (project_dir) => ({
+ name: "sealgen-rewrite-asset-imports",
+ setup(build) {
+ build.onLoad({ filter: /\.tsx?$/ }, async (args) => {
+ let contents = await fs.readFile(args.path, "utf8");
+ const regex_import = new RegExp(
+ `^import ([^ ]+, )?(\\w+|{[^}]+}) from "([^"]+)";`,
+ "gm"
+ );
+ contents = contents.replaceAll(regex_import, (line) => {
+ const replaced = line.replace(
+ `"src/`,
+ `"` +
+ relative(args.path, resolve(project_dir, "./lib/src")) +
+ "/"
+ );
+ return replaced;
+ });
+ return {
+ contents,
+ loader: extname(args.path) === ".tsx" ? "tsx" : "ts",
+ };
+ });
+ },
+});
+
(async () => {
let entryPoints = Object.fromEntries(
- (await glob("./src/**/*.ts")).map((e) => [
- e.replace(/\.ts$/, ""),
- e,
- ])
+ (await glob("./src/**/*.ts")).map((e) => [e.replace(/\.ts$/, ""), e])
);
build({
entryPoints,
sourcemap: true,
outdir: "./lib",
logLevel: "info",
platform: "node",
watch,
target: "node16",
format: "esm",
+ plugins: [handle_absolute_paths(__dirname)],
});
-})();
\ No newline at end of file
+})();
diff --git a/src/example.test.ts b/src/example.test.ts
index 5112258..72ecaee 100644
--- a/src/example.test.ts
+++ b/src/example.test.ts
@@ -1,11 +1,11 @@
-import { Example } from "./index.js";
+import { Example } from "src/index.js";
import * as assert from "assert";
describe("Example", () => {
describe("example", () => {
it("should equal 'example'", () => {
const example = new Example();
assert.equal(example.example(), "example");
});
});
});
diff --git a/tsconfig.json b/tsconfig.json
index 2c0f439..1aa072e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,22 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"target": "ES6",
"declaration": true,
"esModuleInterop": true,
"lib": ["ES6", "ESNext"],
"outDir": "lib",
"checkJs": true,
"allowJs": true,
"declarationDir": "@types",
"resolveJsonModule": true,
"sourceMap": true,
- "skipLibCheck": true
+ "skipLibCheck": true,
+ "paths": {
+ "src/*": ["./src/*"]
+ }
},
- "include": ["src/**/*", ],
+ "include": ["src/**/*"],
"exclude": ["node_modules/**"]
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 8, 10:53 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1032911
Default Alt Text
(2 KB)

Event Timeline