Skip to content

Commit

Permalink
misc: fix infra & add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Aug 18, 2019
1 parent 8b75e1c commit ddb0cce
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 117 deletions.
127 changes: 62 additions & 65 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
module.exports = {
extends: ["eslint:recommended", 'plugin:@typescript-eslint/recommended', "plugin:prettier/recommended"],
env: {
node: true,
es6: true,
jest: true
},
parser: '@typescript-eslint/parser',
root: true,
plugins: ["node"],
parserOptions: { ecmaVersion: 2017, sourceType: "module" },
rules: {
"no-useless-escape": "off",
"quote-props": ["error", "as-needed"],
"no-dupe-keys": "error",
"no-undef": "error",
"no-extra-semi": "error",
"quotes": ["error", "single"],
"prettier/prettier": ["error", { "singleQuote": true }],
"quotemark": [
true,
"single"
],
"semi": "error",
"no-template-curly-in-string": "error",
"no-caller": "error",
"global-require": "off",
"brace-style": "error",
"key-spacing": "error",
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"no-extra-bind": "warn",
"no-empty": "off",
"no-multiple-empty-lines": "error",
"no-multi-spaces": "error",
"no-process-exit": "off",
"no-trailing-spaces": "error",
"no-use-before-define": "off",
"no-unused-vars": ["error", { args: "none" }],
"no-unsafe-negation": "error",
"no-loop-func": "warn",
"space-before-function-paren": ["error", "never"],
"space-before-blocks": "error",
"object-curly-spacing": ["error", "always"],
"object-curly-newline": ["error", { consistent: true }],
"@typescript-eslint/no-var-requires": "off",
"keyword-spacing": [
"error",
{
after: true,
overrides: {
const: { after: true },
try: { after: true },
throw: { after: true },
case: { after: true },
return: { after: true },
finally: { after: true },
do: { after: true }
}
}
],
"no-console": "off",
"valid-jsdoc": "error",
"eol-last": ["error", "always"],
"newline-per-chained-call": "off"
}
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
env: {
node: true,
es6: true,
jest: true,
},
parser: '@typescript-eslint/parser',
root: true,
plugins: ['node'],
parserOptions: { ecmaVersion: 2017, sourceType: 'module' },
rules: {
'no-useless-escape': 'off',
'quote-props': ['error', 'as-needed'],
'no-dupe-keys': 'error',
'no-undef': 'error',
'no-extra-semi': 'error',
'quotes': ['error', 'single'],
'prettier/prettier': ['error', { singleQuote: true }],
'semi': 'error',
'no-template-curly-in-string': 'error',
'no-caller': 'error',
'global-require': 'off',
'brace-style': 'error',
'key-spacing': 'error',
'space-in-parens': ['error', 'never'],
'space-infix-ops': 'error',
'no-extra-bind': 'warn',
'no-empty': 'off',
'no-multiple-empty-lines': 'error',
'no-multi-spaces': 'error',
'no-process-exit': 'off',
'no-trailing-spaces': 'error',
'no-use-before-define': 'off',
'no-unused-vars': ['error', { args: 'none' }],
'no-unsafe-negation': 'error',
'no-loop-func': 'warn',
'space-before-function-paren': ['error', 'never'],
'space-before-blocks': 'error',
'object-curly-spacing': ['error', 'always'],
'object-curly-newline': ['error', { consistent: true }],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'keyword-spacing': [
'error',
{
after: true,
overrides: {
const: { after: true },
try: { after: true },
throw: { after: true },
case: { after: true },
return: { after: true },
finally: { after: true },
do: { after: true },
},
},
],
'no-console': 'off',
'valid-jsdoc': 'error',
'eol-last': ['error', 'always'],
'newline-per-chained-call': 'off',
},
};
25 changes: 12 additions & 13 deletions lib/utils/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const chalk = require('chalk');
const Table = require('cli-table3');

function showEmojiConditionally(emoji) {
if (process.stdout.isTTY && !process.platform === 'darwin') {
if (process.stdout.isTTY && process.platform === 'darwin') {
return emoji;
} else {
return '';
Expand All @@ -18,14 +18,14 @@ function generateOutput(outputOptions, stats, statsErrors) {
const emojies = ['✅', '🌏', '⚒️ ', '⏱ ', '📂'];
const visibleEmojies = emojies.map(e => showEmojiConditionally(e));

console.log('\n');
console.log(` ${visibleEmojies[0]} ${chalk.underline.bold('Compilation Results')}`);
console.log('\n');
console.log(` ${visibleEmojies[1]} webpack v${webpack.version}`);
console.log(` ${visibleEmojies[2]} Built ${new Date(builtAt).toString()}`);
console.log(` ${visibleEmojies[3]} Compile Time ${time}ms`);
console.log(` ${visibleEmojies[4]} Output Directory: ${outputPath}`);
console.log('\n');
process.stdout.write('\n');
process.stdout.write(`${visibleEmojies[0]} ${chalk.underline.bold('Compilation Results')}\n`);
process.stdout.write('\n');
process.stdout.write(`${visibleEmojies[1]} Version: ${webpack.version}\n`);
process.stdout.write(`${visibleEmojies[2]} Built: ${new Date(builtAt).toString()}\n`);
process.stdout.write(`${visibleEmojies[3]} Compile Time: ${time}ms\n`);
process.stdout.write(`${visibleEmojies[4]} Output Directory: ${outputPath}\n`);
process.stdout.write('\n');

let entries = [];
Object.keys(entrypoints).forEach(entry => {
Expand All @@ -49,20 +49,20 @@ function generateOutput(outputOptions, stats, statsErrors) {
});

if (!compilationTableEmpty) {
console.log(table.toString());
process.stdout.write(table.toString());
}

warnings.forEach(warning => {
process.cliLogger.warn(warning);
console.log('\n');
process.stdout.write('\n');
});

if (statsErrors) {
statsErrors.forEach(err => {
if (err.loc) process.cliLogger.warn(err.loc);
if (err.name) {
process.cliLogger.error(err.name);
console.log('\n');
process.stdout.write('\n');
}
});
}
Expand Down Expand Up @@ -127,7 +127,6 @@ module.exports = async function webpackInstance(opts, shouldUseMem) {
if (processingErrors.length > 0) {
throw new Error(processingErrors);
}

const compiler = await webpack(options);
let lastHash = null;

Expand Down
6 changes: 5 additions & 1 deletion packages/generators/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
"prettier/@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-var-requires": "off",
}
}
7 changes: 2 additions & 5 deletions packages/generators/init-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
langQuestionHandler,
tooltip,
generatePluginName,
Loader,
StylingType,
styleQuestionHandler,
entryQuestions
Expand Down Expand Up @@ -81,8 +80,6 @@ export default class InitGenerator extends Generator {
public async prompting(): Promise<void | {}> {
const done: () => {} = this.async();
const self: this = this;
let regExpForStyles: string;
let ExtractUseProps: Loader[];

process.stdout.write(
`\n${logSymbols.info}${chalk.blue(" INFO ")} ` +
Expand Down Expand Up @@ -118,7 +115,7 @@ export default class InitGenerator extends Generator {
this.configuration.config.webpackOptions.entry = entryOption;
}

let { outputDir } = await Input(
const { outputDir } = await Input(
self,
"outputDir",
"In which folder do you want to store your generated bundles?",
Expand Down Expand Up @@ -156,7 +153,7 @@ export default class InitGenerator extends Generator {
this.autoGenerateConfig
);

({ ExtractUseProps, regExpForStyles } = styleQuestionHandler(self, stylingType));
const { ExtractUseProps, regExpForStyles } = styleQuestionHandler(self, stylingType);

if (this.usingDefaults) {
// Ask if the user wants to use extractPlugin
Expand Down
5 changes: 4 additions & 1 deletion packages/generators/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "../../tsconfig.packages.json"
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"allowJs": true
}
}
6 changes: 3 additions & 3 deletions packages/generators/utils/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ interface CustomGenerator extends Generator {
export default async function entry(
self: CustomGenerator,
multiEntries: boolean,
autoGenerateDefaults: boolean = false
autoGenerateDefaults = false
): Promise<void | {}> {
let webpackEntryPoint: object = {};
const webpackEntryPoint: object = {};
// TODO: refactoring to async/await
async function forEachPromise(
entries: string[],
Expand Down Expand Up @@ -55,7 +55,7 @@ export default async function entry(
}

if (multiEntries) {
let multipleEntriesAnswer = await InputValidate(
const multipleEntriesAnswer = await InputValidate(
self,
"multipleEntries",
"What do you want to name your bundles? (separated by comma)",
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/utils/languageSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getFolder = (path: string): string =>

function getEntryFolders(self): string[] {
const entryOption = self.configuration.config.webpackOptions.entry;
let entryFolders = {};
const entryFolders = {};
if (typeof entryOption === "string") {
const folder = getFolder(entryOption);
if (folder.length > 0) entryFolders[folder] = true;
Expand Down
3 changes: 1 addition & 2 deletions packages/generators/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export const replaceAt = (str: string, index: number, replace: string): string =
*/

export const generatePluginName = (rawPluginName: string): string => {
let myPluginNameArray: string[];
myPluginNameArray = rawPluginName.split("-");
const myPluginNameArray = rawPluginName.split("-");
const pluginArrLength: number = myPluginNameArray.length;
for (let i = 0; i < pluginArrLength && pluginArrLength > 1; i++) {
myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase());
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"prettier/@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
}
7 changes: 4 additions & 3 deletions packages/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { transformations } from "./migrate";
import { Node } from "./types/NodePath";
import jscodeshift from "jscodeshift";

declare var process: {
declare let process: {
cwd: Function;
webpackModule: {
validate: Function;
Expand Down Expand Up @@ -132,7 +132,7 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom
}
}
)
.then((answer: { confirmValidation: boolean }): void => {
.then(async(answer: { confirmValidation: boolean }): Promise<void> => {
if (!answer) {
return;
}
Expand All @@ -144,7 +144,8 @@ function runMigration(currentConfigPath: string, outputConfigPath: string): Prom
});

if (answer.confirmValidation) {
const webpackOptionsValidationErrors: string[] = validate(require(outputConfigPath));
const outputPath = await import(outputConfigPath);
const webpackOptionsValidationErrors: string[] = validate(outputPath);

if (webpackOptionsValidationErrors.length) {
console.error(chalk.red("\n✖ Your configuration validation wasn't successful \n"));
Expand Down
3 changes: 1 addition & 2 deletions packages/serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ export default function serve(): Promise<void | Function> {
.then(
(depTypeAns: { confirmDepType: string }): Promise<void | Function> => {
const packager: string = getRootPathModule("package-lock.json") ? "npm" : "yarn";
let spawnAction: () => SpawnSyncReturns<Buffer>;

spawnAction = (): SpawnSyncReturns<Buffer> =>
const spawnAction = (): SpawnSyncReturns<Buffer> =>
spawnWithArg(packager, depTypeAns.confirmDepType);

return processPromise(spawnAction()).then(
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"prettier/@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"]
"plugins": ["@typescript-eslint"],
}
4 changes: 3 additions & 1 deletion packages/utils/__tests__/package-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import * as packageManager from "../package-manager";

import * as globalModules from "global-modules";

jest.mock("cross-spawn");
jest.mock("fs");

Expand Down Expand Up @@ -77,6 +79,6 @@ describe("package-manager", () => {
it("should return the npm global dir from getPathToGlobalPackages if yarn is not installed", () => {
mockSpawnErrorOnce();
const globalPath = packageManager.getPathToGlobalPackages();
expect(globalPath).toBe(require("global-modules"));
expect(globalPath).toBe(globalModules);
});
});
8 changes: 4 additions & 4 deletions packages/utils/copy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const generatorCopy = (generator, templateDir: string): ((filePath: strin
filePath: string
): void => {
const sourceParts = templateDir.split(path.delimiter);
sourceParts.push.apply(sourceParts, filePath.split("/"));
sourceParts.push(...filePath.split("/"));
const targetParts = path.dirname(filePath).split("/");
targetParts.push(path.basename(filePath, ".tpl"));

generator.fs.copy(
path.join.apply(null, sourceParts),
path.join(...sourceParts),
generator.destinationPath(path.join.apply(null, targetParts))
);
};
Expand All @@ -39,12 +39,12 @@ export const generatorCopyTpl = (
templateData: object
): ((filePath: string) => void) => (filePath: string): void => {
const sourceParts = templateDir.split(path.delimiter);
sourceParts.push.apply(sourceParts, filePath.split("/"));
sourceParts.push(...filePath.split("/"));
const targetParts = path.dirname(filePath).split("/");
targetParts.push(path.basename(filePath, ".tpl").slice(1));

generator.fs.copyTpl(
path.join.apply(null, sourceParts),
path.join(...sourceParts),
generator.destinationPath(path.join.apply(null, targetParts)),
templateData
);
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/modify-config-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const DEFAULT_WEBPACK_CONFIG_FILENAME = 'webpack.config.js';
* @returns {Function} runTransform - Returns a transformation instance
*/

export default function modifyHelperUtil(action: string, generator: typeof Generator, configFile: string = DEFAULT_WEBPACK_CONFIG_FILENAME, packages?: string[], autoSetDefaults: boolean = false): void {
let configPath: string | null = null;
export default function modifyHelperUtil(action: string, generator: typeof Generator, configFile: string = DEFAULT_WEBPACK_CONFIG_FILENAME, packages?: string[], autoSetDefaults = false): void {
const configPath: string | null = null;

const env = yeoman.createEnv('webpack', null);
const generatorName = 'webpack-init-generator';
Expand Down
Loading

0 comments on commit ddb0cce

Please sign in to comment.