/
_config.js
45 lines (42 loc) · 1.54 KB
/
_config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const path = require('path');
const assert = require('assert');
const ID_MAIN = path.join(__dirname, 'main.js');
module.exports = {
description: 'does not normalize external paths when set to false',
options: {
makeAbsoluteExternalsRelative: false,
external(id) {
if (
[
'./relativeUnresolved.js',
'../relativeUnresolved.js',
'/absolute.js',
'/pluginAbsolute.js'
].includes(id)
)
return true;
},
plugins: {
async buildStart() {
const testExternal = async (source, expected) =>
assert.deepStrictEqual((await this.resolve(source, ID_MAIN)).external, expected, source);
await testExternal('./relativeUnresolved.js', true);
await testExternal('/absolute.js', 'absolute');
await testExternal('./pluginDirect.js', true);
await testExternal('/pluginDifferentAbsolute.js', 'absolute');
await testExternal('./pluginTrue.js', 'absolute');
await testExternal('./pluginForceAbsolute.js', 'absolute');
await testExternal('./pluginForceRelative.js', true);
},
resolveId(source) {
if (source.endsWith('/pluginDirect.js')) return false;
if (source.endsWith('/pluginDifferentAbsolute.js')) return '/pluginAbsolute.js';
if (source.endsWith('/pluginTrue.js')) return { id: '/pluginTrue.js', external: true };
if (source.endsWith('/pluginForceAbsolute.js'))
return { id: '/pluginForceAbsolute.js', external: 'absolute' };
if (source.endsWith('/pluginForceRelative.js'))
return { id: path.join(__dirname, 'pluginForceRelative.js'), external: 'relative' };
}
}
}
};