@awsless/ts-file-cache 0.0.6 → 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 +40 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +42 -18
- package/package.json +1 -1
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
|
|
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 =
|
|
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 (
|
|
182
|
-
const lockFile = await (
|
|
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,29 +202,53 @@ var pnpm = async (cwd) => {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
const entry = packageData.module ?? packageData.main;
|
|
205
|
-
packages
|
|
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
|
|
213
|
+
return {
|
|
214
|
+
cwd,
|
|
215
|
+
packages
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
var findLockFile = async (path, level = 5) => {
|
|
219
|
+
if (!level) {
|
|
220
|
+
throw new TypeError("No pnpm lock file found");
|
|
221
|
+
}
|
|
222
|
+
const file = (0, import_path4.join)(path, "pnpm-lock.yaml");
|
|
223
|
+
const exists = await fileExist(file);
|
|
224
|
+
if (exists) {
|
|
225
|
+
return [path, await (0, import_promises3.readFile)(file, "utf8")];
|
|
226
|
+
}
|
|
227
|
+
return findLockFile((0, import_path4.normalize)((0, import_path4.join)(path, "..")), level - 1);
|
|
228
|
+
};
|
|
229
|
+
var fileExist = async (file) => {
|
|
230
|
+
try {
|
|
231
|
+
const stat2 = await (0, import_promises3.lstat)(file);
|
|
232
|
+
if (stat2.isFile()) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
} catch (error) {
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
214
238
|
};
|
|
215
239
|
|
|
216
240
|
// src/index.ts
|
|
217
|
-
var loadWorkspace = async (
|
|
218
|
-
const packages = await pnpm(toAbsolute(
|
|
219
|
-
const workspace = { cwd, packages: {} };
|
|
241
|
+
var loadWorkspace = async (search) => {
|
|
242
|
+
const { cwd, packages } = await pnpm(toAbsolute(search));
|
|
220
243
|
const sizes = {};
|
|
221
|
-
|
|
244
|
+
packages.forEach((pkg) => {
|
|
222
245
|
sizes[pkg.name] = pkg.path.split("/").length;
|
|
223
246
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
247
|
+
packages.sort((a, b) => sizes[b.name] - sizes[a.name]);
|
|
248
|
+
return {
|
|
249
|
+
cwd,
|
|
250
|
+
packages
|
|
251
|
+
};
|
|
228
252
|
};
|
|
229
253
|
var defaultOptions = {
|
|
230
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:
|
|
18
|
+
packages: Package[];
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
declare const loadWorkspace: (
|
|
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:
|
|
18
|
+
packages: Package[];
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
declare const loadWorkspace: (
|
|
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
|
|
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 =
|
|
139
|
+
const pkg = workspace.packages.find((pkg2) => {
|
|
140
140
|
return source.startsWith(pkg2.path);
|
|
141
141
|
});
|
|
142
142
|
if (!pkg) {
|
|
@@ -149,13 +149,13 @@ var findDependency = (workspace, module, source) => {
|
|
|
149
149
|
import { extname, resolve as resolve2 } from "path";
|
|
150
150
|
|
|
151
151
|
// src/package-manager/pnpm.ts
|
|
152
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
153
|
-
import { join as join2 } from "path";
|
|
152
|
+
import { lstat, readFile as readFile2 } from "fs/promises";
|
|
153
|
+
import { join as join2, normalize } from "path";
|
|
154
154
|
import { parse as parse2 } from "yaml";
|
|
155
|
-
var pnpm = async (
|
|
156
|
-
const lockFile = await
|
|
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,29 +176,53 @@ var pnpm = async (cwd) => {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
const entry = packageData.module ?? packageData.main;
|
|
179
|
-
packages
|
|
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
|
|
187
|
+
return {
|
|
188
|
+
cwd,
|
|
189
|
+
packages
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
var findLockFile = async (path, level = 5) => {
|
|
193
|
+
if (!level) {
|
|
194
|
+
throw new TypeError("No pnpm lock file found");
|
|
195
|
+
}
|
|
196
|
+
const file = join2(path, "pnpm-lock.yaml");
|
|
197
|
+
const exists = await fileExist(file);
|
|
198
|
+
if (exists) {
|
|
199
|
+
return [path, await readFile2(file, "utf8")];
|
|
200
|
+
}
|
|
201
|
+
return findLockFile(normalize(join2(path, "..")), level - 1);
|
|
202
|
+
};
|
|
203
|
+
var fileExist = async (file) => {
|
|
204
|
+
try {
|
|
205
|
+
const stat2 = await lstat(file);
|
|
206
|
+
if (stat2.isFile()) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
} catch (error) {
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
188
212
|
};
|
|
189
213
|
|
|
190
214
|
// src/index.ts
|
|
191
|
-
var loadWorkspace = async (
|
|
192
|
-
const packages = await pnpm(toAbsolute(
|
|
193
|
-
const workspace = { cwd, packages: {} };
|
|
215
|
+
var loadWorkspace = async (search) => {
|
|
216
|
+
const { cwd, packages } = await pnpm(toAbsolute(search));
|
|
194
217
|
const sizes = {};
|
|
195
|
-
|
|
218
|
+
packages.forEach((pkg) => {
|
|
196
219
|
sizes[pkg.name] = pkg.path.split("/").length;
|
|
197
220
|
});
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
221
|
+
packages.sort((a, b) => sizes[b.name] - sizes[a.name]);
|
|
222
|
+
return {
|
|
223
|
+
cwd,
|
|
224
|
+
packages
|
|
225
|
+
};
|
|
202
226
|
};
|
|
203
227
|
var defaultOptions = {
|
|
204
228
|
extensions: ["js", "mjs", "jsx", "ts", "mts", "tsx"]
|