ts-arc 1.1.16 → 1.1.18

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 +83 -1
  2. package/package.json +1 -1
package/dist/loader.js CHANGED
@@ -123,8 +123,90 @@ const require = createRequire(import.meta.url);`
123
123
  shortCircuit: true
124
124
  };
125
125
  }
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
+ );
205
+ }
126
206
  export {
127
207
  initialize,
128
208
  load,
129
- resolve2 as resolve
209
+ resolve2 as resolve,
210
+ resolveLocalSync,
211
+ resolveSync
130
212
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-arc",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "type": "module",
5
5
  "description": "A simple typescript runtime.",
6
6
  "main": "dist/bin.js",