Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve absolute path handling (#4021)
* Improve absolute path handling * Rename option to makeAbsoluteExternalsRelative and add documentation * Improve coverage and test names * Refine documentation text
- Loading branch information
1 parent
443dc97
commit b7bb5e2
Showing
29 changed files
with
499 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
test/form/samples/make-absolute-externals-relative/make-relative-false/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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' }; | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.