ts-arc 1.1.21 → 1.1.22

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.
Files changed (2) hide show
  1. package/dist/loader.js +28 -26
  2. package/package.json +1 -1
package/dist/loader.js CHANGED
@@ -22,7 +22,7 @@ function getEffectiveBase() {
22
22
  }
23
23
  return null;
24
24
  }
25
- async function resolveLocal(baseDir, relativePath) {
25
+ function resolveLocalSync(baseDir, relativePath) {
26
26
  const fullPath = path.resolve(baseDir, relativePath);
27
27
  const candidates = [
28
28
  fullPath,
@@ -34,15 +34,15 @@ async function resolveLocal(baseDir, relativePath) {
34
34
  path.join(fullPath, "page.tsx")
35
35
  ];
36
36
  for (const candidate of candidates) {
37
- try {
38
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
39
- return { url: url.pathToFileURL(candidate).href };
40
- }
41
- } catch {
37
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
38
+ return { url: url.pathToFileURL(candidate).href };
42
39
  }
43
40
  }
44
41
  throw Object.assign(new Error(`Cannot find module '${relativePath}'`), { code: "ERR_MODULE_NOT_FOUND" });
45
42
  }
43
+ async function resolveLocal(baseDir, relativePath) {
44
+ return resolveLocalSync(baseDir, relativePath);
45
+ }
46
46
  async function resolve2(specifier, context, nextResolve) {
47
47
  let parentPath = process.cwd();
48
48
  if (context.parentURL) {
@@ -125,26 +125,28 @@ const require = createRequire(import.meta.url);`
125
125
  shortCircuit: true
126
126
  };
127
127
  }
128
- function resolveLocalSync(baseDir, relativePath) {
129
- const fullPath = path.resolve(baseDir, relativePath);
130
- const candidates = [
131
- fullPath,
132
- fullPath + ".ts",
133
- fullPath + ".tsx",
134
- path.join(fullPath, "index.ts"),
135
- path.join(fullPath, "index.tsx"),
136
- path.join(fullPath, "page.ts"),
137
- path.join(fullPath, "page.tsx")
138
- ];
139
- for (const candidate of candidates) {
140
- if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
141
- return { url: url.pathToFileURL(candidate).href };
142
- }
128
+ function loadSync(urlStr, context, nextLoadSync) {
129
+ if (!urlStr.endsWith(".ts") && !urlStr.endsWith(".tsx")) {
130
+ return nextLoadSync(urlStr, context);
143
131
  }
144
- throw Object.assign(
145
- new Error(`Cannot find module '${relativePath}'`),
146
- { code: "ERR_MODULE_NOT_FOUND" }
147
- );
132
+ const esbuildLoader = urlStr.endsWith(".tsx") ? "tsx" : "ts";
133
+ const filePath = url.fileURLToPath(urlStr);
134
+ const rawSource = fs.readFileSync(filePath, "utf8");
135
+ const { code } = transformSync(rawSource, {
136
+ loader: esbuildLoader,
137
+ format: "esm",
138
+ target: `node${process.versions.node}`,
139
+ sourcemap: "inline",
140
+ sourcefile: filePath,
141
+ banner: `
142
+ import { createRequire } from 'module';
143
+ const require = createRequire(import.meta.url);`
144
+ });
145
+ return {
146
+ format: "module",
147
+ source: code,
148
+ shortCircuit: true
149
+ };
148
150
  }
149
151
  function resolveSync(specifier, context) {
150
152
  let parentPath = process.cwd();
@@ -208,7 +210,7 @@ function resolveSync(specifier, context) {
208
210
  export {
209
211
  initialize,
210
212
  load,
213
+ loadSync,
211
214
  resolve2 as resolve,
212
- resolveLocalSync,
213
215
  resolveSync
214
216
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",