-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from umijs/feat/es5ImcompatibleVersions
feat(af-webpack): new option es5ImcompatibleVersions
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { dirname } from 'path'; | ||
import pkgUp from 'pkg-up'; | ||
import { satisfies } from 'semver'; | ||
|
||
const pkgPathCache = {}; | ||
const pkgCache = {}; | ||
const { | ||
config: { 'es5-imcompatible-versions': config }, | ||
} = require('es5-imcompatible-versions/package.json'); | ||
|
||
export function getPkgPath(filePath) { | ||
const dir = dirname(filePath); | ||
if (dir in pkgPathCache) return pkgPathCache[dir]; | ||
pkgPathCache[dir] = pkgUp.sync(filePath); | ||
return pkgPathCache[dir]; | ||
} | ||
|
||
export function shouldTransform(pkgPath) { | ||
if (pkgPath in pkgCache) return pkgCache[pkgPath]; | ||
const { name, version } = require(pkgPath); // eslint-disable-line | ||
pkgCache[pkgPath] = isMatch(name, version); | ||
return pkgCache[pkgPath]; | ||
} | ||
|
||
function isMatch(name, version) { | ||
if (config[name]) { | ||
return Object.keys(config[name]).some(sv => satisfies(version, sv)); | ||
} else { | ||
return false; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
packages/af-webpack/src/getUserConfig/configs/es5ImcompatibleVersions.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,13 @@ | ||
import assert from 'assert'; | ||
|
||
export default function() { | ||
return { | ||
name: 'es5ImcompatibleVersions', | ||
validate(val) { | ||
assert( | ||
typeof val === 'boolean', | ||
`The es5ImcompatibleVersions config must be Boolean, but got ${val}`, | ||
); | ||
}, | ||
}; | ||
} |