Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 #165

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

V4 #165

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

const eslint = {
extends: '@chrisblossom/eslint-config',
rules: {
'import/no-extraneous-dependencies': 'off',
},
overrides: [
{
files: ['*.ts', '*.tsx', '.*.ts', '.*.tsx'],
rules: {
'promise/prefer-await-to-then': 'off',
'promise/always-return': 'off',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
files: ['dev-utils/**/*.js', 'dev-utils/**/.*.js'],
parserOptions: {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ By default, this plugin will remove all files inside webpack's `output.path` dir

`npm install --save-dev clean-webpack-plugin`

If you are using [Typescript](https://www.typescriptlang.org/), you might need to install `@types/webpack` and/or `@types/webpack-env` to your `devDependencies`.

## Usage

```js
Expand Down
7 changes: 4 additions & 3 deletions dev-utils/get-webpack-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ function getWebpackVersion() {
const webpackPath = require.resolve('webpack');
const { dir } = path.parse(webpackPath);

const webpackPackageJson = readPkgUp.sync({ cwd: dir, normalize: false });
const webpackPackageJson =
readPkgUp.sync({ cwd: dir, normalize: false }) || {};

const version = webpackPackageJson.package.version
? webpackPackageJson.package.version
const version = webpackPackageJson.packageJson.version
? webpackPackageJson.packageJson.version
: null;

return version;
Expand Down
8 changes: 5 additions & 3 deletions dev-utils/get-webpack-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getWebpackVersionTest = () => require('./get-webpack-version')();
describe('webpackVersion', () => {
test('returns major only and is type number', () => {
jest.doMock('read-pkg-up', () => ({
sync: () => ({ package: { version: '4.29.0' } }),
sync: () => ({ packageJson: { version: '4.29.0' } }),
}));

const version = getWebpackVersionTest();
Expand All @@ -14,15 +14,17 @@ describe('webpackVersion', () => {

test('handles alpha', () => {
jest.doMock('read-pkg-up', () => ({
sync: () => ({ package: { version: '5.0.0-alpha.8' } }),
sync: () => ({ packageJson: { version: '5.0.0-alpha.8' } }),
}));

const version = getWebpackVersionTest();
expect(version).toEqual('5.0.0-alpha.8');
});

test('returns null if no version found', () => {
jest.doMock('read-pkg-up', () => ({ sync: () => ({ package: {} }) }));
jest.doMock('read-pkg-up', () => ({
sync: () => ({ packageJson: {} }),
}));

const version = getWebpackVersionTest();
expect(version).toEqual(null);
Expand Down
3 changes: 2 additions & 1 deletion dev-utils/node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const semver = require('semver');

function getNodeVersion() {
const packageJson =
readPkgUp.sync({ cwd: process.cwd(), normalize: false }).package || {};
readPkgUp.sync({ cwd: process.cwd(), normalize: false }).packageJson ||
{};
const engines = packageJson.engines || {};
const node = engines.node || '8.9.0';

Expand Down
8 changes: 4 additions & 4 deletions dev-utils/node-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('handles undefined pkg', () => {
});

test('handles undefined engines', () => {
jest.doMock('read-pkg-up', () => ({ sync: () => ({ package: {} }) }));
jest.doMock('read-pkg-up', () => ({ sync: () => ({ packageJson: {} }) }));

const nodeVersion = require('./node-version');

Expand All @@ -20,7 +20,7 @@ test('handles undefined engines', () => {

test('handles undefined node', () => {
jest.doMock('read-pkg-up', () => ({
sync: () => ({ package: { engines: { npm: '^5.0.0' } } }),
sync: () => ({ packageJson: { engines: { npm: '^5.0.0' } } }),
}));

const nodeVersion = require('./node-version');
Expand All @@ -30,7 +30,7 @@ test('handles undefined node', () => {

test('handles non-digit characters', () => {
jest.doMock('read-pkg-up', () => ({
sync: () => ({ package: { engines: { node: '>=10.0.0' } } }),
sync: () => ({ packageJson: { engines: { node: '>=10.0.0' } } }),
}));

const nodeVersion = require('./node-version');
Expand All @@ -40,7 +40,7 @@ test('handles non-digit characters', () => {

test('handles empty node', () => {
jest.doMock('read-pkg-up', () => ({
sync: () => ({ package: { engines: { node: '' } } }),
sync: () => ({ packageJson: { engines: { node: '' } } }),
}));

const nodeVersion = require('./node-version');
Expand Down
40 changes: 22 additions & 18 deletions dev-utils/test-supported-webpack-versions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

/* eslint-disable arrow-body-style,no-param-reassign,promise/always-return */
/* eslint-disable no-param-reassign,no-console */

'use strict';

Expand Down Expand Up @@ -40,10 +40,10 @@ const webpackTestTasks = supported.map((version) => {
const npmInstallTaskTitle = `npm ${npmCommandArgs.join(' ')}`;
const npmInstallTask = {
title: npmInstallTaskTitle,
task: (ctx, task) =>
execa('npm', npmCommandArgs).then(() => {
task.title = `${npmInstallTaskTitle} (${getWebpackVersion()})`;
}),
task: async (ctx, task) => {
await execa('npm', npmCommandArgs);
task.title = `${npmInstallTaskTitle} (${getWebpackVersion()})`;
},
};

const jestCommandArgs =
Expand All @@ -69,21 +69,23 @@ const webpackTestTasks = supported.map((version) => {
if (ciEnabled === true) {
const codecovTask = {
title: 'codecov',
task: () =>
execa('codecov', [], {
task: async () => {
const { stdout } = await execa('codecov', [], {
env: { FORCE_COLOR: true },
}).then(({ stdout }) => {
// eslint-disable-next-line no-console
console.log(stdout);
}),
});

console.log(stdout);
},
};

testWebpackVersionTask.push(codecovTask);
}

return {
title: `webpack@${version}`,
task: () => new Listr(testWebpackVersionTask),
task: () => {
return new Listr(testWebpackVersionTask);
},
skip,
};
});
Expand All @@ -104,30 +106,32 @@ tasks
const packageJsonWebpackVersion = readPkgUp.sync({
cwd: process.cwd(),
normalize: false,
}).package.devDependencies.webpack;
}).packageJson.devDependencies.webpack;

return new Listr(
[
{
title: `npm install --no-save webpack@${packageJsonWebpackVersion}`,
task: () =>
execa(
task: () => {
return execa(
'npm',
[
'install',
'--no-save',
`webpack@${packageJsonWebpackVersion}`,
],
{ env: { FORCE_COLOR: true } },
),
skip: () => ciEnabled === true,
);
},
skip: () => {
return ciEnabled === true;
},
},
],
listrOptions,
).run();
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error.message);

// eslint-disable-next-line no-process-exit
Expand Down
53 changes: 25 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,35 @@
"prepublishOnly": "npm run build && npm run lint && npm run typescript && npm run test.all",
"release": "np"
},
"peerDependencies": {
"webpack": "*"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@chrisblossom/eslint-config": "^5.0.0",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.2",
"@types/read-pkg-up": "^3.0.1",
"babel-jest": "^24.8.0",
"codecov": "^3.5.0",
"cross-env": "^5.2.0",
"del-cli": "^1.1.0",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@chrisblossom/eslint-config": "^6.1.5",
"@types/jest": "^24.0.19",
"@types/node": "^12.11.1",
"@types/webpack": "^4.39.3",
"babel-jest": "^24.9.0",
"codecov": "^3.6.1",
"cross-env": "^6.0.3",
"del-cli": "^3.0.0",
"eslint": "^5.16.0",
"execa": "^1.0.0",
"husky": "^2.3.0",
"jest": "^24.8.0",
"lint-staged": "^8.1.7",
"execa": "^3.1.0",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.2",
"listr": "^0.14.3",
"np": "^5.0.2",
"prettier": "^1.17.1",
"read-pkg-up": "^6.0.0",
"semver": "^6.0.0",
"temp-sandbox": "^3.0.0",
"typescript": "^3.4.5",
"webpack": "^4.32.0"
"np": "^5.1.1",
"prettier": "^1.18.2",
"read-pkg-up": "^7.0.0",
"semver": "^6.3.0",
"temp-sandbox": "^4.0.1",
"typescript": "^3.6.4",
"webpack": "^4.41.2"
},
"dependencies": {
"@types/webpack": "^4.4.31",
"del": "^4.1.1"
"del": "^5.1.0",
"slash": "^3.0.0"
}
}
Loading