@awsless/ts-file-cache 0.0.5 → 0.0.7
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/README.MD +1 -1
- package/dist/index.cjs +22 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -3
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
# File hash for js & ts files.
|
|
3
3
|
|
|
4
|
-
Attempt to create a hash from an js file and all it's dependecies.
|
|
4
|
+
Attempt to create a hash from an js/ts file and all it's dependecies.
|
|
5
5
|
The goal is to generate a new hash when ever the file or it's dependecies change.
|
|
6
6
|
|
|
7
7
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -179,7 +179,7 @@ var import_promises3 = require("fs/promises");
|
|
|
179
179
|
var import_path4 = require("path");
|
|
180
180
|
var import_yaml = require("yaml");
|
|
181
181
|
var pnpm = async (cwd) => {
|
|
182
|
-
const lockFile = await (
|
|
182
|
+
const lockFile = await findLockFile(cwd);
|
|
183
183
|
const data = (0, import_yaml.parse)(lockFile);
|
|
184
184
|
const packages = {};
|
|
185
185
|
await Promise.all(
|
|
@@ -212,6 +212,27 @@ var pnpm = async (cwd) => {
|
|
|
212
212
|
);
|
|
213
213
|
return packages;
|
|
214
214
|
};
|
|
215
|
+
var findLockFile = async (path, level = 5) => {
|
|
216
|
+
if (!level) {
|
|
217
|
+
throw new TypeError("No pnpm lock file found");
|
|
218
|
+
}
|
|
219
|
+
const file = (0, import_path4.join)(path, "pnpm-lock.yaml");
|
|
220
|
+
const exists = await fileExist(file);
|
|
221
|
+
if (exists) {
|
|
222
|
+
return (0, import_promises3.readFile)(file, "utf8");
|
|
223
|
+
}
|
|
224
|
+
return findLockFile((0, import_path4.normalize)((0, import_path4.join)(path, "..")), level - 1);
|
|
225
|
+
};
|
|
226
|
+
var fileExist = async (file) => {
|
|
227
|
+
try {
|
|
228
|
+
const stat2 = await (0, import_promises3.lstat)(file);
|
|
229
|
+
if (stat2.isFile()) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
};
|
|
215
236
|
|
|
216
237
|
// src/index.ts
|
|
217
238
|
var loadWorkspace = async (cwd) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -25,4 +25,4 @@ type Options = {
|
|
|
25
25
|
declare const generateFileHash: (workspace: Workspace, file: string, opts?: Options) => Promise<string>;
|
|
26
26
|
declare const generateFolderHash: (workspace: Workspace, folder: string, opts?: Options) => Promise<string>;
|
|
27
27
|
|
|
28
|
-
export { generateFileHash, generateFolderHash, loadWorkspace };
|
|
28
|
+
export { type Dependency, type Package, type PackageDependency, type Workspace, type WorkspaceDependency, generateFileHash, generateFolderHash, loadWorkspace };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,4 +25,4 @@ type Options = {
|
|
|
25
25
|
declare const generateFileHash: (workspace: Workspace, file: string, opts?: Options) => Promise<string>;
|
|
26
26
|
declare const generateFolderHash: (workspace: Workspace, folder: string, opts?: Options) => Promise<string>;
|
|
27
27
|
|
|
28
|
-
export { generateFileHash, generateFolderHash, loadWorkspace };
|
|
28
|
+
export { type Dependency, type Package, type PackageDependency, type Workspace, type WorkspaceDependency, generateFileHash, generateFolderHash, loadWorkspace };
|
package/dist/index.js
CHANGED
|
@@ -149,11 +149,11 @@ 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
155
|
var pnpm = async (cwd) => {
|
|
156
|
-
const lockFile = await
|
|
156
|
+
const lockFile = await findLockFile(cwd);
|
|
157
157
|
const data = parse2(lockFile);
|
|
158
158
|
const packages = {};
|
|
159
159
|
await Promise.all(
|
|
@@ -186,6 +186,27 @@ var pnpm = async (cwd) => {
|
|
|
186
186
|
);
|
|
187
187
|
return packages;
|
|
188
188
|
};
|
|
189
|
+
var findLockFile = async (path, level = 5) => {
|
|
190
|
+
if (!level) {
|
|
191
|
+
throw new TypeError("No pnpm lock file found");
|
|
192
|
+
}
|
|
193
|
+
const file = join2(path, "pnpm-lock.yaml");
|
|
194
|
+
const exists = await fileExist(file);
|
|
195
|
+
if (exists) {
|
|
196
|
+
return readFile2(file, "utf8");
|
|
197
|
+
}
|
|
198
|
+
return findLockFile(normalize(join2(path, "..")), level - 1);
|
|
199
|
+
};
|
|
200
|
+
var fileExist = async (file) => {
|
|
201
|
+
try {
|
|
202
|
+
const stat2 = await lstat(file);
|
|
203
|
+
if (stat2.isFile()) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
};
|
|
189
210
|
|
|
190
211
|
// src/index.ts
|
|
191
212
|
var loadWorkspace = async (cwd) => {
|