@awsless/ts-file-cache 0.0.7 → 0.0.9

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.cjs CHANGED
@@ -155,16 +155,14 @@ var generateRecursiveFileHashes = async (workspace, file, source, allowedExtensi
155
155
  if (import_node_module.builtinModules.includes(file.replace(/^node\:/, ""))) {
156
156
  return;
157
157
  }
158
- throw new Error(`Can't find the dependency version for: ${file}`);
158
+ throw new Error(`Can't find the dependency version for: ${file} inside the source: ${source}`);
159
159
  };
160
160
  var mergeHashes = (hashes) => {
161
161
  const merge = Buffer.concat(Array.from(hashes.values()).sort());
162
162
  return (0, import_crypto.createHash)("sha1").update(merge).digest("hex");
163
163
  };
164
164
  var findDependency = (workspace, module2, source) => {
165
- const pkg = Object.values(workspace.packages).find((pkg2) => {
166
- return source.startsWith(pkg2.path);
167
- });
165
+ const pkg = Object.values(workspace.packages).filter((p) => source.startsWith(p.path)).sort((a, b) => b.path.split("/").length - a.path.split("/").length).find((p) => p.dependencies[module2]);
168
166
  if (!pkg) {
169
167
  return;
170
168
  }
@@ -178,8 +176,8 @@ var import_path5 = require("path");
178
176
  var import_promises3 = require("fs/promises");
179
177
  var import_path4 = require("path");
180
178
  var import_yaml = require("yaml");
181
- var pnpm = async (cwd) => {
182
- const lockFile = await findLockFile(cwd);
179
+ var pnpm = async (search) => {
180
+ const [cwd, lockFile] = await findLockFile(search);
183
181
  const data = (0, import_yaml.parse)(lockFile);
184
182
  const packages = {};
185
183
  await Promise.all(
@@ -210,7 +208,10 @@ var pnpm = async (cwd) => {
210
208
  };
211
209
  })
212
210
  );
213
- return packages;
211
+ return {
212
+ cwd,
213
+ packages
214
+ };
214
215
  };
215
216
  var findLockFile = async (path, level = 5) => {
216
217
  if (!level) {
@@ -219,7 +220,7 @@ var findLockFile = async (path, level = 5) => {
219
220
  const file = (0, import_path4.join)(path, "pnpm-lock.yaml");
220
221
  const exists = await fileExist(file);
221
222
  if (exists) {
222
- return (0, import_promises3.readFile)(file, "utf8");
223
+ return [path, await (0, import_promises3.readFile)(file, "utf8")];
223
224
  }
224
225
  return findLockFile((0, import_path4.normalize)((0, import_path4.join)(path, "..")), level - 1);
225
226
  };
@@ -235,17 +236,12 @@ var fileExist = async (file) => {
235
236
  };
236
237
 
237
238
  // src/index.ts
238
- var loadWorkspace = async (cwd) => {
239
- const packages = await pnpm(toAbsolute(cwd));
240
- const workspace = { cwd, packages: {} };
241
- const sizes = {};
242
- Object.values(packages).forEach((pkg) => {
243
- sizes[pkg.name] = pkg.path.split("/").length;
244
- });
245
- Object.entries(packages).sort(([a], [b]) => sizes[b] - sizes[a]).forEach(([name, pkg]) => {
246
- workspace.packages[name] = pkg;
247
- });
248
- return workspace;
239
+ var loadWorkspace = async (search) => {
240
+ const { cwd, packages } = await pnpm(toAbsolute(search));
241
+ return {
242
+ cwd,
243
+ packages
244
+ };
249
245
  };
250
246
  var defaultOptions = {
251
247
  extensions: ["js", "mjs", "jsx", "ts", "mts", "tsx"]
package/dist/index.d.cts CHANGED
@@ -18,7 +18,7 @@ type Workspace = {
18
18
  packages: Record<string, Package>;
19
19
  };
20
20
 
21
- declare const loadWorkspace: (cwd: string) => Promise<Workspace>;
21
+ declare const loadWorkspace: (search: string) => Promise<Workspace>;
22
22
  type Options = {
23
23
  extensions?: string[];
24
24
  };
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ type Workspace = {
18
18
  packages: Record<string, Package>;
19
19
  };
20
20
 
21
- declare const loadWorkspace: (cwd: string) => Promise<Workspace>;
21
+ declare const loadWorkspace: (search: string) => Promise<Workspace>;
22
22
  type Options = {
23
23
  extensions?: string[];
24
24
  };
package/dist/index.js CHANGED
@@ -129,16 +129,14 @@ var generateRecursiveFileHashes = async (workspace, file, source, allowedExtensi
129
129
  if (builtinModules.includes(file.replace(/^node\:/, ""))) {
130
130
  return;
131
131
  }
132
- throw new Error(`Can't find the dependency version for: ${file}`);
132
+ throw new Error(`Can't find the dependency version for: ${file} inside the source: ${source}`);
133
133
  };
134
134
  var mergeHashes = (hashes) => {
135
135
  const merge = Buffer.concat(Array.from(hashes.values()).sort());
136
136
  return createHash("sha1").update(merge).digest("hex");
137
137
  };
138
138
  var findDependency = (workspace, module, source) => {
139
- const pkg = Object.values(workspace.packages).find((pkg2) => {
140
- return source.startsWith(pkg2.path);
141
- });
139
+ const pkg = Object.values(workspace.packages).filter((p) => source.startsWith(p.path)).sort((a, b) => b.path.split("/").length - a.path.split("/").length).find((p) => p.dependencies[module]);
142
140
  if (!pkg) {
143
141
  return;
144
142
  }
@@ -152,8 +150,8 @@ import { extname, resolve as resolve2 } from "path";
152
150
  import { lstat, readFile as readFile2 } from "fs/promises";
153
151
  import { join as join2, normalize } from "path";
154
152
  import { parse as parse2 } from "yaml";
155
- var pnpm = async (cwd) => {
156
- const lockFile = await findLockFile(cwd);
153
+ var pnpm = async (search) => {
154
+ const [cwd, lockFile] = await findLockFile(search);
157
155
  const data = parse2(lockFile);
158
156
  const packages = {};
159
157
  await Promise.all(
@@ -184,7 +182,10 @@ var pnpm = async (cwd) => {
184
182
  };
185
183
  })
186
184
  );
187
- return packages;
185
+ return {
186
+ cwd,
187
+ packages
188
+ };
188
189
  };
189
190
  var findLockFile = async (path, level = 5) => {
190
191
  if (!level) {
@@ -193,7 +194,7 @@ var findLockFile = async (path, level = 5) => {
193
194
  const file = join2(path, "pnpm-lock.yaml");
194
195
  const exists = await fileExist(file);
195
196
  if (exists) {
196
- return readFile2(file, "utf8");
197
+ return [path, await readFile2(file, "utf8")];
197
198
  }
198
199
  return findLockFile(normalize(join2(path, "..")), level - 1);
199
200
  };
@@ -209,17 +210,12 @@ var fileExist = async (file) => {
209
210
  };
210
211
 
211
212
  // src/index.ts
212
- var loadWorkspace = async (cwd) => {
213
- const packages = await pnpm(toAbsolute(cwd));
214
- const workspace = { cwd, packages: {} };
215
- const sizes = {};
216
- Object.values(packages).forEach((pkg) => {
217
- sizes[pkg.name] = pkg.path.split("/").length;
218
- });
219
- Object.entries(packages).sort(([a], [b]) => sizes[b] - sizes[a]).forEach(([name, pkg]) => {
220
- workspace.packages[name] = pkg;
221
- });
222
- return workspace;
213
+ var loadWorkspace = async (search) => {
214
+ const { cwd, packages } = await pnpm(toAbsolute(search));
215
+ return {
216
+ cwd,
217
+ packages
218
+ };
223
219
  };
224
220
  var defaultOptions = {
225
221
  extensions: ["js", "mjs", "jsx", "ts", "mts", "tsx"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/ts-file-cache",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {