-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(migrate): add typescript support
- Loading branch information
Showing
31 changed files
with
1,499 additions
and
1,188 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/*.js | ||
/**/*.js | ||
!*.test.js | ||
!/**/*.test.js | ||
!/**/__testfixtures__/*.js | ||
!/**/__snapshots__/*.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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"use strict"; | ||
|
||
const defineTest = require("@webpack-cli/utils//defineTest"); | ||
const defineTest = require("@webpack-cli/utils/defineTest"); | ||
|
||
defineTest(__dirname, "extractTextPlugin"); |
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,60 @@ | ||
import * as utils from "@webpack-cli/utils/ast-utils"; | ||
|
||
import { IJSCodeshift, INode } from "../types/NodePath"; | ||
|
||
/** | ||
* | ||
* Check whether `node` is the invocation of the plugin denoted by `pluginName` | ||
* | ||
* @param {Object} j - jscodeshift top-level import | ||
* @param {Path} node - ast node to check | ||
* @param {String} pluginName - name of the plugin | ||
* @returns {Boolean} isPluginInvocation - whether `node` is the invocation of the plugin denoted by `pluginName` | ||
*/ | ||
|
||
function findInvocation(j: IJSCodeshift, path: INode, pluginName: string): boolean { | ||
let found: boolean = false; | ||
found = | ||
j(path) | ||
.find(j.MemberExpression) | ||
.filter((p: INode): boolean => p.get("object").value.name === pluginName) | ||
.size() > 0; | ||
return found; | ||
} | ||
|
||
/** | ||
* | ||
* Transform for ExtractTextPlugin arguments. Consolidates arguments into single options object. | ||
* | ||
* @param {Object} j - jscodeshift top-level import | ||
* @param {Node} ast - jscodeshift ast to transform | ||
* @returns {Node} ast - jscodeshift ast | ||
*/ | ||
|
||
export default function(j: IJSCodeshift, ast: INode): void | INode { | ||
const changeArguments = (path: INode): INode => { | ||
const args: INode[] = path.value.arguments; | ||
|
||
const literalArgs: INode[] = args.filter((p: INode): boolean => utils.isType(p, "Literal")); | ||
if (literalArgs && literalArgs.length > 1) { | ||
const newArgs: object = j.objectExpression( | ||
literalArgs.map((p: INode, index: number): INode => | ||
utils.createProperty(j, index === 0 ? "fallback" : "use", p.value), | ||
), | ||
); | ||
path.value.arguments = [newArgs]; | ||
} | ||
return path; | ||
}; | ||
const name: string = utils.findVariableToPlugin( | ||
j, | ||
ast, | ||
"extract-text-webpack-plugin", | ||
); | ||
if (!name) { return ast; } | ||
|
||
return ast | ||
.find(j.CallExpression) | ||
.filter((p: INode): boolean => findInvocation(j, p, name)) | ||
.forEach(changeArguments); | ||
} |
Oops, something went wrong.