fix getManagedItem and test cases
This commit is contained in:
parent
db265cbff8
commit
31b912f634
|
@ -63,7 +63,7 @@ const mergeMaps = (a, b) => {
|
|||
|
||||
const getManagedItem = (managedPath, path) => {
|
||||
let i = managedPath.length;
|
||||
let slashes = 2;
|
||||
let slashes = 1;
|
||||
loop: while (i < path.length) {
|
||||
switch (path.charCodeAt(i)) {
|
||||
case 47: // slash
|
||||
|
@ -76,6 +76,27 @@ const getManagedItem = (managedPath, path) => {
|
|||
}
|
||||
i++;
|
||||
}
|
||||
// if (path.slice(i + 1, i + 13) === "node_modules")
|
||||
if (
|
||||
path.charCodeAt(i + 1) === 110 &&
|
||||
path.charCodeAt(i + 2) === 111 &&
|
||||
path.charCodeAt(i + 3) === 100 &&
|
||||
path.charCodeAt(i + 4) === 101 &&
|
||||
path.charCodeAt(i + 5) === 95 &&
|
||||
path.charCodeAt(i + 6) === 109 &&
|
||||
path.charCodeAt(i + 7) === 111 &&
|
||||
path.charCodeAt(i + 8) === 100 &&
|
||||
path.charCodeAt(i + 9) === 117 &&
|
||||
path.charCodeAt(i + 10) === 108 &&
|
||||
path.charCodeAt(i + 11) === 101 &&
|
||||
path.charCodeAt(i + 12) === 115
|
||||
) {
|
||||
const c = path.charCodeAt(i + 13);
|
||||
if (c === 47 || c === 92) {
|
||||
// Managed subpath
|
||||
return getManagedItem(path.slice(0, i + 14), path);
|
||||
}
|
||||
}
|
||||
return path.slice(0, i);
|
||||
};
|
||||
|
||||
|
|
|
@ -48,16 +48,24 @@ describe("BuildDependencies", () => {
|
|||
await exec("1");
|
||||
fs.writeFileSync(
|
||||
path.resolve(inputDirectory, "loader-dependency.js"),
|
||||
"module.exports = 2;"
|
||||
"module.exports = Date.now();"
|
||||
);
|
||||
const now = Date.now();
|
||||
await exec("2");
|
||||
await exec("3");
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
const first = require("./js/buildDeps/1/main.js");
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
const second = require("./js/buildDeps/2/main.js");
|
||||
// eslint-disable-next-line node/no-missing-require
|
||||
const third = require("./js/buildDeps/3/main.js");
|
||||
expect(typeof first).toBe("number");
|
||||
expect(typeof second).toBe("number");
|
||||
expect(typeof third).toBe("number");
|
||||
expect(first).toBe(1);
|
||||
expect(second).toBe(2);
|
||||
// Should be invalidated
|
||||
expect(second).toBeGreaterThan(now);
|
||||
// Should stay cached
|
||||
expect(third).toBe(second);
|
||||
}, 30000);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue