Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support extraBabelIncludes (#5942)
* dep: upgrade babel and other deps * feat: support extraBabelIncludes
- Loading branch information
Showing
23 changed files
with
489 additions
and
140 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
6 changes: 6 additions & 0 deletions
6
packages/bundler-webpack/src/fixtures/.extraBabelIncludes/hoo.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,6 @@ | ||
|
||
export default function() { | ||
let hoo = 1; | ||
hoo += 1; | ||
return hoo; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/bundler-webpack/src/fixtures/extraBabelIncludes/config.ts
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,12 @@ | ||
import { join } from 'path'; | ||
|
||
export default { | ||
nodeModulesTransform: { | ||
type: 'none' | ||
}, | ||
extraBabelIncludes: [ | ||
join(__dirname, '../.extraBabelIncludes'), | ||
'foo', | ||
'bar', | ||
], | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/bundler-webpack/src/fixtures/extraBabelIncludes/expect.ts
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,7 @@ | ||
import { IExpectOpts } from '../types'; | ||
|
||
export default ({ indexJS }: IExpectOpts) => { | ||
expect(indexJS).toContain('var bar = 1;'); | ||
expect(indexJS).toContain('var foo = 1;'); | ||
expect(indexJS).toContain('var hoo = 1;'); | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/bundler-webpack/src/fixtures/extraBabelIncludes/index.ts
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,9 @@ | ||
// @ts-ignore | ||
import bar from 'bar/bar'; | ||
// @ts-ignore | ||
import foo from 'foo/foo'; | ||
import hoo from '../.extraBabelIncludes/hoo'; | ||
|
||
bar(); | ||
foo(); | ||
hoo(); |
6 changes: 6 additions & 0 deletions
6
packages/bundler-webpack/src/fixtures/extraBabelIncludes/node_modules/bar/bar.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/bundler-webpack/src/fixtures/extraBabelIncludes/node_modules/bar/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
packages/bundler-webpack/src/fixtures/extraBabelIncludes/node_modules/foo/foo.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/bundler-webpack/src/fixtures/extraBabelIncludes/node_modules/foo/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,16 @@ | ||
import { dirname } from 'path'; | ||
import { pkgUp } from '@umijs/utils'; | ||
|
||
const pkgPathCache = {}; | ||
|
||
export function getPkgPath(filePath: string) { | ||
const dir = dirname(filePath); | ||
if (dir in pkgPathCache) return pkgPathCache[dir]; | ||
pkgPathCache[dir] = pkgUp.sync({ cwd: filePath }); | ||
return pkgPathCache[dir]; | ||
} | ||
|
||
export function shouldTransform(pkgPath: string, include: string) { | ||
const { name } = require(pkgPath); // eslint-disable-line | ||
return name === include; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
packages/preset-built-in/src/plugins/features/extraBabelIncludes.ts
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,12 @@ | ||
import { IApi } from '@umijs/types'; | ||
|
||
export default (api: IApi) => { | ||
api.describe({ | ||
key: 'extraBabelIncludes', | ||
config: { | ||
schema(joi) { | ||
return joi.array(); | ||
}, | ||
}, | ||
}); | ||
}; |
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
Oops, something went wrong.