@awsless/ts-file-cache 0.0.13 → 0.0.14
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 +18 -10
- package/dist/index.js +18 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -131,27 +131,24 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
const code = await (0, import_promises2.readFile)(file, "utf8");
|
|
134
|
-
const
|
|
134
|
+
const deps = await findImports(file, code);
|
|
135
135
|
const hash = (0, import_crypto.createHash)("sha1").update(code).digest();
|
|
136
136
|
hashes.set(relFile, hash);
|
|
137
|
-
if (!ext || !allowedExtensions.includes(ext)) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const deps = await findImports(file, code);
|
|
141
137
|
for (const dep of deps) {
|
|
142
138
|
await generateRecursiveFileHashes(workspace, dep, file, allowedExtensions, hashes);
|
|
143
139
|
}
|
|
144
140
|
return;
|
|
145
141
|
}
|
|
146
|
-
|
|
142
|
+
const module2 = getPackageName(file);
|
|
143
|
+
if (hashes.has(module2)) {
|
|
147
144
|
return;
|
|
148
145
|
}
|
|
149
|
-
const dependency = findDependency(workspace,
|
|
146
|
+
const dependency = findDependency(workspace, module2, sourceFile);
|
|
150
147
|
if (dependency) {
|
|
151
148
|
if (dependency.type === "package") {
|
|
152
|
-
hashes.set(
|
|
149
|
+
hashes.set(module2, Buffer.from(`${module2}:${dependency.version}`, "utf8"));
|
|
153
150
|
} else {
|
|
154
|
-
const localPackage = workspace.packages[
|
|
151
|
+
const localPackage = workspace.packages[module2];
|
|
155
152
|
if (!localPackage) {
|
|
156
153
|
throw new Error(`Can't find the local workspace package for: ${file}`);
|
|
157
154
|
}
|
|
@@ -168,7 +165,7 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
168
165
|
}
|
|
169
166
|
return;
|
|
170
167
|
}
|
|
171
|
-
if (import_node_module.builtinModules.includes(
|
|
168
|
+
if (import_node_module.builtinModules.includes(module2.replace(/^node\:/, ""))) {
|
|
172
169
|
return;
|
|
173
170
|
}
|
|
174
171
|
throw new Error(`Can't find the dependency version for: ${file} inside the source: ${sourceFile}`);
|
|
@@ -177,6 +174,17 @@ var mergeHashes = (hashes) => {
|
|
|
177
174
|
const merge = Buffer.concat(Array.from(hashes.values()).sort());
|
|
178
175
|
return (0, import_crypto.createHash)("sha1").update(merge).digest("hex");
|
|
179
176
|
};
|
|
177
|
+
var getPackageName = (importee) => {
|
|
178
|
+
const parts = importee.split("/");
|
|
179
|
+
if (importee.startsWith("@")) {
|
|
180
|
+
if (parts.length >= 2) {
|
|
181
|
+
return `${parts[0]}/${parts[1]}`;
|
|
182
|
+
}
|
|
183
|
+
} else if (parts.length >= 1) {
|
|
184
|
+
return parts[0];
|
|
185
|
+
}
|
|
186
|
+
throw new Error(`Malformed importee: ${importee}`);
|
|
187
|
+
};
|
|
180
188
|
var findDependency = (workspace, module2, source) => {
|
|
181
189
|
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]);
|
|
182
190
|
if (!pkg) {
|
package/dist/index.js
CHANGED
|
@@ -105,27 +105,24 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
const code = await readFile(file, "utf8");
|
|
108
|
-
const
|
|
108
|
+
const deps = await findImports(file, code);
|
|
109
109
|
const hash = createHash("sha1").update(code).digest();
|
|
110
110
|
hashes.set(relFile, hash);
|
|
111
|
-
if (!ext || !allowedExtensions.includes(ext)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const deps = await findImports(file, code);
|
|
115
111
|
for (const dep of deps) {
|
|
116
112
|
await generateRecursiveFileHashes(workspace, dep, file, allowedExtensions, hashes);
|
|
117
113
|
}
|
|
118
114
|
return;
|
|
119
115
|
}
|
|
120
|
-
|
|
116
|
+
const module = getPackageName(file);
|
|
117
|
+
if (hashes.has(module)) {
|
|
121
118
|
return;
|
|
122
119
|
}
|
|
123
|
-
const dependency = findDependency(workspace,
|
|
120
|
+
const dependency = findDependency(workspace, module, sourceFile);
|
|
124
121
|
if (dependency) {
|
|
125
122
|
if (dependency.type === "package") {
|
|
126
|
-
hashes.set(
|
|
123
|
+
hashes.set(module, Buffer.from(`${module}:${dependency.version}`, "utf8"));
|
|
127
124
|
} else {
|
|
128
|
-
const localPackage = workspace.packages[
|
|
125
|
+
const localPackage = workspace.packages[module];
|
|
129
126
|
if (!localPackage) {
|
|
130
127
|
throw new Error(`Can't find the local workspace package for: ${file}`);
|
|
131
128
|
}
|
|
@@ -142,7 +139,7 @@ var generateRecursiveFileHashes = async (workspace, file, sourceFile, allowedExt
|
|
|
142
139
|
}
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
145
|
-
if (builtinModules.includes(
|
|
142
|
+
if (builtinModules.includes(module.replace(/^node\:/, ""))) {
|
|
146
143
|
return;
|
|
147
144
|
}
|
|
148
145
|
throw new Error(`Can't find the dependency version for: ${file} inside the source: ${sourceFile}`);
|
|
@@ -151,6 +148,17 @@ var mergeHashes = (hashes) => {
|
|
|
151
148
|
const merge = Buffer.concat(Array.from(hashes.values()).sort());
|
|
152
149
|
return createHash("sha1").update(merge).digest("hex");
|
|
153
150
|
};
|
|
151
|
+
var getPackageName = (importee) => {
|
|
152
|
+
const parts = importee.split("/");
|
|
153
|
+
if (importee.startsWith("@")) {
|
|
154
|
+
if (parts.length >= 2) {
|
|
155
|
+
return `${parts[0]}/${parts[1]}`;
|
|
156
|
+
}
|
|
157
|
+
} else if (parts.length >= 1) {
|
|
158
|
+
return parts[0];
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Malformed importee: ${importee}`);
|
|
161
|
+
};
|
|
154
162
|
var findDependency = (workspace, module, source) => {
|
|
155
163
|
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]);
|
|
156
164
|
if (!pkg) {
|