Skip to content

Commit efe8c2a

Browse files
committedJun 7, 2019
chore: update jest snapshots
1 parent 12a38be commit efe8c2a

File tree

8 files changed

+652
-319
lines changed

8 files changed

+652
-319
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"travis:integration": "npm run build && npm run test && npm run reportCoverage",
4949
"travis:lint": "npm run build && npm run lint",
5050
"watch": "npm run build && tsc -w",
51-
"publish:monorepo": "lerna publish -m \"chore: monorepo version update\""
51+
"publish:monorepo": "npm run format && npm run test && lerna publish -m \"chore: monorepo version update\""
5252
},
5353
"husky": {
5454
"hooks": {

‎packages/utils/ast-utils.ts

+89-124
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ function isImportPresent(j: JSCodeshift, ast: Node, path: string): boolean {
66
throw new Error(`path parameter should be string, recieved ${typeof path}`);
77
}
88
let importExists = false;
9-
ast.find(j.CallExpression).forEach(
10-
(callExp: Node): void => {
11-
if (
12-
(callExp.value as Node).callee.name === "require" &&
13-
(callExp.value as Node).arguments[0].value === path
14-
) {
15-
importExists = true;
16-
}
9+
ast.find(j.CallExpression).forEach((callExp: Node): void => {
10+
if ((callExp.value as Node).callee.name === "require" && (callExp.value as Node).arguments[0].value === path) {
11+
importExists = true;
1712
}
18-
);
13+
});
1914
return importExists;
2015
}
2116

@@ -93,13 +88,11 @@ function pathsToMemberExpression(j: JSCodeshift, paths: string[]): Node {
9388
*/
9489

9590
function findPluginsByName(j: JSCodeshift, node: Node, pluginNamesArray: string[]): Node {
96-
return node.find(j.NewExpression).filter(
97-
(path: Node): boolean => {
98-
return pluginNamesArray.some(
99-
(plugin: string): boolean => memberExpressionToPathString(path.get("callee").value as Node) === plugin
100-
);
101-
}
102-
);
91+
return node.find(j.NewExpression).filter((path: Node): boolean => {
92+
return pluginNamesArray.some(
93+
(plugin: string): boolean => memberExpressionToPathString(path.get("callee").value as Node) === plugin
94+
);
95+
});
10396
}
10497

10598
/**
@@ -110,14 +103,12 @@ function findPluginsByName(j: JSCodeshift, node: Node, pluginNamesArray: string[
110103
*/
111104

112105
function findPluginsArrayAndRemoveIfEmpty(j: JSCodeshift, rootNode: Node): Node {
113-
return rootNode.find(j.Identifier, { name: "plugins" }).forEach(
114-
(node: Node): void => {
115-
const elements = safeTraverse(node, ["parent", "value", "value", "elements"]) as Node[];
116-
if (!elements.length) {
117-
j(node.parent).remove();
118-
}
106+
return rootNode.find(j.Identifier, { name: "plugins" }).forEach((node: Node): void => {
107+
const elements = safeTraverse(node, ["parent", "value", "value", "elements"]) as Node[];
108+
if (!elements.length) {
109+
j(node.parent).remove();
119110
}
120-
);
111+
});
121112
}
122113

123114
/**
@@ -250,15 +241,11 @@ function addOrUpdateConfigObject(
250241
if (propertyExists) {
251242
rootNode.properties
252243
.filter((path: Node): boolean => path.key.name === configProperty)
253-
.forEach(
254-
(path: Node): void => {
255-
const newProperties = (path.value as Node).properties.filter(
256-
(p: Node): boolean => p.key.name !== key
257-
);
258-
newProperties.push(j.objectProperty(j.identifier(key), value));
259-
(path.value as Node).properties = newProperties;
260-
}
261-
);
244+
.forEach((path: Node): void => {
245+
const newProperties = (path.value as Node).properties.filter((p: Node): boolean => p.key.name !== key);
246+
newProperties.push(j.objectProperty(j.identifier(key), value));
247+
(path.value as Node).properties = newProperties;
248+
});
262249
} else {
263250
rootNode.properties.push(
264251
j.objectProperty(
@@ -285,17 +272,15 @@ function findAndRemovePluginByName(j: JSCodeshift, node: Node, pluginName: strin
285272

286273
findPluginsByName(j, node, [pluginName])
287274
.filter((path: Node): boolean => !!safeTraverse(path, ["parent", "value"]))
288-
.forEach(
289-
(path: Node): void => {
290-
rootPath = safeTraverse(path, ["parent", "parent", "parent", "value"]) as Node;
291-
const arrayPath = path.parent.value as Node;
292-
if (arrayPath.elements && arrayPath.elements.length === 1) {
293-
j(path.parent.parent).remove();
294-
} else {
295-
j(path).remove();
296-
}
275+
.forEach((path: Node): void => {
276+
rootPath = safeTraverse(path, ["parent", "parent", "parent", "value"]) as Node;
277+
const arrayPath = path.parent.value as Node;
278+
if (arrayPath.elements && arrayPath.elements.length === 1) {
279+
j(path.parent.parent).remove();
280+
} else {
281+
j(path).remove();
297282
}
298-
);
283+
});
299284

300285
return rootPath;
301286
}
@@ -326,45 +311,39 @@ function createOrUpdatePluginByName(j: JSCodeshift, rootNodePath: Node, pluginNa
326311

327312
// If plugin declaration already exist
328313
if (pluginInstancePath.size()) {
329-
pluginInstancePath.forEach(
330-
(path: Node): void => {
331-
// There are options we want to pass as argument
332-
if (optionsProps) {
333-
const args: Node[] = (path.value as Node).arguments;
334-
if (args.length) {
335-
// Plugin is called with object as arguments
336-
// we will merge those objects
337-
const currentProps: Node = j(path)
338-
.find(j.ObjectExpression)
339-
.get("properties");
340-
341-
optionsProps.forEach(
342-
(opt: Node): void => {
343-
// Search for same keys in the existing object
344-
const existingProps = j(currentProps)
345-
.find(j.Identifier)
346-
.filter((p: Node): boolean => opt.key.value === (p.value as Node).name);
347-
348-
if (existingProps.size()) {
349-
// Replacing values for the same key
350-
existingProps.forEach(
351-
(p: Node): void => {
352-
j(p.parent).replaceWith(opt);
353-
}
354-
);
355-
} else {
356-
// Adding new key:values
357-
(currentProps.value as Node[]).push(opt);
358-
}
359-
}
360-
);
361-
} else {
362-
// Plugin is called without arguments
363-
args.push(j.objectExpression(optionsProps));
364-
}
314+
pluginInstancePath.forEach((path: Node): void => {
315+
// There are options we want to pass as argument
316+
if (optionsProps) {
317+
const args: Node[] = (path.value as Node).arguments;
318+
if (args.length) {
319+
// Plugin is called with object as arguments
320+
// we will merge those objects
321+
const currentProps: Node = j(path)
322+
.find(j.ObjectExpression)
323+
.get("properties");
324+
325+
optionsProps.forEach((opt: Node): void => {
326+
// Search for same keys in the existing object
327+
const existingProps = j(currentProps)
328+
.find(j.Identifier)
329+
.filter((p: Node): boolean => opt.key.value === (p.value as Node).name);
330+
331+
if (existingProps.size()) {
332+
// Replacing values for the same key
333+
existingProps.forEach((p: Node): void => {
334+
j(p.parent).replaceWith(opt);
335+
});
336+
} else {
337+
// Adding new key:values
338+
(currentProps.value as Node[]).push(opt);
339+
}
340+
});
341+
} else {
342+
// Plugin is called without arguments
343+
args.push(j.objectExpression(optionsProps));
365344
}
366345
}
367-
);
346+
});
368347
} else {
369348
let argumentsArray: Node[] = [];
370349
if (optionsProps) {
@@ -458,23 +437,19 @@ function addProperty(j: JSCodeshift, p: Node, key: string, value: valueType, act
458437
if (safeTraverseAndGetType(p) === "ArrayExpression") {
459438
arrExp = (p.value as Node).value as Node;
460439
}
461-
value.forEach(
462-
(val: valueType): void => {
463-
addProperty(j, arrExp, null, val);
464-
}
465-
);
440+
value.forEach((val: valueType): void => {
441+
addProperty(j, arrExp, null, val);
442+
});
466443
valForNode = arrExp;
467444
} else if (typeof value === "object" && !(value.__paths || value instanceof RegExp)) {
468445
let objectExp: Node = j.objectExpression([]);
469446
if (safeTraverseAndGetType(p) === "ObjectExpression") {
470447
objectExp = (p.value as Node).value as Node;
471448
}
472449
// object -> loop through it
473-
Object.keys(value).forEach(
474-
(prop: string): void => {
475-
addProperty(j, objectExp, prop, value[prop]);
476-
}
477-
);
450+
Object.keys(value).forEach((prop: string): void => {
451+
addProperty(j, objectExp, prop, value[prop]);
452+
});
478453
valForNode = objectExp;
479454
} else {
480455
valForNode = createIdentifierOrLiteral(j, value);
@@ -527,11 +502,9 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType
527502
value: value.rules[0].loader
528503
}
529504
})
530-
.forEach(
531-
(p: Node): void => {
532-
j(p.parent).remove();
533-
}
534-
);
505+
.forEach((p: Node): void => {
506+
j(p.parent).remove();
507+
});
535508
}
536509
}
537510

@@ -541,14 +514,12 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType
541514
.find(j.Literal, {
542515
value: value[0]
543516
})
544-
.forEach(
545-
(p: Node): void => {
546-
const configKey = safeTraverse(p, ["parent", "parent", "node", "key", "name"]);
547-
if (configKey === key) {
548-
j(p).remove();
549-
}
517+
.forEach((p: Node): void => {
518+
const configKey = safeTraverse(p, ["parent", "parent", "node", "key", "name"]);
519+
if (configKey === key) {
520+
j(p).remove();
550521
}
551-
);
522+
});
552523
}
553524

554525
// value => literal string / boolean / nested object
@@ -569,11 +540,9 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType
569540
type: "Identifier"
570541
}
571542
})
572-
.forEach(
573-
(p: Node): void => {
574-
j(p).remove();
575-
}
576-
);
543+
.forEach((p: Node): void => {
544+
j(p).remove();
545+
});
577546
}
578547

579548
/**
@@ -591,16 +560,14 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType
591560
// eslint-disable-next-line @typescript-eslint/no-unused-vars
592561
function parseTopScope(j: JSCodeshift, ast: Node, value: string[], action: string): boolean | Node {
593562
function createTopScopeProperty(p: Node): boolean {
594-
value.forEach(
595-
(n: string): void => {
596-
if (
597-
!(p.value as Node).body[0].declarations ||
598-
n.indexOf((p.value as Node).body[0].declarations[0].id.name) <= 0
599-
) {
600-
(p.value as Node).body.splice(-1, 0, n);
601-
}
563+
value.forEach((n: string): void => {
564+
if (
565+
!(p.value as Node).body[0].declarations ||
566+
n.indexOf((p.value as Node).body[0].declarations[0].id.name) <= 0
567+
) {
568+
(p.value as Node).body.splice(-1, 0, n);
602569
}
603-
);
570+
});
604571
return false; // TODO: debug later
605572
}
606573
if (value) {
@@ -658,17 +625,15 @@ function parseMerge(j: JSCodeshift, ast: Node, value: string[], action: string):
658625
`Both parameters should be strings. recieved ${typeof configIdentifier}, ${typeof configPath}`
659626
);
660627
}
661-
ast.find(j.Program).forEach(
662-
(p: Node): void => {
663-
if (!isImportPresent(j, ast, "webpack-merge")) {
664-
(p.value as Node).body.splice(-1, 0, `const merge = require('webpack-merge')`);
665-
}
628+
ast.find(j.Program).forEach((p: Node): void => {
629+
if (!isImportPresent(j, ast, "webpack-merge")) {
630+
(p.value as Node).body.splice(-1, 0, `const merge = require('webpack-merge')`);
631+
}
666632

667-
if (!isImportPresent(j, ast, configPath)) {
668-
(p.value as Node).body.splice(-1, 0, `const ${configIdentifier} = require('${configPath}')`);
669-
}
633+
if (!isImportPresent(j, ast, configPath)) {
634+
(p.value as Node).body.splice(-1, 0, `const ${configIdentifier} = require('${configPath}')`);
670635
}
671-
);
636+
});
672637
}
673638

674639
if (value) {

‎packages/utils/modify-config-helper.ts

+39-47
Original file line numberDiff line numberDiff line change
@@ -90,56 +90,48 @@ export default function modifyHelperUtil(
9090
env.run(generatorName, {
9191
configFile
9292
})
93-
.then(
94-
(): void => {
95-
let configModule: object;
96-
try {
97-
const confPath = path.resolve(process.cwd(), ".yo-rc.json");
98-
configModule = require(confPath);
99-
// Change structure of the config to be transformed
100-
const tmpConfig: object = {};
101-
Object.keys(configModule).forEach(
102-
(prop: string): void => {
103-
const configs = Object.keys(configModule[prop].configuration);
104-
configs.forEach(
105-
(conf: string): void => {
106-
tmpConfig[conf] = configModule[prop].configuration[conf];
107-
}
108-
);
109-
}
110-
);
111-
configModule = tmpConfig;
112-
} catch (err) {
113-
console.error(chalk.red("\nCould not find a yeoman configuration file.\n"));
114-
console.error(
115-
chalk.red(
116-
"\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n"
117-
)
118-
);
119-
Error.stackTraceLimit = 0;
120-
process.exitCode = -1;
121-
}
122-
const transformConfig: TransformConfig = Object.assign(
123-
{
124-
configFile: !configPath ? null : fs.readFileSync(configPath, "utf8"),
125-
configPath
126-
},
127-
configModule
128-
);
129-
return runTransform(transformConfig, action);
130-
}
131-
)
132-
.catch(
133-
(err): void => {
93+
.then((): void => {
94+
let configModule: object;
95+
try {
96+
const confPath = path.resolve(process.cwd(), ".yo-rc.json");
97+
configModule = require(confPath);
98+
// Change structure of the config to be transformed
99+
const tmpConfig: object = {};
100+
Object.keys(configModule).forEach((prop: string): void => {
101+
const configs = Object.keys(configModule[prop].configuration);
102+
configs.forEach((conf: string): void => {
103+
tmpConfig[conf] = configModule[prop].configuration[conf];
104+
});
105+
});
106+
configModule = tmpConfig;
107+
} catch (err) {
108+
console.error(chalk.red("\nCould not find a yeoman configuration file.\n"));
134109
console.error(
135110
chalk.red(
136-
`
137-
Unexpected Error
138-
please file an issue here https://github.com/webpack/webpack-cli/issues/new?template=Bug_report.md
139-
`
111+
"\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n"
140112
)
141113
);
142-
console.error(err);
114+
Error.stackTraceLimit = 0;
115+
process.exitCode = -1;
143116
}
144-
);
117+
const transformConfig: TransformConfig = Object.assign(
118+
{
119+
configFile: !configPath ? null : fs.readFileSync(configPath, "utf8"),
120+
configPath
121+
},
122+
configModule
123+
);
124+
return runTransform(transformConfig, action);
125+
})
126+
.catch((err): void => {
127+
console.error(
128+
chalk.red(
129+
`
130+
Unexpected Error
131+
please file an issue here https://github.com/webpack/webpack-cli/issues/new?template=Bug_report.md
132+
`
133+
)
134+
);
135+
console.error(err);
136+
});
145137
}

‎packages/utils/npm-packages-exists.ts

+32-40
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,38 @@ export default function npmPackagesExists(pkg: string[]): void {
2424
}
2525
}
2626

27-
pkg.forEach(
28-
(scaffold: string): void => {
29-
if (isLocalPath(scaffold)) {
30-
// If the scaffold is a path to a local folder, no name validation is necessary.
31-
acceptedPackages.push(scaffold);
32-
resolvePackagesIfReady();
33-
return;
34-
}
35-
36-
// The scaffold is on npm; validate name and existence
37-
if (
38-
scaffold.length <= WEBPACK_SCAFFOLD_PREFIX.length ||
39-
scaffold.slice(0, WEBPACK_SCAFFOLD_PREFIX.length) !== WEBPACK_SCAFFOLD_PREFIX
40-
) {
41-
throw new TypeError(
42-
chalk.bold(`${scaffold} isn't a valid name.\n`) +
43-
chalk.red(
44-
`\nIt should be prefixed with '${WEBPACK_SCAFFOLD_PREFIX}', but have different suffix.\n`
45-
)
46-
);
47-
}
27+
pkg.forEach((scaffold: string): void => {
28+
if (isLocalPath(scaffold)) {
29+
// If the scaffold is a path to a local folder, no name validation is necessary.
30+
acceptedPackages.push(scaffold);
31+
resolvePackagesIfReady();
32+
return;
33+
}
4834

49-
npmExists(scaffold)
50-
.then(
51-
(moduleExists: boolean): void => {
52-
if (moduleExists) {
53-
acceptedPackages.push(scaffold);
54-
} else {
55-
Error.stackTraceLimit = 0;
56-
throw new TypeError(`Cannot resolve location of package ${scaffold}.`);
57-
}
58-
}
59-
)
60-
.catch(
61-
(err: Error): void => {
62-
console.error(err.stack || err);
63-
process.exit(0);
64-
}
65-
)
66-
.then(resolvePackagesIfReady);
35+
// The scaffold is on npm; validate name and existence
36+
if (
37+
scaffold.length <= WEBPACK_SCAFFOLD_PREFIX.length ||
38+
scaffold.slice(0, WEBPACK_SCAFFOLD_PREFIX.length) !== WEBPACK_SCAFFOLD_PREFIX
39+
) {
40+
throw new TypeError(
41+
chalk.bold(`${scaffold} isn't a valid name.\n`) +
42+
chalk.red(`\nIt should be prefixed with '${WEBPACK_SCAFFOLD_PREFIX}', but have different suffix.\n`)
43+
);
6744
}
68-
);
45+
46+
npmExists(scaffold)
47+
.then((moduleExists: boolean): void => {
48+
if (moduleExists) {
49+
acceptedPackages.push(scaffold);
50+
} else {
51+
Error.stackTraceLimit = 0;
52+
throw new TypeError(`Cannot resolve location of package ${scaffold}.`);
53+
}
54+
})
55+
.catch((err: Error): void => {
56+
console.error(err.stack || err);
57+
process.exit(0);
58+
})
59+
.then(resolvePackagesIfReady);
60+
});
6961
}

‎packages/utils/recursive-parser.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,28 @@ export default function recursiveTransform(
2424
// get module.exports prop
2525
const root = ast
2626
.find(j.ObjectExpression)
27-
.filter(
28-
(p: Node): boolean => {
29-
return (
30-
utils.safeTraverse(p, ["parentPath", "value", "left", "object", "name"]) === "module" &&
31-
utils.safeTraverse(p, ["parentPath", "value", "left", "property", "name"]) === "exports"
32-
);
33-
}
34-
)
27+
.filter((p: Node): boolean => {
28+
return (
29+
utils.safeTraverse(p, ["parentPath", "value", "left", "object", "name"]) === "module" &&
30+
utils.safeTraverse(p, ["parentPath", "value", "left", "property", "name"]) === "exports"
31+
);
32+
})
3533
.filter((p: Node): boolean => !!(p.value as Node).properties);
3634

3735
if (node.size() !== 0) {
3836
if (action === "add") {
39-
return utils.findRootNodesByName(j, root, key).forEach(
40-
(p: Node): void => {
41-
j(p).replaceWith(utils.addProperty(j, p, key, value, action));
42-
}
43-
);
37+
return utils.findRootNodesByName(j, root, key).forEach((p: Node): void => {
38+
j(p).replaceWith(utils.addProperty(j, p, key, value, action));
39+
});
4440
} else if (action === "remove") {
4541
return utils.removeProperty(j, root, key, value);
4642
}
4743
} else {
48-
return root.forEach(
49-
(p: Node): void => {
50-
if (value) {
51-
// init, add new property
52-
utils.addProperty(j, p, key, value, null);
53-
}
44+
return root.forEach((p: Node): void => {
45+
if (value) {
46+
// init, add new property
47+
utils.addProperty(j, p, key, value, null);
5448
}
55-
);
49+
});
5650
}
5751
}

‎packages/utils/resolve-packages.ts

+42-50
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ interface ChildProcess {
1919
*/
2020

2121
export function processPromise(child: ChildProcess): Promise<void> {
22-
return new Promise(
23-
(resolve: () => void, reject: () => void): void => {
24-
if (child.status !== 0) {
25-
reject();
26-
} else {
27-
resolve();
28-
}
22+
return new Promise((resolve: () => void, reject: () => void): void => {
23+
if (child.status !== 0) {
24+
reject();
25+
} else {
26+
resolve();
2927
}
30-
);
28+
});
3129
}
3230

3331
/**
@@ -50,52 +48,46 @@ export function resolvePackages(pkg: string[]): Function | void {
5048
}
5149
}
5250

53-
pkg.forEach(
54-
(scaffold: string): void => {
55-
// Resolve paths to modules on local filesystem
56-
if (isLocalPath(scaffold)) {
57-
let absolutePath: string = scaffold;
51+
pkg.forEach((scaffold: string): void => {
52+
// Resolve paths to modules on local filesystem
53+
if (isLocalPath(scaffold)) {
54+
let absolutePath: string = scaffold;
55+
56+
try {
57+
absolutePath = path.resolve(process.cwd(), scaffold);
58+
require.resolve(absolutePath);
59+
packageLocations.push(absolutePath);
60+
} catch (err) {
61+
console.error(`Cannot find a generator at ${absolutePath}.`);
62+
console.error("\nReason:\n");
63+
console.error(chalk.bold.red(err));
64+
process.exitCode = 1;
65+
}
66+
67+
invokeGeneratorIfReady();
68+
return;
69+
}
5870

71+
// Resolve modules on npm registry
72+
processPromise(spawnChild(scaffold))
73+
.then((): void => {
5974
try {
60-
absolutePath = path.resolve(process.cwd(), scaffold);
61-
require.resolve(absolutePath);
62-
packageLocations.push(absolutePath);
75+
const globalPath: string = getPathToGlobalPackages();
76+
packageLocations.push(path.resolve(globalPath, scaffold));
6377
} catch (err) {
64-
console.error(`Cannot find a generator at ${absolutePath}.`);
65-
console.error("\nReason:\n");
78+
console.error("Package wasn't validated correctly..");
79+
console.error("Submit an issue for", pkg, "if this persists");
80+
console.error("\nReason: \n");
6681
console.error(chalk.bold.red(err));
6782
process.exitCode = 1;
6883
}
69-
70-
invokeGeneratorIfReady();
71-
return;
72-
}
73-
74-
// Resolve modules on npm registry
75-
processPromise(spawnChild(scaffold))
76-
.then(
77-
(): void => {
78-
try {
79-
const globalPath: string = getPathToGlobalPackages();
80-
packageLocations.push(path.resolve(globalPath, scaffold));
81-
} catch (err) {
82-
console.error("Package wasn't validated correctly..");
83-
console.error("Submit an issue for", pkg, "if this persists");
84-
console.error("\nReason: \n");
85-
console.error(chalk.bold.red(err));
86-
process.exitCode = 1;
87-
}
88-
}
89-
)
90-
.catch(
91-
(err: string): void => {
92-
console.error("Package couldn't be installed, aborting..");
93-
console.error("\nReason: \n");
94-
console.error(chalk.bold.red(err));
95-
process.exitCode = 1;
96-
}
97-
)
98-
.then(invokeGeneratorIfReady);
99-
}
100-
);
84+
})
85+
.catch((err: string): void => {
86+
console.error("Package couldn't be installed, aborting..");
87+
console.error("\nReason: \n");
88+
console.error(chalk.bold.red(err));
89+
process.exitCode = 1;
90+
})
91+
.then(invokeGeneratorIfReady);
92+
});
10193
}

‎packages/utils/scaffold.ts

+28-37
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ function mapOptionsToTransform(config: Config): string[] {
3636

3737
export default function runTransform(transformConfig: TransformConfig, action: string): void {
3838
// webpackOptions.name sent to nameTransform if match
39-
const webpackConfig = Object.keys(transformConfig).filter(
40-
(p: string): boolean => {
41-
return p !== "configFile" && p !== "configPath";
42-
}
43-
);
39+
const webpackConfig = Object.keys(transformConfig).filter((p: string): boolean => {
40+
return p !== "configFile" && p !== "configPath";
41+
});
4442
const initActionNotDefined = action && action !== "init" ? true : false;
4543

4644
webpackConfig.forEach(
@@ -61,40 +59,33 @@ export default function runTransform(transformConfig: TransformConfig, action: s
6159

6260
const transformAction: string = action || null;
6361

64-
return pEachSeries(
65-
transformations,
66-
(f: string): boolean | Node => {
67-
if (f === "merge" || f === "topScope") {
68-
// TODO: typing here is difficult to understand
69-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
70-
return astTransform(j, ast, f, config[f] as any, transformAction);
71-
}
72-
return astTransform(j, ast, f, config.webpackOptions[f], transformAction);
62+
return pEachSeries(transformations, (f: string): boolean | Node => {
63+
if (f === "merge" || f === "topScope") {
64+
// TODO: typing here is difficult to understand
65+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
66+
return astTransform(j, ast, f, config[f] as any, transformAction);
7367
}
74-
)
75-
.then(
76-
(): void | PromiseLike<void> => {
77-
let configurationName: string;
78-
if (!config.configName) {
79-
configurationName = "webpack.config.js";
80-
} else {
81-
configurationName = "webpack." + config.configName + ".js";
82-
}
83-
const projectRoot = findProjectRoot();
84-
const outputPath: string = initActionNotDefined
85-
? transformConfig.configPath
86-
: path.join(projectRoot || process.cwd(), configurationName);
87-
const source: string = ast.toSource({
88-
quote: "single"
89-
});
90-
runPrettier(outputPath, source);
91-
}
92-
)
93-
.catch(
94-
(err: Error): void => {
95-
console.error(err.message ? err.message : err);
68+
return astTransform(j, ast, f, config.webpackOptions[f], transformAction);
69+
})
70+
.then((): void | PromiseLike<void> => {
71+
let configurationName: string;
72+
if (!config.configName) {
73+
configurationName = "webpack.config.js";
74+
} else {
75+
configurationName = "webpack." + config.configName + ".js";
9676
}
97-
);
77+
const projectRoot = findProjectRoot();
78+
const outputPath: string = initActionNotDefined
79+
? transformConfig.configPath
80+
: path.join(projectRoot || process.cwd(), configurationName);
81+
const source: string = ast.toSource({
82+
quote: "single"
83+
});
84+
runPrettier(outputPath, source);
85+
})
86+
.catch((err: Error): void => {
87+
console.error(err.message ? err.message : err);
88+
});
9889
}
9990
);
10091
let successMessage: string =

‎packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap

+407
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.