@awsless/ts-file-cache 0.0.7 → 0.0.8

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
@@ -135,7 +135,7 @@ var generateRecursiveFileHashes = async (workspace, file, source, allowedExtensi
135
135
  if (dependency.type === "package") {
136
136
  hashes.set(file, Buffer.from(`${file}:${dependency.version}`, "utf8"));
137
137
  } else {
138
- const localPackage = workspace.packages[file];
138
+ const localPackage = workspace.packages.find((p) => p.name === file);
139
139
  if (!localPackage) {
140
140
  throw new Error(`Can't find the local workspace package for: ${file}`);
141
141
  }
@@ -162,7 +162,7 @@ var mergeHashes = (hashes) => {
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) => {
165
+ const pkg = workspace.packages.find((pkg2) => {
166
166
  return source.startsWith(pkg2.path);
167
167
  });
168
168
  if (!pkg) {
@@ -178,10 +178,10 @@ var import_path5 = require("path");
178
178
  var import_promises3 = require("fs/promises");
179
179
  var import_path4 = require("path");
180
180
  var import_yaml = require("yaml");
181
- var pnpm = async (cwd) => {
182
- const lockFile = await findLockFile(cwd);
181
+ var pnpm = async (search) => {
182
+ const [cwd, lockFile] = await findLockFile(search);
183
183
  const data = (0, import_yaml.parse)(lockFile);
184
- const packages = {};
184
+ const packages = [];
185
185
  await Promise.all(
186
186
  Object.entries(data.importers).map(async ([path, importee]) => {
187
187
  const deps = { ...importee.devDependencies, ...importee.dependencies };
@@ -202,15 +202,18 @@ var pnpm = async (cwd) => {
202
202
  }
203
203
  }
204
204
  const entry = packageData.module ?? packageData.main;
205
- packages[packageData.name] = {
205
+ packages.push({
206
206
  name: packageData.name,
207
207
  path: (0, import_path4.join)(cwd, path),
208
208
  main: entry ? (0, import_path4.join)(cwd, path, entry) : void 0,
209
209
  dependencies
210
- };
210
+ });
211
211
  })
212
212
  );
213
- return packages;
213
+ return {
214
+ cwd,
215
+ packages
216
+ };
214
217
  };
215
218
  var findLockFile = async (path, level = 5) => {
216
219
  if (!level) {
@@ -219,7 +222,7 @@ var findLockFile = async (path, level = 5) => {
219
222
  const file = (0, import_path4.join)(path, "pnpm-lock.yaml");
220
223
  const exists = await fileExist(file);
221
224
  if (exists) {
222
- return (0, import_promises3.readFile)(file, "utf8");
225
+ return [path, await (0, import_promises3.readFile)(file, "utf8")];
223
226
  }
224
227
  return findLockFile((0, import_path4.normalize)((0, import_path4.join)(path, "..")), level - 1);
225
228
  };
@@ -235,17 +238,17 @@ var fileExist = async (file) => {
235
238
  };
236
239
 
237
240
  // src/index.ts
238
- var loadWorkspace = async (cwd) => {
239
- const packages = await pnpm(toAbsolute(cwd));
240
- const workspace = { cwd, packages: {} };
241
+ var loadWorkspace = async (search) => {
242
+ const { cwd, packages } = await pnpm(toAbsolute(search));
241
243
  const sizes = {};
242
- Object.values(packages).forEach((pkg) => {
244
+ packages.forEach((pkg) => {
243
245
  sizes[pkg.name] = pkg.path.split("/").length;
244
246
  });
245
- Object.entries(packages).sort(([a], [b]) => sizes[b] - sizes[a]).forEach(([name, pkg]) => {
246
- workspace.packages[name] = pkg;
247
- });
248
- return workspace;
247
+ packages.sort((a, b) => sizes[b.name] - sizes[a.name]);
248
+ return {
249
+ cwd,
250
+ packages
251
+ };
249
252
  };
250
253
  var defaultOptions = {
251
254
  extensions: ["js", "mjs", "jsx", "ts", "mts", "tsx"]
package/dist/index.d.cts CHANGED
@@ -15,10 +15,10 @@ type Package = {
15
15
  };
16
16
  type Workspace = {
17
17
  cwd: string;
18
- packages: Record<string, Package>;
18
+ packages: 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
@@ -15,10 +15,10 @@ type Package = {
15
15
  };
16
16
  type Workspace = {
17
17
  cwd: string;
18
- packages: Record<string, Package>;
18
+ packages: 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
@@ -109,7 +109,7 @@ var generateRecursiveFileHashes = async (workspace, file, source, allowedExtensi
109
109
  if (dependency.type === "package") {
110
110
  hashes.set(file, Buffer.from(`${file}:${dependency.version}`, "utf8"));
111
111
  } else {
112
- const localPackage = workspace.packages[file];
112
+ const localPackage = workspace.packages.find((p) => p.name === file);
113
113
  if (!localPackage) {
114
114
  throw new Error(`Can't find the local workspace package for: ${file}`);
115
115
  }
@@ -136,7 +136,7 @@ var mergeHashes = (hashes) => {
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) => {
139
+ const pkg = workspace.packages.find((pkg2) => {
140
140
  return source.startsWith(pkg2.path);
141
141
  });
142
142
  if (!pkg) {
@@ -152,10 +152,10 @@ import { extname, resolve as resolve2 } from "path";
152
152
  import { lstat, readFile as readFile2 } from "fs/promises";
153
153
  import { join as join2, normalize } from "path";
154
154
  import { parse as parse2 } from "yaml";
155
- var pnpm = async (cwd) => {
156
- const lockFile = await findLockFile(cwd);
155
+ var pnpm = async (search) => {
156
+ const [cwd, lockFile] = await findLockFile(search);
157
157
  const data = parse2(lockFile);
158
- const packages = {};
158
+ const packages = [];
159
159
  await Promise.all(
160
160
  Object.entries(data.importers).map(async ([path, importee]) => {
161
161
  const deps = { ...importee.devDependencies, ...importee.dependencies };
@@ -176,15 +176,18 @@ var pnpm = async (cwd) => {
176
176
  }
177
177
  }
178
178
  const entry = packageData.module ?? packageData.main;
179
- packages[packageData.name] = {
179
+ packages.push({
180
180
  name: packageData.name,
181
181
  path: join2(cwd, path),
182
182
  main: entry ? join2(cwd, path, entry) : void 0,
183
183
  dependencies
184
- };
184
+ });
185
185
  })
186
186
  );
187
- return packages;
187
+ return {
188
+ cwd,
189
+ packages
190
+ };
188
191
  };
189
192
  var findLockFile = async (path, level = 5) => {
190
193
  if (!level) {
@@ -193,7 +196,7 @@ var findLockFile = async (path, level = 5) => {
193
196
  const file = join2(path, "pnpm-lock.yaml");
194
197
  const exists = await fileExist(file);
195
198
  if (exists) {
196
- return readFile2(file, "utf8");
199
+ return [path, await readFile2(file, "utf8")];
197
200
  }
198
201
  return findLockFile(normalize(join2(path, "..")), level - 1);
199
202
  };
@@ -209,17 +212,17 @@ var fileExist = async (file) => {
209
212
  };
210
213
 
211
214
  // src/index.ts
212
- var loadWorkspace = async (cwd) => {
213
- const packages = await pnpm(toAbsolute(cwd));
214
- const workspace = { cwd, packages: {} };
215
+ var loadWorkspace = async (search) => {
216
+ const { cwd, packages } = await pnpm(toAbsolute(search));
215
217
  const sizes = {};
216
- Object.values(packages).forEach((pkg) => {
218
+ packages.forEach((pkg) => {
217
219
  sizes[pkg.name] = pkg.path.split("/").length;
218
220
  });
219
- Object.entries(packages).sort(([a], [b]) => sizes[b] - sizes[a]).forEach(([name, pkg]) => {
220
- workspace.packages[name] = pkg;
221
- });
222
- return workspace;
221
+ packages.sort((a, b) => sizes[b.name] - sizes[a.name]);
222
+ return {
223
+ cwd,
224
+ packages
225
+ };
223
226
  };
224
227
  var defaultOptions = {
225
228
  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.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {