policy: canonicalize before resolving specifiers

PR-URL: https://github.com/nodejs/node/pull/37863
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>

Reviewed-By: Guy Bedford <guybedford@gmail.com>
This commit is contained in:
authored and Michaël Zasso committed 2021-09-04 15:14:55 +02:00
1 parent d42bbe48c5
commit bcb85adee6
12 files changed
+773 -352

No files matched your search

+38 -3
View File
@@ -16,12 +16,13 @@ const dep = fixtures.path('policy', 'parent.js');
'policy',
'dependencies',
'dependencies-redirect-policy.json');
const { status } = spawnSync(
const { status, stderr, stdout } = spawnSync(
process.execPath,
[
'--experimental-policy', depPolicy, dep,
]
);
console.log('%s\n%s', stderr, stdout);
assert.strictEqual(status, 0);
}
{
@@ -55,12 +56,13 @@ const dep = fixtures.path('policy', 'parent.js');
'policy',
'dependencies',
'dependencies-wildcard-policy.json');
const { status } = spawnSync(
const { status, stderr, stdout } = spawnSync(
process.execPath,
[
'--experimental-policy', depPolicy, dep,
]
);
console.log('%s\n%s', stderr, stdout);
assert.strictEqual(status, 0);
}
{
@@ -76,6 +78,19 @@ const dep = fixtures.path('policy', 'parent.js');
);
assert.strictEqual(status, 1);
}
{
const depPolicy = fixtures.path(
'policy',
'dependencies',
'dependencies-missing-policy-default-true.json');
const { status } = spawnSync(
process.execPath,
[
'--experimental-policy', depPolicy, dep,
]
);
assert.strictEqual(status, 0);
}
{
const depPolicy = fixtures.path(
'policy',
@@ -107,5 +122,25 @@ const dep = fixtures.path('policy', 'parent.js');
assert.match(
`${stderr}`,
/SyntaxError: Named export 'doesNotExist' not found\./,
'Should give the real SyntaxError and position');
new Error('Should give the real SyntaxError and position'));
}
{
const depPolicy = fixtures.path(
'policy',
'dependencies',
'dependencies-scopes-relative-specifier.json');
const { status } = spawnSync(
process.execPath,
[
'--experimental-policy',
depPolicy,
fixtures.path('policy', 'canonicalize.mjs'),
]
);
assert.strictEqual(
status,
0,
new Error(
'policies should canonicalize specifiers by default prior to matching')
);
}
@@ -38,6 +38,41 @@ const assert = require('assert');
);
}
}
{
const manifest = new Manifest({
scopes: {
'': {
dependencies: true
}
}
});
for (const href of baseURLs) {
assert.strictEqual(
manifest.getDependencyMapper(href).resolve('fs'),
true
);
}
}
{
const manifest = new Manifest({
scopes: {
'': {
dependencies: true
},
'file:': {
cascade: true
}
}
});
for (const href of baseURLs) {
assert.strictEqual(
manifest.getDependencyMapper(href).resolve('fs'),
true
);
}
}
{
const manifest = new Manifest({
scopes: {