ts-arc 1.1.17 → 1.1.19

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/bin.js CHANGED
@@ -34,7 +34,7 @@ function stripJsonComments(input) {
34
34
  }
35
35
  if (char === "/" && input[i + 1] === "*") {
36
36
  i += 2;
37
- while (i < input.length && !(input[i - 1] === "*" && input[i] === "/")) i++;
37
+ while (!(input[i - 1] === "*" && input[i])) i++;
38
38
  if (i < input.length) i++;
39
39
  continue;
40
40
  }
@@ -47,17 +47,13 @@ function loadConfig(filePath) {
47
47
  const content = fs.readFileSync(filePath, "utf8");
48
48
  const stripped = stripJsonComments(content);
49
49
  const config = JSON.parse(stripped);
50
- if (!config.extends) {
51
- return config;
52
- }
50
+ if (!config.extends) return config;
53
51
  const extendsVal = config.extends;
54
52
  const tsconfigDir = path.dirname(filePath);
55
53
  let extendsPath;
56
54
  if (extendsVal.startsWith("./") || extendsVal.startsWith("../")) {
57
55
  extendsPath = path.resolve(tsconfigDir, extendsVal);
58
- if (!extendsPath.endsWith(".json")) {
59
- extendsPath += ".json";
60
- }
56
+ if (!extendsPath.endsWith(".json")) extendsPath += ".json";
61
57
  } else {
62
58
  try {
63
59
  extendsPath = require2.resolve(extendsVal);
@@ -73,24 +69,36 @@ function loadConfig(filePath) {
73
69
  function findTsConfig(dir) {
74
70
  let current = dir;
75
71
  while (current !== path.parse(current).root) {
76
- const tsconfigPath = path.join(current, "tsconfig.json");
77
- if (fs.existsSync(tsconfigPath)) {
78
- return tsconfigPath;
79
- }
72
+ const tsconfigPath2 = path.join(current, "tsconfig.json");
73
+ if (fs.existsSync(tsconfigPath2)) return tsconfigPath2;
80
74
  current = path.dirname(current);
81
75
  }
82
76
  return null;
83
77
  }
84
- var tsArcConfig = { baseUrl: null, paths: {}, tsconfigDir: null };
85
- async function registerLoader() {
86
- register("./loader.js", import.meta.url, { data: tsArcConfig });
78
+ var tsArcConfig = {
79
+ baseUrl: null,
80
+ paths: {},
81
+ tsconfigDir: null
82
+ };
83
+ var tsconfigPath = findTsConfig(process.cwd());
84
+ if (tsconfigPath) {
85
+ const mergedConfig = loadConfig(tsconfigPath);
86
+ const compilerOptions = mergedConfig.compilerOptions || {};
87
+ const tsconfigDir = path.dirname(tsconfigPath);
88
+ const baseUrlStr = compilerOptions.baseUrl;
89
+ tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
90
+ tsArcConfig.paths = compilerOptions.paths || {};
91
+ tsArcConfig.tsconfigDir = tsconfigDir;
92
+ }
93
+ function registerLoader() {
94
+ register(loaderPath, import.meta.url, { data: tsArcConfig });
87
95
  }
88
96
  async function setArcTsConfig(directory) {
89
- const tsconfigPath = findTsConfig(directory);
90
- if (tsconfigPath) {
91
- const mergedConfig = loadConfig(tsconfigPath);
97
+ const tsconfigPath2 = findTsConfig(directory);
98
+ if (tsconfigPath2) {
99
+ const mergedConfig = loadConfig(tsconfigPath2);
92
100
  const compilerOptions = mergedConfig.compilerOptions || {};
93
- const tsconfigDir = path.dirname(tsconfigPath);
101
+ const tsconfigDir = path.dirname(tsconfigPath2);
94
102
  const baseUrlStr = compilerOptions.baseUrl;
95
103
  tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
96
104
  tsArcConfig.paths = compilerOptions.paths || {};
@@ -100,7 +108,7 @@ async function setArcTsConfig(directory) {
100
108
  async function loadModule(scriptUrl) {
101
109
  const scriptPath = url.fileURLToPath(scriptUrl);
102
110
  setArcTsConfig(path.dirname(scriptPath));
103
- await registerLoader();
111
+ registerLoader();
104
112
  import(scriptUrl).catch((err) => {
105
113
  console.error(err);
106
114
  process.exit(1);
package/dist/cli.js CHANGED
@@ -40,7 +40,7 @@ function stripJsonComments(input) {
40
40
  }
41
41
  if (char === "/" && input[i + 1] === "*") {
42
42
  i += 2;
43
- while (i < input.length && !(input[i - 1] === "*" && input[i] === "/")) i++;
43
+ while (!(input[i - 1] === "*" && input[i])) i++;
44
44
  if (i < input.length) i++;
45
45
  continue;
46
46
  }
@@ -53,17 +53,13 @@ function loadConfig(filePath) {
53
53
  const content = fs.readFileSync(filePath, "utf8");
54
54
  const stripped = stripJsonComments(content);
55
55
  const config = JSON.parse(stripped);
56
- if (!config.extends) {
57
- return config;
58
- }
56
+ if (!config.extends) return config;
59
57
  const extendsVal = config.extends;
60
58
  const tsconfigDir = path.dirname(filePath);
61
59
  let extendsPath;
62
60
  if (extendsVal.startsWith("./") || extendsVal.startsWith("../")) {
63
61
  extendsPath = path.resolve(tsconfigDir, extendsVal);
64
- if (!extendsPath.endsWith(".json")) {
65
- extendsPath += ".json";
66
- }
62
+ if (!extendsPath.endsWith(".json")) extendsPath += ".json";
67
63
  } else {
68
64
  try {
69
65
  extendsPath = require2.resolve(extendsVal);
@@ -79,24 +75,36 @@ function loadConfig(filePath) {
79
75
  function findTsConfig(dir) {
80
76
  let current = dir;
81
77
  while (current !== path.parse(current).root) {
82
- const tsconfigPath = path.join(current, "tsconfig.json");
83
- if (fs.existsSync(tsconfigPath)) {
84
- return tsconfigPath;
85
- }
78
+ const tsconfigPath2 = path.join(current, "tsconfig.json");
79
+ if (fs.existsSync(tsconfigPath2)) return tsconfigPath2;
86
80
  current = path.dirname(current);
87
81
  }
88
82
  return null;
89
83
  }
90
- var tsArcConfig = { baseUrl: null, paths: {}, tsconfigDir: null };
91
- async function registerLoader() {
92
- register("./loader.js", import.meta.url, { data: tsArcConfig });
84
+ var tsArcConfig = {
85
+ baseUrl: null,
86
+ paths: {},
87
+ tsconfigDir: null
88
+ };
89
+ var tsconfigPath = findTsConfig(process.cwd());
90
+ if (tsconfigPath) {
91
+ const mergedConfig = loadConfig(tsconfigPath);
92
+ const compilerOptions = mergedConfig.compilerOptions || {};
93
+ const tsconfigDir = path.dirname(tsconfigPath);
94
+ const baseUrlStr = compilerOptions.baseUrl;
95
+ tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
96
+ tsArcConfig.paths = compilerOptions.paths || {};
97
+ tsArcConfig.tsconfigDir = tsconfigDir;
98
+ }
99
+ function registerLoader() {
100
+ register(loaderPath, import.meta.url, { data: tsArcConfig });
93
101
  }
94
102
  async function setArcTsConfig(directory) {
95
- const tsconfigPath = findTsConfig(directory);
96
- if (tsconfigPath) {
97
- const mergedConfig = loadConfig(tsconfigPath);
103
+ const tsconfigPath2 = findTsConfig(directory);
104
+ if (tsconfigPath2) {
105
+ const mergedConfig = loadConfig(tsconfigPath2);
98
106
  const compilerOptions = mergedConfig.compilerOptions || {};
99
- const tsconfigDir = path.dirname(tsconfigPath);
107
+ const tsconfigDir = path.dirname(tsconfigPath2);
100
108
  const baseUrlStr = compilerOptions.baseUrl;
101
109
  tsArcConfig.baseUrl = baseUrlStr ? path.resolve(tsconfigDir, baseUrlStr) : null;
102
110
  tsArcConfig.paths = compilerOptions.paths || {};
@@ -106,7 +114,7 @@ async function setArcTsConfig(directory) {
106
114
  async function loadModule(scriptUrl2) {
107
115
  const scriptPath2 = url.fileURLToPath(scriptUrl2);
108
116
  setArcTsConfig(path.dirname(scriptPath2));
109
- await registerLoader();
117
+ registerLoader();
110
118
  import(scriptUrl2).catch((err) => {
111
119
  console.error(err);
112
120
  process.exit(1);
package/dist/loader.js CHANGED
@@ -123,12 +123,90 @@ const require = createRequire(import.meta.url);`
123
123
  shortCircuit: true
124
124
  };
125
125
  }
126
- function resolveSync(specifier, context, nextResolve) {
127
- return nextResolve(specifier, context);
126
+ function resolveLocalSync(baseDir, relativePath) {
127
+ const fullPath = path.resolve(baseDir, relativePath);
128
+ const candidates = [
129
+ fullPath,
130
+ fullPath + ".ts",
131
+ fullPath + ".tsx",
132
+ path.join(fullPath, "index.ts"),
133
+ path.join(fullPath, "index.tsx"),
134
+ path.join(fullPath, "page.ts"),
135
+ path.join(fullPath, "page.tsx")
136
+ ];
137
+ for (const candidate of candidates) {
138
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
139
+ return { url: url.pathToFileURL(candidate).href };
140
+ }
141
+ }
142
+ throw Object.assign(
143
+ new Error(`Cannot find module '${relativePath}'`),
144
+ { code: "ERR_MODULE_NOT_FOUND" }
145
+ );
146
+ }
147
+ function resolveSync(specifier, context) {
148
+ let parentPath = process.cwd();
149
+ if (context.parentURL) {
150
+ parentPath = path.dirname(url.fileURLToPath(context.parentURL));
151
+ }
152
+ if (specifier.startsWith("file://")) {
153
+ const filePath = url.fileURLToPath(specifier);
154
+ const dir = path.dirname(filePath);
155
+ const baseName = path.basename(filePath);
156
+ const resolved = resolveLocalSync(dir, baseName);
157
+ return { ...resolved, shortCircuit: true };
158
+ }
159
+ const isPathLike = specifier.startsWith(".") || specifier.startsWith("/");
160
+ if (isPathLike) {
161
+ const resolved = resolveLocalSync(parentPath, specifier);
162
+ return { ...resolved, shortCircuit: true };
163
+ }
164
+ const { paths } = config;
165
+ const effectiveBase = getEffectiveBase();
166
+ for (const key of Object.keys(paths)) {
167
+ let capture = null;
168
+ const isWildcard = key.endsWith("/*");
169
+ const prefix = isWildcard ? key.slice(0, -2) : key;
170
+ if (isWildcard && specifier.startsWith(prefix + "/")) {
171
+ capture = specifier.slice(prefix.length + 1);
172
+ } else if (!isWildcard && specifier === key) {
173
+ capture = "";
174
+ }
175
+ if (capture !== null) {
176
+ for (const target of paths[key]) {
177
+ const mapped = isWildcard ? target.replace(/\*/g, capture) : target;
178
+ if (effectiveBase) {
179
+ try {
180
+ const resolved = resolveLocalSync(effectiveBase, mapped);
181
+ return { ...resolved, shortCircuit: true };
182
+ } catch (e) {
183
+ if (e.code !== "ERR_MODULE_NOT_FOUND") {
184
+ throw e;
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+ if (effectiveBase) {
192
+ try {
193
+ const resolved = resolveLocalSync(effectiveBase, specifier);
194
+ return { ...resolved, shortCircuit: true };
195
+ } catch (e) {
196
+ if (e.code !== "ERR_MODULE_NOT_FOUND") {
197
+ throw e;
198
+ }
199
+ }
200
+ }
201
+ throw Object.assign(
202
+ new Error(`Cannot find module '${specifier}'`),
203
+ { code: "ERR_MODULE_NOT_FOUND" }
204
+ );
128
205
  }
129
206
  export {
130
207
  initialize,
131
208
  load,
132
209
  resolve2 as resolve,
210
+ resolveLocalSync,
133
211
  resolveSync
134
212
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",