← back to IWasCute
verification/TK-11380/normalize-build.cjs
21 lines
const fs = require('node:fs');
const path = require('node:path');
const assert = require('node:assert/strict');
const app = fs.realpathSync(process.argv[2]);
const modules = path.join(app, 'node_modules');
const links = path.join(app, '.next', 'node_modules');
const changed = [];
for (const name of fs.readdirSync(links)) {
const link = path.join(links, name);
if (!fs.lstatSync(link).isSymbolicLink()) continue;
const target = fs.realpathSync(link);
assert.ok(target.startsWith(modules + path.sep), 'External package must resolve inside candidate node_modules');
const relative = path.relative(path.dirname(link), target);
const before = fs.readlinkSync(link);
fs.unlinkSync(link);
fs.symlinkSync(relative, link);
assert.equal(fs.realpathSync(link), target);
changed.push({ name, before, after: relative });
}
console.log(JSON.stringify({ app, links: changed }, null, 2));