Skip to content

Commit

Permalink
save dep and timestamp as tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 27, 2024
1 parent e57f400 commit a4e5862
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,27 @@ const handleExternalDepedencies = async function (
externalDependencies,
getFileTimestamp,
) {
const result = [];
for (const dep of externalDependencies) {
for (const depAndEmptyTimestamp of externalDependencies) {
try {
const [dep] = depAndEmptyTimestamp;
const { timestamp } = await getFileTimestamp(dep);
result.push(dep + "\0" + timestamp);
depAndEmptyTimestamp.push(timestamp);
} catch {
result.push(dep);
// ignore errors if timestamp is not available

Check warning on line 78 in src/cache.js

View check run for this annotation

Codecov / codecov/patch

src/cache.js#L78

Added line #L78 was not covered by tests
}
}
result.sort();
return result;
return externalDependencies;
};

const areExternalDependenciesModified = async function (
externalDepsWithTimestamp,
getFileTimestamp,
) {
for (const depAndTimestamp of externalDepsWithTimestamp) {
const [dep, timestamp] = depAndTimestamp.split("\0");
const [dep, timestamp] = depAndTimestamp;
let newTimestamp;
try {
newTimestamp = (await getFileTimestamp(dep)).timestamp + "";
newTimestamp = (await getFileTimestamp(dep)).timestamp;
} catch {
return true;
}

Check warning on line 95 in src/cache.js

View check run for this annotation

Codecov / codecov/patch

src/cache.js#L94-L95

Added lines #L94 - L95 were not covered by tests
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ async function loader(source, inputSourceMap, overrides) {

const { code, map, metadata, externalDependencies } = result;

externalDependencies?.forEach(depAndTimestamp => {
const dep = depAndTimestamp.split("\0")[0];
externalDependencies?.forEach(([dep]) => {
this.addDependency(dep);
});
metadataSubscribers.forEach(subscriber => {
Expand Down
4 changes: 3 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ module.exports = async function (source, options) {
metadata,
sourceType,
// Convert it from a Set to an Array to make it JSON-serializable.
externalDependencies: Array.from(externalDependencies || []),
externalDependencies: Array.from(externalDependencies || [], dep => [
dep,
]).sort(),
};
};

Expand Down

0 comments on commit a4e5862

Please sign in to comment.